| | @@ -13,7 +13,7 @@ |
| 13 | 13 | This report defines the language. It is short on purpose. Whatever it |
| 14 | 14 | doesn't allow, raz doesn't have. |
| 15 | 15 | |
| 16 | | -This is version 2026-10.33 of the report; section 11 says where each |
| 16 | +This is version 2026-10.34 of the report; section 11 says where each |
| 17 | 17 | version's changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, |
| 18 | 18 | for a language anyone can build again. They break programs written |
| 19 | 19 | for 2026-10.10 and before: for 2026-10.9, say, the report of compiler |
| | @@ -46,7 +46,8 @@ |
| 46 | 46 | break no program; and the library's procedures that took a pointer to |
| 47 | 47 | what they work on take a `var` parameter, a `const` one or a value |
| 48 | 48 | instead (the library volume), which breaks a program that calls them |
| 49 | | -with `ADR`. |
| 49 | +with `ADR`. 2026-10.34 is a tenth: `PTR(s)`, the address a slice |
| 50 | +starts at, even an empty one (section 6.8); it breaks no program. |
| 50 | 51 | |
| 51 | 52 | The language is frozen, softly, from this version on: it changes only |
| 52 | 53 | to mend a defect, and its library grows only by what breaks no program |
| | @@ -493,7 +494,8 @@ |
| 493 | 494 | |
| 494 | 495 | A slice is made from an array (`a[2..5]`, or an array used where a |
| 495 | 496 | slice is wanted), from another slice, or from a pointer (`p[0..n]`). It |
| 496 | | -doesn't own what it points at. |
| 497 | +doesn't own what it points at. `LEN(s)` is its count, and `PTR(s)` its |
| 498 | +pointer (section 6.8). |
| 497 | 499 | |
| 498 | 500 | ### 5.4 Pointers |
| 499 | 501 | |
| | @@ -920,6 +922,7 @@ |
| 920 | 922 | | `SIZE(T)` | the size of type `T` in bytes, an untyped constant; `T` is a type, not a variable | |
| 921 | 923 | | `ADR(x)` | the address of variable `x`, a `^T` | |
| 922 | 924 | | `LEN(a)` | the number of elements of an array or a string constant (an untyped constant) or of a slice (an `INT`) | |
| 925 | +| `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)]` | |
| 923 | 926 | | `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 | |
| 924 | 927 | | `MSG(e)` | the message of the error `e`, a `[]U8` | |
| 925 | 928 | | `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)` | |
| | @@ -941,6 +944,29 @@ |
| 941 | 944 | alignment of `T`, and zeroes the bytes it gets if they aren't `nil`. |
| 942 | 945 | `Mem.Allocator` (the library, `doc/raz-lib.md`) is the one type of the library the |
| 943 | 946 | language names. |
| 947 | + |
| 948 | +`PTR(s)` is the first of the two words of `s` (section 5.3), and is not |
| 949 | +checked. For a slice that isn't empty it is `ADR(s[0])`; for an empty |
| 950 | +one, where `s[0]` would stop the program, it is what the slice holds: |
| 951 | +`nil` for a slice variable as it starts (section 4) and for `[]`, and |
| 952 | +for one cut empty from another, `t[3..3]`, an address that mustn't be |
| 953 | +read through, as the end of an array mustn't. So a slice becomes a |
| 954 | +pointer and a length, for a record or for C, with no test for the |
| 955 | +empty one first: |
| 956 | + |
| 957 | +``` |
| 958 | +type Value = record n: INT; p: ^U8; end; |
| 959 | + |
| 960 | +proc valueOf(s: []U8): Value; |
| 961 | +begin |
| 962 | + return {n: LEN(s), p: PTR(s)}; (* "" too *) |
| 963 | +end; |
| 964 | +``` |
| 965 | + |
| 966 | +and `v.p[0..v.n]` is the slice again (section 6.4), empty when `v.n` |
| 967 | +is 0, whatever `v.p` is. Reading through the pointer is as unchecked as |
| 968 | +through any pointer. `PTR(a)` of an array may be taken wherever the |
| 969 | +slice `a[0..LEN(a)]` may be made, and is an error wherever it may not. |
| 944 | 970 | |
| 945 | 971 | `COPY` is a statement, as `INC` is. It copies the bytes of `LEN(s)` |
| 946 | 972 | elements as one block, as an assignment of an array does, and is right |