fixes recently introduced regression
This commit is contained in:
parent
e5fd84c559
commit
5432b2b83a
2 changed files with 55 additions and 15 deletions
|
|
@ -200,6 +200,18 @@ proc newLabel(c: PTransf, n: PNode): PSym =
|
||||||
result = newSym(skLabel, nil, getCurrOwner(c), n.info)
|
result = newSym(skLabel, nil, getCurrOwner(c), n.info)
|
||||||
result.name = getIdent(genPrefix & $result.id)
|
result.name = getIdent(genPrefix & $result.id)
|
||||||
|
|
||||||
|
proc freshLabels(c: PTransf, n: PNode; symMap: var TIdTable) =
|
||||||
|
if n.kind in {nkBlockStmt, nkBlockExpr}:
|
||||||
|
if n.sons[0].kind == nkSym:
|
||||||
|
let x = newLabel(c, n[0])
|
||||||
|
idTablePut(symMap, n[0].sym, x)
|
||||||
|
n.sons[0].sym = x
|
||||||
|
if n.kind == nkSym and n.sym.kind == skLabel:
|
||||||
|
let x = PSym(idTableGet(symMap, n.sym))
|
||||||
|
if x != nil: n.sym = x
|
||||||
|
else:
|
||||||
|
for i in 0 .. <safeLen(n): freshLabels(c, n.sons[i], symMap)
|
||||||
|
|
||||||
proc transformBlock(c: PTransf, n: PNode): PTransNode =
|
proc transformBlock(c: PTransf, n: PNode): PTransNode =
|
||||||
var labl: PSym
|
var labl: PSym
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty:
|
||||||
|
|
@ -231,21 +243,31 @@ proc transformLoopBody(c: PTransf, n: PNode): PTransNode =
|
||||||
result = transform(c, n)
|
result = transform(c, n)
|
||||||
|
|
||||||
proc transformWhile(c: PTransf; n: PNode): PTransNode =
|
proc transformWhile(c: PTransf; n: PNode): PTransNode =
|
||||||
let labl = newLabel(c, n)
|
if c.inlining > 0:
|
||||||
c.breakSyms.add(labl)
|
result = transformSons(c, n)
|
||||||
result = newTransNode(nkBlockStmt, n.info, 2)
|
else:
|
||||||
result[0] = newSymNode(labl).PTransNode
|
let labl = newLabel(c, n)
|
||||||
|
c.breakSyms.add(labl)
|
||||||
|
result = newTransNode(nkBlockStmt, n.info, 2)
|
||||||
|
result[0] = newSymNode(labl).PTransNode
|
||||||
|
|
||||||
var body = newTransNode(n)
|
var body = newTransNode(n)
|
||||||
for i in 0..n.len-2:
|
for i in 0..n.len-2:
|
||||||
body[i] = transform(c, n.sons[i])
|
body[i] = transform(c, n.sons[i])
|
||||||
body[<n.len] = transformLoopBody(c, n.sons[<n.len])
|
body[<n.len] = transformLoopBody(c, n.sons[<n.len])
|
||||||
result[1] = body
|
result[1] = body
|
||||||
discard c.breakSyms.pop
|
discard c.breakSyms.pop
|
||||||
|
|
||||||
proc transformBreak(c: PTransf, n: PNode): PTransNode =
|
proc transformBreak(c: PTransf, n: PNode): PTransNode =
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty or c.inlining > 0:
|
||||||
result = n.PTransNode
|
result = n.PTransNode
|
||||||
|
when false:
|
||||||
|
let lablCopy = idNodeTableGet(c.transCon.mapping, n.sons[0].sym)
|
||||||
|
if lablCopy.isNil:
|
||||||
|
result = n.PTransNode
|
||||||
|
else:
|
||||||
|
result = newTransNode(n.kind, n.info, 1)
|
||||||
|
result[0] = lablCopy.PTransNode
|
||||||
else:
|
else:
|
||||||
let labl = c.breakSyms[c.breakSyms.high]
|
let labl = c.breakSyms[c.breakSyms.high]
|
||||||
result = transformSons(c, n)
|
result = transformSons(c, n)
|
||||||
|
|
@ -489,8 +511,13 @@ proc transformFor(c: PTransf, n: PNode): PTransNode =
|
||||||
assert(skipTypes(formal.typ, abstractInst).kind == tyVar)
|
assert(skipTypes(formal.typ, abstractInst).kind == tyVar)
|
||||||
idNodeTablePut(newC.mapping, formal, arg)
|
idNodeTablePut(newC.mapping, formal, arg)
|
||||||
# XXX BUG still not correct if the arg has a side effect!
|
# XXX BUG still not correct if the arg has a side effect!
|
||||||
var body = iter.getBody
|
var body = iter.getBody.copyTree
|
||||||
pushInfoContext(n.info)
|
pushInfoContext(n.info)
|
||||||
|
# XXX optimize this somehow. But the check "c.inlining" is not correct:
|
||||||
|
var symMap: TIdTable
|
||||||
|
initIdTable symMap
|
||||||
|
freshLabels(c, body, symMap)
|
||||||
|
|
||||||
inc(c.inlining)
|
inc(c.inlining)
|
||||||
add(stmtList, transform(c, body))
|
add(stmtList, transform(c, body))
|
||||||
#findWrongOwners(c, stmtList.pnode)
|
#findWrongOwners(c, stmtList.pnode)
|
||||||
|
|
@ -755,6 +782,8 @@ proc transformBody*(module: PSym, n: PNode, prc: PSym): PNode =
|
||||||
# result = lambdalifting.liftIterator(prc, result)
|
# result = lambdalifting.liftIterator(prc, result)
|
||||||
incl(result.flags, nfTransf)
|
incl(result.flags, nfTransf)
|
||||||
when useEffectSystem: trackProc(prc, result)
|
when useEffectSystem: trackProc(prc, result)
|
||||||
|
if prc.name.s == "testbody":
|
||||||
|
echo renderTree(result)
|
||||||
|
|
||||||
proc transformStmt*(module: PSym, n: PNode): PNode =
|
proc transformStmt*(module: PSym, n: PNode): PNode =
|
||||||
if nfTransf in n.flags:
|
if nfTransf in n.flags:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''10'''
|
output: '''10
|
||||||
|
true true
|
||||||
|
true false
|
||||||
|
false true
|
||||||
|
false false'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
@ -31,3 +35,10 @@ iterator permutations: int =
|
||||||
for p in permutations():
|
for p in permutations():
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# regression:
|
||||||
|
proc main =
|
||||||
|
for x in [true, false]:
|
||||||
|
for y in [true, false]:
|
||||||
|
echo x, " ", y
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue