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 ///////////////////////////////////////////////
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
sb.append("\n" + sourceName + ": " + firstLine + "\n");
for (int i=0; i < size; i++) {
sb.append(prefix);
- sb.append(i).append(" (").append(line[i]).append(") :");
+ sb.append(i).append(" (").append(line[i]).append("): ");
if (op[i] < 0) sb.append(bytecodeToString[-op[i]]);
else sb.append(codeToString[op[i]]);
sb.append(" ");
sb.append(" finally: ").append(jmps[1] < 0 ? "No finally block" : ""+(i+jmps[1]));
} else if(op[i] == NEWFUNCTION) {
sb.append(((JSFunction) arg[i]).dump(prefix + " "));
+ } else if(op[i] == NEWSCOPE) {
+ int n = ((JSNumber)arg[i]).toInt();
+ sb.append(" base: " + (n>>>16) + " size: " + (n&0xffff));
}
sb.append("\n");
}