diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/binaryen.js/expressions.js | 57 | ||||
-rw-r--r-- | test/binaryen.js/expressions.js.txt | 10 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js | 19 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 42 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 5 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 19 | ||||
-rw-r--r-- | test/gc.wast | 81 | ||||
-rw-r--r-- | test/gc.wast.from-wast | 149 | ||||
-rw-r--r-- | test/gc.wast.fromBinary | 150 | ||||
-rw-r--r-- | test/gc.wast.fromBinary.noDebugInfo | 150 |
10 files changed, 682 insertions, 0 deletions
diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index a97097afe..0d48e5551 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -1649,3 +1649,60 @@ console.log("# TupleExtract"); module.dispose(); })(); + +console.log("# I31New"); +(function testI31New() { + const module = new binaryen.Module(); + + var value = module.local.get(1, binaryen.i32); + const theI31New = binaryen.I31New(module.i31.new(value)); + assert(theI31New instanceof binaryen.I31New); + assert(theI31New instanceof binaryen.Expression); + assert(theI31New.value === value); + assert(theI31New.type === binaryen.i31ref); + + theI31New.value = value = module.local.get(2, binaryen.i32); + assert(theI31New.value === value); + theI31New.type = binaryen.f64; + theI31New.finalize(); + assert(theI31New.type === binaryen.i31ref); + + console.log(theI31New.toText()); + assert( + theI31New.toText() + == + "(i31.new\n (local.get $2)\n)\n" + ); + + module.dispose(); +})(); + +console.log("# I31Get"); +(function testI31Get() { + const module = new binaryen.Module(); + + var i31 = module.local.get(1, binaryen.i31ref); + const theI31Get = binaryen.I31Get(module.i31.get_s(i31)); + assert(theI31Get instanceof binaryen.I31Get); + assert(theI31Get instanceof binaryen.Expression); + assert(theI31Get.i31 === i31); + assert(theI31Get.signed === true); + assert(theI31Get.type === binaryen.i32); + + theI31Get.i31 = i31 = module.local.get(2, binaryen.i31ref); + assert(theI31Get.i31 === i31); + theI31Get.signed = false; + assert(theI31Get.signed === false); + theI31Get.type = binaryen.f64; + theI31Get.finalize(); + assert(theI31Get.type === binaryen.i32); + + console.log(theI31Get.toText()); + assert( + theI31Get.toText() + == + "(i31.get_u\n (local.get $2)\n)\n" + ); + + module.dispose(); +})(); diff --git a/test/binaryen.js/expressions.js.txt b/test/binaryen.js/expressions.js.txt index 22c4f2747..e2b34e501 100644 --- a/test/binaryen.js/expressions.js.txt +++ b/test/binaryen.js/expressions.js.txt @@ -256,3 +256,13 @@ ) ) +# I31New +(i31.new + (local.get $2) +) + +# I31Get +(i31.get_u + (local.get $2) +) + diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index f699e96e0..051f53c54 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -165,6 +165,10 @@ function test_ids() { console.log("ThrowId: " + binaryen.ThrowId); console.log("RethrowId: " + binaryen.RethrowId); console.log("BrOnExnId: " + binaryen.BrOnExnId); + console.log("TupleMakeId: " + binaryen.TupleMakeId); + console.log("TupleExtractId: " + binaryen.TupleExtractId); + console.log("I31NewId: " + binaryen.I31NewId); + console.log("I31GetId: " + binaryen.I31GetId); } function test_core() { @@ -595,6 +599,21 @@ function test_core() { module.memory.size(), module.memory.grow(makeInt32(0)), + // GC + module.i31.new( + module.i32.const(0) + ), + module.i31.get_s( + module.i31.new( + module.i32.const(1) + ) + ), + module.i31.get_u( + module.i31.new( + module.i32.const(2) + ) + ), + // Other module.nop(), module.unreachable(), diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 1c11e787e..9fca3ae53 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -89,6 +89,10 @@ TryId: 44 ThrowId: 45 RethrowId: 46 BrOnExnId: 47 +TupleMakeId: 48 +TupleExtractId: 49 +I31NewId: 50 +I31GetId: 51 getExpressionInfo={"id":15,"type":4,"op":6} (f32.neg (f32.const -33.61199951171875) @@ -1952,6 +1956,25 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7} (i32.const 0) ) ) + (drop + (i31.new + (i32.const 0) + ) + ) + (drop + (i31.get_s + (i31.new + (i32.const 1) + ) + ) + ) + (drop + (i31.get_u + (i31.new + (i32.const 2) + ) + ) + ) (nop) (unreachable) ) @@ -3815,6 +3838,25 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7} (i32.const 0) ) ) + (drop + (i31.new + (i32.const 0) + ) + ) + (drop + (i31.get_s + (i31.new + (i32.const 1) + ) + ) + ) + (drop + (i31.get_u + (i31.new + (i32.const 2) + ) + ) + ) (nop) (unreachable) ) diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 09a6897eb..118fcb3f3 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -312,6 +312,7 @@ void test_core() { BinaryenExpressionRef funcrefExpr = BinaryenRefNull(module, BinaryenTypeFuncref()); funcrefExpr = BinaryenRefFunc(module, "kitchen()sinker"); BinaryenExpressionRef exnrefExpr = BinaryenRefNull(module, BinaryenTypeExnref()); + BinaryenExpressionRef i31refExpr = BinaryenI31New(module, makeInt32(module, 1)); // Events BinaryenAddEvent( @@ -776,6 +777,10 @@ void test_core() { // Memory BinaryenMemorySize(module), BinaryenMemoryGrow(module, makeInt32(module, 0)), + // GC + BinaryenI31New(module, makeInt32(module, 0)), + BinaryenI31Get(module, i31refExpr, 1), + BinaryenI31Get(module, BinaryenI31New(module, makeInt32(module, 2)), 0), // Other BinaryenNop(module), BinaryenUnreachable(module), diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 29ead874f..fe951cdcc 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -1874,6 +1874,25 @@ BinaryenFeatureAll: 4095 (i32.const 0) ) ) + (drop + (i31.new + (i32.const 0) + ) + ) + (drop + (i31.get_s + (i31.new + (i32.const 1) + ) + ) + ) + (drop + (i31.get_u + (i31.new + (i32.const 2) + ) + ) + ) (nop) (unreachable) ) diff --git a/test/gc.wast b/test/gc.wast new file mode 100644 index 000000000..c3c561413 --- /dev/null +++ b/test/gc.wast @@ -0,0 +1,81 @@ +;; A preliminary test for prototype GC types and instructions. +;; TODO: Move subtype tests from reference-types.wast here? + +(module + ;; TODO: There are no trivial global initializers for i31ref globals because + ;; i31ref is non-nullable, hence `(ref.null i31)` cannot be used. The test + ;; currently works around this limitation by importing a constant value. + (import "env" "trivial_i31ref" (global $trivial_i31ref i31ref)) + + ;; Test global initializer expressions + (global $global_anyref (mut anyref) (ref.null any)) + (global $global_eqref (mut eqref) (ref.null eq)) + (global $global_i31ref (mut i31ref) (global.get $trivial_i31ref)) ;; ^ + + ;; Test subtype relationship in global initializer expressions + (global $global_anyref2 (mut anyref) (ref.null eq)) + (global $global_anyref3 (mut anyref) (global.get $trivial_i31ref)) ;; ^ + (global $global_eqref2 (mut eqref) (global.get $trivial_i31ref)) ;; ^ + + (func $test + (local $local_i32 i32) + (local $local_anyref anyref) + (local $local_eqref eqref) + (local $local_i31ref i31ref) + + ;; Test types for local.get/set + (local.set $local_anyref (local.get $local_anyref)) + (local.set $local_anyref (global.get $global_anyref)) + (local.set $local_anyref (ref.null any)) + (local.set $local_eqref (local.get $local_eqref)) + (local.set $local_eqref (global.get $global_eqref)) + (local.set $local_eqref (ref.null eq)) + (local.set $local_i31ref (local.get $local_i31ref)) + (local.set $local_i31ref (global.get $global_i31ref)) + (local.set $local_i31ref (global.get $trivial_i31ref)) ;; ^ + + ;; Test subtype relationship for local.set + (local.set $local_anyref (local.get $local_eqref)) + (local.set $local_anyref (global.get $global_eqref)) + (local.set $local_anyref (ref.null eq)) + (local.set $local_anyref (local.get $local_i31ref)) + (local.set $local_anyref (global.get $global_i31ref)) + (local.set $local_anyref (global.get $trivial_i31ref)) ;; ^ + (local.set $local_eqref (local.get $local_i31ref)) + (local.set $local_eqref (global.get $global_i31ref)) + (local.set $local_eqref (global.get $trivial_i31ref)) ;; ^ + + ;; Test types for global.get/set + (global.set $global_anyref (local.get $local_anyref)) + (global.set $global_anyref (global.get $global_anyref)) + (global.set $global_anyref (ref.null any)) + (global.set $global_eqref (local.get $local_eqref)) + (global.set $global_eqref (global.get $global_eqref)) + (global.set $global_eqref (ref.null eq)) + (global.set $global_i31ref (local.get $local_i31ref)) + (global.set $global_i31ref (global.get $global_i31ref)) + (global.set $global_i31ref (global.get $trivial_i31ref)) ;; ^ + + ;; Test subtype relationship for global.set + (global.set $global_anyref (local.get $local_eqref)) + (global.set $global_anyref (global.get $global_eqref)) + (global.set $global_anyref (ref.null eq)) + (global.set $global_anyref (local.get $local_i31ref)) + (global.set $global_anyref (global.get $global_i31ref)) + (global.set $global_anyref (global.get $trivial_i31ref)) ;; ^ + (global.set $global_eqref (local.get $local_i31ref)) + (global.set $global_eqref (global.get $global_i31ref)) + (global.set $global_eqref (global.get $trivial_i31ref)) ;; ^ + + ;; Test i31.new + (local.set $local_i31ref (i31.new (i32.const 0))) + + ;; Test subtype relationship for i31.new + (local.set $local_anyref (i31.new (i32.const 0))) + (local.set $local_eqref (i31.new (i32.const 0))) + + ;; Test i31.get_s/u + (local.set $local_i32 (i31.get_s (local.get $local_i31ref))) + (local.set $local_i32 (i31.get_u (local.get $local_i31ref))) + ) +) diff --git a/test/gc.wast.from-wast b/test/gc.wast.from-wast new file mode 100644 index 000000000..7a80cffe6 --- /dev/null +++ b/test/gc.wast.from-wast @@ -0,0 +1,149 @@ +(module + (type $none_=>_none (func)) + (import "env" "trivial_i31ref" (global $trivial_i31ref i31ref)) + (global $global_anyref (mut anyref) (ref.null any)) + (global $global_eqref (mut eqref) (ref.null eq)) + (global $global_i31ref (mut i31ref) (global.get $trivial_i31ref)) + (global $global_anyref2 (mut anyref) (ref.null eq)) + (global $global_anyref3 (mut anyref) (global.get $trivial_i31ref)) + (global $global_eqref2 (mut eqref) (global.get $trivial_i31ref)) + (func $test + (local $local_i32 i32) + (local $local_anyref anyref) + (local $local_eqref eqref) + (local $local_i31ref i31ref) + (local.set $local_anyref + (local.get $local_anyref) + ) + (local.set $local_anyref + (global.get $global_anyref) + ) + (local.set $local_anyref + (ref.null any) + ) + (local.set $local_eqref + (local.get $local_eqref) + ) + (local.set $local_eqref + (global.get $global_eqref) + ) + (local.set $local_eqref + (ref.null eq) + ) + (local.set $local_i31ref + (local.get $local_i31ref) + ) + (local.set $local_i31ref + (global.get $global_i31ref) + ) + (local.set $local_i31ref + (global.get $trivial_i31ref) + ) + (local.set $local_anyref + (local.get $local_eqref) + ) + (local.set $local_anyref + (global.get $global_eqref) + ) + (local.set $local_anyref + (ref.null eq) + ) + (local.set $local_anyref + (local.get $local_i31ref) + ) + (local.set $local_anyref + (global.get $global_i31ref) + ) + (local.set $local_anyref + (global.get $trivial_i31ref) + ) + (local.set $local_eqref + (local.get $local_i31ref) + ) + (local.set $local_eqref + (global.get $global_i31ref) + ) + (local.set $local_eqref + (global.get $trivial_i31ref) + ) + (global.set $global_anyref + (local.get $local_anyref) + ) + (global.set $global_anyref + (global.get $global_anyref) + ) + (global.set $global_anyref + (ref.null any) + ) + (global.set $global_eqref + (local.get $local_eqref) + ) + (global.set $global_eqref + (global.get $global_eqref) + ) + (global.set $global_eqref + (ref.null eq) + ) + (global.set $global_i31ref + (local.get $local_i31ref) + ) + (global.set $global_i31ref + (global.get $global_i31ref) + ) + (global.set $global_i31ref + (global.get $trivial_i31ref) + ) + (global.set $global_anyref + (local.get $local_eqref) + ) + (global.set $global_anyref + (global.get $global_eqref) + ) + (global.set $global_anyref + (ref.null eq) + ) + (global.set $global_anyref + (local.get $local_i31ref) + ) + (global.set $global_anyref + (global.get $global_i31ref) + ) + (global.set $global_anyref + (global.get $trivial_i31ref) + ) + (global.set $global_eqref + (local.get $local_i31ref) + ) + (global.set $global_eqref + (global.get $global_i31ref) + ) + (global.set $global_eqref + (global.get $trivial_i31ref) + ) + (local.set $local_i31ref + (i31.new + (i32.const 0) + ) + ) + (local.set $local_anyref + (i31.new + (i32.const 0) + ) + ) + (local.set $local_eqref + (i31.new + (i32.const 0) + ) + ) + (local.set $local_i32 + (i31.get_s + (local.get $local_i31ref) + ) + ) + (local.set $local_i32 + (i31.get_u + (local.get $local_i31ref) + ) + ) + ) +) diff --git a/test/gc.wast.fromBinary b/test/gc.wast.fromBinary new file mode 100644 index 000000000..f1308b9b1 --- /dev/null +++ b/test/gc.wast.fromBinary @@ -0,0 +1,150 @@ +(module + (type $none_=>_none (func)) + (import "env" "trivial_i31ref" (global $gimport$0 i31ref)) + (global $global$0 (mut anyref) (ref.null any)) + (global $global$1 (mut eqref) (ref.null eq)) + (global $global$2 (mut i31ref) (global.get $gimport$0)) + (global $global$3 (mut anyref) (ref.null eq)) + (global $global$4 (mut anyref) (global.get $gimport$0)) + (global $global$5 (mut eqref) (global.get $gimport$0)) + (func $test + (local $local_i32 i32) + (local $local_anyref anyref) + (local $local_eqref eqref) + (local $local_i31ref i31ref) + (local.set $local_anyref + (local.get $local_anyref) + ) + (local.set $local_anyref + (global.get $global$0) + ) + (local.set $local_anyref + (ref.null any) + ) + (local.set $local_eqref + (local.get $local_eqref) + ) + (local.set $local_eqref + (global.get $global$1) + ) + (local.set $local_eqref + (ref.null eq) + ) + (local.set $local_i31ref + (local.get $local_i31ref) + ) + (local.set $local_i31ref + (global.get $global$2) + ) + (local.set $local_i31ref + (global.get $gimport$0) + ) + (local.set $local_anyref + (local.get $local_eqref) + ) + (local.set $local_anyref + (global.get $global$1) + ) + (local.set $local_anyref + (ref.null eq) + ) + (local.set $local_anyref + (local.get $local_i31ref) + ) + (local.set $local_anyref + (global.get $global$2) + ) + (local.set $local_anyref + (global.get $gimport$0) + ) + (local.set $local_eqref + (local.get $local_i31ref) + ) + (local.set $local_eqref + (global.get $global$2) + ) + (local.set $local_eqref + (global.get $gimport$0) + ) + (global.set $global$0 + (local.get $local_anyref) + ) + (global.set $global$0 + (global.get $global$0) + ) + (global.set $global$0 + (ref.null any) + ) + (global.set $global$1 + (local.get $local_eqref) + ) + (global.set $global$1 + (global.get $global$1) + ) + (global.set $global$1 + (ref.null eq) + ) + (global.set $global$2 + (local.get $local_i31ref) + ) + (global.set $global$2 + (global.get $global$2) + ) + (global.set $global$2 + (global.get $gimport$0) + ) + (global.set $global$0 + (local.get $local_eqref) + ) + (global.set $global$0 + (global.get $global$1) + ) + (global.set $global$0 + (ref.null eq) + ) + (global.set $global$0 + (local.get $local_i31ref) + ) + (global.set $global$0 + (global.get $global$2) + ) + (global.set $global$0 + (global.get $gimport$0) + ) + (global.set $global$1 + (local.get $local_i31ref) + ) + (global.set $global$1 + (global.get $global$2) + ) + (global.set $global$1 + (global.get $gimport$0) + ) + (local.set $local_i31ref + (i31.new + (i32.const 0) + ) + ) + (local.set $local_anyref + (i31.new + (i32.const 0) + ) + ) + (local.set $local_eqref + (i31.new + (i32.const 0) + ) + ) + (local.set $local_i32 + (i31.get_s + (local.get $local_i31ref) + ) + ) + (local.set $local_i32 + (i31.get_u + (local.get $local_i31ref) + ) + ) + ) +) + diff --git a/test/gc.wast.fromBinary.noDebugInfo b/test/gc.wast.fromBinary.noDebugInfo new file mode 100644 index 000000000..9989a5ad8 --- /dev/null +++ b/test/gc.wast.fromBinary.noDebugInfo @@ -0,0 +1,150 @@ +(module + (type $none_=>_none (func)) + (import "env" "trivial_i31ref" (global $gimport$0 i31ref)) + (global $global$0 (mut anyref) (ref.null any)) + (global $global$1 (mut eqref) (ref.null eq)) + (global $global$2 (mut i31ref) (global.get $gimport$0)) + (global $global$3 (mut anyref) (ref.null eq)) + (global $global$4 (mut anyref) (global.get $gimport$0)) + (global $global$5 (mut eqref) (global.get $gimport$0)) + (func $0 + (local $0 i32) + (local $1 anyref) + (local $2 eqref) + (local $3 i31ref) + (local.set $1 + (local.get $1) + ) + (local.set $1 + (global.get $global$0) + ) + (local.set $1 + (ref.null any) + ) + (local.set $2 + (local.get $2) + ) + (local.set $2 + (global.get $global$1) + ) + (local.set $2 + (ref.null eq) + ) + (local.set $3 + (local.get $3) + ) + (local.set $3 + (global.get $global$2) + ) + (local.set $3 + (global.get $gimport$0) + ) + (local.set $1 + (local.get $2) + ) + (local.set $1 + (global.get $global$1) + ) + (local.set $1 + (ref.null eq) + ) + (local.set $1 + (local.get $3) + ) + (local.set $1 + (global.get $global$2) + ) + (local.set $1 + (global.get $gimport$0) + ) + (local.set $2 + (local.get $3) + ) + (local.set $2 + (global.get $global$2) + ) + (local.set $2 + (global.get $gimport$0) + ) + (global.set $global$0 + (local.get $1) + ) + (global.set $global$0 + (global.get $global$0) + ) + (global.set $global$0 + (ref.null any) + ) + (global.set $global$1 + (local.get $2) + ) + (global.set $global$1 + (global.get $global$1) + ) + (global.set $global$1 + (ref.null eq) + ) + (global.set $global$2 + (local.get $3) + ) + (global.set $global$2 + (global.get $global$2) + ) + (global.set $global$2 + (global.get $gimport$0) + ) + (global.set $global$0 + (local.get $2) + ) + (global.set $global$0 + (global.get $global$1) + ) + (global.set $global$0 + (ref.null eq) + ) + (global.set $global$0 + (local.get $3) + ) + (global.set $global$0 + (global.get $global$2) + ) + (global.set $global$0 + (global.get $gimport$0) + ) + (global.set $global$1 + (local.get $3) + ) + (global.set $global$1 + (global.get $global$2) + ) + (global.set $global$1 + (global.get $gimport$0) + ) + (local.set $3 + (i31.new + (i32.const 0) + ) + ) + (local.set $1 + (i31.new + (i32.const 0) + ) + ) + (local.set $2 + (i31.new + (i32.const 0) + ) + ) + (local.set $0 + (i31.get_s + (local.get $3) + ) + ) + (local.set $0 + (i31.get_u + (local.get $3) + ) + ) + ) +) + |