raz / commit b03190fd

commit
b03190fd7c09b5f1a768d3fc6e4cfa077d565e95
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
fa546d68
Report draft 2026-10.11: the reviewers' points

Exported vars are values outside their module (match arms, NEW too);
a slice in one isn't the module's. Instances named by the generic's
whole source and by what a type stands for, so one type gives one
name. Constants must fit the type they take; SIZE and constant LEN
are untyped; one paragraph on where integers of any type do. Shifts
count modulo the width, as ir.md says; min / -1 stops for every
signed type. Atomics on INT, UINT, pointers only. Alignment is C's;
reals' errors come at a use. Defined behaviour names check off and
string bytes. Changelog made whole; the thaw said up front.

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

patch · log

1 file changed, +136 -91

doc/raz.md (history) modified +136 -91

@@ -1,17 +1,19 @@
11 # The programming language raz
22
3-raz is a small systems language for x86-64 Linux. A raz program can lay
4-a record over a device's registers, read and write a device's memory
5-exactly as written, take part in lock-free algorithms, make system calls and call
6-C libraries. It has no garbage collector and no hidden run time: what
7-the program does is what its text says.
3+raz is a small systems language, first made for x86-64 Linux. A raz
4+program can lay a record over a device's registers, read and write a
5+device's memory exactly as written, take part in lock-free algorithms,
6+make system calls and call C libraries. It has no garbage collector and
7+no hidden run time: what the program does is what its text says.
88
99 This report defines the language. It is short on purpose. Whatever it
1010 doesn't allow, raz doesn't have.
1111
1212 This is version 2026-10.10 of the report; section 12 says what each
1313 version changed. Version 2026-10.11, written into it, is a draft for
14-review: the compiler doesn't follow it yet.
14+review: the compiler doesn't follow it yet. It is a thaw the owner
15+chose, for a language anyone can build again, and it breaks programs
16+written for 2026-10.10.
1517
1618 The language is frozen, softly, from this version on: it changes only
1719 to mend a defect, and its library grows only by what breaks no program
@@ -134,14 +136,18 @@
134136 is exported: other modules can use it as `Module.name`. Record fields
135137 are exported the same way. Everything else is private to the module.
136138 An exported variable can be read by the modules that import it, but
137-only its own module changes it. Outside it, the variable, and every
138-field and element of it, can't be assigned, given to a `var`
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.
139+only its own module changes it. Outside it, the variable is a value,
140+not a variable: nothing that could write it, or let something else
141+write it, may name it or a field or element of it. So it can't be
142+assigned, passed as a `var` argument, changed by `INC`, `DEC` or
143+`NEW`, given to `ADR`, sliced, or used where a slice is expected (the
144+silent conversion of an array, section 5.10); in `match`, its arms'
145+names stand for the fields of a copy. It can be read, copied and
146+compared, and a copy is the importer's own. What a pointer or a slice
147+in it points at is another variable, and isn't held to this: with
148+`s: []U8` exported, `M.s[0] := 0` writes what `M.s` points at, not
149+`M`. A module that means to share an array exports a pointer to it,
150+or a procedure that returns a slice of it.
145151
146152 **Imports.** `import Out;` makes `Out`'s exports available as `Out.x`.
147153 `import O := Out;` uses the name `O` instead. A module can't import
@@ -256,13 +262,14 @@
256262 calls, or its own threads, which the C library wouldn't know about.
257263
258264 **`check off;`**, after the links, leaves out of the module's own code
259-the checks of indexes and slice bounds (sections 6.4 and 6.5), for speed where the
265+the checks of indexes and slice bounds of section 6.5, and that a slice
266+of a pointer doesn't run backwards (section 6.4), for speed where the
260267 program is sure of them. An index out of range there reads or writes
261-whatever memory it reaches, and what follows isn't defined. Every
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.
268+whatever memory it reaches, and what follows isn't defined. Every other
269+check stays, and the module's callers keep theirs. An instance of a
270+generic module follows the generic module's own `check` line, not that
271+of the module that made it. `check` and `off` aren't reserved words, as
272+`static` isn't.
266273
267274 ## 4. Declarations
268275
@@ -325,8 +332,8 @@
325332 | Type | Size | Values |
326333 |---|---|---|
327334 | `I8` `I16` `I32` `I64` | 1, 2, 4, 8 | signed integers, two's complement |
328-| `INT` | an address's: 8 on x86-64 | the machine's word, signed |
329-| `UINT` | an address's | the machine's word, unsigned |
335+| `INT` | an address's: 8 on x86-64 | signed, as big as an address |
336+| `UINT` | an address's | unsigned, as big as an address |
330337 | `U8` `U16` `U32` `U64` | 1, 2, 4, 8 | unsigned integers |
331338 | `BOOL` | 1 | `false` (0), `true` (1) |
332339 | `F32` | 4 | IEEE 754 single precision |
@@ -335,15 +342,20 @@
335342 `INT` is the everyday integer: lengths, indexes and sizes are `INT`s.
336343 It is as big as an address, so it is the integer a pointer converts
337344 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
345+6.8). `INT` and `I64` are two types, even where they have the same
339346 size: an `INT` goes silently into an `I64` (section 5.10), but the two
340-don't mix in an expression (section 6.1).
347+don't mix in an expression (section 6.1), and an `I64` becomes an
348+`INT` only by `INT(x)`, which may drop bits on a smaller target. A
349+type bigger than the largest `INT` in bytes is an error.
341350
342351 `F32` and `F64` exist only on a target that has reals (appendix A). On
343-one that hasn't, they, real literals and anything made of them are
344-errors.
352+one that hasn't, a real literal, and a use of `F32`, `F64` or of a
353+name whose type is made of them, is an error; a declaration that no
354+used code names isn't, so a module like `Fmt` keeps one interface on
355+every target.
345356
346-Each is aligned to its size. So are `ERROR` (section 5.8), pointers
357+Each is aligned as the target's C aligns it: to its size on x86-64.
358+So are `ERROR` (section 5.8), pointers
347359 and procedures, each as big as an address; a slice is aligned as an
348360 address is.
349361
@@ -426,9 +438,9 @@
426438 on), then the space for the fields. Each case's fields are laid out
427439 in that space as a record's would be, after the tag, and the cases
428440 share it, so the variant is as big as its largest case needs, padded
429-to its alignment, the largest of `INT`'s and its fields'. `variant
430-a(x: U8); b(y: I64; z: U8); end` is 24 bytes on x86-64. A variant that starts at zero
431-therefore holds its first case.
441+to its alignment, the largest of an `INT`'s and its fields'.
442+`variant a(x: U8); b(y: I64; z: U8); end` is 24 bytes on x86-64. A
443+variant that starts at zero therefore holds its first case.
432444
433445 ### 5.7 Enumerations and sets
434446
@@ -454,9 +466,9 @@
454466 const NotFound*: ERROR = "not found";
455467 ```
456468
457-`ERROR` is a basic type as big as an address. A value of it is made only by a
458-constant declared as above, and each such declaration makes an error
459-different from every other, whatever its message: two modules that
469+`ERROR` is a basic type as big as an address. A value of it is made only
470+by a constant declared as above, and each such declaration makes an
471+error different from every other, whatever its message: two modules that
460472 both declare `"not found"` have two different errors. A generic module
461473 makes its errors once per instance. `nil` is no error.
462474
@@ -478,9 +490,10 @@
478490 ```
479491
480492 A value of a procedure type is the address of a procedure with that
481-signature, as big as an address, or `nil`. Two signatures are alike when their
482-parameters have the same types, each `var` or not alike, in order, and
483-their results are the same types; the parameters' names don't matter.
493+signature, as big as an address, or `nil`. Two signatures are alike when
494+their parameters have the same types, each `var` or not alike, in order,
495+and their results are the same types; the parameters' names don't
496+matter.
484497
485498 ### 5.10 Same and assignable
486499
@@ -516,13 +529,15 @@
516529
517530 A string's bytes are constant. A `[]U8` or `^U8` made from a string
518531 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
532+through it isn't defined: on a target with read-only memory, it may
533+stop the program as a bad address (section 10). A `[n]U8` made from a
521534 string is a copy, the program's to change.
522535
523536 Nothing else converts silently. In particular, there is no other
524-conversion between integer types, between integers and reals, or between `F32`
525-and `F64`, without a written conversion (section 6.7).
537+conversion between integer types, between integers and reals, or
538+between `F32` and `F64`, without a written conversion (section 6.7).
539+Several results, and `return f(x)`, need the same types exactly: an
540+`INT` result doesn't pass up as an `I64`.
526541
527542 ## 6. Expressions
528543
@@ -562,23 +577,35 @@
562577
563578 ### 6.1 Integers
564579
565-Both operands of `+ - * div mod & | xor` have the same integer
566-type, or one is an untyped constant that takes the other's type. The
567-result has that type and wraps around at its width: in `U8`,
568-`200 + 100` is `44`. A unary minus wraps too: for `x` of an unsigned
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`.
580+Both operands of `+ - * div mod & | xor`, and of a relation, have the
581+same integer type, or one is an untyped constant that takes the
582+other's type, which it must fit. So do `v` and `k` in `INC(v, k)` and
583+`DEC(v, k)`. The result has that type and wraps around at its width:
584+in `U8`, `200 + 100` is `44`. A unary minus wraps too: for `x` of an
585+unsigned type, `-x` is `0 - x`. Two integer types are never mixed,
586+whatever their sizes: with `i: I64`, `i < LEN(s)` is an error, and
587+`i` should be an `INT`.
588+
589+Where the report asks for an integer and names no type, as an index, a
590+slice's bound, a shift's count, a pointer's offset `i` in `p + i`, or
591+a conversion's operand, any integer type will do, and its value is
592+taken. On a target whose `INT` is narrower, a pointer's offset is cut
593+to an `INT`.
594+
595+`SIZE(T)`, and `LEN` of an array or a string constant, are untyped
596+constants, like a literal.
572597
573598 `div` rounds toward zero and `mod` takes the sign of the dividend, as
574599 in C: `-7 div 2` is `-3`, `-7 mod 2` is `-1`. Dividing by zero, and
575-dividing the smallest `I64` by `-1`, stop the program (`SIGFPE`).
600+dividing the smallest value of a signed type by `-1`, stop the program
601+(`SIGFPE`), whatever the type and the target.
576602
577603 `&` (and), `|` (or), `xor` and `~` (not) work on every bit. `x shl n`
578-and `x shr n` shift by `n & 63`; `shr` brings in copies of the sign bit
579-for signed types and zeros for unsigned ones. `n` may be of any integer
580-type. The result has `x`'s type, cut to its width: in `U8`, `0C0H shl
581-1` is `80H`.
604+and `x shr n` shift by `n` modulo the width of `x`'s type, in bits:
605+for `x: U8`, `x shl 9` is `x shl 1`. `shr` brings in copies of the
606+sign bit for signed types and zeros for unsigned ones. `n` may be of
607+any integer type. The result has `x`'s type, cut to its width: in
608+`U8`, `0C0H shl 1` is `80H`.
582609
583610 Relations compare as signed or unsigned according to the type.
584611
@@ -627,8 +654,8 @@
627654 of range for a length of 5`), and stops the program with status 2.
628655 An index or a bound may be of any integer type, and is checked by its
629656 value, whatever its type: a negative `I8`, or a `U64` past the length,
630-fails like any other. A module that says
631-`check off;` (section 3) leaves these checks out of its code.
657+fails like any other. A module that says `check off;` (section 3)
658+leaves these checks out of its code.
632659
633660 **Literals.** `[e1, e2, ...]` builds an array, and `{f: e, g: e, ...}`
634661 a record, where the type it must have is known: assigned to a variable,
@@ -702,12 +729,12 @@
702729
703730 | Call | Result |
704731 |---|---|
705-| `SIZE(T)` | the size of type `T` in bytes, a constant; `T` is a type, not a variable |
732+| `SIZE(T)` | the size of type `T` in bytes, an untyped constant; `T` is a type, not a variable |
706733 | `ADR(x)` | the address of variable `x`, a `^T` |
707-| `LEN(a)` | the number of elements of an array or a string constant (a constant) or of a slice, an `INT` |
734+| `LEN(a)` | the number of elements of an array or a string constant (an untyped constant) or of a slice (an `INT`) |
708735 | `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 |
709736 | `MSG(e)` | the message of the error `e`, a `[]U8` |
710-| `SYSCALL(n, x1, ..., x6)` | Linux system call `n` with up to six integer or pointer arguments; the raw result, an `INT` (a negative number is `-errno`) |
737+| `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`) |
711738 | `INC(v)`, `INC(v, k)` | adds 1, or `k`, to the integer variable `v`; it wraps, like `+` |
712739 | `DEC(v)`, `DEC(v, k)` | subtracts 1, or `k`, from `v` |
713740 | `FENCE` | a full memory barrier |
@@ -731,9 +758,8 @@
731758 pointer, and not atomic; `XADD` is the atomic one.
732759
733760 For `CAS`, `XCHG` and `XADD`, `p` is a `^T` or `^VOLATILE T` where `T`
734-is an integer or pointer type as big as an address: `INT`, `UINT` or a
735-pointer, and on x86-64 `I64` and `U64` too (an integer type for
736-`XADD`). They are sequentially consistent, on every target; how a
761+is `INT`, `UINT` or a pointer type (`INT` or `UINT` for `XADD`), on
762+every target. They are sequentially consistent, on every target; how a
737763 machine without atomic instructions makes them so is the
738764 implementation's choice (appendix A).
739765
@@ -778,7 +804,7 @@
778804 are evaluated once, before the first round; `s` is a constant other
779805 than zero, and 1 if left out. `a` and `b` have `i`'s type, or are
780806 untyped constants that take it, as with `+` (section 6.1): so in
781-`for i := 0 to LEN(s) - 1`, `i` is an `INT`.
807+`for i := 0 to LEN(s) - 1`, `i` must be an `INT`.
782808
783809 The loop never steps past `b`, so `i` can't wrap: afterwards `i`
784810 holds the last value it took, or `a` if the body never ran. The body
@@ -1058,10 +1084,12 @@
10581084
10591085 **Defined behaviour.** Every variable starts at zero, integers wrap,
10601086 and indexing arrays and slices is checked, so a program's behaviour is
1061-defined by this report, with one exception: memory reached through a
1062-pointer. Dereferencing a stale or made-up pointer, indexing through a
1063-pointer, a code procedure that breaks its rules, and C code can read or
1064-write any memory, and what follows isn't defined. Dereferencing `nil`, dividing
1087+defined by this report, with one exception: memory reached other than
1088+through a checked variable. Dereferencing a stale or made-up pointer,
1089+indexing through a pointer, an index out of range in a module that
1090+says `check off;`, writing a string's bytes, a code procedure that
1091+breaks its rules, and C code can read or write any memory, and what
1092+follows isn't defined. Dereferencing `nil`, dividing
10651093 by zero, calling a `nil` procedure and running out of stack stop the
10661094 program, on every target. Before it stops, the program prints to
10671095 standard error where it was, as file, line and column, and why, as far
@@ -1075,20 +1103,28 @@
10751103 code, in an intermediate form that a back end turns into any target's
10761104 machine code. A program is made from the object files of its modules.
10771105 An object file records the fingerprint of every interface it was
1078-compiled against, and stays current while its source and those
1079-interfaces don't change; when it isn't current, the compiler compiles
1106+compiled against, and of the whole source of every generic module it
1107+made an instance of, and stays current while its source and those
1108+don't change; when it isn't current, the compiler compiles
10801109 the module again from its source. A program comes out the same
10811110 whether its modules were compiled one at a time or all at once.
10821111
1083-An instance of a generic module goes into the object file of the
1084-module that made it, named by the generic module, its arguments, and
1085-the fingerprints of the generic module's declarations and of each
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
1091-the same name hold the same code, and the program keeps one.
1112+An instance is made from the generic module's source, and goes into
1113+the object file of the module that made it, named by the generic
1114+module, the fingerprint of its whole source, and its arguments. A
1115+type argument is named as it is built, down to its records, variants
1116+and enumerations, so that two arguments that are the same type
1117+(section 5.10) give one name: an alias, or a named pointer, array,
1118+slice, set or procedure type, is named as what it stands for, and a
1119+procedure type without its parameters' names. A record, variant or
1120+enumeration is named by where it is declared, with the fingerprint of
1121+its declaration: its module, its procedure if it is local to one, or
1122+the instance's name if an instance declares it, and its name. One
1123+given as a type argument must therefore be named, since each written
1124+anonymously is a type of its own. A procedure given as an argument is
1125+named by its module and its name. Two object files that hold an
1126+instance of the same name hold the same code, and the program keeps
1127+one.
10921128
10931129 **Messages.** The compiler reports an error with its file, line and
10941130 column, the line of source with the offending part underlined, and,
@@ -1636,18 +1672,27 @@
16361672 accesses are no longer promised to be made exactly as written, only
16371673 volatile and atomic ones (section 7.6).
16381674 - **2026-10.11, a draft for review.** `INT` and `UINT`, as big as an
1639- address, are the integers of lengths, indexes, sizes, pointer
1640- differences and pointer conversions; an `INT` widens to an `I64`
1641- silently; pointers, procedures, `ERROR`s, slices and variants' tags
1642- are sized by the address (section 5). Reals are a target's to have
1643- or not (section 5.1). An exported variable is read only outside its
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.
1675+ address, are the integers of lengths, slices, pointer differences,
1676+ pointer conversions, `SYSCALL` and `ARGC`; `SIZE` and a constant
1677+ `LEN` are untyped; `INT` widens silently to `I64` and `UINT` to
1678+ `U64`, but neither mixes with them in an expression or a `for`
1679+ (sections 5, 6.1 and 7.2); `Mem.Allocator` takes `INT` sizes.
1680+ Pointers, procedures, `ERROR`s, slices and variants' tags are sized
1681+ by the address, and basic types aligned as the target's C aligns
1682+ them (section 5). Reals are a target's to have or not (section
1683+ 5.1). An exported variable can't be changed, passed by `var`,
1684+ addressed or sliced outside its module (section 3). `check off;`
1685+ leaves a module's index and slice checks out (sections 3, 6.4 and
1686+ 6.5). An index of any integer type is checked by its value (6.5). A
1687+ shift counts modulo its operand's width, and the smallest value of
1688+ every signed type divided by -1 stops the program (6.1). Writing a
1689+ string's bytes isn't defined (5.10). The atomic built-ins work on
1690+ `INT`, `UINT` and pointers (6.8). An integer constant past an
1691+ extern's parameters goes as an `INT` (9). Modules compile on their
1692+ own, into object files, and instances are named so that one type
1693+ gives one name (section 10; appendix A). The library of section 11
1694+ still says `I64` for its lengths, sizes, counts and descriptors;
1695+ they become `INT` when it is revised for this version.
16511696
16521697 ## Appendix A. What an implementation chooses
16531698
@@ -1693,9 +1738,9 @@
16931738 **The core.** A target may leave out what the system under it can't
16941739 give: `Sys` past writing, ending the program and getting memory,
16951740 `Thread`, `link` and `extern`. What it must have, besides the whole
1696-language, is the core of the library: `Rt`, `Out`, `Mem`, `Arena`,
1697-`Lock`, `Str` and `Buf`, and of `Sys` what they need. A
1698-program that keeps to the core runs on every target.
1741+language, reals aside, is the core of the library: `Rt`, `Out`, `Mem`,
1742+`Arena`, `Lock`, `Str` and `Buf`, and of `Sys` what they need. A program
1743+that keeps to the core runs on every target.
16991744
17001745 ## Appendix B. The grammar
17011746