From f784f53105492be941ccc108937a9fa25a0863c0 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Thu, 15 Oct 2026 08:20:25 +0000 Subject: [PATCH] Views, v.(T): the bytes of a variable read and written as another type --- diff --git a/conform/err/ViewAdr.raz b/conform/err/ViewAdr.raz new file mode 100644 index 0000000..e7a0dfb --- /dev/null +++ b/conform/err/ViewAdr.raz @@ -0,0 +1,7 @@ +module ViewAdr; +var mem: [16]U8; p: ^I64; +proc main*; +begin + p := ADR(mem[0].(I64)); +end; +end ViewAdr. diff --git a/conform/err/ViewArrayTooSmall.raz b/conform/err/ViewArrayTooSmall.raz new file mode 100644 index 0000000..bb009f5 --- /dev/null +++ b/conform/err/ViewArrayTooSmall.raz @@ -0,0 +1,7 @@ +module ViewArrayTooSmall; +var mem: [4]U8; i: INT; n: I64; +proc main*; +begin + n := mem[i].(I64); +end; +end ViewArrayTooSmall. diff --git a/conform/err/ViewBool.raz b/conform/err/ViewBool.raz new file mode 100644 index 0000000..7c323bd --- /dev/null +++ b/conform/err/ViewBool.raz @@ -0,0 +1,7 @@ +module ViewBool; +var mem: [8]U8; b: BOOL; +proc main*; +begin + b := mem[0].(BOOL); +end; +end ViewBool. diff --git a/conform/err/ViewCall.raz b/conform/err/ViewCall.raz new file mode 100644 index 0000000..bb6cf55 --- /dev/null +++ b/conform/err/ViewCall.raz @@ -0,0 +1,8 @@ +module ViewCall; +proc f: F64; begin return 1.0; end; +var u: U64; +proc main*; +begin + u := f().(U64); +end; +end ViewCall. diff --git a/conform/err/ViewConst.raz b/conform/err/ViewConst.raz new file mode 100644 index 0000000..f4a2fae --- /dev/null +++ b/conform/err/ViewConst.raz @@ -0,0 +1,8 @@ +module ViewConst; +const Table: [4]U8 = [1, 2, 3, 4]; +var n: U32; +proc main*; +begin + n := Table[0].(U32); +end; +end ViewConst. diff --git a/conform/err/ViewEnum.raz b/conform/err/ViewEnum.raz new file mode 100644 index 0000000..85132b3 --- /dev/null +++ b/conform/err/ViewEnum.raz @@ -0,0 +1,8 @@ +module ViewEnum; +type Colour = (red, green); +var mem: [8]U8; c: Colour; +proc main*; +begin + c := mem[0].(Colour); +end; +end ViewEnum. diff --git a/conform/err/ViewPastEnd.raz b/conform/err/ViewPastEnd.raz new file mode 100644 index 0000000..dbb49a6 --- /dev/null +++ b/conform/err/ViewPastEnd.raz @@ -0,0 +1,7 @@ +module ViewPastEnd; +var mem: [16]U8; n: I64; +proc main*; +begin + n := mem[10].(I64); +end; +end ViewPastEnd. diff --git a/conform/err/ViewReadOnly.raz b/conform/err/ViewReadOnly.raz new file mode 100644 index 0000000..2a0c48f --- /dev/null +++ b/conform/err/ViewReadOnly.raz @@ -0,0 +1,7 @@ +module ViewReadOnly; +import ViewMod; +proc main*; +begin + ViewMod.mem[0].(I64) := 1; +end; +end ViewReadOnly. diff --git a/conform/err/ViewRecordBool.raz b/conform/err/ViewRecordBool.raz new file mode 100644 index 0000000..6ff946f --- /dev/null +++ b/conform/err/ViewRecordBool.raz @@ -0,0 +1,8 @@ +module ViewRecordBool; +type Flags = record on: BOOL; n: I32; end; +var mem: [32]U8; f: Flags; +proc main*; +begin + f := mem[0].(Flags); +end; +end ViewRecordBool. diff --git a/conform/err/ViewSlice.raz b/conform/err/ViewSlice.raz new file mode 100644 index 0000000..2026941 --- /dev/null +++ b/conform/err/ViewSlice.raz @@ -0,0 +1,7 @@ +module ViewSlice; +var mem: [32]U8; s: []U8; +proc main*; +begin + s := mem[0].([]U8); +end; +end ViewSlice. diff --git a/conform/err/ViewSliceOf.raz b/conform/err/ViewSliceOf.raz new file mode 100644 index 0000000..3f4a780 --- /dev/null +++ b/conform/err/ViewSliceOf.raz @@ -0,0 +1,7 @@ +module ViewSliceOf; +var mem: [16]U8; s: []U8; +proc main*; +begin + s := mem[0].([8]U8)[0..4]; +end; +end ViewSliceOf. diff --git a/conform/err/ViewTooBig.raz b/conform/err/ViewTooBig.raz new file mode 100644 index 0000000..5ccac8e --- /dev/null +++ b/conform/err/ViewTooBig.raz @@ -0,0 +1,7 @@ +module ViewTooBig; +var n: I32; u: U64; +proc main*; +begin + u := n.(U64); +end; +end ViewTooBig. diff --git a/conform/err/ViewVarParam.raz b/conform/err/ViewVarParam.raz new file mode 100644 index 0000000..64894ad --- /dev/null +++ b/conform/err/ViewVarParam.raz @@ -0,0 +1,8 @@ +module ViewVarParam; +var mem: [16]U8; +proc put(var x: I64); begin x := 1; end; +proc main*; +begin + put(mem[3].(I64)); +end; +end ViewVarParam. diff --git a/conform/err/ViewVolatile.raz b/conform/err/ViewVolatile.raz new file mode 100644 index 0000000..73c3ddf --- /dev/null +++ b/conform/err/ViewVolatile.raz @@ -0,0 +1,7 @@ +module ViewVolatile; +var p: ^VOLATILE [16]U8; n: U32; +proc main*; +begin + n := p^[4].(U32); +end; +end ViewVolatile. diff --git a/conform/err/mods/ViewMod.raz b/conform/err/mods/ViewMod.raz new file mode 100644 index 0000000..25163dd --- /dev/null +++ b/conform/err/mods/ViewMod.raz @@ -0,0 +1,3 @@ +module ViewMod; +var mem*: [16]U8; +end ViewMod. diff --git a/conform/run/ViewNegative.expect b/conform/run/ViewNegative.expect new file mode 100644 index 0000000..573541a --- /dev/null +++ b/conform/run/ViewNegative.expect @@ -0,0 +1 @@ +0 diff --git a/conform/run/ViewNegative.raz b/conform/run/ViewNegative.raz new file mode 100644 index 0000000..2677f23 --- /dev/null +++ b/conform/run/ViewNegative.raz @@ -0,0 +1,18 @@ +module ViewNegative; +(* A negative index to a view is past the end too *) +import Out; + +var mem: [16]U8; + +proc at(i: INT): I64; +begin + return mem[i].(I64); +end; + +proc main*; +begin + Out.int(at(0)); Out.ln; + Out.int(at(-1)); Out.ln; +end; + +end ViewNegative. diff --git a/conform/run/ViewNegative.status b/conform/run/ViewNegative.status new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/conform/run/ViewNegative.status @@ -0,0 +1 @@ +2 diff --git a/conform/run/ViewPast.expect b/conform/run/ViewPast.expect new file mode 100644 index 0000000..ad47100 --- /dev/null +++ b/conform/run/ViewPast.expect @@ -0,0 +1 @@ +0123456789 \ No newline at end of file diff --git a/conform/run/ViewPast.raz b/conform/run/ViewPast.raz new file mode 100644 index 0000000..a1917c2 --- /dev/null +++ b/conform/run/ViewPast.raz @@ -0,0 +1,16 @@ +module ViewPast; +(* A view of an array's element that runs past the array's end *) +import Out; + +var mem: [16]U8; + +proc main*; +var i: INT; +begin + for i := 0 to 15 do + Out.int(i); + mem[i].(I64) := 1; + end; +end; + +end ViewPast. diff --git a/conform/run/ViewPast.status b/conform/run/ViewPast.status new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/conform/run/ViewPast.status @@ -0,0 +1 @@ +2 diff --git a/conform/run/ViewPastSlice.expect b/conform/run/ViewPastSlice.expect new file mode 100644 index 0000000..6f06f40 --- /dev/null +++ b/conform/run/ViewPastSlice.expect @@ -0,0 +1 @@ +01234567 \ No newline at end of file diff --git a/conform/run/ViewPastSlice.raz b/conform/run/ViewPastSlice.raz new file mode 100644 index 0000000..3e8d439 --- /dev/null +++ b/conform/run/ViewPastSlice.raz @@ -0,0 +1,15 @@ +module ViewPastSlice; +(* A view of a slice's element that runs past the slice's end *) +import Out; + +proc main*; +var a: [16]U8; s: []U8; i: INT; +begin + s := a[2..12]; + for i := 0 to 9 do + Out.int(i); + s[i].(U32) := 1; + end; +end; + +end ViewPastSlice. diff --git a/conform/run/ViewPastSlice.status b/conform/run/ViewPastSlice.status new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/conform/run/ViewPastSlice.status @@ -0,0 +1 @@ +2 diff --git a/conform/run/ViewReals.expect b/conform/run/ViewReals.expect new file mode 100644 index 0000000..c0192a8 --- /dev/null +++ b/conform/run/ViewReals.expect @@ -0,0 +1,5 @@ +1.5's bits 3FF8000000000000 +x from bits, times 2: 5 +F32 1.0's bits 3F800000 +mem[3].(F64) times 8: 2 +its bits 3FD0000000000000 diff --git a/conform/run/ViewReals.raz b/conform/run/ViewReals.raz new file mode 100644 index 0000000..d85c379 --- /dev/null +++ b/conform/run/ViewReals.raz @@ -0,0 +1,26 @@ +(* Views of reals: their bits, read and written (report section 6.9) *) +module ViewReals; +import Out; + +var mem: [16]U8; + +proc main*; +var x: F64; f: F32; u: U64; k: U32; +begin + (* locals kept in registers otherwise *) + x := 1.5; + u := x.(U64); + Out.str("1.5's bits "); Out.hex(u, 16); Out.ln; + u := 4004000000000000H; + x.(U64) := u; + Out.str("x from bits, times 2: "); Out.int(I64(x * 2.0)); Out.ln; + f := 1.0; + k := f.(U32); + Out.str("F32 1.0's bits "); Out.hex(U64(k), 8); Out.ln; + (* a real in an array of bytes *) + mem[3].(F64) := 0.25; + Out.str("mem[3].(F64) times 8: "); Out.int(I64(mem[3].(F64) * 8.0)); Out.ln; + Out.str("its bits "); Out.hex(mem[3].(U64), 16); Out.ln; +end; + +end ViewReals. diff --git a/conform/run/ViewReals.reals b/conform/run/ViewReals.reals new file mode 100644 index 0000000..e69de29 diff --git a/conform/run/Views.expect b/conform/run/Views.expect new file mode 100644 index 0000000..d045b45 --- /dev/null +++ b/conform/run/Views.expect @@ -0,0 +1,16 @@ +mem[16].(I64) -1 +mem[23] 255 +mem[3].(I64), misaligned 1008 +the last 8 bytes 7 +258's first byte 2 +U8(258) 2 +h.count 2 +b[4] 9 +mem[36].(I32) -5 +Pair's value 300 +n through a pointer from bytes 77 +b[8].(I64) 123456789 +sum 59 +regs[1] 5 +regs[3] 6 +ViewData.bytes[0].(I64) 42 diff --git a/conform/run/Views.raz b/conform/run/Views.raz new file mode 100644 index 0000000..edcf1b8 --- /dev/null +++ b/conform/run/Views.raz @@ -0,0 +1,101 @@ +(* Views, v.(T): the bytes of a variable read and written as another + type (report section 6.9). The output holds on a target that puts a + word's low byte first, as appendix A lets a target choose; the + bytes are written here a byte at a time where order matters. *) +module Views; +import Out, ViewData; + +type + Header = record magic: U32; count: U32; end; + Pair = packed record tag: U8; value: I32; end; + +var + mem: [64]U8; (* a module's array *) + regs: [4]U64; + +proc show(label: []U8; v: I64); +begin + Out.str(label); Out.str(" "); Out.int(v); Out.ln; +end; + +(* a var parameter, an array reached through a pointer, viewed *) +proc fill(var b: [16]U8; v: I64); +begin + b[8].(I64) := v; +end; + +(* a slice parameter's element, viewed *) +proc sum(s: []U8): I64; +var i, t: INT; +begin + t := 0; + i := 0; + while i + 4 <= LEN(s) do + t := t + INT(s[i].(I32)); + i := i + 4; + end; + return t; +end; + +proc main*; +var + n, a: I64; b: [16]U8; s: []U8; + p: ^I64; h: Header; +begin + (* an I64 in an array of bytes, at an index known and one not *) + mem[16].(I64) := -1; + show("mem[16].(I64)", mem[16].(I64)); + show("mem[23]", I64(mem[23])); + a := 3; + mem[a].(I64) := 1000; + INC(mem[a].(I64), 8); + show("mem[3].(I64), misaligned", mem[a].(I64)); + mem[56].(I64) := 7; + show("the last 8 bytes", mem[56].(I64)); + + (* a view of a whole variable, a local kept in a register + otherwise: the first byte of a number, its low byte, low byte + first *) + n := 258; + show("258's first byte", I64(n.(U8))); + show("U8(258)", I64(U8(n))); + + (* a record over bytes, and a field of it, read and written *) + b[0] := 1; b[4] := 2; + h := b[0].(Header); + show("h.count", I64(h.count)); + b[0].(Header).count := 9; + show("b[4]", I64(b[4])); + + (* an array as the type, indexed past the view *) + mem[32].([2]I32)[1] := -5; + show("mem[36].(I32)", I64(mem[36].(I32))); + + (* a packed record, and a pointer read from bytes, then followed *) + mem[40].(Pair) := {tag: 1, value: 300}; + show("Pair's value", I64(mem[41].(I32))); + p := ADR(n); + mem[48].(^I64) := p; + mem[48].(^I64)^ := 77; + show("n through a pointer from bytes", n); + + (* a var parameter's array, a slice parameter, a slice's element *) + fill(b, 123456789); + show("b[8].(I64)", b[8].(I64)); + s := mem[0..16]; + s[0].(I32) := 10; s[4].(I32) := 20; s[8].(I32) := 30; s[12].(I32) := -1; + show("sum", sum(s)); + + (* a module's array of U64s viewed as bytes, and an element of + bigger elements viewed from its start *) + regs[1] := 0; + regs[0].([32]U8)[8] := 5; + show("regs[1]", I64(regs[1])); + regs[2].([2]U64)[1] := 6; + show("regs[3]", I64(regs[3])); + + (* another module's variable, read through a view *) + show("ViewData.bytes[0].(I64)", ViewData.bytes[0].(I64)); +end; + +end Views. diff --git a/conform/run/mods/ViewData.raz b/conform/run/mods/ViewData.raz new file mode 100644 index 0000000..1856f86 --- /dev/null +++ b/conform/run/mods/ViewData.raz @@ -0,0 +1,8 @@ +(* An exported variable, which an importer may read through a view *) +module ViewData; + +var bytes*: [8]U8; + +begin + bytes[0] := 42; +end ViewData. diff --git a/doc/compiler.md b/doc/compiler.md index 79c4019..fab23ed 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -18,9 +18,9 @@ | `src/Sym.raz` | 687 | 556 | Types, objects, scopes, layout | | `src/Chunk.raz` | 363 | 279 | The compiled program: chunks, fixups, line notes | | `src/X64.raz` | 1,517 | 1,253 | The instruction encoder, jumps within a procedure, the assembler | -| `src/Gen.raz` | 2,516 | 1,800 | The stack machine, for x86-64: values, operations, checks, calls, frames | -| `src/Item.raz` | 1,792 | 1,478 | Items: types, constants, variables, operators, conversions, calls | -| `src/Parse.raz` | 3,960 | 3,445 | Declarations, statements, expressions, built-ins, recovery, warnings | +| `src/Gen.raz` | 2,552 | 1,821 | The stack machine, for x86-64: values, operations, checks, calls, frames | +| `src/Item.raz` | 1,948 | 1,594 | Items: types, constants, variables, operators, conversions, calls | +| `src/Parse.raz` | 4,000 | 3,478 | Declarations, statements, expressions, built-ins, recovery, warnings | | `src/Link.raz` | 381 | 298 | Tree shaking, layout, patching, the places | | `src/Elf.raz` | 431 | 344 | Static and dynamic ELF, symbol table, line numbers | | `src/Raz.raz` | 305 | 238 | The command line | @@ -1068,7 +1068,7 @@ - jumps: `jump`, `jumpIf` (on a `BOOL`), `jumpCmp` (on two integers), `jumpOut` (`jumpCmp` from within an expression) and `condValue` for `and` and `or`, `fix` where the label is, and `joinJumps`; -- checks: `checkIndex`, `checkEnum`, and `indexSlice`, `slice` and +- checks: `checkIndex`, `checkView`, `checkEnum`, and `indexSlice`, `slice` and `slicePtr`, which check as they make their address or slice; and `indexArray`, an element's address in an array in the frame or a chunk, the index checked before; @@ -1282,6 +1282,37 @@ only the item's type changes. `assign` stores, or copies records and arrays. `convert` is the written conversion, `T(x)`. +Views, `v.(T)` (report section 6.9): a view is the item of `v` with +`T` for its type. It is at the same place, so nothing is copied or +computed to make it: `mem[16].(I64) := n` compiles to the store +`mem[16] := n` would be, but of 8 bytes. What `view` and `indexView` +add is the checks: + +- `viewable`: `v` is a variable (not a constant or a temporary; another + module's is read only, by its `ro`), not volatile, and `T` is plain + data (`notPlain`: integers, reals, pointers, and records and arrays + of them alone); +- the room: `view` wants `T` to fit in `v`, which the compiler always + knows; `indexView`, for `a[i].(T)`, wants `T` from `a[i]` to `a`'s + end. `T` takes `k` elements (`elementsFor`), so in an array of `n` + the index must be below `n - k + 1`: one unsigned compare + (`Gen.checkView`) in place of `index`'s `i < n`, which a negative + `i`, huge unsigned, fails too. A slice's length is known only as the + program runs: `Gen.indexSlice` checks `i < len` as ever, then, with + a view's `room` of `k - 1`, that `len - i`, which can't wrap once `i + < len`, is more than `room` (`checkRoom`). A failed one is kind 7 of + `Rt.fail`: "a view at index 9 runs past a length of 16". + +The item is marked `view`, which keeps `ADR`, a `var` argument and a +slice from it (`noAddress`), as `odd` does for a field of a packed +record: a view may be misaligned. A variable kept in a register has no +bytes to view, so `becomeView` demotes it to memory as `address` does +(`demote`), and the procedure is compiled again. The parser sees a view +of an element only after the `]`: `designator` reads the index, then +looks past the `]` for `.(` (`viewNext`, by `Scan.saveScan` and +`restoreScan`), so that `indexView` has the index and the array +together. + Calls: `beginCall`, then `passArg` for each argument, then `endCall`, which has Gen's `call` make the call. Each argument is left on Gen's stack, a slice as its two words (`pushWords`). `return f(x);` passing on @@ -1300,7 +1331,8 @@ Start with expressions, bottom up: `factor`, `term`, `simpleExpr`, `relation`, `conjunct` (the `and`s), `expression` (the `or`s). Then `designator`, which reads a name and what follows -it: `.field`, `^`, `[i]`, `[lo..hi]`, a call, a conversion. Each step +it: `.field`, `^`, `[i]`, `[lo..hi]`, a call, a conversion, a view +`.(T)`. Each step calls the matching routine in `Item.raz` on the item it has. The `want` parameter carries the type an expression must have, where it is known, so that `[1, 2, 3]`, `{x: 1}` and `{red}` know what to build diff --git a/lib/Rt.raz b/lib/Rt.raz index d1c4274..cd528fa 100644 --- a/lib/Rt.raz +++ b/lib/Rt.raz @@ -537,7 +537,8 @@ status 2. what is 0 for an index a and 1 for a slice a..b, of something whose length is len; 2 for a, which is no position of the enumeration called name; 3 for a slice a..b of a pointer, which - runs backwards. What a target's machine doesn't catch the code + runs backwards; 7 for a view at index a that runs past the end of + something whose length is len. What a target's machine doesn't catch the code tests for, and stops at with what 4, a nil pointer; 5, a division by zero; 6, a stack overflow; these end the program by exit with status 2 too, as the signal handler does. rdi and rsi are the @@ -547,7 +548,7 @@ regs[5] := rdi; regs[6] := rsi; where(at); - if what >= 4 then + if (what >= 4) and (what <= 6) then put("stopped by "); if what = 4 then put("a nil pointer"); elsif what = 5 then put("a division fault"); @@ -560,6 +561,11 @@ if what = 0 then put("index "); putInt(a); + elsif what = 7 then + put("a view at index "); + putInt(a); + put(" runs past a length of "); + putInt(len); elsif (what = 1) or (what = 3) then put("slice "); putInt(a); diff --git a/src/Gen.raz b/src/Gen.raz index 7e95016..b619349 100644 --- a/src/Gen.raz +++ b/src/Gen.raz @@ -134,7 +134,7 @@ rtFail*, argcChunk*, argvChunk*: INT; (* the stubs that check's code calls, one for each kind of failure, made by entryPoint for those used *) - failStubs: [6]INT; + failStubs: [8]INT; lost*: BOOL; (* a parameter kept where it arrived was wanted for other work: the procedure is compiled again, the parameter in memory *) @@ -191,7 +191,7 @@ end; const - StubNames: [6][]U8 = ["check0", "check1", "check2", "check3", "check4", "check5"]; + StubNames: [8][]U8 = ["check0", "check1", "check2", "check3", "check4", "check5", "check6", "check7"]; (* the registers of the stack: the value at depth d is in Regs[d mod NumRegs]. rax, rdx and rcx, which division and shifts need, and rsi and rdi, which copying needs, aren't among them. *) @@ -1451,7 +1451,8 @@ found by at, which a stub works out from where it was called; what is an index a (0), a slice a..b (1), each for a length len, a position a of the enumeration called name (2), a slice of a pointer a..b that - runs backwards (3), or a nil pointer (4). Rt.fail knows 5 and 6, a + runs backwards (3), a nil pointer (4), or a view at index a that runs + past a length len (7). Rt.fail knows 5 and 6, a division fault and a stack overflow, which this machine catches itself, so no check here has them. The arguments go in rdi, rsi, rdx, rcx, r8 and r9: a is in register ra, b in RDX; len is in memory at m, @@ -1528,6 +1529,38 @@ check(X.ccB, 0, p, r, noMem(), n, -1); end; +(* The index on top is the element a view starts at, in an array of n + elements: the view needs k elements from there, so the index must be + below n - k + 1, which is below. A negative index is a huge one, + unsigned, so one comparison does (report section 6.9). *) +proc checkView*(n, below: I64; p: Diag.Pos); +var r: INT; +begin + r := peek(depth - 1); + cmpI(r, below); + check(X.ccB, 7, p, r, noMem(), n, -1); +end; + +(* What a failed index check is: an index past the length (0), or a + view that runs past it (7), when the view needs room elements more + than the one indexed. *) +proc kindOfIndex(room: I64): INT; +begin + if room > 0 then return 7; end; + return 0; +end; + +(* A view of a slice's element, at the index in r, needs room elements + after it: rdx holds the slice's length, which r is below already, + so length - r, at least 1, can't wrap, and must be more than room. + The length is at m for the message. *) +proc checkRoom(r: INT; room: I64; p: Diag.Pos; m: X.Mem); +begin + X.alu(X.aluSub, RDX, r); + X.aluI(X.aluCmp, RDX, INT(room)); + check(X.ccA, 7, p, r, m, 0, -1); +end; + (* The integer on top is a position of an enumeration of n names *) proc checkEnum*(n: I64; name: INT; p: Diag.Pos); var r: INT; @@ -1568,7 +1601,7 @@ compared with and added to them; for an element of 1, 2, 4 or 8 bytes, its address is only noted, as the operand [pointer + index * size], to be read or written where it is used (lIdx). *) -proc indexSlice*(a: Adr; size: I64; checked: BOOL; p: Diag.Pos); +proc indexSlice*(a: Adr; size, room: I64; checked: BOOL; p: Diag.Pos); var m, ml: X.Mem; r: INT; inRax: BOOL; o: I64; begin if (a.base = bReg) and (((size = 1) or (size = 2) or (size = 4) or (size = 8))) then @@ -1577,7 +1610,8 @@ r := peek(depth - 1); if checked then X.alu(X.aluCmp, r, a.hi); - check(X.ccB, 0, p, r, inRegister(a.hi), 0, -1); + check(X.ccB, kindOfIndex(room), p, r, inRegister(a.hi), 0, -1); + if room > 0 then X.movRR(RDX, a.hi); checkRoom(r, room, p, inRegister(a.hi)); end; end; drop(); newMem(lIdx, X.memIdx(a.chunk, r, INT(size), o), kWord, 8, false); @@ -1589,7 +1623,8 @@ if a.base = bReg then if checked then X.alu(X.aluCmp, r, a.hi); - check(X.ccB, 0, p, r, inRegister(a.hi), 0, -1); + check(X.ccB, kindOfIndex(room), p, r, inRegister(a.hi), 0, -1); + if room > 0 then X.movRR(RDX, a.hi); checkRoom(r, room, p, inRegister(a.hi)); end; end; mulI(r, size); X.alu(X.aluAdd, r, a.chunk); @@ -1598,7 +1633,8 @@ ml := m; ml.disp := ml.disp + 8; if checked then X.aluM(X.aluCmp, r, ml); - check(X.ccB, 0, p, r, ml, 0, -1); + check(X.ccB, kindOfIndex(room), p, r, ml, 0, -1); + if room > 0 then X.load(RDX, ml, 8, false); checkRoom(r, room, p, ml); end; end; mulI(r, size); X.aluM(X.aluAdd, r, m); diff --git a/src/Item.raz b/src/Item.raz index 8314117..3fe2695 100644 --- a/src/Item.raz +++ b/src/Item.raz @@ -48,6 +48,8 @@ vol*: BOOL; (* mVar: reached through ^VOLATILE *) isVar*: BOOL; (* mVar: a variable of the program, not a temporary *) odd*: BOOL; (* mVar: in a packed record, so maybe misaligned *) + view*: BOOL; (* mVar: a view, v.(T), or part of one: maybe + misaligned, and with no address *) ro*: BOOL; (* mVar: another module's exported variable, or part of one, which only that module changes *) deref*: BOOL; (* mVar: at an address from a pointer, which may be @@ -363,19 +365,25 @@ return nil; end; -(* The address of the variable or string x, on top of the stack *) -proc address*(var x: Item): ERROR; +(* x, a variable kept in a register, is wanted in memory after all, for + its address or a view of its bytes: the procedure is compiled again + with the variable in memory; till then, this code is thrown away *) +proc demote(var x: Item); begin - nilTest(x); if (x.mode = mVar) and (x.base = Gen.bReg) then - (* its address is wanted after all: the procedure is compiled again - with the variable in memory; till then, this code is thrown away *) x.obj^.reg := 0; x.obj^.reg2 := 0; demoted := true; x.base := Gen.bFrame; x.off := x.obj^.val; end; +end; + +(* The address of the variable or string x, on top of the stack *) +proc address*(var x: Item): ERROR; +begin + nilTest(x); + demote(x); if x.mode = mStr then Gen.pushAdr(globalAdr(x.chunk)); elsif x.mode = mVar then Gen.pushAdr(adrOf(x)); @@ -509,6 +517,13 @@ return Scan.Failed; end; +(* An error at x, which is a view, or part of one, and so has no + address: text, and help that says what to do instead. *) +proc noAddress*(x: Item; text: []U8): ERROR; +begin + return Scan.markHelp(x.pos, text, "a view has no address, since it may be misaligned: copy it to a variable"); +end; + proc coerce*(var x: Item; t: ^Sym.Type): ERROR; var s: ^Sym.Type; tmp: I64; begin @@ -546,6 +561,7 @@ try notReadOnly(x); if x.vol then return Scan.markAt(x.pos, "can't make a slice through a volatile pointer"); end; if x.odd then return Scan.markAt(x.pos, "can't make a slice of a field of a packed record"); end; + if x.view then return noAddress(x, "can't make a slice of a view"); end; try address(x); sliceOf(x, t, s^.len); elsif (x.mode = mProc) and (t^.form # Sym.fProc) and (s^.base = nil) then @@ -612,6 +628,7 @@ try value(x); x.mode := mVar; x.base := Gen.bStack; x.off := 0; x.deref := true; x.typ := t^.base; x.vol := t^.vol; x.isVar := true; x.odd := false; x.ro := false; + x.view := false; return nil; end; @@ -669,7 +686,7 @@ Gen.op(Scan.sPlus, Gen.kWord, 8, false); else Gen.indexPtr(s); end; x.mode := mVar; x.base := Gen.bStack; x.off := 0; - x.vol := t^.vol; x.isVar := true; x.odd := false; x.ro := false; + x.vol := t^.vol; x.isVar := true; x.odd := false; x.ro := false; x.view := false; elsif (t^.form = Sym.fArray) and (y.mode = mConst) then if (y.val < 0) or (y.val >= t^.len) then return Scan.markAt(y.pos, Diag.say("index {} is out of range for a length of {}", [Fmt.int(y.val), Fmt.int(t^.len)])); @@ -683,7 +700,7 @@ x.base := Gen.bStack; else try value(y); - Gen.indexSlice(adrOf(x), s, checks, y.pos); + Gen.indexSlice(adrOf(x), s, 0, checks, y.pos); x.base := Gen.bStack; x.off := 0; x.isVar := true; x.vol := false; x.ro := false; end; x.typ := t^.base; @@ -707,6 +724,7 @@ end; if x.vol then return Scan.markAt(x.pos, "can't make a slice through a volatile pointer"); end; if x.odd then return Scan.markAt(x.pos, "can't make a slice of a field of a packed record"); end; + if x.view then return noAddress(x, "can't make a slice of a view"); end; if t^.form = Sym.fArray then try notReadOnly(x); end; try value(hi); tmp := Gen.allocTemp(16, 8); @@ -718,6 +736,143 @@ return nil; end; +(* Views, v.(T): the bytes of the variable v read and written as a T + (report section 6.9). A view is the item of v with T for its type: + the same place, so nothing is copied or computed to make one. What + is left is to check the type, and that T's bytes lie where v's room + is; and to mark the item a view, which may be misaligned, as a field + of a packed record may, so that nothing takes its address. *) + +(* Any bytes at all are a value of an integer, a real or a pointer, + and of a record or array made of them alone. A BOOL, an enumeration + or a set has bytes that are none of its values, and a slice, + variant, procedure or ERROR holds more than bytes can say. The type + in t that isn't plain data, or nil if all of it is. *) +proc notPlain(t: ^Sym.Type): ^Sym.Type; +var f: ^Sym.Obj; u: ^Sym.Type; +begin + match t^.form of + | fInt, fReal, fPtr: return nil; + | fArray: return notPlain(t^.base); + | fRecord: + if t^.tuple then return t; end; + f := t^.fields; + while f # nil do + u := notPlain(f^.typ); + if u # nil then return u; end; + f := f^.next; + end; + return nil; + | else: return t; + end; +end; + +(* What x must be to have a view made of it, as a T: a variable, not + volatile, and T a type of plain data. *) +proc viewable(x: Item; t: ^Sym.Type): ERROR; +var u: ^Sym.Type; text: []U8; +begin + (* another module's variable, ro, is one too, read and not written *) + if (x.mode # mVar) or not (x.isVar or x.ro) then + return Scan.markHelp(x.pos, "a view needs a variable", + "a constant, or the result of a call or an operator, has no bytes to view: copy it to a variable"); + end; + if x.vol then + return Scan.markHelp(x.pos, "can't make a view of a volatile variable", + "a view may be misaligned, which can't be one access: reach a device through a ^VOLATILE pointer to a record"); + end; + u := notPlain(t); + if u = nil then return nil; end; + if u # t then + text := say2("can't view bytes as {}, which holds {}", Sym.typeName(t), Sym.typeName(u)); + else + text := say1("can't view bytes as {}", Sym.typeName(t)); + end; + if u^.form = Sym.fBool then + return Scan.markHelp(x.pos, text, "some bytes are no BOOL: view an integer, and compare it with 0"); + elsif u^.form in {Sym.fEnum, Sym.fSet} then + return Scan.markHelp(x.pos, text, + say1("some bytes are no {}: view an integer, and convert it", Sym.typeName(u))); + end; + 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; + +(* 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. *) +proc becomeView(var x: Item; t: ^Sym.Type); +begin + demote(x); + x.typ := t; + x.view := true; +end; + +(* v.(T), where v is not an element: T must fit in v itself. *) +proc view*(var x: Item; t: ^Sym.Type): ERROR; +begin + try viewable(x, t); + if t^.size > x.typ^.size then + return Scan.markAt(x.pos, Diag.say("a view of {} bytes doesn't fit in {}, of {}", + [Fmt.int(t^.size), Fmt.str(Sym.typeName(x.typ)), Fmt.int(x.typ^.size)])); + end; + becomeView(x, t); + return nil; +end; + +(* The number of elements of size s that n bytes reach into, at least + one: those of a[i] up to a[i + k - 1]. *) +proc elementsFor(n, s: I64): I64; +begin + if (s = 0) or (n <= s) then return 1; end; + return (n + s - 1) div s; +end; + +(* a[i].(T): x is the array, slice or pointer, y the index. T must lie + from a[i] to a's end: in an array of n elements, k of them from i on, + so i is below n - k + 1; a slice's length is known only as the + program runs, which checks that length - i, at least 1 since i is + below it, is at least k. Through a pointer, no check: p[i] has none + (report section 6.9). *) +proc indexView*(var x, y: Item; t: ^Sym.Type): ERROR; +var at: ^Sym.Type; s, k: I64; +begin + at := x.typ; + s := at^.base^.size; + k := elementsFor(t^.size, s); + if not Sym.isInt(y.typ) then + return Scan.markAt(y.pos, say1("an index is an integer, found {}", what(y))); + end; + if (at^.form = Sym.fArray) and (k > at^.len) then + return Scan.markAt(Diag.join(x.pos, y.pos), Diag.say("a view of {} bytes doesn't fit in {}, of {}", + [Fmt.int(t^.size), Fmt.str(Sym.typeName(at)), Fmt.int(at^.size)])); + end; + if (at^.form = Sym.fArray) and (y.mode = mConst) then + if (y.val < 0) or (y.val > at^.len - k) then + return Scan.markAt(y.pos, Diag.say("a view of {} bytes at index {} runs past a length of {}", + [Fmt.int(t^.size), Fmt.int(y.val), Fmt.int(at^.len)])); + end; + try index(x, y); + elsif (at^.form = Sym.fArray) and checks then + (* as index does, with the view's check in place of i < n *) + try value(y); + Gen.checkView(at^.len, at^.len - k + 1, y.pos); + if x.base = Gen.bStack then scaleBy(s); Gen.op(Scan.sPlus, Gen.kWord, 8, false); + else Gen.indexArray(adrOf(x), s); x.off := 0; end; + x.base := Gen.bStack; + x.typ := at^.base; + elsif at^.form = Sym.fSlice then + try value(y); + Gen.indexSlice(adrOf(x), s, k - 1, checks, y.pos); + x.base := Gen.bStack; x.off := 0; x.isVar := true; x.vol := false; x.ro := false; + x.typ := at^.base; + else + try index(x, y); + end; + try viewable(x, t); + becomeView(x, t); + return nil; +end; + (* Operators *) proc neg*(var x: Item): ERROR; @@ -1090,10 +1245,10 @@ end; t := xt; elsif Sym.same(xt, yt) then t := xt; - (* an INT meeting an I64 widens to it, a UINT to a U64 (report - section 6.1): the same 64 bits here, so only the type changes *) - elsif widens(xt, yt) then t := yt; - elsif widens(yt, xt) then t := xt; + elsif widens(xt, yt) or widens(yt, xt) then + (* an INT meeting an I64 widens to it, a UINT to a U64 (report + section 6.1): the same 64 bits here, so only the type changes *) + if widens(xt, yt) then t := yt; else t := xt; end; else return mismatchOps(x, y, xt, yt); end; if not intOp(op) then return doesntApply(op, x, y, t); end; elsif (xt^.form = Sym.fReal) and (yt^.form = Sym.fReal) then @@ -1356,6 +1511,7 @@ try notReadOnly(a); if (a.mode # mVar) or not a.isVar then return Scan.markAt(a.pos, "a var parameter needs a variable"); end; if a.odd then return Scan.markAt(a.pos, "a field of a packed record can't be a var parameter"); end; + if a.view then return noAddress(a, "a view can't be a var parameter"); end; if not Sym.same(a.typ, p^.typ) then return mismatch(a, say2("a var parameter needs exactly {}, found {}", Sym.typeName(p^.typ), what(a))); end; diff --git a/src/Parse.raz b/src/Parse.raz index 45cd158..705010a 100644 --- a/src/Parse.raz +++ b/src/Parse.raz @@ -905,6 +905,7 @@ try Item.notReadOnly(y); if (y.mode # Item.mVar) or not y.isVar then return Scan.markAt(y.pos, "ADR needs a variable"); end; if y.odd then return Scan.markAt(y.pos, "a field of a packed record has no address"); end; + if y.view then return Item.noAddress(y, "ADR can't take a view"); end; t := newPtr(y.typ, y.vol); try Item.address(y); Item.makeConst(x, t, 0); @@ -1012,6 +1013,28 @@ (* A designator, with any selectors and calls after it. called tells whether the last thing done was a call. *) +(* Whether a view, ".(", is next: a "." and, past it, a "(". *) +proc viewNext: BOOL; +var st: Scan.State; yes: BOOL; +begin + if Scan.tok # Scan.sPeriod then return false; end; + Scan.saveScan(st); + Scan.next; + yes := Scan.tok = Scan.sLparen; + Scan.restoreScan(st); + return yes; +end; + +(* The "(" T ")" of a view, at the "(": T. *) +proc viewType: (PType, ERROR); +var t: PType; +begin + Scan.next; + t := try parseType(); + try expect(Scan.sRparen); + return t, nil; +end; + proc designator(var x: TItem; var called: BOOL): ERROR; var o, f: PObj; y, z: TItem; t: PType; start: INT; begin @@ -1032,12 +1055,18 @@ x.pos := Scan.spanFromAt(start); match Scan.tok of | sPeriod: - Scan.next; - if (x.mode # Item.mVar) or (x.typ^.form # Sym.fRecord) then return fieldOfWhat(x); end; - if Scan.tok # Scan.sIdent then return expected("a field"); end; - f := try fieldOf(x.typ); Scan.next; - try Item.field(x, f); + if Scan.tok = Scan.sLparen then + t := try viewType(); + x.pos := Scan.spanFromAt(start); + try Item.view(x, t); + else + if (x.mode # Item.mVar) or (x.typ^.form # Sym.fRecord) then return fieldOfWhat(x); end; + if Scan.tok # Scan.sIdent then return expected("a field"); end; + f := try fieldOf(x.typ); + Scan.next; + try Item.field(x, f); + end; called := false; | sArrow: Scan.next; @@ -1052,10 +1081,21 @@ try Item.sliceLo(y); try expression(z, nil); try Item.slice(x, y, z); + try expect(Scan.sRbrak); else - try Item.index(x, y); + (* a[i].(T), a view of an element, is checked against the + end of a, not of the element: so the parser looks past + the "]" for ".(" before the index is made *) + try expect(Scan.sRbrak); + if viewNext() then + Scan.next; + t := try viewType(); + x.pos := Scan.spanFromAt(start); + try Item.indexView(x, y, t); + else + try Item.index(x, y); + end; end; - try expect(Scan.sRbrak); called := false; | sLparen: if x.mode = Item.mType then diff --git a/src/check.sh b/src/check.sh index 754b95a..635f83c 100755 --- a/src/check.sh +++ b/src/check.sh @@ -9,7 +9,8 @@ # 2026-10.25): the files that use them are the compiler's alone, and # so are those whose message says what match takes. It predates, too, # an INT widened in an expression and the rest (report 2026-10.26), -# and the messages for an I64 that goes to an INT. +# and the messages for an I64 that goes to an INT; and views, v.(T), +# whose tests are conform/*/View*.raz. newer="conform/run/RawStrings.raz conform/err/ScanRawOpen.raz conform/err/ScanRawIndent.raz conform/run/MatchStr.raz conform/err/MatchStrTwice.raz conform/err/MatchStrNoElse.raz conform/err/MatchStrVar.raz conform/err/MatchReal.raz conform/err/AtMatch.raz @@ -17,6 +18,7 @@ conform/run/IntWiden.raz conform/err/IntIncNarrow.raz conform/err/IntNarrow.raz conform/err/IntNarrowSum.raz conform/err/IntResultsNarrow.raz" newer() { + case $1 in conform/*/View*.raz) return 0 ;; esac for g in $newer; do [ $g = $1 ] && return 0; done return 1 } diff --git a/test/msg/ViewAdr.err b/test/msg/ViewAdr.err new file mode 100644 index 0000000..9bb2893 --- /dev/null +++ b/test/msg/ViewAdr.err @@ -0,0 +1,5 @@ +conform/err/ViewAdr.raz:5:14: error: ADR can't take a view + 5 | p := ADR(mem[0].(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/ViewArrayTooSmall.err b/test/msg/ViewArrayTooSmall.err new file mode 100644 index 0000000..148de8d --- /dev/null +++ b/test/msg/ViewArrayTooSmall.err @@ -0,0 +1,4 @@ +conform/err/ViewArrayTooSmall.raz:5:10: error: a view of 8 bytes doesn't fit in [4]U8, of 4 + 5 | n := mem[i].(I64); + | ^^^^^ +raz: 1 error diff --git a/test/msg/ViewBool.err b/test/msg/ViewBool.err new file mode 100644 index 0000000..091e73a --- /dev/null +++ b/test/msg/ViewBool.err @@ -0,0 +1,5 @@ +conform/err/ViewBool.raz:5:10: error: can't view bytes as BOOL + 5 | b := mem[0].(BOOL); + | ^^^^^^^^^^^^^ +help: some bytes are no BOOL: view an integer, and compare it with 0 +raz: 1 error diff --git a/test/msg/ViewCall.err b/test/msg/ViewCall.err new file mode 100644 index 0000000..cccf146 --- /dev/null +++ b/test/msg/ViewCall.err @@ -0,0 +1,5 @@ +conform/err/ViewCall.raz:6:10: error: a view needs a variable + 6 | u := f().(U64); + | ^^^^^^^^^ +help: a constant, or the result of a call or an operator, has no bytes to view: copy it to a variable +raz: 1 error diff --git a/test/msg/ViewConst.err b/test/msg/ViewConst.err new file mode 100644 index 0000000..5dc62d3 --- /dev/null +++ b/test/msg/ViewConst.err @@ -0,0 +1,5 @@ +conform/err/ViewConst.raz:6:10: error: a view needs a variable + 6 | n := Table[0].(U32); + | ^^^^^^^^^^^^^^ +help: a constant, or the result of a call or an operator, has no bytes to view: copy it to a variable +raz: 1 error diff --git a/test/msg/ViewEnum.err b/test/msg/ViewEnum.err new file mode 100644 index 0000000..96e29bd --- /dev/null +++ b/test/msg/ViewEnum.err @@ -0,0 +1,5 @@ +conform/err/ViewEnum.raz:6:10: error: can't view bytes as Colour + 6 | c := mem[0].(Colour); + | ^^^^^^^^^^^^^^^ +help: some bytes are no Colour: view an integer, and convert it +raz: 1 error diff --git a/test/msg/ViewNegative.stderr b/test/msg/ViewNegative.stderr new file mode 100644 index 0000000..e01e07e --- /dev/null +++ b/test/msg/ViewNegative.stderr @@ -0,0 +1,3 @@ +conform/run/ViewNegative.raz:9:16: a view at index -1 runs past a length of 16 + in ViewNegative.at at conform/run/ViewNegative.raz:9:16: i = -1 + in ViewNegative.main at conform/run/ViewNegative.raz:15:5 diff --git a/test/msg/ViewPast.stderr b/test/msg/ViewPast.stderr new file mode 100644 index 0000000..96b6147 --- /dev/null +++ b/test/msg/ViewPast.stderr @@ -0,0 +1,2 @@ +conform/run/ViewPast.raz:12:13: a view at index 9 runs past a length of 16 + in ViewPast.main at conform/run/ViewPast.raz:12:13: i = 9 diff --git a/test/msg/ViewPastEnd.err b/test/msg/ViewPastEnd.err new file mode 100644 index 0000000..6db5171 --- /dev/null +++ b/test/msg/ViewPastEnd.err @@ -0,0 +1,4 @@ +conform/err/ViewPastEnd.raz:5:14: error: a view of 8 bytes at index 10 runs past a length of 16 + 5 | n := mem[10].(I64); + | ^^ +raz: 1 error diff --git a/test/msg/ViewPastSlice.stderr b/test/msg/ViewPastSlice.stderr new file mode 100644 index 0000000..aae03ba --- /dev/null +++ b/test/msg/ViewPastSlice.stderr @@ -0,0 +1,2 @@ +conform/run/ViewPastSlice.raz:11:11: a view at index 7 runs past a length of 10 + in ViewPastSlice.main at conform/run/ViewPastSlice.raz:11:11: i = 7 diff --git a/test/msg/ViewReadOnly.err b/test/msg/ViewReadOnly.err new file mode 100644 index 0000000..5a346cc --- /dev/null +++ b/test/msg/ViewReadOnly.err @@ -0,0 +1,4 @@ +conform/err/ViewReadOnly.raz:5:5: error: ViewMod.mem[0].(I64) is ViewMod's, and can't be changed outside it + 5 | ViewMod.mem[0].(I64) := 1; + | ^^^^^^^^^^^^^^^^^^^^ +raz: 1 error diff --git a/test/msg/ViewRecordBool.err b/test/msg/ViewRecordBool.err new file mode 100644 index 0000000..02c56ec --- /dev/null +++ b/test/msg/ViewRecordBool.err @@ -0,0 +1,5 @@ +conform/err/ViewRecordBool.raz:6:10: error: can't view bytes as Flags, which holds BOOL + 6 | f := mem[0].(Flags); + | ^^^^^^^^^^^^^^ +help: some bytes are no BOOL: view an integer, and compare it with 0 +raz: 1 error diff --git a/test/msg/ViewSlice.err b/test/msg/ViewSlice.err new file mode 100644 index 0000000..c721a88 --- /dev/null +++ b/test/msg/ViewSlice.err @@ -0,0 +1,5 @@ +conform/err/ViewSlice.raz:5:10: error: can't view bytes as []U8 + 5 | s := mem[0].([]U8); + | ^^^^^^^^^^^^^ +help: a view is an integer, a real or a pointer, or a record or array made of them +raz: 1 error diff --git a/test/msg/ViewSliceOf.err b/test/msg/ViewSliceOf.err new file mode 100644 index 0000000..0d06f78 --- /dev/null +++ b/test/msg/ViewSliceOf.err @@ -0,0 +1,5 @@ +conform/err/ViewSliceOf.raz:5:10: error: can't make a slice of a view + 5 | s := mem[0].([8]U8)[0..4]; + | ^^^^^^^^^^^^^^ +help: a view has no address, since it may be misaligned: copy it to a variable +raz: 1 error diff --git a/test/msg/ViewTooBig.err b/test/msg/ViewTooBig.err new file mode 100644 index 0000000..8bb6e59 --- /dev/null +++ b/test/msg/ViewTooBig.err @@ -0,0 +1,4 @@ +conform/err/ViewTooBig.raz:5:10: error: a view of 8 bytes doesn't fit in I32, of 4 + 5 | u := n.(U64); + | ^^^^^^^ +raz: 1 error diff --git a/test/msg/ViewVarParam.err b/test/msg/ViewVarParam.err new file mode 100644 index 0000000..50da164 --- /dev/null +++ b/test/msg/ViewVarParam.err @@ -0,0 +1,5 @@ +conform/err/ViewVarParam.raz:6:9: error: a view can't be a var parameter + 6 | put(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/ViewVolatile.err b/test/msg/ViewVolatile.err new file mode 100644 index 0000000..800d7fa --- /dev/null +++ b/test/msg/ViewVolatile.err @@ -0,0 +1,5 @@ +conform/err/ViewVolatile.raz:5:10: error: can't make a view of a volatile variable + 5 | n := p^[4].(U32); + | ^^^^^^^^^^^ +help: a view may be misaligned, which can't be one access: reach a device through a ^VOLATILE pointer to a record +raz: 1 error