updated Makefile.common
[org.ibex.core.git] / src / org / ibex / js / JSFunction.java
index 61b5268..d50e566 100644 (file)
@@ -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 ///////////////////////////////////////////////
@@ -32,21 +33,6 @@ class JSFunction extends JS implements ByteCodes, Tokens, Task {
         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
@@ -98,8 +84,7 @@ class JSFunction extends JS implements ByteCodes, Tokens, Task {
 
     // Debugging //////////////////////////////////////////////////////////////////////
 
-    // FIXME: Put this back in
-    public String xtoString() { return "JSFunction [" + sourceName + ":" + firstLine + "]"; }
+    String extendedToString() { return "[" + sourceName + ":" + firstLine + "]"; }
 
     String dump() { return dump(""); }
     private  String dump(String prefix) {
@@ -107,7 +92,7 @@ class JSFunction extends JS implements ByteCodes, Tokens, Task {
         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(" ");
@@ -120,6 +105,9 @@ class JSFunction extends JS implements ByteCodes, Tokens, Task {
                 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");
         }