Conditional return instructions
This commit is contained in:
13
vm/opcode.go
13
vm/opcode.go
@@ -3,10 +3,8 @@ package vm
|
||||
type OpCodeType uint32
|
||||
|
||||
const (
|
||||
OpNoOp OpCodeType = 0x00000000
|
||||
OpNop = OpNoOp
|
||||
OpReturn = 0x00000002
|
||||
OpRet = OpReturn
|
||||
OpNoOp OpCodeType = 0x00000000
|
||||
OpNop = OpNoOp
|
||||
|
||||
OpMove = 0x00000100
|
||||
OpMov = OpMove
|
||||
@@ -53,4 +51,11 @@ const (
|
||||
OpCalT = OpCallIfTrue
|
||||
OpCallIfFalse = 0x00000502
|
||||
OpCalF = OpCallIfFalse
|
||||
|
||||
OpReturn = 0x00000600
|
||||
OpRet = OpReturn
|
||||
OpReturnIfTrue = 0x00000601
|
||||
OpRetT = OpReturnIfTrue
|
||||
OpReturnIfFalse = 0x00000602
|
||||
OpRetF = OpReturnIfFalse
|
||||
)
|
||||
|
||||
@@ -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