diff --git a/src/vm.go b/src/vm.go index e458244..8c367ba 100644 --- a/src/vm.go +++ b/src/vm.go @@ -45,6 +45,8 @@ func coBC(label string, stack *Stack, bc []byte) { } func run_vm(vm *VMstate) (err error) { + defer handle(vm) + for { vm.b = vm.bc[vm.o] @@ -84,3 +86,13 @@ func run_vm(vm *VMstate) (err error) { } } } + +func handle(vm *VMstate) { + if err := recover(); err != nil { + warn("(run_vm) something went terribly wrong: ") + print("\n") + vm.debug() + print("\n") + panic(err) + } +} diff --git a/src/vm_state.go b/src/vm_state.go index ec7d227..d138102 100644 --- a/src/vm_state.go +++ b/src/vm_state.go @@ -35,7 +35,7 @@ func (vm *VMstate) debug() { print("\n") print(" all bytes: [") - fmt.Printf("0x%0.2X", vm.b) + fmt.Printf("0x%0.2X", vm.bc) print("]\n") print(" meta stack: ")