X-Git-Url: http://git.megacz.com/?p=org.ibex.js.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FInterpreter.java;fp=src%2Forg%2Fibex%2Fjs%2FInterpreter.java;h=77da0aba07e0ba00112163b334e898cdc11ad0f7;hp=e20e6307d0d8107375b1a1ffba03e4ff2fce5791;hb=f3ad8b6cba43f3c5364dc2cd9f1d050c1f48f167;hpb=f63da7aeac2f942be41aefde91002d14117a8573 diff --git a/src/org/ibex/js/Interpreter.java b/src/org/ibex/js/Interpreter.java index e20e630..77da0ab 100644 --- a/src/org/ibex/js/Interpreter.java +++ b/src/org/ibex/js/Interpreter.java @@ -248,10 +248,10 @@ class Interpreter implements ByteCodes, Tokens, Pausable { TrapMarker tm = (TrapMarker) o; JS key = tm.t.key(); JS target = tm.t.target(); - if(tm.t.isWriteTrap() != write) throw new JSExn("tried to do a " + (write?"write":"read") + " cascade in a " + (write?"read":"write") + " trap"); + if(tm.t.isWriteTrap() != write) + throw new JSExn("tried to do a "+(write?"write":"read") + " cascade in a " + (write?"read":"write") + " trap"); JS.Trap t = write ? tm.t.nextWrite() : tm.t.nextRead(); - // FIXME: Doesn't handle multiple levels of clone's (probably can just make this a while loop) - if(t == null && target instanceof JS.Clone) { + while (t == null && target instanceof JS.Clone) { target = ((JS.Clone)target).clonee; t = target.getTrap(key); if(t != null) t = write ? t.write() : t.read(); @@ -344,10 +344,9 @@ class Interpreter implements ByteCodes, Tokens, Pausable { } case CALL: case CALLMETHOD: { - // FIXME: can a lot of simple cases in Parser be - // reduced so creating a new JS[] is not necessary? JS[] jsargs; if (arg instanceof JSNumber.I) { + // FIXME: we should be able to recycle JS[]'s here jsargs = new JS[((JSNumber.I)arg).toInt()]; for (int i=0; i < jsargs.length; i++) jsargs[i] = (JS)stack.pop(); } else jsargs = (JS[])arg; @@ -390,35 +389,12 @@ class Interpreter implements ByteCodes, Tokens, Pausable { case THROW: throw new JSExn((JS)stack.pop(), this); - /* FIXME GRAMMAR - case MAKE_GRAMMAR: { - final Grammar r = (Grammar)arg; - final JSScope final_scope = scope; - Grammar r2 = new Grammar() { - public int match(String s, int start, Map v, JSScope scope) throws JSExn { - return r.match(s, start, v, final_scope); - } - public int matchAndWrite(String s, int start, Map v, JSScope scope, String key) throws JSExn { - return r.matchAndWrite(s, start, v, final_scope, key); - } - public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { - Map v = new Map(); - r.matchAndWrite((String)a0, 0, v, final_scope, "foo"); - return v.get("foo"); - } - }; - Object obj = stack.pop(); - if (obj != null && obj instanceof Grammar) r2 = new Grammar.Alternative((Grammar)obj, r2); - stack.push(r2); - break; - } - */ case ADD_TRAP: case DEL_TRAP: { JS val = (JS)stack.pop(); JS key = (JS)stack.pop(); JS js = (JS)stack.peek(); // A trap addition/removal - if(!(val instanceof JSFunction)) throw new JSExn("tried to add/remove a non-function trap"); // FIXME + if(!(val instanceof JSFunction)) throw new JSExn("tried to add/remove a non-function trap"); if(op == ADD_TRAP) js.addTrap(key, val); else js.delTrap(key, val); break; @@ -558,7 +534,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable { void setupTrap(JS.Trap t, JS val, CallMarker cm) throws JSExn { stack.push(cm); stack.push(new TrapArgs(t, val)); - f = (JSFunction)t.function(); // FIXME + f = (JSFunction)t.function(); scope = f.parentScope; pc = 0; }