Add conditional call instructions
This commit is contained in:
@@ -5,8 +5,6 @@ type OpCodeType uint32
|
||||
const (
|
||||
OpNoOp OpCodeType = 0x00000000
|
||||
OpNop = OpNoOp
|
||||
OpCall = 0x00000001
|
||||
OpCal = OpCall
|
||||
OpReturn = 0x00000002
|
||||
OpRet = OpReturn
|
||||
|
||||
@@ -48,4 +46,11 @@ const (
|
||||
OpJmpT = OpJumpIfTrue
|
||||
OpJumpIfFalse = 0x00000402
|
||||
OpJmpF = OpJumpIfFalse
|
||||
|
||||
OpCall = 0x00000500
|
||||
OpCal = OpCall
|
||||
OpCallIfTrue = 0x00000501
|
||||
OpCalT = OpCallIfTrue
|
||||
OpCallIfFalse = 0x00000502
|
||||
OpCalF = OpCallIfFalse
|
||||
)
|
||||
|
||||
@@ -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