Conditional return instructions
This commit is contained in:
@@ -3,8 +3,7 @@ package vm
|
||||
type opHandler func(*State, *Instruction)
|
||||
|
||||
var opHandlers = map[OpCodeType]opHandler{
|
||||
OpNoOp: (*State).handleNoOp,
|
||||
OpReturn: (*State).handleReturn,
|
||||
OpNoOp: (*State).handleNoOp,
|
||||
|
||||
OpMove: (*State).handleMove,
|
||||
|
||||
@@ -31,15 +30,15 @@ var opHandlers = map[OpCodeType]opHandler{
|
||||
OpCall: (*State).handleCall,
|
||||
OpCallIfTrue: (*State).handleCallIfTrue,
|
||||
OpCallIfFalse: (*State).handleCallIfFalse,
|
||||
|
||||
OpReturn: (*State).handleReturn,
|
||||
OpReturnIfTrue: (*State).handleReturnIfTrue,
|
||||
OpReturnIfFalse: (*State).handleReturnIfFalse,
|
||||
}
|
||||
|
||||
func (state *State) handleNoOp(instr *Instruction) {
|
||||
}
|
||||
|
||||
func (state *State) handleReturn(instr *Instruction) {
|
||||
state.ret()
|
||||
}
|
||||
|
||||
func (state *State) handleMove(instr *Instruction) {
|
||||
in := state.readUnsigned(&instr.Operand2)
|
||||
state.writeUnsigned(&instr.Operand1, in)
|
||||
@@ -162,3 +161,19 @@ func (state *State) handleCallIfFalse(instr *Instruction) {
|
||||
state.handleCall(instr)
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) handleReturn(instr *Instruction) {
|
||||
state.ret()
|
||||
}
|
||||
|
||||
func (state *State) handleReturnIfTrue(instr *Instruction) {
|
||||
if state.comparisonResult == true {
|
||||
state.handleReturn(instr)
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) handleReturnIfFalse(instr *Instruction) {
|
||||
if state.comparisonResult == false {
|
||||
state.handleReturn(instr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user