diff options
| author | Dibyendu Majumdar <dibyendumajumdar@users.noreply.github.com> | 2024-01-15 16:23:49 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-15 08:23:49 -0800 |
| commit | d016a42b63b6c590dfd3c15a5f9cf8be10a9de56 (patch) | |
| tree | d916dcca269b0c5460e2e85b2e480edb0f56f77d /chapter04/src | |
| parent | 399bb146cc0bb0c548cd0b50e51fb9aa29a7900c (diff) | |
| download | Simple-d016a42b63b6c590dfd3c15a5f9cf8be10a9de56.tar.gz Simple-d016a42b63b6c590dfd3c15a5f9cf8be10a9de56.zip | |
Sync changes to previous chapters (#57)
Also fix broken links in README
Diffstat (limited to 'chapter04/src')
| -rw-r--r-- | chapter04/src/main/java/com/seaofnodes/simple/Parser.java | 4 | ||||
| -rw-r--r-- | chapter04/src/main/java/com/seaofnodes/simple/node/Node.java | 11 |
2 files changed, 5 insertions, 10 deletions
diff --git a/chapter04/src/main/java/com/seaofnodes/simple/Parser.java b/chapter04/src/main/java/com/seaofnodes/simple/Parser.java index 8daaed73..b517d20e 100644 --- a/chapter04/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter04/src/main/java/com/seaofnodes/simple/Parser.java @@ -199,10 +199,10 @@ public class Parser { var lhs = parseAddition(); if (match("==")) return new BoolNode.EQ(lhs, parseComparison()).peephole(); if (match("!=")) return new NotNode(new BoolNode.EQ(lhs, parseComparison()).peephole()).peephole(); - if (match("<" )) return new BoolNode.LT(lhs, parseComparison()).peephole(); if (match("<=")) return new BoolNode.LE(lhs, parseComparison()).peephole(); - if (match(">" )) return new BoolNode.LT(parseComparison(), lhs).peephole(); + if (match("<" )) return new BoolNode.LT(lhs, parseComparison()).peephole(); if (match(">=")) return new BoolNode.LE(parseComparison(), lhs).peephole(); + if (match(">" )) return new BoolNode.LT(parseComparison(), lhs).peephole(); return lhs; } diff --git a/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java index 2b293193..bebfd3a1 100644 --- a/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/chapter04/src/main/java/com/seaofnodes/simple/node/Node.java @@ -81,10 +81,7 @@ public abstract class Node { // line (because this is what a debugger typically displays by default) and // has to be robust with broken graph/nodes. @Override - public final String toString() { - // TODO: This needs a lot of work - return print(); - } + public final String toString() { return print(); } // This is a *deep* print. This version will fail on cycles, which we will // correct later when we can parse programs with loops. We print with a @@ -121,8 +118,6 @@ public abstract class Node { public boolean isCFG() { return false; } - - /** * Change a <em>def</em> into a Node. Keeps the edges correct, by removing * the corresponding <em>use->def</em> edge. This may make the original @@ -180,11 +175,11 @@ public abstract class Node { // Error is 'use' does not exist; ok for 'use' to be null. protected boolean delUse( Node use ) { Utils.del(_outputs, Utils.find(_outputs, use)); - return _outputs.size() == 0; + return _outputs.isEmpty(); } // Shortcut for "popping" n nodes. A "pop" is basically a - // set_def(last,null) followed by lowering the nIns() count. + // setDef(last,null) followed by lowering the nIns() count. void popN(int n) { for( int i=0; i<n; i++ ) { Node old_def = _inputs.removeLast(); |
