Skip to content

Commit

Permalink
another great bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Oct 29, 2023
1 parent e17237c commit 0f194a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 16 additions & 2 deletions compiler/nir/ast2ir.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ proc freeTemp(c: var ProcCon; tmp: Value) =
if s != SymId(-1):
freeTemp(c.sm, s)

proc freeTemps(c: var ProcCon; tmps: openArray[Value]) =
for t in tmps: freeTemp(c, t)

proc typeToIr(m: ModuleCon; t: PType): TypeId =
typeToIr(m.types, m.nirm.types, t)

Expand Down Expand Up @@ -482,6 +485,7 @@ proc genCall(c: var ProcCon; n: PNode; d: var Value) =
rawCall c, info, opc, tb, args
else:
rawCall c, info, opc, tb, args
freeTemps c, args

proc genRaise(c: var ProcCon; n: PNode) =
let info = toLineInfo(c, n.info)
Expand Down Expand Up @@ -694,6 +698,16 @@ template valueIntoDest(c: var ProcCon; info: PackedLineInfo; d: var Value; typ:
copyTree c.code, d
body(c.code)

template constrIntoDest(c: var ProcCon; info: PackedLineInfo; d: var Value; typ: PType; body: untyped) =
var tmp = default(Value)
body(Tree tmp)
if isEmpty(d):
d = tmp
else:
buildTyped c.code, info, Asgn, typeToIr(c.m, typ):
copyTree c.code, d
copyTree c.code, tmp

proc genBinaryOp(c: var ProcCon; n: PNode; d: var Value; opc: Opcode) =
let info = toLineInfo(c, n.info)
let tmp = c.genx(n[1])
Expand Down Expand Up @@ -2060,7 +2074,7 @@ proc genObjOrTupleConstr(c: var ProcCon; n: PNode; d: var Value; t: PType) =
target.addImmediateVal info, 1 # "name" field is at position after the "parent". See system.nim
target.addStrVal c.lit.strings, info, t.skipTypes(abstractInst).sym.name.s

valueIntoDest c, info, d, t, body
constrIntoDest c, info, d, t, body

proc genRefObjConstr(c: var ProcCon; n: PNode; d: var Value) =
if isEmpty(d): d = getTemp(c, n)
Expand Down Expand Up @@ -2110,7 +2124,7 @@ proc genArrayConstr(c: var ProcCon; n: PNode, d: var Value) =
copyTree target, tmp
c.freeTemp(tmp)

valueIntoDest c, info, d, n.typ, body
constrIntoDest c, info, d, n.typ, body

proc genAsgn2(c: var ProcCon; a, b: PNode) =
assert a != nil
Expand Down
6 changes: 6 additions & 0 deletions compiler/nir/nirvm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ proc debug(bc: Bytecode; info: PackedLineInfo) =
let (litId, line, col) = bc.m.man.unpack(info)
echo bc.m.lit.strings[litId], ":", line, ":", col

proc debug(bc: Bytecode; t: Tree; n: NodePos) =
var buf = ""
toString(t, n, bc.m.lit.strings, bc.m.lit.numbers, bc.m.symnames, buf)
echo buf

template `[]`(t: seq[Instr]; n: CodePos): Instr = t[n.int]

proc traverseObject(b: var Bytecode; t, offsetKey: TypeId) =
Expand Down Expand Up @@ -421,6 +426,7 @@ proc preprocess(c: var Preprocessing; bc: var Bytecode; t: Tree; n: NodePos; fla
for ch in sonsFrom1(t, n):
preprocess(c, bc, t, ch, {WantAddr})
of ObjConstr:
#debug bc, t, n
var i = 0
let typ = t[n.firstSon].typeId
build bc, info, ObjConstrM:
Expand Down

0 comments on commit 0f194a4

Please sign in to comment.