X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FGSS.java;h=5feba84a0b935984625efaed044aa75b6b5b4129;hb=1b46ed935f0fb6fb18afd40f5d1771be030a5a0d;hp=d2b040d42fa475eae6bba5d4a3d1e32ca5c9790f;hpb=ddf7ffb485e6b3dd0fe6b1b39b47a21a1e4b8973;p=sbp.git diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java index d2b040d..5feba84 100644 --- a/src/edu/berkeley/sbp/GSS.java +++ b/src/edu/berkeley/sbp/GSS.java @@ -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) p.queueReductions(parent); + if (p!=parent && !fromEmptyReduction && reducing) p.performReductions(parent); return true; } private boolean newNode3(Node parent, Forest pending, State state, boolean fromEmptyReduction) { @@ -140,9 +140,11 @@ class GSS { //return; } while(false); - Node n = new Node(parent, pending, state, fromEmptyReduction); // ALLOC - n.queueEmptyReductions(); - if (!fromEmptyReduction) n.queueReductions(parent); + Node n = new Node(parent, pending, state); // ALLOC + if (reducing) { + n.performEmptyReductions(); + if (!fromEmptyReduction) n.performReductions(parent); + } return true; } @@ -181,13 +183,13 @@ class GSS { int num = hash.size(); for(int i=0; i implements Invokable { - public boolean touched = false; private Forest.Ref holder = null; private boolean allqueued = false; @@ -260,44 +261,59 @@ class GSS { public final State state; /** which Phase this Node belongs to (node that Node is also a non-static inner class of Phase) */ - public Phase phase() { return Phase.this; } - + public Phase phase() { return Phase.this; } public Forest.Ref holder() { return holder==null ? (holder = new Forest.Ref()) : holder; } public Forest pending() { return Phase.this.closed ? holder().resolve() : holder; } public FastSet parents() { return this; } - public void queueReductions() { - if (!reducing) return; + public void performReductions() { if (allqueued) return; allqueued = true; - int where = parents().size(); 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); - return; + 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) n.finish(r, r.zero(), n.phase(), holder); + else r.reduce(n, r.position.pos-1, n.phase(), holder); + } else { + Forest[] holder = new Forest[r.position.pos]; + if (r.position.pos<=0) throw new Error("called wrong form of reduce()"); + int pos = r.position.pos-1; + Forest old = holder[pos]; + holder[pos] = n.pending(); + if (pos==0) { + System.arraycopy(holder, 0, r.position.holder, 0, holder.length); + Forest rex = r.position.rewrite(n.phase().getLocation()); + n2.finish(r, rex, n.phase(), holder); + } else { + r.reduce(n2, pos-1, n.phase(), holder); + } + holder[pos] = old; } - if (r.position.pos==0) return; - if (n2==null) r.reduce(n); - else r.reduce(n, n2); } - public void queueEmptyReductions() { - if (!reducing) return; - state.invokeReductions(token, this, null, null); + + public void finish(Reduction r, Forest result, GSS.Phase target, Forest[] holder) { + State state0 = state.gotoSetNonTerminals.get(r.position.owner()); + if (result==null) throw new Error(); + if (state0!=null) + target.newNode(this, result, state0, r.position.pos<=0, r); } - private boolean fe; - public boolean dead = false; - public boolean redo = false; - private Node(Node parent, Forest pending, State state, boolean fe) { - this.fe = fe; + public void performEmptyReductions() { state.invokeReductions(token, this, null, null); } + + private Node(Node parent, Forest pending, State state) { this.state = state; this.holder().merge(pending); Phase start = parent==null ? null : parent.phase();