raz / commit 56f93056

commit
56f9305670870c12b67ce74bccf91c3d16c62026
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
500f3369
Report 2026-10.34: PTR(s), the address a slice starts at

The tenth thaw, by the owner's word, from PROPOSALS.md's "A slice's
pointer": PTR(s) is the first of a slice's two words, unchecked, so
that an empty slice becomes a pointer and a length where ADR(s[0])
stops the program; of an array, that of the slice of all of it, and
an error where that slice is. A predeclared name may be hidden, so it
breaks no program.

patch · log

2 files changed, +35 -3

doc/raz.md (history) modified +29 -3

@@ -13,7 +13,7 @@
1313 This report defines the language. It is short on purpose. Whatever it
1414 doesn't allow, raz doesn't have.
1515
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
1717 version's changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose,
1818 for a language anyone can build again. They break programs written
1919 for 2026-10.10 and before: for 2026-10.9, say, the report of compiler
@@ -46,7 +46,8 @@
4646 break no program; and the library's procedures that took a pointer to
4747 what they work on take a `var` parameter, a `const` one or a value
4848 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.
5051
5152 The language is frozen, softly, from this version on: it changes only
5253 to mend a defect, and its library grows only by what breaks no program
@@ -493,7 +494,8 @@
493494
494495 A slice is made from an array (`a[2..5]`, or an array used where a
495496 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).
497499
498500 ### 5.4 Pointers
499501
@@ -920,6 +922,7 @@
920922 | `SIZE(T)` | the size of type `T` in bytes, an untyped constant; `T` is a type, not a variable |
921923 | `ADR(x)` | the address of variable `x`, a `^T` |
922924 | `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)]` |
923926 | `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 |
924927 | `MSG(e)` | the message of the error `e`, a `[]U8` |
925928 | `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 @@
941944 alignment of `T`, and zeroes the bytes it gets if they aren't `nil`.
942945 `Mem.Allocator` (the library, `doc/raz-lib.md`) is the one type of the library the
943946 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.
944970
945971 `COPY` is a statement, as `INC` is. It copies the bytes of `LEN(s)`
946972 elements as one block, as an assignment of an array does, and is right

doc/report-history.md (history) modified +6 -0

@@ -211,3 +211,9 @@
211211 `replace`, `Sys`'s directories, `Thread.lock` and `unlock`, `Vec`
212212 (volume 2). That breaks a program that calls them with `ADR`; it is
213213 mended by writing `x` for `ADR(x)`, and `p^` for a pointer `p`.
214+- **2026-10.34.** A thaw, the tenth, by the owner's word. `PTR(s)` is
215+ the address a slice starts at, a `^T` for `s: []T`, with no check:
216+ `ADR(s[0])` when `s` isn't empty, and what the slice holds when it
217+ is, where `ADR(s[0])` stops the program; of an array, that of the
218+ slice of all of it (sections 5.3 and 6.8). A predeclared name may be
219+ hidden (section 2), so it breaks no program.