blob: 1189fffa144e8c80b4e2cf1dc11f8da729cfc873 (
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
|
;; expected = R"---(;; This is a polyglot C++/WAT file.
;; Comment lines are ignored and not expected in the disassembler output.
(module
;; Structs.
(type $type0 (struct))
(type $type1 (struct (field $field0 i32)))
(type $type2 (struct (field $field0 (mut i32)) (field $field1 (mut i64))))
(type $type3 (struct (field $field0 i8) (field $field1 (mut i16))))
;; Arrays.
(type $type4 (array (field i64)))
(type $type5 (array (field (mut i64))))
(type $type6 (array (field i8)))
;; References to other types, mutual recursion.
(type $type7 (struct (field $field0 (ref $type0))))
;; TODO: rec-groups are supported in the binary format, but they are not
;; printed yet. Once that is implemented in the disassembler, uncomment:
;; (rec
(type $type8 (struct (field $field0 (ref $type9))))
(type $type9 (struct (field $field0 (ref $type8))))
;; )
;; Subtyping constraints.
;; TODO: Change to `sub` keyword, once that is standardized.
(type $type10 (struct_subtype (field $field0 i32) $type0))
;; Globals using reference types.
(global $env.imported_global (;0;) (import "env" "imported_global") (ref $type7))
(global $env.another_global (;1;) (import "env" "another_global") (ref $type8))
(global $global2 anyref (ref.null none))
(global $global3 (mut eqref) (ref.null none))
;; Function with GC instructions and taking GC types as parameters.
(func $func0 (param $var0 (ref $type1)) (param $var1 eqref)
;; Structs.
struct.new_default $type1
struct.get $type1 $field0
drop
struct.new_default $type2
i32.const 0
struct.set $type2 $field0
struct.new_default $type3
struct.get_s $type3 $field0
drop
struct.new_default $type3
struct.get_u $type3 $field1
drop
;; Arrays.
array.new_fixed $type4 0
drop
i32.const 0
array.new_default $type4
array.len
drop
i64.const 0
i32.const 0
array.new $type4
i32.const 0
array.get $type4
drop
i32.const 0
array.new_default $type5
i32.const 0
i64.const 0
array.set $type5
i32.const 0
array.new_default $type6
i32.const 0
array.get_s $type6
drop
i32.const 0
array.new_default $type6
i32.const 0
array.get_u $type6
drop
;; References.
local.get $var1
local.get $var1
ref.eq
drop
local.get $var1
ref.test $type0
drop
local.get $var0
ref.cast $type0
drop
local.get $var0
ref.test null $type0
drop
local.get $var0
ref.cast null $type0
drop
;; Branches.
block $label0 (result (ref $type1))
local.get $var0
br_on_non_null $label0
local.get $var0
br_on_cast $label0 $type1
drop
local.get $var0
br_on_cast_fail $label0 $type1
drop
;; TODO: Once `br_on_cast null` is implemented, uncomment:
;; local.get $var0
;; br_on_cast $label0 null $type1
local.get $var0
end $label0
drop
)
)
;;)---";
|