// Path: src/stone/StoneException.java
// public class StoneException extends RuntimeException {
//     public StoneException(String m) { super(m); }
//     public StoneException(String m, ASTree t) {
//         super(m + " " + t.location());
//     }
// }
// 
// Path: src/chap11/EnvOptimizer.java
// @Reviser public static interface EnvEx2 extends Environment {
//     Symbols symbols();
//     void put(int nest, int index, Object value);
//     Object get(int nest, int index);
//     void putNew(String name, Object value);
//     Environment where(String name);
// }
// 
// Path: src/chap6/Environment.java
// public interface Environment {
//     void put(String name, Object value);
//     Object get(String name);
// }


import stone.StoneException;
import chap11.EnvOptimizer.EnvEx2;
import chap6.Environment;
package chap11;

public class ArrayEnv implements Environment {
    protected Object[] values;
    protected Environment outer;
    public ArrayEnv(int size, Environment out) {
        values = new Object[size];
        outer = out;
    }
    public Symbols symbols() { throw new StoneException("no symbols"); }
    public Object get(int nest, int index) {
        if (nest == 0)
            return values[index];
        else if (outer == null)
            return null;
        else
            return ((EnvEx2)outer).get(nest - 1, index);
    }
    public void put(int nest, int index, Object value) {
        if (nest == 0)
            values[index] = value;
        else if (outer == null)
            throw new StoneException("no outer environment");
        else
            ((EnvEx2)outer).put(nest - 1, index, value);
    }
// Path: src/stone/StoneException.java
// public class StoneException extends RuntimeException {
//     public StoneException(String m) { super(m); }
//     public StoneException(String m, ASTree t) {
//         super(m + " " + t.location());
//     }
// }
// 
// Path: src/chap11/EnvOptimizer.java
// @Reviser public static interface EnvEx2 extends Environment {
//     Symbols symbols();
//     void put(int nest, int index, Object value);
//     Object get(int nest, int index);
//     void putNew(String name, Object value);
//     Environment where(String name);
// }
// 
// Path: src/chap6/Environment.java
// public interface Environment {
//     void put(String name, Object value);
//     Object get(String name);
// }


// Path: src/chap11/ArrayEnv.java
import stone.StoneException;
import chap11.EnvOptimizer.EnvEx2;
import chap6.Environment;

package chap11;

public class ArrayEnv implements Environment {
    protected Object[] values;
    protected Environment outer;
    public ArrayEnv(int size, Environment out) {
        values = new Object[size];
        outer = out;
    }
    public Symbols symbols() { throw new StoneException("no symbols"); }
    public Object get(int nest, int index) {
        if (nest == 0)
            return values[index];
        else if (outer == null)
            return null;
        else
            return ((EnvEx2)outer).get(nest - 1, index);
    }
    public void put(int nest, int index, Object value) {
        if (nest == 0)
            values[index] = value;
        else if (outer == null)
            throw new StoneException("no outer environment");
        else
            ((EnvEx2)outer).put(nest - 1, index, value);
    }
    public Object get(String name) { error(name); return null; }