Add conditional call instructions
This commit is contained in:
@@ -4,7 +4,6 @@ type opHandler func(*State, *Instruction)
|
||||
|
||||
var opHandlers = map[OpCodeType]opHandler{
|
||||
OpNoOp: (*State).handleNoOp,
|
||||
OpCall: (*State).handleCall,
|
||||
OpReturn: (*State).handleReturn,
|
||||
|
||||
OpMove: (*State).handleMove,
|
||||
@@ -28,16 +27,15 @@ var opHandlers = map[OpCodeType]opHandler{
|
||||
OpJump: (*State).handleJump,
|
||||
OpJumpIfTrue: (*State).handleJumpIfTrue,
|
||||
OpJumpIfFalse: (*State).handleJumpIfFalse,
|
||||
|
||||
OpCall: (*State).handleCall,
|
||||
OpCallIfTrue: (*State).handleCallIfTrue,
|
||||
OpCallIfFalse: (*State).handleCallIfFalse,
|
||||
}
|
||||
|
||||
func (state *State) handleNoOp(instr *Instruction) {
|
||||
}
|
||||
|
||||
func (state *State) handleCall(instr *Instruction) {
|
||||
in := state.readSigned(&instr.Operand1)
|
||||
state.call(in)
|
||||
}
|
||||
|
||||
func (state *State) handleReturn(instr *Instruction) {
|
||||
state.ret()
|
||||
}
|
||||
@@ -147,3 +145,20 @@ func (state *State) handleJumpIfFalse(instr *Instruction) {
|
||||
state.handleJump(instr)
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) handleCall(instr *Instruction) {
|
||||
in := state.readSigned(&instr.Operand1)
|
||||
state.call(in)
|
||||
}
|
||||
|
||||
func (state *State) handleCallIfTrue(instr *Instruction) {
|
||||
if state.comparisonResult == true {
|
||||
state.handleCall(instr)
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) handleCallIfFalse(instr *Instruction) {
|
||||
if state.comparisonResult == false {
|
||||
state.handleCall(instr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user