From 51a90a630cbd3b2e3b4634d72b3568edcc476dc4 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sat, 17 Oct 2026 09:04:26 +0000 Subject: [PATCH] Report 2026-10.33 is followed; the tutorial, STANDARDS.md and CLAUDE.md say so The compiler follows report 2026-10.33: the version line that let it lag goes, and raz --version says 10.33. The tutorial's section 4 shows a const parameter beside a var one, with a program make check runs; section 12 takes its shapes from a constant of variants; section 16 gives C's and Pascal's const and var their raz forms. STANDARDS.md's "library until a thaw" goes, the library having come to it. CLAUDE.md records the thaw, its readings, and the next step: v0.20.0, built by v0.19.0, drops the Pascal seed. The report grows by about one page, to 32 of 40 (counted by words; this container's pandoc can't make the PDF). --- diff --git a/CLAUDE.md b/CLAUDE.md index 705aeea..de92fc7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -83,7 +83,16 @@ ## Where things stand -v0.18.1, report 2026-10.32, is the latest release: v0.18.0's thaw (a +v0.19.0, report 2026-10.33, is the latest release: the ninth thaw, a +`const` parameter, a variant in a constant, and the library taking +`var`, `const` or a value where it took a pointer (`Arena`, `Buf`, +`Files`, `Fmt`, `List`, `Lock`, `Map`, `Opt`, `Str`, `Sys`'s +directories, `Thread`'s `Mutex`, `Vec`; and `tools/Scan.raz`), which +breaks calls written with `ADR`; the compiler's message names the +mending. Next: v0.20.0, built by v0.19.0, drops the Pascal seed; then +`Buf.bytes`, `Sys.entryKind` and `src/`'s records only read take +`const`. +v0.18.1, report 2026-10.32, before it: v0.18.0's thaw (a constant typed `[]T` may be `[]`, the empty slice, as may a constant's slice part), with `Vec.pop` and `Sys.Info.links`, and a constant's slice part naming another module's array constant, a defect mended; @@ -97,7 +106,7 @@ compiler in raz, built by itself (Self, done); the seed in `seed/` is frozen, and v0.9.1 was the last release it built. The compiler takes 1.4 times the Pascal one's time; `make kernels` measures `test/bench` -against FPC `-O2`. Next: what the owner chooses. What +against FPC `-O2`. What each version of the report changed is in `doc/report-history.md`, and what each step did is in git; don't repeat it here. @@ -111,7 +120,8 @@ for it. A wish for more, the owner's or yours, goes in `PROPOSALS.md`, for a later thaw; it isn't built. Thaws happen only by the owner's word (v0.6.0, reports 2026-10.13 to 10.23, 10.25 for strings, -and 10.26 for `INT` and views). +10.26 for `INT` and views, and 10.33 for `const` parameters, variants +in constants and the library by `var`). **The reserved words and the module names are settled.** That a word is reserved, however common (`code`, `to`, `packed`, `forward`, `set`, @@ -274,3 +284,20 @@ generic module's parameters; a generic module is warned of in its first instance only. Assigning a variable whole (`x :=`, `a, b :=`) doesn't read it; anything else does. +- A `const` parameter (report 2026-10.33) is a `var` one never changed: + passed by address always, its `Obj` `isVar` and `isConst`, an item of + it `ro`. A slice of its array may be made, to read; through it the + caller's array may be written, which the report says (8). An argument + that isn't a variable, or is a packed field, a view or volatile, goes + in a temporary of the statement. `match` on a `const` parameter or a + constant gives names that are only read. Procedure types compare + `const` as `var`. It is unused if never read, as a value parameter. +- A variant in a constant must be typed; `const D = dot;` is an error + that says to write its type. Its case is read by name (`constCase`). +- The library takes a `var` for what it changes and `const` for a record + or array it only reads (report 2026-10.33), but in the modules the + seed compiles (`Buf`, `Sys`, ...), which take a value or `var` there + until the seed is gone. Measured: a `Map` passed as a value, four + words, made a loop of `get` half again as slow as `const`. A trace + shows no `var` or `const` parameter. `Fmt`'s `format` and `put` keep + `^Buf.Buf`, since `nil` is standard output there. diff --git a/README.md b/README.md index b763b7a..8bae23d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ $ examples/Hello hello, world -The compiler is about 10,700 lines of raz, written in itself: one pass, no +The compiler is about 11,400 lines of raz, written in itself: one pass, no intermediate form, no optimizer. It writes x86-64 machine code and the ELF executable itself, with no assembler or linker, and compiles about 500,000 lines a second. diff --git a/STANDARDS.md b/STANDARDS.md index c403944..4d6100f 100644 --- a/STANDARDS.md +++ b/STANDARDS.md @@ -3,8 +3,8 @@ How raz is written here: in `src/`, `lib/`, `tools/` and `examples/`, and in the programs and libraries that use them (rpg, rsqlite, rmacs, ravite, ...). The report says what a program may do; this says what we -do. New code keeps to it; old code comes to it when it is next changed, -or, for the library's interfaces, at a thaw (`PROPOSALS.md`). +do. New code keeps to it; old code comes to it when it is next changed. +The library came to it in report 2026-10.33. ## Parameters: a value, `const`, `var`, or a pointer @@ -51,11 +51,3 @@ Anything else that takes `^T` and neither keeps it nor needs one of the above is a mistake, and its callers' `ADR`s are noise. - -## The library until a thaw - -The library's interfaces mostly take `^T` (`Buf`, `Vec`, `Map`, -`List`, `Lock`, `Opt`, ...), though none keeps what it is given. They -can't change while the freeze holds, since every caller would break; -`PROPOSALS.md` lists them for the next thaw. Until then a program -calls them with `ADR`, and its own procedures keep to this file. diff --git a/doc/raz-lib.md b/doc/raz-lib.md index f22c1a1..e155e1e 100644 --- a/doc/raz-lib.md +++ b/doc/raz-lib.md @@ -956,7 +956,7 @@ number from 1 to 600, not '0'`; for a number with no top, given the largest `I64` for `hi`, `--jobs wants a number from 1 up, not '0'`. `refuse` refuses a value the program reads itself, as `number` refuses one, naming the option as -the user wrote it, `-b` or `--bar`: `Opt.refuse(ADR(p), "a label with +the user wrote it, `-b` or `--bar`: `Opt.refuse(p, "a label with no spaces")` writes `keep: -b wants a label with no spaces, not 'a b'`, and the synopsis lines. `p.spelt` is that spelling, for the program's own sentences. `fail` writes the program's own diff --git a/doc/raz-tutorial.7 b/doc/raz-tutorial.7 index 7818a88..021d280 100644 --- a/doc/raz-tutorial.7 +++ b/doc/raz-tutorial.7 @@ -323,6 +323,53 @@ does, is warned of; .Cm "_ := Sys.write(fd, s);" says it is meant. +.Pp +A record or an array that a procedure only reads goes as +.Cm const : +the caller's variable itself, read in place with nothing copied, which +the procedure can't change. +.Bd -literal -offset indent +module Grids; +import Out; + +type Grid = record cells: [64]INT; w, h: INT; end; + +proc fill(var g: Grid; v: INT); (* changes g *) +var i: INT; +begin + for i := 0 to g.w * g.h - 1 do g.cells[i] := v; end; +end; + +proc sum(const g: Grid): INT; (* reads g in place *) +var i, s: INT; +begin + s := 0; + for i := 0 to g.w * g.h - 1 do s := s + g.cells[i]; end; + return s; +end; + +proc main*; +var g: Grid; +begin + g.w := 4; + g.h := 2; + fill(g, 3); + Out.int(sum(g)); Out.ln; +end; + +end Grids. +.Ed +.Bd -literal -offset indent +24 +.Ed +.Pp +So a heading says what a procedure does with what it is given: a value +for a single value or a slice it reads, +.Cm const +for a record or an array it reads, +.Cm var +for what it changes, and a pointer only for what it keeps past the +call. .Sh 5. ARRAYS, SLICES AND STRINGS .Bd -literal -offset indent module Slices; @@ -956,7 +1003,9 @@ dot; end; -proc area(s: Shape): F64; +const Some: []Shape = [circle(1.0), rect(2.0, 3.5), dot]; + +proc area(const s: Shape): F64; begin match s of | circle(r): return Math.pi * r * r; @@ -985,11 +1034,10 @@ end; proc main*; -var shapes: [3]Shape; i: INT; warm: Colours; c: Colour; +var i: INT; warm: Colours; c: Colour; begin - shapes := [circle(1.0), rect(2.0, 3.5), dot]; - for i := 0 to 2 do - Fmt.print("{}\en", [Fmt.real(area(shapes[i]), 2)]); + for i := 0 to LEN(Some) - 1 do + Fmt.print("{}\en", [Fmt.real(area(Some[i]), 2)]); end; Fmt.print("{} {} {}\en", [Fmt.str(kind('7')), Fmt.str(kind('x')), Fmt.str(kind('+'))]); @@ -1031,6 +1079,11 @@ .Cm match is the only way to read them: it runs the arm of the case the variant holds, naming its fields. +A constant may hold variants, each a case built from constants, as +.Cm Some +does; a +.Cm match +on one names fields that are only read. Every case has an arm, unless an .Cm "| else:" comes last. @@ -1269,6 +1322,8 @@ .It "malloc(sizeof *p)" Ta "new(p)" Ta "NEW(p, Heap.heap)" .It "free(p)" Ta "dispose(p)" Ta "Mem.free(Heap.heap, ^U8(p))" .It "int f(int *out)" Ta "function f(var x)" Ta "proc f: (INT, INT);" +.It "void f(T *p)" Ta "procedure f(var p: T)" Ta "proc f(var p: T);" +.It "f(const T *p)" Ta "procedure f(const p: T)" Ta "proc f(const p: T);" .It "return -1; errno" Ta "exceptions" Ta "return 0, NotFound;" .It "(void)f(x);" Ta "f(x);" Ta "_ := f(x);" .It "goto cleanup;" Ta "try ... finally" Ta "defer close(fd);" diff --git a/doc/raz.md b/doc/raz.md index 36eb44d..7111225 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -48,8 +48,6 @@ instead (the library volume), which breaks a program that calls them with `ADR`. -The compiler follows version 2026-10.32 until the library has moved. - 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 written for it. What anyone wishes it had waits on a list, for a later diff --git a/src/Raz.raz b/src/Raz.raz index 5c7405a..ec3d496 100644 --- a/src/Raz.raz +++ b/src/Raz.raz @@ -31,7 +31,7 @@ import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Parse, Link, Elf; const - Report = "2026-10.32"; (* the version of doc/raz.md it follows *) + Report = "2026-10.33"; (* the version of doc/raz.md it follows *) MemfdCreate = 319; (* the system call *) MfdCloexec = 1; (* an ELF still executes: the kernel opens it first *) Execve = 59;