raz / commit 1e0e24af

commit
1e0e24af95dc0a2d1aac57abd78361c4257531aa
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
d4d2852b
Report 2026-10.11, a draft: INT, optional reals, read-only exports, object files

For review before any code. INT and UINT, as big as an address, are
the integers of lengths, indexes, sizes, pointer differences and
pointer conversions, and an INT widens to an I64 silently; pointers,
procedures, ERRORs, slices and tags are sized by the address. A target
has reals or not. An exported variable is read only outside its
module. check off; leaves a module's index and slice checks out. The
atomic built-ins work on words. Modules compile on their own into
object files, generic instances named by their arguments and
fingerprints. The compiler still follows 2026-10.10.

patch · log

2 files changed, +96 -31

PLAN.md (history) modified +3 -3

@@ -66,7 +66,7 @@
6666
6767 ## Proposed, v0.6.0: raz to be rebuilt by anyone
6868
69-Under way: step 1 is in review. The freeze doesn't hold for this
69+Under way: step 2, the report's draft 2026-10.11, is in review. The freeze doesn't hold for this
7070 work, by the owner's word.
7171
7272 **For:** a language a person alone can implement again, from the
@@ -84,7 +84,7 @@
8484 **Kept out:** a second back end (aarch64 is the milestone after, to
8585 measure a port); an optimiser; the wishes below.
8686
87-- [ ] 1. The report as it stands, made complete: the whole grammar;
87+- [x] 1. The report as it stands, made complete: the whole grammar;
8888 the readings in CLAUDE.md moved into the report; what every
8989 implementation must do set apart from what each may choose
9090 (code procedures, `SYSCALL`, `extern`'s convention, how several
@@ -92,7 +92,7 @@
9292 have (the language, `Rt` and `Out`, over writing, exiting and
9393 getting memory) and what it may leave out. No language change.
9494 For review before anything else.
95-- [ ] 2. The report, the new language, for review before any code: the
95+- [x] 2. The report, the new language, for review before any code: the
9696 system integers `INT` and `UINT`, the size of an address, which
9797 `LEN`, indexes, sizes and `p - q` give, and through which
9898 integers and pointers convert (the owner's choices), and how

doc/raz.md (history) modified +93 -28

@@ -10,7 +10,8 @@
1010 doesn't allow, raz doesn't have.
1111
1212 This is version 2026-10.10 of the report; section 12 says what each
13-version changed.
13+version changed. Version 2026-10.11, written into it, is a draft for
14+review: the compiler doesn't follow it yet.
1415
1516 The language is frozen, softly, from this version on: it changes only
1617 to mend a defect, and its library grows only by what breaks no program
@@ -117,12 +118,13 @@
117118
118119 ```
119120 Module = "module" ident [ "(" ModParams ")" ] ";"
120- { Import } { Link } { Declaration }
121+ { Import } { Link } [ Check ] { Declaration }
121122 [ "begin" Statements ] "end" ident "." .
122123 ModParams = ident { "," ident } { ";" ident ":" "proc" Signature } .
123124 Import = "import" ImportItem { "," ImportItem } ";" .
124125 ImportItem = ident [ ":=" ident [ "(" Type { "," Type } ")" ] ] .
125126 Link = "link" ( string | "static" ) ";" .
127+Check = "check" "off" ";" .
126128 ```
127129
128130 A module lives in a file of its own name: module `Out` is `Out.raz`.
@@ -131,8 +133,12 @@
131133 **Exports.** A name declared at the top of a module with `*` after it
132134 is exported: other modules can use it as `Module.name`. Record fields
133135 are exported the same way. Everything else is private to the module.
134-An exported variable can be read and assigned by the modules that
135-import it.
136+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, 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.
136142
137143 **Imports.** `import Out;` makes `Out`'s exports available as `Out.x`.
138144 `import O := Out;` uses the name `O` instead. A module can't import
@@ -246,6 +252,13 @@
246252 module needs a program without C (section 10): it makes its own system
247253 calls, or its own threads, which the C library wouldn't know about.
248254
255+**`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
257+program is sure of them. An index out of range there reads or writes
258+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.
261+
249262 ## 4. Declarations
250263
251264 ```
@@ -307,13 +320,25 @@
307320 | Type | Size | Values |
308321 |---|---|---|
309322 | `I8` `I16` `I32` `I64` | 1, 2, 4, 8 | signed integers, two's complement |
323+| `INT` | an address's: 8 on x86-64 | the machine's word, signed |
324+| `UINT` | an address's | the machine's word, unsigned |
310325 | `U8` `U16` `U32` `U64` | 1, 2, 4, 8 | unsigned integers |
311326 | `BOOL` | 1 | `false` (0), `true` (1) |
312327 | `F32` | 4 | IEEE 754 single precision |
313328 | `F64` | 8 | IEEE 754 double precision |
314329
330+`INT` is the everyday integer: lengths, indexes and sizes are `INT`s.
331+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).
334+
335+`F32` and `F64` exist only on a target that has reals (appendix A). On
336+one that hasn't, they, real literals and anything made of them are
337+errors.
338+
315339 Each is aligned to its size. So are `ERROR` (section 5.8), pointers
316-and procedures, 8 bytes; a slice is aligned to 8.
340+and procedures, each as big as an address; a slice is aligned as an
341+address is.
317342
318343 ### 5.2 Arrays
319344
@@ -323,10 +348,10 @@
323348 ### 5.3 Slices
324349
325350 `[]T` is a view of elements that live elsewhere: a pointer to the first
326-and a count, 16 bytes in all.
351+and a count, two addresses' worth, 16 bytes on x86-64.
327352
328353 ```
329-Slice = record ptr: ^T; len: I64; end; (* its layout *)
354+Slice = record ptr: ^T; len: INT; end; (* its layout *)
330355 ```
331356
332357 A slice is made from an array (`a[2..5]`, or an array used where a
@@ -335,7 +360,8 @@
335360
336361 ### 5.4 Pointers
337362
338-`^T` is the address of a `T`, 8 bytes. `nil` is the pointer to nothing.
363+`^T` is the address of a `T`, as big as an `INT`. `nil` is the pointer
364+to nothing.
339365
340366 `^VOLATILE T` is the address of a `T` that something besides the
341367 program may read or change: a device register, memory shared with
@@ -389,12 +415,12 @@
389415 procedure, `circle(2.0)`; a case without fields is just `dot`. The only
390416 way to read the fields is `match` (section 7.4).
391417
392-Layout: an `I64` tag (0 for the first case, 1 for the second, and so
418+Layout: an `INT` tag (0 for the first case, 1 for the second, and so
393419 on), then the space for the fields. Each case's fields are laid out
394420 in that space as a record's would be, after the tag, and the cases
395421 share it, so the variant is as big as its largest case needs, padded
396-to its alignment, the largest of 8 and its fields'. `variant a(x:
397-U8); b(y: I64; z: U8); end` is 24 bytes. A variant that starts at zero
422+to its alignment, the largest of `INT`'s and its fields'. `variant
423+a(x: U8); b(y: I64; z: U8); end` is 24 bytes on x86-64. A variant that starts at zero
398424 therefore holds its first case.
399425
400426 ### 5.7 Enumerations and sets
@@ -421,7 +447,7 @@
421447 const NotFound*: ERROR = "not found";
422448 ```
423449
424-`ERROR` is a basic type of 8 bytes. A value of it is made only by a
450+`ERROR` is a basic type as big as an address. A value of it is made only by a
425451 constant declared as above, and each such declaration makes an error
426452 different from every other, whatever its message: two modules that
427453 both declare `"not found"` have two different errors. A generic module
@@ -445,7 +471,7 @@
445471 ```
446472
447473 A value of a procedure type is the address of a procedure with that
448-signature, 8 bytes, or `nil`. Two signatures are alike when their
474+signature, as big as an address, or `nil`. Two signatures are alike when their
449475 parameters have the same types, each `var` or not alike, in order, and
450476 their results are the same types; the parameters' names don't matter.
451477
@@ -477,10 +503,12 @@
477503 - `A` is a string literal and `B` is `[]U8`, `^U8` (a pointer to the
478504 bytes followed by a zero byte, as C wants), or `[n]U8` with `n` at
479505 least the string's length (the rest is zero);
480-- `A` is a procedure and `B` a procedure type with the same signature.
506+- `A` is a procedure and `B` a procedure type with the same signature;
507+- `A` is `INT` and `B` is `I64`, or `A` is `UINT` and `B` is `U64`,
508+ which loses nothing on any target.
481509
482-Nothing else converts silently. In particular, there is no conversion
483-between integer types, between integers and reals, or between `F32`
510+Nothing else converts silently. In particular, there is no other
511+conversion between integer types, between integers and reals, or between `F32`
484512 and `F64`, without a written conversion (section 6.7).
485513
486514 ## 6. Expressions
@@ -564,7 +592,7 @@
564592 - `p + i` and `p - i`, with `i` an integer, move `p` by `i` elements:
565593 by `i * SIZE(T)` bytes for `p: ^T`.
566594 - `p - q`, with both of the same pointer type, is the number of
567- elements between them, an `I64`.
595+ elements between them, an `INT`.
568596 - `p[i]` is `(p + i)^`. `p[lo..hi]` is the slice of the `hi - lo`
569597 elements from `p + lo`. Neither is checked against a length, which a
570598 pointer doesn't have, but a slice of a pointer that runs backwards,
@@ -582,6 +610,8 @@
582610 A check that fails prints to standard error where it is, as file, line
583611 and column, and what failed, with the values involved (`index 7 is out
584612 of range for a length of 5`), and stops the program with status 2.
613+An index or a bound may be of any integer type. A module that says
614+`check off;` (section 3) leaves these checks out of its code.
585615
586616 **Literals.** `[e1, e2, ...]` builds an array, and `{f: e, g: e, ...}`
587617 a record, where the type it must have is known: assigned to a variable,
@@ -641,12 +671,13 @@
641671 | integer | enumeration | the name at that position; a position out of range is a failed check (6.5) |
642672 | set | integer | its bits |
643673 | integer | set | the low bits, as many as the set has |
644-| integer | pointer, procedure | the address |
645-| pointer, procedure | integer | the address |
674+| `INT`, `UINT` | pointer, procedure | the address |
675+| pointer, procedure | `INT`, `UINT` | the address |
646676 | pointer, procedure | pointer, procedure | the same address, seen as the new type |
647677
648-There are no others: no conversion between `BOOL` and integers, and
649-none to or from records, arrays, slices, variants or `ERROR`. A
678+There are no others: no conversion between `BOOL` and integers, none
679+between pointers and integers other than `INT` and `UINT`, and none to
680+or from records, arrays, slices, variants or `ERROR`. A
650681 conversion of a constant is made by the compiler, by the same rules:
651682 `U8(300)` is 44.
652683
@@ -656,17 +687,17 @@
656687 |---|---|
657688 | `SIZE(T)` | the size of type `T` in bytes, a constant; `T` is a type, not a variable |
658689 | `ADR(x)` | the address of variable `x`, a `^T` |
659-| `LEN(a)` | the number of elements of an array or a string constant (a constant) or of a slice, an `I64` |
690+| `LEN(a)` | the number of elements of an array or a string constant (a constant) or of a slice, an `INT` |
660691 | `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 |
661692 | `MSG(e)` | the message of the error `e`, a `[]U8` |
662-| `SYSCALL(n, x1, ..., x6)` | Linux system call `n` with up to six integer or pointer arguments; the raw result, an `I64` (a negative number is `-errno`) |
693+| `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`) |
663694 | `INC(v)`, `INC(v, k)` | adds 1, or `k`, to the integer variable `v`; it wraps, like `+` |
664695 | `DEC(v)`, `DEC(v, k)` | subtracts 1, or `k`, from `v` |
665696 | `FENCE` | a full memory barrier |
666697 | `CAS(p, old, new)` | if `p^ = old`, sets `p^ := new` and returns `true`; atomically |
667698 | `XCHG(p, x)` | sets `p^ := x` and returns the value before, atomically |
668699 | `XADD(p, x)` | adds `x` to `p^` and returns the value before, atomically |
669-| `ARGC()` | the number of command line arguments, an `I64` |
700+| `ARGC()` | the number of command line arguments, an `INT` |
670701 | `ARGV()` | the arguments, a `^^U8` (C strings) |
671702
672703 `SYSCALL` exists only on Linux targets. Other systems have no stable
@@ -683,7 +714,10 @@
683714 pointer, and not atomic; `XADD` is the atomic one.
684715
685716 For `CAS`, `XCHG` and `XADD`, `p` is a `^T` or `^VOLATILE T` where `T`
686-is an 8-byte integer or pointer type (an integer type for `XADD`). They
717+is an integer or pointer type as big as an address: `INT`, `UINT` or a
718+pointer, and on x86-64 `I64` and `U64` too (an integer type for
719+`XADD`). A machine with one processor and no atomic instructions makes
720+them atomic by holding off interrupts while they run. They
687721 are sequentially consistent.
688722
689723 ## 7. Statements
@@ -1017,6 +1051,23 @@
10171051 the compiled code checks for them is the implementation's choice
10181052 (appendix A); that they stop the program isn't.
10191053
1054+**Object files.** A module can be compiled on its own, into an object
1055+file: its interface, what it exports as an importer sees it, and its
1056+code, in an intermediate form that a back end turns into any target's
1057+machine code. A program is made from the object files of its modules.
1058+An object file records the fingerprint of every interface it was
1059+compiled against, and stays current while its source and those
1060+interfaces don't change; when it isn't current, the compiler compiles
1061+the module again from its source. A program comes out the same
1062+whether its modules were compiled one at a time or all at once.
1063+
1064+An instance of a generic module goes into the object file of the
1065+module that made it, named by the generic module, its arguments, and
1066+the fingerprints of the generic module's declarations and of each
1067+argument's. A type argument is named as it is built, a private type
1068+with the name of its module. Two object files that hold an instance of
1069+the same name hold the same code, and the program keeps one.
1070+
10201071 **Messages.** The compiler reports an error with its file, line and
10211072 column, the line of source with the offending part underlined, and,
10221073 where they help, notes pointing at other places, such as where a name
@@ -1064,7 +1115,7 @@
10641115 module Mem;
10651116 type
10661117 Allocator* = record
1067- alloc*: proc(a: ^Allocator; size, align: I64): ^U8;
1118+ alloc*: proc(a: ^Allocator; size, align: INT): ^U8;
10681119 free*: proc(a: ^Allocator; p: ^U8);
10691120 end;
10701121 ...
@@ -1562,6 +1613,16 @@
15621613 2); a slice of a pointer can't run backwards (section 6.4). Ordinary
15631614 accesses are no longer promised to be made exactly as written, only
15641615 volatile and atomic ones (section 7.6).
1616+- **2026-10.11, a draft for review.** `INT` and `UINT`, as big as an
1617+ address, are the integers of lengths, indexes, sizes, pointer
1618+ differences and pointer conversions; an `INT` widens to an `I64`
1619+ silently; pointers, procedures, `ERROR`s, slices and variants' tags
1620+ are sized by the address (section 5). Reals are a target's to have
1621+ or not (section 5.1). An exported variable is read only outside its
1622+ module (section 3). `check off;` leaves a module's index and slice
1623+ checks out (sections 3 and 6.5). The atomic built-ins work on words
1624+ (section 6.8). Modules compile on their own, into object files
1625+ (section 10).
15651626
15661627 ## Appendix A. What an implementation chooses
15671628
@@ -1570,7 +1631,10 @@
15701631 compiler's choices are in `doc/compiler.md`.
15711632
15721633 - **The target.** Which machines and systems it compiles for, and the
1573- names of their files (`linux-x86_64`, section 3).
1634+ names of their files (`linux-x86_64`, section 3); for each, the size
1635+ of an address, and so of `INT`, and whether it has reals.
1636+- **Object files.** Their format, and the intermediate form of the
1637+ code in them (section 10); this compiler's is in `doc/ir.md`.
15741638 - **The calling convention.** On x86-64 Linux it is System V
15751639 (sections 8 and 9); elsewhere it is the C library's own, so that
15761640 `extern` procedures and callbacks work. How a procedure returns
@@ -1625,12 +1689,13 @@
16251689 anyHex = hexDigit | "a" .. "f" .
16261690
16271691 Module = "module" ident [ "(" ModParams ")" ] ";"
1628- { Import } { Link } { Declaration }
1692+ { Import } { Link } [ Check ] { Declaration }
16291693 [ "begin" Statements ] "end" ident "." .
16301694 ModParams = ident { "," ident } { ";" ident ":" "proc" Signature } .
16311695 Import = "import" ImportItem { "," ImportItem } ";" .
16321696 ImportItem = ident [ ":=" ident [ "(" Type { "," Type } ")" ] ] .
16331697 Link = "link" ( string | "static" ) ";" .
1698+Check = "check" "off" ";" .
16341699
16351700 Declaration = "const" { IdentDef [ ":" "ERROR" ] "=" Expr ";" }
16361701 | "type" { IdentDef "=" Type ";" }