This commit is contained in:
Araq 2014-08-14 00:02:24 +02:00
commit f3d530e482
7 changed files with 54 additions and 15 deletions

View file

@ -24,6 +24,15 @@ proc registerGcRoot(p: BProc, v: PSym) =
linefmt(p.module.initProc, cpsStmts,
"#nimRegisterGlobalMarker($1);$n", prc)
proc isAssignedImmediately(n: PNode): bool {.inline.} =
if n.kind == nkEmpty: return false
if isInvalidReturnType(n.typ):
# var v = f()
# is transformed into: var v; f(addr v)
# where 'f' **does not** initialize the result!
return false
result = true
proc genVarTuple(p: BProc, n: PNode) =
var tup, field: TLoc
if n.kind != nkVarTuple: internalError(n.info, "genVarTuple")
@ -40,7 +49,7 @@ proc genVarTuple(p: BProc, n: PNode) =
registerGcRoot(p, v)
else:
assignLocalVar(p, v)
initLocalVar(p, v, immediateAsgn=true)
initLocalVar(p, v, immediateAsgn=isAssignedImmediately(n[L-1]))
initLoc(field, locExpr, t.sons[i], tup.s)
if t.kind == tyTuple:
field.r = ropef("$1.Field$2", [rdLoc(tup), toRope(i)])
@ -146,11 +155,12 @@ proc genBreakState(p: BProc, n: PNode) =
# lineF(p, cpsStmts, "if (($1) < 0) break;$n", [rdLoc(a)])
proc genVarPrototypeAux(m: BModule, sym: PSym)
proc genSingleVar(p: BProc, a: PNode) =
var v = a.sons[0].sym
if sfCompileTime in v.flags: return
var targetProc = p
var immediateAsgn = a.sons[2].kind != nkEmpty
var immediateAsgn = isAssignedImmediately(a.sons[2])
if sfGlobal in v.flags:
if sfPure in v.flags:
# v.owner.kind != skModule:
@ -177,7 +187,7 @@ proc genSingleVar(p: BProc, a: PNode) =
loadInto(targetProc, a.sons[0], a.sons[2], v.loc)
proc genClosureVar(p: BProc, a: PNode) =
var immediateAsgn = a.sons[2].kind != nkEmpty
var immediateAsgn = isAssignedImmediately(a.sons[2])
if immediateAsgn:
var v: TLoc
initLocExpr(p, a.sons[0], v)