/** * This allows access to the memory * the SaM Processor uses */ public interface Memory { /** * Memory limit. */ final static int MEMORYLIMIT = 10000; /** * Stack limit. */ final static int STACKLIMIT = 1000; /** * Stack Type: Memory Address * */ final static byte MA = 0; /** * Stack Type: Integer */ final static byte INT = 1; /** * Stack Type: Floating Point Number */ final static byte FLOAT = 2; /** * Stack Type: Program Address */ final static byte PA = 3; /** * Stack Type: Character */ final static byte CH = 4; /** * Reset memory to default state (0). **/ void reset(); /** * Returns the requested memory position * @param pos the memory address * @return the value of the memory at the specified position */ int getMem(int pos) throws SystemException; /** * Returns the type of the value at the requested memory position. * @param pos the memory address * @return the type of the memory address specified by pos */ byte getType(int pos) throws SystemException; /** * Sets the value at the given memory address (INT type) * @param pos the memory address to change * @param value the value */ void setMem(int pos, int value) throws SystemException; /** * Sets the value at the given memory address, with the given type * @param pos The address of the memory to set * @param type The type of the new value * @param value The value */ void setMem(int pos, byte type, int value) throws SystemException; /** * Returns an array containing the current stack. */ int[] getStack(); /** * Returns an array containing the current heap. */ int[] getHeap(); /** * Returns an array containg the requested memory range. */ int[] getMemoryRange(int low, int high); /** * Returns an array containing the types of the values on the stack. */ byte[] getStackTypes(); /** * Returns an array containing the types of the values in the heap. */ byte[] getHeapTypes(); /** * Returns an array containing the types of the values in the requested * memory range. */ byte[] getTypesRange(int low, int high); /** * Pushes a value onto the stack (INT type) * @param value the value to push onto the stack * @throws SystemException if htere is an error accessing the stack */ void push(int value) throws SystemException; /** * Pushes a value onto the stack with the given type. * @param type the type of the value to push * @param value the value to push * @throws SystemException if there is an error while adding to the stack */ void push(byte type, int value) throws SystemException; /** * Pops a value off the stack * @throws SystemException if there is an error accessing the stack * @return The value popped off the stack */ int pop() throws SystemException; /** * Allocates the specified amount of memory on the heap + 1, * sets HP to the address of the allocated memory, and pushes * that on the stack. * @param size the amount of memory to allocate * @throws SystemException if there is an error allocating memory */ void malloc(int size) throws SystemException; }