Skip to content

Commit acc6057

Browse files
committed
Implement BREAK and CONTINUE opcodes
1 parent c8a27c6 commit acc6057

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

vm/eval.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,24 @@ func do_PRINT_EXPR(vm *Vm, arg int32) {
315315

316316
// Terminates a loop due to a break statement.
317317
func do_BREAK_LOOP(vm *Vm, arg int32) {
318-
vm.NotImplemented("BREAK_LOOP", arg)
318+
vm.frame.Lasti = vm.frame.Block.Handler
319+
vm.frame.PopBlock()
319320
}
320321

321322
// Continues a loop due to a continue statement. target is the address
322323
// to jump to (which should be a FOR_ITER instruction).
323324
func do_CONTINUE_LOOP(vm *Vm, target int32) {
324-
vm.NotImplemented("CONTINUE_LOOP", target)
325+
switch vm.frame.Block.Type {
326+
case SETUP_LOOP:
327+
case SETUP_WITH:
328+
vm.NotImplemented("CONTINUE_LOOP WITH", target)
329+
case SETUP_EXCEPT:
330+
vm.NotImplemented("CONTINUE_LOOP EXCEPT", target)
331+
case SETUP_FINALLY:
332+
vm.NotImplemented("CONTINUE_LOOP FINALLY", target)
333+
default:
334+
}
335+
vm.frame.Lasti = vm.frame.Block.Handler
325336
}
326337

327338
// Implements assignment with a starred target: Unpacks an iterable in

0 commit comments

Comments
 (0)