edu.cornell.cs.sam.core
Class SamMemory

java.lang.Object
  extended by edu.cornell.cs.sam.core.SamMemory
All Implemented Interfaces:
Memory

public class SamMemory
extends java.lang.Object
implements Memory

Memory implementation: Integer Array - Alternating data/type fields, 32-bit wide - Even addresses contain type - Odd addresses contain data


Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.cornell.cs.sam.core.Memory
Memory.Data, Memory.Type
 
Field Summary
 
Fields inherited from interface edu.cornell.cs.sam.core.Memory
MEMORYLIMIT, STACKLIMIT, UNIT_SIZE
 
Constructor Summary
SamMemory(Sys sys)
           
 
Method Summary
 java.util.List<Memory.Data> getAllocation(HeapAllocator.Allocation alloc)
          Returns an array containing the data for the given allocation.
 HeapAllocator getHeapAllocator()
          Get the Heap Allocator object associated with this memory.
 Memory.Data getMem(int pos)
          Returns the data object at the requested memory position
 java.util.List<Memory.Data> getStack()
          Returns a list containing the current stack
 Sys getSystem()
          Return the Sys object associated with this memory.
 Memory.Type getType(int pos)
          Returns the type at the requested memory position
 int getValue(int pos)
          Returns the value at the requested memory position
 void init()
          Initializes memory to default state
 Memory.Data pop()
          Pops a data object off the stack
 char popCH()
          Pops a character off the stack
 float popFLOAT()
          Pops a floating pointer number off the stack
 int popINT()
          Pops an integer off the stack
 int popMA()
          Pops a memory address off the stack
 int popPA()
          Pops a program address off the stack
 int popValue()
          Pops a value off the stack
 void push(int value, Memory.Type type)
          Pushes a value/type pair on the stack
 void push(Memory.Data data)
          Pushes a data object on the stack
 void pushCH(char ch)
          Pushes a character on the stack
 void pushFLOAT(float fl)
          Pushes a floating pointer number on the stack
 void pushINT(int i)
          Pushes an integer on the stack
 void pushMA(int ma)
          Pushes a memory address on the stack
 void pushPA(int pa)
          Pushes a program address on the stack
 void setHeapAllocator(HeapAllocator heap)
          Set the HeapAllocator object associated with this memory.
 void setMem(int pos, int data, Memory.Type type)
          Stores the given value/type pair in memory
 void setMem(int pos, Memory.Data data)
          Stores the given data object in memory
 void setSystem(Sys sys)
          Set the Sys object associated with this memory.
 void setType(int pos, Memory.Type type)
          Sets this location to the given type
 void setValue(int pos, int data)
          Stores the given value in memory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SamMemory

public SamMemory(Sys sys)
Method Detail

getSystem

public Sys getSystem()
Description copied from interface: Memory
Return the Sys object associated with this memory.

Specified by:
getSystem in interface Memory
Returns:
The Sys object

setSystem

public void setSystem(Sys sys)
Description copied from interface: Memory
Set the Sys object associated with this memory.

Specified by:
setSystem in interface Memory
Parameters:
sys - The Sys object

getHeapAllocator

public HeapAllocator getHeapAllocator()
Description copied from interface: Memory
Get the Heap Allocator object associated with this memory.

Specified by:
getHeapAllocator in interface Memory
Returns:
The heap allocator

setHeapAllocator

public void setHeapAllocator(HeapAllocator heap)
Description copied from interface: Memory
Set the HeapAllocator object associated with this memory.

Specified by:
setHeapAllocator in interface Memory
Parameters:
heap - The allocator

init

public void init()
Description copied from interface: Memory
Initializes memory to default state

Specified by:
init in interface Memory

getMem

public Memory.Data getMem(int pos)
                   throws SystemException
Description copied from interface: Memory
Returns the data object at the requested memory position

Specified by:
getMem in interface Memory
Parameters:
pos - The memory address
Returns:
The data object stored at the specified position
Throws:
SystemException - if there is an error accessing memory

getValue

public int getValue(int pos)
             throws SystemException
Description copied from interface: Memory
Returns the value at the requested memory position

Specified by:
getValue in interface Memory
Parameters:
pos - The memory address
Returns:
The value stored at the specified position
Throws:
SystemException - if there is an error accessing memory

getType

public Memory.Type getType(int pos)
                    throws SystemException
Description copied from interface: Memory
Returns the type at the requested memory position

Specified by:
getType in interface Memory
Parameters:
pos - The memory address
Returns:
The type stored at the specified position
Throws:
SystemException - if there is an error accessing memory

setMem

public void setMem(int pos,
                   Memory.Data data)
            throws SystemException
Description copied from interface: Memory
Stores the given data object in memory

Specified by:
setMem in interface Memory
data - The data object to set
Throws:
SystemException - if there is an error accessing memory

setMem

