raz / commit 02c4c3cc

commit
02c4c3cc959badb5effc0a744490d865d15a622a
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
76a05a0c
Report draft 2026-10.11: review

Exported vars can't be sliced outside their module; a string's bytes
are constant; INT and I64 don't mix in exprs or for; check off covers
6.4 and follows the generic module's line; instances name types by
module, proc and name, and records given to generics are named;
atomics' means are appendix A's; extern int consts go as INT.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

patch · log

1 file changed, +47 -20

doc/raz.md (history) modified +47 -20

@@ -136,9 +136,12 @@
136136 An exported variable can be read by the modules that import it, but
137137 only its own module changes it. Outside it, the variable, and every
138138 field and element of it, can't be assigned, given to a `var`
139-parameter, `INC`ed or `DEC`ed, or have its address taken with `ADR`.
140-What a pointer in it points at is another variable, and isn't held to
141-this.
139+parameter, `INC`ed or `DEC`ed, have its address taken with `ADR`, be
140+sliced, or stand where a slice is expected (section 5.10). It can be
141+copied, and the copy is the importer's own. What a pointer or a slice
142+in it points at is another variable, and isn't held to this; a module
143+that means to share its array writes a procedure that returns a slice
144+of it.
142145
143146 **Imports.** `import Out;` makes `Out`'s exports available as `Out.x`.
144147 `import O := Out;` uses the name `O` instead. A module can't import
@@ -253,11 +256,13 @@
253256 calls, or its own threads, which the C library wouldn't know about.
254257
255258 **`check off;`**, after the links, leaves out of the module's own code
256-the checks of indexes and slices (section 6.5), for speed where the
259+the checks of indexes and slice bounds (sections 6.4 and 6.5), for speed where the
257260 program is sure of them. An index out of range there reads or writes
258261 whatever memory it reaches, and what follows isn't defined. Every
259-other check stays, and the module's callers keep theirs. `check` and
260-`off` aren't reserved words.
262+other check stays, and the module's callers keep theirs. An instance
263+of a generic module follows the generic module's own `check` line, not
264+that of the module that made it. `check` and `off` aren't reserved
265+words.
261266
262267 ## 4. Declarations
263268
@@ -329,8 +334,10 @@
329334
330335 `INT` is the everyday integer: lengths, indexes and sizes are `INT`s.
331336 It is as big as an address, so it is the integer a pointer converts
332-to (section 6.7), and the one the atomic built-ins work on (section
333-6.8).
337+to (section 6.7), and a word the atomic built-ins work on (section
338+6.8). `INT` and `I64` are two types, even where they are the same
339+size: an `INT` goes silently into an `I64` (section 5.10), but the two
340+don't mix in an expression (section 6.1).
334341
335342 `F32` and `F64` exist only on a target that has reals (appendix A). On
336343 one that hasn't, they, real literals and anything made of them are
@@ -507,6 +514,12 @@
507514 - `A` is `INT` and `B` is `I64`, or `A` is `UINT` and `B` is `U64`,
508515 which loses nothing on any target.
509516
517+A string's bytes are constant. A `[]U8` or `^U8` made from a string
518+literal, or a slice of a string constant, points at them, and writing
519+through it isn't defined: on a target with read-only memory, it stops
520+the program as a bad address (section 10). A `[n]U8` made from a
521+string is a copy, the program's to change.
522+
510523 Nothing else converts silently. In particular, there is no other
511524 conversion between integer types, between integers and reals, or between `F32`
512525 and `F64`, without a written conversion (section 6.7).
@@ -553,7 +566,9 @@
553566 type, or one is an untyped constant that takes the other's type. The
554567 result has that type and wraps around at its width: in `U8`,
555568 `200 + 100` is `44`. A unary minus wraps too: for `x` of an unsigned
556-type, `-x` is `0 - x`.
569+type, `-x` is `0 - x`. Two integer types are never mixed, whatever
570+their sizes: with `i: I64`, `i < LEN(s)` is an error, and `i` is
571+better an `INT`.
557572
558573 `div` rounds toward zero and `mod` takes the sign of the dividend, as
559574 in C: `-7 div 2` is `-3`, `-7 mod 2` is `-1`. Dividing by zero, and
@@ -718,9 +733,9 @@
718733 For `CAS`, `XCHG` and `XADD`, `p` is a `^T` or `^VOLATILE T` where `T`
719734 is an integer or pointer type as big as an address: `INT`, `UINT` or a
720735 pointer, and on x86-64 `I64` and `U64` too (an integer type for
721-`XADD`). A machine with one processor and no atomic instructions makes
722-them atomic by holding off interrupts while they run. They
723-are sequentially consistent.
736+`XADD`). They are sequentially consistent, on every target; how a
737+machine without atomic instructions makes them so is the
738+implementation's choice (appendix A).
724739
725740 ## 7. Statements
726741
@@ -761,7 +776,9 @@
761776 `i <= b` (or `i >= b` if `s` is negative). `i` is a variable of an
762777 integer or enumeration type, named by its name alone; `a` and then `b`
763778 are evaluated once, before the first round; `s` is a constant other
764-than zero, and 1 if left out.
779+than zero, and 1 if left out. `a` and `b` have `i`'s type, or are
780+untyped constants that take it, as with `+` (section 6.1): so in
781+`for i := 0 to LEN(s) - 1`, `i` is an `INT`.
765782
766783 The loop never steps past `b`, so `i` can't wrap: afterwards `i`
767784 holds the last value it took, or `a` if the body never ran. The body
@@ -977,7 +994,7 @@
977994 types, and is allowed only in an `extern`. C takes no `float` there,
978995 so an `F32` given to `...` is an error: the program writes `F64(x)`.
979996 Past the parameters, a real constant goes as an `F64`, an integer
980-constant as an `I64`, and a string literal as a pointer to its bytes
997+constant as an `INT`, and a string literal as a pointer to its bytes
981998 followed by a zero byte.
982999
9831000 An `extern` variable is C's variable itself: reading it reads C's,
@@ -1066,8 +1083,11 @@
10661083 An instance of a generic module goes into the object file of the
10671084 module that made it, named by the generic module, its arguments, and
10681085 the fingerprints of the generic module's declarations and of each
1069-argument's. A type argument is named as it is built, a private type
1070-with the name of its module. Two object files that hold an instance of
1086+argument's. A type argument is named as it is built, and a named type
1087+by where it is declared: its module, its procedure if it is local to
1088+one, and its name. A record, variant or enumeration given as a type
1089+argument must therefore be named, since each written anonymously is a
1090+type of its own (section 5.10). Two object files that hold an instance of
10711091 the same name hold the same code, and the program keeps one.
10721092
10731093 **Messages.** The compiler reports an error with its file, line and
@@ -1621,10 +1641,13 @@
16211641 silently; pointers, procedures, `ERROR`s, slices and variants' tags
16221642 are sized by the address (section 5). Reals are a target's to have
16231643 or not (section 5.1). An exported variable is read only outside its
1624- module (section 3). `check off;` leaves a module's index and slice
1625- checks out (sections 3 and 6.5). The atomic built-ins work on words
1626- (section 6.8). Modules compile on their own, into object files
1627- (section 10).
1644+ module (section 3), nor sliced there. `check off;` leaves a module's
1645+ index and slice checks out (sections 3, 6.4 and 6.5). `INT` and
1646+ `I64` don't mix in an expression (section 6.1). Writing a string's
1647+ bytes isn't defined (section 5.10). The atomic built-ins work on
1648+ words (section 6.8). Modules compile on their own, into object files
1649+ (section 10); a record, variant or enumeration given to a generic
1650+ module is named.
16281651
16291652 ## Appendix A. What an implementation chooses
16301653
@@ -1637,6 +1660,10 @@
16371660 of an address, and so of `INT`, and whether it has reals.
16381661 - **Object files.** Their format, and the intermediate form of the
16391662 code in them (section 10); this compiler's is in `doc/ir.md`.
1663+- **Atomics.** How `CAS`, `XCHG` and `XADD` are made sequentially
1664+ consistent on a machine without atomic instructions (section 6.8):
1665+ on one with a single processor, by holding off interrupts while
1666+ they run, for one.
16401667 - **The calling convention.** On x86-64 Linux it is System V
16411668 (sections 8 and 9); elsewhere it is the C library's own, so that
16421669 `extern` procedures and callbacks work. How a procedure returns