summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/spec/get_local.wast
blob: e1f9625b96d41da7e883103f3f1eed9e7534e7f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
;; Test `get_local` operator

(module
  ;; Typing

  (func (export "type-local-i32") (result i32) (local i32) (get_local 0))
  (func (export "type-local-i64") (result i64) (local i64) (get_local 0))
  (func (export "type-local-f32") (result f32) (local f32) (get_local 0))
  (func (export "type-local-f64") (result f64) (local f64) (get_local 0))

  (func (export "type-param-i32") (param i32) (result i32) (get_local 0))
  (func (export "type-param-i64") (param i64) (result i64) (get_local 0))
  (func (export "type-param-f32") (param f32) (result f32) (get_local 0))
  (func (export "type-param-f64") (param f64) (result f64) (get_local 0))

  (func (export "type-mixed") (param i64 f32 f64 i32 i32)
    (local f32 i64 i64 f64)
    (drop (i64.eqz (get_local 0)))
    (drop (f32.neg (get_local 1)))
    (drop (f64.neg (get_local 2)))
    (drop (i32.eqz (get_local 3)))
    (drop (i32.eqz (get_local 4)))
    (drop (f32.neg (get_local 5)))
    (drop (i64.eqz (get_local 6)))
    (drop (i64.eqz (get_local 7)))
    (drop (f64.neg (get_local 8)))
  )

  ;; Reading

  (func (export "read") (param i64 f32 f64 i32 i32) (result f64)
    (local f32 i64 i64 f64)
    (set_local 5 (f32.const 5.5))
    (set_local 6 (i64.const 6))
    (set_local 8 (f64.const 8))
    (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)
                  )
                )
              )
            )
          )
        )
      )
    )
  )
)

(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 2))
(assert_return (invoke "type-param-i64" (i64.const 3)) (i64.const 3))
(assert_return (invoke "type-param-f32" (f32.const 4.4)) (f32.const 4.4))
(assert_return (invoke "type-param-f64" (f64.const 5.5)) (f64.const 5.5))

(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 "read"
    (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) (get_local 0)))
  "type mismatch"
)
(assert_invalid
  (module (func $type-local-num-vs-num (local f32) (i32.eqz (get_local 0))))
  "type mismatch"
)
(assert_invalid
  (module (func $type-local-num-vs-num (local f64 i64) (f64.neg (get_local 1))))
  "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"
)


;; 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"
)