8000 Implement remaining JUMP_* opcodes · go-python/gpython@36faf9f · GitHub
[go: up one dir, main page]

Skip to content

Commit 36faf9f

Browse files
committed
Implement remaining JUMP_* opcodes
1 parent 64c73d3 commit 36faf9f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

vm/eval.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func (vm *Vm) SET_SECOND(v py.Object) { vm.stack[len(vm.stack)-2] = v }
2020
func (vm *Vm) SET_THIRD(v py.Object) { vm.stack[len(vm.stack)-3] = v }
2121
func (vm *Vm) SET_FOURTH(v py.Object) { vm.stack[len(vm.stack)-4] = v }
2222
func (vm *Vm) SET_VALUE(n int, v py.Object) { vm.stack[len(vm.stack)-(n)] = (v) }
23+
func (vm *Vm) DROP() { vm.stack = vm.stack[:len(vm.stack)-1] }
2324
func (vm *Vm) DROPN(n int) { vm.stack = vm.stack[:len(vm.stack)-n] }
2425

2526
// Pop from top of vm stack
@@ -580,18 +581,26 @@ func do_POP_JUMP_IF_FALSE(vm *Vm, target int32) {
580581
// If TOS is true, sets the bytecode counter to target and leaves TOS
581582
// on the stack. Otherwise (TOS is false), TOS is popped.
582583
func do_JUMP_IF_TRUE_OR_POP(vm *Vm, target int32) {
583-
vm.NotImplemented("JUMP_IF_TRUE_OR_POP", target)
584+
if py.MakeBool(vm.TOP()).(py.Bool) {
585+
vm.frame.Lasti = target
586+
} else {
587+
vm.DROP()
588+
}
584589
}
585590

586591
// If TOS is false, sets the bytecode counter to target and leaves TOS
587592
// on the stack. Otherwise (TOS is true), TOS is popped.
588593
func do_JUMP_IF_FALSE_OR_POP(vm *Vm, target int32) {
589-
vm.NotImplemented("JUMP_IF_FALSE_OR_POP", target)
594+
if !py.MakeBool(vm.TOP()).(py.Bool) {
595+
vm.frame.Lasti = target
596+
} else {
597+
vm.DROP()
598+
}
590599
}
591600

592601
// Set bytecode counter to target.
593602
func do_JUMP_ABSOLUTE(vm *Vm, target int32) {
594-
vm.NotImplemented("JUMP_ABSOLUTE", target)
603+
vm.frame.Lasti = target
595604
}
596605

597606
// TOS is an iterator. Call its next( ) method. If this yields a new

0 commit comments

Comments
 (0)
0