Skip to content

Commit

Permalink
When an error occurs in the VM, display debug
Browse files Browse the repository at this point in the history
  • Loading branch information
acook committed Apr 17, 2021
1 parent 85fe816 commit 947ac5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/vm_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
Expand Down

0 comments on commit 947ac5f

Please sign in to comment.