diff options
-rw-r--r-- | compiler/vm.nim | 8 | ||||
-rw-r--r-- | compiler/vmgen.nim | 12 | ||||
-rw-r--r-- | tests/discard/tneedsdiscard.nim | 2 | ||||
-rw-r--r-- | tests/exprs/tstmtexp.nim | 4 |
4 files changed, 16 insertions, 10 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index 6277b2dc6..108979739 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -109,14 +109,18 @@ template decodeBx(k: expr) {.immediate, dirty.} = template move(a, b: expr) {.immediate, dirty.} = system.shallowCopy(a, b) # XXX fix minor 'shallowCopy' overloading bug in compiler -template createStrKeepNode(x) = +proc createStrKeepNode(x: var TRegister) = if x.node.isNil: x.node = newNode(nkStrLit) elif x.node.kind == nkNilLit: system.reset(x.node[]) x.node.kind = nkStrLit else: - assert x.node.kind in {nkStrLit..nkTripleStrLit} + # XXX this is hacky; tests/txmlgen triggers it: + x.node = newNode(nkStrLit) + #if x.node.kind notin {nkStrLit..nkTripleStrLit}: + # debug x.node + #assert x.node.kind in {nkStrLit..nkTripleStrLit} template createStr(x) = x.node = newNode(nkStrLit) diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index b594c00a9..a9029442e 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -924,7 +924,7 @@ proc genAddrDeref(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode; flags: TGenFlags) = # a nop for certain types let isAddr = opc in {opcAddrNode, opcAddrReg} - let flags = if isAddr: flags+{gfAddrOf} else: flags + let newflags = if isAddr: flags+{gfAddrOf} else: flags # consider: # proc foo(f: var ref int) = # f = new(int) @@ -935,12 +935,14 @@ proc genAddrDeref(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode; # The type of 'f' is 'var ref int' and of 'x' is 'ref int'. Hence for # nkAddr we must not use 'unneededIndirection', but for deref we use it. if not isAddr and unneededIndirection(n.sons[0]): - gen(c, n.sons[0], dest, flags) + gen(c, n.sons[0], dest, newflags) else: - let tmp = c.genx(n.sons[0], flags) + let tmp = c.genx(n.sons[0], newflags) if dest < 0: dest = c.getTemp(n.typ) if not isAddr: gABC(c, n, opc, dest, tmp) + if gfAddrOf notin flags and fitsRegister(n.typ): + c.gABC(n, opcNodeToReg, dest, dest) elif c.prc.slots[tmp].kind >= slotTempUnknown: gABC(c, n, opcAddrReg, dest, tmp) else: @@ -1541,8 +1543,8 @@ proc genProc(c: PCtx; s: PSym): int = c.optimizeJumps(result) s.offset = c.prc.maxSlots #if s.name.s == "importImpl_forward" or s.name.s == "importImpl": - # c.echoCode(result) - # echo renderTree(body) + #c.echoCode(result) + #echo renderTree(body) c.prc = oldPrc else: c.prc.maxSlots = s.offset diff --git a/tests/discard/tneedsdiscard.nim b/tests/discard/tneedsdiscard.nim index 24f5b2eee..2a7856b4a 100644 --- a/tests/discard/tneedsdiscard.nim +++ b/tests/discard/tneedsdiscard.nim @@ -1,6 +1,6 @@ discard """ line: 10 - errormsg: "value returned by statement has to be discarded" + errormsg: "value of type 'bool' has to be discarded" """ proc p = diff --git a/tests/exprs/tstmtexp.nim b/tests/exprs/tstmtexp.nim index 7cbf2eb3d..fe60dd3ba 100644 --- a/tests/exprs/tstmtexp.nim +++ b/tests/exprs/tstmtexp.nim @@ -1,9 +1,9 @@ discard """ file: "tstmtexp.nim" line: 8 - errormsg: "value returned by statement has to be discarded" + errormsg: "value of type 'int literal(5)' has to be discarded" """ # Test 3 -1+4 #ERROR_MSG value returned by statement has to be discarded +1+4 |