| | @@ -136,9 +136,12 @@ |
| 136 | 136 | An exported variable can be read by the modules that import it, but |
| 137 | 137 | only its own module changes it. Outside it, the variable, and every |
| 138 | 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. |
| 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. |
| 142 | 145 | |
| 143 | 146 | **Imports.** `import Out;` makes `Out`'s exports available as `Out.x`. |
| 144 | 147 | `import O := Out;` uses the name `O` instead. A module can't import |
| | @@ -253,11 +256,13 @@ |
| 253 | 256 | calls, or its own threads, which the C library wouldn't know about. |
| 254 | 257 | |
| 255 | 258 | **`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 |
| 257 | 260 | program is sure of them. An index out of range there reads or writes |
| 258 | 261 | 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. |
| 261 | 266 | |
| 262 | 267 | ## 4. Declarations |
| 263 | 268 | |
| | @@ -329,8 +334,10 @@ |
| 329 | 334 | |
| 330 | 335 | `INT` is the everyday integer: lengths, indexes and sizes are `INT`s. |
| 331 | 336 | 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). |
| 334 | 341 | |
| 335 | 342 | `F32` and `F64` exist only on a target that has reals (appendix A). On |
| 336 | 343 | one that hasn't, they, real literals and anything made of them are |
| | @@ -507,6 +514,12 @@ |
| 507 | 514 | - `A` is `INT` and `B` is `I64`, or `A` is `UINT` and `B` is `U64`, |
| 508 | 515 | which loses nothing on any target. |
| 509 | 516 | |
| 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 | + |
| 510 | 523 | Nothing else converts silently. In particular, there is no other |
| 511 | 524 | conversion between integer types, between integers and reals, or between `F32` |
| 512 | 525 | and `F64`, without a written conversion (section 6.7). |
| | @@ -553,7 +566,9 @@ |
| 553 | 566 | type, or one is an untyped constant that takes the other's type. The |
| 554 | 567 | result has that type and wraps around at its width: in `U8`, |
| 555 | 568 | `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`. |
| 557 | 572 | |
| 558 | 573 | `div` rounds toward zero and `mod` takes the sign of the dividend, as |
| 559 | 574 | in C: `-7 div 2` is `-3`, `-7 mod 2` is `-1`. Dividing by zero, and |
| | @@ -718,9 +733,9 @@ |
| 718 | 733 | For `CAS`, `XCHG` and `XADD`, `p` is a `^T` or `^VOLATILE T` where `T` |
| 719 | 734 | is an integer or pointer type as big as an address: `INT`, `UINT` or a |
| 720 | 735 | 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). |
| 724 | 739 | |
| 725 | 740 | ## 7. Statements |
| 726 | 741 | |
| | @@ -761,7 +776,9 @@ |
| 761 | 776 | `i <= b` (or `i >= b` if `s` is negative). `i` is a variable of an |
| 762 | 777 | integer or enumeration type, named by its name alone; `a` and then `b` |
| 763 | 778 | 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`. |
| 765 | 782 | |
| 766 | 783 | The loop never steps past `b`, so `i` can't wrap: afterwards `i` |
| 767 | 784 | holds the last value it took, or `a` if the body never ran. The body |
| | @@ -977,7 +994,7 @@ |
| 977 | 994 | types, and is allowed only in an `extern`. C takes no `float` there, |
| 978 | 995 | so an `F32` given to `...` is an error: the program writes `F64(x)`. |
| 979 | 996 | 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 |
| 981 | 998 | followed by a zero byte. |
| 982 | 999 | |
| 983 | 1000 | An `extern` variable is C's variable itself: reading it reads C's, |
| | @@ -1066,8 +1083,11 @@ |
| 1066 | 1083 | An instance of a generic module goes into the object file of the |
| 1067 | 1084 | module that made it, named by the generic module, its arguments, and |
| 1068 | 1085 | 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 |
| 1071 | 1091 | the same name hold the same code, and the program keeps one. |
| 1072 | 1092 | |
| 1073 | 1093 | **Messages.** The compiler reports an error with its file, line and |
| | @@ -1621,10 +1641,13 @@ |
| 1621 | 1641 | silently; pointers, procedures, `ERROR`s, slices and variants' tags |
| 1622 | 1642 | are sized by the address (section 5). Reals are a target's to have |
| 1623 | 1643 | 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. |
| 1628 | 1651 | |
| 1629 | 1652 | ## Appendix A. What an implementation chooses |
| 1630 | 1653 | |
| | @@ -1637,6 +1660,10 @@ |
| 1637 | 1660 | of an address, and so of `INT`, and whether it has reals. |
| 1638 | 1661 | - **Object files.** Their format, and the intermediate form of the |
| 1639 | 1662 | 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. |
| 1640 | 1667 | - **The calling convention.** On x86-64 Linux it is System V |
| 1641 | 1668 | (sections 8 and 9); elsewhere it is the C library's own, so that |
| 1642 | 1669 | `extern` procedures and callbacks work. How a procedure returns |