raz / commit 69532854

commit
69532854a7f3eca07fa7e90c22894cab4d7af1bc
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
088a65e9
Report 2026-10.11: array constants, joined strings, match on integers

The three wishes come into the thaw, by the owner's word: a constant may
have an array type, used as a variable that can't be changed; + joins
string constants; match takes an integer, labels being constants and
inclusive ranges, else required. PLAN.md: steps 6a-c; the budget is now
a soft 8,000 lines, the compiler documented throughout (also CLAUDE.md).

patch · log

3 files changed, +79 -23

CLAUDE.md modified +4 -2

@@ -55,8 +55,10 @@
5555 `Luis <42945842+ldiaz94@users.noreply.github.com>`, unsigned
5656 (`--no-gpg-sign`), no attribution trailer. Push to `main`. No pull
5757 requests unless asked.
58-- Budget: about 6,000 lines of code (blank and comment lines not
59- counted), within 10%; at least 400,000 lines of raz a second.
58+- Budget: a soft limit of 8,000 lines of code (blank and comment lines
59+ not counted), with the compiler documented and commented throughout,
60+ most of all where it is obscure or needs a compiler writer's
61+ knowledge; at least 400,000 lines of raz a second.
6062 - Style: clarity over cleverness; each unit opens with what it is, what
6163 it depends on and what it leaves out; comments say why. Match the
6264 report's plain, short prose in documentation.

PLAN.md (history) modified +24 -12

