raz / commit caca71d3

commit
caca71d32db21c4de324e0eb151691ca3a1998ed
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
1d7fac9c
The report, 2026-10.3: operators, inline =, generics on first use

and, or and not are for BOOLs and bind below the relations; &, | and ~
are the operators on bits, and xor is for integers only, as in Go.
Arrays and slices of integers, BOOLs, enumerations, sets and pointers
compare with =, by code where it stands, not a call into Rt. A generic
instance is made where it is first used, so its arguments may name
types declared after the imports. With return f(x), approved by the
owner.

PLAN.md: stage 6, the steps that make them, none started.

patch · log

2 files changed, +109 -22

PLAN.md (history) modified +51 -0

@@ -409,3 +409,54 @@
409409 - [x] 41. Once the owner approves step 34: `Sys` gains it, on Linux
410410 and over C, with tests; ravite's `Tty` goes. `make check` runs
411411 ravite's sessions over both.
412+
413+Stage 6: the language of report 2026-10.3
414+
415+The owner's choices after stage 5, written into the report first:
416+results passed on by `return`; `and`, `or` and `not` for `BOOL`s only,
417+binding below the relations, and `&`, `|`, `~` for bits, as in Go; `=`
418+on arrays and slices of plain elements, compiled where it stands
419+rather than called in `Rt`, so that no syntax runs hidden library
420+code; and generic instances made where they are first used, so that
421+their arguments may name types declared after the imports. Not
422+started: each step waits for the owner's word, and stage 4's open
423+steps come first unless the owner says otherwise.
424+
425+- [x] 42. The report, version 2026-10.3: sections 2, 3, 6, 6.5, 7.3, 8
426+ and 11, and the list of versions. Approved before any code.
427+- [ ] 43. `return f(x);`: the call writes its results through the
428+ procedure's own hidden pointer, the one its caller gave it. The
429+ results must be the procedure's, type for type; `test/err` for
430+ a mismatch, `test/run` for one, two and three results, through
431+ two levels of calls.
432+- [ ] 44. `=` and `#` inline: the lengths compared, then, if equal,
433+ the bytes, `LEN * SIZE(T)` of them, with `repe cmpsb`; for
434+ strings and for arrays and slices of integers, `BOOL`s,
435+ enumerations, sets and pointers, any mix of `[n]T` and `[]T`.
436+ `Rt.eq` goes, and CLAUDE.md's note that the compiler finds it by
437+ name. Tests: equal, of different lengths, empty, a string
438+ literal against an array, and in `test/err` arrays of `F64`, of
439+ records, and of two element types.
440+- [ ] 45. Operators: `&` and `~` in the scanner, `|` an operator where
441+ an operand came before it; the parser's levels, `or` over `and`
442+ over the relations; `and`, `or`, `not` refused on integers and
443+ `&`, `|`, `xor`, `~` on `BOOL`s, each with a message that names
444+ the other. Every raz source moves to the new operators: `lib/`,
445+ `tools/` (Pretty spaces `&` and `|` as it spaces `+`, and
446+ leaves a match arm's `|` where it is), `examples/`, `test/`, the
447+ report's examples, and `test/genbench.py`; each `and` or `or`
448+ between relations is checked by hand, since its meaning may
449+ change without an error. `make bench` must still pass.
450+- [ ] 46. Generic instances on first use: the import keeps its
451+ arguments unresolved, and the instance is made, and its body
452+ queued to run before the importer's, the first time the import's
453+ name is used; an argument not declared by then is an error at
454+ the import. Tests: a type declared after the import, two imports
455+ sharing one instance, an import never used (no instance), and
456+ the error.
457+- [ ] 47. `doc/compiler.md` (its table and routine names),
458+ `README.md`, CLAUDE.md's readings, the report's first line and
459+ the compiler's to 2026-10.3; `make loc` within 6,000 and 10%,
460+ `make bench` at 400,000 lines a second. Then the editors, rmacs
461+ and ravite, move their pin to this raz, in their own
462+ repositories, with their sources moved to the new operators.

doc/raz.md (history) modified +58 -22

@@ -88,8 +88,11 @@
8888 **Operators and delimiters:**
8989
9090 ```
91-+ - * / = # < <= > >= := : ; , . .. ... ( ) [ ] { } ^ |
91++ - * / & | ~ = # < <= > >= := : ; , . .. ... ( ) [ ] { } ^
9292 ```
93+
94+`|` is also what starts an arm of `match` (section 7.4); an arm comes
95+where a statement could, never after an operand, so the two don't mix.
9396
9497 ## 3. Modules
9598
@@ -130,7 +133,20 @@
130133 share one instance. Since every instance is checked on its own, an
131134 operation the argument type doesn't support (adding two records, say)
132135 is reported as an error in that instance.
136+
137+An instance is made where its module is first used, not at the
138+import: so the arguments may name types the importing module declares
139+after its imports, as long as they are declared before that first
140+use.
133141
142+```
143+import Table := Map([]U8, Colour, Str.hash, Str.eq);
144+
145+type Colour = (red, green, blue);
146+
147+var names: Table.Map; (* the instance is made here *)
148+```
149+
134150 What a generic module needs to do with its types, beyond moving them
135151 about, it is given as procedures, after the types:
136152
@@ -389,14 +405,16 @@
389405 ## 6. Expressions
390406
391407 ```
392-Expr = SimpleExpr [ Relation SimpleExpr ] .
393-Relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "in" .
408+Expr = Conjunct { "or" Conjunct } .
409+Conjunct = Relation { "and" Relation } .
410+Relation = SimpleExpr [ RelOp SimpleExpr ] .
411+RelOp = "=" | "#" | "<" | "<=" | ">" | ">=" | "in" .
394412 SimpleExpr = [ "-" ] Term { AddOp Term } .
395-AddOp = "+" | "-" | "or" | "xor" .
413+AddOp = "+" | "-" | "|" | "xor" .
396414 Term = Factor { MulOp Factor } .
397-MulOp = "*" | "/" | "div" | "mod" | "and" | "shl" | "shr" .
415+MulOp = "*" | "/" | "div" | "mod" | "&" | "shl" | "shr" .
398416 Factor = number | char | string | Designator | "(" Expr ")"
399- | "not" Factor
417+ | "not" Factor | "~" Factor
400418 | "[" [ Expr { "," Expr } ] "]"
401419 | "{" [ Element { "," Element } ] "}"
402420 | "^" [ "VOLATILE" ] Type "(" Expr ")" .
@@ -406,14 +424,19 @@
406424 | "(" [ Expr { "," Expr } ] ")" .
407425 ```
408426
409-The operators bind in the order of the grammar: `not` most tightly,
410-then the multiplying operators, then the adding ones, then the
411-relations. So `a + b * c = d` is `(a + (b * c)) = d`. A unary minus
412-applies to the first term: `-a * b` is `-(a * b)`.
427+The operators bind in the order of the grammar: `not` and `~` most
428+tightly, then the multiplying operators, then the adding ones, then
429+the relations, then `and`, then `or`. So `a + b * c = d` is
430+`(a + (b * c)) = d`, `x & 0FH = 0` is `(x & 0FH) = 0`, and
431+`i < n and a[i] # 0 or done` is `((i < n) and (a[i] # 0)) or done`. A
432+unary minus applies to the first term: `-a * b` is `-(a * b)`.
413433
434+`and`, `or` and `not` are for `BOOL`s only; `&`, `|`, `xor` and `~`
435+are for integers only.
436+
414437 ### 6.1 Integers
415438
416-Both operands of `+ - * div mod and or xor` have the same integer
439+Both operands of `+ - * div mod & | xor` have the same integer
417440 type, or one is an untyped constant that takes the other's type. The
418441 result has that type and wraps around at its width: in `U8`,
419442 `200 + 100` is `44`.
@@ -422,17 +445,16 @@
422445 in C: `-7 div 2` is `-3`, `-7 mod 2` is `-1`. Dividing by zero, and
423446 dividing the smallest `I64` by `-1`, stop the program (`SIGFPE`).
424447
425-`and`, `or`, `xor` and `not` work on every bit. `x shl n` and
426-`x shr n` shift by `n and 63`; `shr` brings in copies of the sign bit
448+`&` (and), `|` (or), `xor` and `~` (not) work on every bit. `x shl n`
449+and `x shr n` shift by `n & 63`; `shr` brings in copies of the sign bit
427450 for signed types and zeros for unsigned ones.
428451
429452 Relations compare as signed or unsigned according to the type.
430453
431454 ### 6.2 Booleans
432455
433-`and` and `or` on `BOOL` evaluate their right operand only when it
434-decides the result. `not` negates, `xor` is "different", and `=` and
435-`#` compare.
456+`and` and `or` evaluate their right operand only when it decides the
457+result. `not` negates, and `=` and `#` compare; `#` is "different".
436458
437459 ### 6.3 Reals
438460
@@ -480,10 +502,17 @@
480502 Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.int(m)]);
481503 ```
482504
483-**Strings compare.** Two operands that are each a `[]U8`, a `[n]U8` or
484-a string literal are `=` when they have the same length and the same
485-bytes, and `#` otherwise. Other arrays and slices, records and variants
486-can't be compared; write a loop. Ordering strings is the library's
505+**Arrays and strings compare.** Two operands that are each a `[]T` or
506+a `[n]T`, of the same element type `T`, are `=` when they have the
507+same length and the same elements, and `#` otherwise, where `T` is an
508+integer type, `BOOL`, an enumeration, a set or a pointer type. A string
509+literal compares as a `[]U8`. The comparison is code of its own where
510+it stands, a check of the lengths and then of the bytes, not a call.
511+
512+Arrays of reals don't compare this way, since `-0.0 = 0.0` and a NaN
513+is equal to nothing, though their bytes say otherwise; nor do arrays
514+of records, variants or procedures, nor records and variants
515+themselves. Write a loop. Ordering strings is the library's
487516 `Str.cmp`.
488517
489518 ### 6.6 Enumerations and sets
@@ -876,7 +905,7 @@
876905
877906 | Module | What |
878907 |---|---|
879-| `Rt` | ending the program, `exit` and `atExit`; `stop`, which ends it with a message; what the compiler's checks call when they fail; string comparison |
908+| `Rt` | ending the program, `exit` and `atExit`; `stop`, which ends it with a message; what the compiler's checks call when they fail |
880909 | `Sys` | system calls: `openRead`, `create`, `read`, `write`, `close`, `mmap`, `munmap`, `isTerminal`, `yield`, `exit`; files and directories, `rename`, `remove`, `makeDir`, `info`, `openDir`, `nextEntry`, `closeDir`; the terminal, `rawMode`, `restoreMode`, `termSize`, `ready`; and `env` and `workDir`. One file per target, and `Sys.raz` over the C library for the others |
881910 | `Out` | writing text and numbers to standard output, buffered; safe to call from several threads |
882911 | `C` | the parts of the C library the others use, and `printf`, `fflush`, `stdout`, `pthread_create`; a program that imports it uses C |
@@ -977,4 +1006,11 @@
9771006 - **2026-10.2.** `Sys` gains files and directories, the terminal, and
9781007 the environment (section 11).
9791008 - **2026-10.3.** `return f(x);` passes on the several results of `f`
980- (sections 7.3 and 8).
1009+ (sections 7.3 and 8). `and`, `or` and `not` are for `BOOL`s, and
1010+ bind below the relations; `&`, `|` and `~` are the operators on bits,
1011+ and `xor` is for integers only (sections 2 and 6). Arrays and slices
1012+ of integers, `BOOL`s, enumerations, sets and pointers compare with
1013+ `=`, by code where the comparison stands, not by a call into `Rt`
1014+ (section 6.5). A generic module's instance is made where it is first
1015+ used, so its arguments may name types declared after the imports
1016+ (section 3).