2003/10/31 10:57:24
[org.ibex.core.git] / src / org / xwt / js / CompiledFunctionImpl.java
index df1b621..2c69e1d 100644 (file)
@@ -10,7 +10,7 @@ class CompiledFunctionImpl extends JS.Obj implements ByteCodes, Tokens {
     // Fields and Accessors ///////////////////////////////////////////////
 
     /** the number of formal arguments */
-    int numFormalArgs = 0;
+    int numFormalArgs = 20;
 
     /** the source code file that this block was drawn from */
      String sourceName;
@@ -45,6 +45,7 @@ class CompiledFunctionImpl extends JS.Obj implements ByteCodes, Tokens {
         ret.arg = this.arg;
         ret.line = this.line;
         ret.size = this.size;
+        ret.numFormalArgs = this.numFormalArgs;
         return ret;
     }
 
@@ -96,10 +97,11 @@ class CompiledFunctionImpl extends JS.Obj implements ByteCodes, Tokens {
     // Invoking the Bytecode ///////////////////////////////////////////////////////
 
     /** returns false if the thread has been paused */
-    static void eval(final JS.Thread cx) throws JS.Exn {
-        OUTER: for(; cx.currentCompiledFunction == null || cx.pc<((CompiledFunctionImpl)cx.currentCompiledFunction).size; cx.pc++) {
+    static Object eval(final JS.Thread cx) throws JS.Exn {
+        OUTER: for(;; cx.pc++) {
         try {
-            if (cx.paused || cx.currentCompiledFunction == null) return;
+            if (cx.paused) return null;
+            cx.bind();
             if (cx.tailCallFunction != null) {
                 cx.stack.pop();  // discard actual return value
                 cx.pc -= 2;
@@ -111,6 +113,8 @@ class CompiledFunctionImpl extends JS.Obj implements ByteCodes, Tokens {
                 cx.scope = new FunctionScope("unknown", cx.currentCompiledFunction.parentScope);
                 cx.pc = 0;
             }
+            if (cx.currentCompiledFunction == null) return cx.stack.pop();
+            if (cx.pc >= ((CompiledFunctionImpl)cx.currentCompiledFunction).size) return cx.stack.pop();
             String label = null;
             int curOP = cx.currentCompiledFunction.op[cx.pc];
             Object curArg = cx.currentCompiledFunction.arg[cx.pc];
@@ -482,8 +486,6 @@ class CompiledFunctionImpl extends JS.Obj implements ByteCodes, Tokens {
             throw e;
         } // end try/catch
         } // end for
-        // this should never happen, we will ALWAYS have a RETURN at the end of the func
-        throw new Error("Just fell out of CompiledFunction::eval() loop.");
     }
 
     // Debugging //////////////////////////////////////////////////////////////////////