- 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);
+ }