checkpoint harmony
authoradam <adam@megacz.com>
Wed, 11 Jan 2006 07:31:06 +0000 (02:31 -0500)
committeradam <adam@megacz.com>
Wed, 11 Jan 2006 07:31:06 +0000 (02:31 -0500)
darcs-hash:20060111073106-5007d-8ba844c992ac61df6b273d12e5d8ab190c4dd879.gz

src/edu/berkeley/sbp/GSS.java
src/edu/berkeley/sbp/Parser.java

index 4f8b4a9..6316aad 100644 (file)
@@ -125,7 +125,7 @@ class GSS {
             p.holder.merge(pending);
             if (p.parents().contains(parent)) return true;
             p.parents().add(parent, true);
-            if (p!=parent && !fromEmptyReduction && reducing) p.queueReductions(parent);
+            if (p!=parent && !fromEmptyReduction && reducing) p.performReductions(parent);
             return true;
         }
         private boolean newNode3(Node parent, Forest pending, State state, boolean fromEmptyReduction) {
@@ -142,8 +142,8 @@ class GSS {
 
             Node n = new Node(parent, pending, state);  // ALLOC
             if (reducing) {
-                n.queueEmptyReductions();
-                if (!fromEmptyReduction) n.queueReductions(parent);
+                n.performEmptyReductions();
+                if (!fromEmptyReduction) n.performReductions(parent);
             }
             return true;
         }
@@ -183,13 +183,13 @@ class GSS {
                 int num = hash.size();
                 for(int i=0; i<num; i++) {
                     Node n = reducing_list[i];
-                    n.queueEmptyReductions();
+                    n.performEmptyReductions();
                     // INVARIANT: we never "see" a node until its parent-set is complete, modulo merges
                 }
                 for(int i=0; i<num; i++) {
                     Node n = reducing_list[i];
                     reducing_list[i] = null;
-                    n.queueReductions();
+                    n.performReductions();
                 }
             } catch (Reset r) {
                 reset();
@@ -266,28 +266,33 @@ class GSS {
             public  Forest pending() { return Phase.this.closed ? holder().resolve() : holder; }
             public  FastSet<Node> parents() { return this; }
 
-            public void queueReductions() {
+            public void performReductions() {
                 if (allqueued) return;
                 allqueued = true;
                 state.invokeReductions(token, this, this, null);
             }
 
-            public void queueReductions(Node n2) {
-                if (!allqueued) { queueReductions(); return; }
-                state.invokeReductions(token, this, this, n2);
+            public void performReductions(Node n2) {
+                if (!allqueued) performReductions();
+                else            state.invokeReductions(token, this, this, n2);
             }
 
             public final void invoke(Reduction r, Node n, Node n2) {
-                if (n==null) {
-                    if (r.position.pos==0) r.reduce(this);
-                } else if (r.position.pos==0) return;
-                else if (n2==null) r.reduce(n);
-                else          r.reduce(n, n2);
+                if (n==null || n2==null || r.position.pos==0) {
+                    if (r.position.pos==0) {
+                        if (n==null) n = this;
+                        else return;
+                    }
+                    if (n==null) return;
+                    Forest[] holder = new Forest[r.position.pos];
+                    if (r.position.pos==0) r.finish(n, r.zero(), n.phase(), holder);
+                    else                   r.reduce(n, r.position.pos-1, n.phase(), holder);
+                } else {
+                    r.reduce(n, n2);
+                }
             }
-            public void queueEmptyReductions() { state.invokeReductions(token, this, null, null); }
+            public void performEmptyReductions() { state.invokeReductions(token, this, null, null); }
 
-            public boolean dead = false;
-            public boolean redo = false;
             private Node(Node parent, Forest pending, State state) {
                 this.state = state;
                 this.holder().merge(pending);
index 41eae02..2a090b0 100644 (file)
@@ -272,12 +272,6 @@ public abstract class Parser<T extends Token, R> {
                 return zero = position.rewrite(null);
             }
 
-            public void reduce(GSS.Phase.Node parent) {
-                Forest[] holder = new Forest[position.pos];
-                if (position.pos==0) finish(parent, zero(), parent.phase(), holder);
-                else           reduce(parent, position.pos-1, parent.phase(), holder);
-            }
-
             public void reduce(GSS.Phase.Node parent, GSS.Phase.Node onlychild) {
                 Forest[] holder = new Forest[position.pos];
                 if (position.pos<=0) throw new Error("called wrong form of reduce()");
@@ -294,7 +288,7 @@ public abstract class Parser<T extends Token, R> {
             }
 
             // FIXME: this could be more elegant and/or cleaner and/or somewhere else
-            private void reduce(GSS.Phase.Node parent, int pos, GSS.Phase target, Forest[] holder) {
+            public void reduce(GSS.Phase.Node parent, int pos, GSS.Phase target, Forest[] holder) {
                 Forest old = holder[pos];
                 holder[pos] = parent.pending();
                 if (pos==0) {
@@ -307,7 +301,7 @@ public abstract class Parser<T extends Token, R> {
                 }
                 holder[pos] = old;
             }
-            private void finish(GSS.Phase.Node parent, Forest result, GSS.Phase target, Forest[] holder) {
+            public void finish(GSS.Phase.Node parent, Forest result, GSS.Phase target, Forest[] holder) {
                 State state = parent.state.gotoSetNonTerminals.get(position.owner());
                 if (result==null) throw new Error();
                 if (state!=null)