raz / commit 8e0ec9ce

commit
8e0ec9ce6877ce052036be2d812797367733f9f7
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
32b1a75b
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.

patch · log

31 files changed, +416 -6

CLAUDE.md modified +8 -0

@@ -358,3 +358,11 @@
358358 `M.T` is read whole and a `.` past the type is a field's,
359359 `SIZE(M.T.f)` too. `T` must be a record type (a variant is refused,
360360 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.

conform/err/BytesBool.raz (history) added +7 -0

@@ -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.

conform/err/BytesConst.raz (history) added +7 -0

@@ -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.

conform/err/BytesExport.raz (history) added +8 -0

@@ -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.

conform/err/BytesFrame.raz (history) added +52 -0

@@ -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.

conform/err/BytesPacked.raz (history) added +8 -0

@@ -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.

conform/err/BytesRecordBool.raz (history) added +8 -0

@@ -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.

conform/err/BytesSliceEnum.raz (history) added +7 -0

@@ -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.

conform/err/BytesString.raz (history) added +8 -0

@@ -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.

conform/err/BytesValue.raz (history) added +11 -0

@@ -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.

conform/err/BytesView.raz (history) added +7 -0

@@ -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.

conform/err/BytesVolatile.raz (history) added +9 -0

@@ -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.

conform/run/BytesOf.expect (history) added +14 -0

@@ -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

conform/run/BytesOf.raz (history) added +79 -0

@@ -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.

doc/compiler.md (history) modified +21 -3

@@ -18,12 +18,12 @@
1818 |---|---|---|---|
1919 | `src/Diag.raz` | 422 | 324 | Messages: positions, source excerpts, colour, counts |
2020 | `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 |
2222 | `src/Chunk.raz` | 363 | 279 | The compiled program: chunks, fixups, line notes |
2323 | `src/X64.raz` | 1,605 | 1,318 | The instruction encoder, jumps within a procedure, the assembler |
2424 | `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 |
2727 | `src/Link.raz` | 407 | 315 | Tree shaking, layout, patching, the places |
2828 | `src/Elf.raz` | 449 | 355 | Static and dynamic ELF, symbol table, line numbers |
2929 | `src/Raz.raz` | 418 | 333 | The command line |
@@ -1671,6 +1671,24 @@
16711671
16721672 ADR(s[0]) check 0 < LEN(s), then s's first word (stops on "")
16731673 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.
16741692
16751693 `ROL(x, n)` and `ROR(x, n)` (report 2026-10.35) are Item's `rotand`,
16761694 which refuses an `x` not of an unsigned type, an untyped constant with

editor/emacs/raz-mode.el (history) modified +1 -1

@@ -32,7 +32,7 @@
3232 '("I8" "I16" "I32" "I64" "INT" "UINT" "U8" "U16" "U32" "U64" "BOOL" "F32" "F64" "ERROR"))
3333
3434 (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"
3636 "ARGC" "ARGV" "INC" "DEC" "COPY" "ROL" "ROR" "MIN" "MAX"
3737 "CLZ" "CTZ" "POPCOUNT"))
3838

editor/vim/syntax/raz.vim (history) modified +1 -1

@@ -14,7 +14,7 @@
1414 syntax keyword razKeyword repeat return set shl shr then to try type until
1515 syntax keyword razKeyword var variant VOLATILE while xor
1616 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
1818 syntax keyword razBuiltin ARGC ARGV INC DEC COPY ROL ROR MIN MAX
1919 syntax keyword razBuiltin CLZ CTZ POPCOUNT
2020 syntax keyword razConstant true false nil

src/Item.raz (history) modified +81 -0

@@ -934,6 +934,87 @@
934934 return Scan.markHelp(x.pos, text, "a view is an integer, a real or a pointer, or a record or array made of them");
935935 end;
936936
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+
9371018 (* x becomes the view of itself as a T, its type changed and nothing
9381019 else: the bytes are where x's are. A variable in a register has no
9391020 bytes to view, so it goes to memory. *)

src/Parse.raz (history) modified +4 -0

@@ -1112,6 +1112,10 @@
11121112 try expression(y, nil);
11131113 try ptrOf(y);
11141114 x := y;
1115+ | Sym.bBytes:
1116+ try expression(y, nil);
1117+ try Item.bytesOf(y);
1118+ x := y;
11151119 | Sym.bSyscall:
11161120 n := 0;
11171121 repeat

src/Sym.raz (history) modified +2 -1

@@ -133,7 +133,7 @@
133133 bFence* = 6; bCas* = 7; bXchg* = 8; bXadd* = 9; bArgc* = 10; bArgv* = 11;
134134 bInc* = 12; bDec* = 13; bCopy* = 14; bPtr* = 15; bRol* = 16; bRor* = 17;
135135 bMin* = 18; bMax* = 19; bClz* = 20; bCtz* = 21; bPopcount* = 22;
136- bOffset* = 23;
136+ bOffset* = 23; bBytes* = 24;
137137
138138 MaxDepth* = 64; (* scopes open at once *)
139139
@@ -701,6 +701,7 @@
701701 enter("LEN", oBuiltin, nil, bLen);
702702 enter("PTR", oBuiltin, nil, bPtr);
703703 enter("OFFSET", oBuiltin, nil, bOffset);
704+ enter("BYTES", oBuiltin, nil, bBytes);
704705 enter("NEW", oBuiltin, nil, bNew);
705706 enter("MSG", oBuiltin, nil, bMsg);
706707 enter("SYSCALL", oBuiltin, nil, bSyscall);

test/msg/BytesBool.err (history) added +5 -0

@@ -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

test/msg/BytesConst.err (history) added +5 -0

@@ -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

test/msg/BytesExport.err (history) added +4 -0

@@ -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

test/msg/BytesFrame.err (history) added +25 -0

@@ -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

test/msg/BytesPacked.err (history) added +4 -0

@@ -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

test/msg/BytesRecordBool.err (history) added +5 -0

@@ -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

test/msg/BytesSliceEnum.err (history) added +5 -0

@@ -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

test/msg/BytesString.err (history) added +5 -0

@@ -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

test/msg/BytesValue.err (history) added +5 -0

@@ -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

test/msg/BytesView.err (history) added +5 -0

@@ -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

test/msg/BytesVolatile.err (history) added +5 -0

@@ -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