Skip to content

Commit 6a5709a

Browse files
committed
Simplify final state
1 parent 731493d commit 6a5709a

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

compiler/closureiters.nim

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,8 +1478,7 @@ proc transformClosureIterator*(g: ModuleGraph; idgen: IdGenerator; fn: PSym, n:
14781478

14791479
discard ctx.newState(n, false, nil)
14801480

1481-
let finalState = ctx.newStateLabel()
1482-
let gotoOut = newTree(nkGotoState, finalState)
1481+
let gotoOut = newTree(nkGotoState, g.newIntLit(n.info, -1))
14831482

14841483
var ns = false
14851484
n = ctx.lowerStmtListExprs(n, ns)
@@ -1491,15 +1490,10 @@ proc transformClosureIterator*(g: ModuleGraph; idgen: IdGenerator; fn: PSym, n:
14911490
# Splitting transformation
14921491
discard ctx.transformClosureIteratorBody(n, gotoOut)
14931492

1494-
let finalStateBody = newTree(nkStmtList)
14951493
if ctx.hasExceptions:
1496-
finalStateBody.add(ctx.newRestoreExternException())
14971494
ctx.nullifyCurExc.add(ctx.newNullifyCurExc(fn.info))
14981495
ctx.restoreExternExc.add(ctx.newRestoreExternException())
14991496

1500-
finalStateBody.add(newTree(nkGotoState, g.newIntLit(n.info, -1)))
1501-
discard ctx.newState(finalStateBody, true, finalState)
1502-
15031497
# Assign state label indexes
15041498
for i in 0 .. ctx.states.high:
15051499
ctx.states[i].label.intVal = i
@@ -1517,7 +1511,9 @@ proc transformClosureIterator*(g: ModuleGraph; idgen: IdGenerator; fn: PSym, n:
15171511
let body = ctx.transformStateAssignments(s.body)
15181512
caseDispatcher.add newTreeI(nkOfBranch, body.info, s.label, body)
15191513

1520-
caseDispatcher.add newTreeI(nkElse, n.info, newTreeI(nkReturnStmt, n.info, g.emptyNode))
1514+
caseDispatcher.add newTreeI(nkElse, n.info,
1515+
newTree(nkStmtList, ctx.restoreExternExc,
1516+
newTreeI(nkReturnStmt, n.info, g.emptyNode)))
15211517

15221518
result = wrapIntoStateLoop(ctx, caseDispatcher)
15231519
result = liftLocals(ctx, result)

0 commit comments

Comments
 (0)