mt-lang 0.3.27 → 0.3.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 802d8ba551d2f4712c3dc174ade901063ef797baf33a87ad8a2b902db2916b24
4
- data.tar.gz: 322d7781ae7fcbf67108bf260b63caf8889facf0382c3d7e248e124868a0bbd0
3
+ metadata.gz: 20058db447f681f83bcc651d9a9772e79b23bd9f1677e5c33d2053bab536a14f
4
+ data.tar.gz: 204af7f1018ce7637690eddc2bc9a7f297fc1f10e59c1a573491bd3b7c0b0d1c
5
5
  SHA512:
6
- metadata.gz: afd649faf27c7327ab60c9050c56eb66416fd022fbb11a2d8b8f16438a021732fdec0a65e76a16649f6b35ec7c070d2e0873b56a02ff0d8aa8c1505ffb72d685
7
- data.tar.gz: eee26037932660079c5b1352eac96ef923766930c42d611895206c66276ef31a313213cc3b104046f4ff0048af7035bb77a2aa4cf270c79a08aa0e203e31bb85
6
+ metadata.gz: ec63256de42954560cedc8e5021370b8f45a64e083ebb839d3057d4ea93816a51d45f950283ece162152ad10be6f1bb6ec4aa54a6ad8ce7b2db107830dd1db6a
7
+ data.tar.gz: 616bc238b0ee79df60a7a09fc62b895b1ab7717a1116a6b96c50879549578ba0aab91fbb9a74e40aedfc559973c333a8bc2c2cc40d3d16b6913584a744230819
data/README.md CHANGED
@@ -249,6 +249,10 @@ struct Vec2:
249
249
  x: float
250
250
  y: float
251
251
 
252
+ # Methods may also be defined directly inside the struct body:
253
+ function length_sq() -> float:
254
+ return this.x * this.x + this.y * this.y
255
+
252
256
  @[packed]
253
257
  struct Header:
254
258
  tag: ubyte
@@ -310,6 +314,7 @@ variant Token:
310
314
  Rules:
311
315
 
312
316
  - `struct` and `opaque` may declare nominal interface conformance with `implements`.
317
+ - `struct` bodies may contain `function`, `editable function`, and `static function` declarations directly — they desugar to `extending` blocks targeting the enclosing struct. This is pure syntactic sugar; the compiler emits identical code as a separate `extending` block.
313
318
  - `attribute[target, ...]` declares reusable declaration attributes for `struct`, `field`, `callable`, `const`, `event`, `enum`, `flags`, `union`, and `variant` targets.
314
319
  - Attributes are applied with one or more leading `@[name(...)]` blocks. Built-in `packed`, `align(bytes)`, and `deprecated(message)` are predefined attributes.
315
320
  - `variant` arms may carry named payload fields.
@@ -358,11 +363,31 @@ Method kinds:
358
363
  - `editable function` -> editable receiver
359
364
  - `static function` -> no receiver
360
365
 
366
+ Methods may appear inside a struct body (desugared to an `extending` block) or in a separate
367
+ `extending` declaration:
368
+
369
+ ```mt
370
+ struct Counter:
371
+ value: int
372
+
373
+ function read() -> int:
374
+ return this.value
375
+
376
+ editable function bump() -> void:
377
+ this.value += 1
378
+
379
+ static function zero() -> Counter:
380
+ return Counter(value = 0)
381
+ ```
382
+
383
+ Both inline and `extending` forms lower to identical C code.
384
+
361
385
  Method notes:
362
386
 
363
387
  - Async methods are supported.
364
388
  - Generic methods are supported.
365
389
  - There is no constructor keyword. Names like `init` and `default` are ordinary static methods.
390
+ - Methods may be defined inside struct bodies directly (as syntactic sugar for `extending`) or in separate `extending` blocks. Both forms lower to the same C code; the inline form is preferred when the struct and its core methods appear in the same file.
366
391
 
367
392
  ## 7. Functions, Externals, And Foreign Functions
368
393
 
@@ -300,7 +300,25 @@ Callable and `ref[...]` rules:
300
300
  struct Vec2:
301
301
  x: float
302
302
  y: float
303
+ ```
304
+
305
+ `struct` bodies may also contain `function`, `editable function`, and `static function` declarations directly — they desugar to `extending` blocks targeting the enclosing struct. This is pure syntactic sugar and produces identical C code. See §3.6 for the method kind rules.
306
+
307
+ ```mt
308
+ struct Counter:
309
+ value: int
310
+
311
+ function read() -> int:
312
+ return this.value
313
+
314
+ editable function bump() -> void:
315
+ this.value += 1
316
+
317
+ static function zero() -> Counter:
318
+ return Counter(value = 0)
319
+ ```
303
320
 
321
+ ```mt
304
322
  union Number:
305
323
  i: int
306
324
  f: float
@@ -417,7 +435,25 @@ Rules:
417
435
 
418
436
  ### 3.6 Methods
419
437
 
438
+ Methods may appear directly inside a struct body (desugared to an `extending` block) or in a separate `extending` declaration. Both forms lower to identical C code.
439
+
440
+ ```mt
441
+ # Inline form (sugar)
442
+ struct Counter:
443
+ value: int
444
+
445
+ function read() -> int:
446
+ return this.value
447
+
448
+ editable function bump() -> void:
449
+ this.value += 1
450
+
451
+ static function zero() -> Counter:
452
+ return Counter(value = 0)
453
+ ```
454
+
420
455
  ```mt
456
+ # Equivalent extending form
421
457
  extending Counter:
422
458
  function read() -> int:
423
459
  return this.value