From: crawshaw Date: Sat, 8 Jan 2005 10:00:34 +0000 (+0000) Subject: reintroduce JSArgs X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=31ab0680a77eccd2083e550ffb555883e76512ed;p=org.ibex.js.git reintroduce JSArgs darcs-hash:20050108100034-2eb37-69192a7b4961e35a851862e2b4482a24b80a00b5.gz --- diff --git a/src/org/ibex/js/Interpreter.java b/src/org/ibex/js/Interpreter.java index 693ad9c..3fedf8f 100644 --- a/src/org/ibex/js/Interpreter.java +++ b/src/org/ibex/js/Interpreter.java @@ -29,7 +29,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable { this.scope = f.parentScope; try { stack.push(new CallMarker(null)); // the "root function returned" marker -- f==null - stack.push(args); + stack.push(new JSArgs(args, f)); // FIXME: temprorary bug fix } catch(JSExn e) { throw new Error("should never happen"); } @@ -123,7 +123,12 @@ class Interpreter implements ByteCodes, Tokens, Pausable { case OLDSCOPE: scope = scope.parent; break; case GLOBALSCOPE: stack.push(scope.getGlobal()); break; case SCOPEGET: stack.push(scope.get((JS)arg)); break; - case SCOPEPUT: scope.put((JS)arg, (JS)stack.peek()); break; + case SCOPEPUT: { + // FIXME: HACK: share this around more and find the callee. + Object val = stack.peek(); + if (val != null && val instanceof JS[]) val = new JSArgs((JS[])val, null); + scope.put((JS)arg, (JS)val); break; + } case ASSERT: if (!JSU.toBoolean((JS)stack.pop())) throw je("ibex.assertion.failed"); break; case BITNOT: stack.push(JSU.N(~JSU.toLong((JS)stack.pop()))); break; case BANG: stack.push(JSU.B(!JSU.toBoolean((JS)stack.pop()))); break; @@ -621,6 +626,22 @@ class Interpreter implements ByteCodes, Tokens, Pausable { public FinallyData(JSExn exn) { this.exn = exn; this.op = -1; this.arg = null; } // Just throw this exn } + static class JSArgs extends JS.Immutable { + private final JS[] args; + private final JS callee; + + public JSArgs(JS[] args, JS callee) { this.args = args; this.callee = callee; } + + public JS get(JS key) throws JSExn { + if(JSU.isInt(key)) return args[JSU.toInt(key)]; + //#switch(JSU.toString(key)) + case "callee": return callee; + case "length": return JSU.N(args.length); + //#end + return super.get(key); + } + } + static class TrapArgs extends JS.Immutable { private Trap t; private JS val;