blob: f735f7c375362acb14c7e41ca29e794143b09e2e (
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
|
(module
(type $vec (array i8))
(type $mvec (array (mut i8)))
(data "\00\01\02\03\04")
(func $new (export "new") (result (ref $vec))
(array.new_data $vec 0 (i32.const 1) (i32.const 3))
)
(func $get (param $i i32) (param $v (ref $vec)) (result i32)
(array.get_u $vec (local.get $v) (local.get $i))
)
(func (export "get") (param $i i32) (result i32)
(call $get (local.get $i) (call $new))
)
(func $set_get (param $i i32) (param $v (ref $mvec)) (param $y i32) (result i32)
(array.set $mvec (local.get $v) (local.get $i) (local.get $y))
(array.get_u $mvec (local.get $v) (local.get $i))
)
(func (export "set_get") (param $i i32) (param $y i32) (result i32)
(call $set_get (local.get $i)
(array.new_data $mvec 0 (i32.const 1) (i32.const 3))
(local.get $y)
)
)
(func $len (param $v (ref array)) (result i32)
(array.len (local.get $v))
)
(func (export "len") (result i32)
(call $len (call $new))
)
)
(assert_return (invoke "get" (i32.const 0)) (i32.const 1))
(assert_return (invoke "set_get" (i32.const 1) (i32.const 7)) (i32.const 7))
(assert_return (invoke "len") (i32.const 3))
(module
(type $vec (array i32))
(type $mvec (array (mut i8)))
(data "\00\01\00\00\00\02\00\00\00\03\00\00\00\04\00\00\00")
(func $new (export "new") (result (ref $vec))
(array.new_data $vec 0 (i32.const 1) (i32.const 3))
)
(func $get (param $i i32) (param $v (ref $vec)) (result i32)
(array.get $vec (local.get $v) (local.get $i))
)
(func (export "get") (param $i i32) (result i32)
(call $get (local.get $i) (call $new))
)
(func $set_get (param $i i32) (param $v (ref $mvec)) (param $y i32) (result i32)
(array.set $mvec (local.get $v) (local.get $i) (local.get $y))
(array.get $mvec (local.get $v) (local.get $i))
)
(func (export "set_get") (param $i i32) (param $y i32) (result i32)
(call $set_get (local.get $i)
(array.new_data $mvec 0 (i32.const 1) (i32.const 3))
(local.get $y)
)
)
(func $len (param $v (ref array)) (result i32)
(array.len (local.get $v))
)
(func (export "len") (result i32)
(call $len (call $new))
)
)
(assert_return (invoke "get" (i32.const 0)) (i32.const 1))
(assert_return (invoke "set_get" (i32.const 1) (i32.const 7)) (i32.const 7))
(assert_return (invoke "len") (i32.const 3))
(module
(type $vec (array i32))
(data "")
(func $new-huge (export "new-huge") (result (ref $vec))
(array.new_data $vec 0 (i32.const 4) (i32.const -1))
)
)
(assert_trap (invoke "new-huge") "out of bounds segment access in array.new_data")
|