2004/01/13 03:56:00
[org.ibex.core.git] / src / org / xwt / js / Interpreter.java
index ae8dc1f..c6c61b7 100644 (file)
@@ -163,7 +163,8 @@ class Interpreter implements ByteCodes, Tokens {
                     } else if (o instanceof CallMarker) {
                         if (scope instanceof Trap.TrapScope) { // handles return component of a read trap
                             Trap.TrapScope ts = (Trap.TrapScope)scope;
-                            if (retval != null) ts.cascadeHappened = true;
+                            if (retval != null && retval instanceof Boolean && ((Boolean)retval).booleanValue())
+                                ts.cascadeHappened = true;
                             if (!ts.cascadeHappened) {
                                 ts.cascadeHappened = true;
                                 Trap t = ts.t.next;
@@ -356,6 +357,28 @@ class Interpreter implements ByteCodes, Tokens {
             case THROW:
                 throw new JSExn(stack.pop());
 
+            case MAKE_GRAMMAR: {
+                final Grammar r = (Grammar)arg;
+                final JSScope final_scope = scope;
+                Grammar r2 = new Grammar() {
+                        public int match(String s, int start, Hash v, JSScope scope) throws JSExn {
+                            return r.match(s, start, v, final_scope);
+                        }
+                        public int matchAndWrite(String s, int start, Hash v, JSScope scope, String key) throws JSExn {
+                            return r.matchAndWrite(s, start, v, final_scope, key);
+                        }
+                        public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+                            Hash v = new Hash();
+                            r.matchAndWrite((String)a0, 0, v, final_scope, "foo");
+                            return v.get("foo");
+                        }
+                    };
+                Object obj = stack.pop();
+                if (obj != null && obj instanceof Grammar) r2 = new Grammar.Alternative((Grammar)obj, r2);
+                stack.push(r2);
+                break;
+            }
+
             case ASSIGN_SUB: case ASSIGN_ADD: {
                 Object val = stack.pop();
                 Object key = stack.pop();