From 8e0ec9ce6877ce052036be2d812797367733f9f7 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 23 Oct 2026 12:24:56 +0100 Subject: [PATCH] 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. --- diff --git a/CLAUDE.md b/CLAUDE.md index 044ece4..bb78aaa 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -358,3 +358,11 @@ `M.T` is read whole and a `.` past the type is a field's, `SIZE(M.T.f)` too. `T` must be a record type (a variant is refused, with help); a path `a.b` is refused, its help naming `a`'s type. + `BYTES(x)`: of a slice, its `PTR` and `LEN * SIZE(T)`, with no check + of what holds the slice (a `const` one, another module's, a field of + a packed record), as for `PTR`; of anything else, a variable's + address and size, refused, as `ADR` refuses, for what is only read, + and, beyond `ADR`, for a volatile variable; a constant of any kind + is no variable. `T` is refused by the view's `notPlain`. The result + keeps `x`'s `frame`, so the bytes of a local are caught by + `notOfFrame` as far as a slice of it is. diff --git a/conform/err/BytesBool.raz b/conform/err/BytesBool.raz new file mode 100644 index 0000000..545913d --- /dev/null +++ b/conform/err/BytesBool.raz @@ -0,0 +1,7 @@ +module BytesBool; +proc main*; +var done: BOOL; b: []U8; +begin + b := BYTES(done); +end; +end BytesBool. diff --git a/conform/err/BytesConst.raz b/conform/err/BytesConst.raz new file mode 100644 index 0000000..a70f78b --- /dev/null +++ b/conform/err/BytesConst.raz @@ -0,0 +1,7 @@ +module BytesConst; +type Header = record magic: U32; count: U32; end; +proc send(const h: Header): INT; +begin + return LEN(BYTES(h)); +end; +end BytesConst. diff --git a/conform/err/BytesExport.raz b/conform/err/BytesExport.raz new file mode 100644 index 0000000..f1d69a4 --- /dev/null +++ b/conform/err/BytesExport.raz @@ -0,0 +1,8 @@ +module BytesExport; +import Owner; +proc main*; +var b: []U8; +begin + b := BYTES(Owner.n); +end; +end BytesExport. diff --git a/conform/err/BytesFrame.raz b/conform/err/BytesFrame.raz new file mode 100644 index 0000000..4412781 --- /dev/null +++ b/conform/err/BytesFrame.raz @@ -0,0 +1,52 @@ +module BytesFrame; +(* the bytes of a local can't be returned, a field or an element of one + included (report section 7.3); those of a var parameter, a module + variable, what a pointer points at, or a slice given, can *) + +type + Header = record magic: U32; count: U32; end; + +var g: Header; + +proc local: []U8; +var h: Header; +begin + return BYTES(h); (* the procedure's own variable *) +end; + +proc field: []U8; +var h: Header; +begin + return BYTES(h.count); (* a field of one *) +end; + +proc element(i: INT): ([]U8, INT); +var a: [4]I32; +begin + return BYTES(a[i]), i; (* an element of one, one of several results *) +end; + +proc param(h: Header): []U8; +begin + return BYTES(h); (* the procedure's copy *) +end; + +proc scalar: []U8; +var n: I64; +begin + n := 1; + return BYTES(n); (* a local that may live in a register *) +end; + +proc part: []U8; +var a: [4]I32; +begin + return BYTES(a[1..3]); (* a slice of a local array *) +end; + +proc ok(var h: Header; s: []I32; p: ^Header): ([]U8, []U8, []U8, []U8); +begin + return BYTES(h), BYTES(s), BYTES(p^), BYTES(g); +end; + +end BytesFrame. diff --git a/conform/err/BytesPacked.raz b/conform/err/BytesPacked.raz new file mode 100644 index 0000000..214de4c --- /dev/null +++ b/conform/err/BytesPacked.raz @@ -0,0 +1,8 @@ +module BytesPacked; +type R = packed record tag: U8; word: I32; end; +proc main*; +var r: R; b: []U8; +begin + b := BYTES(r.word); +end; +end BytesPacked. diff --git a/conform/err/BytesRecordBool.raz b/conform/err/BytesRecordBool.raz new file mode 100644 index 0000000..fb10779 --- /dev/null +++ b/conform/err/BytesRecordBool.raz @@ -0,0 +1,8 @@ +module BytesRecordBool; +type Entry = record key: U32; live: BOOL; end; +proc main*; +var e: Entry; b: []U8; +begin + b := BYTES(e); +end; +end BytesRecordBool. diff --git a/conform/err/BytesSliceEnum.raz b/conform/err/BytesSliceEnum.raz new file mode 100644 index 0000000..88fdd1d --- /dev/null +++ b/conform/err/BytesSliceEnum.raz @@ -0,0 +1,7 @@ +module BytesSliceEnum; +type Colour = (red, green, blue); +proc paint(s: []Colour): []U8; +begin + return BYTES(s); +end; +end BytesSliceEnum. diff --git a/conform/err/BytesString.raz b/conform/err/BytesString.raz new file mode 100644 index 0000000..66a6829 --- /dev/null +++ b/conform/err/BytesString.raz @@ -0,0 +1,8 @@ +module BytesString; +const Hello = "hello"; +proc main*; +var b: []U8; +begin + b := BYTES(Hello); +end; +end BytesString. diff --git a/conform/err/BytesValue.raz b/conform/err/BytesValue.raz new file mode 100644 index 0000000..4e369fd --- /dev/null +++ b/conform/err/BytesValue.raz @@ -0,0 +1,11 @@ +module BytesValue; +proc seven: I64; +begin + return 7; +end; +proc main*; +var b: []U8; +begin + b := BYTES(seven()); +end; +end BytesValue. diff --git a/conform/err/BytesView.raz b/conform/err/BytesView.raz new file mode 100644 index 0000000..546b804 --- /dev/null +++ b/conform/err/BytesView.raz @@ -0,0 +1,7 @@ +module BytesView; +proc main*; +var mem: [16]U8; b: []U8; +begin + b := BYTES(mem[3].(I64)); +end; +end BytesView. diff --git a/conform/err/BytesVolatile.raz b/conform/err/BytesVolatile.raz new file mode 100644 index 0000000..7512025 --- /dev/null +++ b/conform/err/BytesVolatile.raz @@ -0,0 +1,9 @@ +module BytesVolatile; +type Regs = record ctrl: U32; status: U32; end; +proc main*; +var r: ^VOLATILE Regs; b: []U8; +begin + r := ^VOLATILE Regs(0FEE00000H); + b := BYTES(r^); +end; +end BytesVolatile. diff --git a/conform/run/BytesOf.expect b/conform/run/BytesOf.expect new file mode 100644 index 0000000..7952a25 --- /dev/null +++ b/conform/run/BytesOf.expect @@ -0,0 +1,14 @@ +8 8 +2 1 +CAFEF00D 513 3 +3 +6 -1 256 +7 +12 12 +10 21 41 +4 16 +0 0 +16 21 +715 +0 0 +4 same diff --git a/conform/run/BytesOf.raz b/conform/run/BytesOf.raz new file mode 100644 index 0000000..3edb05b --- /dev/null +++ b/conform/run/BytesOf.raz @@ -0,0 +1,79 @@ +(* BYTES(x), the bytes of x as a []U8 (report section 6.8): of a + record, an array and a []I32 slice, read and written through; their + lengths, SIZE(T) or LEN(s) * SIZE(T); an empty slice's; and the + bytes of a field and an element, of what a pointer points at, of a + var parameter, and of a slice a call returns. Bytes are compared + with a view of the same place, which is the target's order too. *) +module BytesOf; +import Out; + +type + Header = record magic: U32; count: U16; flags: U8; end; + +var g: [4]I32; + +(* the bytes of h, given as a var parameter, written zero *) +proc clear(var h: Header); +var b: []U8; i: INT; +begin + b := BYTES(h); + for i := 0 to LEN(b) - 1 do b[i] := 0; end; +end; + +(* the module's array, as a slice a call returns *) +proc whole: []I32; +begin + return g; +end; + +(* the bytes of the module's array, returned: they outlive the call *) +proc gBytes: []U8; +begin + return BYTES(g); +end; + +proc main*; +var h: Header; a: [3]I16; s, none: []I32; b: []U8; p: ^Header; n: I32; i: INT; +begin + h := {magic: 1, count: 2, flags: 3}; + b := BYTES(h); + Out.int(LEN(b)); Out.str(" "); Out.int(SIZE(Header)); Out.ln; + Out.int(LEN(BYTES(h.count))); Out.str(" "); Out.int(LEN(BYTES(h.flags))); Out.ln; + b[OFFSET(Header, magic)].(U32) := 0CAFEF00DH; (* written through the bytes *) + BYTES(h.count)[0].(U16) := 513; + Out.hex(U64(h.magic), 8); Out.str(" "); Out.int(I64(h.count)); Out.str(" "); Out.int(I64(h.flags)); Out.ln; + Out.int(I64(BYTES(h)[OFFSET(Header, flags)])); Out.ln; + + a := [1, -1, 256]; + b := BYTES(a); + Out.int(LEN(b)); Out.str(" "); Out.int(I64(b[2].(I16))); Out.str(" "); Out.int(I64(b[4].(I16))); Out.ln; + BYTES(a[1])[0] := 7; BYTES(a[1])[1] := 0; + Out.int(I64(a[1])); Out.ln; + + s := g[1..4]; + g := [10, 20, 30, 40]; + b := BYTES(s); + Out.int(LEN(b)); Out.str(" "); Out.int(LEN(s) * SIZE(I32)); Out.ln; + for i := 0 to LEN(s) - 1 do + b[i * SIZE(I32)].(I32) := b[i * SIZE(I32)].(I32) + 1; + end; + Out.int(I64(g[0])); Out.str(" "); Out.int(I64(g[1])); Out.str(" "); Out.int(I64(g[3])); Out.ln; + Out.int(LEN(BYTES(s[1..2]))); Out.str(" "); Out.int(LEN(BYTES(whole()))); Out.ln; + Out.int(LEN(BYTES(none))); Out.str(" "); Out.int(LEN(BYTES(g[2..2]))); Out.ln; + Out.int(LEN(gBytes())); Out.str(" "); Out.int(I64(gBytes()[4].(I32))); Out.ln; + + p := ADR(h); + n := 0; + for i := 0 to OFFSET(Header, flags) do (* not the padding after *) + INC(n, I32(BYTES(p^)[i])); + end; + Out.int(I64(n)); Out.ln; + clear(h); + Out.int(I64(h.magic)); Out.str(" "); Out.int(I64(h.count)); Out.ln; + + n := 01020304H; + b := BYTES(n); + Out.int(LEN(b)); if b[0].(I32) = n then Out.str(" same"); end; Out.ln; +end; + +end BytesOf. diff --git a/doc/compiler.md b/doc/compiler.md index d209b7e..6013c5c 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -18,12 +18,12 @@ |---|---|---|---| | `src/Diag.raz` | 422 | 324 | Messages: positions, source excerpts, colour, counts | | `src/Scan.raz` | 1,169 | 965 | Symbols, literals, comments, positions | -| `src/Sym.raz` | 721 | 579 | Types, objects, scopes, layout | +| `src/Sym.raz` | 724 | 582 | Types, objects, scopes, layout | | `src/Chunk.raz` | 363 | 279 | The compiled program: chunks, fixups, line notes | | `src/X64.raz` | 1,605 | 1,318 | The instruction encoder, jumps within a procedure, the assembler | | `src/Gen.raz` | 2,666 | 1,885 | The stack machine, for x86-64: values, operations, checks, calls, frames | -| `src/Item.raz` | 2,297 | 1,844 | Items: types, constants, variables, operators, conversions, calls | -| `src/Parse.raz` | 4,403 | 3,803 | Declarations, statements, expressions, built-ins, recovery, warnings | +| `src/Item.raz` | 2,378 | 1,909 | Items: types, constants, variables, operators, conversions, calls | +| `src/Parse.raz` | 4,459 | 3,851 | Declarations, statements, expressions, built-ins, recovery, warnings | | `src/Link.raz` | 407 | 315 | Tree shaking, layout, patching, the places | | `src/Elf.raz` | 449 | 355 | Static and dynamic ELF, symbol table, line numbers | | `src/Raz.raz` | 418 | 333 | The command line | @@ -1671,6 +1671,24 @@ ADR(s[0]) check 0 < LEN(s), then s's first word (stops on "") PTR(s) s's first word (no check) + +`BYTES(x)` (report 2026-10.36) is Item's `bytesOf`. It is made as a +slice of `x` is, and refused where one is: 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, each with its message; and +`bytesType` refuses a type a view may not take, by `notPlain`, its help +naming the record's field that holds it. The call becomes a slice in a +temporary of the statement: + + BYTES(s) {PTR(s), LEN(s) * SIZE(T)} s: []T + BYTES(v) {ADR(v), SIZE(T)} v: T, anything else + +A slice's two words are read as `PTR` and `LEN` read them, so one +reached through an address on the stack, or a call's two words, goes +to a temporary first. `ADR(v)` is `address`, which puts a variable kept +in a register in memory. The slice keeps `x`'s `frame`, so `notOfFrame` +refuses `return BYTES(h)` of a local `h`, a field or an element of one +too, as it refuses a slice of one. `ROL(x, n)` and `ROR(x, n)` (report 2026-10.35) are Item's `rotand`, which refuses an `x` not of an unsigned type, an untyped constant with diff --git a/editor/emacs/raz-mode.el b/editor/emacs/raz-mode.el index e694956..32aa3ae 100644 --- a/editor/emacs/raz-mode.el +++ b/editor/emacs/raz-mode.el @@ -32,7 +32,7 @@ '("I8" "I16" "I32" "I64" "INT" "UINT" "U8" "U16" "U32" "U64" "BOOL" "F32" "F64" "ERROR")) (defconst raz-builtins - '("SIZE" "OFFSET" "ADR" "LEN" "PTR" "NEW" "MSG" "SYSCALL" "FENCE" "CAS" "XCHG" "XADD" + '("SIZE" "OFFSET" "ADR" "LEN" "PTR" "BYTES" "NEW" "MSG" "SYSCALL" "FENCE" "CAS" "XCHG" "XADD" "ARGC" "ARGV" "INC" "DEC" "COPY" "ROL" "ROR" "MIN" "MAX" "CLZ" "CTZ" "POPCOUNT")) diff --git a/editor/vim/syntax/raz.vim b/editor/vim/syntax/raz.vim index 8f5e128..d27adeb 100644 --- a/editor/vim/syntax/raz.vim +++ b/editor/vim/syntax/raz.vim @@ -14,7 +14,7 @@ syntax keyword razKeyword repeat return set shl shr then to try type until syntax keyword razKeyword var variant VOLATILE while xor syntax keyword razType I8 I16 I32 I64 INT UINT U8 U16 U32 U64 BOOL F32 F64 ERROR -syntax keyword razBuiltin SIZE OFFSET ADR LEN PTR NEW MSG SYSCALL FENCE CAS XCHG XADD +syntax keyword razBuiltin SIZE OFFSET ADR LEN PTR BYTES NEW MSG SYSCALL FENCE CAS XCHG XADD syntax keyword razBuiltin ARGC ARGV INC DEC COPY ROL ROR MIN MAX syntax keyword razBuiltin CLZ CTZ POPCOUNT syntax keyword razConstant true false nil diff --git a/src/Item.raz b/src/Item.raz index 7e3f683..bceeec1 100644 --- a/src/Item.raz +++ b/src/Item.raz @@ -934,6 +934,87 @@ return Scan.markHelp(x.pos, text, "a view is an integer, a real or a pointer, or a record or array made of them"); end; +(* What BYTES(x) refuses of its type, t, or of a slice's elements, t: + a type a view may not take (report section 6.8), since bytes written + through the slice must still be a value of it. In a record, the help + names the field that holds it. *) +proc bytesType(x: Item; t: ^Sym.Type): ERROR; +var u: ^Sym.Type; f: ^Sym.Obj; text, hint: []U8; +begin + u := notPlain(t); + if u = nil then return nil; end; + if u # x.typ then + text := say2("BYTES can't take {}, which holds {}", Sym.typeName(x.typ), Sym.typeName(u)); + else + text := say1("BYTES can't take {}", Sym.typeName(u)); + end; + hint := say1("some bytes are no {}: BYTES takes integers, reals and pointers, and records and arrays of them", + Sym.typeName(u)); + if t^.form = Sym.fRecord then + f := t^.fields; + while (f # nil) and (notPlain(f^.typ) = nil) do f := f^.next; end; + if f # nil then + hint := Diag.say("its field {} is of type {}, and some bytes are no {}", + [Fmt.str(Scan.nameOf(f^.name)), Fmt.str(Sym.typeName(f^.typ)), Fmt.str(Sym.typeName(u))]); + end; + end; + return Scan.markHelp(x.pos, text, hint); +end; + +(* BYTES(x), the bytes of x as a []U8 (report section 6.8), made as a + slice of x is, refused where one is, and keeping x's frame mark, so + that returnValue refuses the bytes of a local as a slice of one: + + BYTES(s) {PTR(s), LEN(s) * SIZE(T)} for a slice s: []T + BYTES(v) {ADR(v), SIZE(T)} for v: T, anything else + + A slice's words are read as PTR and LEN read them, once it is where + both can be read: a call's two words, or a slice reached through an + address on the stack, go to a temporary first. *) +proc bytesOf*(var x: Item): ERROR; +var t: ^Sym.Type; inFrame: BOOL; y: Item; s: I64; +begin + if x.mode = mStr then + return Scan.markHelp(x.pos, "BYTES can't take a string constant", + "a string constant is only read: where a []U8 is wanted, the string itself will do"); + end; + t := x.typ; + inFrame := x.frame; + if t^.form = Sym.fSlice then + try bytesType(x, t^.base); + if (x.mode # mVar) or (x.base = Gen.bStack) then try copyToTemp(x); end; + y := x; + y.typ := Sym.tInt; + try value(y); (* its first word, where it starts *) + x.off := x.off + 8; + x.typ := Sym.tInt; + try value(x); (* its second, the number of elements *) + scaleBy(t^.base^.size); + s := Gen.allocTemp(16, 8); + Gen.popVar(frameAdr(s + 8), 8); + Gen.popVar(frameAdr(s), 8); + tempItem(x, Sym.tBytes, s); + x.frame := inFrame; + return nil; + end; + try notReadOnly(x); + if (x.mode # mVar) or not x.isVar then + return Scan.markHelp(x.pos, "BYTES needs a variable", + "a constant, or the result of a call or an operator, has no bytes of its own: copy it to a variable"); + end; + if x.vol then + return Scan.markHelp(x.pos, "BYTES can't take a volatile variable", + "reading and writing its bytes through a slice wouldn't be volatile accesses"); + end; + if x.odd then return Scan.markAt(x.pos, "BYTES can't take a field of a packed record, which has no address"); end; + if x.view then return noAddress(x, "BYTES can't take a view"); end; + try bytesType(x, t); + try address(x); + sliceOf(x, Sym.tBytes, t^.size); + x.frame := inFrame; + return nil; +end; + (* x becomes the view of itself as a T, its type changed and nothing else: the bytes are where x's are. A variable in a register has no bytes to view, so it goes to memory. *) diff --git a/src/Parse.raz b/src/Parse.raz index 9aea0dd..4f94676 100644 --- a/src/Parse.raz +++ b/src/Parse.raz @@ -1112,6 +1112,10 @@ try expression(y, nil); try ptrOf(y); x := y; + | Sym.bBytes: + try expression(y, nil); + try Item.bytesOf(y); + x := y; | Sym.bSyscall: n := 0; repeat diff --git a/src/Sym.raz b/src/Sym.raz index ff2a653..9ed3ad5 100644 --- a/src/Sym.raz +++ b/src/Sym.raz @@ -133,7 +133,7 @@ bFence* = 6; bCas* = 7; bXchg* = 8; bXadd* = 9; bArgc* = 10; bArgv* = 11; bInc* = 12; bDec* = 13; bCopy* = 14; bPtr* = 15; bRol* = 16; bRor* = 17; bMin* = 18; bMax* = 19; bClz* = 20; bCtz* = 21; bPopcount* = 22; - bOffset* = 23; + bOffset* = 23; bBytes* = 24; MaxDepth* = 64; (* scopes open at once *) @@ -701,6 +701,7 @@ enter("LEN", oBuiltin, nil, bLen); enter("PTR", oBuiltin, nil, bPtr); enter("OFFSET", oBuiltin, nil, bOffset); + enter("BYTES", oBuiltin, nil, bBytes); enter("NEW", oBuiltin, nil, bNew); enter("MSG", oBuiltin, nil, bMsg); enter("SYSCALL", oBuiltin, nil, bSyscall); diff --git a/test/msg/BytesBool.err b/test/msg/BytesBool.err new file mode 100644 index 0000000..d37f79a --- /dev/null +++ b/test/msg/BytesBool.err @@ -0,0 +1,5 @@ +conform/err/BytesBool.raz:5:16: error: BYTES can't take BOOL + 5 | b := BYTES(done); + | ^^^^ +help: some bytes are no BOOL: BYTES takes integers, reals and pointers, and records and arrays of them +raz: 1 error diff --git a/test/msg/BytesConst.err b/test/msg/BytesConst.err new file mode 100644 index 0000000..0cdd28a --- /dev/null +++ b/test/msg/BytesConst.err @@ -0,0 +1,5 @@ +conform/err/BytesConst.raz:5:22: error: h is only read here, and can't be changed + 5 | return LEN(BYTES(h)); + | ^ +help: a const parameter, a constant, and the names a match gives their fields, are only read: take a var parameter to change it +raz: 1 error diff --git a/test/msg/BytesExport.err b/test/msg/BytesExport.err new file mode 100644 index 0000000..da0aa16 --- /dev/null +++ b/test/msg/BytesExport.err @@ -0,0 +1,4 @@ +conform/err/BytesExport.raz:6:16: error: Owner.n is Owner's, and can't be changed outside it + 6 | b := BYTES(Owner.n); + | ^^^^^^^ +raz: 1 error diff --git a/test/msg/BytesFrame.err b/test/msg/BytesFrame.err new file mode 100644 index 0000000..d606c2c --- /dev/null +++ b/test/msg/BytesFrame.err @@ -0,0 +1,25 @@ +conform/err/BytesFrame.raz:14:12: error: can't return a slice of the procedure's own frame + 14 | return BYTES(h); (* the procedure's own variable *) + | ^^^^^^^^ +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives +conform/err/BytesFrame.raz:20:12: error: can't return a slice of the procedure's own frame + 20 | return BYTES(h.count); (* a field of one *) + | ^^^^^^^^^^^^^^ +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives +conform/err/BytesFrame.raz:26:12: error: can't return a slice of the procedure's own frame + 26 | return BYTES(a[i]), i; (* an element of one, one of several results *) + | ^^^^^^^^^^^ +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives +conform/err/BytesFrame.raz:31:12: error: can't return a slice of the procedure's own frame + 31 | return BYTES(h); (* the procedure's copy *) + | ^^^^^^^^ +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives +conform/err/BytesFrame.raz:38:12: error: can't return a slice of the procedure's own frame + 38 | return BYTES(n); (* a local that may live in a register *) + | ^^^^^^^^ +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives +conform/err/BytesFrame.raz:44:12: error: can't return a slice of the procedure's own frame + 44 | return BYTES(a[1..3]); (* a slice of a local array *) + | ^^^^^^^^^^^^^^ +help: it is gone once the procedure returns: take the array as a var parameter, or fill a buffer the caller gives +raz: 6 errors diff --git a/test/msg/BytesPacked.err b/test/msg/BytesPacked.err new file mode 100644 index 0000000..393d4a6 --- /dev/null +++ b/test/msg/BytesPacked.err @@ -0,0 +1,4 @@ +conform/err/BytesPacked.raz:6:16: error: BYTES can't take a field of a packed record, which has no address + 6 | b := BYTES(r.word); + | ^^^^^^ +raz: 1 error diff --git a/test/msg/BytesRecordBool.err b/test/msg/BytesRecordBool.err new file mode 100644 index 0000000..df315ec --- /dev/null +++ b/test/msg/BytesRecordBool.err @@ -0,0 +1,5 @@ +conform/err/BytesRecordBool.raz:6:16: error: BYTES can't take Entry, which holds BOOL + 6 | b := BYTES(e); + | ^ +help: its field live is of type BOOL, and some bytes are no BOOL +raz: 1 error diff --git a/test/msg/BytesSliceEnum.err b/test/msg/BytesSliceEnum.err new file mode 100644 index 0000000..ee604cb --- /dev/null +++ b/test/msg/BytesSliceEnum.err @@ -0,0 +1,5 @@ +conform/err/BytesSliceEnum.raz:5:18: error: BYTES can't take []Colour, which holds Colour + 5 | return BYTES(s); + | ^ +help: some bytes are no Colour: BYTES takes integers, reals and pointers, and records and arrays of them +raz: 1 error diff --git a/test/msg/BytesString.err b/test/msg/BytesString.err new file mode 100644 index 0000000..14d6a5f --- /dev/null +++ b/test/msg/BytesString.err @@ -0,0 +1,5 @@ +conform/err/BytesString.raz:6:16: error: BYTES can't take a string constant + 6 | b := BYTES(Hello); + | ^^^^^ +help: a string constant is only read: where a []U8 is wanted, the string itself will do +raz: 1 error diff --git a/test/msg/BytesValue.err b/test/msg/BytesValue.err new file mode 100644 index 0000000..12c6cd5 --- /dev/null +++ b/test/msg/BytesValue.err @@ -0,0 +1,5 @@ +conform/err/BytesValue.raz:9:16: error: BYTES needs a variable + 9 | b := BYTES(seven()); + | ^^^^^^^ +help: a constant, or the result of a call or an operator, has no bytes of its own: copy it to a variable +raz: 1 error diff --git a/test/msg/BytesView.err b/test/msg/BytesView.err new file mode 100644 index 0000000..ed6d2dc --- /dev/null +++ b/test/msg/BytesView.err @@ -0,0 +1,5 @@ +conform/err/BytesView.raz:5:16: error: BYTES can't take a view + 5 | b := BYTES(mem[3].(I64)); + | ^^^^^^^^^^^^ +help: a view has no address, since it may be misaligned: copy it to a variable +raz: 1 error diff --git a/test/msg/BytesVolatile.err b/test/msg/BytesVolatile.err new file mode 100644 index 0000000..dae16c7 --- /dev/null +++ b/test/msg/BytesVolatile.err @@ -0,0 +1,5 @@ +conform/err/BytesVolatile.raz:7:16: error: BYTES can't take a volatile variable + 7 | b := BYTES(r^); + | ^^ +help: reading and writing its bytes through a slice wouldn't be volatile accesses +raz: 1 error