import java.util.HashMap;

/**
 * Class that defines the memory space for the SILLY interpreter.
 *   @author Dave Reed
 *   @version 1/24/22
 */
public class MemorySpace {
    private HashMap<Token, DataValue> globalScope;

    /**
     * Constructs an empty memory space.
     */
    public MemorySpace() {
        this.globalScope = new HashMap<Token, DataValue>();
    }

    /**
     * Declares a variable (without storing an actual value).
     *   @param variable the variable to be declared
     */
    public void declare(Token variable) {
        this.globalScope.put(variable, null);
    }
    
    /** 
     * Determines if a variable is already declared.
     * @param variable the variable to be found
     * @return true if it is declared and/or assigned
     */
    public boolean isDeclared(Token variable) {
    	return this.globalScope.containsKey(variable);
    }

    /**
     * Determines the value associated with a variable in memory.
     *   @param variable the variable to look up
     *   @return the value associated with that variable
     */      
    public DataValue lookup(Token variable) {
        return this.globalScope.get(variable);
    }
    
    /**
     * Stores a variable/value in the stack segment.
     *   @param variable the variable name
     *   @param val the value to be stored under that name
     */
    public void store(Token variable, DataValue val)  {
        this.globalScope.put(variable, val);
    }
}
