summaryrefslogtreecommitdiff
path: root/chapter14
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-09-05 09:15:15 -0700
committerThalia Archibald <thalia@archibald.dev>2024-09-07 10:54:48 -0700
commitec7f127c3b32e229ada9ee52def44d6f476c0a99 (patch)
treeb87d15e9157562b0316f216a23885ac3fafaa5ea /chapter14
parent489598387697dcefee1ec2aa5e356b3134722a9a (diff)
downloadSimple-ec7f127c3b32e229ada9ee52def44d6f476c0a99.tar.gz
Simple-ec7f127c3b32e229ada9ee52def44d6f476c0a99.zip
Cleanup comments to match design
Went through several iterations, one where a null _obj was allowed, but settled on using TypeStruct.BOT instead.
Diffstat (limited to 'chapter14')
-rw-r--r--chapter14/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java24
1 files changed, 13 insertions, 11 deletions
diff --git a/chapter14/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java b/chapter14/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java
index 565e15a4..06fe2963 100644
--- a/chapter14/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java
+++ b/chapter14/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java
@@ -13,16 +13,21 @@ import java.util.ArrayList;
*/
public class TypeMemPtr extends Type {
// A TypeMemPtr is pair (obj,nil)
- // where obj is one of
- // (null,TypeStruct).
- // where nil is one of
- // (true,false) meaning an explicit null is allowed or not
+ // where obj is a TypeStruct, possibly TypeStruct.BOT
+ // where nil is an explicit null is allowed or not
- public final TypeStruct _obj; // null, a TypeStruct, or sentinel TypeStruct.MANY
+ // Examples:
+ // (Person,false) - a not-nil Person
+ // (Person,true ) - a Person or a nil
+ // (BOT ,false) - a not-nil void* (unspecified struct)
+ // (TOP ,true ) - a nil
+
+ public final TypeStruct _obj;
public final boolean _nil;
private TypeMemPtr(TypeStruct obj, boolean nil) {
super(TMEMPTR);
+ assert obj!=null;
_obj = obj;
_nil = nil;
}
@@ -44,19 +49,16 @@ public class TypeMemPtr extends Type {
}
@Override
- public TypeMemPtr dual() { return TypeMemPtr.make(_obj==null ? null : _obj.dual(), !_nil); }
+ public TypeMemPtr dual() { return TypeMemPtr.make(_obj.dual(), !_nil); }
@Override
- public Type glb() {
- if( _obj==null ) return BOT;
- return make(_obj.glb(),true);
- }
+ public Type glb() { return make(_obj.glb(),true); }
@Override public TypeMemPtr makeInit() { return NULLPTR; }
@Override public boolean isHigh() { return this==TOP; }
@Override
- int hash() { return (_obj==null ? 0xDEADBEEF : _obj.hashCode()) ^ (_nil ? 1024 : 0); }
+ int hash() { return _obj.hashCode() ^ (_nil ? 1024 : 0); }
@Override
boolean eq(Type t) {