summaryrefslogtreecommitdiff
path: root/chapter13/src/main/java/com/seaofnodes
diff options
context:
space:
mode:
Diffstat (limited to 'chapter13/src/main/java/com/seaofnodes')
-rw-r--r--chapter13/src/main/java/com/seaofnodes/simple/node/AddNode.java10
-rw-r--r--chapter13/src/main/java/com/seaofnodes/simple/node/DivNode.java10
-rw-r--r--chapter13/src/main/java/com/seaofnodes/simple/node/MinusNode.java2
-rw-r--r--chapter13/src/main/java/com/seaofnodes/simple/node/MulNode.java10
-rw-r--r--chapter13/src/main/java/com/seaofnodes/simple/node/NotNode.java6
-rw-r--r--chapter13/src/main/java/com/seaofnodes/simple/node/SubNode.java10
6 files changed, 33 insertions, 15 deletions
diff --git a/chapter13/src/main/java/com/seaofnodes/simple/node/AddNode.java b/chapter13/src/main/java/com/seaofnodes/simple/node/AddNode.java
index 1c4b94f8..eb1bd073 100644
--- a/chapter13/src/main/java/com/seaofnodes/simple/node/AddNode.java
+++ b/chapter13/src/main/java/com/seaofnodes/simple/node/AddNode.java
@@ -19,12 +19,16 @@ public class AddNode extends Node {
@Override
public Type compute() {
- if( in(1)._type instanceof TypeInteger i0 &&
- in(2)._type instanceof TypeInteger i1 ) {
+ Type t1 = in(1)._type, t2 = in(2)._type;
+ if( t1==Type.TOP || t1==TypeInteger.TOP ||
+ t2==Type.TOP || t2==TypeInteger.TOP )
+ return TypeInteger.TOP;
+ if( t1 instanceof TypeInteger i0 &&
+ t2 instanceof TypeInteger i1 ) {
if (i0.isConstant() && i1.isConstant())
return TypeInteger.constant(i0.value()+i1.value());
}
- return in(1)._type.meet(in(2)._type);
+ return TypeInteger.BOT;
}
@Override
diff --git a/chapter13/src/main/java/com/seaofnodes/simple/node/DivNode.java b/chapter13/src/main/java/com/seaofnodes/simple/node/DivNode.java
index ae73284f..bc9ff7d9 100644
--- a/chapter13/src/main/java/com/seaofnodes/simple/node/DivNode.java
+++ b/chapter13/src/main/java/com/seaofnodes/simple/node/DivNode.java
@@ -19,14 +19,18 @@ public class DivNode extends Node {
@Override
public Type compute() {
- if (in(1)._type instanceof TypeInteger i0 &&
- in(2)._type instanceof TypeInteger i1) {
+ Type t1 = in(1)._type, t2 = in(2)._type;
+ if( t1==Type.TOP || t1==TypeInteger.TOP ||
+ t2==Type.TOP || t2==TypeInteger.TOP )
+ return TypeInteger.TOP;
+ if (t1 instanceof TypeInteger i0 &&
+ t2 instanceof TypeInteger i1) {
if (i0.isConstant() && i1.isConstant())
return i1.value() == 0
? TypeInteger.ZERO
: TypeInteger.constant(i0.value()/i1.value());
}
- return in(1)._type.meet(in(2)._type);
+ return TypeInteger.BOT;
}
@Override
diff --git a/chapter13/src/main/java/com/seaofnodes/simple/node/MinusNode.java b/chapter13/src/main/java/com/seaofnodes/simple/node/MinusNode.java
index 0f2669b9..c3be733c 100644
--- a/chapter13/src/main/java/com/seaofnodes/simple/node/MinusNode.java
+++ b/chapter13/src/main/java/com/seaofnodes/simple/node/MinusNode.java
@@ -20,7 +20,7 @@ public class MinusNode extends Node {
public Type compute() {
if (in(1)._type instanceof TypeInteger i0)
return i0.isConstant() ? TypeInteger.constant(-i0.value()) : i0;
- return TypeInteger.TOP.meet(in(1)._type);
+ return in(1)._type==Type.TOP ? TypeInteger.TOP : TypeInteger.BOT;
}
@Override
diff --git a/chapter13/src/main/java/com/seaofnodes/simple/node/MulNode.java b/chapter13/src/main/java/com/seaofnodes/simple/node/MulNode.java
index e631492c..4cd075e4 100644
--- a/chapter13/src/main/java/com/seaofnodes/simple/node/MulNode.java
+++ b/chapter13/src/main/java/com/seaofnodes/simple/node/MulNode.java
@@ -19,12 +19,16 @@ public class MulNode extends Node {
@Override
public Type compute() {
- if (in(1)._type instanceof TypeInteger i0 &&
- in(2)._type instanceof TypeInteger i1) {
+ Type t1 = in(1)._type, t2 = in(2)._type;
+ if( t1==Type.TOP || t1==TypeInteger.TOP ||
+ t2==Type.TOP || t2==TypeInteger.TOP )
+ return TypeInteger.TOP;
+ if (t1 instanceof TypeInteger i0 &&
+ t2 instanceof TypeInteger i1) {
if (i0.isConstant() && i1.isConstant())
return TypeInteger.constant(i0.value()*i1.value());
}
- return in(1)._type.meet(in(2)._type);
+ return TypeInteger.BOT;
}
@Override
diff --git a/chapter13/src/main/java/com/seaofnodes/simple/node/NotNode.java b/chapter13/src/main/java/com/seaofnodes/simple/node/NotNode.java
index e987bd82..bb7e9265 100644
--- a/chapter13/src/main/java/com/seaofnodes/simple/node/NotNode.java
+++ b/chapter13/src/main/java/com/seaofnodes/simple/node/NotNode.java
@@ -20,7 +20,9 @@ public class NotNode extends Node {
Type t0 = in(1)._type;
switch( t0 ) {
case TypeInteger i0: return i0.isConstant() ? TypeInteger.constant(i0.value()==0 ? 1 : 0) : i0;
- case TypeFloat i0: return i0.isConstant() ? TypeInteger.constant(i0.value()==0 ? 1 : 0) : i0;
+ case TypeFloat i0:
+ if( i0==TypeFloat.TOP ) return TypeInteger.TOP;
+ return i0.isConstant() ? TypeInteger.constant(i0.value()==0 ? 1 : 0) : TypeInteger.BOT;
case TypeMemPtr p0:
// top->top, bot->bot, null->1, *void->0, not-null ptr->0, ptr/nil->bot
// If input in null then true
@@ -33,7 +35,7 @@ public class NotNode extends Node {
if( t0.getClass() != Type.class )
// Only doing NOT on ints and ptrs
throw Utils.TODO();
- return t0==Type.TOP ? Type.TOP : Type.BOTTOM;
+ return t0==Type.TOP ? TypeInteger.TOP : TypeInteger.BOT;
}
}
diff --git a/chapter13/src/main/java/com/seaofnodes/simple/node/SubNode.java b/chapter13/src/main/java/com/seaofnodes/simple/node/SubNode.java
index 467d9181..4b860c37 100644
--- a/chapter13/src/main/java/com/seaofnodes/simple/node/SubNode.java
+++ b/chapter13/src/main/java/com/seaofnodes/simple/node/SubNode.java
@@ -20,17 +20,21 @@ public class SubNode extends Node {
@Override
public Type compute() {
+ Type t1 = in(1)._type, t2 = in(2)._type;
+ if( t1==Type.TOP || t1==TypeInteger.TOP ||
+ t2==Type.TOP || t2==TypeInteger.TOP )
+ return TypeInteger.TOP;
// Sub of same is 0
if( in(1)==in(2) )
return TypeInteger.ZERO;
- if (in(1)._type instanceof TypeInteger i0 &&
- in(2)._type instanceof TypeInteger i1) {
+ if (t1 instanceof TypeInteger i0 &&
+ t2 instanceof TypeInteger i1) {
if (i0.isConstant() && i1.isConstant())
return TypeInteger.constant(i0.value()-i1.value());
}
- return in(1)._type.meet(in(2)._type);
+ return TypeInteger.BOT;
}
@Override