| | @@ -53,9 +53,12 @@ |
| 53 | 53 | twelfth: `MIN(T)` and `MAX(T)`, the limits of an integer type, and |
| 54 | 54 | `CLZ`, `CTZ` and `POPCOUNT`, which count bits (sections 6.1 and 6.8); |
| 55 | 55 | `INT(b)`, a `BOOL` as an integer (section 6.7); `OFFSET(T, f)` and |
| 56 | | -`SIZE(T.f)`, where a field lies and how big it is; and `BYTES(x)`, the |
| 57 | | -bytes of a variable or a slice (sections 4 and 6.8); it breaks no |
| 58 | | -program. |
| 56 | +`SIZE(T.f)`, where a field lies and how big it is; `BYTES(x)`, the |
| 57 | +bytes of a variable or a slice (sections 4 and 6.8); `FILL(d, x)`, an |
| 58 | +array or a slice set to one value (section 6.8); a qualified case in a |
| 59 | +`match` arm (section 7.4); a slice part written as a literal, and an |
| 60 | +`ERROR` constant named by another (sections 4 and 5.8); and a `const` |
| 61 | +parameter's slice returned (section 7.3); it breaks no program. |
| 59 | 62 | |
| 60 | 63 | The language is frozen, softly, from this version on: it changes only |
| 61 | 64 | to mend a defect, and its library grows only by what breaks no program |
| | @@ -405,9 +408,11 @@ |
| 405 | 408 | literal (section 6.5) of constants, that of a variant one a case built |
| 406 | 409 | from constants, as a program builds one (section 5.6). Its elements |
| 407 | 410 | and fields are integers, reals, `BOOL`s, enumerations, sets, `ERROR`s, |
| 408 | | -procedures, `nil`, a string for a `[]U8`, an array constant or the |
| 409 | | -empty slice for a slice of its element type, and arrays, records and |
| 410 | | -variants of these; no other pointer. A variant constant must have a |
| 411 | +procedures, `nil`, a string for a `[]U8`, an array constant, an array |
| 412 | +literal or the empty slice for a slice of its element type, and |
| 413 | +arrays, records and variants of these; no other pointer. A named |
| 414 | +constant stands for its literal wherever an array, record or variant is |
| 415 | +wanted. A variant constant must have a |
| 411 | 416 | type: `const D = dot;` is an error, `const D: Shape = dot;` isn't. |
| 412 | 417 | |
| 413 | 418 | ``` |
| | @@ -415,6 +420,7 @@ |
| 415 | 420 | type Rule = record class: []U8; tag: INT; float: BOOL; end; |
| 416 | 421 | const Rules: [2]Rule = [{class: "firefox", tag: 2}, {class: "mpv", float: true}]; |
| 417 | 422 | const Shapes: []Shape = [circle(1.0), rect(2.0, 3.0), dot]; (* Shape of section 5.6 *) |
| 423 | +const Rows: [][]INT = [[1, 2], [3]]; (* each row an array constant of its own *) |
| 418 | 424 | ... |
| 419 | 425 | p := Primes[i]; |
| 420 | 426 | ``` |
| | @@ -636,7 +642,11 @@ |
| 636 | 642 | by a constant declared as above, and each such declaration makes an |
| 637 | 643 | error different from every other, whatever its message: two modules that |
| 638 | 644 | both declare `"not found"` have two different errors. A generic module |
| 639 | | -makes its errors once per instance. `nil` is no error. |
| 645 | +makes its errors once per instance. `nil` is no error. Only a string |
| 646 | +makes a new error: an `ERROR` constant whose value is another `ERROR` |
| 647 | +constant is that same error, so `const Short*: ERROR = PictBase.Short;` |
| 648 | +passes on an error of another module, and `Short = PictBase.Short` |
| 649 | +holds. |
| 640 | 650 | |
| 641 | 651 | Errors compare with `=` and `#` only, by which declaration made them, |
| 642 | 652 | never by their message. `MSG(e)` is the message, a `[]U8`; `MSG(nil)` |
| | @@ -974,6 +984,7 @@ |
| 974 | 984 | | `NEW(p, a)` | sets `p: ^T` to a fresh, zeroed `T` from the allocator `a: ^Mem.Allocator`, or to `nil` if `a` has no room | |
| 975 | 985 | | `MSG(e)` | the message of the error `e`, a `[]U8` | |
| 976 | 986 | | `COPY(d, s)` | copies the elements of `s` to the start of `d`, both arrays or slices of one type `T`; `LEN(s)` must be at most `LEN(d)` | |
| 987 | +| `FILL(d, x)` | sets every element of `d`, an array or a slice of elements of type `T`, to `x`, a value of `T` | |
| 977 | 988 | | `SYSCALL(n, x1, ..., x6)` | Linux system call `n` with up to six arguments, each a pointer or an integer no wider than `INT`; the raw result, an `INT` (a negative number is `-errno`) | |
| 978 | 989 | | `INC(v)`, `INC(v, k)` | adds 1, or `k`, to the integer variable `v`; it wraps, like `+` | |
| 979 | 990 | | `DEC(v)`, `DEC(v, k)` | subtracts 1, or `k`, from `v` | |
| | @@ -1054,6 +1065,17 @@ |
| 1054 | 1065 | checked as a slice is: past `LEN(d)`, it stops the program, unless the |
| 1055 | 1066 | module says `check off;`. |
| 1056 | 1067 | |
| 1068 | +`FILL` is a statement too. `d` is written as `COPY`'s destination is, |
| 1069 | +and `x` is assigned to each element as by `:=`: |
| 1070 | + |
| 1071 | +``` |
| 1072 | +FILL(row[a..b], U32(bg)); (* a row of pixels *) |
| 1073 | +FILL(window, 0.0); (* window: [576]F32 *) |
| 1074 | +``` |
| 1075 | + |
| 1076 | +It is no wipe: it may be left out when nothing reads what it wrote, as |
| 1077 | +any write may (section 7.6). |
| 1078 | + |
| 1057 | 1079 | `INC` and `DEC` evaluate `v` once, so `INC(a[f(i)])` calls `f` once. They |
| 1058 | 1080 | read `v` and then write it: two accesses, even through a `^VOLATILE` |
| 1059 | 1081 | pointer, and not atomic; `XADD` is the atomic one. |
| | @@ -1174,7 +1196,7 @@ |
| 1174 | 1196 | | "continue" |
| 1175 | 1197 | | "defer" Statement |
| 1176 | 1198 | | "try" Designator . |
| 1177 | | -Arm = ( ident [ "(" ident { "," ident } ")" ] |
| 1199 | +Arm = ( ident { "." ident } [ "(" ident { "," ident } ")" ] |
| 1178 | 1200 | | Label { "," Label } | "else" ) ":" Statements . |
| 1179 | 1201 | Label = Expr [ ".." Expr ] . |
| 1180 | 1202 | Target = Designator | "_" . |
| | @@ -1262,9 +1284,10 @@ |
| 1262 | 1284 | end; |
| 1263 | 1285 | ``` |
| 1264 | 1286 | |
| 1265 | | -A slice of a `var` parameter, of a module variable, or of what a |
| 1266 | | -pointer points at may be returned: none of them is this procedure's |
| 1267 | | -frame. A slice of a frame that leaves it some other way isn't caught, |
| 1287 | +A slice of a `var` or `const` parameter, of a module variable, or of |
| 1288 | +what a pointer points at may be returned: none of them is this |
| 1289 | +procedure's frame. For a `const` parameter given a temporary, the slice |
| 1290 | +lives to the end of the caller's statement (section 8). A slice of a frame that leaves it some other way isn't caught, |
| 1268 | 1291 | and is the exception of section 10: one held in a local slice |
| 1269 | 1292 | variable, or in a record, that is returned; one stored in a module |
| 1270 | 1293 | variable or through a pointer; and one that came back from a call, as |
| | @@ -1305,6 +1328,11 @@ |
| 1305 | 1328 | arm. A variant's arm names one case: the fields it may name belong to |
| 1306 | 1329 | that case alone. |
| 1307 | 1330 | |
| 1331 | +An arm on an enumeration or a variant names its case alone or as it is |
| 1332 | +written anywhere else, with its type, its module, or both (`done`, |
| 1333 | +`Kind.done`, `Xml.done`, `Xml.Kind.done`), and a qualified name must be |
| 1334 | +a case of the matched type. |
| 1335 | + |
| 1308 | 1336 | `match` on an integer runs the arm whose labels hold its value: |
| 1309 | 1337 | |
| 1310 | 1338 | ``` |
| | @@ -1843,6 +1871,14 @@ |
| 1843 | 1871 | what a program that fails says on standard error: conformance is |
| 1844 | 1872 | judged by a program's standard output and exit status, never by its |
| 1845 | 1873 | standard error. |
| 1874 | +- **Copies.** A procedure's frame may hold copies of its variables |
| 1875 | + that the program can't name: registers saved to it, temporaries of |
| 1876 | + its statements, its value parameters, and arrays its calls return. |
| 1877 | + An implementation may leave them where they are when the procedure |
| 1878 | + returns, until the stack is used again. A wipe (section 7.6) reaches |
| 1879 | + only the variables it is given. A secret is best kept in one |
| 1880 | + variable, passed by `var` or `const` or by pointer, never by value, |
| 1881 | + and wiped there. |
| 1846 | 1882 | - **The command line.** How the compiler is run, its options, and |
| 1847 | 1883 | where its library lives (sections 1 and 3). |
| 1848 | 1884 | |
| | @@ -1942,7 +1978,7 @@ |
| 1942 | 1978 | | "continue" |
| 1943 | 1979 | | "defer" Statement |
| 1944 | 1980 | | "try" Designator . |
| 1945 | | -Arm = ( ident [ "(" ident { "," ident } ")" ] |
| 1981 | +Arm = ( ident { "." ident } [ "(" ident { "," ident } ")" ] |
| 1946 | 1982 | | Label { "," Label } | "else" ) ":" Statements . |
| 1947 | 1983 | Label = Expr [ ".." Expr ] . |
| 1948 | 1984 | Target = Designator | "_" . |