+ private final int base;
+ private final JS[] vars;
+ final JSScope parent;
+
+ public static class Top extends JSScope {
+ private final JS global;
+ public Top(JS global) { super(null,0,0); this.global = global; }
+ JS get(int i) throws JSExn { throw new JSExn("scope index out of range"); }
+ void put(int i, JS o) throws JSExn { throw new JSExn("scope index out of range"); }
+ JS getGlobal() { return global; }
+ };
+
+ // NOTE: We can't just set base to parent.base + parent.vars.length
+ // sometimes we only access part of a parent's scope
+ public JSScope(JSScope parent, int base, int size) {
+ this.parent = parent;
+ this.base = base;
+ this.vars = new JS[size];
+ }
+
+ final JS get(JS i) throws JSExn {
+ if(i==null) throw new NullPointerException();
+ try {
+ return get(JS.toInt(i));
+ } catch(ArrayIndexOutOfBoundsException e) {
+ throw new JSExn("scope index out of range");
+ }
+ }
+ final void put(JS i, JS o) throws JSExn {
+ if(i==null) throw new NullPointerException();
+ try {
+ put(JS.toInt(i),o);
+ } catch(ArrayIndexOutOfBoundsException e) {
+ throw new JSExn("scope index out of range");
+ }
+ }
+ JS get(int i) throws JSExn { return i < base ? parent.get(i) : vars[i-base]; }
+ void put(int i, JS o) throws JSExn { if(i < base) parent.put(i,o); else vars[i-base] = o; }
+
+ JS getGlobal() { return parent.getGlobal(); }
+
+ /*private JSScope parentScope;