1 ;; Test files can define multiple modules. Test that implementations treat
2 ;; each module independently from the other.
5 (func (export "foo") (result i32) (i32.const 0))
8 (assert_return (invoke "foo") (i32.const 0))
10 ;; Another module, same function name, different contents.
13 (func (export "foo") (result i32) (i32.const 1))
16 (assert_return (invoke "foo") (i32.const 1))
20 ;; Test that we can use the empty string as a symbol.
21 (func (export "") (result f32) (f32.const 0x1.91p+2))
23 ;; Test that we can use names beginning with a digit.
24 (func (export "0") (result f32) (f32.const 0x1.97p+2))
26 ;; Test that we can use names beginning with an underscore.
27 (func (export "_") (result f32) (f32.const 0x1.98p+2))
29 ;; Test that we can use names beginning with a dollar sign.
30 (func (export "$") (result f32) (f32.const 0x1.99p+2))
32 ;; Test that we can use names beginning with an at sign.
33 (func (export "@") (result f32) (f32.const 0x2.00p+2))
35 ;; Test that we can use non-alphanumeric names.
36 (func (export "~!@#$%^&*()_+`-={}|[]\\:\";'<>?,./ ") (result f32) (f32.const 0x1.96p+2))
38 ;; Test that we can use names that have special meaning in JS.
39 (func (export "NaN") (result f32) (f32.const 0x2.01p+2))
40 (func (export "Infinity") (result f32) (f32.const 0x2.02p+2))
41 (func (export "if") (result f32) (f32.const 0x2.03p+2))
43 ;; Test that we can use common libc names without conflict.
44 (func (export "malloc") (result f32) (f32.const 0x1.92p+2))
46 ;; Test that we can use some libc hidden names without conflict.
47 (func (export "_malloc") (result f32) (f32.const 0x1.93p+2))
48 (func (export "__malloc") (result f32) (f32.const 0x1.94p+2))
51 (assert_return (invoke "") (f32.const 0x1.91p+2))
52 (assert_return (invoke "malloc") (f32.const 0x1.92p+2))
53 (assert_return (invoke "_malloc") (f32.const 0x1.93p+2))
54 (assert_return (invoke "__malloc") (f32.const 0x1.94p+2))
55 (assert_return (invoke "~!@#$%^&*()_+`-={}|[]\\:\";'<>?,./ ") (f32.const 0x1.96p+2))
56 (assert_return (invoke "0") (f32.const 0x1.97p+2))
57 (assert_return (invoke "_") (f32.const 0x1.98p+2))
58 (assert_return (invoke "$") (f32.const 0x1.99p+2))
59 (assert_return (invoke "@") (f32.const 0x2.00p+2))
60 (assert_return (invoke "NaN") (f32.const 0x2.01p+2))
61 (assert_return (invoke "Infinity") (f32.const 0x2.02p+2))
62 (assert_return (invoke "if") (f32.const 0x2.03p+2))
65 ;; Test that we can use indices instead of names to reference imports,
66 ;; exports, functions and parameters.
67 (import "spectest" "print" (func (param i32)))
68 (func (import "spectest" "print") (param i32))
69 (func (param i32) (param i32)
70 (call 0 (get_local 0))
71 (call 1 (get_local 1))
73 (export "print32" (func 2))
76 (invoke "print32" (i32.const 42) (i32.const 123))