summaryrefslogtreecommitdiff
path: root/test/example
diff options
context:
space:
mode:
Diffstat (limited to 'test/example')
-rw-r--r--test/example/type-builder-nominal-new.cpp28
-rw-r--r--test/example/type-builder-nominal-new.txt2
-rw-r--r--test/example/type-builder-nominal.cpp35
-rw-r--r--test/example/type-builder-nominal.txt42
4 files changed, 83 insertions, 24 deletions
diff --git a/test/example/type-builder-nominal-new.cpp b/test/example/type-builder-nominal-new.cpp
index d7fe83e5f..a8bef1eca 100644
--- a/test/example/type-builder-nominal-new.cpp
+++ b/test/example/type-builder-nominal-new.cpp
@@ -114,6 +114,33 @@ void test_canonicalization() {
assert(built[2] != built[3]);
}
+// Check that defined basic HeapTypes are handled correctly.
+void test_basic() {
+ std::cout << ";; Test basic\n";
+
+ TypeBuilder builder(6);
+ makeNominal(builder);
+
+ Type anyref = builder.getTempRefType(builder[4], Nullable);
+ Type i31ref = builder.getTempRefType(builder[5], NonNullable);
+
+ builder[0] = Signature(Type::anyref, Type::i31ref);
+ builder[1] = Signature(anyref, Type::i31ref);
+ builder[2] = Signature(Type::anyref, i31ref);
+ builder[3] = Signature(anyref, i31ref);
+ builder[4] = HeapType::any;
+ builder[5] = HeapType::i31;
+
+ std::vector<HeapType> built = builder.build();
+
+ assert(built[0].getSignature() == Signature(Type::anyref, Type::i31ref));
+ assert(built[1].getSignature() == built[0].getSignature());
+ assert(built[2].getSignature() == built[1].getSignature());
+ assert(built[3].getSignature() == built[2].getSignature());
+ assert(built[4] == HeapType::any);
+ assert(built[5] == HeapType::i31);
+}
+
void test_recursive() {
std::cout << ";; Test recursive types\n";
@@ -429,6 +456,7 @@ int main() {
for (size_t i = 0; i < 2; ++i) {
test_builder();
test_canonicalization();
+ test_basic();
test_recursive();
test_subtypes();
}
diff --git a/test/example/type-builder-nominal-new.txt b/test/example/type-builder-nominal-new.txt
index 036dd9374..6f0218e54 100644
--- a/test/example/type-builder-nominal-new.txt
+++ b/test/example/type-builder-nominal-new.txt
@@ -21,6 +21,7 @@ After building types:
(rtt 0 $array) => (rtt 0 (array (mut externref)))
;; Test canonicalization
+;; Test basic
;; Test recursive types
(func (result (ref null ...1)))
@@ -67,6 +68,7 @@ After building types:
(rtt 0 $array) => (rtt 0 (array (mut externref)))
;; Test canonicalization
+;; Test basic
;; Test recursive types
(func (result (ref null ...1)))
diff --git a/test/example/type-builder-nominal.cpp b/test/example/type-builder-nominal.cpp
index 1904bb7ee..5d3bcc17c 100644
--- a/test/example/type-builder-nominal.cpp
+++ b/test/example/type-builder-nominal.cpp
@@ -99,6 +99,32 @@ void test_canonicalization() {
assert(built[2] != built[3]);
}
+// Check that defined basic HeapTypes are handled correctly.
+void test_basic() {
+ std::cout << ";; Test basic\n";
+
+ TypeBuilder builder(6);
+
+ Type anyref = builder.getTempRefType(builder[4], Nullable);
+ Type i31ref = builder.getTempRefType(builder[5], NonNullable);
+
+ builder[0] = Signature(Type::anyref, Type::i31ref);
+ builder[1] = Signature(anyref, Type::i31ref);
+ builder[2] = Signature(Type::anyref, i31ref);
+ builder[3] = Signature(anyref, i31ref);
+ builder[4] = HeapType::any;
+ builder[5] = HeapType::i31;
+
+ std::vector<HeapType> built = builder.build();
+
+ assert(built[0].getSignature() == Signature(Type::anyref, Type::i31ref));
+ assert(built[1].getSignature() == built[0].getSignature());
+ assert(built[2].getSignature() == built[1].getSignature());
+ assert(built[3].getSignature() == built[2].getSignature());
+ assert(built[4] == HeapType::any);
+ assert(built[5] == HeapType::i31);
+}
+
// Check that signatures created with TypeBuilders are properly recorded as
// canonical.
void test_signatures(bool warm) {
@@ -106,14 +132,14 @@ void test_signatures(bool warm) {
TypeBuilder builder(2);
Type tempRef = builder.getTempRefType(builder[0], Nullable);
- builder[0] = Signature(Type::anyref, Type::i31ref);
+ builder[0] = Signature(Type::i31ref, Type::anyref);
builder[1] = Signature(tempRef, tempRef);
std::vector<HeapType> built = builder.build();
- HeapType small = Signature(Type::anyref, Type::i31ref);
+ HeapType small = Signature(Type::i31ref, Type::anyref);
HeapType big =
- Signature(Type(Signature(Type::anyref, Type::i31ref), Nullable),
- Type(Signature(Type::anyref, Type::i31ref), Nullable));
+ Signature(Type(Signature(Type::i31ref, Type::anyref), Nullable),
+ Type(Signature(Type::i31ref, Type::anyref), Nullable));
if (warm) {
assert(built[0] != small);
assert(built[1] != big);
@@ -416,6 +442,7 @@ int main() {
for (size_t i = 0; i < 2; ++i) {
test_builder();
test_canonicalization();
+ test_basic();
test_signatures(i == 1);
test_recursive();
test_subtypes();
diff --git a/test/example/type-builder-nominal.txt b/test/example/type-builder-nominal.txt
index 2ecb08c89..ff3e1c5fe 100644
--- a/test/example/type-builder-nominal.txt
+++ b/test/example/type-builder-nominal.txt
@@ -1,17 +1,17 @@
;; Test TypeBuilder
Before setting heap types:
-(ref $sig) => (ref [T](func))
-(ref $struct) => (ref [T](func))
-(ref $array) => (ref [T](func))
-(ref null $array) => (ref null [T](func))
-(rtt 0 $array) => (rtt 0 [T](func))
+(ref $sig) => [T](ref [T](func))
+(ref $struct) => [T](ref [T](func))
+(ref $array) => [T](ref [T](func))
+(ref null $array) => [T](ref null [T](func))
+(rtt 0 $array) => [T](rtt 0 [T](func))
After setting heap types:
-(ref $sig) => (ref [T](func (param (ref [T](struct (field (ref null [T](array (mut externref))) (mut (rtt 0 [T](array (mut externref)))))))) (result (ref [T](array (mut externref))) i32)))
-(ref $struct) => (ref [T](struct (field (ref null [T](array (mut externref))) (mut (rtt 0 [T](array (mut externref)))))))
-(ref $array) => (ref [T](array (mut externref)))
-(ref null $array) => (ref null [T](array (mut externref)))
-(rtt 0 $array) => (rtt 0 [T](array (mut externref)))
+(ref $sig) => [T](ref [T](func (param [T](ref [T](struct (field [T](ref null [T](array (mut externref))) (mut [T](rtt 0 [T](array (mut externref)))))))) (result [T](ref [T](array (mut externref))) i32)))
+(ref $struct) => [T](ref [T](struct (field [T](ref null [T](array (mut externref))) (mut [T](rtt 0 [T](array (mut externref)))))))
+(ref $array) => [T](ref [T](array (mut externref)))
+(ref null $array) => [T](ref null [T](array (mut externref)))
+(rtt 0 $array) => [T](rtt 0 [T](array (mut externref)))
After building types:
(ref $sig) => (ref (func (param (ref (struct (field (ref null (array (mut externref))) (mut (rtt 0 (array (mut externref)))))))) (result (ref (array (mut externref))) i32)))
@@ -21,6 +21,7 @@ After building types:
(rtt 0 $array) => (rtt 0 (array (mut externref)))
;; Test canonicalization
+;; Test basic
;; Test canonical signatures
;; Test recursive types
(func (result (ref null ...1)))
@@ -47,18 +48,18 @@ After building types:
;; Test subtyping
;; Test TypeBuilder
Before setting heap types:
-(ref $sig) => (ref [T](func))
-(ref $struct) => (ref [T](func))
-(ref $array) => (ref [T](func))
-(ref null $array) => (ref null [T](func))
-(rtt 0 $array) => (rtt 0 [T](func))
+(ref $sig) => [T](ref [T](func))
+(ref $struct) => [T](ref [T](func))
+(ref $array) => [T](ref [T](func))
+(ref null $array) => [T](ref null [T](func))
+(rtt 0 $array) => [T](rtt 0 [T](func))
After setting heap types:
-(ref $sig) => (ref [T](func (param (ref [T](struct (field (ref null [T](array (mut externref))) (mut (rtt 0 [T](array (mut externref)))))))) (result (ref [T](array (mut externref))) i32)))
-(ref $struct) => (ref [T](struct (field (ref null [T](array (mut externref))) (mut (rtt 0 [T](array (mut externref)))))))
-(ref $array) => (ref [T](array (mut externref)))
-(ref null $array) => (ref null [T](array (mut externref)))
-(rtt 0 $array) => (rtt 0 [T](array (mut externref)))
+(ref $sig) => [T](ref [T](func (param [T](ref [T](struct (field [T](ref null [T](array (mut externref))) (mut [T](rtt 0 [T](array (mut externref)))))))) (result [T](ref [T](array (mut externref))) i32)))
+(ref $struct) => [T](ref [T](struct (field [T](ref null [T](array (mut externref))) (mut [T](rtt 0 [T](array (mut externref)))))))
+(ref $array) => [T](ref [T](array (mut externref)))
+(ref null $array) => [T](ref null [T](array (mut externref)))
+(rtt 0 $array) => [T](rtt 0 [T](array (mut externref)))
After building types:
(ref $sig) => (ref (func (param (ref (struct (field (ref null (array (mut externref))) (mut (rtt 0 (array (mut externref)))))))) (result (ref (array (mut externref))) i32)))
@@ -68,6 +69,7 @@ After building types:
(rtt 0 $array) => (rtt 0 (array (mut externref)))
;; Test canonicalization
+;; Test basic
;; Test canonical signatures
;; Test recursive types
(func (result (ref null ...1)))