forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_copy.wast
63 lines (51 loc) · 1.66 KB
/
table_copy.wast
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
(module
(func $f (param i32 i32 i32) (result i32) (local.get 0))
(func $g (param i32 i32 i32) (result i32) (local.get 1))
(func $h (param i32 i32 i32) (result i32) (local.get 2))
;; Indices: 0 1 2 3 4 5 6 7 8
(table funcref (elem $f $g $h $f $g $h $f $g $h))
;; After table.copy: $g $h $f
(func (export "copy") (param i32 i32 i32)
local.get 0
local.get 1
local.get 2
table.copy)
(func (export "call") (param i32 i32 i32 i32) (result i32)
local.get 0
local.get 1
local.get 2
local.get 3
call_indirect (param i32 i32 i32) (result i32))
)
;; Call $f at 0
(assert_return
(invoke "call" (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 0))
(i32.const 1))
;; Call $g at 1
(assert_return
(invoke "call" (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 1))
(i32.const 1))
;; Call $h at 2
(assert_return
(invoke "call" (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 2))
(i32.const 1))
;; Do a `table.copy` to rearrange the elements. Copy from 4..7 to 0..3.
(invoke "copy" (i32.const 0) (i32.const 4) (i32.const 3))
;; Call $g at 0
(assert_return
(invoke "call" (i32.const 0) (i32.const 1) (i32.const 0) (i32.const 0))
(i32.const 1))
;; Call $h at 1
(assert_return
(invoke "call" (i32.const 0) (i32.const 0) (i32.const 1) (i32.const 1))
(i32.const 1))
;; Call $f at 2
(assert_return
(invoke "call" (i32.const 1) (i32.const 0) (i32.const 0) (i32.const 2))
(i32.const 1))
;; Copying up to the end does not trap.
(invoke "copy" (i32.const 7) (i32.const 0) (i32.const 2))
;; Copying past the end traps.
(assert_trap
(invoke "copy" (i32.const 7) (i32.const 0) (i32.const 3))
"undefined element")