/** Resets the stack machine to the state it was in before it started running the stack program */ public void reset() { this.programCounter = 0; this.stack.clear(); this.numInstructions = 0; this.store = new StackValue<?>[STORE_SIZE]; this.inputIndex = 0; this.output = new ArrayList<StackValue<?>>(); for (int i = 0; i < STORE_SIZE; i++) { store[i] = new IntStackValue(0); for (StackMachineListener l : listeners) l.storeChanged(i); } for (StackMachineListener l : listeners) l.machineReset(); }
/** * Set a particular address in store * * @param address The address to set * @param value The value to set the address to * @throws InvalidAddressException */ public void setStore(int address, StackValue<?> value) throws InvalidAddressException { if (0 <= address && address < STORE_SIZE) { store[address] = value; for (StackMachineListener l : listeners) l.storeChanged(address); } else throw new InvalidAddressException(address, programCounter); }