public void setMem(int pos,
                   int data,
                   Memory.Type type)
            throws SystemException
Description copied from interface: Memory
Stores the given value/type pair in memory

Specified by:
setMem in interface Memory
data - The value to store
type - The type of this value
Throws:
SystemException - if there is an error accessing memory

setValue

public void setValue(int pos,
                     int data)
              throws SystemException
Description copied from interface: Memory
Stores the given value in memory

Specified by:
setValue in interface Memory
data - The value to store
Throws:
SystemException - if there is an error accessing memory

setType

public void setType(int pos,
                    Memory.Type type)
             throws SystemException
Description copied from interface: Memory
Sets this location to the given type

Specified by:
setType in interface Memory
type - The type to set
Throws:
SystemException - if there is an error accessing memory

getAllocation

public java.util.List<Memory.Data> getAllocation(HeapAllocator.Allocation alloc)
Description copied from interface: Memory
Returns an array containing the data for the given allocation.

Specified by:
getAllocation in interface Memory
Parameters:
alloc - The heap allocation
Returns:
The list of data for this allocation.

getStack

public java.util.List<Memory.Data> getStack()
Description copied from interface: Memory
Returns a list containing the current stack

Specified by:
getStack in interface Memory
Returns:
The list of data.

pop

public Memory.Data pop()
                throws SystemException
Description copied from interface: Memory
Pops a data object off the stack

Specified by:
pop in interface Memory
Returns:
The data object popped off the stack
Throws:
SystemException - if there is an error accessing the stack

popValue

public int popValue()
             throws SystemException
Description copied from interface: Memory
Pops a value off the stack

Specified by:
popValue in interface Memory
Returns:
The value popped off the stack
Throws:
SystemException - if there is an error accessing the stack

push

public void push(Memory.Data data)
          throws SystemException
Description copied from interface: Memory
Pushes a data object on the stack

Specified by:
push in interface Memory
Parameters:
data - The data object to push on the stack
Throws:
SystemException - if there is an error accessing the stack

push

public void push(int value,
                 Memory.Type type)
          throws SystemException
Description copied from interface: Memory
Pushes a value/type pair on the stack

Specified by:
push in interface Memory
Parameters:
value - The value to push on the stack
type - The type of this value
Throws:
SystemException - if there is an error accessing the stack

popFLOAT

public float popFLOAT()
               throws SystemException
Description copied from interface: Memory
Pops a floating pointer number off the stack

Specified by:
popFLOAT in interface Memory
Returns:
The floating pointer number popped off the stack
Throws:
SystemException - if there is an error accessing the stack

pushFLOAT

public void pushFLOAT(float fl)
               throws SystemException
Description copied from interface: Memory
Pushes a floating pointer number on the stack

Specified by:
pushFLOAT in interface Memory
Parameters:
fl - The floating point number to push
Throws:
SystemException - if there is an error accessing the stack

popINT

public int popINT()
           throws SystemException
Description copied from interface: Memory
Pops an integer off the stack

Specified by:
popINT in interface Memory
Returns:
The integer popped off the stack
Throws:
SystemException - if there is an error accessing the stack

pushINT

public void pushINT(int i)
             throws SystemException
Description copied from interface: Memory
Pushes an integer on the stack

Specified by:
pushINT in interface Memory
Parameters:
i - The integer to push
Throws:
SystemException - if there is an error accessing the stack

popCH

public char popCH()
           throws SystemException
Description copied from interface: Memory
Pops a character off the stack

Specified by:
popCH in interface Memory
Returns:
The character popped off the stack
Throws:
SystemException - if there is an error accessing the stack

pushCH

public void pushCH(char ch)
            throws SystemException
Description copied from interface: Memory
Pushes a character on the stack

Specified by:
pushCH in interface Memory
Parameters:
ch - The character to push
Throws:
SystemException - if there is an error accessing the stack

popPA

public int popPA()
          throws SystemException
Description copied from interface: Memory
Pops a program address off the stack

Specified by:
popPA in interface Memory
Returns:
The program address popped off the stack
Throws:
SystemException - if there is an error accessing the stack

pushPA

public void pushPA(int pa)
            throws SystemException
Description copied from interface: Memory
Pushes a program address on the stack

Specified by:
pushPA in interface Memory
Parameters:
pa - The program address to push
Throws:
SystemException - if there is an error accessing the stack

popMA

public int popMA()
          throws SystemException
Description copied from interface: Memory
Pops a memory address off the stack

Specified by:
popMA in interface Memory
Returns:
The memory address popped off the stack
Throws:
SystemException - if there is an error accessing the stack

pushMA

public void pushMA(int ma)
            throws SystemException
Description copied from interface: Memory
Pushes a memory address on the stack

Specified by:
pushMA in interface Memory
Parameters:
ma - The address to push
Throws:
SystemException - if there is an error accessing the stack