From 4b40e9726af6d1d8b5f8029b20241ee56b7e486b Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 23 Oct 2026 12:46:41 +0100 Subject: [PATCH] raz.md: FILL, a qualified case in an arm, slice and ERROR constants, a const parameter's slice returned, and what a wipe can't reach --- diff --git a/doc/raz.7 b/doc/raz.7 index 2ca973f..b54927b 100644 --- a/doc/raz.7 +++ b/doc/raz.7 @@ -472,6 +472,12 @@ as one block, even if they overlap; past .Fn LEN d , a failed check. +.It Fn FILL d x +Every element of the array or slice +.Ar d +set to +.Ar x , +a value of its type. .It Fn INC v k , Fn DEC v k .Ar v plus or minus @@ -558,6 +564,8 @@ which any .Cm match may end with. +An imported case may be written qualified, +.Cm "| Xml.done:" . .It Cm return With the results, several separated by commas, or .Cm "return f(x)" , diff --git a/doc/raz.md b/doc/raz.md index bf4cd84..78b1331 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -53,9 +53,12 @@ twelfth: `MIN(T)` and `MAX(T)`, the limits of an integer type, and `CLZ`, `CTZ` and `POPCOUNT`, which count bits (sections 6.1 and 6.8); `INT(b)`, a `BOOL` as an integer (section 6.7); `OFFSET(T, f)` and -`SIZE(T.f)`, where a field lies and how big it is; and `BYTES(x)`, the -bytes of a variable or a slice (sections 4 and 6.8); it breaks no -program. +`SIZE(T.f)`, where a field lies and how big it is; `BYTES(x)`, the +bytes of a variable or a slice (sections 4 and 6.8); `FILL(d, x)`, an +array or a slice set to one value (section 6.8); a qualified case in a +`match` arm (section 7.4); a slice part written as a literal, and an +`ERROR` constant named by another (sections 4 and 5.8); and a `const` +parameter's slice returned (section 7.3); it breaks no program. The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program @@ -405,9 +408,11 @@ literal (section 6.5) of constants, that of a variant one a case built from constants, as a program builds one (section 5.6). Its elements and fields are integers, reals, `BOOL`s, enumerations, sets, `ERROR`s, -procedures, `nil`, a string for a `[]U8`, an array constant or the -empty slice for a slice of its element type, and arrays, records and -variants of these; no other pointer. A variant constant must have a +procedures, `nil`, a string for a `[]U8`, an array constant, an array +literal or the empty slice for a slice of its element type, and +arrays, records and variants of these; no other pointer. A named +constant stands for its literal wherever an array, record or variant is +wanted. A variant constant must have a type: `const D = dot;` is an error, `const D: Shape = dot;` isn't. ``` @@ -415,6 +420,7 @@ type Rule = record class: []U8; tag: INT; float: BOOL; end; const Rules: [2]Rule = [{class: "firefox", tag: 2}, {class: "mpv", float: true}]; const Shapes: []Shape = [circle(1.0), rect(2.0, 3.0), dot]; (* Shape of section 5.6 *) +const Rows: [][]INT = [[1, 2], [3]]; (* each row an array constant of its own *) ... p := Primes[i]; ``` @@ -636,7 +642,11 @@ by a constant declared as above, and each such declaration makes an error different from every other, whatever its message: two modules that both declare `"not found"` have two different errors. A generic module -makes its errors once per instance. `nil` is no error. +makes its errors once per instance. `nil` is no error. Only a string +makes a new error: an `ERROR` constant whose value is another `ERROR` +constant is that same error, so `const Short*: ERROR = PictBase.Short;` +passes on an error of another module, and `Short = PictBase.Short` +holds. Errors compare with `=` and `#` only, by which declaration made them, never by their message. `MSG(e)` is the message, a `[]U8`; `MSG(nil)` @@ -974,6 +984,7 @@ | `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 | | `MSG(e)` | the message of the error `e`, a `[]U8` | | `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)` | +| `FILL(d, x)` | sets every element of `d`, an array or a slice of elements of type `T`, to `x`, a value of `T` | | `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`) | | `INC(v)`, `INC(v, k)` | adds 1, or `k`, to the integer variable `v`; it wraps, like `+` | | `DEC(v)`, `DEC(v, k)` | subtracts 1, or `k`, from `v` | @@ -1054,6 +1065,17 @@ checked as a slice is: past `LEN(d)`, it stops the program, unless the module says `check off;`. +`FILL` is a statement too. `d` is written as `COPY`'s destination is, +and `x` is assigned to each element as by `:=`: + +``` +FILL(row[a..b], U32(bg)); (* a row of pixels *) +FILL(window, 0.0); (* window: [576]F32 *) +``` + +It is no wipe: it may be left out when nothing reads what it wrote, as +any write may (section 7.6). + `INC` and `DEC` evaluate `v` once, so `INC(a[f(i)])` calls `f` once. They read `v` and then write it: two accesses, even through a `^VOLATILE` pointer, and not atomic; `XADD` is the atomic one. @@ -1174,7 +1196,7 @@ | "continue" | "defer" Statement | "try" Designator . -Arm = ( ident [ "(" ident { "," ident } ")" ] +Arm = ( ident { "." ident } [ "(" ident { "," ident } ")" ] | Label { "," Label } | "else" ) ":" Statements . Label = Expr [ ".." Expr ] . Target = Designator | "_" . @@ -1262,9 +1284,10 @@ end; ``` -A slice of a `var` parameter, of a module variable, or of what a -pointer points at may be returned: none of them is this procedure's -frame. A slice of a frame that leaves it some other way isn't caught, +A slice of a `var` or `const` parameter, of a module variable, or of +what a pointer points at may be returned: none of them is this +procedure's frame. For a `const` parameter given a temporary, the slice +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, and is the exception of section 10: one held in a local slice variable, or in a record, that is returned; one stored in a module variable or through a pointer; and one that came back from a call, as @@ -1305,6 +1328,11 @@ arm. A variant's arm names one case: the fields it may name belong to that case alone. +An arm on an enumeration or a variant names its case alone or as it is +written anywhere else, with its type, its module, or both (`done`, +`Kind.done`, `Xml.done`, `Xml.Kind.done`), and a qualified name must be +a case of the matched type. + `match` on an integer runs the arm whose labels hold its value: ``` @@ -1843,6 +1871,14 @@ what a program that fails says on standard error: conformance is judged by a program's standard output and exit status, never by its standard error. +- **Copies.** A procedure's frame may hold copies of its variables + that the program can't name: registers saved to it, temporaries of + its statements, its value parameters, and arrays its calls return. + An implementation may leave them where they are when the procedure + returns, until the stack is used again. A wipe (section 7.6) reaches + only the variables it is given. A secret is best kept in one + variable, passed by `var` or `const` or by pointer, never by value, + and wiped there. - **The command line.** How the compiler is run, its options, and where its library lives (sections 1 and 3). @@ -1942,7 +1978,7 @@ | "continue" | "defer" Statement | "try" Designator . -Arm = ( ident [ "(" ident { "," ident } ")" ] +Arm = ( ident { "." ident } [ "(" ident { "," ident } ")" ] | Label { "," Label } | "else" ) ":" Statements . Label = Expr [ ".." Expr ] . Target = Designator | "_" . diff --git a/doc/report-history.md b/doc/report-history.md index eed97ac..c302204 100644 --- a/doc/report-history.md +++ b/doc/report-history.md @@ -246,5 +246,11 @@ `BOOL`. `OFFSET(T, f)` and `SIZE(T.f)` are the offset of a field in a record type and its size, untyped constants (sections 4 and 6.8); and `BYTES(x)` is the bytes of a variable or a slice as a `[]U8`, - of a type a view may take (sections 6.8, 6.9 and 7.3). It breaks no - program. + of a type a view may take (sections 6.8, 6.9 and 7.3). `FILL(d, x)` + sets every element of an array or a slice to `x` (section 6.8). An + arm of a `match` may name an imported case as it is written + elsewhere, `| Xml.done:` (section 7.4). A constant's slice part may + be an array literal, `[[1, 2], [3]]`, and an `ERROR` constant may be + another `ERROR` constant, the same error (sections 4 and 5.8). A + slice of a `const` parameter may be returned (section 7.3). Appendix + A says what a wipe can't reach. It breaks no program.