/**
 * Class that defines the memory space for the SILLY interpreter. 
 *   @author Dave Reed 
 *   @version 2/8/15
 */
public class MemorySpace {
    private ActivationRecord stack;
    private Heap heap;
    
    /**
     * Constructs an empty memory space.
     */
    public MemorySpace() {
    	this.stack = new ActivationRecord();
    	this.heap = new Heap();
    }
    
    /**
     * Stores a variable/value in the stack segment.
     *   @param token the variable name
     *   @param val the value to be stored under that name
     */
    public void storeVariable(Token token, DataValue val) {
    	this.stack.store(token,  val);
    }

    /**
     * Retrieves the value for a variable (from the stack segment).
     * @param token the variable name
     * @return the value stored under that name
     */
	public DataValue lookupVariable(Token token) {
    	return this.stack.lookup(token);
	}

    /**
     * Stores a string constant in the heap segment.
     *   @param str the string constant
     *   @return the heap index where that string constant is stored
     */
    public int storeString(String str) {
    	return this.heap.store(str);
    }

    /**
     * Retrieves a string constant from the heap segment.
     * @param n the heap index of the string constant
     * @return the string constant at index n
     */
    public String lookupString(int n) {
    	return this.heap.lookup(n);
	}
}
