| | @@ -13,7 +13,7 @@ |
| 13 | 13 | This report defines the language. It is short on purpose. Whatever it |
| 14 | 14 | doesn't allow, raz doesn't have. |
| 15 | 15 | |
| 16 | | -This is version 2026-10.30 of the report; section 11 says where each |
| 16 | +This is version 2026-10.31 of the report; section 11 says where each |
| 17 | 17 | version's changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, |
| 18 | 18 | for a language anyone can build again. They break programs written |
| 19 | 19 | for 2026-10.10 and before: for 2026-10.9, say, the report of compiler |
| | @@ -34,7 +34,12 @@ |
| 34 | 34 | sixth thaw: an array constant typed `[]T` takes its length from its |
| 35 | 35 | literal (section 4); it breaks no program. 2026-10.30 mends a defect: |
| 36 | 36 | `[]` used as a slice is the empty slice, which may be returned |
| 37 | | -(sections 6.5 and 7.3); it breaks no program. |
| 37 | +(sections 6.5 and 7.3); it breaks no program. 2026-10.31 is a seventh |
| 38 | +thaw: `INT` is at least 16 bits, and `U8`, `I8` and `I16` widen to it |
| 39 | +(sections 5.1, 5.10 and 6.1); an enumeration's name may be written with |
| 40 | +its type, and must be where another declaration shares it (section |
| 41 | +5.7); and `continue` (section 7.2), which breaks a program that has a |
| 42 | +name `continue`. |
| 38 | 43 | |
| 39 | 44 | The language is frozen, softly, from this version on: it changes only |
| 40 | 45 | to mend a defect, and its library grows only by what breaks no program |
| | @@ -77,10 +82,10 @@ |
| 77 | 82 | **Reserved words** are lowercase, except `VOLATILE`: |
| 78 | 83 | |
| 79 | 84 | ``` |
| 80 | | -and begin break by code const defer div do else elsif end extern for |
| 81 | | -forward if import in link match mod module not of or packed proc record |
| 82 | | -repeat return set shl shr then to try type until var variant VOLATILE |
| 83 | | -while xor |
| 85 | +and begin break by code const continue defer div do else elsif end |
| 86 | +extern for forward if import in link match mod module not of or packed |
| 87 | +proc record repeat return set shl shr then to try type until var |
| 88 | +variant VOLATILE while xor |
| 84 | 89 | ``` |
| 85 | 90 | |
| 86 | 91 | `static`, in `link static;` (section 3), and `check` and `off`, in |
| | @@ -437,8 +442,8 @@ |
| 437 | 442 | | `F64` | 8 | IEEE 754 double precision | |
| 438 | 443 | |
| 439 | 444 | `INT` is the everyday integer: lengths, indexes and sizes are `INT`s. |
| 440 | | -It is as big as an address, so it is the integer a pointer converts |
| 441 | | -to (section 6.7), and a word the atomic built-ins work on (section |
| 445 | +It is as big as an address, and at least 16 bits, as `UINT` is, on |
| 446 | +every target; so it is the integer a pointer converts to (section 6.7), and a word the atomic built-ins work on (section |
| 442 | 447 | 6.8). `INT` and `I64` are two types, even where they have the same |
| 443 | 448 | size: an `INT` goes silently into an `I64` wherever it meets one, in |
| 444 | 449 | an expression too (sections 5.10 and 6.1), and an `I64` becomes an |
| | @@ -552,6 +557,30 @@ |
| 552 | 557 | enumeration has at most 256 names and takes 1 byte; the first name is |
| 553 | 558 | 0, the next 1, and so on. |
| 554 | 559 | |
| 560 | +A name of an enumeration may also be written with its type, |
| 561 | +`Color.red`, and one imported with the type's module, `M.Color.red`. |
| 562 | +Two enumerations of a scope may share a name, and an enumeration may |
| 563 | +have a name that something else of its scope has, a constant, a |
| 564 | +variable or a procedure: such a name is written with its type, |
| 565 | +`Elem.bold`. Written alone, it names the one declaration of it that |
| 566 | +isn't an enumeration's, if there is one, and is an error if there |
| 567 | +isn't: |
| 568 | + |
| 569 | +``` |
| 570 | +type |
| 571 | + Style = (bold, italic); |
| 572 | + Elem = (para, bold, rule); |
| 573 | +proc rule; (* a procedure, beside Elem's rule *) |
| 574 | +... |
| 575 | +s := Style.bold; e := Elem.bold; e := Elem.rule; |
| 576 | +e := para; (* para is Elem's alone *) |
| 577 | +rule; (* the procedure *) |
| 578 | +s := bold; (* an error: write Style.bold or Elem.bold *) |
| 579 | +``` |
| 580 | + |
| 581 | +The type is never taken from where the name stands: `s := bold` is an |
| 582 | +error though `s` is a `Style`. |
| 583 | + |
| 555 | 584 | `set of E`, for an enumeration `E` of at most 64 names, holds any |
| 556 | 585 | choice of `E`'s names: bit `i` stands for the name at position `i`. It |
| 557 | 586 | takes the smallest of 1, 2, 4 and 8 bytes that has a bit for each name, |
| | @@ -626,7 +655,11 @@ |
| 626 | 655 | least the string's length (the rest is zero); |
| 627 | 656 | - `A` is a procedure and `B` a procedure type with the same signature; |
| 628 | 657 | - `A` is `INT` and `B` is `I64`, or `A` is `UINT` and `B` is `U64`, |
| 629 | | - which loses nothing on any target. |
| 658 | + which loses nothing on any target; |
| 659 | +- `A` is `U8`, `I8` or `I16` and `B` is `INT`, or `A` is `U8` or `U16` |
| 660 | + and `B` is `UINT`, which an `INT` or a `UINT` of 16 bits holds whole, |
| 661 | + so on every target; unless the value is what an operator gives |
| 662 | + (below). |
| 630 | 663 | |
| 631 | 664 | A string's bytes are constant. A `[]U8` or `^U8` made from a string |
| 632 | 665 | literal, or a slice of a string constant, points at them, and writing |
| | @@ -646,6 +679,26 @@ |
| 646 | 679 | parameter of type `I64`, and a procedure returning an `INT` isn't of a |
| 647 | 680 | procedure type returning an `I64`. |
| 648 | 681 | |
| 682 | +A `U8`, `I8` or `I16` widens to `INT`, and a `U8` or `U16` to `UINT`, |
| 683 | +in the same places, as an `INT` to `I64`: assigned, passed, returned, |
| 684 | +in `a, b := f(x)`, to a `for`'s bounds and `INC` and `DEC`'s step, and |
| 685 | +in an expression, where it meets an `INT` or a `UINT` (section 6.1). |
| 686 | +They widen only that far: a `U8` meets an `I64` only as `INT(b)` or |
| 687 | +`I64(b)`. And they widen only as values that are moved: a variable, an |
| 688 | +element, a field, a call's result or a conversion's. What an operator |
| 689 | +gives on them doesn't: it was computed in their type, and has wrapped |
| 690 | +there. With `a, b: U8` holding 200 and 100, `a + b` is 44, so |
| 691 | +`n := a + b`, for an `INT` `n`, is an error; `n := INT(a) + b` is 300, |
| 692 | +and says where the sum is made. |
| 693 | + |
| 694 | +``` |
| 695 | +var s: []U8; n, d: INT; |
| 696 | +n := s[i]; (* an element: widens *) |
| 697 | +n := n * 10 + s[i] - '0'; (* n * 10 + s[i] is an INT, and so the rest *) |
| 698 | +d := s[i] - '0'; (* an error: a U8, which may have wrapped *) |
| 699 | +d := INT(s[i]) - '0'; (* below '0' too, it is negative *) |
| 700 | +``` |
| 701 | + |
| 649 | 702 | ## 6. Expressions |
| 650 | 703 | |
| 651 | 704 | ``` |
| | @@ -689,14 +742,16 @@ |
| 689 | 742 | Both operands of `+ - * div mod & | xor`, and of a relation, have the |
| 690 | 743 | same integer type, or one is an untyped constant that takes the |
| 691 | 744 | other's type, which it must fit, or one is an `INT` and the other an |
| 692 | | -`I64` (a `UINT` and a `U64`), and the `INT` widens to `I64` (section |
| 693 | | -5.10). So do `v` and `k` in `INC(v, k)` and |
| 745 | +`I64` (a `UINT` and a `U64`), and the `INT` widens to `I64`, or one is |
| 746 | +an `INT` and the other a `U8`, `I8` or `I16` (a `UINT` and a `U8` or |
| 747 | +`U16`) that no operator gave, and it widens to `INT` (section 5.10). So do `v` and `k` in `INC(v, k)` and |
| 694 | 748 | `DEC(v, k)`, where only `k` widens: an `I64` `k` isn't added to an |
| 695 | 749 | `INT` `v`. The result has that type and wraps around at its width: |
| 696 | 750 | in `U8`, `200 + 100` is `44`. A unary minus wraps too: for `x` of an |
| 697 | 751 | unsigned type, `-x` is `0 - x`. Other integer types are never mixed, |
| 698 | 752 | whatever their sizes: with `i: I32`, `i < LEN(s)` is an error, and |
| 699 | | -`i` should be an `INT`. With `pos: I64`, `pos + LEN(s)` is an `I64`. |
| 753 | +`i` should be an `INT`; with `c: U8`, `c < LEN(s)` is an `INT` |
| 754 | +comparison. With `pos: I64`, `pos + LEN(s)` is an `I64`. |
| 700 | 755 | |
| 701 | 756 | Where the report asks for an integer and names no type, as an index, a |
| 702 | 757 | slice's bound, a shift's count, a pointer's offset `i` in `p + i`, or |
| | @@ -993,6 +1048,7 @@ |
| 993 | 1048 | | "match" Expr "of" { "|" Arm } "end" |
| 994 | 1049 | | "return" [ Expr { "," Expr } ] |
| 995 | 1050 | | "break" |
| 1051 | + | "continue" |
| 996 | 1052 | | "defer" Statement |
| 997 | 1053 | | "try" Designator . |
| 998 | 1054 | Arm = ( ident [ "(" ident { "," ident } ")" ] |
| | @@ -1043,8 +1099,23 @@ |
| 1043 | 1099 | `i <= b`. A negative `s` is the same, the other way round. |
| 1044 | 1100 | |
| 1045 | 1101 | `break` ends the innermost `while`, `repeat` or `for` it stands in, |
| 1046 | | -and the program goes on after it. There is no `goto`. |
| 1102 | +and the program goes on after it. `continue` ends the round of the |
| 1103 | +innermost one, as reaching the end of its body would: a `while` tests |
| 1104 | +its condition again, a `repeat` tests its `until`, and a `for` steps |
| 1105 | +its variable, or ends. There is no `goto`. |
| 1106 | + |
| 1107 | +A `continue` passes over the rest of the body, the step of a `while` |
| 1108 | +or a `repeat` included, if it stands there: so the step comes first. |
| 1047 | 1109 | |
| 1110 | +``` |
| 1111 | +while i < LEN(t) do |
| 1112 | + ch, n := Str.decode(t[i..LEN(t)]); |
| 1113 | + i := i + n; (* before any continue *) |
| 1114 | + if ch = 0ADH then continue; end; (* a soft hyphen, passed over *) |
| 1115 | + ... |
| 1116 | +end; |
| 1117 | +``` |
| 1118 | + |
| 1048 | 1119 | ### 7.3 Return |
| 1049 | 1120 | |
| 1050 | 1121 | `return e;` ends the procedure with the result `e`; `return a, b;` with |
| | @@ -1181,7 +1252,7 @@ |
| 1181 | 1252 | |
| 1182 | 1253 | `defer s;` runs the statement `s` when the program leaves the statement |
| 1183 | 1254 | list the `defer` stands in: at its end, or by a `return`, or by a |
| 1184 | | -`break` out of it. Statements deferred in the same list run in the |
| 1255 | +`break` or `continue` out of it. Statements deferred in the same list run in the |
| 1185 | 1256 | opposite order to their `defer`s, and only those whose `defer` has been |
| 1186 | 1257 | reached run. |
| 1187 | 1258 | |
| | @@ -1215,8 +1286,8 @@ |
| 1215 | 1286 | ``` |
| 1216 | 1287 | |
| 1217 | 1288 | `return e;` evaluates `e` before the deferred statements run. A |
| 1218 | | -deferred statement can't contain `defer`, nor a `return`, `break` or |
| 1219 | | -`try` that would leave it. A failed check, `Rt.exit` and `Sys.exit` end the |
| 1289 | +deferred statement can't contain `defer`, nor a `return`, `break`, |
| 1290 | +`continue` or `try` that would leave it. A failed check, `Rt.exit` and `Sys.exit` end the |
| 1220 | 1291 | program without running the deferred statements still pending. |
| 1221 | 1292 | |
| 1222 | 1293 | ### 7.8 Try |
| | @@ -1705,6 +1776,7 @@ |
| 1705 | 1776 | | "match" Expr "of" { "|" Arm } "end" |
| 1706 | 1777 | | "return" [ Expr { "," Expr } ] |
| 1707 | 1778 | | "break" |
| 1779 | + | "continue" |
| 1708 | 1780 | | "defer" Statement |
| 1709 | 1781 | | "try" Designator . |
| 1710 | 1782 | Arm = ( ident [ "(" ident { "," ident } ")" ] |