raz / commit 4b40e972

commit
4b40e9726af6d1d8b5f8029b20241ee56b7e486b
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
bfb011ac
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

patch · log

3 files changed, +64 -14

doc/raz.7 (history) modified +8 -0

@@ -472,6 +472,12 @@
472472 as one block, even if they overlap; past
473473 .Fn LEN d ,
474474 a failed check.
475+.It Fn FILL d x
476+Every element of the array or slice
477+.Ar d
478+set to
479+.Ar x ,
480+a value of its type.
475481 .It Fn INC v k , Fn DEC v k
476482 .Ar v
477483 plus or minus
@@ -558,6 +564,8 @@
558564 which any
559565 .Cm match
560566 may end with.
567+An imported case may be written qualified,
568+.Cm "| Xml.done:" .
561569 .It Cm return
562570 With the results, several separated by commas, or
563571 .Cm "return f(x)" ,

doc/raz.md (history) modified +48 -12

@@ -53,9 +53,12 @@
5353 twelfth: `MIN(T)` and `MAX(T)`, the limits of an integer type, and
5454 `CLZ`, `CTZ` and `POPCOUNT`, which count bits (sections 6.1 and 6.8);
5555 `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.
5962
6063 The language is frozen, softly, from this version on: it changes only
6164 to mend a defect, and its library grows only by what breaks no program
@@ -405,9 +408,11 @@
405408 literal (section 6.5) of constants, that of a variant one a case built
406409 from constants, as a program builds one (section 5.6). Its elements
407410 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
411416 type: `const D = dot;` is an error, `const D: Shape = dot;` isn't.
412417
413418 ```
@@ -415,6 +420,7 @@
415420 type Rule = record class: []U8; tag: INT; float: BOOL; end;
416421 const Rules: [2]Rule = [{class: "firefox", tag: 2}, {class: "mpv", float: true}];
417422 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 *)
418424 ...
419425 p := Primes[i];
420426 ```
@@ -636,7 +642,11 @@
636642 by a constant declared as above, and each such declaration makes an
637643 error different from every other, whatever its message: two modules that
638644 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.
640650
641651 Errors compare with `=` and `#` only, by which declaration made them,
642652 never by their message. `MSG(e)` is the message, a `[]U8`; `MSG(nil)`
@@ -974,6 +984,7 @@
974984 | `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 |
975985 | `MSG(e)` | the message of the error `e`, a `[]U8` |
976986 | `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` |
977988 | `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`) |
978989 | `INC(v)`, `INC(v, k)` | adds 1, or `k`, to the integer variable `v`; it wraps, like `+` |
979990 | `DEC(v)`, `DEC(v, k)` | subtracts 1, or `k`, from `v` |
@@ -1054,6 +1065,17 @@
10541065 checked as a slice is: past `LEN(d)`, it stops the program, unless the
10551066 module says `check off;`.
10561067
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+
10571079 `INC` and `DEC` evaluate `v` once, so `INC(a[f(i)])` calls `f` once. They
10581080 read `v` and then write it: two accesses, even through a `^VOLATILE`
10591081 pointer, and not atomic; `XADD` is the atomic one.
@@ -1174,7 +1196,7 @@
11741196 | "continue"
11751197 | "defer" Statement
11761198 | "try" Designator .
1177-Arm = ( ident [ "(" ident { "," ident } ")" ]
1199+Arm = ( ident { "." ident } [ "(" ident { "," ident } ")" ]
11781200 | Label { "," Label } | "else" ) ":" Statements .
11791201 Label = Expr [ ".." Expr ] .
11801202 Target = Designator | "_" .
@@ -1262,9 +1284,10 @@
12621284 end;
12631285 ```
12641286
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,
12681291 and is the exception of section 10: one held in a local slice
12691292 variable, or in a record, that is returned; one stored in a module
12701293 variable or through a pointer; and one that came back from a call, as
@@ -1305,6 +1328,11 @@
13051328 arm. A variant's arm names one case: the fields it may name belong to
13061329 that case alone.
13071330
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+
13081336 `match` on an integer runs the arm whose labels hold its value:
13091337
13101338 ```
@@ -1843,6 +1871,14 @@
18431871 what a program that fails says on standard error: conformance is
18441872 judged by a program's standard output and exit status, never by its
18451873 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.
18461882 - **The command line.** How the compiler is run, its options, and
18471883 where its library lives (sections 1 and 3).
18481884
@@ -1942,7 +1978,7 @@
19421978 | "continue"
19431979 | "defer" Statement
19441980 | "try" Designator .
1945-Arm = ( ident [ "(" ident { "," ident } ")" ]
1981+Arm = ( ident { "." ident } [ "(" ident { "," ident } ")" ]
19461982 | Label { "," Label } | "else" ) ":" Statements .
19471983 Label = Expr [ ".." Expr ] .
19481984 Target = Designator | "_" .

doc/report-history.md (history) modified +8 -2

@@ -246,5 +246,11 @@
246246 `BOOL`. `OFFSET(T, f)` and `SIZE(T.f)` are the offset of a field in
247247 a record type and its size, untyped constants (sections 4 and 6.8);
248248 and `BYTES(x)` is the bytes of a variable or a slice as a `[]U8`,
249- of a type a view may take (sections 6.8, 6.9 and 7.3). It breaks no
250- program.
249+ of a type a view may take (sections 6.8, 6.9 and 7.3). `FILL(d, x)`
250+ sets every element of an array or a slice to `x` (section 6.8). An
251+ arm of a `match` may name an imported case as it is written
252+ elsewhere, `| Xml.done:` (section 7.4). A constant's slice part may
253+ be an array literal, `[[1, 2], [3]]`, and an `ERROR` constant may be
254+ another `ERROR` constant, the same error (sections 4 and 5.8). A
255+ slice of a `const` parameter may be returned (section 7.3). Appendix
256+ A says what a wipe can't reach. It breaks no program.