@@ -66,8 +66,8 @@
6666
6767 ## Proposed, v0.6.0: raz to be rebuilt by anyone
6868
69-Under way: steps 1 to 4 are done, step 3 set aside since; the change
70-to steps 7 and 8, and dropping 9 and 9f, is for review. The freeze
69+Under way: steps 1 to 4 are done, step 3 set aside since. The owner
70+has agreed the rest, to step 10, to be done without stopping. The freeze
7171 doesn't hold for this work, by the owner's word.
7272
7373 **For:** a language a person alone can implement again, from the
@@ -78,9 +78,12 @@
7878 **Done when:** the report alone is enough to rebuild raz, with a
7979 conformance suite to say when a rebuild is done; the report has a
8080 system integer and optional reals, and leaves separate compilation to
81-the implementation; the parser reaches the machine only through
81+the implementation; it has array constants, joined string constants
82+and `match` on integers; the parser reaches the machine only through
8283 `gen`, the boundary a port writes again, and the back end keeps its
83-values in registers as Wirth's compilers do; `make bench` still passes; a new code budget is written down; `v0.6.0` is tagged.
84+values in registers as Wirth's compilers do; `make bench` still
85+passes; the compiler is within the new budget below; `v0.6.0` is
86+tagged.
8487
8588 **Kept out:** a second back end (aarch64 is the milestone after, to
8689 measure a port); an optimiser; separate compilation: object files, an
@@ -118,6 +121,14 @@
118121 passes, apart from this compiler's own messages.
119122 - [ ] 5. The system integer.
120123 - [ ] 6. Optional reals: a target says whether it has them.
124+- [ ] 6a. `+` joins string constants (report, section 4).
125+- [ ] 6b. Array constants: `const P: [5]I64 = [...]`, in read-only
126+ data, used as a variable that can't be changed (section 4).
127+ Done so that a string constant is the same mechanism.
128+- [ ] 6c. `match` on integers: constants and inclusive ranges as
129+ labels, no value in two, `else` required (7.4); compares and
130+ branches, no jump table. `examples/Sh.raz`'s chains of `elsif`
131+ become `match`.
121132 - [ ] 7. The parser reaches the machine only through `gen`: calls of
122133 a stack machine, with the kind of each value (a word, a 64-bit
123134 integer, an `F32`, an `F64`) and the place in the source, and no
@@ -148,20 +159,21 @@
148159 - [ ] 9e. A profiler in `Rt`: a program run with `RAZ_PROFILE` set
149160 samples where it is, and at its end says which procedures and
150161 lines took the time.
151-- [ ] 10. `doc/compiler.md`, README, the budget, the report's version
152- and the compiler's; tag `v0.6.0`.
162+- [ ] 10. `doc/compiler.md`, README, the report's version and the
163+ compiler's; tag `v0.6.0`.
153164
165+The budget, by the owner's word: a soft limit of 8,000 lines of code,
166+with the compiler documented and commented throughout, most of all
167+where it is obscure, not obvious, or needs a compiler writer's
168+knowledge.
169+
154170 ## Wishes, for a later thaw
155171
156172 What the language or the library might have, met while writing raz;
157173 none is built while the freeze holds.
158174
159-- `case` on integers and characters: `match` takes variants only, so
160- a choice among numbers is a chain of `elsif` (`examples/Sh.raz`).
161-- Constant arrays: a table of numbers is assigned in a procedure, as
162- `Math`'s bits of 2/pi are, or kept in a variable.
163-- Joining string constants, `"a" + B`: a test's expected text is
164- written out whole each time (`Opt`'s test).
175+Taken into v0.6.0: `match` on integers, array constants, joining
176+string constants.
165177
166178 ## After v0.5.0
167179

doc/raz.md (history) modified +51 -9

@@ -277,7 +277,7 @@
277277 ## 4. Declarations
278278
279279 ```
280-Declaration = "const" { IdentDef [ ":" "ERROR" ] "=" Expr ";" }
280+Declaration = "const" { IdentDef [ ":" Type ] "=" Expr ";" }
281281 | "type" { IdentDef "=" Type ";" }
282282 | "var" { IdentList ":" Type ";" }
283283 | ProcDeclaration ";"
@@ -294,17 +294,36 @@
294294 **Constants** are evaluated by the compiler. Their expressions use only
295295 literals, other constants, operators, conversions, `SIZE` and the `LEN`
296296 of arrays and strings. A constant is an integer, a real, a `BOOL`, a
297-name of an enumeration, a set, a string or an `ERROR`. A constant of an integer type wraps as the
297+name of an enumeration, a set, a string, an array or an `ERROR`. A constant of an integer type wraps as the
298298 program would: `U8(250) + 10` is 4. Dividing by zero in a constant is
299299 an error. A string constant can be indexed and sliced as an array of
300-`U8` is, and its `LEN` is its length in bytes:
300+`U8` is, and its `LEN` is its length in bytes. `+` joins two string
301+constants into one:
301302
302303 ```
303304 const Text = "the cat";
305+ Line = Text + "\n";
304306 ...
305307 w := Text[4..7]; (* "cat" *)
306308 ```
307309
310+A constant with a type is an `ERROR` (section 5.8) or an array. An
311+array constant has a type `[n]T`, where `T` is an integer type, a
312+real, `BOOL`, an enumeration or a set, and its value is an array
313+literal (section 6.5) of constants:
314+
315+```
316+const Primes: [5]I64 = [2, 3, 5, 7, 11];
317+...
318+p := Primes[i];
319+```
320+
321+It is used as a variable of that type is, but can't be changed: it can
322+be indexed and sliced, its `LEN` is `n`, it can be assigned and
323+compared, and it can be passed as a `[n]T` or a `[]T`. Its elements
324+are constant as a string's bytes are (section 5.10). An element of it
325+isn't a constant, even at a constant index.
326+
308327 **Variables** of a module live as long as the program; variables of a
309328 procedure live as long as its call. Both start at zero: every byte of
310329 them is zero. So a number starts as `0` (`0.0` for `F32` and `F64`),
@@ -781,7 +800,9 @@
781800 | "return" [ Expr { "," Expr } ]
782801 | "break"
783802 | "defer" Statement .
784-Arm = ( ident [ "(" ident { "," ident } ")" ] | "else" ) ":" Statements .
803+Arm = ( ident [ "(" ident { "," ident } ")" ]
804+ | Label { "," Label } | "else" ) ":" Statements .
805+Label = Expr [ ".." Expr ] .
785806 ```
786807
787808 Every statement ends in `;`, including the ones that end in `end` or
@@ -848,6 +869,23 @@
848869 `match` on an enumeration works the same way: each arm names one of the
849870 enumeration's names.
850871
872+`match` on an integer runs the arm whose labels hold its value:
873+
874+```
875+match ch of
876+| ' ', '\t': skip := true;
877+| '0' .. '9': digit := true;
878+| else:
879+end;
880+```
881+
882+A label is a constant, or `lo .. hi`, the constants from `lo` to `hi`,
883+both included (unlike a slice, which leaves `hi` out). Each must fit
884+the integer's type, and no value may be in two labels. An integer
885+`match` must have an `| else:` arm, which may be empty. Whether an arm
886+names a case or gives labels is set by the type matched: `| Max:` is a
887+case of a variant or an enumeration, and a constant for an integer.
888+
851889 ### 7.5 Order of evaluation
852890
853891 Operands, arguments and the designators of an assignment are evaluated
@@ -927,7 +965,7 @@
927965 ProcDeclaration = "proc" IdentDef Signature ";"
928966 ( "forward" | { LocalDeclaration } "begin" Statements "end" [ ident ]
929967 | "code" Expr { "," Expr } ) .
930-LocalDeclaration = "const" { ident [ ":" "ERROR" ] "=" Expr ";" }
968+LocalDeclaration = "const" { ident [ ":" Type ] "=" Expr ";" }
931969 | "type" { ident "=" Type ";" }
932970 | "var" { ident { "," ident } ":" Type ";" } .
933971 Signature = "(" [ Params { ";" Params } [ ";" "..." ] ] ")" [ ":" Results ]
@@ -1684,7 +1722,9 @@
16841722 `main`'s and `Rt.exit`'s among them, and `I32` for a character;
16851723 `I64` stays for what may pass an `INT` on a small target: a file's
16861724 size and position, times, and numbers read from text (section
1687- 11).
1725+ 11). An array constant has a type and is used as a variable that
1726+ can't be changed; `+` joins string constants (section 4). `match`
1727+ takes an integer, with constants and ranges as labels (7.4).
16881728
16891729 ## Appendix A. What an implementation chooses
16901730
@@ -1769,7 +1809,7 @@
17691809 Link = "link" ( string | "static" ) ";" .
17701810 Check = "check" "off" ";" .
17711811
1772-Declaration = "const" { IdentDef [ ":" "ERROR" ] "=" Expr ";" }
1812+Declaration = "const" { IdentDef [ ":" Type ] "=" Expr ";" }
17731813 | "type" { IdentDef "=" Type ";" }
17741814 | "var" { IdentList ":" Type ";" }
17751815 | ProcDeclaration ";"
@@ -1820,12 +1860,14 @@
18201860 | "return" [ Expr { "," Expr } ]
18211861 | "break"
18221862 | "defer" Statement .
1823-Arm = ( ident [ "(" ident { "," ident } ")" ] | "else" ) ":" Statements .
1863+Arm = ( ident [ "(" ident { "," ident } ")" ]
1864+ | Label { "," Label } | "else" ) ":" Statements .
1865+Label = Expr [ ".." Expr ] .
18241866
18251867 ProcDeclaration = "proc" IdentDef Signature ";"
18261868 ( "forward" | { LocalDeclaration } "begin" Statements "end" [ ident ]
18271869 | "code" Expr { "," Expr } ) .
1828-LocalDeclaration = "const" { ident [ ":" "ERROR" ] "=" Expr ";" }
1870+LocalDeclaration = "const" { ident [ ":" Type ] "=" Expr ";" }
18291871 | "type" { ident "=" Type ";" }
18301872 | "var" { ident { "," ident } ":" Type ";" } .
18311873 Signature = "(" [ Params { ";" Params } [ ";" "..." ] ] ")" [ ":" Results ]