| | @@ -3261,7 +3261,7 @@ |
| 3261 | 3261 | |
| 3262 | 3262 | (* The part of type t at offset off of the constant *) |
| 3263 | 3263 | proc constPart(t: PType; off: INT): ERROR; |
| 3264 | | -var e: TItem; f: PObj; k: INT; r: F32; start: Diag.Pos; src: ^U8; st: INT; |
| 3264 | +var e: TItem; f: PObj; k: INT; r: F32; start: Diag.Pos; src: ^U8; st, fx: INT; |
| 3265 | 3265 | begin |
| 3266 | 3266 | start := Scan.tokPos(); |
| 3267 | 3267 | if (t^.form = Sym.fSlice) and (Scan.tok = Scan.sLbrak) and (literalLength() = 0) then |
| | @@ -3331,7 +3331,17 @@ |
| 3331 | 3331 | elsif t^.form = Sym.fVariant then |
| 3332 | 3332 | return Scan.markAt(e.pos, say1("expected a case of {}", Sym.typeName(t))); |
| 3333 | 3333 | elsif (t^.form = Sym.fArray) or (t^.form = Sym.fRecord) then |
| 3334 | | - return Scan.markAt(e.pos, say1("expected a literal of {}", Sym.typeName(t))); |
| 3334 | + (* a literal, or the whole of a constant of the type: its bytes and addresses are copied *) |
| 3335 | + if (e.mode # Item.mVar) or (e.obj = nil) or (e.obj^.cls # Sym.oConst) or (e.typ # e.obj^.typ) |
| 3336 | + or not Sym.same(e.typ, t) then |
| 3337 | + return Scan.markAt(e.pos, say1("expected a literal of {}", Sym.typeName(t))); |
| 3338 | + end; |
| 3339 | + st := Chunk.chunks[e.chunk].start; |
| 3340 | + COPY(constBytes[off..off + INT(t^.size)], Chunk.rodata[st..st + INT(t^.size)]); |
| 3341 | + fx := Chunk.chunks[e.chunk].firstFix; |
| 3342 | + for k := fx to fx + Chunk.chunks[e.chunk].numFix - 1 do |
| 3343 | + try constFix(off + Chunk.dataFixups[k].at, Chunk.dataFixups[k].chunk); |
| 3344 | + end; |
| 3335 | 3345 | else |
| 3336 | 3346 | try Item.coerce(e, t); |
| 3337 | 3347 | if (e.mode = Item.mProc) and not e.obj^.ext then |