File: types.wast

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 48,492 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (337 lines) | stat: -rw-r--r-- 8,324 bytes parent folder | download | duplicates (3)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
(component
  (type string)
  (type (func (param "a" string)))
  (type $r (record (field "x" (result)) (field "y" string)))
  (type $u (variant (case "r" $r) (case "s" string)))
  (type $e (result $u (error u32)))
  (type (result $u))
  (type (result (error $u)))
  (type (result))

  (type (func (param "a" $e) (result (option $r))))

  (type (variant
    (case "a" string)
    (case "b" u32)
    (case "c" float32)
    (case "d" float64)
  ))

  (type $errno (enum "a" "b" "e"))
  (type (list $errno))
  (type $oflags (flags "read" "write" "exclusive"))
  (type (tuple $oflags $errno $r))

  ;; primitives in functions
  (type (func
    (param "a" bool)
    (param "b" u8)
    (param "c" s8)
    (param "d" u16)
    (param "e" s16)
    (param "f" u32)
    (param "g" s32)
    (param "h" u64)
    (param "i" s64)
    (param "j" char)
    (param "k" string)
  ))

  ;; primitives in types
  (type bool)
  (type u8)
  (type s8)
  (type u16)
  (type s16)
  (type u32)
  (type s32)
  (type u64)
  (type s64)
  (type char)
  (type string)
)

(component
  (type $empty (func))
  (type (func (param "a" string) (result u32)))
  (type (component))
  (core type (module))
  (core type (func))
  (type (instance))

  (type (component
    (import "x" (func (type $empty)))
    (import "y" (func))
    (import "z" (component))

    (type $t (instance))

    (export "a" (core module))
    (export "b" (instance (type $t)))
  ))

  (type (instance
    (export "x" (func (type $empty)))
    (export "y" (func))
    (export "z" (component))

    (type $t (instance))

    (export "a" (core module))
    (export "b" (instance (type $t)))
  ))

  (core type (module
    (import "" "" (func (param i32)))
    (import "" "1" (func (result i32)))
    (export "1" (global i32))
    (export "2" (memory 1))
    (export "3" (table 1 funcref))
  ))
)

;; outer core aliases work
(component $C
  (core type $f (func))
  (core type $m (module))

  (component $C2
    (alias outer $C $f (core type $my_f))
    (import "a" (core module (type $m)))
    (import "x" (core module
      (alias outer $C2 $my_f (type $my_f))
      (import "" "1" (func (type $my_f)))
    ))
  )
)

;; type exports work
(component $C
  (component $C2
    (type string)
    (export "x" (type 0))
  )
  (instance (instantiate 0))
  (alias export 0 "x" (type))
  (export "x" (type 0))
)

(component
  (core module $m (func (export "") (param i32) (result i32) local.get 0))
  (core instance $m (instantiate $m))
  (func (export "i-to-b") (param "a" u32) (result bool) (canon lift (core func $m "")))
  (func (export "i-to-u8") (param "a" u32) (result u8) (canon lift (core func $m "")))
  (func (export "i-to-s8") (param "a" u32) (result s8) (canon lift (core func $m "")))
  (func (export "i-to-u16") (param "a" u32) (result u16) (canon lift (core func $m "")))
  (func (export "i-to-s16") (param "a" u32) (result s16) (canon lift (core func $m "")))
)
(assert_return (invoke "i-to-b" (u32.const 0)) (bool.const false))
(assert_return (invoke "i-to-b" (u32.const 1)) (bool.const true))
(assert_return (invoke "i-to-b" (u32.const 2)) (bool.const true))
(assert_return (invoke "i-to-u8" (u32.const 0x00)) (u8.const 0))
(assert_return (invoke "i-to-u8" (u32.const 0x01)) (u8.const 1))
(assert_return (invoke "i-to-u8" (u32.const 0xf01)) (u8.const 1))
(assert_return (invoke "i-to-u8" (u32.const 0xf00)) (u8.const 0))
(assert_return (invoke "i-to-s8" (u32.const 0xffffffff)) (s8.const -1))
(assert_return (invoke "i-to-s8" (u32.const 127)) (s8.const 127))
(assert_return (invoke "i-to-u16" (u32.const 0)) (u16.const 0))
(assert_return (invoke "i-to-u16" (u32.const 1)) (u16.const 1))
(assert_return (invoke "i-to-u16" (u32.const 0xffffffff)) (u16.const 0xffff))
(assert_return (invoke "i-to-s16" (u32.const 0)) (s16.const 0))
(assert_return (invoke "i-to-s16" (u32.const 1)) (s16.const 1))
(assert_return (invoke "i-to-s16" (u32.const 0xffffffff)) (s16.const -1))

