Start exercising grow code, breaking the VM
This commit is contained in:
@@ -73,13 +73,25 @@ func (state *State) handleMultiply(instr *Instruction) {
|
||||
func (state *State) handleDivideUnsigned(instr *Instruction) {
|
||||
in1 := state.readUnsigned(instr.Operands[0])
|
||||
in2 := state.readUnsigned(instr.Operands[1])
|
||||
state.writeUnsigned(instr.Operands[0], in1/in2)
|
||||
|
||||
if in2 == 0 {
|
||||
// Divide by zero just returns zero
|
||||
state.writeUnsigned(instr.Operands[0], 0)
|
||||
} else {
|
||||
state.writeUnsigned(instr.Operands[0], in1/in2)
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) handleDivideSigned(instr *Instruction) {
|
||||
in1 := state.readSigned(instr.Operands[0])
|
||||
in2 := state.readSigned(instr.Operands[1])
|
||||
state.writeSigned(instr.Operands[0], in1/in2)
|
||||
|
||||
if in2 == 0 {
|
||||
// Divide by zero just returns zero
|
||||
state.writeSigned(instr.Operands[0], 0)
|
||||
} else {
|
||||
state.writeSigned(instr.Operands[0], in1/in2)
|
||||
}
|
||||
}
|
||||
|
||||
func (state *State) handleNot(instr *Instruction) {
|
||||
|
||||
@@ -71,11 +71,11 @@ func (state *State) processInstruction() {
|
||||
state.instructionIndex += 1
|
||||
instr.opHandler(state, instr)
|
||||
|
||||
if state.functionIndex >= int64(len(state.program.Functions)) {
|
||||
if state.functionIndex < 0 || state.functionIndex >= int64(len(state.program.Functions)) {
|
||||
state.ret()
|
||||
}
|
||||
|
||||
if state.instructionIndex >= int64(len(fnc.Instructions)) {
|
||||
if state.instructionIndex < 0 || state.instructionIndex >= int64(len(fnc.Instructions)) {
|
||||
state.ret()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user