This commit is contained in:
Araq
2015-10-15 09:31:43 +02:00
parent 7d6c9143d7
commit c97cbe7abd
3 changed files with 37 additions and 1 deletions

View File

@@ -511,7 +511,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
regs[ra].regAddr = addr(regs[rb])
of opcAddrNode:
decodeB(rkNodeAddr)
regs[ra].nodeAddr = addr(regs[rb].node)
if regs[rb].kind == rkNode:
regs[ra].nodeAddr = addr(regs[rb].node)
else:
stackTrace(c, tos, pc, errGenerated, "limited VM support for 'addr'")
of opcLdDeref:
# a = b[]
let ra = instr.regA

View File

@@ -1091,10 +1091,32 @@ proc requiresCopy(n: PNode): bool =
proc unneededIndirection(n: PNode): bool =
n.typ.skipTypes(abstractInst-{tyTypeDesc}).kind == tyRef
proc canElimAddr(n: PNode): PNode =
case n.sons[0].kind
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
var m = n.sons[0].sons[0]
if m.kind in {nkDerefExpr, nkHiddenDeref}:
# addr ( nkConv ( deref ( x ) ) ) --> nkConv(x)
result = copyNode(n.sons[0])
result.add m.sons[0]
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
var m = n.sons[0].sons[1]
if m.kind in {nkDerefExpr, nkHiddenDeref}:
# addr ( nkConv ( deref ( x ) ) ) --> nkConv(x)
result = copyNode(n.sons[0])
result.add m.sons[0]
else:
if n.sons[0].kind in {nkDerefExpr, nkHiddenDeref}:
# addr ( deref ( x )) --> x
result = n.sons[0].sons[0]
proc genAddrDeref(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode;
flags: TGenFlags) =
# a nop for certain types
let isAddr = opc in {opcAddrNode, opcAddrReg}
if isAddr and (let m = canElimAddr(n); m != nil):
gen(c, m, dest, flags)
return
let newflags = if isAddr: flags+{gfAddrOf} else: flags
# consider:
# proc foo(f: var ref int) =

11
tests/cpp/tasync_cpp.nim Normal file
View File

@@ -0,0 +1,11 @@
discard """
cmd: "nim cpp $file"
output: "hello"
"""
# bug #3299
import jester
import asyncdispatch, asyncnet
echo "hello"