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