(assert_invalid
  (component
    (type $t1 string)
    (type $t2 (list $t1))
    (type $t3 (list $t2))
    (type $t4 (list $t3))
    (type $t5 (list $t4))
    (type $t6 (list $t5))
    (type $t7 (list $t6))
    (type $t8 (list $t7))
    (type $t9 (list $t8))
    (type $t10 (list $t9))
    (type $t11 (list $t10))
    (type $t12 (list $t11))
    (type $t13 (list $t12))
    (type $t14 (list $t13))
    (type $t15 (list $t14))
    (type $t16 (list $t15))
    (type $t17 (list $t16))
    (type $t18 (list $t17))
    (type $t19 (list $t18))
    (type $t20 (list $t19))
    (type $t21 (list $t20))
    (type $t22 (list $t21))
    (type $t23 (list $t22))
    (type $t24 (list $t23))
    (type $t25 (list $t24))
    (type $t26 (list $t25))
    (type $t27 (list $t26))
    (type $t28 (list $t27))
    (type $t29 (list $t28))
    (type $t30 (list $t29))
    (type $t31 (list $t30))
    (type $t32 (list $t31))
    (type $t33 (list $t32))
    (type $t34 (list $t33))
    (type $t35 (list $t34))
    (type $t36 (list $t35))
    (type $t37 (list $t36))
    (type $t38 (list $t37))
    (type $t39 (list $t38))
    (type $t40 (list $t39))
    (type $t41 (list $t40))
    (type $t42 (list $t41))
    (type $t43 (list $t42))
    (type $t44 (list $t43))
    (type $t45 (list $t44))
    (type $t46 (list $t45))
    (type $t47 (list $t46))
    (type $t48 (list $t47))
    (type $t49 (list $t48))
    (type $t50 (list $t49))
    (type $t51 (list $t50))
    (type $t52 (list $t51))
    (type $t53 (list $t52))
    (type $t54 (list $t53))
    (type $t55 (list $t54))
    (type $t56 (list $t55))
    (type $t57 (list $t56))
    (type $t58 (list $t57))
    (type $t59 (list $t58))
    (type $t60 (list $t59))
    (type $t61 (list $t60))
    (type $t62 (list $t61))
    (type $t63 (list $t62))
    (type $t64 (list $t63))
    (type $t65 (list $t64))
    (type $t66 (list $t65))
    (type $t67 (list $t66))
    (type $t68 (list $t67))
    (type $t69 (list $t68))
    (type $t70 (list $t69))
    (type $t71 (list $t70))
    (type $t72 (list $t71))
    (type $t73 (list $t72))
    (type $t74 (list $t73))
    (type $t75 (list $t74))
    (type $t76 (list $t75))
    (type $t77 (list $t76))
    (type $t78 (list $t77))
    (type $t79 (list $t78))
    (type $t80 (list $t79))
    (type $t81 (list $t80))
    (type $t82 (list $t81))
    (type $t83 (list $t82))
    (type $t84 (list $t83))
    (type $t85 (list $t84))
    (type $t86 (list $t85))
    (type $t87 (list $t86))
    (type $t88 (list $t87))
    (type $t89 (list $t88))
    (type $t90 (list $t89))
    (type $t91 (list $t90))
    (type $t92 (list $t91))
    (type $t93 (list $t92))
    (type $t94 (list $t93))
    (type $t95 (list $t94))
    (type $t96 (list $t95))
    (type $t97 (list $t96))
    (type $t98 (list $t97))
    (type $t99 (list $t98))
    (type $t100 (list $t99))
    (type $t101 (list $t100))
    (export "t" (type $t101))
  )
  "type nesting is too deep")

(component
  (type (instance
    (export $x "x" (instance
      (type $t u32)
      (export "y" (type (eq $t)))
    ))
    (alias export $x "y" (type $t))
    (export "my-y" (type (eq $t)))
  ))

  (type (component
    (import "x" (instance $x
      (type $t u32)
      (export "y" (type (eq $t)))
    ))
    (alias export $x "y" (type $t))
    (export "my-y" (type (eq $t)))
  ))
)

(component
  (type $t u32)
  (export $t2 "t" (type $t))
  (type $r (record (field "x" $t2)))
  (export "r" (type $r))
)

(component
  (component
    (import "x" (instance $i
      (type $i u32)
      (export "i" (type (eq $i)))
    ))
    (alias export $i "i" (type $i))
    (export "i" (type $i))
  )
)

(component
  (type $u u32)
  (instance $i
    (export "i" (type $u))
  )
  (alias export $i "i" (type $i))
  (export "i" (type $i))
)

(component
  (component $c
    (type $t u32)
    (export "t" (type $t))
  )
  (instance $c (instantiate $c))
  (export "i" (type $c "t"))
)

(component
  (component $c
    (import "x" (component $c
      (type $t u32)
      (export "t" (type (eq $t)))
    ))
    (instance $c (instantiate $c))
    (export "i" (type $c "t"))
  )

  (component $x
    (type $t u32)
    (export "t" (type $t))
  )

  (instance $c (instantiate $c (with "x" (component $x))))
)

(component
  (type $t1 u64)
  (import "a" (type $t2 (eq $t1)))
  (import "b" (type $t3 (eq $t2)))
)

(component
  (import "a" (instance
    (type $t1 u64)
    (export $t2 "a" (type (eq $t1)))
    (export "b" (type (eq $t2)))
  ))
)