| | @@ -10,7 +10,8 @@ |
| 10 | 10 | doesn't allow, raz doesn't have. |
| 11 | 11 | |
| 12 | 12 | 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. |
| 14 | 15 | |
| 15 | 16 | The language is frozen, softly, from this version on: it changes only |
| 16 | 17 | to mend a defect, and its library grows only by what breaks no program |
| | @@ -117,12 +118,13 @@ |
| 117 | 118 | |
| 118 | 119 | ``` |
| 119 | 120 | Module = "module" ident [ "(" ModParams ")" ] ";" |
| 120 | | - { Import } { Link } { Declaration } |
| 121 | + { Import } { Link } [ Check ] { Declaration } |
| 121 | 122 | [ "begin" Statements ] "end" ident "." . |
| 122 | 123 | ModParams = ident { "," ident } { ";" ident ":" "proc" Signature } . |
| 123 | 124 | Import = "import" ImportItem { "," ImportItem } ";" . |
| 124 | 125 | ImportItem = ident [ ":=" ident [ "(" Type { "," Type } ")" ] ] . |
| 125 | 126 | Link = "link" ( string | "static" ) ";" . |
| 127 | +Check = "check" "off" ";" . |
| 126 | 128 | ``` |
| 127 | 129 | |
| 128 | 130 | A module lives in a file of its own name: module `Out` is `Out.raz`. |
| | @@ -131,8 +133,12 @@ |
| 131 | 133 | **Exports.** A name declared at the top of a module with `*` after it |
| 132 | 134 | is exported: other modules can use it as `Module.name`. Record fields |
| 133 | 135 | 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. |
| 136 | 142 | |
| 137 | 143 | **Imports.** `import Out;` makes `Out`'s exports available as `Out.x`. |
| 138 | 144 | `import O := Out;` uses the name `O` instead. A module can't import |
| | @@ -246,6 +252,13 @@ |
| 246 | 252 | module needs a program without C (section 10): it makes its own system |
| 247 | 253 | calls, or its own threads, which the C library wouldn't know about. |
| 248 | 254 | |
| 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 | + |
| 249 | 262 | ## 4. Declarations |
| 250 | 263 | |
| 251 | 264 | ``` |
| | @@ -307,13 +320,25 @@ |
| 307 | 320 | | Type | Size | Values | |
| 308 | 321 | |---|---|---| |
| 309 | 322 | | `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 | |
| 310 | 325 | | `U8` `U16` `U32` `U64` | 1, 2, 4, 8 | unsigned integers | |
| 311 | 326 | | `BOOL` | 1 | `false` (0), `true` (1) | |
| 312 | 327 | | `F32` | 4 | IEEE 754 single precision | |
| 313 | 328 | | `F64` | 8 | IEEE 754 double precision | |
| 314 | 329 | |
| 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 | + |
| 315 | 339 | 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. |
| 317 | 342 | |
| 318 | 343 | ### 5.2 Arrays |
| 319 | 344 | |
| | @@ -323,10 +348,10 @@ |
| 323 | 348 | ### 5.3 Slices |
| 324 | 349 | |
| 325 | 350 | `[]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. |
| 327 | 352 | |
| 328 | 353 | ``` |
| 329 | | -Slice = record ptr: ^T; len: I64; end; (* its layout *) |
| 354 | +Slice = record ptr: ^T; len: INT; end; (* its layout *) |
| 330 | 355 | ``` |
| 331 | 356 | |
| 332 | 357 | A slice is made from an array (`a[2..5]`, or an array used where a |
| | @@ -335,7 +360,8 @@ |
| 335 | 360 | |
| 336 | 361 | ### 5.4 Pointers |
| 337 | 362 | |
| 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. |
| 339 | 365 | |
| 340 | 366 | `^VOLATILE T` is the address of a `T` that something besides the |
| 341 | 367 | program may read or change: a device register, memory shared with |
| | @@ -389,12 +415,12 @@ |
| 389 | 415 | procedure, `circle(2.0)`; a case without fields is just `dot`. The only |
| 390 | 416 | way to read the fields is `match` (section 7.4). |
| 391 | 417 | |
| 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 |
| 393 | 419 | on), then the space for the fields. Each case's fields are laid out |
| 394 | 420 | in that space as a record's would be, after the tag, and the cases |
| 395 | 421 | 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 |
| 398 | 424 | therefore holds its first case. |
| 399 | 425 | |
| 400 | 426 | ### 5.7 Enumerations and sets |
| | @@ -421,7 +447,7 @@ |
| 421 | 447 | const NotFound*: ERROR = "not found"; |
| 422 | 448 | ``` |
| 423 | 449 | |
| 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 |
| 425 | 451 | constant declared as above, and each such declaration makes an error |
| 426 | 452 | different from every other, whatever its message: two modules that |
| 427 | 453 | both declare `"not found"` have two different errors. A generic module |
| | @@ -445,7 +471,7 @@ |
| 445 | 471 | ``` |
| 446 | 472 | |
| 447 | 473 | 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 |
| 449 | 475 | parameters have the same types, each `var` or not alike, in order, and |
| 450 | 476 | their results are the same types; the parameters' names don't matter. |
| 451 | 477 | |
| | @@ -477,10 +503,12 @@ |
| 477 | 503 | - `A` is a string literal and `B` is `[]U8`, `^U8` (a pointer to the |
| 478 | 504 | bytes followed by a zero byte, as C wants), or `[n]U8` with `n` at |
| 479 | 505 | 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. |
| 481 | 509 | |
| 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` |
| 484 | 512 | and `F64`, without a written conversion (section 6.7). |
| 485 | 513 | |
| 486 | 514 | ## 6. Expressions |
| | @@ -564,7 +592,7 @@ |
| 564 | 592 | - `p + i` and `p - i`, with `i` an integer, move `p` by `i` elements: |
| 565 | 593 | by `i * SIZE(T)` bytes for `p: ^T`. |
| 566 | 594 | - `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`. |
| 568 | 596 | - `p[i]` is `(p + i)^`. `p[lo..hi]` is the slice of the `hi - lo` |
| 569 | 597 | elements from `p + lo`. Neither is checked against a length, which a |
| 570 | 598 | pointer doesn't have, but a slice of a pointer that runs backwards, |
| | @@ -582,6 +610,8 @@ |
| 582 | 610 | A check that fails prints to standard error where it is, as file, line |
| 583 | 611 | and column, and what failed, with the values involved (`index 7 is out |
| 584 | 612 | 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. |
| 585 | 615 | |
| 586 | 616 | **Literals.** `[e1, e2, ...]` builds an array, and `{f: e, g: e, ...}` |
| 587 | 617 | a record, where the type it must have is known: assigned to a variable, |
| | @@ -641,12 +671,13 @@ |
| 641 | 671 | | integer | enumeration | the name at that position; a position out of range is a failed check (6.5) | |
| 642 | 672 | | set | integer | its bits | |
| 643 | 673 | | 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 | |
| 646 | 676 | | pointer, procedure | pointer, procedure | the same address, seen as the new type | |
| 647 | 677 | |
| 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 |
| 650 | 681 | conversion of a constant is made by the compiler, by the same rules: |
| 651 | 682 | `U8(300)` is 44. |
| 652 | 683 | |
| | @@ -656,17 +687,17 @@ |
| 656 | 687 | |---|---| |
| 657 | 688 | | `SIZE(T)` | the size of type `T` in bytes, a constant; `T` is a type, not a variable | |
| 658 | 689 | | `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` | |
| 660 | 691 | | `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 | |
| 661 | 692 | | `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`) | |
| 663 | 694 | | `INC(v)`, `INC(v, k)` | adds 1, or `k`, to the integer variable `v`; it wraps, like `+` | |
| 664 | 695 | | `DEC(v)`, `DEC(v, k)` | subtracts 1, or `k`, from `v` | |
| 665 | 696 | | `FENCE` | a full memory barrier | |
| 666 | 697 | | `CAS(p, old, new)` | if `p^ = old`, sets `p^ := new` and returns `true`; atomically | |
| 667 | 698 | | `XCHG(p, x)` | sets `p^ := x` and returns the value before, atomically | |
| 668 | 699 | | `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` | |
| 670 | 701 | | `ARGV()` | the arguments, a `^^U8` (C strings) | |
| 671 | 702 | |
| 672 | 703 | `SYSCALL` exists only on Linux targets. Other systems have no stable |
| | @@ -683,7 +714,10 @@ |
| 683 | 714 | pointer, and not atomic; `XADD` is the atomic one. |
| 684 | 715 | |
| 685 | 716 | 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 |
| 687 | 721 | are sequentially consistent. |
| 688 | 722 | |
| 689 | 723 | ## 7. Statements |
| | @@ -1017,6 +1051,23 @@ |
| 1017 | 1051 | the compiled code checks for them is the implementation's choice |
| 1018 | 1052 | (appendix A); that they stop the program isn't. |
| 1019 | 1053 | |
| 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 | + |
| 1020 | 1071 | **Messages.** The compiler reports an error with its file, line and |
| 1021 | 1072 | column, the line of source with the offending part underlined, and, |
| 1022 | 1073 | where they help, notes pointing at other places, such as where a name |
| | @@ -1064,7 +1115,7 @@ |
| 1064 | 1115 | module Mem; |
| 1065 | 1116 | type |
| 1066 | 1117 | Allocator* = record |
| 1067 | | - alloc*: proc(a: ^Allocator; size, align: I64): ^U8; |
| 1118 | + alloc*: proc(a: ^Allocator; size, align: INT): ^U8; |
| 1068 | 1119 | free*: proc(a: ^Allocator; p: ^U8); |
| 1069 | 1120 | end; |
| 1070 | 1121 | ... |
| | @@ -1562,6 +1613,16 @@ |
| 1562 | 1613 | 2); a slice of a pointer can't run backwards (section 6.4). Ordinary |
| 1563 | 1614 | accesses are no longer promised to be made exactly as written, only |
| 1564 | 1615 | 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). |
| 1565 | 1626 | |
| 1566 | 1627 | ## Appendix A. What an implementation chooses |
| 1567 | 1628 | |
| | @@ -1570,7 +1631,10 @@ |
| 1570 | 1631 | compiler's choices are in `doc/compiler.md`. |
| 1571 | 1632 | |
| 1572 | 1633 | - **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`. |
| 1574 | 1638 | - **The calling convention.** On x86-64 Linux it is System V |
| 1575 | 1639 | (sections 8 and 9); elsewhere it is the C library's own, so that |
| 1576 | 1640 | `extern` procedures and callbacks work. How a procedure returns |
| | @@ -1625,12 +1689,13 @@ |
| 1625 | 1689 | anyHex = hexDigit | "a" .. "f" . |
| 1626 | 1690 | |
| 1627 | 1691 | Module = "module" ident [ "(" ModParams ")" ] ";" |
| 1628 | | - { Import } { Link } { Declaration } |
| 1692 | + { Import } { Link } [ Check ] { Declaration } |
| 1629 | 1693 | [ "begin" Statements ] "end" ident "." . |
| 1630 | 1694 | ModParams = ident { "," ident } { ";" ident ":" "proc" Signature } . |
| 1631 | 1695 | Import = "import" ImportItem { "," ImportItem } ";" . |
| 1632 | 1696 | ImportItem = ident [ ":=" ident [ "(" Type { "," Type } ")" ] ] . |
| 1633 | 1697 | Link = "link" ( string | "static" ) ";" . |
| 1698 | +Check = "check" "off" ";" . |
| 1634 | 1699 | |
| 1635 | 1700 | Declaration = "const" { IdentDef [ ":" "ERROR" ] "=" Expr ";" } |
| 1636 | 1701 | | "type" { IdentDef "=" Type ";" } |