| | @@ -238,7 +238,7 @@ |
| 238 | 238 | not a variable: nothing that could write it, or let something else |
| 239 | 239 | write it, may name it or a field or element of it. So it can't be |
| 240 | 240 | assigned, passed as a `var` argument, changed by `INC`, `DEC` or |
| 241 | | -`NEW`, or given to `ADR`; an array in it is sliced, or used where a |
| 241 | +`NEW`, or given to `SYSTEM.ADR`; an array in it is sliced, or used where a |
| 242 | 242 | slice is expected (the silent conversion of an array, section 5.10), |
| 243 | 243 | only as a `[]const T`, whose elements can't be written (section 5.3); |
| 244 | 244 | a slice in it may be sliced, since that makes a new slice and can't |
| | @@ -255,6 +255,32 @@ |
| 255 | 255 | `import O := Out;` uses the name `O` instead. A module can't import |
| 256 | 256 | itself, directly or through others. |
| 257 | 257 | |
| 258 | +**`import SYSTEM`.** `SYSTEM` is no file but a module the language |
| 259 | +gives, of the operations that reach memory other than through the |
| 260 | +program's variables, or let something outside the program do so. A |
| 261 | +module that does any of these says `import SYSTEM;`, and it is an |
| 262 | +error to do them in one that doesn't: |
| 263 | + |
| 264 | +- `SYSTEM.ADR`, `SYSTEM.PTR`, `SYSTEM.SYSCALL` and `SYSTEM.ARGV` |
| 265 | + (section 6.8), which are written so, by that name; |
| 266 | +- `p + i`, `p - i`, `p[i]` and `p[lo..hi]` on a pointer (section 6.4); |
| 267 | +- a conversion to a pointer or a procedure type from an integer or |
| 268 | + from another pointer or procedure type, or from a pointer or a |
| 269 | + procedure to an integer (section 6.7), and a string literal given |
| 270 | + where a `^U8` is wanted (section 5.10); |
| 271 | +- a view whose type holds a pointer, a view written over a variable |
| 272 | + whose type holds anything but integers and reals, and `BYTES` of |
| 273 | + such a variable (sections 6.8 and 6.9); |
| 274 | +- `extern` and `link` of a library (section 9), code procedures |
| 275 | + (section 8) and `check off;` (below). |
| 276 | + |
| 277 | +`SYSTEM` can't be imported under another name, so that every module |
| 278 | +that reaches memory so says it by that name. What such a module does |
| 279 | +is its own to get right: section 10 says what isn't defined. A module |
| 280 | +that imports one that says `import SYSTEM` needn't say it itself; it |
| 281 | +trusts that module as it trusts the library, whose `Rt`, `Mem`, |
| 282 | +`Heap`, `Sys`, `Thread` and others say it. |
| 283 | + |
| 258 | 284 | **Generic modules** take types as parameters: |
| 259 | 285 | |
| 260 | 286 | ``` |
| | @@ -341,7 +367,7 @@ |
| 341 | 367 | (the library, `doc/raz-lib.md`) are kept for it: a program or another library doesn't |
| 342 | 368 | name a module of its own `Arena`, `Buf`, `C`, `Files`, `Fmt`, `Guarded`, |
| 343 | 369 | `Heap`, `List`, `Lock`, `Map`, `Math`, `Mem`, `Opt`, `Out`, `Rt`, |
| 344 | | -`Sort`, `Str`, `Sys`, `Task` or `Thread`, nor any name the library takes later. The |
| 370 | +`Sort`, `Str`, `Sys`, `SYSTEM`, `Task` or `Thread`, nor any name the library takes later. The |
| 345 | 371 | modules of any other library share a prefix of their own, as an X11 |
| 346 | 372 | library's `Xauth` and `Xkeys` do, and a program that wants a shorter |
| 347 | 373 | name imports one: `import Auth := Xauth;`. |
| | @@ -371,11 +397,13 @@ |
| 371 | 397 | are zero before any body runs. `return;` ends a body early. |
| 372 | 398 | |
| 373 | 399 | **`link "libX11.so.6";`** names a shared library to load at run time, |
| 374 | | -for the `extern` declarations of section 9. **`link static;`** says the |
| 400 | +for the `extern` declarations of section 9, in a module that imports |
| 401 | +`SYSTEM`. **`link static;`** says the |
| 375 | 402 | module needs a program without C (section 10): it makes its own system |
| 376 | 403 | calls, or its own threads, which the C library wouldn't know about. |
| 377 | 404 | |
| 378 | | -**`check off;`**, after the links, leaves out of the module's own code |
| 405 | +**`check off;`**, after the links, in a module that imports `SYSTEM`, |
| 406 | +leaves out of the module's own code |
| 379 | 407 | the checks of indexes and slice bounds of section 6.5, and that a slice |
| 380 | 408 | of a pointer doesn't run backwards (section 6.4), for speed where the |
| 381 | 409 | program is sure of them. An index out of range there reads or writes |
| | @@ -537,15 +565,15 @@ |
| 537 | 565 | |
| 538 | 566 | A slice is made from an array (`a[2..5]`, or an array used where a |
| 539 | 567 | slice is wanted), from another slice, or from a pointer (`p[0..n]`). It |
| 540 | | -doesn't own what it points at. `LEN(s)` is its count, and `PTR(s)` its |
| 541 | | -pointer (section 6.8). |
| 568 | +doesn't own what it points at. `LEN(s)` is its count, and |
| 569 | +`SYSTEM.PTR(s)` its pointer (section 6.8). |
| 542 | 570 | |
| 543 | 571 | `[]const T` is a slice whose elements can't be written through it. It |
| 544 | 572 | is laid out as `[]T` is. Its elements are read, and it is sliced, and a |
| 545 | 573 | slice of it is a `[]const T` too; but an element of it isn't assigned, |
| 546 | 574 | given to `COPY` or `FILL` as the destination, changed by `INC` or `DEC`, |
| 547 | | -passed as a `var` argument, or written through a view, and `ADR` of one |
| 548 | | -is an error. A `[]T` and an array of `T` go silently where a |
| 575 | +passed as a `var` argument, or written through a view, and |
| 576 | +`SYSTEM.ADR` of one is an error. A `[]T` and an array of `T` go silently where a |
| 549 | 577 | `[]const T` is wanted, never the other way (section 5.10). So a |
| 550 | 578 | procedure that only reads a slice takes a `[]const T`, and every |
| 551 | 579 | caller's slice or array fits it: |
| | @@ -586,7 +614,7 @@ |
| 586 | 614 | other, on every target, even one whose machine can't reach a |
| 587 | 615 | misaligned word in one access: the compiled code reaches it in parts |
| 588 | 616 | there. But a field of a packed record whose type is aligned to more |
| 589 | | -than 1 byte, and anything inside it, has no address: `ADR` of it, a |
| 617 | +than 1 byte, and anything inside it, has no address: `SYSTEM.ADR` of it, a |
| 590 | 618 | `var` parameter of it and a slice of it are errors. Nor can it be |
| 591 | 619 | reached through a `^VOLATILE` pointer, since a misaligned access can't |
| 592 | 620 | be promised as one access (section 7.6). Its value can be copied out |
| | @@ -730,7 +758,7 @@ |
| 730 | 758 | it is written, named or not: two `record x: I64; end` are two types. |
| 731 | 759 | A named and an anonymous type are the |
| 732 | 760 | same if the named one is built like the anonymous one, so that |
| 733 | | -`p := ADR(n)` works for `p: NodePtr` with `type NodePtr = ^Node`. |
| 761 | +`p := SYSTEM.ADR(n)` works for `p: NodePtr` with `type NodePtr = ^Node`. |
| 734 | 762 | Sameness doesn't pass through the anonymous type: with `type P1 = |
| 735 | 763 | ^Node; P2 = ^Node;`, each of `P1` and `P2` is the same as `^Node`, but |
| 736 | 764 | they are two declarations, so not the same as each other. |
| | @@ -747,9 +775,10 @@ |
| 747 | 775 | - `A` is `^T` and `B` is `^VOLATILE T`; |
| 748 | 776 | - `A` is `[n]T` and `B` is `[]T` or `[]const T`, or `A` is `[]T` and |
| 749 | 777 | `B` is `[]const T`; |
| 750 | | -- `A` is a string literal and `B` is `[]const U8`, `^U8` (a pointer to the |
| 751 | | - bytes followed by a zero byte, as C wants), or `[n]U8` with `n` at |
| 752 | | - least the string's length (the rest is zero); |
| 778 | +- `A` is a string literal and `B` is `[]const U8`, `[n]U8` with `n` at |
| 779 | + least the string's length (the rest is zero), or, in a module that |
| 780 | + imports `SYSTEM`, `^U8` (a pointer to the bytes followed by a zero |
| 781 | + byte, as C wants); |
| 753 | 782 | - `A` is a procedure and `B` a procedure type with the same signature; |
| 754 | 783 | - `A` is `INT` and `B` is `I64`, or `A` is `UINT` and `B` is `U64`, |
| 755 | 784 | which loses nothing on any target; |
| | @@ -942,6 +971,10 @@ |
| 942 | 971 | elements are `p^[i]`. |
| 943 | 972 | - Pointers compare with `= # < <= > >=` as unsigned addresses. |
| 944 | 973 | Procedure values compare with `=` and `#` only. |
| 974 | + |
| 975 | +`p + i`, `p - i`, `p[i]` and `p[lo..hi]` reach memory no variable of |
| 976 | +the program names, and are allowed only in a module that imports |
| 977 | +`SYSTEM` (section 3). `p^`, `p - q` and comparing are allowed in any. |
| 945 | 978 | |
| 946 | 979 | ### 6.5 Arrays and slices |
| 947 | 980 | |
| | @@ -1023,7 +1056,10 @@ |
| 1023 | 1056 | |
| 1024 | 1057 | There are no others: none from an integer to `BOOL` (`x # 0` says it), |
| 1025 | 1058 | none between pointers and integers other than `INT` and `UINT`, and none to |
| 1026 | | -or from records, arrays, slices, variants or `ERROR`. An untyped integer constant converts to a pointer as an `INT` does, as |
| 1059 | +or from records, arrays, slices, variants or `ERROR`. The last three |
| 1060 | +rows, from an integer to a pointer or a procedure, back, and from one |
| 1061 | +pointer or procedure type to another, are allowed only in a module |
| 1062 | +that imports `SYSTEM` (section 3). An untyped integer constant converts to a pointer as an `INT` does, as |
| 1027 | 1063 | in `^VOLATILE U32(0FEE00000H)`; it isn't assigned to a pointer without |
| 1028 | 1064 | the conversion. A conversion of a constant is made by the compiler, by |
| 1029 | 1065 | the same rules: `U8(300)` is 44. `U64(a = b)` is 0 or 1, and |
| | @@ -1037,15 +1073,15 @@ |
| 1037 | 1073 | | `SIZE(T)` | the size of type `T` in bytes, an untyped constant; `T` is a type, not a variable | |
| 1038 | 1074 | | `SIZE(T.f)` | the size of field `f` of the record type `T`, an untyped constant | |
| 1039 | 1075 | | `OFFSET(T, f)` | the byte offset of field `f` in the record type `T`, an untyped constant | |
| 1040 | | -| `ADR(x)` | the address of variable `x`, a `^T` | |
| 1076 | +| `SYSTEM.ADR(x)` | the address of variable `x`, a `^T` | |
| 1041 | 1077 | | `LEN(a)` | the number of elements of an array or a string constant (an untyped constant) or of a slice (an `INT`) | |
| 1042 | | -| `PTR(s)` | the address the slice `s` starts at, a `^T` for `s: []T`, unchecked; for an array `a`, that of `a[0..LEN(a)]` | |
| 1078 | +| `SYSTEM.PTR(s)` | the address the slice `s` starts at, a `^T` for `s: []T` or `[]const T`, unchecked; for an array `a`, that of `a[0..LEN(a)]` | |
| 1043 | 1079 | | `BYTES(x)` | the bytes of `x` as a `[]U8`: for a slice `s: []T`, its `LEN(s) * SIZE(T)` bytes, a `[]const U8` for a `[]const T`; for a variable of any other type `T`, its `SIZE(T)` bytes | |
| 1044 | 1080 | | `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 | |
| 1045 | 1081 | | `MSG(e)` | the message of the error `e`, a `[]const U8` | |
| 1046 | 1082 | | `COPY(d, s)` | copies the elements of `s` to the start of `d`, both arrays or slices of one type `T`; `LEN(s)` must be at most `LEN(d)` | |
| 1047 | 1083 | | `FILL(d, x)` | sets every element of `d`, an array or a slice of elements of type `T`, to `x`, a value of `T` | |
| 1048 | | -| `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`) | |
| 1084 | +| `SYSTEM.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`) | |
| 1049 | 1085 | | `INC(v)`, `INC(v, k)` | adds 1, or `k`, to the integer variable `v`; it wraps, like `+` | |
| 1050 | 1086 | | `DEC(v)`, `DEC(v, k)` | subtracts 1, or `k`, from `v` | |
| 1051 | 1087 | | `FENCE` | a full memory barrier | |
| | @@ -1058,9 +1094,9 @@ |
| 1058 | 1094 | | `POPCOUNT(x)` | the number of one bits in `x`, or of members of the set `x`, an `INT`; `x` of an unsigned integer type or a set | |
| 1059 | 1095 | | `MIN(T)`, `MAX(T)` | the smallest, or the largest, value of the integer type `T`, an untyped constant; any other type is an error | |
| 1060 | 1096 | | `ARGC()` | the number of command line arguments, an `INT` | |
| 1061 | | -| `ARGV()` | the arguments, a `^^U8` (C strings) | |
| 1097 | +| `SYSTEM.ARGV()` | the arguments, a `^^U8` (C strings) | |
| 1062 | 1098 | |
| 1063 | | -`SYSCALL` exists only on Linux targets. Other systems have no stable |
| 1099 | +`SYSTEM.SYSCALL` exists only on Linux targets. Other systems have no stable |
| 1064 | 1100 | system call interface, and their modules call the C library instead |
| 1065 | 1101 | (section 9). |
| 1066 | 1102 | |
| | @@ -1087,19 +1123,21 @@ |
| 1087 | 1123 | `T` must be a type a view may take (section 6.9), since writing through |
| 1088 | 1124 | the slice must not make a value mean nothing: a `BOOL`, a set, an |
| 1089 | 1125 | enumeration, a slice, a variant, a procedure type, `ERROR`, or a record |
| 1090 | | -or array holding one, is an error. The slice is made, and checked, as |
| 1126 | +or array holding one, is an error; and, outside a module that imports |
| 1127 | +`SYSTEM`, so is a pointer, or a record or array holding one. The slice |
| 1128 | +is made, and checked, as |
| 1091 | 1129 | any slice of the variable is, so its bytes follow the rules for it: the |
| 1092 | 1130 | bytes of a local can't be returned (section 7.3). Of a slice they are |
| 1093 | | -its elements, as `PTR(s)` gives them, whatever holds the slice, and |
| 1094 | | -can be written only if the slice can. Of any |
| 1095 | | -other variable they are its own, as `ADR` gives them: a `const` |
| 1096 | | -parameter, another module's variable, a view and a field of a packed |
| 1097 | | -record are errors, as they are for `ADR`, and so is a volatile variable. |
| 1131 | +its elements, as `SYSTEM.PTR(s)` gives them, whatever holds the slice, |
| 1132 | +and can be written only if the slice can. Of any other variable they |
| 1133 | +are its own, as `SYSTEM.ADR` gives them: a `const` parameter, another |
| 1134 | +module's variable, a view and a field of a packed record are errors, |
| 1135 | +as they are for `SYSTEM.ADR`, and so is a volatile variable. |
| 1098 | 1136 | `x` must be a variable: a constant, a string constant too, is an error. |
| 1099 | 1137 | The bytes are in the target's order (appendix A). |
| 1100 | 1138 | |
| 1101 | | -`PTR(s)` is the first of the two words of `s` (section 5.3), and is not |
| 1102 | | -checked. For a slice that isn't empty it is `ADR(s[0])`; for an empty |
| 1139 | +`SYSTEM.PTR(s)` is the first of the two words of `s` (section 5.3), and |
| 1140 | +is not checked. For a slice that isn't empty it is `SYSTEM.ADR(s[0])`; for an empty |
| 1103 | 1141 | one, where `s[0]` would stop the program, it is what the slice holds: |
| 1104 | 1142 | `nil` for a slice variable as it starts (section 4) and for `[]`, and |
| 1105 | 1143 | for one cut empty from another, `t[3..3]`, an address that mustn't be |
| | @@ -1112,13 +1150,13 @@ |
| 1112 | 1150 | |
| 1113 | 1151 | proc valueOf(s: []const U8): Value; |
| 1114 | 1152 | begin |
| 1115 | | - return {n: LEN(s), p: PTR(s)}; (* "" too *) |
| 1153 | + return {n: LEN(s), p: SYSTEM.PTR(s)}; (* "" too *) |
| 1116 | 1154 | end; |
| 1117 | 1155 | ``` |
| 1118 | 1156 | |
| 1119 | 1157 | and `v.p[0..v.n]` is the slice again (section 6.4), empty when `v.n` |
| 1120 | 1158 | is 0, whatever `v.p` is. Reading through the pointer is as unchecked as |
| 1121 | | -through any pointer. `PTR(a)` of an array may be taken wherever the |
| 1159 | +through any pointer. `SYSTEM.PTR(a)` of an array may be taken wherever the |
| 1122 | 1160 | slice `a[0..LEN(a)]` may be made, and is an error wherever it may not. |
| 1123 | 1161 | |
| 1124 | 1162 | `COPY` is a statement, as `INC` is. It copies the bytes of `LEN(s)` |
| | @@ -1147,7 +1185,7 @@ |
| 1147 | 1185 | target, and may be volatile: a counter shared between threads is |
| 1148 | 1186 | `XADD(count, 1)`, one reached through a pointer `XADD(p^, 1)`. It is |
| 1149 | 1187 | evaluated once, and must have an address, so a field of a packed |
| 1150 | | -record and a view are errors, as they are for `ADR`. They are sequentially consistent, on every target; how a |
| 1188 | +record and a view are errors, as they are for `SYSTEM.ADR`. They are sequentially consistent, on every target; how a |
| 1151 | 1189 | machine without atomic instructions makes them so is the |
| 1152 | 1190 | implementation's choice (appendix A). |
| 1153 | 1191 | ### 6.9 Views |
| | @@ -1199,6 +1237,13 @@ |
| 1199 | 1237 | name of one, a field or element of one, or what a pointer points at; |
| 1200 | 1238 | not a constant, nor the result of a call or of an operator. |
| 1201 | 1239 | |
| 1240 | +A view makes values from bytes, so where those bytes could be made |
| 1241 | +into an address the module must import `SYSTEM` (section 3): a view |
| 1242 | +whose `T` holds a pointer, and a view written over a variable `v` |
| 1243 | +whose type holds anything but integers and reals, which would change |
| 1244 | +a pointer, a `BOOL` or a slice behind its type. Reading any variable |
| 1245 | +through a view of integers and reals is allowed in any module. |
| 1246 | + |
| 1202 | 1247 | **Where its bytes lie.** The `T` lies within the variable `v` is part |
| 1203 | 1248 | of: |
| 1204 | 1249 | |
| | @@ -1218,7 +1263,8 @@ |
| 1218 | 1263 | `I64` whose first byte is `mem[3]`. As a field of a packed record is |
| 1219 | 1264 | (section 5.5), it is read and written on every target, in parts where |
| 1220 | 1265 | the machine needs that; and, as such a field, a view has no address: |
| 1221 | | -`ADR` of it, a `var` argument of it and a slice of it are errors. Copy |
| 1266 | +`SYSTEM.ADR` of it, a `var` argument of it and a slice of it are |
| 1267 | +errors. Copy |
| 1222 | 1268 | it out to a variable, and back in. A view of a volatile variable is an |
| 1223 | 1269 | error too, since its access can't be promised as one (section 7.6): a |
| 1224 | 1270 | device's registers are reached through a `^VOLATILE` pointer to a |
| | @@ -1233,12 +1279,13 @@ |
| 1233 | 1279 | and may still: `mem[a].(I64) := n` does what |
| 1234 | 1280 | |
| 1235 | 1281 | ``` |
| 1236 | | -p := ^I64(ADR(mem[a])); |
| 1282 | +p := ^I64(SYSTEM.ADR(mem[a])); |
| 1237 | 1283 | p^ := n; |
| 1238 | 1284 | ``` |
| 1239 | 1285 | |
| 1240 | 1286 | does, but with `a` checked against the length of `mem`, no pointer |
| 1241 | | -variable, and no address of a word that may be misaligned. |
| 1287 | +variable, and no address of a word that may be misaligned, and no |
| 1288 | +`import SYSTEM`. |
| 1242 | 1289 | |
| 1243 | 1290 | `v` is evaluated once, and its check made, before the bytes are read |
| 1244 | 1291 | or written. |
| | @@ -1463,8 +1510,14 @@ |
| 1463 | 1510 | thread writes while another reads or writes it, unless both use |
| 1464 | 1511 | volatile accesses or the atomic built-ins, or a `FENCE` orders them, |
| 1465 | 1512 | holds no particular value then: a read of it gives a value it had or |
| 1466 | | -was given, or a mixture of their bytes. Nothing else of the program |
| 1467 | | -becomes undefined by it. |
| 1513 | +was given, or a mixture of their bytes. For a variable of a basic, |
| 1514 | +enumeration or set type, or a record or array of these, nothing else |
| 1515 | +of the program becomes undefined by it. For one that holds a pointer, |
| 1516 | +a procedure, a slice, an `ERROR` or a variant, a mixture may be an |
| 1517 | +address no variable has, or a slice's address with another's length, |
| 1518 | +or a case's tag with another's fields, and what follows isn't defined |
| 1519 | +(section 10). A program that shares such a variable between threads |
| 1520 | +orders their accesses, with a lock or the atomic built-ins. |
| 1468 | 1521 | |
| 1469 | 1522 | ### 7.7 Defer |
| 1470 | 1523 | |
| | @@ -1631,8 +1684,8 @@ |
| 1631 | 1684 | A `const` parameter is the caller's variable too, read in place, |
| 1632 | 1685 | whatever its size, with nothing copied; the procedure may only read it. |
| 1633 | 1686 | It may not assign it or a part of it (a field, an element of an array |
| 1634 | | -in it), give it or a part of it to a `var` parameter, take the `ADR` of |
| 1635 | | -either, write it through a view (section 6.9), or assign the names a |
| 1687 | +in it), give it or a part of it to a `var` parameter, take the |
| 1688 | +`SYSTEM.ADR` of either, write it through a view (section 6.9), or assign the names a |
| 1636 | 1689 | `match` arm gives its fields. What a slice or a pointer in it points at |
| 1637 | 1690 | isn't part of it: the procedure may write through them, as it may |
| 1638 | 1691 | through a value parameter's; but a slice it makes of an array in it is |
| | @@ -1714,7 +1767,8 @@ |
| 1714 | 1767 | Procedures don't nest. |
| 1715 | 1768 | |
| 1716 | 1769 | **Code procedures.** A procedure whose body is `code` is machine code, |
| 1717 | | -written by hand in the target's assembly language (appendix A): one |
| 1770 | +written by hand in the target's assembly language (appendix A), in a |
| 1771 | +module that imports `SYSTEM`: one |
| 1718 | 1772 | instruction to each `;`, and labels for jumps, up to `end`: |
| 1719 | 1773 | |
| 1720 | 1774 | ``` |
| | @@ -1761,7 +1815,8 @@ |
| 1761 | 1815 | ``` |
| 1762 | 1816 | |
| 1763 | 1817 | An `extern` procedure or variable is found by its name in the C |
| 1764 | | -libraries the program links: the C library always, and each library |
| 1818 | +libraries the program links, and is declared only in a module that |
| 1819 | +imports `SYSTEM` (section 3), since C can reach any memory: the C library always, and each library |
| 1765 | 1820 | named by `link`. |
| 1766 | 1821 | |
| 1767 | 1822 | An `extern` procedure's parameters and result are integers, `BOOL`, |
| | @@ -1786,9 +1841,9 @@ |
| 1786 | 1841 | ``` |
| 1787 | 1842 | var ev: [24]I64; (* XEvent: 192 bytes *) |
| 1788 | 1843 | ... |
| 1789 | | -XNextEvent(dpy, ADR(ev)); |
| 1844 | +XNextEvent(dpy, SYSTEM.ADR(ev)); |
| 1790 | 1845 | if I32(ev[0]) = KeyPress then |
| 1791 | | - key := ^XKeyEvent(ADR(ev)); |
| 1846 | + key := ^XKeyEvent(SYSTEM.ADR(ev)); |
| 1792 | 1847 | ... |
| 1793 | 1848 | end; |
| 1794 | 1849 | ``` |
| | @@ -1837,12 +1892,16 @@ |
| 1837 | 1892 | **Defined behaviour.** Every variable starts at zero, integers wrap, |
| 1838 | 1893 | and indexing arrays and slices is checked, so a program's behaviour is |
| 1839 | 1894 | defined by this report, with one exception: memory reached other than |
| 1840 | | -through a checked variable. Dereferencing a stale or made-up pointer, |
| 1841 | | -indexing through a pointer, a slice kept after the call whose frame |
| 1842 | | -holds what it points at (section 7.3), an index out of range in a |
| 1843 | | -module that says `check off;`, writing a string's bytes, a code procedure that |
| 1844 | | -breaks its rules, and C code can read or write any memory, and what |
| 1845 | | -follows isn't defined. Dereferencing `nil`, dividing |
| 1895 | +through a checked variable. In any module, three things reach it: a |
| 1896 | +pointer used after the memory it points at was given back (by |
| 1897 | +`Heap`'s `free` or an arena's reset, say), a slice kept after the |
| 1898 | +call whose frame holds what it points at (section 7.3), and a race on |
| 1899 | +a variable that holds a pointer, a slice or a variant (section 7.6). |
| 1900 | +In a module that imports `SYSTEM`, so does what that module does there |
| 1901 | +(section 3): a made-up pointer, indexing through a pointer, an index |
| 1902 | +out of range under `check off;`, writing a string's bytes through a |
| 1903 | +`^U8`, a code procedure that breaks its rules, and C code. Each can |
| 1904 | +read or write any memory, and what follows isn't defined. Dereferencing `nil`, dividing |
| 1846 | 1905 | by zero, calling a `nil` procedure and running out of stack stop the |
| 1847 | 1906 | program, on every target, with status 2, as a failed check does. |
| 1848 | 1907 | Before it stops, the program prints to |
| | @@ -1914,7 +1973,7 @@ |
| 1914 | 1973 | implementation's. |
| 1915 | 1974 | - **What is the target's.** Code procedures (section 8) hold the |
| 1916 | 1975 | target's machine code, written in its assembly language, and exist |
| 1917 | | - only where the implementation says so; `SYSCALL` exists only on Linux targets (section 6.8). A record's |
| 1976 | + only where the implementation says so; `SYSTEM.SYSCALL` exists only on Linux targets (section 6.8). A record's |
| 1918 | 1977 | layout is the target's C layout (section 5.5), and the order of a |
| 1919 | 1978 | value's bytes is the target's (little-endian on x86-64). |
| 1920 | 1979 | - **The assembly language.** How a code procedure's instructions are |