added new invocation that does not create a call frame
authoradam <adam@megacz.com>
Mon, 27 Sep 2004 07:54:24 +0000 (07:54 +0000)
committeradam <adam@megacz.com>
Mon, 27 Sep 2004 07:54:24 +0000 (07:54 +0000)
darcs-hash:20040927075424-5007d-9644b8a4d76f908ff83b4fe097cec351aa5849d6.gz

src/org/ibex/js/Interpreter.java
src/org/ibex/js/JS.java

index 504bbd2..94ccab5 100644 (file)
@@ -22,11 +22,12 @@ class Interpreter implements ByteCodes, Tokens {
     Vec stack = new Vec();        ///< the object stack
     int pc = 0;                   ///< the program counter
 
-    Interpreter(JSFunction f, boolean pauseable, JSArray args) {
+    Interpreter(JSFunction f, boolean pauseable, JSArray args) { this(f, pauseable, args, true); }
+    Interpreter(JSFunction f, boolean pauseable, JSArray args, boolean wrap) {
         stack.push(new Interpreter.CallMarker(this));    // the "root function returned" marker -- f==null
         this.f = f;
         this.pausecount = pauseable ? 0 : -1;
-        this.scope = new JSScope(f.parentScope);
+        this.scope = wrap ? new JSScope(f.parentScope) : f.parentScope;
         stack.push(args);
     }
     
index 3a11127..7cd1fc7 100644 (file)
@@ -187,6 +187,11 @@ public class JS /*extends org.ibex.util.BalancedTree*/ implements Serializable {
         return ((JSFunction)j)._cloneWithNewParentScope(s);
     }
 
+    public static Object eval(JS j) throws JSExn {
+        Interpreter cx = new Interpreter((JSFunction)j, false, new JSArray(), false);
+        return cx.resume();
+    }
+
 
     // Trap support //////////////////////////////////////////////////////////////////////////////