Skip to content

Commit

Permalink
Fix OpLoadEnv disassemble
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Jul 19, 2023
1 parent 3c23d10 commit d3fee6e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion vm/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (program *Program) Disassemble() string {
case OpLoadFunc:
argument("OpLoadFunc")

case OpLoadEnv:
code("OpLoadEnv")

case OpFetch:
code("OpFetch")

Expand Down Expand Up @@ -270,7 +273,7 @@ func (program *Program) Disassemble() string {
code("OpEnd")

default:
_, _ = fmt.Fprintf(w, "%v\t%#x\n", ip, op)
_, _ = fmt.Fprintf(w, "%v\t%#x (unknown)\n", ip, op)
}
}
_ = w.Flush()
Expand Down
2 changes: 1 addition & 1 deletion vm/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestProgram_Disassemble(t *testing.T) {
Arguments: []int{1},
}
d := program.Disassemble()
if strings.Contains(d, "\t0x") {
if strings.Contains(d, "(unknown)") {
t.Errorf("cannot disassemble all opcodes")
}
}
Expand Down
1 change: 1 addition & 0 deletions vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (vm *VM) Run(program *Program, env interface{}) (_ interface{}, err error)

case OpLoadEnv:
vm.push(env)

case OpMethod:
a := vm.pop()
vm.push(runtime.FetchMethod(a, program.Constants[arg].(*runtime.Method)))
Expand Down

0 comments on commit d3fee6e

Please sign in to comment.