diff options
| author | Cliff Click <cliffc@acm.org> | 2024-09-13 09:23:19 -0700 |
|---|---|---|
| committer | XmiliaH <45106915+XmiliaH@users.noreply.github.com> | 2024-09-13 18:46:01 +0200 |
| commit | 703f88dbb2e1e4352a0725b7e742151739b82ea1 (patch) | |
| tree | a1e541797a02d79c372508a22b7ddabb0f25fdb9 /chapter14 | |
| parent | ce4c47a5bec87ca404fbb49a2d91f34ab6f4e545 (diff) | |
| download | Simple-703f88dbb2e1e4352a0725b7e742151739b82ea1.tar.gz Simple-703f88dbb2e1e4352a0725b7e742151739b82ea1.zip | |
x-x==0
Move x-x==0 to compute.
Add x/1 ==> x
All chapters
Diffstat (limited to 'chapter14')
| -rw-r--r-- | chapter14/src/main/java/com/seaofnodes/simple/node/DivNode.java | 7 | ||||
| -rw-r--r-- | chapter14/src/main/java/com/seaofnodes/simple/node/SubNode.java | 8 |
2 files changed, 10 insertions, 5 deletions
diff --git a/chapter14/src/main/java/com/seaofnodes/simple/node/DivNode.java b/chapter14/src/main/java/com/seaofnodes/simple/node/DivNode.java index 0d169cda..da9571db 100644 --- a/chapter14/src/main/java/com/seaofnodes/simple/node/DivNode.java +++ b/chapter14/src/main/java/com/seaofnodes/simple/node/DivNode.java @@ -35,7 +35,12 @@ public class DivNode extends Node { } @Override - public Node idealize() { return null; } + public Node idealize() { + // Div of 1. + if( in(2)._type.isConstant() && in(2)._type instanceof TypeInteger i && i.value()==1 ) + return in(1); + return null; + } @Override Node copy(Node lhs, Node rhs) { return new DivNode(lhs,rhs); } @Override Node copyF() { return new DivFNode(null,null); } diff --git a/chapter14/src/main/java/com/seaofnodes/simple/node/SubNode.java b/chapter14/src/main/java/com/seaofnodes/simple/node/SubNode.java index 89e7227e..009fb30e 100644 --- a/chapter14/src/main/java/com/seaofnodes/simple/node/SubNode.java +++ b/chapter14/src/main/java/com/seaofnodes/simple/node/SubNode.java @@ -30,15 +30,15 @@ public class SubNode extends Node { if (i1.isConstant() && i2.isConstant()) return TypeInteger.constant(i1.value()-i2.value()); } + // Sub of same is 0 + if( in(1)==in(2) ) + return TypeInteger.ZERO; + return TypeInteger.BOT; } @Override public Node idealize() { - // Sub of same is 0 - if( in(1)==in(2) ) - return Parser.ZERO; - // x - (-y) is x+y if( in(2) instanceof MinusNode minus ) return new AddNode(in(1),minus.in(1)); |
