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:
|
|
||||||
# raise
|
|
||||||
# else:
|
# else:
|
||||||
# :state = nearestFinally
|
# raise
|
||||||
# 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,44 +434,35 @@ 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)
|
||||||
|
let branch = newNode(nkElifBranch)
|
||||||
|
|
||||||
if ctx.nearestFinally == 0 or true:
|
let cmp = newNode(nkCall)
|
||||||
ifBody = newNode(nkIfStmt)
|
cmp.add(getSysMagic("==", mEqRef).newSymNode)
|
||||||
let branch = newNode(nkElifBranch)
|
let curExc = ctx.newCurExcAccess()
|
||||||
|
let nilnode = newNode(nkNilLit)
|
||||||
|
nilnode.typ = curExc.typ
|
||||||
|
cmp.add(curExc)
|
||||||
|
cmp.add(nilnode)
|
||||||
|
cmp.typ = getSysType(tyBool)
|
||||||
|
branch.add(cmp)
|
||||||
|
|
||||||
let cmp = newNode(nkCall)
|
let retStmt = newNode(nkReturnStmt)
|
||||||
cmp.add(getSysMagic("==", mEqRef).newSymNode)
|
let asgn = newNode(nkAsgn)
|
||||||
let curExc = ctx.newCurExcAccess()
|
addSon(asgn, newSymNode(getClosureIterResult(ctx.fn)))
|
||||||
let nilnode = newNode(nkNilLit)
|
addSon(asgn, ctx.newTmpResultAccess())
|
||||||
nilnode.typ = curExc.typ
|
retStmt.add(asgn)
|
||||||
cmp.add(curExc)
|
branch.add(retStmt)
|
||||||
cmp.add(nilnode)
|
|
||||||
cmp.typ = getSysType(tyBool)
|
|
||||||
branch.add(cmp)
|
|
||||||
|
|
||||||
var retStmt = newNode(nkReturnStmt)
|
let elseBranch = newNode(nkElse)
|
||||||
if true:
|
let raiseStmt = newNode(nkRaiseStmt)
|
||||||
var a = newNode(nkAsgn)
|
|
||||||
addSon(a, newSymNode(getClosureIterResult(ctx.fn)))
|
|
||||||
addSon(a, ctx.newTmpResultAccess())
|
|
||||||
retStmt.add(a)
|
|
||||||
else:
|
|
||||||
retStmt.add(emptyNode)
|
|
||||||
branch.add(retStmt)
|
|
||||||
|
|
||||||
let elseBranch = newNode(nkElse)
|
# The C++ backend requires `getCurrentException` here.
|
||||||
let raiseStmt = newNode(nkRaiseStmt)
|
raiseStmt.add(callCodegenProc("getCurrentException", emptyNode))
|
||||||
|
elseBranch.add(raiseStmt)
|
||||||
|
|
||||||
# The C++ backend requires `getCurrentException` here.
|
ifBody.add(branch)
|
||||||
raiseStmt.add(callCodegenProc("getCurrentException", emptyNode))
|
ifBody.add(elseBranch)
|
||||||
elseBranch.add(raiseStmt)
|
|
||||||
|
|
||||||
ifBody.add(branch)
|
|
||||||
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