X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FJS.java;h=6c9448dfa41a9230104d6e177fc378f696538fe8;hp=ea117c4349435d182e7f14da0e6331875c5bbb97;hb=6076f07a78d5e01a53304b0ae9df97273a0688fe;hpb=bf615a8d1871c2f8a9bf0044297ff253600862e3 diff --git a/src/org/xwt/js/JS.java b/src/org/xwt/js/JS.java index ea117c4..6c9448d 100644 --- a/src/org/xwt/js/JS.java +++ b/src/org/xwt/js/JS.java @@ -132,10 +132,26 @@ public abstract class JS { } /** Anything that is callable */ - public static abstract class Function extends Obj { - public String getSourceName() throws JS.Exn { return "unknown"; } - public int getLine() throws JS.Exn { return -1; } - public abstract Object _call(JS.Array args) throws JS.Exn, ByteCodeBlock.ControlTransferException; + public static class Function extends Obj { + ByteCodeBlock bytecodes; + int line; + String sourceName; + Scope parentScope; + public Function() { this(-1, "unknown", null, null); } + public Function(int line, String sourceName, ByteCodeBlock bytecodes, Scope parentScope) { + this.sourceName = sourceName; + this.line = line; + this.bytecodes = bytecodes; + this.parentScope = parentScope; + } + public String getSourceName() throws JS.Exn { return sourceName; } + public int getLine() throws JS.Exn { return line; } + public Object _call(JS.Array args) throws JS.Exn, ByteCodeBlock.ControlTransferException { + if (bytecodes == null) throw new Error("tried to call() a JS.Function with bytecodes == null"); + Vec stack = new Vec(); + stack.push(args); + return bytecodes.eval(new FunctionScope(sourceName, parentScope), stack); + } public final Object call(JS.Array args) throws JS.Exn { Function saved = (Function)currentFunction.get(Thread.currentThread()); currentFunction.put(Thread.currentThread(), this); @@ -159,7 +175,7 @@ public abstract class JS { public String getSourceName() throws JS.Exn { return ((ByteCodeBlock)e.elementAt(0)).getSourceName(); } public Object _call(JS.Array args) throws JS.Exn, ByteCodeBlock.ControlTransferException { Scope rootScope = (Scope)args.elementAt(0); - for(int i=0; i