Disassembler skeleton

This commit is contained in:
Ian Gulliver
2021-11-19 20:38:56 -10:00
parent 5ccf6832c8
commit 579ddab2de
7 changed files with 111 additions and 6 deletions

View File

@@ -42,7 +42,7 @@ func (state *State) stackFrame() *stackFrame {
return state.stack[len(state.stack)-1]
}
func (state *State) function() []*Instruction {
func (state *State) function() *Function {
return state.program.Functions[state.functionIndex]
}
@@ -53,7 +53,7 @@ func (state *State) setError(err error) {
func (state *State) setHandlers() {
for _, fnc := range state.program.Functions {
for _, instr := range fnc {
for _, instr := range fnc.Instructions {
handler, found := opHandlers[instr.OpCode]
if !found {
state.setError(fmt.Errorf("Invalid OpCode: 0x%08x", instr.OpCode))
@@ -67,7 +67,7 @@ func (state *State) setHandlers() {
func (state *State) processInstruction() {
fnc := state.function()
instr := fnc[state.instructionIndex]
instr := fnc.Instructions[state.instructionIndex]
state.instructionIndex += 1
instr.opHandler(state, instr)
@@ -75,7 +75,7 @@ func (state *State) processInstruction() {
state.ret()
}
if state.instructionIndex >= int64(len(fnc)) {
if state.instructionIndex >= int64(len(fnc.Instructions)) {
state.ret()
}
}