You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
flag = 5
while True:
try:
break
finally: flag = 10
From this section we know that "When a return, break or continue statement is executed in the try suite of a try…finally statement, the finally clause is also executed ‘on the way out.’".
So, our implementation of try by means of goto must catch both exceptions and the break. It then must execute finally and rethrow everything that was not processed by the except clause (including break). The break then will be caught again up the stack by the implementation of while.
Like so:
flag.write 5
goto
[stackUp]
TRUE.while
write.
resultOfTry
goto
[stackUp]
stackUp.forward breakConstant // this is the break
if.
is-exception resultOfTry
// here goes the implementation of except clause, which is BTW empty in our example
0
flag.write 10 // here goes the implementation of finally, so it is executed for exceptions and for the break
if.
is-break resultOfTry
stackUp.forward resultOfTry // redirect the break further up the stack
0
We may also imagine a return that happens somewhere deep in the hierarchy of whiles and trys. This is a kind of semi-manual stack unwinding, IMHO.
The text was updated successfully, but these errors were encountered:
@yegor256 It is not a question. It is an answer to you suggestion: you asked to describe how break and exception are implemented with the help of goto in py2eo as an issue.
Consider this python code
We can translate it this way
Now consider this:
From this section we know that "When a return, break or continue statement is executed in the try suite of a try…finally statement, the finally clause is also executed ‘on the way out.’".
So, our implementation of
try
by means ofgoto
must catch both exceptions and thebreak
. It then must executefinally
and rethrow everything that was not processed by theexcept
clause (includingbreak
). Thebreak
then will be caught again up the stack by the implementation ofwhile
.Like so:
We may also imagine a
return
that happens somewhere deep in the hierarchy of whiles and trys. This is a kind of semi-manual stack unwinding, IMHO.The text was updated successfully, but these errors were encountered: