@@ -46,6 +46,8 @@ class Type {
4646 FuncRef = -0x10 , // 0x70
4747 ExternRef = -0x11 , // 0x6f
4848 Reference = -0x15 , // 0x6b
49+ HeapRef = -0x1c , // 0x64
50+ HeapNullRef = -0x1d , // 0x63
4951 Func = -0x20 , // 0x60
5052 Struct = -0x21 , // 0x5f
5153 Array = -0x22 , // 0x5e
@@ -63,20 +65,24 @@ class Type {
6365 : enum_(static_cast <Enum>(code)), type_index_(kInvalidIndex ) {}
6466 Type (Enum e) : enum_(e), type_index_(kInvalidIndex ) {}
6567 Type (Enum e, Index type_index) : enum_(e), type_index_(type_index) {
66- assert (e == Enum::Reference);
68+ assert (e == Enum::Reference || e == Enum::HeapRef ||
69+ e == Enum::HeapNullRef || type_index == kInvalidIndex );
6770 }
6871 constexpr operator Enum () const { return enum_; }
6972
70- bool IsRef () const {
73+ bool IsNullableRef () const {
7174 return enum_ == Type::ExternRef || enum_ == Type::FuncRef ||
72- enum_ == Type::Reference || enum_ == Type::ExnRef;
75+ enum_ == Type::Reference || enum_ == Type::ExnRef ||
76+ enum_ == Type::HeapNullRef;
7377 }
7478
75- bool IsReferenceWithIndex () const { return enum_ == Type::Reference; }
79+ bool IsRef () const {
80+ return IsNullableRef () || enum_ == Type::HeapRef;
81+ }
7682
77- bool IsNullableRef () const {
78- // Currently all reftypes are nullable
79- return IsRef () ;
83+ bool IsReferenceWithIndex () const {
84+ return enum_ == Type::Reference || enum_ == Type::HeapRef ||
85+ enum_ == Type::HeapNullRef ;
8086 }
8187
8288 std::string GetName () const {
@@ -95,6 +101,8 @@ class Type {
95101 case Type::Any: return " any" ;
96102 case Type::ExternRef: return " externref" ;
97103 case Type::Reference:
104+ case Type::HeapRef:
105+ case Type::HeapNullRef:
98106 return StringPrintf (" (ref %d)" , type_index_);
99107 default :
100108 return StringPrintf (" <type_index[%d]>" , enum_);
@@ -132,7 +140,7 @@ class Type {
132140 }
133141
134142 Index GetReferenceIndex () const {
135- assert (enum_ == Enum::Reference );
143+ assert (IsReferenceWithIndex () );
136144 return type_index_;
137145 }
138146
@@ -151,6 +159,8 @@ class Type {
151159 case Type::ExnRef:
152160 case Type::ExternRef:
153161 case Type::Reference:
162+ case Type::HeapRef:
163+ case Type::HeapNullRef:
154164 return TypeVector (this , this + 1 );
155165
156166 default :
0 commit comments