First program generation
This commit is contained in:
@@ -13,6 +13,8 @@ type State struct {
|
||||
comparisonResult bool
|
||||
globalMemory *Memory
|
||||
stack []*stackFrame
|
||||
|
||||
instructionCount uint64
|
||||
}
|
||||
|
||||
func NewState(prog *Program) (*State, error) {
|
||||
@@ -70,6 +72,12 @@ func (state *State) processInstruction() {
|
||||
instr := fnc.Instructions[state.instructionIndex]
|
||||
state.instructionIndex += 1
|
||||
instr.opHandler(state, instr)
|
||||
state.instructionCount += 1
|
||||
|
||||
if state.program.InstructionLimit > 0 && state.instructionCount > state.program.InstructionLimit {
|
||||
state.err = fmt.Errorf("Instruction limit (%d) exceeded", state.program.InstructionLimit)
|
||||
state.running = false
|
||||
}
|
||||
|
||||
if state.functionIndex < 0 || state.functionIndex >= int64(len(state.program.Functions)) {
|
||||
state.ret()
|
||||
|
||||
Reference in New Issue
Block a user