X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fibex%2Fjs%2FJSFunction.java;fp=src%2Forg%2Fibex%2Fjs%2FJSFunction.java;h=d50e5661ac61812bd4405982c1ac39fc7c220a3e;hb=19d66e161db458135518efd3539048f44e1e5622;hp=9dfc5dbc82272a5df1f270f493b06e8c4f66b51f;hpb=44ba228826e0d6a6c4ad3ed0072b90e05622ee21;p=org.ibex.js.git
diff --git a/src/org/ibex/js/JSFunction.java b/src/org/ibex/js/JSFunction.java
index 9dfc5db..d50e566 100644
--- a/src/org/ibex/js/JSFunction.java
+++ b/src/org/ibex/js/JSFunction.java
@@ -5,7 +5,8 @@ import java.io.*;
import org.ibex.util.*;
/** A JavaScript function, compiled into bytecode */
-class JSFunction extends JS implements ByteCodes, Tokens, Task {
+// FIXME: This shouldn't be public, needed for public add/delTrap (which is needed for the Template.java hack)
+public class JSFunction extends JS implements ByteCodes, Tokens, Task {
// Fields and Accessors ///////////////////////////////////////////////
@@ -21,32 +22,17 @@ class JSFunction extends JS implements ByteCodes, Tokens, Task {
int size = 0; ///< the number of instruction/argument pairs
JSScope parentScope; ///< the default scope to use as a parent scope when executing this
- Vec formalArgs = new Vec();
+
// Public //////////////////////////////////////////////////////////////////////////////
// FEATURE: make sure that this can only be called from the Scheduler...
/** if you enqueue a function, it gets invoked in its own pauseable context */
public void perform() throws JSExn {
- Interpreter i = new Interpreter(this, true, new JSArray());
+ Interpreter i = new Interpreter(this, true, new Interpreter.JSArgs(this));
i.resume();
}
- /** parse and compile a function */
- public static JSFunction _fromReader(String sourceName, int firstLine, Reader sourceCode) throws IOException {
- JSFunction ret = new JSFunction(sourceName, firstLine, null);
- if (sourceCode == null) return ret;
- Parser p = new Parser(sourceCode, sourceName, firstLine);
- while(true) {
- int s = ret.size;
- p.parseStatement(ret, null);
- if (s == ret.size) break;
- }
- ret.add(-1, LITERAL, null);
- ret.add(-1, RETURN);
- return ret;
- }
-
public JSFunction _cloneWithNewParentScope(JSScope s) {
JSFunction ret = new JSFunction(sourceName, firstLine, s);
// Reuse the same op, arg, line, and size variables for the new "instance" of the function
@@ -55,19 +41,13 @@ class JSFunction extends JS implements ByteCodes, Tokens, Task {
ret.arg = this.arg;
ret.line = this.line;
ret.size = this.size;
- ret.formalArgs = this.formalArgs;
ret.numFormalArgs = this.numFormalArgs;
return ret;
}
/** Note: code gets run in an unpauseable context. */
- public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
- JSArray args = new JSArray();
- if (nargs > 0) args.addElement(a0);
- if (nargs > 1) args.addElement(a1);
- if (nargs > 2) args.addElement(a2);
- for(int i=3; i>>16) + " size: " + (n&0xffff));
}
sb.append("\n");
}