raz / commit 0081856c

commit
0081856c0c285fc8a3b9a7932475ae2bfa6b736d
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
ae6fc91d
A constant's slice part may name another module's array constant

constPart took the whole constant only by its bare name, by the length
of its text; Widths.Wide failed. It now asks for the constant's own
type, which a part of it, an element or a slice, hasn't.

patch · log

5 files changed, +11 -7

conform/run/EmptySliceConst.expect (history) modified +2 -0

@@ -3,3 +3,5 @@
33 wide 1
44 narrow 0
55 none 0
6+Widths.Wide 3
7+Widths.Narrow 0

conform/run/EmptySliceConst.raz (history) modified +2 -1

@@ -10,7 +10,8 @@
1010 None: []I64 = [];
1111 Wide: [][2]I32 = [[1100H, 115FH]];
1212 Narrow: [][2]I32 = [];
13- Props: []Prop = [{name: "wide", runs: Wide}, {name: "narrow", runs: Narrow}, {name: "none", runs: []}];
13+ Props: []Prop = [{name: "wide", runs: Wide}, {name: "narrow", runs: Narrow}, {name: "none", runs: []},
14+ {name: "Widths.Wide", runs: Widths.Wide}, {name: "Widths.Narrow", runs: Widths.Narrow}];
1415
1516 proc sum(a: []I64): I64;
1617 var s: I64; i: INT;

doc/compiler.md (history) modified +1 -1

@@ -20,7 +20,7 @@
2020 | `src/X64.raz` | 1,517 | 1,253 | The instruction encoder, jumps within a procedure, the assembler |
2121 | `src/Gen.raz` | 2,552 | 1,821 | The stack machine, for x86-64: values, operations, checks, calls, frames |
2222 | `src/Item.raz` | 2,037 | 1,651 | Items: types, constants, variables, operators, conversions, calls |
23-| `src/Parse.raz` | 4,175 | 3,616 | Declarations, statements, expressions, built-ins, recovery, warnings |
23+| `src/Parse.raz` | 4,176 | 3,615 | Declarations, statements, expressions, built-ins, recovery, warnings |
2424 | `src/Link.raz` | 381 | 298 | Tree shaking, layout, patching, the places |
2525 | `src/Elf.raz` | 431 | 344 | Static and dynamic ELF, symbol table, line numbers |
2626 | `src/Raz.raz` | 305 | 238 | The command line |

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

@@ -3234,9 +3234,10 @@
32343234 COPY(constBytes[off..off + INT(e.val)], Chunk.rodata[st..st + INT(e.val)]);
32353235 end;
32363236 elsif t^.form = Sym.fSlice then
3237- if (e.mode # Item.mVar) or (e.obj = nil) or (e.obj^.cls # Sym.oConst)
3238- or not (e.typ^.form in {Sym.fArray, Sym.fSlice})
3239- or (e.pos.b - e.pos.a # LEN(nameOf(e.obj^.name))) or not Sym.same(e.typ^.base, t^.base) then
3237+ (* the whole constant, here or another module's, not a part of
3238+ it, which has a type of its own: the element's, or a slice's *)
3239+ if (e.mode # Item.mVar) or (e.obj = nil) or (e.obj^.cls # Sym.oConst) or (e.typ # e.obj^.typ)
3240+ or not (e.typ^.form in {Sym.fArray, Sym.fSlice}) or not Sym.same(e.typ^.base, t^.base) then
32403241 return Scan.markAt(e.pos, say1("a constant slice is a string, an array constant of its elements or [], found {}", Item.what(e)));
32413242 end;
32423243 if e.typ^.form = Sym.fArray then (* else an empty slice constant, whose bytes stay zero *)

test/msg/EmptySliceConst.stderr (history) modified +2 -2

@@ -1,2 +1,2 @@
1-conform/run/EmptySliceConst.raz:34:18: index 0 is out of range for a length of 0
2- in EmptySliceConst.main at conform/run/EmptySliceConst.raz:34:18: i = 0
1+conform/run/EmptySliceConst.raz:35:18: index 0 is out of range for a length of 0
2+ in EmptySliceConst.main at conform/run/EmptySliceConst.raz:35:18: i = 0