This commit is contained in:
Yuriy Glukhov 2018-05-04 16:39:59 +03:00
commit ac86b8ce61

View file

@ -123,14 +123,10 @@
# STATE2: # Finally
# yield 2
# if :unrollFinally: # This node is created by `newEndFinallyNode`
# when nearestFinally == 0: # Pseudocode. The `when` is not emitted in reality
# if :curExc.isNil:
# return :tmpResult
# else:
# raise
# else:
# :state = nearestFinally
# break :stateLoop
# state = -1 # Goto next state. In this case we just exit
# break :stateLoop
@ -427,15 +423,10 @@ proc lowerStmtListExpr(ctx: var Ctx, n: PNode): PNode =
proc newEndFinallyNode(ctx: var Ctx): PNode =
# Generate the following code:
# if :unrollFinally:
# when nearestFinally == 0: # Pseudocode. The `when` is not emitted in reality
# if :curExc.isNil:
# return :tmpResult
# else:
# raise
# else:
# goto nearestFinally
# :state = nearestFinally
# break :stateLoop
result = newNode(nkIfStmt)
@ -443,10 +434,7 @@ proc newEndFinallyNode(ctx: var Ctx): PNode =
elifBranch.add(ctx.newUnrollFinallyAccess())
result.add(elifBranch)
var ifBody: PNode
if ctx.nearestFinally == 0 or true:
ifBody = newNode(nkIfStmt)
let ifBody = newNode(nkIfStmt)
let branch = newNode(nkElifBranch)
let cmp = newNode(nkCall)
@ -459,14 +447,11 @@ proc newEndFinallyNode(ctx: var Ctx): PNode =
cmp.typ = getSysType(tyBool)
branch.add(cmp)
var retStmt = newNode(nkReturnStmt)
if true:
var a = newNode(nkAsgn)
addSon(a, newSymNode(getClosureIterResult(ctx.fn)))
addSon(a, ctx.newTmpResultAccess())
retStmt.add(a)
else:
retStmt.add(emptyNode)
let retStmt = newNode(nkReturnStmt)
let asgn = newNode(nkAsgn)
addSon(asgn, newSymNode(getClosureIterResult(ctx.fn)))
addSon(asgn, ctx.newTmpResultAccess())
retStmt.add(asgn)
branch.add(retStmt)
let elseBranch = newNode(nkElse)
@ -478,9 +463,6 @@ proc newEndFinallyNode(ctx: var Ctx): PNode =
ifBody.add(branch)
ifBody.add(elseBranch)
else:
ifBody = newNode(nkGotoState)
ifBody.add(newIntLit(ctx.nearestFinally))
elifBranch.add(ifBody)