Refactor block stack unwinding to enable finally execution.

This commit is contained in:
Windel Bouwman committed 2019-08-27 19:40:00 +02:00
1 parent 9168455b12
commit 86fc18ec6c
3 files changed
+174 -131

No files matched your search

+19 -1
View File
@@ -178,6 +178,22 @@ pub enum Instruction {
start: Label,
end: Label,
},
/// Setup a finally handler, which will be called whenever one of this events occurs:
/// - the block is popped
/// - the function returns
/// - an exception is returned
SetupFinally {
handler: Label,
},
/// Marker bytecode for the end of a finally sequence.
/// When this bytecode is executed, the eval loop does one of those things:
/// - Continue at a certain bytecode position
/// - Propagate the exception
/// - Return from a function
EndFinally,
SetupExcept {
handler: Label,
},
@@ -475,7 +491,9 @@ impl Instruction {
YieldValue => w!(YieldValue),
YieldFrom => w!(YieldFrom),
SetupLoop { start, end } => w!(SetupLoop, label_map[start], label_map[end]),
SetupExcept { handler } => w!(SetupExcept, handler),
SetupExcept { handler } => w!(SetupExcept, label_map[handler]),
SetupFinally { handler } => w!(SetupFinally, label_map[handler]),
EndFinally => w!(EndFinally),
SetupWith { end } => w!(SetupWith, end),
CleanupWith { end } => w!(CleanupWith, end),
PopBlock => w!(PopBlock),