parent
5fa8a61a23
commit
690f21043d
3 changed files with 24 additions and 10 deletions
|
|
@ -139,7 +139,7 @@ proc isLastRead(s: PSym; c: var Con; pc, comesFrom: int): int =
|
||||||
of def:
|
of def:
|
||||||
if c.g[pc].sym == s:
|
if c.g[pc].sym == s:
|
||||||
# the path lead to a redefinition of 's' --> abandon it.
|
# the path lead to a redefinition of 's' --> abandon it.
|
||||||
return pc
|
return high(int)
|
||||||
inc pc
|
inc pc
|
||||||
of use:
|
of use:
|
||||||
if c.g[pc].sym == s:
|
if c.g[pc].sym == s:
|
||||||
|
|
@ -150,14 +150,16 @@ proc isLastRead(s: PSym; c: var Con; pc, comesFrom: int): int =
|
||||||
pc = pc + c.g[pc].dest
|
pc = pc + c.g[pc].dest
|
||||||
of fork:
|
of fork:
|
||||||
# every branch must lead to the last read of the location:
|
# every branch must lead to the last read of the location:
|
||||||
let variantA = isLastRead(s, c, pc+1, pc)
|
var variantA = isLastRead(s, c, pc+1, pc)
|
||||||
if variantA < 0: return -1
|
if variantA < 0: return -1
|
||||||
let variantB = isLastRead(s, c, pc + c.g[pc].dest, pc)
|
let variantB = isLastRead(s, c, pc + c.g[pc].dest, pc)
|
||||||
if variantB < 0: return -1
|
if variantB < 0: return -1
|
||||||
pc = variantA+1
|
elif variantA == high(int):
|
||||||
|
variantA = variantB
|
||||||
|
pc = variantA
|
||||||
of InstrKind.join:
|
of InstrKind.join:
|
||||||
let dest = pc + c.g[pc].dest
|
let dest = pc + c.g[pc].dest
|
||||||
if dest == comesFrom: return pc
|
if dest == comesFrom: return pc + 1
|
||||||
inc pc
|
inc pc
|
||||||
return pc
|
return pc
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ proc codeListing(c: ControlFlowGraph, result: var string, start=0; last = -1) =
|
||||||
while i <= last:
|
while i <= last:
|
||||||
if i in jumpTargets: result.add("L" & $i & ":\n")
|
if i in jumpTargets: result.add("L" & $i & ":\n")
|
||||||
result.add "\t"
|
result.add "\t"
|
||||||
result.add $c[i].kind
|
result.add ($i & " " & $c[i].kind)
|
||||||
result.add "\t"
|
result.add "\t"
|
||||||
case c[i].kind
|
case c[i].kind
|
||||||
of def, use:
|
of def, use:
|
||||||
|
|
@ -540,13 +540,17 @@ proc genTry(c: var Con; n: PNode) =
|
||||||
c.gen(fin.sons[0])
|
c.gen(fin.sons[0])
|
||||||
doAssert(c.forks.len == oldLen)
|
doAssert(c.forks.len == oldLen)
|
||||||
|
|
||||||
|
template genNoReturn(c: var Con; n: PNode) =
|
||||||
|
# leave the graph
|
||||||
|
c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len)
|
||||||
|
|
||||||
proc genRaise(c: var Con; n: PNode) =
|
proc genRaise(c: var Con; n: PNode) =
|
||||||
genJoins(c, n)
|
genJoins(c, n)
|
||||||
gen(c, n.sons[0])
|
gen(c, n.sons[0])
|
||||||
if c.inTryStmt > 0:
|
if c.inTryStmt > 0:
|
||||||
c.tryStmtFixups.add c.gotoI(n)
|
c.tryStmtFixups.add c.gotoI(n)
|
||||||
else:
|
else:
|
||||||
c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len)
|
genNoReturn(c, n)
|
||||||
|
|
||||||
proc genImplicitReturn(c: var Con) =
|
proc genImplicitReturn(c: var Con) =
|
||||||
if c.owner.kind in {skProc, skFunc, skMethod, skIterator, skConverter} and resultPos < c.owner.ast.len:
|
if c.owner.kind in {skProc, skFunc, skMethod, skIterator, skConverter} and resultPos < c.owner.ast.len:
|
||||||
|
|
@ -558,7 +562,7 @@ proc genReturn(c: var Con; n: PNode) =
|
||||||
gen(c, n.sons[0])
|
gen(c, n.sons[0])
|
||||||
else:
|
else:
|
||||||
genImplicitReturn(c)
|
genImplicitReturn(c)
|
||||||
c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len)
|
genNoReturn(c, n)
|
||||||
|
|
||||||
const
|
const
|
||||||
InterestingSyms = {skVar, skResult, skLet, skParam}
|
InterestingSyms = {skVar, skResult, skLet, skParam}
|
||||||
|
|
@ -612,9 +616,6 @@ proc genMagic(c: var Con; n: PNode; m: TMagic) =
|
||||||
of mNew, mNewFinalize:
|
of mNew, mNewFinalize:
|
||||||
genDef(c, n[1])
|
genDef(c, n[1])
|
||||||
for i in 2..<n.len: gen(c, n[i])
|
for i in 2..<n.len: gen(c, n[i])
|
||||||
of mExit:
|
|
||||||
genCall(c, n)
|
|
||||||
c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len)
|
|
||||||
else:
|
else:
|
||||||
genCall(c, n)
|
genCall(c, n)
|
||||||
|
|
||||||
|
|
@ -639,6 +640,8 @@ proc gen(c: var Con; n: PNode) =
|
||||||
genMagic(c, n, s.magic)
|
genMagic(c, n, s.magic)
|
||||||
else:
|
else:
|
||||||
genCall(c, n)
|
genCall(c, n)
|
||||||
|
if sfNoReturn in n.sons[0].sym.flags:
|
||||||
|
genNoReturn(c, n)
|
||||||
else:
|
else:
|
||||||
genCall(c, n)
|
genCall(c, n)
|
||||||
of nkCharLit..nkNilLit: discard
|
of nkCharLit..nkNilLit: discard
|
||||||
|
|
|
||||||
|
|
@ -166,3 +166,12 @@ seq4 =
|
||||||
var ii = 1
|
var ii = 1
|
||||||
let arr2 = [newMySeq(2, 5.0), if i > 1: newMySeq(3, 1.0) else: newMySeq(0, 0.0)]
|
let arr2 = [newMySeq(2, 5.0), if i > 1: newMySeq(3, 1.0) else: newMySeq(0, 0.0)]
|
||||||
var seqOfSeq2 = @[newMySeq(2, 5.0), newMySeq(3, 1.0)]
|
var seqOfSeq2 = @[newMySeq(2, 5.0), newMySeq(3, 1.0)]
|
||||||
|
|
||||||
|
|
||||||
|
## issue #10462
|
||||||
|
proc myfuncLoop(x: int): MySeqNonCopyable =
|
||||||
|
for i in 0..<x:
|
||||||
|
var cc = newMySeq(i, 5.0)
|
||||||
|
result = cc
|
||||||
|
|
||||||
|
discard myfuncLoop(3)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue