mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-04 18:10:18 +00:00
Add more wasm spectests
This commit is contained in:
parent
b94049f949
commit
91bd5b27ba
26
examples/loop.wat
Normal file
26
examples/loop.wat
Normal file
@ -0,0 +1,26 @@
|
||||
(module
|
||||
;; dummy memory
|
||||
(memory 1)
|
||||
|
||||
;; Entry point
|
||||
(func $main (result i32)
|
||||
(local $total i32)
|
||||
(local $count i32)
|
||||
(set_local $count (i32.const 10)) ;; Giving $count an inital value of 10
|
||||
|
||||
;; Iteratively decrement $count and increment $total by 2
|
||||
(loop $loop
|
||||
(if (i32.eqz (get_local $count))
|
||||
(then)
|
||||
(else
|
||||
(set_local $count (i32.sub (get_local $count) (i32.const 1)))
|
||||
(set_local $total (i32.add (get_local $total) (i32.const 2)))
|
||||
(br $loop)
|
||||
)
|
||||
)
|
||||
)
|
||||
(get_local $total)
|
||||
)
|
||||
|
||||
(export "main" (func $main))
|
||||
)
|
23
examples/select.wat
Normal file
23
examples/select.wat
Normal file
@ -0,0 +1,23 @@
|
||||
(module
|
||||
(func $ternary (param $lhs i64) (param $rhs i64) (param $cond i32) (result i64)
|
||||
(select
|
||||
(get_local $lhs)
|
||||
(get_local $rhs)
|
||||
(get_local $cond)
|
||||
)
|
||||
)
|
||||
|
||||
(func $main (result i64)
|
||||
(call $ternary
|
||||
(i64.const 126)
|
||||
(call $ternary
|
||||
(i64.const 1024)
|
||||
(i64.const 4028)
|
||||
(i32.const 0)
|
||||
)
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
|
||||
(export "main" (func $main))
|
||||
)
|
217
spectests/endianness.wast
Normal file
217
spectests/endianness.wast
Normal file
@ -0,0 +1,217 @@
|
||||
(module
|
||||
(memory 1)
|
||||
|
||||
;; Stores an i16 value in little-endian-format
|
||||
(func $i16_store_little (param $address i32) (param $value i32)
|
||||
(i32.store8 (get_local $address) (get_local $value))
|
||||
(i32.store8 (i32.add (get_local $address) (i32.const 1)) (i32.shr_u (get_local $value) (i32.const 8)))
|
||||
)
|
||||
|
||||
;; Stores an i32 value in little-endian format
|
||||
(func $i32_store_little (param $address i32) (param $value i32)
|
||||
(call $i16_store_little (get_local $address) (get_local $value))
|
||||
(call $i16_store_little (i32.add (get_local $address) (i32.const 2)) (i32.shr_u (get_local $value) (i32.const 16)))
|
||||
)
|
||||
|
||||
;; Stores an i64 value in little-endian format
|
||||
(func $i64_store_little (param $address i32) (param $value i64)
|
||||
(call $i32_store_little (get_local $address) (i32.wrap/i64 (get_local $value)))
|
||||
(call $i32_store_little (i32.add (get_local $address) (i32.const 4)) (i32.wrap/i64 (i64.shr_u (get_local $value) (i64.const 32))))
|
||||
)
|
||||
|
||||
;; Loads an i16 value in little-endian format
|
||||
(func $i16_load_little (param $address i32) (result i32)
|
||||
(i32.or
|
||||
(i32.load8_u (get_local $address))
|
||||
(i32.shl (i32.load8_u (i32.add (get_local $address) (i32.const 1))) (i32.const 8))
|
||||
)
|
||||
)
|
||||
|
||||
;; Loads an i32 value in little-endian format
|
||||
(func $i32_load_little (param $address i32) (result i32)
|
||||
(i32.or
|
||||
(call $i16_load_little (get_local $address))
|
||||
(i32.shl (call $i16_load_little (i32.add (get_local $address) (i32.const 2))) (i32.const 16))
|
||||
)
|
||||
)
|
||||
|
||||
;; Loads an i64 value in little-endian format
|
||||
(func $i64_load_little (param $address i32) (result i64)
|
||||
(i64.or
|
||||
(i64.extend_u/i32 (call $i32_load_little (get_local $address)))
|
||||
(i64.shl (i64.extend_u/i32 (call $i32_load_little (i32.add (get_local $address) (i32.const 4)))) (i64.const 32))
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "i32_load16_s") (param $value i32) (result i32)
|
||||
(call $i16_store_little (i32.const 0) (get_local $value))
|
||||
(i32.load16_s (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i32_load16_u") (param $value i32) (result i32)
|
||||
(call $i16_store_little (i32.const 0) (get_local $value))
|
||||
(i32.load16_u (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i32_load") (param $value i32) (result i32)
|
||||
(call $i32_store_little (i32.const 0) (get_local $value))
|
||||
(i32.load (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i64_load16_s") (param $value i64) (result i64)
|
||||
(call $i16_store_little (i32.const 0) (i32.wrap/i64 (get_local $value)))
|
||||
(i64.load16_s (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i64_load16_u") (param $value i64) (result i64)
|
||||
(call $i16_store_little (i32.const 0) (i32.wrap/i64 (get_local $value)))
|
||||
(i64.load16_u (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i64_load32_s") (param $value i64) (result i64)
|
||||
(call $i32_store_little (i32.const 0) (i32.wrap/i64 (get_local $value)))
|
||||
(i64.load32_s (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i64_load32_u") (param $value i64) (result i64)
|
||||
(call $i32_store_little (i32.const 0) (i32.wrap/i64 (get_local $value)))
|
||||
(i64.load32_u (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i64_load") (param $value i64) (result i64)
|
||||
(call $i64_store_little (i32.const 0) (get_local $value))
|
||||
(i64.load (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "f32_load") (param $value f32) (result f32)
|
||||
(call $i32_store_little (i32.const 0) (i32.reinterpret/f32 (get_local $value)))
|
||||
(f32.load (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "f64_load") (param $value f64) (result f64)
|
||||
(call $i64_store_little (i32.const 0) (i64.reinterpret/f64 (get_local $value)))
|
||||
(f64.load (i32.const 0))
|
||||
)
|
||||
|
||||
|
||||
(func (export "i32_store16") (param $value i32) (result i32)
|
||||
(i32.store16 (i32.const 0) (get_local $value))
|
||||
(call $i16_load_little (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i32_store") (param $value i32) (result i32)
|
||||
(i32.store (i32.const 0) (get_local $value))
|
||||
(call $i32_load_little (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "i64_store16") (param $value i64) (result i64)
|
||||
(i64.store16 (i32.const 0) (get_local $value))
|
||||
(i64.extend_u/i32 (call $i16_load_little (i32.const 0)))
|
||||
)
|
||||
|
||||
(func (export "i64_store32") (param $value i64) (result i64)
|
||||
(i64.store32 (i32.const 0) (get_local $value))
|
||||
(i64.extend_u/i32 (call $i32_load_little (i32.const 0)))
|
||||
)
|
||||
|
||||
(func (export "i64_store") (param $value i64) (result i64)
|
||||
(i64.store (i32.const 0) (get_local $value))
|
||||
(call $i64_load_little (i32.const 0))
|
||||
)
|
||||
|
||||
(func (export "f32_store") (param $value f32) (result f32)
|
||||
(f32.store (i32.const 0) (get_local $value))
|
||||
(f32.reinterpret/i32 (call $i32_load_little (i32.const 0)))
|
||||
)
|
||||
|
||||
(func (export "f64_store") (param $value f64) (result f64)
|
||||
(f64.store (i32.const 0) (get_local $value))
|
||||
(f64.reinterpret/i64 (call $i64_load_little (i32.const 0)))
|
||||
)
|
||||
)
|
||||
|
||||
(assert_return (invoke "i32_load16_s" (i32.const -1)) (i32.const -1))
|
||||
(assert_return (invoke "i32_load16_s" (i32.const -4242)) (i32.const -4242))
|
||||
(assert_return (invoke "i32_load16_s" (i32.const 42)) (i32.const 42))
|
||||
(assert_return (invoke "i32_load16_s" (i32.const 0x3210)) (i32.const 0x3210))
|
||||
|
||||
(assert_return (invoke "i32_load16_u" (i32.const -1)) (i32.const 0xFFFF))
|
||||
(assert_return (invoke "i32_load16_u" (i32.const -4242)) (i32.const 61294))
|
||||
(assert_return (invoke "i32_load16_u" (i32.const 42)) (i32.const 42))
|
||||
(assert_return (invoke "i32_load16_u" (i32.const 0xCAFE)) (i32.const 0xCAFE))
|
||||
|
||||
(assert_return (invoke "i32_load" (i32.const -1)) (i32.const -1))
|
||||
(assert_return (invoke "i32_load" (i32.const -42424242)) (i32.const -42424242))
|
||||
(assert_return (invoke "i32_load" (i32.const 42424242)) (i32.const 42424242))
|
||||
(assert_return (invoke "i32_load" (i32.const 0xABAD1DEA)) (i32.const 0xABAD1DEA))
|
||||
|
||||
(assert_return (invoke "i64_load16_s" (i64.const -1)) (i64.const -1))
|
||||
(assert_return (invoke "i64_load16_s" (i64.const -4242)) (i64.const -4242))
|
||||
(assert_return (invoke "i64_load16_s" (i64.const 42)) (i64.const 42))
|
||||
(assert_return (invoke "i64_load16_s" (i64.const 0x3210)) (i64.const 0x3210))
|
||||
|
||||
(assert_return (invoke "i64_load16_u" (i64.const -1)) (i64.const 0xFFFF))
|
||||
(assert_return (invoke "i64_load16_u" (i64.const -4242)) (i64.const 61294))
|
||||
(assert_return (invoke "i64_load16_u" (i64.const 42)) (i64.const 42))
|
||||
(assert_return (invoke "i64_load16_u" (i64.const 0xCAFE)) (i64.const 0xCAFE))
|
||||
|
||||
(assert_return (invoke "i64_load32_s" (i64.const -1)) (i64.const -1))
|
||||
(assert_return (invoke "i64_load32_s" (i64.const -42424242)) (i64.const -42424242))
|
||||
(assert_return (invoke "i64_load32_s" (i64.const 42424242)) (i64.const 42424242))
|
||||
(assert_return (invoke "i64_load32_s" (i64.const 0x12345678)) (i64.const 0x12345678))
|
||||
|
||||
(assert_return (invoke "i64_load32_u" (i64.const -1)) (i64.const 0xFFFFFFFF))
|
||||
(assert_return (invoke "i64_load32_u" (i64.const -42424242)) (i64.const 4252543054))
|
||||
(assert_return (invoke "i64_load32_u" (i64.const 42424242)) (i64.const 42424242))
|
||||
(assert_return (invoke "i64_load32_u" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
|
||||
|
||||
(assert_return (invoke "i64_load" (i64.const -1)) (i64.const -1))
|
||||
(assert_return (invoke "i64_load" (i64.const -42424242)) (i64.const -42424242))
|
||||
(assert_return (invoke "i64_load" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
|
||||
(assert_return (invoke "i64_load" (i64.const 0xABADCAFEDEAD1DEA)) (i64.const 0xABADCAFEDEAD1DEA))
|
||||
|
||||
(assert_return (invoke "f32_load" (f32.const -1)) (f32.const -1))
|
||||
(assert_return (invoke "f32_load" (f32.const 1234e-5)) (f32.const 1234e-5))
|
||||
(assert_return (invoke "f32_load" (f32.const 4242.4242)) (f32.const 4242.4242))
|
||||
(assert_return (invoke "f32_load" (f32.const 0x1.fffffep+127)) (f32.const 0x1.fffffep+127))
|
||||
|
||||
(assert_return (invoke "f64_load" (f64.const -1)) (f64.const -1))
|
||||
(assert_return (invoke "f64_load" (f64.const 123456789e-5)) (f64.const 123456789e-5))
|
||||
(assert_return (invoke "f64_load" (f64.const 424242.424242)) (f64.const 424242.424242))
|
||||
(assert_return (invoke "f64_load" (f64.const 0x1.fffffffffffffp+1023)) (f64.const 0x1.fffffffffffffp+1023))
|
||||
|
||||
|
||||
(assert_return (invoke "i32_store16" (i32.const -1)) (i32.const 0xFFFF))
|
||||
(assert_return (invoke "i32_store16" (i32.const -4242)) (i32.const 61294))
|
||||
(assert_return (invoke "i32_store16" (i32.const 42)) (i32.const 42))
|
||||
(assert_return (invoke "i32_store16" (i32.const 0xCAFE)) (i32.const 0xCAFE))
|
||||
|
||||
(assert_return (invoke "i32_store" (i32.const -1)) (i32.const -1))
|
||||
(assert_return (invoke "i32_store" (i32.const -4242)) (i32.const -4242))
|
||||
(assert_return (invoke "i32_store" (i32.const 42424242)) (i32.const 42424242))
|
||||
(assert_return (invoke "i32_store" (i32.const 0xDEADCAFE)) (i32.const 0xDEADCAFE))
|
||||
|
||||
(assert_return (invoke "i64_store16" (i64.const -1)) (i64.const 0xFFFF))
|
||||
(assert_return (invoke "i64_store16" (i64.const -4242)) (i64.const 61294))
|
||||
(assert_return (invoke "i64_store16" (i64.const 42)) (i64.const 42))
|
||||
(assert_return (invoke "i64_store16" (i64.const 0xCAFE)) (i64.const 0xCAFE))
|
||||
|
||||
(assert_return (invoke "i64_store32" (i64.const -1)) (i64.const 0xFFFFFFFF))
|
||||
(assert_return (invoke "i64_store32" (i64.const -4242)) (i64.const 4294963054))
|
||||
(assert_return (invoke "i64_store32" (i64.const 42424242)) (i64.const 42424242))
|
||||
(assert_return (invoke "i64_store32" (i64.const 0xDEADCAFE)) (i64.const 0xDEADCAFE))
|
||||
|
||||
(assert_return (invoke "i64_store" (i64.const -1)) (i64.const -1))
|
||||
(assert_return (invoke "i64_store" (i64.const -42424242)) (i64.const -42424242))
|
||||
(assert_return (invoke "i64_store" (i64.const 0xABAD1DEA)) (i64.const 0xABAD1DEA))
|
||||
(assert_return (invoke "i64_store" (i64.const 0xABADCAFEDEAD1DEA)) (i64.const 0xABADCAFEDEAD1DEA))
|
||||
|
||||
(assert_return (invoke "f32_store" (f32.const -1)) (f32.const -1))
|
||||
(assert_return (invoke "f32_store" (f32.const 1234e-5)) (f32.const 1234e-5))
|
||||
(assert_return (invoke "f32_store" (f32.const 4242.4242)) (f32.const 4242.4242))
|
||||
(assert_return (invoke "f32_store" (f32.const 0x1.fffffep+127)) (f32.const 0x1.fffffep+127))
|
||||
|
||||
(assert_return (invoke "f64_store" (f64.const -1)) (f64.const -1))
|
||||
(assert_return (invoke "f64_store" (f64.const 123456789e-5)) (f64.const 123456789e-5))
|
||||
(assert_return (invoke "f64_store" (f64.const 424242.424242)) (f64.const 424242.424242))
|
||||
(assert_return (invoke "f64_store" (f64.const 0x1.fffffffffffffp+1023)) (f64.const 0x1.fffffffffffffp+1023))
|
507
spectests/float_literals.wast
Normal file
507
spectests/float_literals.wast
Normal file
@ -0,0 +1,507 @@
|
||||
;; Test floating-point literal parsing.
|
||||
|
||||
(module
|
||||
;; f32 special values
|
||||
(func (export "f32.nan") (result i32) (i32.reinterpret/f32 (f32.const nan)))
|
||||
(func (export "f32.positive_nan") (result i32) (i32.reinterpret/f32 (f32.const +nan)))
|
||||
(func (export "f32.negative_nan") (result i32) (i32.reinterpret/f32 (f32.const -nan)))
|
||||
(func (export "f32.plain_nan") (result i32) (i32.reinterpret/f32 (f32.const nan:0x400000)))
|
||||
(func (export "f32.informally_known_as_plain_snan") (result i32) (i32.reinterpret/f32 (f32.const nan:0x200000)))
|
||||
(func (export "f32.all_ones_nan") (result i32) (i32.reinterpret/f32 (f32.const -nan:0x7fffff)))
|
||||
(func (export "f32.misc_nan") (result i32) (i32.reinterpret/f32 (f32.const nan:0x012345)))
|
||||
(func (export "f32.misc_positive_nan") (result i32) (i32.reinterpret/f32 (f32.const +nan:0x304050)))
|
||||
(func (export "f32.misc_negative_nan") (result i32) (i32.reinterpret/f32 (f32.const -nan:0x2abcde)))
|
||||
(func (export "f32.infinity") (result i32) (i32.reinterpret/f32 (f32.const inf)))
|
||||
(func (export "f32.positive_infinity") (result i32) (i32.reinterpret/f32 (f32.const +inf)))
|
||||
(func (export "f32.negative_infinity") (result i32) (i32.reinterpret/f32 (f32.const -inf)))
|
||||
|
||||
;; f32 numbers
|
||||
(func (export "f32.zero") (result i32) (i32.reinterpret/f32 (f32.const 0x0.0p0)))
|
||||
(func (export "f32.positive_zero") (result i32) (i32.reinterpret/f32 (f32.const +0x0.0p0)))
|
||||
(func (export "f32.negative_zero") (result i32) (i32.reinterpret/f32 (f32.const -0x0.0p0)))
|
||||
(func (export "f32.misc") (result i32) (i32.reinterpret/f32 (f32.const 0x1.921fb6p+2)))
|
||||
(func (export "f32.min_positive") (result i32) (i32.reinterpret/f32 (f32.const 0x1p-149)))
|
||||
(func (export "f32.min_normal") (result i32) (i32.reinterpret/f32 (f32.const 0x1p-126)))
|
||||
(func (export "f32.max_finite") (result i32) (i32.reinterpret/f32 (f32.const 0x1.fffffep+127)))
|
||||
(func (export "f32.max_subnormal") (result i32) (i32.reinterpret/f32 (f32.const 0x1.fffffcp-127)))
|
||||
(func (export "f32.trailing_dot") (result i32) (i32.reinterpret/f32 (f32.const 0x1.p10)))
|
||||
|
||||
;; f32 in decimal format
|
||||
(func (export "f32_dec.zero") (result i32) (i32.reinterpret/f32 (f32.const 0.0e0)))
|
||||
(func (export "f32_dec.positive_zero") (result i32) (i32.reinterpret/f32 (f32.const +0.0e0)))
|
||||
(func (export "f32_dec.negative_zero") (result i32) (i32.reinterpret/f32 (f32.const -0.0e0)))
|
||||
(func (export "f32_dec.misc") (result i32) (i32.reinterpret/f32 (f32.const 6.28318548202514648)))
|
||||
(func (export "f32_dec.min_positive") (result i32) (i32.reinterpret/f32 (f32.const 1.4013e-45)))
|
||||
(func (export "f32_dec.min_normal") (result i32) (i32.reinterpret/f32 (f32.const 1.1754944e-38)))
|
||||
(func (export "f32_dec.max_subnormal") (result i32) (i32.reinterpret/f32 (f32.const 1.1754942e-38)))
|
||||
(func (export "f32_dec.max_finite") (result i32) (i32.reinterpret/f32 (f32.const 3.4028234e+38)))
|
||||
(func (export "f32_dec.trailing_dot") (result i32) (i32.reinterpret/f32 (f32.const 1.e10)))
|
||||
|
||||
;; https://twitter.com/Archivd/status/994637336506912768
|
||||
(func (export "f32_dec.root_beer_float") (result i32) (i32.reinterpret/f32 (f32.const 1.000000119)))
|
||||
|
||||
;; f64 special values
|
||||
(func (export "f64.nan") (result i64) (i64.reinterpret/f64 (f64.const nan)))
|
||||
(func (export "f64.positive_nan") (result i64) (i64.reinterpret/f64 (f64.const +nan)))
|
||||
(func (export "f64.negative_nan") (result i64) (i64.reinterpret/f64 (f64.const -nan)))
|
||||
(func (export "f64.plain_nan") (result i64) (i64.reinterpret/f64 (f64.const nan:0x8000000000000)))
|
||||
(func (export "f64.informally_known_as_plain_snan") (result i64) (i64.reinterpret/f64 (f64.const nan:0x4000000000000)))
|
||||
(func (export "f64.all_ones_nan") (result i64) (i64.reinterpret/f64 (f64.const -nan:0xfffffffffffff)))
|
||||
(func (export "f64.misc_nan") (result i64) (i64.reinterpret/f64 (f64.const nan:0x0123456789abc)))
|
||||
(func (export "f64.misc_positive_nan") (result i64) (i64.reinterpret/f64 (f64.const +nan:0x3040506070809)))
|
||||
(func (export "f64.misc_negative_nan") (result i64) (i64.reinterpret/f64 (f64.const -nan:0x2abcdef012345)))
|
||||
(func (export "f64.infinity") (result i64) (i64.reinterpret/f64 (f64.const inf)))
|
||||
(func (export "f64.positive_infinity") (result i64) (i64.reinterpret/f64 (f64.const +inf)))
|
||||
(func (export "f64.negative_infinity") (result i64) (i64.reinterpret/f64 (f64.const -inf)))
|
||||
|
||||
;; f64 numbers
|
||||
(func (export "f64.zero") (result i64) (i64.reinterpret/f64 (f64.const 0x0.0p0)))
|
||||
(func (export "f64.positive_zero") (result i64) (i64.reinterpret/f64 (f64.const +0x0.0p0)))
|
||||
(func (export "f64.negative_zero") (result i64) (i64.reinterpret/f64 (f64.const -0x0.0p0)))
|
||||
(func (export "f64.misc") (result i64) (i64.reinterpret/f64 (f64.const 0x1.921fb54442d18p+2)))
|
||||
(func (export "f64.min_positive") (result i64) (i64.reinterpret/f64 (f64.const 0x0.0000000000001p-1022)))
|
||||
(func (export "f64.min_normal") (result i64) (i64.reinterpret/f64 (f64.const 0x1p-1022)))
|
||||
(func (export "f64.max_subnormal") (result i64) (i64.reinterpret/f64 (f64.const 0x0.fffffffffffffp-1022)))
|
||||
(func (export "f64.max_finite") (result i64) (i64.reinterpret/f64 (f64.const 0x1.fffffffffffffp+1023)))
|
||||
(func (export "f64.trailing_dot") (result i64) (i64.reinterpret/f64 (f64.const 0x1.p100)))
|
||||
|
||||
;; f64 numbers in decimal format
|
||||
(func (export "f64_dec.zero") (result i64) (i64.reinterpret/f64 (f64.const 0.0e0)))
|
||||
(func (export "f64_dec.positive_zero") (result i64) (i64.reinterpret/f64 (f64.const +0.0e0)))
|
||||
(func (export "f64_dec.negative_zero") (result i64) (i64.reinterpret/f64 (f64.const -0.0e0)))
|
||||
(func (export "f64_dec.misc") (result i64) (i64.reinterpret/f64 (f64.const 6.28318530717958623)))
|
||||
(func (export "f64_dec.min_positive") (result i64) (i64.reinterpret/f64 (f64.const 4.94066e-324)))
|
||||
(func (export "f64_dec.min_normal") (result i64) (i64.reinterpret/f64 (f64.const 2.2250738585072012e-308)))
|
||||
(func (export "f64_dec.max_subnormal") (result i64) (i64.reinterpret/f64 (f64.const 2.2250738585072011e-308)))
|
||||
(func (export "f64_dec.max_finite") (result i64) (i64.reinterpret/f64 (f64.const 1.7976931348623157e+308)))
|
||||
(func (export "f64_dec.trailing_dot") (result i64) (i64.reinterpret/f64 (f64.const 1.e100)))
|
||||
|
||||
;; https://twitter.com/Archivd/status/994637336506912768
|
||||
(func (export "f64_dec.root_beer_float") (result i64) (i64.reinterpret/f64 (f64.const 1.000000119)))
|
||||
|
||||
(func (export "f32-dec-sep1") (result f32) (f32.const 1_000_000))
|
||||
(func (export "f32-dec-sep2") (result f32) (f32.const 1_0_0_0))
|
||||
(func (export "f32-dec-sep3") (result f32) (f32.const 100_3.141_592))
|
||||
(func (export "f32-dec-sep4") (result f32) (f32.const 99e+1_3))
|
||||
(func (export "f32-dec-sep5") (result f32) (f32.const 122_000.11_3_54E0_2_3))
|
||||
(func (export "f32-hex-sep1") (result f32) (f32.const 0xa_0f_00_99))
|
||||
(func (export "f32-hex-sep2") (result f32) (f32.const 0x1_a_A_0_f))
|
||||
(func (export "f32-hex-sep3") (result f32) (f32.const 0xa0_ff.f141_a59a))
|
||||
(func (export "f32-hex-sep4") (result f32) (f32.const 0xf0P+1_3))
|
||||
(func (export "f32-hex-sep5") (result f32) (f32.const 0x2a_f00a.1f_3_eep2_3))
|
||||
|
||||
(func (export "f64-dec-sep1") (result f64) (f64.const 1_000_000))
|
||||
(func (export "f64-dec-sep2") (result f64) (f64.const 1_0_0_0))
|
||||
(func (export "f64-dec-sep3") (result f64) (f64.const 100_3.141_592))
|
||||
(func (export "f64-dec-sep4") (result f64) (f64.const 99e-1_23))
|
||||
(func (export "f64-dec-sep5") (result f64) (f64.const 122_000.11_3_54e0_2_3))
|
||||
(func (export "f64-hex-sep1") (result f64) (f64.const 0xa_f00f_0000_9999))
|
||||
(func (export "f64-hex-sep2") (result f64) (f64.const 0x1_a_A_0_f))
|
||||
(func (export "f64-hex-sep3") (result f64) (f64.const 0xa0_ff.f141_a59a))
|
||||
(func (export "f64-hex-sep4") (result f64) (f64.const 0xf0P+1_3))
|
||||
(func (export "f64-hex-sep5") (result f64) (f64.const 0x2a_f00a.1f_3_eep2_3))
|
||||
)
|
||||
|
||||
(assert_return (invoke "f32.nan") (i32.const 0x7fc00000))
|
||||
(assert_return (invoke "f32.positive_nan") (i32.const 0x7fc00000))
|
||||
(assert_return (invoke "f32.negative_nan") (i32.const 0xffc00000))
|
||||
(assert_return (invoke "f32.plain_nan") (i32.const 0x7fc00000))
|
||||
(assert_return (invoke "f32.informally_known_as_plain_snan") (i32.const 0x7fa00000))
|
||||
(assert_return (invoke "f32.all_ones_nan") (i32.const 0xffffffff))
|
||||
(assert_return (invoke "f32.misc_nan") (i32.const 0x7f812345))
|
||||
(assert_return (invoke "f32.misc_positive_nan") (i32.const 0x7fb04050))
|
||||
(assert_return (invoke "f32.misc_negative_nan") (i32.const 0xffaabcde))
|
||||
(assert_return (invoke "f32.infinity") (i32.const 0x7f800000))
|
||||
(assert_return (invoke "f32.positive_infinity") (i32.const 0x7f800000))
|
||||
(assert_return (invoke "f32.negative_infinity") (i32.const 0xff800000))
|
||||
(assert_return (invoke "f32.zero") (i32.const 0))
|
||||
(assert_return (invoke "f32.positive_zero") (i32.const 0))
|
||||
(assert_return (invoke "f32.negative_zero") (i32.const 0x80000000))
|
||||
(assert_return (invoke "f32.misc") (i32.const 0x40c90fdb))
|
||||
(assert_return (invoke "f32.min_positive") (i32.const 1))
|
||||
(assert_return (invoke "f32.min_normal") (i32.const 0x800000))
|
||||
(assert_return (invoke "f32.max_subnormal") (i32.const 0x7fffff))
|
||||
(assert_return (invoke "f32.max_finite") (i32.const 0x7f7fffff))
|
||||
(assert_return (invoke "f32.trailing_dot") (i32.const 0x44800000))
|
||||
(assert_return (invoke "f32_dec.zero") (i32.const 0))
|
||||
(assert_return (invoke "f32_dec.positive_zero") (i32.const 0))
|
||||
(assert_return (invoke "f32_dec.negative_zero") (i32.const 0x80000000))
|
||||
(assert_return (invoke "f32_dec.misc") (i32.const 0x40c90fdb))
|
||||
(assert_return (invoke "f32_dec.min_positive") (i32.const 1))
|
||||
(assert_return (invoke "f32_dec.min_normal") (i32.const 0x800000))
|
||||
(assert_return (invoke "f32_dec.max_subnormal") (i32.const 0x7fffff))
|
||||
(assert_return (invoke "f32_dec.max_finite") (i32.const 0x7f7fffff))
|
||||
(assert_return (invoke "f32_dec.trailing_dot") (i32.const 0x501502f9))
|
||||
(assert_return (invoke "f32_dec.root_beer_float") (i32.const 0x3f800001))
|
||||
|
||||
(assert_return (invoke "f64.nan") (i64.const 0x7ff8000000000000))
|
||||
(assert_return (invoke "f64.positive_nan") (i64.const 0x7ff8000000000000))
|
||||
(assert_return (invoke "f64.negative_nan") (i64.const 0xfff8000000000000))
|
||||
(assert_return (invoke "f64.plain_nan") (i64.const 0x7ff8000000000000))
|
||||
(assert_return (invoke "f64.informally_known_as_plain_snan") (i64.const 0x7ff4000000000000))
|
||||
(assert_return (invoke "f64.all_ones_nan") (i64.const 0xffffffffffffffff))
|
||||
(assert_return (invoke "f64.misc_nan") (i64.const 0x7ff0123456789abc))
|
||||
(assert_return (invoke "f64.misc_positive_nan") (i64.const 0x7ff3040506070809))
|
||||
(assert_return (invoke "f64.misc_negative_nan") (i64.const 0xfff2abcdef012345))
|
||||
(assert_return (invoke "f64.infinity") (i64.const 0x7ff0000000000000))
|
||||
(assert_return (invoke "f64.positive_infinity") (i64.const 0x7ff0000000000000))
|
||||
(assert_return (invoke "f64.negative_infinity") (i64.const 0xfff0000000000000))
|
||||
(assert_return (invoke "f64.zero") (i64.const 0))
|
||||
(assert_return (invoke "f64.positive_zero") (i64.const 0))
|
||||
(assert_return (invoke "f64.negative_zero") (i64.const 0x8000000000000000))
|
||||
(assert_return (invoke "f64.misc") (i64.const 0x401921fb54442d18))
|
||||
(assert_return (invoke "f64.min_positive") (i64.const 1))
|
||||
(assert_return (invoke "f64.min_normal") (i64.const 0x10000000000000))
|
||||
(assert_return (invoke "f64.max_subnormal") (i64.const 0xfffffffffffff))
|
||||
(assert_return (invoke "f64.max_finite") (i64.const 0x7fefffffffffffff))
|
||||
(assert_return (invoke "f64.trailing_dot") (i64.const 0x4630000000000000))
|
||||
(assert_return (invoke "f64_dec.zero") (i64.const 0))
|
||||
(assert_return (invoke "f64_dec.positive_zero") (i64.const 0))
|
||||
(assert_return (invoke "f64_dec.negative_zero") (i64.const 0x8000000000000000))
|
||||
(assert_return (invoke "f64_dec.misc") (i64.const 0x401921fb54442d18))
|
||||
(assert_return (invoke "f64_dec.min_positive") (i64.const 1))
|
||||
(assert_return (invoke "f64_dec.min_normal") (i64.const 0x10000000000000))
|
||||
(assert_return (invoke "f64_dec.max_subnormal") (i64.const 0xfffffffffffff))
|
||||
(assert_return (invoke "f64_dec.max_finite") (i64.const 0x7fefffffffffffff))
|
||||
(assert_return (invoke "f64_dec.trailing_dot") (i64.const 0x54b249ad2594c37d))
|
||||
(assert_return (invoke "f64_dec.root_beer_float") (i64.const 0x3ff000001ff19e24))
|
||||
|
||||
(assert_return (invoke "f32-dec-sep1") (f32.const 1000000))
|
||||
(assert_return (invoke "f32-dec-sep2") (f32.const 1000))
|
||||
(assert_return (invoke "f32-dec-sep3") (f32.const 1003.141592))
|
||||
(assert_return (invoke "f32-dec-sep4") (f32.const 99e+13))
|
||||
(assert_return (invoke "f32-dec-sep5") (f32.const 122000.11354e23))
|
||||
(assert_return (invoke "f32-hex-sep1") (f32.const 0xa0f0099))
|
||||
(assert_return (invoke "f32-hex-sep2") (f32.const 0x1aa0f))
|
||||
(assert_return (invoke "f32-hex-sep3") (f32.const 0xa0ff.f141a59a))
|
||||
(assert_return (invoke "f32-hex-sep4") (f32.const 0xf0P+13))
|
||||
(assert_return (invoke "f32-hex-sep5") (f32.const 0x2af00a.1f3eep23))
|
||||
|
||||
(assert_return (invoke "f64-dec-sep1") (f64.const 1000000))
|
||||
(assert_return (invoke "f64-dec-sep2") (f64.const 1000))
|
||||
(assert_return (invoke "f64-dec-sep3") (f64.const 1003.141592))
|
||||
(assert_return (invoke "f64-dec-sep4") (f64.const 99e-123))
|
||||
(assert_return (invoke "f64-dec-sep5") (f64.const 122000.11354e23))
|
||||
(assert_return (invoke "f64-hex-sep1") (f64.const 0xaf00f00009999))
|
||||
(assert_return (invoke "f64-hex-sep2") (f64.const 0x1aa0f))
|
||||
(assert_return (invoke "f64-hex-sep3") (f64.const 0xa0ff.f141a59a))
|
||||
(assert_return (invoke "f64-hex-sep4") (f64.const 0xf0P+13))
|
||||
(assert_return (invoke "f64-hex-sep5") (f64.const 0x2af00a.1f3eep23))
|
||||
|
||||
;; Test parsing a float from binary
|
||||
(module binary
|
||||
;; (func (export "4294967249") (result f64) (f64.const 4294967249))
|
||||
"\00\61\73\6d\01\00\00\00\01\85\80\80\80\00\01\60"
|
||||
"\00\01\7c\03\82\80\80\80\00\01\00\07\8e\80\80\80"
|
||||
"\00\01\0a\34\32\39\34\39\36\37\32\34\39\00\00\0a"
|
||||
"\91\80\80\80\00\01\8b\80\80\80\00\00\44\00\00\20"
|
||||
"\fa\ff\ff\ef\41\0b"
|
||||
)
|
||||
|
||||
(assert_return (invoke "4294967249") (f64.const 4294967249))
|
||||
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const _100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const +_100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const -_100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 99_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1__000))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const _1.0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1.0_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1_.0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1._0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const _1e1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1e1_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1_e1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1e_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const _1.0e1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1.0e1_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1.0_e1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1.0e_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1.0e+_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 1.0e_+1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const _0x100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0_x100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x_100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x00_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0xff__ffff))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x_1.0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1.0_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1_.0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1._0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x_1p1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1p1_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1_p1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1p_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x_1.0p1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1.0p1_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1.0_p1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1.0p_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1.0p+_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f32 (f32.const 0x1.0p_+1))")
|
||||
"unknown operator"
|
||||
)
|
||||
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const _100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const +_100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const -_100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 99_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1__000))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const _1.0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1.0_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1_.0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1._0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const _1e1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1e1_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1_e1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1e_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const _1.0e1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1.0e1_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1.0_e1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1.0e_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1.0e+_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 1.0e_+1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const _0x100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0_x100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x_100))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x00_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0xff__ffff))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x_1.0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1.0_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1_.0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1._0))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x_1p1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1p1_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1_p1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1p_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x_1.0p1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1.0p1_))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1.0_p1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1.0p_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1.0p+_1))")
|
||||
"unknown operator"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(global f64 (f64.const 0x1.0p_+1))")
|
||||
"unknown operator"
|
||||
)
|
312
spectests/return_.wast
Normal file
312
spectests/return_.wast
Normal file
@ -0,0 +1,312 @@
|
||||
;; Test `return` operator
|
||||
|
||||
(module
|
||||
;; Auxiliary definition
|
||||
(func $dummy)
|
||||
|
||||
(func (export "type-i32") (drop (i32.ctz (return))))
|
||||
(func (export "type-i64") (drop (i64.ctz (return))))
|
||||
(func (export "type-f32") (drop (f32.neg (return))))
|
||||
(func (export "type-f64") (drop (f64.neg (return))))
|
||||
|
||||
(func (export "type-i32-value") (result i32)
|
||||
(block (result i32) (i32.ctz (return (i32.const 1))))
|
||||
)
|
||||
(func (export "type-i64-value") (result i64)
|
||||
(block (result i64) (i64.ctz (return (i64.const 2))))
|
||||
)
|
||||
(func (export "type-f32-value") (result f32)
|
||||
(block (result f32) (f32.neg (return (f32.const 3))))
|
||||
)
|
||||
(func (export "type-f64-value") (result f64)
|
||||
(block (result f64) (f64.neg (return (f64.const 4))))
|
||||
)
|
||||
|
||||
(func (export "nullary") (return))
|
||||
(func (export "unary") (result f64) (return (f64.const 3)))
|
||||
|
||||
(func (export "as-func-first") (result i32)
|
||||
(return (i32.const 1)) (i32.const 2)
|
||||
)
|
||||
(func (export "as-func-mid") (result i32)
|
||||
(call $dummy) (return (i32.const 2)) (i32.const 3)
|
||||
)
|
||||
(func (export "as-func-last")
|
||||
(nop) (call $dummy) (return)
|
||||
)
|
||||
(func (export "as-func-value") (result i32)
|
||||
(nop) (call $dummy) (return (i32.const 3))
|
||||
)
|
||||
|
||||
(func (export "as-block-first")
|
||||
(block (return) (call $dummy))
|
||||
)
|
||||
(func (export "as-block-mid")
|
||||
(block (call $dummy) (return) (call $dummy))
|
||||
)
|
||||
(func (export "as-block-last")
|
||||
(block (nop) (call $dummy) (return))
|
||||
)
|
||||
(func (export "as-block-value") (result i32)
|
||||
(block (result i32) (nop) (call $dummy) (return (i32.const 2)))
|
||||
)
|
||||
|
||||
(func (export "as-loop-first") (result i32)
|
||||
(loop (result i32) (return (i32.const 3)) (i32.const 2))
|
||||
)
|
||||
(func (export "as-loop-mid") (result i32)
|
||||
(loop (result i32) (call $dummy) (return (i32.const 4)) (i32.const 2))
|
||||
)
|
||||
(func (export "as-loop-last") (result i32)
|
||||
(loop (result i32) (nop) (call $dummy) (return (i32.const 5)))
|
||||
)
|
||||
|
||||
(func (export "as-br-value") (result i32)
|
||||
(block (result i32) (br 0 (return (i32.const 9))))
|
||||
)
|
||||
|
||||
(func (export "as-br_if-cond")
|
||||
(block (br_if 0 (return)))
|
||||
)
|
||||
(func (export "as-br_if-value") (result i32)
|
||||
(block (result i32)
|
||||
(drop (br_if 0 (return (i32.const 8)) (i32.const 1))) (i32.const 7)
|
||||
)
|
||||
)
|
||||
(func (export "as-br_if-value-cond") (result i32)
|
||||
(block (result i32)
|
||||
(drop (br_if 0 (i32.const 6) (return (i32.const 9)))) (i32.const 7)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-br_table-index") (result i64)
|
||||
(block (br_table 0 0 0 (return (i64.const 9)))) (i64.const -1)
|
||||
)
|
||||
(func (export "as-br_table-value") (result i32)
|
||||
(block (result i32)
|
||||
(br_table 0 0 0 (return (i32.const 10)) (i32.const 1)) (i32.const 7)
|
||||
)
|
||||
)
|
||||
(func (export "as-br_table-value-index") (result i32)
|
||||
(block (result i32)
|
||||
(br_table 0 0 (i32.const 6) (return (i32.const 11))) (i32.const 7)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-return-value") (result i64)
|
||||
(return (return (i64.const 7)))
|
||||
)
|
||||
|
||||
(func (export "as-if-cond") (result i32)
|
||||
(if (result i32)
|
||||
(return (i32.const 2)) (then (i32.const 0)) (else (i32.const 1))
|
||||
)
|
||||
)
|
||||
(func (export "as-if-then") (param i32 i32) (result i32)
|
||||
(if (result i32)
|
||||
(get_local 0) (then (return (i32.const 3))) (else (get_local 1))
|
||||
)
|
||||
)
|
||||
(func (export "as-if-else") (param i32 i32) (result i32)
|
||||
(if (result i32)
|
||||
(get_local 0) (then (get_local 1)) (else (return (i32.const 4)))
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-select-first") (param i32 i32) (result i32)
|
||||
(select (return (i32.const 5)) (get_local 0) (get_local 1))
|
||||
)
|
||||
(func (export "as-select-second") (param i32 i32) (result i32)
|
||||
(select (get_local 0) (return (i32.const 6)) (get_local 1))
|
||||
)
|
||||
(func (export "as-select-cond") (result i32)
|
||||
(select (i32.const 0) (i32.const 1) (return (i32.const 7)))
|
||||
)
|
||||
|
||||
(func $f (param i32 i32 i32) (result i32) (i32.const -1))
|
||||
(func (export "as-call-first") (result i32)
|
||||
(call $f (return (i32.const 12)) (i32.const 2) (i32.const 3))
|
||||
)
|
||||
(func (export "as-call-mid") (result i32)
|
||||
(call $f (i32.const 1) (return (i32.const 13)) (i32.const 3))
|
||||
)
|
||||
(func (export "as-call-last") (result i32)
|
||||
(call $f (i32.const 1) (i32.const 2) (return (i32.const 14)))
|
||||
)
|
||||
|
||||
(type $sig (func (param i32 i32 i32) (result i32)))
|
||||
(table anyfunc (elem $f))
|
||||
(func (export "as-call_indirect-func") (result i32)
|
||||
(call_indirect (type $sig)
|
||||
(return (i32.const 20)) (i32.const 1) (i32.const 2) (i32.const 3)
|
||||
)
|
||||
)
|
||||
(func (export "as-call_indirect-first") (result i32)
|
||||
(call_indirect (type $sig)
|
||||
(i32.const 0) (return (i32.const 21)) (i32.const 2) (i32.const 3)
|
||||
)
|
||||
)
|
||||
(func (export "as-call_indirect-mid") (result i32)
|
||||
(call_indirect (type $sig)
|
||||
(i32.const 0) (i32.const 1) (return (i32.const 22)) (i32.const 3)
|
||||
)
|
||||
)
|
||||
(func (export "as-call_indirect-last") (result i32)
|
||||
(call_indirect (type $sig)
|
||||
(i32.const 0) (i32.const 1) (i32.const 2) (return (i32.const 23))
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-set_local-value") (result i32) (local f32)
|
||||
(set_local 0 (return (i32.const 17))) (i32.const -1)
|
||||
)
|
||||
|
||||
(memory 1)
|
||||
(func (export "as-load-address") (result f32)
|
||||
(f32.load (return (f32.const 1.7)))
|
||||
)
|
||||
(func (export "as-loadN-address") (result i64)
|
||||
(i64.load8_s (return (i64.const 30)))
|
||||
)
|
||||
|
||||
(func (export "as-store-address") (result i32)
|
||||
(f64.store (return (i32.const 30)) (f64.const 7)) (i32.const -1)
|
||||
)
|
||||
(func (export "as-store-value") (result i32)
|
||||
(i64.store (i32.const 2) (return (i32.const 31))) (i32.const -1)
|
||||
)
|
||||
|
||||
(func (export "as-storeN-address") (result i32)
|
||||
(i32.store8 (return (i32.const 32)) (i32.const 7)) (i32.const -1)
|
||||
)
|
||||
(func (export "as-storeN-value") (result i32)
|
||||
(i64.store16 (i32.const 2) (return (i32.const 33))) (i32.const -1)
|
||||
)
|
||||
|
||||
(func (export "as-unary-operand") (result f32)
|
||||
(f32.neg (return (f32.const 3.4)))
|
||||
)
|
||||
|
||||
(func (export "as-binary-left") (result i32)
|
||||
(i32.add (return (i32.const 3)) (i32.const 10))
|
||||
)
|
||||
(func (export "as-binary-right") (result i64)
|
||||
(i64.sub (i64.const 10) (return (i64.const 45)))
|
||||
)
|
||||
|
||||
(func (export "as-test-operand") (result i32)
|
||||
(i32.eqz (return (i32.const 44)))
|
||||
)
|
||||
|
||||
(func (export "as-compare-left") (result i32)
|
||||
(f64.le (return (i32.const 43)) (f64.const 10))
|
||||
)
|
||||
(func (export "as-compare-right") (result i32)
|
||||
(f32.ne (f32.const 10) (return (i32.const 42)))
|
||||
)
|
||||
|
||||
(func (export "as-convert-operand") (result i32)
|
||||
(i32.wrap/i64 (return (i32.const 41)))
|
||||
)
|
||||
|
||||
(func (export "as-memory.grow-size") (result i32)
|
||||
(memory.grow (return (i32.const 40)))
|
||||
)
|
||||
)
|
||||
|
||||
(assert_return (invoke "type-i32"))
|
||||
(assert_return (invoke "type-i64"))
|
||||
(assert_return (invoke "type-f32"))
|
||||
(assert_return (invoke "type-f64"))
|
||||
|
||||
(assert_return (invoke "type-i32-value") (i32.const 1))
|
||||
(assert_return (invoke "type-i64-value") (i64.const 2))
|
||||
(assert_return (invoke "type-f32-value") (f32.const 3))
|
||||
(assert_return (invoke "type-f64-value") (f64.const 4))
|
||||
|
||||
(assert_return (invoke "nullary"))
|
||||
(assert_return (invoke "unary") (f64.const 3))
|
||||
|
||||
(assert_return (invoke "as-func-first") (i32.const 1))
|
||||
(assert_return (invoke "as-func-mid") (i32.const 2))
|
||||
(assert_return (invoke "as-func-last"))
|
||||
(assert_return (invoke "as-func-value") (i32.const 3))
|
||||
|
||||
(assert_return (invoke "as-block-first"))
|
||||
(assert_return (invoke "as-block-mid"))
|
||||
(assert_return (invoke "as-block-last"))
|
||||
(assert_return (invoke "as-block-value") (i32.const 2))
|
||||
|
||||
(assert_return (invoke "as-loop-first") (i32.const 3))
|
||||
(assert_return (invoke "as-loop-mid") (i32.const 4))
|
||||
(assert_return (invoke "as-loop-last") (i32.const 5))
|
||||
|
||||
(assert_return (invoke "as-br-value") (i32.const 9))
|
||||
|
||||
(assert_return (invoke "as-br_if-cond"))
|
||||
(assert_return (invoke "as-br_if-value") (i32.const 8))
|
||||
(assert_return (invoke "as-br_if-value-cond") (i32.const 9))
|
||||
|
||||
(assert_return (invoke "as-br_table-index") (i64.const 9))
|
||||
(assert_return (invoke "as-br_table-value") (i32.const 10))
|
||||
(assert_return (invoke "as-br_table-value-index") (i32.const 11))
|
||||
|
||||
(assert_return (invoke "as-return-value") (i64.const 7))
|
||||
|
||||
(assert_return (invoke "as-if-cond") (i32.const 2))
|
||||
(assert_return (invoke "as-if-then" (i32.const 1) (i32.const 6)) (i32.const 3))
|
||||
(assert_return (invoke "as-if-then" (i32.const 0) (i32.const 6)) (i32.const 6))
|
||||
(assert_return (invoke "as-if-else" (i32.const 0) (i32.const 6)) (i32.const 4))
|
||||
(assert_return (invoke "as-if-else" (i32.const 1) (i32.const 6)) (i32.const 6))
|
||||
|
||||
(assert_return (invoke "as-select-first" (i32.const 0) (i32.const 6)) (i32.const 5))
|
||||
(assert_return (invoke "as-select-first" (i32.const 1) (i32.const 6)) (i32.const 5))
|
||||
(assert_return (invoke "as-select-second" (i32.const 0) (i32.const 6)) (i32.const 6))
|
||||
(assert_return (invoke "as-select-second" (i32.const 1) (i32.const 6)) (i32.const 6))
|
||||
(assert_return (invoke "as-select-cond") (i32.const 7))
|
||||
|
||||
(assert_return (invoke "as-call-first") (i32.const 12))
|
||||
(assert_return (invoke "as-call-mid") (i32.const 13))
|
||||
(assert_return (invoke "as-call-last") (i32.const 14))
|
||||
|
||||
(assert_return (invoke "as-call_indirect-func") (i32.const 20))
|
||||
(assert_return (invoke "as-call_indirect-first") (i32.const 21))
|
||||
(assert_return (invoke "as-call_indirect-mid") (i32.const 22))
|
||||
(assert_return (invoke "as-call_indirect-last") (i32.const 23))
|
||||
|
||||
(assert_return (invoke "as-set_local-value") (i32.const 17))
|
||||
|
||||
(assert_return (invoke "as-load-address") (f32.const 1.7))
|
||||
(assert_return (invoke "as-loadN-address") (i64.const 30))
|
||||
|
||||
(assert_return (invoke "as-store-address") (i32.const 30))
|
||||
(assert_return (invoke "as-store-value") (i32.const 31))
|
||||
(assert_return (invoke "as-storeN-address") (i32.const 32))
|
||||
(assert_return (invoke "as-storeN-value") (i32.const 33))
|
||||
|
||||
(assert_return (invoke "as-unary-operand") (f32.const 3.4))
|
||||
|
||||
(assert_return (invoke "as-binary-left") (i32.const 3))
|
||||
(assert_return (invoke "as-binary-right") (i64.const 45))
|
||||
|
||||
(assert_return (invoke "as-test-operand") (i32.const 44))
|
||||
|
||||
(assert_return (invoke "as-compare-left") (i32.const 43))
|
||||
(assert_return (invoke "as-compare-right") (i32.const 42))
|
||||
|
||||
(assert_return (invoke "as-convert-operand") (i32.const 41))
|
||||
|
||||
(assert_return (invoke "as-memory.grow-size") (i32.const 40))
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-value-empty-vs-num (result f64) (return)))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-value-void-vs-num (result f64) (return (nop))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-value-num-vs-num (result f64) (return (i64.const 1))))
|
||||
"type mismatch"
|
||||
)
|
67
spectests/select.wast
Normal file
67
spectests/select.wast
Normal file
@ -0,0 +1,67 @@
|
||||
(module
|
||||
(func (export "select_i32") (param $lhs i32) (param $rhs i32) (param $cond i32) (result i32)
|
||||
(select (get_local $lhs) (get_local $rhs) (get_local $cond)))
|
||||
|
||||
(func (export "select_i64") (param $lhs i64) (param $rhs i64) (param $cond i32) (result i64)
|
||||
(select (get_local $lhs) (get_local $rhs) (get_local $cond)))
|
||||
|
||||
(func (export "select_f32") (param $lhs f32) (param $rhs f32) (param $cond i32) (result f32)
|
||||
(select (get_local $lhs) (get_local $rhs) (get_local $cond)))
|
||||
|
||||
(func (export "select_f64") (param $lhs f64) (param $rhs f64) (param $cond i32) (result f64)
|
||||
(select (get_local $lhs) (get_local $rhs) (get_local $cond)))
|
||||
|
||||
;; Check that both sides of the select are evaluated
|
||||
(func (export "select_trap_l") (param $cond i32) (result i32)
|
||||
(select (unreachable) (i32.const 0) (get_local $cond))
|
||||
)
|
||||
(func (export "select_trap_r") (param $cond i32) (result i32)
|
||||
(select (i32.const 0) (unreachable) (get_local $cond))
|
||||
)
|
||||
|
||||
(func (export "select_unreached")
|
||||
(unreachable) (select)
|
||||
(unreachable) (i32.const 0) (select)
|
||||
(unreachable) (i32.const 0) (i32.const 0) (select)
|
||||
(unreachable) (f32.const 0) (i32.const 0) (select)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
|
||||
(assert_return (invoke "select_i32" (i32.const 1) (i32.const 2) (i32.const 1)) (i32.const 1))
|
||||
(assert_return (invoke "select_i64" (i64.const 2) (i64.const 1) (i32.const 1)) (i64.const 2))
|
||||
(assert_return (invoke "select_f32" (f32.const 1) (f32.const 2) (i32.const 1)) (f32.const 1))
|
||||
(assert_return (invoke "select_f64" (f64.const 1) (f64.const 2) (i32.const 1)) (f64.const 1))
|
||||
|
||||
(assert_return (invoke "select_i32" (i32.const 1) (i32.const 2) (i32.const 0)) (i32.const 2))
|
||||
(assert_return (invoke "select_i32" (i32.const 2) (i32.const 1) (i32.const 0)) (i32.const 1))
|
||||
(assert_return (invoke "select_i64" (i64.const 2) (i64.const 1) (i32.const -1)) (i64.const 2))
|
||||
(assert_return (invoke "select_i64" (i64.const 2) (i64.const 1) (i32.const 0xf0f0f0f0)) (i64.const 2))
|
||||
|
||||
(assert_return (invoke "select_f32" (f32.const nan) (f32.const 1) (i32.const 1)) (f32.const nan))
|
||||
(assert_return (invoke "select_f32" (f32.const nan:0x20304) (f32.const 1) (i32.const 1)) (f32.const nan:0x20304))
|
||||
(assert_return (invoke "select_f32" (f32.const nan) (f32.const 1) (i32.const 0)) (f32.const 1))
|
||||
(assert_return (invoke "select_f32" (f32.const nan:0x20304) (f32.const 1) (i32.const 0)) (f32.const 1))
|
||||
(assert_return (invoke "select_f32" (f32.const 2) (f32.const nan) (i32.const 1)) (f32.const 2))
|
||||
(assert_return (invoke "select_f32" (f32.const 2) (f32.const nan:0x20304) (i32.const 1)) (f32.const 2))
|
||||
(assert_return (invoke "select_f32" (f32.const 2) (f32.const nan) (i32.const 0)) (f32.const nan))
|
||||
(assert_return (invoke "select_f32" (f32.const 2) (f32.const nan:0x20304) (i32.const 0)) (f32.const nan:0x20304))
|
||||
|
||||
(assert_return (invoke "select_f64" (f64.const nan) (f64.const 1) (i32.const 1)) (f64.const nan))
|
||||
(assert_return (invoke "select_f64" (f64.const nan:0x20304) (f64.const 1) (i32.const 1)) (f64.const nan:0x20304))
|
||||
(assert_return (invoke "select_f64" (f64.const nan) (f64.const 1) (i32.const 0)) (f64.const 1))
|
||||
(assert_return (invoke "select_f64" (f64.const nan:0x20304) (f64.const 1) (i32.const 0)) (f64.const 1))
|
||||
(assert_return (invoke "select_f64" (f64.const 2) (f64.const nan) (i32.const 1)) (f64.const 2))
|
||||
(assert_return (invoke "select_f64" (f64.const 2) (f64.const nan:0x20304) (i32.const 1)) (f64.const 2))
|
||||
(assert_return (invoke "select_f64" (f64.const 2) (f64.const nan) (i32.const 0)) (f64.const nan))
|
||||
(assert_return (invoke "select_f64" (f64.const 2) (f64.const nan:0x20304) (i32.const 0)) (f64.const nan:0x20304))
|
||||
|
||||
(assert_trap (invoke "select_trap_l" (i32.const 1)) "unreachable executed")
|
||||
(assert_trap (invoke "select_trap_l" (i32.const 0)) "unreachable executed")
|
||||
(assert_trap (invoke "select_trap_r" (i32.const 1)) "unreachable executed")
|
||||
(assert_trap (invoke "select_trap_r" (i32.const 0)) "unreachable executed")
|
||||
|
||||
(assert_invalid
|
||||
(module (func $arity-0 (select (nop) (nop) (i32.const 1))))
|
||||
"type mismatch"
|
||||
)
|
150
spectests/switch.wast
Normal file
150
spectests/switch.wast
Normal file
@ -0,0 +1,150 @@
|
||||
(module
|
||||
;; Statement switch
|
||||
(func (export "stmt") (param $i i32) (result i32)
|
||||
(local $j i32)
|
||||
(set_local $j (i32.const 100))
|
||||
(block $switch
|
||||
(block $7
|
||||
(block $default
|
||||
(block $6
|
||||
(block $5
|
||||
(block $4
|
||||
(block $3
|
||||
(block $2
|
||||
(block $1
|
||||
(block $0
|
||||
(br_table $0 $1 $2 $3 $4 $5 $6 $7 $default
|
||||
(get_local $i)
|
||||
)
|
||||
) ;; 0
|
||||
(return (get_local $i))
|
||||
) ;; 1
|
||||
(nop)
|
||||
;; fallthrough
|
||||
) ;; 2
|
||||
;; fallthrough
|
||||
) ;; 3
|
||||
(set_local $j (i32.sub (i32.const 0) (get_local $i)))
|
||||
(br $switch)
|
||||
) ;; 4
|
||||
(br $switch)
|
||||
) ;; 5
|
||||
(set_local $j (i32.const 101))
|
||||
(br $switch)
|
||||
) ;; 6
|
||||
(set_local $j (i32.const 101))
|
||||
;; fallthrough
|
||||
) ;; default
|
||||
(set_local $j (i32.const 102))
|
||||
) ;; 7
|
||||
;; fallthrough
|
||||
)
|
||||
(return (get_local $j))
|
||||
)
|
||||
|
||||
;; Expression switch
|
||||
(func (export "expr") (param $i i64) (result i64)
|
||||
(local $j i64)
|
||||
(set_local $j (i64.const 100))
|
||||
(return
|
||||
(block $switch (result i64)
|
||||
(block $7
|
||||
(block $default
|
||||
(block $4
|
||||
(block $5
|
||||
(block $6
|
||||
(block $3
|
||||
(block $2
|
||||
(block $1
|
||||
(block $0
|
||||
(br_table $0 $1 $2 $3 $4 $5 $6 $7 $default
|
||||
(i32.wrap/i64 (get_local $i))
|
||||
)
|
||||
) ;; 0
|
||||
(return (get_local $i))
|
||||
) ;; 1
|
||||
(nop)
|
||||
;; fallthrough
|
||||
) ;; 2
|
||||
;; fallthrough
|
||||
) ;; 3
|
||||
(br $switch (i64.sub (i64.const 0) (get_local $i)))
|
||||
) ;; 6
|
||||
(set_local $j (i64.const 101))
|
||||
;; fallthrough
|
||||
) ;; 4
|
||||
;; fallthrough
|
||||
) ;; 5
|
||||
;; fallthrough
|
||||
) ;; default
|
||||
(br $switch (get_local $j))
|
||||
) ;; 7
|
||||
(i64.const -5)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; Argument switch
|
||||
(func (export "arg") (param $i i32) (result i32)
|
||||
(return
|
||||
(block $2 (result i32)
|
||||
(i32.add (i32.const 10)
|
||||
(block $1 (result i32)
|
||||
(i32.add (i32.const 100)
|
||||
(block $0 (result i32)
|
||||
(i32.add (i32.const 1000)
|
||||
(block $default (result i32)
|
||||
(br_table $0 $1 $2 $default
|
||||
(i32.mul (i32.const 2) (get_local $i))
|
||||
(i32.and (i32.const 3) (get_local $i))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; Corner cases
|
||||
(func (export "corner") (result i32)
|
||||
(block
|
||||
(br_table 0 (i32.const 0))
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
|
||||
(assert_return (invoke "stmt" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "stmt" (i32.const 1)) (i32.const -1))
|
||||
(assert_return (invoke "stmt" (i32.const 2)) (i32.const -2))
|
||||
(assert_return (invoke "stmt" (i32.const 3)) (i32.const -3))
|
||||
(assert_return (invoke "stmt" (i32.const 4)) (i32.const 100))
|
||||
(assert_return (invoke "stmt" (i32.const 5)) (i32.const 101))
|
||||
(assert_return (invoke "stmt" (i32.const 6)) (i32.const 102))
|
||||
(assert_return (invoke "stmt" (i32.const 7)) (i32.const 100))
|
||||
(assert_return (invoke "stmt" (i32.const -10)) (i32.const 102))
|
||||
|
||||
(assert_return (invoke "expr" (i64.const 0)) (i64.const 0))
|
||||
(assert_return (invoke "expr" (i64.const 1)) (i64.const -1))
|
||||
(assert_return (invoke "expr" (i64.const 2)) (i64.const -2))
|
||||
(assert_return (invoke "expr" (i64.const 3)) (i64.const -3))
|
||||
(assert_return (invoke "expr" (i64.const 6)) (i64.const 101))
|
||||
(assert_return (invoke "expr" (i64.const 7)) (i64.const -5))
|
||||
(assert_return (invoke "expr" (i64.const -10)) (i64.const 100))
|
||||
|
||||
(assert_return (invoke "arg" (i32.const 0)) (i32.const 110))
|
||||
(assert_return (invoke "arg" (i32.const 1)) (i32.const 12))
|
||||
(assert_return (invoke "arg" (i32.const 2)) (i32.const 4))
|
||||
(assert_return (invoke "arg" (i32.const 3)) (i32.const 1116))
|
||||
(assert_return (invoke "arg" (i32.const 4)) (i32.const 118))
|
||||
(assert_return (invoke "arg" (i32.const 5)) (i32.const 20))
|
||||
(assert_return (invoke "arg" (i32.const 6)) (i32.const 12))
|
||||
(assert_return (invoke "arg" (i32.const 7)) (i32.const 1124))
|
||||
(assert_return (invoke "arg" (i32.const 8)) (i32.const 126))
|
||||
|
||||
(assert_return (invoke "corner") (i32.const 1))
|
||||
|
||||
(assert_invalid (module (func (br_table 3 (i32.const 0)))) "unknown label")
|
235
spectests/tee_local.wast
Normal file
235
spectests/tee_local.wast
Normal file
@ -0,0 +1,235 @@
|
||||
;; Test `tee_local` operator
|
||||
|
||||
(module
|
||||
;; Typing
|
||||
|
||||
(func (export "type-local-i32") (result i32) (local i32) (tee_local 0 (i32.const 0)))
|
||||
(func (export "type-local-i64") (result i64) (local i64) (tee_local 0 (i64.const 0)))
|
||||
(func (export "type-local-f32") (result f32) (local f32) (tee_local 0 (f32.const 0)))
|
||||
(func (export "type-local-f64") (result f64) (local f64) (tee_local 0 (f64.const 0)))
|
||||
|
||||
(func (export "type-param-i32") (param i32) (result i32) (tee_local 0 (i32.const 10)))
|
||||
(func (export "type-param-i64") (param i64) (result i64) (tee_local 0 (i64.const 11)))
|
||||
(func (export "type-param-f32") (param f32) (result f32) (tee_local 0 (f32.const 11.1)))
|
||||
(func (export "type-param-f64") (param f64) (result f64) (tee_local 0 (f64.const 12.2)))
|
||||
|
||||
(func (export "type-mixed") (param i64 f32 f64 i32 i32) (local f32 i64 i64 f64)
|
||||
(drop (i64.eqz (tee_local 0 (i64.const 0))))
|
||||
(drop (f32.neg (tee_local 1 (f32.const 0))))
|
||||
(drop (f64.neg (tee_local 2 (f64.const 0))))
|
||||
(drop (i32.eqz (tee_local 3 (i32.const 0))))
|
||||
(drop (i32.eqz (tee_local 4 (i32.const 0))))
|
||||
(drop (f32.neg (tee_local 5 (f32.const 0))))
|
||||
(drop (i64.eqz (tee_local 6 (i64.const 0))))
|
||||
(drop (i64.eqz (tee_local 7 (i64.const 0))))
|
||||
(drop (f64.neg (tee_local 8 (f64.const 0))))
|
||||
)
|
||||
|
||||
;; Writing
|
||||
|
||||
(func (export "write") (param i64 f32 f64 i32 i32) (result i64) (local f32 i64 i64 f64)
|
||||
(drop (tee_local 1 (f32.const -0.3)))
|
||||
(drop (tee_local 3 (i32.const 40)))
|
||||
(drop (tee_local 4 (i32.const -7)))
|
||||
(drop (tee_local 5 (f32.const 5.5)))
|
||||
(drop (tee_local 6 (i64.const 6)))
|
||||
(drop (tee_local 8 (f64.const 8)))
|
||||
(i64.trunc_s/f64
|
||||
(f64.add
|
||||
(f64.convert_u/i64 (get_local 0))
|
||||
(f64.add
|
||||
(f64.promote/f32 (get_local 1))
|
||||
(f64.add
|
||||
(get_local 2)
|
||||
(f64.add
|
||||
(f64.convert_u/i32 (get_local 3))
|
||||
(f64.add
|
||||
(f64.convert_s/i32 (get_local 4))
|
||||
(f64.add
|
||||
(f64.promote/f32 (get_local 5))
|
||||
(f64.add
|
||||
(f64.convert_u/i64 (get_local 6))
|
||||
(f64.add
|
||||
(f64.convert_u/i64 (get_local 7))
|
||||
(get_local 8)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; Result
|
||||
|
||||
(func (export "result") (param i64 f32 f64 i32 i32) (result f64)
|
||||
(local f32 i64 i64 f64)
|
||||
(f64.add
|
||||
(f64.convert_u/i64 (tee_local 0 (i64.const 1)))
|
||||
(f64.add
|
||||
(f64.promote/f32 (tee_local 1 (f32.const 2)))
|
||||
(f64.add
|
||||
(tee_local 2 (f64.const 3.3))
|
||||
(f64.add
|
||||
(f64.convert_u/i32 (tee_local 3 (i32.const 4)))
|
||||
(f64.add
|
||||
(f64.convert_s/i32 (tee_local 4 (i32.const 5)))
|
||||
(f64.add
|
||||
(f64.promote/f32 (tee_local 5 (f32.const 5.5)))
|
||||
(f64.add
|
||||
(f64.convert_u/i64 (tee_local 6 (i64.const 6)))
|
||||
(f64.add
|
||||
(f64.convert_u/i64 (tee_local 7 (i64.const 0)))
|
||||
(tee_local 8 (f64.const 8))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(assert_return (invoke "type-local-i32") (i32.const 0))
|
||||
(assert_return (invoke "type-local-i64") (i64.const 0))
|
||||
(assert_return (invoke "type-local-f32") (f32.const 0))
|
||||
(assert_return (invoke "type-local-f64") (f64.const 0))
|
||||
|
||||
(assert_return (invoke "type-param-i32" (i32.const 2)) (i32.const 10))
|
||||
(assert_return (invoke "type-param-i64" (i64.const 3)) (i64.const 11))
|
||||
(assert_return (invoke "type-param-f32" (f32.const 4.4)) (f32.const 11.1))
|
||||
(assert_return (invoke "type-param-f64" (f64.const 5.5)) (f64.const 12.2))
|
||||
|
||||
(assert_return
|
||||
(invoke "type-mixed"
|
||||
(i64.const 1) (f32.const 2.2) (f64.const 3.3) (i32.const 4) (i32.const 5)
|
||||
)
|
||||
)
|
||||
|
||||
(assert_return
|
||||
(invoke "write"
|
||||
(i64.const 1) (f32.const 2) (f64.const 3.3) (i32.const 4) (i32.const 5)
|
||||
)
|
||||
(i64.const 56)
|
||||
)
|
||||
|
||||
(assert_return
|
||||
(invoke "result"
|
||||
(i64.const -1) (f32.const -2) (f64.const -3.3) (i32.const -4) (i32.const -5)
|
||||
)
|
||||
(f64.const 34.8)
|
||||
)
|
||||
|
||||
|
||||
;; Invalid typing of access to locals
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-local-num-vs-num (result i64) (local i32) (tee_local 0 (i32.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-local-num-vs-num (local f32) (i32.eqz (tee_local 0 (f32.const 0)))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-local-num-vs-num (local f64 i64) (f64.neg (tee_local 1 (i64.const 0)))))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-local-arg-void-vs-num (local i32) (tee_local 0 (nop))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-local-arg-num-vs-num (local i32) (tee_local 0 (f32.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-local-arg-num-vs-num (local f32) (tee_local 0 (f64.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-local-arg-num-vs-num (local f64 i64) (tee_local 1 (f64.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
|
||||
;; Invalid typing of access to parameters
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-param-num-vs-num (param i32) (result i64) (get_local 0)))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-param-num-vs-num (param f32) (i32.eqz (get_local 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-param-num-vs-num (param f64 i64) (f64.neg (get_local 1))))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-param-arg-void-vs-num (param i32) (tee_local 0 (nop))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-param-arg-num-vs-num (param i32) (tee_local 0 (f32.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-param-arg-num-vs-num (param f32) (tee_local 0 (f64.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-param-arg-num-vs-num (param f64 i64) (tee_local 1 (f64.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
|
||||
;; Invalid local index
|
||||
|
||||
(assert_invalid
|
||||
(module (func $unbound-local (local i32 i64) (get_local 3)))
|
||||
"unknown local"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $large-local (local i32 i64) (get_local 14324343)))
|
||||
"unknown local"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $unbound-param (param i32 i64) (get_local 2)))
|
||||
"unknown local"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $large-param (local i32 i64) (get_local 714324343)))
|
||||
"unknown local"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $unbound-mixed (param i32) (local i32 i64) (get_local 3)))
|
||||
"unknown local"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $large-mixed (param i64) (local i32 i64) (get_local 214324343)))
|
||||
"unknown local"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-mixed-arg-num-vs-num (param f32) (local i32) (tee_local 1 (f32.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-mixed-arg-num-vs-num (param i64 i32) (local f32) (tee_local 1 (f32.const 0))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-mixed-arg-num-vs-num (param i64) (local f64 i64) (tee_local 1 (i64.const 0))))
|
||||
"type mismatch"
|
||||
)
|
@ -15,7 +15,7 @@ static ENV_VAR: &str = "WASM_GENERATE_SPECTESTS";
|
||||
static BANNER: &str = "// Rust test file autogenerated with cargo build (src/build_spectests.rs).
|
||||
// Please do NOT modify it by hand, as it will be reseted on next build.\n";
|
||||
|
||||
const TESTS: [&str; 25] = [
|
||||
const TESTS: [&str; 31] = [
|
||||
"spectests/address.wast",
|
||||
"spectests/align.wast",
|
||||
"spectests/block.wast",
|
||||
@ -27,6 +27,7 @@ const TESTS: [&str; 25] = [
|
||||
"spectests/call_indirect.wast",
|
||||
"spectests/const_.wast",
|
||||
"spectests/data.wast",
|
||||
"spectests/endianness.wast",
|
||||
"spectests/exports.wast",
|
||||
"spectests/f32_.wast",
|
||||
"spectests/f32_bitwise.wast",
|
||||
@ -34,12 +35,17 @@ const TESTS: [&str; 25] = [
|
||||
"spectests/f64_.wast",
|
||||
"spectests/f64_bitwise.wast",
|
||||
"spectests/f64_cmp.wast",
|
||||
"spectests/float_literals.wast",
|
||||
"spectests/func_ptrs.wast",
|
||||
"spectests/i32_.wast",
|
||||
"spectests/i64_.wast",
|
||||
"spectests/labels.wast",
|
||||
"spectests/memory.wast",
|
||||
"spectests/return_.wast",
|
||||
"spectests/select.wast",
|
||||
"spectests/set_local.wast",
|
||||
"spectests/switch.wast",
|
||||
"spectests/tee_local.wast",
|
||||
"spectests/types.wast",
|
||||
];
|
||||
|
||||
|
1114
src/spectests/endianness.rs
Normal file
1114
src/spectests/endianness.rs
Normal file
File diff suppressed because it is too large
Load Diff
2044
src/spectests/float_literals.rs
Normal file
2044
src/spectests/float_literals.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@ mod call;
|
||||
mod call_indirect;
|
||||
mod const_;
|
||||
mod data;
|
||||
mod endianness;
|
||||
mod exports;
|
||||
mod f32_;
|
||||
mod f32_bitwise;
|
||||
@ -21,10 +22,15 @@ mod f32_cmp;
|
||||
mod f64_;
|
||||
mod f64_bitwise;
|
||||
mod f64_cmp;
|
||||
mod float_literals;
|
||||
mod func_ptrs;
|
||||
mod i32_;
|
||||
mod i64_;
|
||||
mod labels;
|
||||
mod memory;
|
||||
mod return_;
|
||||
mod select;
|
||||
mod set_local;
|
||||
mod switch;
|
||||
mod tee_local;
|
||||
mod types;
|
||||
|
381
src/spectests/put/elem.wast
Normal file
381
src/spectests/put/elem.wast
Normal file
@ -0,0 +1,381 @@
|
||||
;; Test the element section
|
||||
|
||||
;; Syntax
|
||||
(module
|
||||
(table $t 10 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 0))
|
||||
(elem (i32.const 0) $f $f)
|
||||
(elem (offset (i32.const 0)))
|
||||
(elem (offset (i32.const 0)) $f $f)
|
||||
(elem 0 (i32.const 0))
|
||||
(elem 0x0 (i32.const 0) $f $f)
|
||||
(elem 0x000 (offset (i32.const 0)))
|
||||
(elem 0 (offset (i32.const 0)) $f $f)
|
||||
(elem $t (i32.const 0))
|
||||
(elem $t (i32.const 0) $f $f)
|
||||
(elem $t (offset (i32.const 0)))
|
||||
(elem $t (offset (i32.const 0)) $f $f)
|
||||
)
|
||||
|
||||
;; Basic use
|
||||
|
||||
(module
|
||||
(table 10 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
)
|
||||
(module
|
||||
(import "spectest" "table" (table 10 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
)
|
||||
|
||||
(module
|
||||
(table 10 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
(elem (i32.const 3) $f)
|
||||
(elem (i32.const 7) $f)
|
||||
(elem (i32.const 5) $f)
|
||||
(elem (i32.const 3) $f)
|
||||
)
|
||||
(module
|
||||
(import "spectest" "table" (table 10 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 9) $f)
|
||||
(elem (i32.const 3) $f)
|
||||
(elem (i32.const 7) $f)
|
||||
(elem (i32.const 3) $f)
|
||||
(elem (i32.const 5) $f)
|
||||
)
|
||||
|
||||
(module
|
||||
(global (import "spectest" "global_i32") i32)
|
||||
(table 1000 anyfunc)
|
||||
(func $f)
|
||||
(elem (get_global 0) $f)
|
||||
)
|
||||
|
||||
(module
|
||||
(global $g (import "spectest" "global_i32") i32)
|
||||
(table 1000 anyfunc)
|
||||
(func $f)
|
||||
(elem (get_global $g) $f)
|
||||
)
|
||||
|
||||
(module
|
||||
(type $out-i32 (func (result i32)))
|
||||
(table 10 anyfunc)
|
||||
(elem (i32.const 7) $const-i32-a)
|
||||
(elem (i32.const 9) $const-i32-b)
|
||||
(func $const-i32-a (type $out-i32) (i32.const 65))
|
||||
(func $const-i32-b (type $out-i32) (i32.const 66))
|
||||
(func (export "call-7") (type $out-i32)
|
||||
(call_indirect (type $out-i32) (i32.const 7))
|
||||
)
|
||||
(func (export "call-9") (type $out-i32)
|
||||
(call_indirect (type $out-i32) (i32.const 9))
|
||||
)
|
||||
)
|
||||
(assert_return (invoke "call-7") (i32.const 65))
|
||||
(assert_return (invoke "call-9") (i32.const 66))
|
||||
|
||||
;; Corner cases
|
||||
|
||||
(module
|
||||
(table 10 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 9) $f)
|
||||
)
|
||||
(module
|
||||
(import "spectest" "table" (table 10 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 9) $f)
|
||||
)
|
||||
|
||||
(module
|
||||
(table 0 anyfunc)
|
||||
(elem (i32.const 0))
|
||||
)
|
||||
(module
|
||||
(import "spectest" "table" (table 0 anyfunc))
|
||||
(elem (i32.const 0))
|
||||
)
|
||||
|
||||
(module
|
||||
(table 0 0 anyfunc)
|
||||
(elem (i32.const 0))
|
||||
)
|
||||
|
||||
(module
|
||||
(table 20 anyfunc)
|
||||
(elem (i32.const 20))
|
||||
)
|
||||
|
||||
(module
|
||||
(import "spectest" "table" (table 0 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
)
|
||||
|
||||
(module
|
||||
(import "spectest" "table" (table 0 100 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
)
|
||||
|
||||
(module
|
||||
(import "spectest" "table" (table 0 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 1) $f)
|
||||
)
|
||||
|
||||
(module
|
||||
(import "spectest" "table" (table 0 30 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 1) $f)
|
||||
)
|
||||
|
||||
;; Invalid bounds for elements
|
||||
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(table 0 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(table 0 0 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(table 0 1 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(table 0 anyfunc)
|
||||
(elem (i32.const 1))
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(table 10 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 10) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "spectest" "table" (table 10 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 10) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(table 10 20 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const 10) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "spectest" "table" (table 10 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const 10) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(table 10 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const -1) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "spectest" "table" (table 10 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const -1) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(table 10 anyfunc)
|
||||
(func $f)
|
||||
(elem (i32.const -10) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
(assert_unlinkable
|
||||
(module
|
||||
(import "spectest" "table" (table 10 anyfunc))
|
||||
(func $f)
|
||||
(elem (i32.const -10) $f)
|
||||
)
|
||||
"elements segment does not fit"
|
||||
)
|
||||
|
||||
;; Element without table
|
||||
|
||||
(assert_invalid
|
||||
(module
|
||||
(func $f)
|
||||
(elem (i32.const 0) $f)
|
||||
)
|
||||
"unknown table 0"
|
||||
)
|
||||
|
||||
;; Invalid offsets
|
||||
|
||||
(assert_invalid
|
||||
(module
|
||||
(table 1 anyfunc)
|
||||
(elem (i64.const 0))
|
||||
)
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module
|
||||
(table 1 anyfunc)
|
||||
(elem (i32.ctz (i32.const 0)))
|
||||
)
|
||||
"constant expression required"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module
|
||||
(table 1 anyfunc)
|
||||
(elem (nop))
|
||||
)
|
||||
"constant expression required"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module
|
||||
(table 1 anyfunc)
|
||||
(elem (offset (nop) (i32.const 0)))
|
||||
)
|
||||
"constant expression required"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module
|
||||
(table 1 anyfunc)
|
||||
(elem (offset (i32.const 0) (nop)))
|
||||
)
|
||||
"constant expression required"
|
||||
)
|
||||
|
||||
;; Use of internal globals in constant expressions is not allowed in MVP.
|
||||
;; (assert_invalid
|
||||
;; (module (memory 1) (data (get_global $g)) (global $g (mut i32) (i32.const 0)))
|
||||
;; "constant expression required"
|
||||
;; )
|
||||
|
||||
;; Two elements target the same slot
|
||||
|
||||
(module
|
||||
(type $out-i32 (func (result i32)))
|
||||
(table 10 anyfunc)
|
||||
(elem (i32.const 9) $const-i32-a)
|
||||
(elem (i32.const 9) $const-i32-b)
|
||||
(func $const-i32-a (type $out-i32) (i32.const 65))
|
||||
(func $const-i32-b (type $out-i32) (i32.const 66))
|
||||
(func (export "call-overwritten") (type $out-i32)
|
||||
(call_indirect (type $out-i32) (i32.const 9))
|
||||
)
|
||||
)
|
||||
(assert_return (invoke "call-overwritten") (i32.const 66))
|
||||
|
||||
(module
|
||||
(type $out-i32 (func (result i32)))
|
||||
(import "spectest" "table" (table 10 anyfunc))
|
||||
(elem (i32.const 9) $const-i32-a)
|
||||
(elem (i32.const 9) $const-i32-b)
|
||||
(func $const-i32-a (type $out-i32) (i32.const 65))
|
||||
(func $const-i32-b (type $out-i32) (i32.const 66))
|
||||
(func (export "call-overwritten-element") (type $out-i32)
|
||||
(call_indirect (type $out-i32) (i32.const 9))
|
||||
)
|
||||
)
|
||||
(assert_return (invoke "call-overwritten-element") (i32.const 66))
|
||||
|
||||
;; Element sections across multiple modules change the same table
|
||||
|
||||
(module $module1
|
||||
(type $out-i32 (func (result i32)))
|
||||
(table (export "shared-table") 10 anyfunc)
|
||||
(elem (i32.const 8) $const-i32-a)
|
||||
(elem (i32.const 9) $const-i32-b)
|
||||
(func $const-i32-a (type $out-i32) (i32.const 65))
|
||||
(func $const-i32-b (type $out-i32) (i32.const 66))
|
||||
(func (export "call-7") (type $out-i32)
|
||||
(call_indirect (type $out-i32) (i32.const 7))
|
||||
)
|
||||
(func (export "call-8") (type $out-i32)
|
||||
(call_indirect (type $out-i32) (i32.const 8))
|
||||
)
|
||||
(func (export "call-9") (type $out-i32)
|
||||
(call_indirect (type $out-i32) (i32.const 9))
|
||||
)
|
||||
)
|
||||
|
||||
(register "module1" $module1)
|
||||
|
||||
(assert_trap (invoke $module1 "call-7") "uninitialized element 7")
|
||||
(assert_return (invoke $module1 "call-8") (i32.const 65))
|
||||
(assert_return (invoke $module1 "call-9") (i32.const 66))
|
||||
|
||||
(module $module2
|
||||
(type $out-i32 (func (result i32)))
|
||||
(import "module1" "shared-table" (table 10 anyfunc))
|
||||
(elem (i32.const 7) $const-i32-c)
|
||||
(elem (i32.const 8) $const-i32-d)
|
||||
(func $const-i32-c (type $out-i32) (i32.const 67))
|
||||
(func $const-i32-d (type $out-i32) (i32.const 68))
|
||||
)
|
||||
|
||||
(assert_return (invoke $module1 "call-7") (i32.const 67))
|
||||
(assert_return (invoke $module1 "call-8") (i32.const 68))
|
||||
(assert_return (invoke $module1 "call-9") (i32.const 66))
|
||||
|
||||
(module $module3
|
||||
(type $out-i32 (func (result i32)))
|
||||
(import "module1" "shared-table" (table 10 anyfunc))
|
||||
(elem (i32.const 8) $const-i32-e)
|
||||
(elem (i32.const 9) $const-i32-f)
|
||||
(func $const-i32-e (type $out-i32) (i32.const 69))
|
||||
(func $const-i32-f (type $out-i32) (i32.const 70))
|
||||
)
|
||||
|
||||
(assert_return (invoke $module1 "call-7") (i32.const 67))
|
||||
(assert_return (invoke $module1 "call-8") (i32.const 69))
|
||||
(assert_return (invoke $module1 "call-9") (i32.const 70))
|
742
src/spectests/put/if_.wast
Normal file
742
src/spectests/put/if_.wast
Normal file
@ -0,0 +1,742 @@
|
||||
;; Test `if` operator
|
||||
|
||||
(module
|
||||
;; Auxiliary definition
|
||||
(memory 1)
|
||||
|
||||
(func $dummy)
|
||||
|
||||
(func (export "empty") (param i32)
|
||||
(if (get_local 0) (then))
|
||||
(if (get_local 0) (then) (else))
|
||||
(if $l (get_local 0) (then))
|
||||
(if $l (get_local 0) (then) (else))
|
||||
)
|
||||
|
||||
(func (export "singular") (param i32) (result i32)
|
||||
(if (get_local 0) (then (nop)))
|
||||
(if (get_local 0) (then (nop)) (else (nop)))
|
||||
(if (result i32) (get_local 0) (then (i32.const 7)) (else (i32.const 8)))
|
||||
)
|
||||
|
||||
(func (export "multi") (param i32) (result i32)
|
||||
(if (get_local 0) (then (call $dummy) (call $dummy) (call $dummy)))
|
||||
(if (get_local 0) (then) (else (call $dummy) (call $dummy) (call $dummy)))
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (call $dummy) (i32.const 8))
|
||||
(else (call $dummy) (call $dummy) (i32.const 9))
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "nested") (param i32 i32) (result i32)
|
||||
(if (result i32) (get_local 0)
|
||||
(then
|
||||
(if (get_local 1) (then (call $dummy) (block) (nop)))
|
||||
(if (get_local 1) (then) (else (call $dummy) (block) (nop)))
|
||||
(if (result i32) (get_local 1)
|
||||
(then (call $dummy) (i32.const 9))
|
||||
(else (call $dummy) (i32.const 10))
|
||||
)
|
||||
)
|
||||
(else
|
||||
(if (get_local 1) (then (call $dummy) (block) (nop)))
|
||||
(if (get_local 1) (then) (else (call $dummy) (block) (nop)))
|
||||
(if (result i32) (get_local 1)
|
||||
(then (call $dummy) (i32.const 10))
|
||||
(else (call $dummy) (i32.const 11))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-select-first") (param i32) (result i32)
|
||||
(select
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(i32.const 2) (i32.const 3)
|
||||
)
|
||||
)
|
||||
(func (export "as-select-mid") (param i32) (result i32)
|
||||
(select
|
||||
(i32.const 2)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
(func (export "as-select-last") (param i32) (result i32)
|
||||
(select
|
||||
(i32.const 2) (i32.const 3)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-loop-first") (param i32) (result i32)
|
||||
(loop (result i32)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(call $dummy) (call $dummy)
|
||||
)
|
||||
)
|
||||
(func (export "as-loop-mid") (param i32) (result i32)
|
||||
(loop (result i32)
|
||||
(call $dummy)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(call $dummy)
|
||||
)
|
||||
)
|
||||
(func (export "as-loop-last") (param i32) (result i32)
|
||||
(loop (result i32)
|
||||
(call $dummy) (call $dummy)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-if-condition") (param i32) (result i32)
|
||||
(if (result i32)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (i32.const 1)) (else (i32.const 0))
|
||||
)
|
||||
(then (call $dummy) (i32.const 2))
|
||||
(else (call $dummy) (i32.const 3))
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-br_if-first") (param i32) (result i32)
|
||||
(block (result i32)
|
||||
(br_if 0
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(return (i32.const 3))
|
||||
)
|
||||
)
|
||||
(func (export "as-br_if-last") (param i32) (result i32)
|
||||
(block (result i32)
|
||||
(br_if 0
|
||||
(i32.const 2)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
)
|
||||
(return (i32.const 3))
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-br_table-first") (param i32) (result i32)
|
||||
(block (result i32)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(i32.const 2)
|
||||
(br_table 0 0)
|
||||
)
|
||||
)
|
||||
(func (export "as-br_table-last") (param i32) (result i32)
|
||||
(block (result i32)
|
||||
(i32.const 2)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(br_table 0 0)
|
||||
)
|
||||
)
|
||||
|
||||
(func $func (param i32 i32) (result i32) (get_local 0))
|
||||
(type $check (func (param i32 i32) (result i32)))
|
||||
(table anyfunc (elem $func))
|
||||
(func (export "as-call_indirect-first") (param i32) (result i32)
|
||||
(block (result i32)
|
||||
(call_indirect (type $check)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(i32.const 2) (i32.const 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "as-call_indirect-mid") (param i32) (result i32)
|
||||
(block (result i32)
|
||||
(call_indirect (type $check)
|
||||
(i32.const 2)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "as-call_indirect-last") (param i32) (result i32)
|
||||
(block (result i32)
|
||||
(call_indirect (type $check)
|
||||
(i32.const 2) (i32.const 0)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-store-first") (param i32)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(i32.const 2)
|
||||
(i32.store)
|
||||
)
|
||||
(func (export "as-store-last") (param i32)
|
||||
(i32.const 2)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 1))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
(i32.store)
|
||||
)
|
||||
|
||||
(func (export "as-memory.grow-value") (param i32) (result i32)
|
||||
(memory.grow
|
||||
(if (result i32) (get_local 0)
|
||||
(then (i32.const 1))
|
||||
(else (i32.const 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(func $f (param i32) (result i32) (get_local 0))
|
||||
|
||||
(func (export "as-call-value") (param i32) (result i32)
|
||||
(call $f
|
||||
(if (result i32) (get_local 0)
|
||||
(then (i32.const 1))
|
||||
(else (i32.const 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "as-return-value") (param i32) (result i32)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (i32.const 1))
|
||||
(else (i32.const 0)))
|
||||
(return)
|
||||
)
|
||||
(func (export "as-drop-operand") (param i32)
|
||||
(drop
|
||||
(if (result i32) (get_local 0)
|
||||
(then (i32.const 1))
|
||||
(else (i32.const 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "as-br-value") (param i32) (result i32)
|
||||
(block (result i32)
|
||||
(br 0
|
||||
(if (result i32) (get_local 0)
|
||||
(then (i32.const 1))
|
||||
(else (i32.const 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "as-set_local-value") (param i32) (result i32)
|
||||
(local i32)
|
||||
(set_local 0
|
||||
(if (result i32) (get_local 0)
|
||||
(then (i32.const 1))
|
||||
(else (i32.const 0))
|
||||
)
|
||||
)
|
||||
(get_local 0)
|
||||
)
|
||||
(func (export "as-load-operand") (param i32) (result i32)
|
||||
(i32.load
|
||||
(if (result i32) (get_local 0)
|
||||
(then (i32.const 11))
|
||||
(else (i32.const 10))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "as-unary-operand") (param i32) (result i32)
|
||||
(i32.ctz
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 13))
|
||||
(else (call $dummy) (i32.const -13))
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "as-binary-operand") (param i32 i32) (result i32)
|
||||
(i32.mul
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 3))
|
||||
(else (call $dummy) (i32.const -3))
|
||||
)
|
||||
(if (result i32) (get_local 1)
|
||||
(then (call $dummy) (i32.const 4))
|
||||
(else (call $dummy) (i32.const -5))
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "as-test-operand") (param i32) (result i32)
|
||||
(i32.eqz
|
||||
(if (result i32) (get_local 0)
|
||||
(then (call $dummy) (i32.const 13))
|
||||
(else (call $dummy) (i32.const 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (export "as-compare-operand") (param i32 i32) (result i32)
|
||||
(f32.gt
|
||||
(if (result f32) (get_local 0)
|
||||
(then (call $dummy) (f32.const 3))
|
||||
(else (call $dummy) (f32.const -3))
|
||||
)
|
||||
(if (result f32) (get_local 1)
|
||||
(then (call $dummy) (f32.const 4))
|
||||
(else (call $dummy) (f32.const -4))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "break-bare") (result i32)
|
||||
(if (i32.const 1) (then (br 0) (unreachable)))
|
||||
(if (i32.const 1) (then (br 0) (unreachable)) (else (unreachable)))
|
||||
(if (i32.const 0) (then (unreachable)) (else (br 0) (unreachable)))
|
||||
(if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)))
|
||||
(if (i32.const 1) (then (br_if 0 (i32.const 1)) (unreachable)) (else (unreachable)))
|
||||
(if (i32.const 0) (then (unreachable)) (else (br_if 0 (i32.const 1)) (unreachable)))
|
||||
(if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)))
|
||||
(if (i32.const 1) (then (br_table 0 (i32.const 0)) (unreachable)) (else (unreachable)))
|
||||
(if (i32.const 0) (then (unreachable)) (else (br_table 0 (i32.const 0)) (unreachable)))
|
||||
(i32.const 19)
|
||||
)
|
||||
|
||||
(func (export "break-value") (param i32) (result i32)
|
||||
(if (result i32) (get_local 0)
|
||||
(then (br 0 (i32.const 18)) (i32.const 19))
|
||||
(else (br 0 (i32.const 21)) (i32.const 20))
|
||||
)
|
||||
)
|
||||
|
||||
(func (export "effects") (param i32) (result i32)
|
||||
(local i32)
|
||||
(if
|
||||
(block (result i32) (set_local 1 (i32.const 1)) (get_local 0))
|
||||
(then
|
||||
(set_local 1 (i32.mul (get_local 1) (i32.const 3)))
|
||||
(set_local 1 (i32.sub (get_local 1) (i32.const 5)))
|
||||
(set_local 1 (i32.mul (get_local 1) (i32.const 7)))
|
||||
(br 0)
|
||||
(set_local 1 (i32.mul (get_local 1) (i32.const 100)))
|
||||
)
|
||||
(else
|
||||
(set_local 1 (i32.mul (get_local 1) (i32.const 5)))
|
||||
(set_local 1 (i32.sub (get_local 1) (i32.const 7)))
|
||||
(set_local 1 (i32.mul (get_local 1) (i32.const 3)))
|
||||
(br 0)
|
||||
(set_local 1 (i32.mul (get_local 1) (i32.const 1000)))
|
||||
)
|
||||
)
|
||||
(get_local 1)
|
||||
)
|
||||
)
|
||||
|
||||
(assert_return (invoke "empty" (i32.const 0)))
|
||||
(assert_return (invoke "empty" (i32.const 1)))
|
||||
(assert_return (invoke "empty" (i32.const 100)))
|
||||
(assert_return (invoke "empty" (i32.const -2)))
|
||||
|
||||
(assert_return (invoke "singular" (i32.const 0)) (i32.const 8))
|
||||
(assert_return (invoke "singular" (i32.const 1)) (i32.const 7))
|
||||
(assert_return (invoke "singular" (i32.const 10)) (i32.const 7))
|
||||
(assert_return (invoke "singular" (i32.const -10)) (i32.const 7))
|
||||
|
||||
(assert_return (invoke "multi" (i32.const 0)) (i32.const 9))
|
||||
(assert_return (invoke "multi" (i32.const 1)) (i32.const 8))
|
||||
(assert_return (invoke "multi" (i32.const 13)) (i32.const 8))
|
||||
(assert_return (invoke "multi" (i32.const -5)) (i32.const 8))
|
||||
|
||||
(assert_return (invoke "nested" (i32.const 0) (i32.const 0)) (i32.const 11))
|
||||
(assert_return (invoke "nested" (i32.const 1) (i32.const 0)) (i32.const 10))
|
||||
(assert_return (invoke "nested" (i32.const 0) (i32.const 1)) (i32.const 10))
|
||||
(assert_return (invoke "nested" (i32.const 3) (i32.const 2)) (i32.const 9))
|
||||
(assert_return (invoke "nested" (i32.const 0) (i32.const -100)) (i32.const 10))
|
||||
(assert_return (invoke "nested" (i32.const 10) (i32.const 10)) (i32.const 9))
|
||||
(assert_return (invoke "nested" (i32.const 0) (i32.const -1)) (i32.const 10))
|
||||
(assert_return (invoke "nested" (i32.const -111) (i32.const -2)) (i32.const 9))
|
||||
|
||||
(assert_return (invoke "as-select-first" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-select-first" (i32.const 1)) (i32.const 1))
|
||||
(assert_return (invoke "as-select-mid" (i32.const 0)) (i32.const 2))
|
||||
(assert_return (invoke "as-select-mid" (i32.const 1)) (i32.const 2))
|
||||
(assert_return (invoke "as-select-last" (i32.const 0)) (i32.const 3))
|
||||
(assert_return (invoke "as-select-last" (i32.const 1)) (i32.const 2))
|
||||
|
||||
(assert_return (invoke "as-loop-first" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-loop-first" (i32.const 1)) (i32.const 1))
|
||||
(assert_return (invoke "as-loop-mid" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-loop-mid" (i32.const 1)) (i32.const 1))
|
||||
(assert_return (invoke "as-loop-last" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-loop-last" (i32.const 1)) (i32.const 1))
|
||||
|
||||
(assert_return (invoke "as-if-condition" (i32.const 0)) (i32.const 3))
|
||||
(assert_return (invoke "as-if-condition" (i32.const 1)) (i32.const 2))
|
||||
|
||||
(assert_return (invoke "as-br_if-first" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-br_if-first" (i32.const 1)) (i32.const 1))
|
||||
(assert_return (invoke "as-br_if-last" (i32.const 0)) (i32.const 3))
|
||||
(assert_return (invoke "as-br_if-last" (i32.const 1)) (i32.const 2))
|
||||
|
||||
(assert_return (invoke "as-br_table-first" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-br_table-first" (i32.const 1)) (i32.const 1))
|
||||
(assert_return (invoke "as-br_table-last" (i32.const 0)) (i32.const 2))
|
||||
(assert_return (invoke "as-br_table-last" (i32.const 1)) (i32.const 2))
|
||||
|
||||
(assert_return (invoke "as-call_indirect-first" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-call_indirect-first" (i32.const 1)) (i32.const 1))
|
||||
(assert_return (invoke "as-call_indirect-mid" (i32.const 0)) (i32.const 2))
|
||||
(assert_return (invoke "as-call_indirect-mid" (i32.const 1)) (i32.const 2))
|
||||
(assert_return (invoke "as-call_indirect-last" (i32.const 0)) (i32.const 2))
|
||||
(assert_trap (invoke "as-call_indirect-last" (i32.const 1)) "undefined element")
|
||||
|
||||
(assert_return (invoke "as-store-first" (i32.const 0)))
|
||||
(assert_return (invoke "as-store-first" (i32.const 1)))
|
||||
(assert_return (invoke "as-store-last" (i32.const 0)))
|
||||
(assert_return (invoke "as-store-last" (i32.const 1)))
|
||||
|
||||
(assert_return (invoke "as-memory.grow-value" (i32.const 0)) (i32.const 1))
|
||||
(assert_return (invoke "as-memory.grow-value" (i32.const 1)) (i32.const 1))
|
||||
|
||||
(assert_return (invoke "as-call-value" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-call-value" (i32.const 1)) (i32.const 1))
|
||||
|
||||
(assert_return (invoke "as-return-value" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-return-value" (i32.const 1)) (i32.const 1))
|
||||
|
||||
(assert_return (invoke "as-drop-operand" (i32.const 0)))
|
||||
(assert_return (invoke "as-drop-operand" (i32.const 1)))
|
||||
|
||||
(assert_return (invoke "as-br-value" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-br-value" (i32.const 1)) (i32.const 1))
|
||||
|
||||
(assert_return (invoke "as-set_local-value" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-set_local-value" (i32.const 1)) (i32.const 1))
|
||||
|
||||
(assert_return (invoke "as-load-operand" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-load-operand" (i32.const 1)) (i32.const 0))
|
||||
|
||||
(assert_return (invoke "as-unary-operand" (i32.const 0)) (i32.const 0))
|
||||
(assert_return (invoke "as-unary-operand" (i32.const 1)) (i32.const 0))
|
||||
(assert_return (invoke "as-unary-operand" (i32.const -1)) (i32.const 0))
|
||||
|
||||
(assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 0)) (i32.const 15))
|
||||
(assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 1)) (i32.const -12))
|
||||
(assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 0)) (i32.const -15))
|
||||
(assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 1)) (i32.const 12))
|
||||
|
||||
(assert_return (invoke "as-test-operand" (i32.const 0)) (i32.const 1))
|
||||
(assert_return (invoke "as-test-operand" (i32.const 1)) (i32.const 0))
|
||||
|
||||
(assert_return (invoke "as-compare-operand" (i32.const 0) (i32.const 0)) (i32.const 1))
|
||||
(assert_return (invoke "as-compare-operand" (i32.const 0) (i32.const 1)) (i32.const 0))
|
||||
(assert_return (invoke "as-compare-operand" (i32.const 1) (i32.const 0)) (i32.const 1))
|
||||
(assert_return (invoke "as-compare-operand" (i32.const 1) (i32.const 1)) (i32.const 0))
|
||||
|
||||
(assert_return (invoke "break-bare") (i32.const 19))
|
||||
(assert_return (invoke "break-value" (i32.const 1)) (i32.const 18))
|
||||
(assert_return (invoke "break-value" (i32.const 0)) (i32.const 21))
|
||||
|
||||
(assert_return (invoke "effects" (i32.const 1)) (i32.const -14))
|
||||
(assert_return (invoke "effects" (i32.const 0)) (i32.const -6))
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-empty-i32 (result i32) (if (i32.const 0) (then))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-empty-i64 (result i64) (if (i32.const 0) (then))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-empty-f32 (result f32) (if (i32.const 0) (then))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-empty-f64 (result f64) (if (i32.const 0) (then))))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-empty-i32 (result i32) (if (i32.const 0) (then) (else))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-empty-i64 (result i64) (if (i32.const 0) (then) (else))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-empty-f32 (result f32) (if (i32.const 0) (then) (else))))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-empty-f64 (result f64) (if (i32.const 0) (then) (else))))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-num-vs-void
|
||||
(if (i32.const 1) (then (i32.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-num-vs-void
|
||||
(if (i32.const 1) (then (i32.const 1)) (else))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-else-value-num-vs-void
|
||||
(if (i32.const 1) (then) (else (i32.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-both-value-num-vs-void
|
||||
(if (i32.const 1) (then (i32.const 1)) (else (i32.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-empty-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then) (else (i32.const 0)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-empty-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (i32.const 0)) (else))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-both-value-empty-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then) (else))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-no-else-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (i32.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-void-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (nop)) (else (i32.const 0)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-void-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (i32.const 0)) (else (nop)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-both-value-void-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (nop)) (else (nop)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-num-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (i64.const 1)) (else (i32.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-num-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (i32.const 1)) (else (i64.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-both-value-num-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (i64.const 1)) (else (i64.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-both-different-value-num-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (i64.const 1)) (else (f64.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-then-value-unreached-select (result i32)
|
||||
(if (result i64)
|
||||
(i32.const 0)
|
||||
(then (select (unreachable) (unreachable) (unreachable)))
|
||||
(else (i64.const 0))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-else-value-unreached-select (result i32)
|
||||
(if (result i64)
|
||||
(i32.const 1)
|
||||
(then (i64.const 0))
|
||||
(else (select (unreachable) (unreachable) (unreachable)))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-else-value-unreached-select (result i32)
|
||||
(if (result i64)
|
||||
(i32.const 1)
|
||||
(then (select (unreachable) (unreachable) (unreachable)))
|
||||
(else (select (unreachable) (unreachable) (unreachable)))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-then-break-last-void-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (br 0)) (else (i32.const 1)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-else-break-last-void-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1) (then (i32.const 1)) (else (br 0)))
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-then-break-empty-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1)
|
||||
(then (br 0) (i32.const 1))
|
||||
(else (i32.const 1))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-else-break-empty-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1)
|
||||
(then (i32.const 1))
|
||||
(else (br 0) (i32.const 1))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-then-break-void-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1)
|
||||
(then (br 0 (nop)) (i32.const 1))
|
||||
(else (i32.const 1))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-else-break-void-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1)
|
||||
(then (i32.const 1))
|
||||
(else (br 0 (nop)) (i32.const 1))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
(assert_invalid
|
||||
(module (func $type-then-break-num-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1)
|
||||
(then (br 0 (i64.const 1)) (i32.const 1))
|
||||
(else (i32.const 1))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
(assert_invalid
|
||||
(module (func $type-else-break-num-vs-num (result i32)
|
||||
(if (result i32) (i32.const 1)
|
||||
(then (i32.const 1))
|
||||
(else (br 0 (i64.const 1)) (i32.const 1))
|
||||
)
|
||||
))
|
||||
"type mismatch"
|
||||
)
|
||||
|
||||
|
||||
(assert_malformed
|
||||
(module quote "(func if end $l)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if $a end $l)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if else $l end)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if $a else $l end)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if else end $l)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if else $l end $l)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if else $l1 end $l2)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if $a else end $l)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if $a else $a end $l)")
|
||||
"mismatching label"
|
||||
)
|
||||
(assert_malformed
|
||||
(module quote "(func if $a else $l end $l)")
|
||||
"mismatching label"
|
||||
)
|
1238
src/spectests/return_.rs
Normal file
1238
src/spectests/return_.rs
Normal file
File diff suppressed because it is too large
Load Diff
420
src/spectests/select.rs
Normal file
420
src/spectests/select.rs
Normal file
@ -0,0 +1,420 @@
|
||||
// Rust test file autogenerated with cargo build (src/build_spectests.rs).
|
||||
// Please do NOT modify it by hand, as it will be reseted on next build.
|
||||
// Test based on spectests/select.wast
|
||||
#![allow(
|
||||
warnings,
|
||||
dead_code
|
||||
)]
|
||||
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
|
||||
use super::_common::spectest_importobject;
|
||||
use wabt::wat2wasm;
|
||||
|
||||
|
||||
// Line 1
|
||||
fn create_module_1() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(type (;0;) (func (param i32 i32 i32) (result i32)))
|
||||
(type (;1;) (func (param i64 i64 i32) (result i64)))
|
||||
(type (;2;) (func (param f32 f32 i32) (result f32)))
|
||||
(type (;3;) (func (param f64 f64 i32) (result f64)))
|
||||
(type (;4;) (func (param i32) (result i32)))
|
||||
(type (;5;) (func))
|
||||
(func (;0;) (type 0) (param i32 i32 i32) (result i32)
|
||||
get_local 0
|
||||
get_local 1
|
||||
get_local 2
|
||||
select)
|
||||
(func (;1;) (type 1) (param i64 i64 i32) (result i64)
|
||||
get_local 0
|
||||
get_local 1
|
||||
get_local 2
|
||||
select)
|
||||
(func (;2;) (type 2) (param f32 f32 i32) (result f32)
|
||||
get_local 0
|
||||
get_local 1
|
||||
get_local 2
|
||||
select)
|
||||
(func (;3;) (type 3) (param f64 f64 i32) (result f64)
|
||||
get_local 0
|
||||
get_local 1
|
||||
get_local 2
|
||||
select)
|
||||
(func (;4;) (type 4) (param i32) (result i32)
|
||||
unreachable
|
||||
i32.const 0
|
||||
get_local 0
|
||||
select)
|
||||
(func (;5;) (type 4) (param i32) (result i32)
|
||||
i32.const 0
|
||||
unreachable
|
||||
get_local 0
|
||||
select)
|
||||
(func (;6;) (type 5)
|
||||
unreachable
|
||||
select
|
||||
unreachable
|
||||
i32.const 0
|
||||
select
|
||||
unreachable
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
select
|
||||
unreachable
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
i32.const 0
|
||||
select
|
||||
unreachable)
|
||||
(export \"select_i32\" (func 0))
|
||||
(export \"select_i64\" (func 1))
|
||||
(export \"select_f32\" (func 2))
|
||||
(export \"select_f64\" (func 3))
|
||||
(export \"select_trap_l\" (func 4))
|
||||
(export \"select_trap_r\" (func 5))
|
||||
(export \"select_unreached\" (func 6)))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
}
|
||||
|
||||
// Line 31
|
||||
fn l31_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l31_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_i32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, i32, i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1 as i32, 2 as i32, 1 as i32, &vm_context);
|
||||
assert_eq!(result, 1 as i32);
|
||||
}
|
||||
|
||||
// Line 32
|
||||
fn l32_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l32_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_i64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, i64, i32, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2 as i64, 1 as i64, 1 as i32, &vm_context);
|
||||
assert_eq!(result, 2 as i64);
|
||||
}
|
||||
|
||||
// Line 33
|
||||
fn l33_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l33_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1.0 as f32, 2.0 as f32, 1 as i32, &vm_context);
|
||||
assert_eq!(result, 1.0 as f32);
|
||||
}
|
||||
|
||||
// Line 34
|
||||
fn l34_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l34_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1.0 as f64, 2.0 as f64, 1 as i32, &vm_context);
|
||||
assert_eq!(result, 1.0 as f64);
|
||||
}
|
||||
|
||||
// Line 36
|
||||
fn l36_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l36_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_i32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, i32, i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1 as i32, 2 as i32, 0 as i32, &vm_context);
|
||||
assert_eq!(result, 2 as i32);
|
||||
}
|
||||
|
||||
// Line 37
|
||||
fn l37_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l37_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_i32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, i32, i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2 as i32, 1 as i32, 0 as i32, &vm_context);
|
||||
assert_eq!(result, 1 as i32);
|
||||
}
|
||||
|
||||
// Line 38
|
||||
fn l38_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l38_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_i64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, i64, i32, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2 as i64, 1 as i64, -1 as i32, &vm_context);
|
||||
assert_eq!(result, 2 as i64);
|
||||
}
|
||||
|
||||
// Line 39
|
||||
fn l39_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l39_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_i64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, i64, i32, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2 as i64, 1 as i64, -252645136 as i32, &vm_context);
|
||||
assert_eq!(result, 2 as i64);
|
||||
}
|
||||
|
||||
// Line 41
|
||||
fn l41_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l41_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(std::f32::NAN, 1.0 as f32, 1 as i32, &vm_context);
|
||||
assert!(result.is_nan());
|
||||
assert_eq!(result.is_sign_positive(), (std::f32::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
// Line 42
|
||||
fn l42_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l42_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(std::f32::NAN, 1.0 as f32, 1 as i32, &vm_context);
|
||||
assert!(result.is_nan());
|
||||
assert_eq!(result.is_sign_positive(), (std::f32::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
// Line 43
|
||||
fn l43_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l43_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(std::f32::NAN, 1.0 as f32, 0 as i32, &vm_context);
|
||||
assert_eq!(result, 1.0 as f32);
|
||||
}
|
||||
|
||||
// Line 44
|
||||
fn l44_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l44_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(std::f32::NAN, 1.0 as f32, 0 as i32, &vm_context);
|
||||
assert_eq!(result, 1.0 as f32);
|
||||
}
|
||||
|
||||
// Line 45
|
||||
fn l45_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l45_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2.0 as f32, std::f32::NAN, 1 as i32, &vm_context);
|
||||
assert_eq!(result, 2.0 as f32);
|
||||
}
|
||||
|
||||
// Line 46
|
||||
fn l46_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l46_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2.0 as f32, std::f32::NAN, 1 as i32, &vm_context);
|
||||
assert_eq!(result, 2.0 as f32);
|
||||
}
|
||||
|
||||
// Line 47
|
||||
fn l47_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l47_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2.0 as f32, std::f32::NAN, 0 as i32, &vm_context);
|
||||
assert!(result.is_nan());
|
||||
assert_eq!(result.is_sign_positive(), (std::f32::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
// Line 48
|
||||
fn l48_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l48_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, f32, i32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2.0 as f32, std::f32::NAN, 0 as i32, &vm_context);
|
||||
assert!(result.is_nan());
|
||||
assert_eq!(result.is_sign_positive(), (std::f32::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
// Line 50
|
||||
fn l50_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l50_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(std::f64::NAN, 1.0 as f64, 1 as i32, &vm_context);
|
||||
assert!(result.is_nan());
|
||||
assert_eq!(result.is_sign_positive(), (std::f64::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
// Line 51
|
||||
fn l51_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l51_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(std::f64::NAN, 1.0 as f64, 1 as i32, &vm_context);
|
||||
assert!(result.is_nan());
|
||||
assert_eq!(result.is_sign_positive(), (std::f64::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
// Line 52
|
||||
fn l52_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l52_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(std::f64::NAN, 1.0 as f64, 0 as i32, &vm_context);
|
||||
assert_eq!(result, 1.0 as f64);
|
||||
}
|
||||
|
||||
// Line 53
|
||||
fn l53_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l53_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(std::f64::NAN, 1.0 as f64, 0 as i32, &vm_context);
|
||||
assert_eq!(result, 1.0 as f64);
|
||||
}
|
||||
|
||||
// Line 54
|
||||
fn l54_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l54_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2.0 as f64, std::f64::NAN, 1 as i32, &vm_context);
|
||||
assert_eq!(result, 2.0 as f64);
|
||||
}
|
||||
|
||||
// Line 55
|
||||
fn l55_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l55_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2.0 as f64, std::f64::NAN, 1 as i32, &vm_context);
|
||||
assert_eq!(result, 2.0 as f64);
|
||||
}
|
||||
|
||||
// Line 56
|
||||
fn l56_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l56_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2.0 as f64, std::f64::NAN, 0 as i32, &vm_context);
|
||||
assert!(result.is_nan());
|
||||
assert_eq!(result.is_sign_positive(), (std::f64::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
// Line 57
|
||||
fn l57_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l57_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("select_f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, f64, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2.0 as f64, std::f64::NAN, 0 as i32, &vm_context);
|
||||
assert!(result.is_nan());
|
||||
assert_eq!(result.is_sign_positive(), (std::f64::NAN).is_sign_positive());
|
||||
}
|
||||
|
||||
// Line 59
|
||||
|
||||
// Line 60
|
||||
|
||||
// Line 61
|
||||
|
||||
// Line 62
|
||||
|
||||
// Line 65
|
||||
#[test]
|
||||
fn l65_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 9, 1, 7, 0, 1, 1, 65, 1, 27, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_module_1() {
|
||||
let result_object = create_module_1();
|
||||
let vm_context = result_object.instance.generate_context();
|
||||
// We group the calls together
|
||||
l31_assert_return_invoke(&result_object, &vm_context);
|
||||
l32_assert_return_invoke(&result_object, &vm_context);
|
||||
l33_assert_return_invoke(&result_object, &vm_context);
|
||||
l34_assert_return_invoke(&result_object, &vm_context);
|
||||
l36_assert_return_invoke(&result_object, &vm_context);
|
||||
l37_assert_return_invoke(&result_object, &vm_context);
|
||||
l38_assert_return_invoke(&result_object, &vm_context);
|
||||
l39_assert_return_invoke(&result_object, &vm_context);
|
||||
l41_assert_return_invoke(&result_object, &vm_context);
|
||||
l42_assert_return_invoke(&result_object, &vm_context);
|
||||
l43_assert_return_invoke(&result_object, &vm_context);
|
||||
l44_assert_return_invoke(&result_object, &vm_context);
|
||||
l45_assert_return_invoke(&result_object, &vm_context);
|
||||
l46_assert_return_invoke(&result_object, &vm_context);
|
||||
l47_assert_return_invoke(&result_object, &vm_context);
|
||||
l48_assert_return_invoke(&result_object, &vm_context);
|
||||
l50_assert_return_invoke(&result_object, &vm_context);
|
||||
l51_assert_return_invoke(&result_object, &vm_context);
|
||||
l52_assert_return_invoke(&result_object, &vm_context);
|
||||
l53_assert_return_invoke(&result_object, &vm_context);
|
||||
l54_assert_return_invoke(&result_object, &vm_context);
|
||||
l55_assert_return_invoke(&result_object, &vm_context);
|
||||
l56_assert_return_invoke(&result_object, &vm_context);
|
||||
l57_assert_return_invoke(&result_object, &vm_context);
|
||||
}
|
492
src/spectests/switch.rs
Normal file
492
src/spectests/switch.rs
Normal file
@ -0,0 +1,492 @@
|
||||
// Rust test file autogenerated with cargo build (src/build_spectests.rs).
|
||||
// Please do NOT modify it by hand, as it will be reseted on next build.
|
||||
// Test based on spectests/switch.wast
|
||||
#![allow(
|
||||
warnings,
|
||||
dead_code
|
||||
)]
|
||||
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
|
||||
use super::_common::spectest_importobject;
|
||||
use wabt::wat2wasm;
|
||||
|
||||
|
||||
// Line 1
|
||||
fn create_module_1() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(type (;0;) (func (param i32) (result i32)))
|
||||
(type (;1;) (func (param i64) (result i64)))
|
||||
(type (;2;) (func (result i32)))
|
||||
(func (;0;) (type 0) (param i32) (result i32)
|
||||
(local i32)
|
||||
i32.const 100
|
||||
set_local 1
|
||||
block ;; label = @1
|
||||
block ;; label = @2
|
||||
block ;; label = @3
|
||||
block ;; label = @4
|
||||
block ;; label = @5
|
||||
block ;; label = @6
|
||||
block ;; label = @7
|
||||
block ;; label = @8
|
||||
block ;; label = @9
|
||||
block ;; label = @10
|
||||
get_local 0
|
||||
br_table 0 (;@10;) 1 (;@9;) 2 (;@8;) 3 (;@7;) 4 (;@6;) 5 (;@5;) 6 (;@4;) 8 (;@2;) 7 (;@3;)
|
||||
end
|
||||
get_local 0
|
||||
return
|
||||
end
|
||||
nop
|
||||
end
|
||||
end
|
||||
i32.const 0
|
||||
get_local 0
|
||||
i32.sub
|
||||
set_local 1
|
||||
br 5 (;@1;)
|
||||
end
|
||||
br 4 (;@1;)
|
||||
end
|
||||
i32.const 101
|
||||
set_local 1
|
||||
br 3 (;@1;)
|
||||
end
|
||||
i32.const 101
|
||||
set_local 1
|
||||
end
|
||||
i32.const 102
|
||||
set_local 1
|
||||
end
|
||||
end
|
||||
get_local 1
|
||||
return)
|
||||
(func (;1;) (type 1) (param i64) (result i64)
|
||||
(local i64)
|
||||
i64.const 100
|
||||
set_local 1
|
||||
block (result i64) ;; label = @1
|
||||
block ;; label = @2
|
||||
block ;; label = @3
|
||||
block ;; label = @4
|
||||
block ;; label = @5
|
||||
block ;; label = @6
|
||||
block ;; label = @7
|
||||
block ;; label = @8
|
||||
block ;; label = @9
|
||||
block ;; label = @10
|
||||
get_local 0
|
||||
i32.wrap/i64
|
||||
br_table 0 (;@10;) 1 (;@9;) 2 (;@8;) 3 (;@7;) 6 (;@4;) 5 (;@5;) 4 (;@6;) 8 (;@2;) 7 (;@3;)
|
||||
end
|
||||
get_local 0
|
||||
return
|
||||
end
|
||||
nop
|
||||
end
|
||||
end
|
||||
i64.const 0
|
||||
get_local 0
|
||||
i64.sub
|
||||
br 5 (;@1;)
|
||||
end
|
||||
i64.const 101
|
||||
set_local 1
|
||||
end
|
||||
end
|
||||
end
|
||||
get_local 1
|
||||
br 1 (;@1;)
|
||||
end
|
||||
i64.const -5
|
||||
end
|
||||
return)
|
||||
(func (;2;) (type 0) (param i32) (result i32)
|
||||
block (result i32) ;; label = @1
|
||||
i32.const 10
|
||||
block (result i32) ;; label = @2
|
||||
i32.const 100
|
||||
block (result i32) ;; label = @3
|
||||
i32.const 1000
|
||||
block (result i32) ;; label = @4
|
||||
i32.const 2
|
||||
get_local 0
|
||||
i32.mul
|
||||
i32.const 3
|
||||
get_local 0
|
||||
i32.and
|
||||
br_table 1 (;@3;) 2 (;@2;) 3 (;@1;) 0 (;@4;)
|
||||
end
|
||||
i32.add
|
||||
end
|
||||
i32.add
|
||||
end
|
||||
i32.add
|
||||
end
|
||||
return)
|
||||
(func (;3;) (type 2) (result i32)
|
||||
block ;; label = @1
|
||||
i32.const 0
|
||||
br_table 0 (;@1;)
|
||||
end
|
||||
i32.const 1)
|
||||
(export \"stmt\" (func 0))
|
||||
(export \"expr\" (func 1))
|
||||
(export \"arg\" (func 2))
|
||||
(export \"corner\" (func 3)))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
}
|
||||
|
||||
// Line 120
|
||||
fn l120_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l120_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(0 as i32, &vm_context);
|
||||
assert_eq!(result, 0 as i32);
|
||||
}
|
||||
|
||||
// Line 121
|
||||
fn l121_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l121_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1 as i32, &vm_context);
|
||||
assert_eq!(result, -1 as i32);
|
||||
}
|
||||
|
||||
// Line 122
|
||||
fn l122_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l122_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2 as i32, &vm_context);
|
||||
assert_eq!(result, -2 as i32);
|
||||
}
|
||||
|
||||
// Line 123
|
||||
fn l123_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l123_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(3 as i32, &vm_context);
|
||||
assert_eq!(result, -3 as i32);
|
||||
}
|
||||
|
||||
// Line 124
|
||||
fn l124_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l124_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(4 as i32, &vm_context);
|
||||
assert_eq!(result, 100 as i32);
|
||||
}
|
||||
|
||||
// Line 125
|
||||
fn l125_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l125_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(5 as i32, &vm_context);
|
||||
assert_eq!(result, 101 as i32);
|
||||
}
|
||||
|
||||
// Line 126
|
||||
fn l126_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l126_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(6 as i32, &vm_context);
|
||||
assert_eq!(result, 102 as i32);
|
||||
}
|
||||
|
||||
// Line 127
|
||||
fn l127_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l127_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(7 as i32, &vm_context);
|
||||
assert_eq!(result, 100 as i32);
|
||||
}
|
||||
|
||||
// Line 128
|
||||
fn l128_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l128_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("stmt") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(-10 as i32, &vm_context);
|
||||
assert_eq!(result, 102 as i32);
|
||||
}
|
||||
|
||||
// Line 130
|
||||
fn l130_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l130_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("expr") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(0 as i64, &vm_context);
|
||||
assert_eq!(result, 0 as i64);
|
||||
}
|
||||
|
||||
// Line 131
|
||||
fn l131_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l131_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("expr") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1 as i64, &vm_context);
|
||||
assert_eq!(result, -1 as i64);
|
||||
}
|
||||
|
||||
// Line 132
|
||||
fn l132_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l132_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("expr") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2 as i64, &vm_context);
|
||||
assert_eq!(result, -2 as i64);
|
||||
}
|
||||
|
||||
// Line 133
|
||||
fn l133_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l133_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("expr") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(3 as i64, &vm_context);
|
||||
assert_eq!(result, -3 as i64);
|
||||
}
|
||||
|
||||
// Line 134
|
||||
fn l134_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l134_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("expr") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(6 as i64, &vm_context);
|
||||
assert_eq!(result, 101 as i64);
|
||||
}
|
||||
|
||||
// Line 135
|
||||
fn l135_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l135_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("expr") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(7 as i64, &vm_context);
|
||||
assert_eq!(result, -5 as i64);
|
||||
}
|
||||
|
||||
// Line 136
|
||||
fn l136_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l136_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("expr") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(-10 as i64, &vm_context);
|
||||
assert_eq!(result, 100 as i64);
|
||||
}
|
||||
|
||||
// Line 138
|
||||
fn l138_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l138_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(0 as i32, &vm_context);
|
||||
assert_eq!(result, 110 as i32);
|
||||
}
|
||||
|
||||
// Line 139
|
||||
fn l139_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l139_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1 as i32, &vm_context);
|
||||
assert_eq!(result, 12 as i32);
|
||||
}
|
||||
|
||||
// Line 140
|
||||
fn l140_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l140_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2 as i32, &vm_context);
|
||||
assert_eq!(result, 4 as i32);
|
||||
}
|
||||
|
||||
// Line 141
|
||||
fn l141_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l141_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(3 as i32, &vm_context);
|
||||
assert_eq!(result, 1116 as i32);
|
||||
}
|
||||
|
||||
// Line 142
|
||||
fn l142_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l142_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(4 as i32, &vm_context);
|
||||
assert_eq!(result, 118 as i32);
|
||||
}
|
||||
|
||||
// Line 143
|
||||
fn l143_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l143_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(5 as i32, &vm_context);
|
||||
assert_eq!(result, 20 as i32);
|
||||
}
|
||||
|
||||
// Line 144
|
||||
fn l144_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l144_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(6 as i32, &vm_context);
|
||||
assert_eq!(result, 12 as i32);
|
||||
}
|
||||
|
||||
// Line 145
|
||||
fn l145_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l145_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(7 as i32, &vm_context);
|
||||
assert_eq!(result, 1124 as i32);
|
||||
}
|
||||
|
||||
// Line 146
|
||||
fn l146_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l146_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("arg") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(8 as i32, &vm_context);
|
||||
assert_eq!(result, 126 as i32);
|
||||
}
|
||||
|
||||
// Line 148
|
||||
fn l148_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l148_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("corner") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(&vm_context);
|
||||
assert_eq!(result, 1 as i32);
|
||||
}
|
||||
|
||||
// Line 150
|
||||
#[test]
|
||||
fn l150_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 9, 1, 7, 0, 65, 0, 14, 0, 3, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_module_1() {
|
||||
let result_object = create_module_1();
|
||||
let vm_context = result_object.instance.generate_context();
|
||||
// We group the calls together
|
||||
l120_assert_return_invoke(&result_object, &vm_context);
|
||||
l121_assert_return_invoke(&result_object, &vm_context);
|
||||
l122_assert_return_invoke(&result_object, &vm_context);
|
||||
l123_assert_return_invoke(&result_object, &vm_context);
|
||||
l124_assert_return_invoke(&result_object, &vm_context);
|
||||
l125_assert_return_invoke(&result_object, &vm_context);
|
||||
l126_assert_return_invoke(&result_object, &vm_context);
|
||||
l127_assert_return_invoke(&result_object, &vm_context);
|
||||
l128_assert_return_invoke(&result_object, &vm_context);
|
||||
l130_assert_return_invoke(&result_object, &vm_context);
|
||||
l131_assert_return_invoke(&result_object, &vm_context);
|
||||
l132_assert_return_invoke(&result_object, &vm_context);
|
||||
l133_assert_return_invoke(&result_object, &vm_context);
|
||||
l134_assert_return_invoke(&result_object, &vm_context);
|
||||
l135_assert_return_invoke(&result_object, &vm_context);
|
||||
l136_assert_return_invoke(&result_object, &vm_context);
|
||||
l138_assert_return_invoke(&result_object, &vm_context);
|
||||
l139_assert_return_invoke(&result_object, &vm_context);
|
||||
l140_assert_return_invoke(&result_object, &vm_context);
|
||||
l141_assert_return_invoke(&result_object, &vm_context);
|
||||
l142_assert_return_invoke(&result_object, &vm_context);
|
||||
l143_assert_return_invoke(&result_object, &vm_context);
|
||||
l144_assert_return_invoke(&result_object, &vm_context);
|
||||
l145_assert_return_invoke(&result_object, &vm_context);
|
||||
l146_assert_return_invoke(&result_object, &vm_context);
|
||||
l148_assert_return_invoke(&result_object, &vm_context);
|
||||
}
|
521
src/spectests/tee_local.rs
Normal file
521
src/spectests/tee_local.rs
Normal file
@ -0,0 +1,521 @@
|
||||
// Rust test file autogenerated with cargo build (src/build_spectests.rs).
|
||||
// Please do NOT modify it by hand, as it will be reseted on next build.
|
||||
// Test based on spectests/tee_local.wast
|
||||
#![allow(
|
||||
warnings,
|
||||
dead_code
|
||||
)]
|
||||
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
|
||||
use super::_common::spectest_importobject;
|
||||
use wabt::wat2wasm;
|
||||
|
||||
|
||||
// Line 3
|
||||
fn create_module_1() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(type (;0;) (func (result i32)))
|
||||
(type (;1;) (func (result i64)))
|
||||
(type (;2;) (func (result f32)))
|
||||
(type (;3;) (func (result f64)))
|
||||
(type (;4;) (func (param i32) (result i32)))
|
||||
(type (;5;) (func (param i64) (result i64)))
|
||||
(type (;6;) (func (param f32) (result f32)))
|
||||
(type (;7;) (func (param f64) (result f64)))
|
||||
(type (;8;) (func (param i64 f32 f64 i32 i32)))
|
||||
(type (;9;) (func (param i64 f32 f64 i32 i32) (result i64)))
|
||||
(type (;10;) (func (param i64 f32 f64 i32 i32) (result f64)))
|
||||
(func (;0;) (type 0) (result i32)
|
||||
(local i32)
|
||||
i32.const 0
|
||||
tee_local 0)
|
||||
(func (;1;) (type 1) (result i64)
|
||||
(local i64)
|
||||
i64.const 0
|
||||
tee_local 0)
|
||||
(func (;2;) (type 2) (result f32)
|
||||
(local f32)
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
tee_local 0)
|
||||
(func (;3;) (type 3) (result f64)
|
||||
(local f64)
|
||||
f64.const 0x0p+0 (;=0;)
|
||||
tee_local 0)
|
||||
(func (;4;) (type 4) (param i32) (result i32)
|
||||
i32.const 10
|
||||
tee_local 0)
|
||||
(func (;5;) (type 5) (param i64) (result i64)
|
||||
i64.const 11
|
||||
tee_local 0)
|
||||
(func (;6;) (type 6) (param f32) (result f32)
|
||||
f32.const 0x1.633334p+3 (;=11.1;)
|
||||
tee_local 0)
|
||||
(func (;7;) (type 7) (param f64) (result f64)
|
||||
f64.const 0x1.8666666666666p+3 (;=12.2;)
|
||||
tee_local 0)
|
||||
(func (;8;) (type 8) (param i64 f32 f64 i32 i32)
|
||||
(local f32 i64 i64 f64)
|
||||
i64.const 0
|
||||
tee_local 0
|
||||
i64.eqz
|
||||
drop
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
tee_local 1
|
||||
f32.neg
|
||||
drop
|
||||
f64.const 0x0p+0 (;=0;)
|
||||
tee_local 2
|
||||
f64.neg
|
||||
drop
|
||||
i32.const 0
|
||||
tee_local 3
|
||||
i32.eqz
|
||||
drop
|
||||
i32.const 0
|
||||
tee_local 4
|
||||
i32.eqz
|
||||
drop
|
||||
f32.const 0x0p+0 (;=0;)
|
||||
tee_local 5
|
||||
f32.neg
|
||||
drop
|
||||
i64.const 0
|
||||
tee_local 6
|
||||
i64.eqz
|
||||
drop
|
||||
i64.const 0
|
||||
tee_local 7
|
||||
i64.eqz
|
||||
drop
|
||||
f64.const 0x0p+0 (;=0;)
|
||||
tee_local 8
|
||||
f64.neg
|
||||
drop)
|
||||
(func (;9;) (type 9) (param i64 f32 f64 i32 i32) (result i64)
|
||||
(local f32 i64 i64 f64)
|
||||
f32.const -0x1.333334p-2 (;=-0.3;)
|
||||
tee_local 1
|
||||
drop
|
||||
i32.const 40
|
||||
tee_local 3
|
||||
drop
|
||||
i32.const -7
|
||||
tee_local 4
|
||||
drop
|
||||
f32.const 0x1.6p+2 (;=5.5;)
|
||||
tee_local 5
|
||||
drop
|
||||
i64.const 6
|
||||
tee_local 6
|
||||
drop
|
||||
f64.const 0x1p+3 (;=8;)
|
||||
tee_local 8
|
||||
drop
|
||||
get_local 0
|
||||
f64.convert_u/i64
|
||||
get_local 1
|
||||
f64.promote/f32
|
||||
get_local 2
|
||||
get_local 3
|
||||
f64.convert_u/i32
|
||||
get_local 4
|
||||
f64.convert_s/i32
|
||||
get_local 5
|
||||
f64.promote/f32
|
||||
get_local 6
|
||||
f64.convert_u/i64
|
||||
get_local 7
|
||||
f64.convert_u/i64
|
||||
get_local 8
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
i64.trunc_s/f64)
|
||||
(func (;10;) (type 10) (param i64 f32 f64 i32 i32) (result f64)
|
||||
(local f32 i64 i64 f64)
|
||||
i64.const 1
|
||||
tee_local 0
|
||||
f64.convert_u/i64
|
||||
f32.const 0x1p+1 (;=2;)
|
||||
tee_local 1
|
||||
f64.promote/f32
|
||||
f64.const 0x1.a666666666666p+1 (;=3.3;)
|
||||
tee_local 2
|
||||
i32.const 4
|
||||
tee_local 3
|
||||
f64.convert_u/i32
|
||||
i32.const 5
|
||||
tee_local 4
|
||||
f64.convert_s/i32
|
||||
f32.const 0x1.6p+2 (;=5.5;)
|
||||
tee_local 5
|
||||
f64.promote/f32
|
||||
i64.const 6
|
||||
tee_local 6
|
||||
f64.convert_u/i64
|
||||
i64.const 0
|
||||
tee_local 7
|
||||
f64.convert_u/i64
|
||||
f64.const 0x1p+3 (;=8;)
|
||||
tee_local 8
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add
|
||||
f64.add)
|
||||
(export \"type-local-i32\" (func 0))
|
||||
(export \"type-local-i64\" (func 1))
|
||||
(export \"type-local-f32\" (func 2))
|
||||
(export \"type-local-f64\" (func 3))
|
||||
(export \"type-param-i32\" (func 4))
|
||||
(export \"type-param-i64\" (func 5))
|
||||
(export \"type-param-f32\" (func 6))
|
||||
(export \"type-param-f64\" (func 7))
|
||||
(export \"type-mixed\" (func 8))
|
||||
(export \"write\" (func 9))
|
||||
(export \"result\" (func 10)))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
}
|
||||
|
||||
// Line 98
|
||||
fn l98_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l98_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-local-i32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(&vm_context);
|
||||
assert_eq!(result, 0 as i32);
|
||||
}
|
||||
|
||||
// Line 99
|
||||
fn l99_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l99_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-local-i64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(&VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(&vm_context);
|
||||
assert_eq!(result, 0 as i64);
|
||||
}
|
||||
|
||||
// Line 100
|
||||
fn l100_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l100_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-local-f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(&VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(&vm_context);
|
||||
assert_eq!(result, 0.0 as f32);
|
||||
}
|
||||
|
||||
// Line 101
|
||||
fn l101_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l101_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-local-f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(&VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(&vm_context);
|
||||
assert_eq!(result, 0.0 as f64);
|
||||
}
|
||||
|
||||
// Line 103
|
||||
fn l103_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l103_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-param-i32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(2 as i32, &vm_context);
|
||||
assert_eq!(result, 10 as i32);
|
||||
}
|
||||
|
||||
// Line 104
|
||||
fn l104_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l104_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-param-i64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(3 as i64, &vm_context);
|
||||
assert_eq!(result, 11 as i64);
|
||||
}
|
||||
|
||||
// Line 105
|
||||
fn l105_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l105_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-param-f32") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f32, &VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(4.4 as f32, &vm_context);
|
||||
assert_eq!(result, 11.1 as f32);
|
||||
}
|
||||
|
||||
// Line 106
|
||||
fn l106_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l106_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-param-f64") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(f64, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(5.5 as f64, &vm_context);
|
||||
assert_eq!(result, 12.2 as f64);
|
||||
}
|
||||
|
||||
// Line 109
|
||||
fn l109_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l109_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("type-mixed") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, f32, f64, i32, i32, &VmCtx) = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1 as i64, 2.2 as f32, 3.3 as f64, 4 as i32, 5 as i32, &vm_context);
|
||||
assert_eq!(result, ());
|
||||
}
|
||||
|
||||
// Line 115
|
||||
fn l115_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l115_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("write") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, f32, f64, i32, i32, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(1 as i64, 2.0 as f32, 3.3 as f64, 4 as i32, 5 as i32, &vm_context);
|
||||
assert_eq!(result, 56 as i64);
|
||||
}
|
||||
|
||||
// Line 122
|
||||
fn l122_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) {
|
||||
println!("Executing function {}", "l122_assert_return_invoke");
|
||||
let func_index = match result_object.module.info.exports.get("result") {
|
||||
Some(&Export::Function(index)) => index,
|
||||
_ => panic!("Function not found"),
|
||||
};
|
||||
let invoke_fn: fn(i64, f32, f64, i32, i32, &VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
|
||||
let result = invoke_fn(-1 as i64, -2.0 as f32, -3.3 as f64, -4 as i32, -5 as i32, &vm_context);
|
||||
assert_eq!(result, 34.8 as f64);
|
||||
}
|
||||
|
||||
// Line 132
|
||||
#[test]
|
||||
fn l132_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 126, 3, 2, 1, 0, 10, 10, 1, 8, 1, 1, 127, 65, 0, 34, 0, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 136
|
||||
#[test]
|
||||
fn l136_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 14, 1, 12, 1, 1, 125, 67, 0, 0, 0, 0, 34, 0, 69, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 140
|
||||
#[test]
|
||||
fn l140_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 124, 1, 126, 66, 0, 34, 1, 154, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 145
|
||||
#[test]
|
||||
fn l145_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 9, 1, 7, 1, 1, 127, 1, 34, 0, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 149
|
||||
#[test]
|
||||
fn l149_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 127, 67, 0, 0, 0, 0, 34, 0, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 153
|
||||
#[test]
|
||||
fn l153_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 17, 1, 15, 1, 1, 125, 68, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 157
|
||||
#[test]
|
||||
fn l157_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 19, 1, 17, 2, 1, 124, 1, 126, 68, 0, 0, 0, 0, 0, 0, 0, 0, 34, 1, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 165
|
||||
#[test]
|
||||
fn l165_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 126, 3, 2, 1, 0, 10, 6, 1, 4, 0, 32, 0, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 169
|
||||
#[test]
|
||||
fn l169_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 32, 0, 69, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 173
|
||||
#[test]
|
||||
fn l173_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 124, 126, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 32, 1, 154, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 178
|
||||
#[test]
|
||||
fn l178_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 1, 34, 0, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 182
|
||||
#[test]
|
||||
fn l182_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 11, 1, 9, 0, 67, 0, 0, 0, 0, 34, 0, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 186
|
||||
#[test]
|
||||
fn l186_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 15, 1, 13, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 190
|
||||
#[test]
|
||||
fn l190_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 124, 126, 0, 3, 2, 1, 0, 10, 15, 1, 13, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 34, 1, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 198
|
||||
#[test]
|
||||
fn l198_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 2, 1, 127, 1, 126, 32, 3, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 202
|
||||
#[test]
|
||||
fn l202_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 127, 1, 126, 32, 247, 164, 234, 6, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 207
|
||||
#[test]
|
||||
fn l207_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 127, 126, 0, 3, 2, 1, 0, 10, 6, 1, 4, 0, 32, 2, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 211
|
||||
#[test]
|
||||
fn l211_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 14, 1, 12, 2, 1, 127, 1, 126, 32, 247, 242, 206, 212, 2, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 216
|
||||
#[test]
|
||||
fn l216_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 10, 1, 8, 2, 1, 127, 1, 126, 32, 3, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 220
|
||||
#[test]
|
||||
fn l220_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 126, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 127, 1, 126, 32, 247, 168, 153, 102, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 225
|
||||
#[test]
|
||||
fn l225_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 127, 67, 0, 0, 0, 0, 34, 1, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 229
|
||||
#[test]
|
||||
fn l229_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 126, 127, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 125, 67, 0, 0, 0, 0, 34, 1, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
// Line 233
|
||||
#[test]
|
||||
fn l233_assert_invalid() {
|
||||
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 126, 0, 3, 2, 1, 0, 10, 12, 1, 10, 2, 1, 124, 1, 126, 66, 0, 34, 1, 11];
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), "WASM should not compile as is invalid");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_module_1() {
|
||||
let result_object = create_module_1();
|
||||
let vm_context = result_object.instance.generate_context();
|
||||
// We group the calls together
|
||||
l98_assert_return_invoke(&result_object, &vm_context);
|
||||
l99_assert_return_invoke(&result_object, &vm_context);
|
||||
l100_assert_return_invoke(&result_object, &vm_context);
|
||||
l101_assert_return_invoke(&result_object, &vm_context);
|
||||
l103_assert_return_invoke(&result_object, &vm_context);
|
||||
l104_assert_return_invoke(&result_object, &vm_context);
|
||||
l105_assert_return_invoke(&result_object, &vm_context);
|
||||
l106_assert_return_invoke(&result_object, &vm_context);
|
||||
l109_assert_return_invoke(&result_object, &vm_context);
|
||||
l115_assert_return_invoke(&result_object, &vm_context);
|
||||
l122_assert_return_invoke(&result_object, &vm_context);
|
||||
}
|
Loading…
Reference in New Issue
Block a user