BYTES(x): a variable's bytes as a []U8, as report 2026-10.36 has them
Sym enters BYTES; Parse's builtin hands the item to Item's bytesOf,
which makes it a slice in a temporary: of a slice s: []T, PTR(s) and
LEN(s) * SIZE(T), its words read as PTR and LEN read them (a call's
two words, or a slice through an address on the stack, go to a
temporary first); of any other variable v: T, ADR(v) and SIZE(T), so
a register variable goes to memory. It refuses a string constant,
another constant or a call's result, what is only read, a volatile
variable, a packed record's field and a view, as ADR and PTR do; and,
by bytesType over the view's notPlain, a type a view may not take,
its help naming the record's field that holds it. The slice keeps x's
frame mark, so notOfFrame refuses returning the bytes of a local, a
field or an element of one, as a slice of one.
Tests: conform/run/BytesOf (a record, an array, a []I32, written
through and read back, their lengths, an empty slice, a field, an
element, p^, a var parameter, a call's slice, bytes returned of a
module variable); conform/err Bytes{RecordBool,SliceEnum,Bool,Const,
View,Volatile,String,Packed,Value,Export,Frame}, their messages in
test/msg. compiler.md, the editors' built-in lists and CLAUDE.md's
readings say so. Code lines 11,926 -> 11,996.
| @@ -358,3 +358,11 @@ | ||
| 358 | 358 | `M.T` is read whole and a `.` past the type is a field's, |
| 359 | 359 | `SIZE(M.T.f)` too. `T` must be a record type (a variant is refused, |
| 360 | 360 | with help); a path `a.b` is refused, its help naming `a`'s type. |
| 361 | + `BYTES(x)`: of a slice, its `PTR` and `LEN * SIZE(T)`, with no check | |
| 362 | + of what holds the slice (a `const` one, another module's, a field of | |
| 363 | + a packed record), as for `PTR`; of anything else, a variable's | |
| 364 | + address and size, refused, as `ADR` refuses, for what is only read, | |
| 365 | + and, beyond `ADR`, for a volatile variable; a constant of any kind | |
| 366 | + is no variable. `T` is refused by the view's `notPlain`. The result | |
| 367 | + keeps `x`'s `frame`, so the bytes of a local are caught by | |
| 368 | + `notOfFrame` as far as a slice of it is. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module BytesBool; | |
| 2 | +proc main*; | |
| 3 | +var done: BOOL; b: []U8; | |
| 4 | +begin | |
| 5 | + b := BYTES(done); | |
| 6 | +end; | |
| 7 | +end BytesBool. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module BytesConst; | |
| 2 | +type Header = record magic: U32; count: U32; end; | |
| 3 | +proc send(const h: Header): INT; | |
| 4 | +begin | |
| 5 | + return LEN(BYTES(h)); | |
| 6 | +end; | |
| 7 | +end BytesConst. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module BytesExport; | |
| 2 | +import Owner; | |
| 3 | +proc main*; | |
| 4 | +var b: []U8; | |
| 5 | +begin | |
| 6 | + b := BYTES(Owner.n); | |
| 7 | +end; | |
| 8 | +end BytesExport. |
| @@ -0,0 +1,52 @@ | ||
| 1 | +module BytesFrame; | |
| 2 | +(* the bytes of a local can't be returned, a field or an element of one | |
| 3 | + included (report section 7.3); those of a var parameter, a module | |
| 4 | + variable, what a pointer points at, or a slice given, can *) | |
| 5 | + | |
| 6 | +type | |
| 7 | + Header = record magic: U32; count: U32; end; | |
| 8 | + | |
| 9 | +var g: Header; | |
| 10 | + | |
| 11 | +proc local: []U8; | |
| 12 | +var h: Header; | |
| 13 | +begin | |
| 14 | + return BYTES(h); (* the procedure's own variable *) | |
| 15 | +end; | |
| 16 | + | |
| 17 | +proc field: []U8; | |
| 18 | +var h: Header; | |
| 19 | +begin | |
| 20 | + return BYTES(h.count); (* a field of one *) | |
| 21 | +end; | |
| 22 | + | |
| 23 | +proc element(i: INT): ([]U8, INT); | |
| 24 | +var a: [4]I32; | |
| 25 | +begin | |
| 26 | + return BYTES(a[i]), i; (* an element of one, one of several results *) | |
| 27 | +end; | |
| 28 | + | |
| 29 | +proc param(h: Header): []U8; | |
| 30 | +begin | |
| 31 | + return BYTES(h); (* the procedure's copy *) | |
| 32 | +end; | |
| 33 | + | |
| 34 | +proc scalar: []U8; | |
| 35 | +var n: I64; | |
| 36 | +begin | |
| 37 | + n := 1; | |
| 38 | + return BYTES(n); (* a local that may live in a register *) | |
| 39 | +end; | |
| 40 | + | |
| 41 | +proc part: []U8; | |
| 42 | +var a: [4]I32; | |
| 43 | +begin | |
| 44 | + return BYTES(a[1..3]); (* a slice of a local array *) | |
| 45 | +end; | |
| 46 | + | |
| 47 | +proc ok(var h: Header; s: []I32; p: ^Header): ([]U8, []U8, []U8, []U8); | |
| 48 | +begin | |
| 49 | + return BYTES(h), BYTES(s), BYTES(p^), BYTES(g); | |
| 50 | +end; | |
| 51 | + | |
| 52 | +end BytesFrame. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module BytesPacked; | |
| 2 | +type R = packed record tag: U8; word: I32; end; | |
| 3 | +proc main*; | |
| 4 | +var r: R; b: []U8; | |
| 5 | +begin | |
| 6 | + b := BYTES(r.word); | |
| 7 | +end; | |
| 8 | +end BytesPacked. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module BytesRecordBool; | |
| 2 | +type Entry = record key: U32; live: BOOL; end; | |
| 3 | +proc main*; | |
| 4 | +var e: Entry; b: []U8; | |
| 5 | +begin | |
| 6 | + b := BYTES(e); | |
| 7 | +end; | |
| 8 | +end BytesRecordBool. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module BytesSliceEnum; | |
| 2 | +type Colour = (red, green, blue); | |
| 3 | +proc paint(s: []Colour): []U8; | |
| 4 | +begin | |
| 5 | + return BYTES(s); | |
| 6 | +end; | |
| 7 | +end BytesSliceEnum. |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module BytesString; | |
| 2 | +const Hello = "hello"; | |
| 3 | +proc main*; | |
| 4 | +var b: []U8; | |
| 5 | +begin | |
| 6 | + b := BYTES(Hello); | |
| 7 | +end; | |
| 8 | +end BytesString. |
| @@ -0,0 +1,11 @@ | ||
| 1 | +module BytesValue; | |
| 2 | +proc seven: I64; | |
| 3 | +begin | |
| 4 | + return 7; | |
| 5 | +end; | |
| 6 | +proc main*; | |
| 7 | +var b: []U8; | |
| 8 | +begin | |
| 9 | + b := BYTES(seven()); | |
| 10 | +end; | |
| 11 | +end BytesValue. |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module BytesView; | |
| 2 | +proc main*; | |
| 3 | +var mem: [16]U8; b: []U8; | |
| 4 | +begin | |
| 5 | + b := BYTES(mem[3].(I64)); | |
| 6 | +end; | |
| 7 | +end BytesView. |
| @@ -0,0 +1,9 @@ | ||
| 1 | +module BytesVolatile; | |
| 2 | +type Regs = record ctrl: U32; status: U32; end; | |
| 3 | +proc main*; | |
| 4 | +var r: ^VOLATILE Regs; b: []U8; | |
| 5 | +begin | |
| 6 | + r := ^VOLATILE Regs(0FEE00000H); | |
| 7 | + b := BYTES(r^); | |
| 8 | +end; | |
| 9 | +end BytesVolatile. |
| @@ -0,0 +1,14 @@ | ||
| 1 | +8 8 | |
| 2 | +2 1 | |
| 3 | +CAFEF00D 513 3 | |
| 4 | +3 | |
| 5 | +6 -1 256 | |
| 6 | +7 | |
| 7 | +12 12 | |
| 8 | +10 21 41 | |
| 9 | +4 16 | |
| 10 | +0 0 | |
| 11 | +16 21 | |
| 12 | +715 | |
| 13 | +0 0 | |
| 14 | +4 same |
| @@ -0,0 +1,79 @@ | ||
| 1 | +(* BYTES(x), the bytes of x as a []U8 (report section 6.8): of a | |
| 2 | + record, an array and a []I32 slice, read and written through; their | |
| 3 | + lengths, SIZE(T) or LEN(s) * SIZE(T); an empty slice's; and the | |
| 4 | + bytes of a field and an element, of what a pointer points at, of a | |
| 5 | + var parameter, and of a slice a call returns. Bytes are compared | |
| 6 | + with a view of the same place, which is the target's order too. *) | |
| 7 | +module BytesOf; | |
| 8 | +import Out; | |
| 9 | + | |
| 10 | +type | |
| 11 | + Header = record magic: U32; count: U16; flags: U8; end; | |
| 12 | + | |
| 13 | +var g: [4]I32; | |
| 14 | + | |
| 15 | +(* the bytes of h, given as a var parameter, written zero *) | |
| 16 | +proc clear(var h: Header); | |
| 17 | +var b: []U8; i: INT; | |
| 18 | +begin | |
| 19 | + b := BYTES(h); | |
| 20 | + for i := 0 to LEN(b) - 1 do b[i] := 0; end; | |
| 21 | +end; | |
| 22 | + | |
| 23 | +(* the module's array, as a slice a call returns *) | |
| 24 | +proc whole: []I32; | |
| 25 | +begin | |
| 26 | + return g; | |
| 27 | +end; | |
| 28 | + | |
| 29 | +(* the bytes of the module's array, returned: they outlive the call *) | |
| 30 | +proc gBytes: []U8; | |
| 31 | +begin | |
| 32 | + return BYTES(g); | |
| 33 | +end; | |
| 34 | + | |
| 35 | +proc main*; | |
| 36 | +var h: Header; a: [3]I16; s, none: []I32; b: []U8; p: ^Header; n: I32; i: INT; | |
| 37 | +begin | |
| 38 | + h := {magic: 1, count: 2, flags: 3}; | |
| 39 | + b := BYTES(h); | |
| 40 | + Out.int(LEN(b)); Out.str(" "); Out.int(SIZE(Header)); Out.ln; | |
| 41 | + Out.int(LEN(BYTES(h.count))); Out.str(" "); Out.int(LEN(BYTES(h.flags))); Out.ln; | |
| 42 | + b[OFFSET(Header, magic)].(U32) := 0CAFEF00DH; (* written through the bytes *) | |
| 43 | + BYTES(h.count)[0].(U16) := 513; | |
| 44 | + Out.hex(U64(h.magic), 8); Out.str(" "); Out.int(I64(h.count)); Out.str(" "); Out.int(I64(h.flags)); Out.ln; | |
| 45 | + Out.int(I64(BYTES(h)[OFFSET(Header, flags)])); Out.ln; | |
| 46 | + | |
| 47 | + a := [1, -1, 256]; | |
| 48 | + b := BYTES(a); | |
| 49 | + Out.int(LEN(b)); Out.str(" "); Out.int(I64(b[2].(I16))); Out.str(" "); Out.int(I64(b[4].(I16))); Out.ln; | |
| 50 | + BYTES(a[1])[0] := 7; BYTES(a[1])[1] := 0; | |
| 51 | + Out.int(I64(a[1])); Out.ln; | |
| 52 | + | |
| 53 | + s := g[1..4]; | |
| 54 | + g := [10, 20, 30, 40]; | |
| 55 | + b := BYTES(s); | |
| 56 | + Out.int(LEN(b)); Out.str(" "); Out.int(LEN(s) * SIZE(I32)); Out.ln; | |
| 57 | + for i := 0 to LEN(s) - 1 do | |
| 58 | + b[i * SIZE(I32)].(I32) := b[i * SIZE(I32)].(I32) + 1; | |
| 59 | + end; | |
| 60 | + Out.int(I64(g[0])); Out.str(" "); Out.int(I64(g[1])); Out.str(" "); Out.int(I64(g[3])); Out.ln; | |
| 61 | + Out.int(LEN(BYTES(s[1..2]))); Out.str(" "); Out.int(LEN(BYTES(whole()))); Out.ln; | |
| 62 | + Out.int(LEN(BYTES(none))); Out.str(" "); Out.int(LEN(BYTES(g[2..2]))); Out.ln; | |
| 63 | + Out.int(LEN(gBytes())); Out.str(" "); Out.int(I64(gBytes()[4].(I32))); Out.ln; | |
| 64 | + | |
| 65 | + p := ADR(h); | |
| 66 | + n := 0; | |
| 67 | + for i := 0 to OFFSET(Header, flags) do (* not the padding after *) | |
| 68 | + INC(n, I32(BYTES(p^)[i])); | |
| 69 | + end; | |
| 70 | + Out.int(I64(n)); Out.ln; | |
| 71 | + clear(h); | |
| 72 | + Out.int(I64(h.magic)); Out.str(" "); Out.int(I64(h.count)); Out.ln; | |
| 73 | + | |
| 74 | + n := 01020304H; | |
| 75 | + b := BYTES(n); | |
| 76 | + Out.int(LEN(b)); if b[0].(I32) = n then Out.str(" same"); end; Out.ln; | |
| 77 | +end; | |
| 78 | + | |
| 79 | +end BytesOf. |
| @@ -18,12 +18,12 @@ | ||
| 18 | 18 | |---|---|---|---| |
| 19 | 19 | | `src/Diag.raz` | 422 | 324 | Messages: positions, source excerpts, colour, counts | |
| 20 | 20 | | `src/Scan.raz` | 1,169 | 965 | Symbols, literals, comments, positions | |
| 21 | -| `src/Sym.raz` | 721 | 579 | Types, objects, scopes, layout | | |
| 21 | +| `src/Sym.raz` | 724 | 582 | Types, objects, scopes, layout | | |
| 22 | 22 | | `src/Chunk.raz` | 363 | 279 | The compiled program: chunks, fixups, line notes | |
| 23 | 23 | | `src/X64.raz` | 1,605 | 1,318 | The instruction encoder, jumps within a procedure, the assembler | |
| 24 | 24 | | `src/Gen.raz` | 2,666 | 1,885 | The stack machine, for x86-64: values, operations, checks, calls, frames | |
| 25 | -| `src/Item.raz` | 2,297 | 1,844 | Items: types, constants, variables, operators, conversions, calls | | |
| 26 | -| `src/Parse.raz` | 4,403 | 3,803 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 25 | +| `src/Item.raz` | 2,378 | 1,909 | Items: types, constants, variables, operators, conversions, calls | | |
| 26 | +| `src/Parse.raz` | 4,459 | 3,851 | Declarations, statements, expressions, built-ins, recovery, warnings | | |
| 27 | 27 | | `src/Link.raz` | 407 | 315 | Tree shaking, layout, patching, the places | |
| 28 | 28 | | `src/Elf.raz` | 449 | 355 | Static and dynamic ELF, symbol table, line numbers | |
| 29 | 29 | | `src/Raz.raz` | 418 | 333 | The command line | |
| @@ -1671,6 +1671,24 @@ | ||
| 1671 | 1671 | |
| 1672 | 1672 | ADR(s[0]) check 0 < LEN(s), then s's first word (stops on "") |
| 1673 | 1673 | PTR(s) s's first word (no check) |
| 1674 | + | |
| 1675 | +`BYTES(x)` (report 2026-10.36) is Item's `bytesOf`. It is made as a | |
| 1676 | +slice of `x` is, and refused where one is: a string constant, another | |
| 1677 | +constant or a call's result, what is only read, a volatile variable, a | |
| 1678 | +packed record's field and a view, each with its message; and | |
| 1679 | +`bytesType` refuses a type a view may not take, by `notPlain`, its help | |
| 1680 | +naming the record's field that holds it. The call becomes a slice in a | |
| 1681 | +temporary of the statement: | |
| 1682 | + | |
| 1683 | + BYTES(s) {PTR(s), LEN(s) * SIZE(T)} s: []T | |
| 1684 | + BYTES(v) {ADR(v), SIZE(T)} v: T, anything else | |
| 1685 | + | |
| 1686 | +A slice's two words are read as `PTR` and `LEN` read them, so one | |
| 1687 | +reached through an address on the stack, or a call's two words, goes | |
| 1688 | +to a temporary first. `ADR(v)` is `address`, which puts a variable kept | |
| 1689 | +in a register in memory. The slice keeps `x`'s `frame`, so `notOfFrame` | |
| 1690 | +refuses `return BYTES(h)` of a local `h`, a field or an element of one | |
| 1691 | +too, as it refuses a slice of one. | |
| 1674 | 1692 | |
| 1675 | 1693 | `ROL(x, n)` and `ROR(x, n)` (report 2026-10.35) are Item's `rotand`, |
| 1676 | 1694 | which refuses an `x` not of an unsigned type, an untyped constant with |
| @@ -32,7 +32,7 @@ | ||
| 32 | 32 | '("I8" "I16" "I32" "I64" "INT" "UINT" "U8" "U16" "U32" "U64" "BOOL" "F32" "F64" "ERROR")) |
| 33 | 33 | |
| 34 | 34 | (defconst raz-builtins |
| 35 | - '("SIZE" "OFFSET" "ADR" "LEN" "PTR" "NEW" "MSG" "SYSCALL" "FENCE" "CAS" "XCHG" "XADD" | |
| 35 | + '("SIZE" "OFFSET" "ADR" "LEN" "PTR" "BYTES" "NEW" "MSG" "SYSCALL" "FENCE" "CAS" "XCHG" "XADD" | |
| 36 | 36 | "ARGC" "ARGV" "INC" "DEC" "COPY" "ROL" "ROR" "MIN" "MAX" |
| 37 | 37 | "CLZ" "CTZ" "POPCOUNT")) |
| 38 | 38 |
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | syntax keyword razKeyword repeat return set shl shr then to try type until |
| 15 | 15 | syntax keyword razKeyword var variant VOLATILE while xor |
| 16 | 16 | syntax keyword razType I8 I16 I32 I64 INT UINT U8 U16 U32 U64 BOOL F32 F64 ERROR |
| 17 | -syntax keyword razBuiltin SIZE OFFSET ADR LEN PTR NEW MSG SYSCALL FENCE CAS XCHG XADD | |
| 17 | +syntax keyword razBuiltin SIZE OFFSET ADR LEN PTR BYTES NEW MSG SYSCALL FENCE CAS XCHG XADD | |
| 18 | 18 | syntax keyword razBuiltin ARGC ARGV INC DEC COPY ROL ROR MIN MAX |
| 19 | 19 | syntax keyword razBuiltin CLZ CTZ POPCOUNT |
| 20 | 20 | syntax keyword razConstant true false nil |
| @@ -934,6 +934,87 @@ | ||
| 934 | 934 | return Scan.markHelp(x.pos, text, "a view is an integer, a real or a pointer, or a record or array made of them"); |
| 935 | 935 | end; |
| 936 | 936 | |
| 937 | +(* What BYTES(x) refuses of its type, t, or of a slice's elements, t: | |
| 938 | + a type a view may not take (report section 6.8), since bytes written | |
| 939 | + through the slice must still be a value of it. In a record, the help | |
| 940 | + names the field that holds it. *) | |
| 941 | +proc bytesType(x: Item; t: ^Sym.Type): ERROR; | |
| 942 | +var u: ^Sym.Type; f: ^Sym.Obj; text, hint: []U8; | |
| 943 | +begin | |
| 944 | + u := notPlain(t); | |
| 945 | + if u = nil then return nil; end; | |
| 946 | + if u # x.typ then | |
| 947 | + text := say2("BYTES can't take {}, which holds {}", Sym.typeName(x.typ), Sym.typeName(u)); | |
| 948 | + else | |
| 949 | + text := say1("BYTES can't take {}", Sym.typeName(u)); | |
| 950 | + end; | |
| 951 | + hint := say1("some bytes are no {}: BYTES takes integers, reals and pointers, and records and arrays of them", | |
| 952 | + Sym.typeName(u)); | |
| 953 | + if t^.form = Sym.fRecord then | |
| 954 | + f := t^.fields; | |
| 955 | + while (f # nil) and (notPlain(f^.typ) = nil) do f := f^.next; end; | |
| 956 | + if f # nil then | |
| 957 | + hint := Diag.say("its field {} is of type {}, and some bytes are no {}", | |
| 958 | + [Fmt.str(Scan.nameOf(f^.name)), Fmt.str(Sym.typeName(f^.typ)), Fmt.str(Sym.typeName(u))]); | |
| 959 | + end; | |
| 960 | + end; | |
| 961 | + return Scan.markHelp(x.pos, text, hint); | |
| 962 | +end; | |
| 963 | + | |
| 964 | +(* BYTES(x), the bytes of x as a []U8 (report section 6.8), made as a | |
| 965 | + slice of x is, refused where one is, and keeping x's frame mark, so | |
| 966 | + that returnValue refuses the bytes of a local as a slice of one: | |
| 967 | + | |
| 968 | + BYTES(s) {PTR(s), LEN(s) * SIZE(T)} for a slice s: []T | |
| 969 | + BYTES(v) {ADR(v), SIZE(T)} for v: T, anything else | |
| 970 | + | |
| 971 | + A slice's words are read as PTR and LEN read them, once it is where | |
| 972 | + both can be read: a call's two words, or a slice reached through an | |
| 973 | + address on the stack, go to a temporary first. *) | |
| 974 | +proc bytesOf*(var x: Item): ERROR; | |
| 975 | +var t: ^Sym.Type; inFrame: BOOL; y: Item; s: I64; | |
| 976 | +begin | |
| 977 | + if x.mode = mStr then | |
| 978 | + return Scan.markHelp(x.pos, "BYTES can't take a string constant", | |
| 979 | + "a string constant is only read: where a []U8 is wanted, the string itself will do"); | |
| 980 | + end; | |
| 981 | + t := x.typ; | |
| 982 | + inFrame := x.frame; | |
| 983 | + if t^.form = Sym.fSlice then | |
| 984 | + try bytesType(x, t^.base); | |
| 985 | + if (x.mode # mVar) or (x.base = Gen.bStack) then try copyToTemp(x); end; | |
| 986 | + y := x; | |
| 987 | + y.typ := Sym.tInt; | |
| 988 | + try value(y); (* its first word, where it starts *) | |
| 989 | + x.off := x.off + 8; | |
| 990 | + x.typ := Sym.tInt; | |
| 991 | + try value(x); (* its second, the number of elements *) | |
| 992 | + scaleBy(t^.base^.size); | |
| 993 | + s := Gen.allocTemp(16, 8); | |
| 994 | + Gen.popVar(frameAdr(s + 8), 8); | |
| 995 | + Gen.popVar(frameAdr(s), 8); | |
| 996 | + tempItem(x, Sym.tBytes, s); | |
| 997 | + x.frame := inFrame; | |
| 998 | + return nil; | |
| 999 | + end; | |
| 1000 | + try notReadOnly(x); | |
| 1001 | + if (x.mode # mVar) or not x.isVar then | |
| 1002 | + return Scan.markHelp(x.pos, "BYTES needs a variable", | |
| 1003 | + "a constant, or the result of a call or an operator, has no bytes of its own: copy it to a variable"); | |
| 1004 | + end; | |
| 1005 | + if x.vol then | |
| 1006 | + return Scan.markHelp(x.pos, "BYTES can't take a volatile variable", | |
| 1007 | + "reading and writing its bytes through a slice wouldn't be volatile accesses"); | |
| 1008 | + end; | |
| 1009 | + if x.odd then return Scan.markAt(x.pos, "BYTES can't take a field of a packed record, which has no address"); end; | |
| 1010 | + if x.view then return noAddress(x, "BYTES can't take a view"); end; | |
| 1011 | + try bytesType(x, t); | |
| 1012 | + try address(x); | |
| 1013 | + sliceOf(x, Sym.tBytes, t^.size); | |
| 1014 | + x.frame := inFrame; | |
| 1015 | + return nil; | |
| 1016 | +end; | |
| 1017 | + | |
| 937 | 1018 | (* x becomes the view of itself as a T, its type changed and nothing |
| 938 | 1019 | else: the bytes are where x's are. A variable in a register has no |
| 939 | 1020 | bytes to view, so it goes to memory. *) |
| @@ -1112,6 +1112,10 @@ | ||
| 1112 | 1112 | try expression(y, nil); |
| 1113 | 1113 | try ptrOf(y); |
| 1114 | 1114 | x := y; |
| 1115 | + | Sym.bBytes: | |
| 1116 | + try expression(y, nil); | |
| 1117 | + try Item.bytesOf(y); | |
| 1118 | + x := y; | |
| 1115 | 1119 | | Sym.bSyscall: |
| 1116 | 1120 | n := 0; |
| 1117 | 1121 | repeat |
| @@ -133,7 +133,7 @@ | ||
| 133 | 133 | bFence* = 6; bCas* = 7; bXchg* = 8; bXadd* = 9; bArgc* = 10; bArgv* = 11; |
| 134 | 134 | bInc* = 12; bDec* = 13; bCopy* = 14; bPtr* = 15; bRol* = 16; bRor* = 17; |
| 135 | 135 | bMin* = 18; bMax* = 19; bClz* = 20; bCtz* = 21; bPopcount* = 22; |
| 136 | - bOffset* = 23; | |
| 136 | + bOffset* = 23; bBytes* = 24; | |
| 137 | 137 | |
| 138 | 138 | MaxDepth* = 64; (* scopes open at once *) |
| 139 | 139 | |
| @@ -701,6 +701,7 @@ | ||
| 701 | 701 | enter("LEN", oBuiltin, nil, bLen); |
| 702 | 702 | enter("PTR", oBuiltin, nil, bPtr); |
| 703 | 703 | enter("OFFSET", oBuiltin, nil, bOffset); |
| 704 | + enter("BYTES", oBuiltin, nil, bBytes); | |
| 704 | 705 | enter("NEW", oBuiltin, nil, bNew); |
| 705 | 706 | enter("MSG", oBuiltin, nil, bMsg); |
| 706 | 707 | enter("SYSCALL", oBuiltin, nil, bSyscall); |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/BytesBool.raz:5:16: error: BYTES can't take BOOL | |
| 2 | + 5 | b := BYTES(done); | |
| 3 | + | ^^^^ | |
| 4 | +help: some bytes are no BOOL: BYTES takes integers, reals and pointers, and records and arrays of them | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/BytesConst.raz:5:22: error: h is only read here, and can't be changed | |
| 2 | + 5 | return LEN(BYTES(h)); | |
| 3 | + | ^ | |
| 4 | +help: a const parameter, a constant, and the names a match gives their fields, are only read: take a var parameter to change it | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/BytesExport.raz:6:16: error: Owner.n is Owner's, and can't be changed outside it | |
| 2 | + 6 | b := BYTES(Owner.n); | |
| 3 | + | ^^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,25 @@ | ||
| 1 | +conform/err/BytesFrame.raz:14:12: error: can't return a slice of the procedure's own frame | |
| 2 | + 14 | return BYTES(h); (* the procedure's own variable *) | |
| 3 | + | ^^^^^^^^ | |
| 4 | +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives | |
| 5 | +conform/err/BytesFrame.raz:20:12: error: can't return a slice of the procedure's own frame | |
| 6 | + 20 | return BYTES(h.count); (* a field of one *) | |
| 7 | + | ^^^^^^^^^^^^^^ | |
| 8 | +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives | |
| 9 | +conform/err/BytesFrame.raz:26:12: error: can't return a slice of the procedure's own frame | |
| 10 | + 26 | return BYTES(a[i]), i; (* an element of one, one of several results *) | |
| 11 | + | ^^^^^^^^^^^ | |
| 12 | +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives | |
| 13 | +conform/err/BytesFrame.raz:31:12: error: can't return a slice of the procedure's own frame | |
| 14 | + 31 | return BYTES(h); (* the procedure's copy *) | |
| 15 | + | ^^^^^^^^ | |
| 16 | +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives | |
| 17 | +conform/err/BytesFrame.raz:38:12: error: can't return a slice of the procedure's own frame | |
| 18 | + 38 | return BYTES(n); (* a local that may live in a register *) | |
| 19 | + | ^^^^^^^^ | |
| 20 | +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives | |
| 21 | +conform/err/BytesFrame.raz:44:12: error: can't return a slice of the procedure's own frame | |
| 22 | + 44 | return BYTES(a[1..3]); (* a slice of a local array *) | |
| 23 | + | ^^^^^^^^^^^^^^ | |
| 24 | +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives | |
| 25 | +raz: 6 errors |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/BytesPacked.raz:6:16: error: BYTES can't take a field of a packed record, which has no address | |
| 2 | + 6 | b := BYTES(r.word); | |
| 3 | + | ^^^^^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/BytesRecordBool.raz:6:16: error: BYTES can't take Entry, which holds BOOL | |
| 2 | + 6 | b := BYTES(e); | |
| 3 | + | ^ | |
| 4 | +help: its field live is of type BOOL, and some bytes are no BOOL | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/BytesSliceEnum.raz:5:18: error: BYTES can't take []Colour, which holds Colour | |
| 2 | + 5 | return BYTES(s); | |
| 3 | + | ^ | |
| 4 | +help: some bytes are no Colour: BYTES takes integers, reals and pointers, and records and arrays of them | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/BytesString.raz:6:16: error: BYTES can't take a string constant | |
| 2 | + 6 | b := BYTES(Hello); | |
| 3 | + | ^^^^^ | |
| 4 | +help: a string constant is only read: where a []U8 is wanted, the string itself will do | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/BytesValue.raz:9:16: error: BYTES needs a variable | |
| 2 | + 9 | b := BYTES(seven()); | |
| 3 | + | ^^^^^^^ | |
| 4 | +help: a constant, or the result of a call or an operator, has no bytes of its own: copy it to a variable | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/BytesView.raz:5:16: error: BYTES can't take a view | |
| 2 | + 5 | b := BYTES(mem[3].(I64)); | |
| 3 | + | ^^^^^^^^^^^^ | |
| 4 | +help: a view has no address, since it may be misaligned: copy it to a variable | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,5 @@ | ||
| 1 | +conform/err/BytesVolatile.raz:7:16: error: BYTES can't take a volatile variable | |
| 2 | + 7 | b := BYTES(r^); | |
| 3 | + | ^^ | |
| 4 | +help: reading and writing its bytes through a slice wouldn't be volatile accesses | |
| 5 | +raz: 1 error |