wat4wasm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/examples/01-text/module-output.wat +228 -0
- package/examples/01-text/module.wat +9 -0
- package/examples/02-include/module-output.wat +22 -0
- package/examples/02-include/module.wat +3 -0
- package/examples/02-include/used-folder/included-file.wat +4 -0
- package/examples/03-ref.extern/module-output.wat +1537 -0
- package/examples/03-ref.extern/module.wat +33 -0
- package/examples/04-ref.func/module-output.wat +25 -0
- package/examples/04-ref.func/module.wat +8 -0
- package/examples/05-global.get/module-output.wat +991 -0
- package/examples/05-global.get/module.wat +26 -0
- package/examples/06-async/module-output.wat +661 -0
- package/examples/06-async/module.wat +15 -0
- package/examples/07-data/module-output.wasm +0 -0
- package/examples/07-data/module.wat +29 -0
- package/examples/07-data/used-folder/clear-text.txt +1 -0
- package/examples/07-data/used-folder/compile-this.wat +8 -0
- package/examples/08-reflectors/how-to/README.md +0 -0
- package/examples/08-reflectors/how-to/output-01-command.sh +0 -0
- package/examples/08-reflectors/how-to/output-02-command.sh +0 -0
- package/examples/08-reflectors/how-to/output-03-command.sh +0 -0
- package/examples/08-reflectors/how-to/output-04-command.sh +0 -0
- package/examples/08-reflectors/how-to/wat4wasm-outputs/01-module.wat +3 -0
- package/examples/08-reflectors/how-to/wat4wasm-outputs/02-module.wasm +3 -0
- package/examples/08-reflectors/how-to/wat4wasm-outputs/03-module.js +0 -0
- package/examples/08-reflectors/how-to/wat4wasm-outputs/04-module.html +0 -0
- package/examples/08-reflectors/module-output.wat +995 -0
- package/examples/08-reflectors/module.wat +108 -0
- package/examples/09-replaceAll/module-output.wat +347 -0
- package/examples/09-replaceAll/module.wat +68 -0
- package/examples/99-complex/module.wat +8 -0
- package/examples/99-complex/output.html +1 -0
- package/examples/99-complex/sub/worker.wat +2 -0
- package/examples/shell-usages.sh +60 -0
- package/lib/build +33 -0
- package/lib/clean.js +91 -0
- package/lib/cli.js +273 -0
- package/lib/helpers.js +567 -0
- package/lib/index.js +95 -0
- package/lib/processors/async.js +53 -0
- package/lib/processors/data.js +188 -0
- package/lib/processors/import.js +178 -0
- package/lib/processors/include.js +17 -0
- package/lib/processors/new.js +21 -0
- package/lib/processors/ref_extern.js +64 -0
- package/lib/processors/ref_func.js +44 -0
- package/lib/processors/replace_all.js +56 -0
- package/lib/processors/start.js +42 -0
- package/lib/processors/string.js +57 -0
- package/lib/processors/text.js +115 -0
- package/lib/processors/wat4wasm.js +285 -0
- package/lib/wat4beauty.js +320 -0
- package/package.json +30 -0
- package/ss-console.png +0 -0
- package/ss-terminal.png +0 -0
- package/test/boot.wat +5 -0
- package/test/test-output.html +1 -0
- package/test/test-output.js +27 -0
- package/test/test-output.wasm +0 -0
- package/test/test-sub.wat +4 -0
- package/test/test.wat +73 -0
- package/test/test_worker.js +1 -0
- package/wat4wasm +1998 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
(module
|
|
2
|
+
(func $01-console.*
|
|
3
|
+
|
|
4
|
+
(text "hello world")
|
|
5
|
+
(console $log<ext>)
|
|
6
|
+
|
|
7
|
+
(text "bye bye world") (i32.const -1)
|
|
8
|
+
(console $log<ext.i32>)
|
|
9
|
+
|
|
10
|
+
(NaN)
|
|
11
|
+
(console $warn<ext>)
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
(func $02-array.*
|
|
15
|
+
|
|
16
|
+
(array $of<ext>ext (string "🦋"))
|
|
17
|
+
(drop)
|
|
18
|
+
|
|
19
|
+
(array $isArray<ext>i32 (array))
|
|
20
|
+
(drop)
|
|
21
|
+
|
|
22
|
+
(array $fromAsync<ext>ext (array))
|
|
23
|
+
(drop)
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
(func $03-object.*
|
|
27
|
+
|
|
28
|
+
(object $is<ext.ext>i32 (null) (undefined))
|
|
29
|
+
(drop)
|
|
30
|
+
|
|
31
|
+
(object $is<ext.f32>i32 (NaN) (f32.const nan))
|
|
32
|
+
(drop)
|
|
33
|
+
|
|
34
|
+
(object $fromEntries<ext>ext (array))
|
|
35
|
+
(drop)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
(func $04-reflect.*
|
|
39
|
+
|
|
40
|
+
(reflect $set<ext.ext.ext>i32
|
|
41
|
+
(global.get $self) (text "name") (text "test")
|
|
42
|
+
)
|
|
43
|
+
(drop)
|
|
44
|
+
|
|
45
|
+
(reflect $get<ext.ext>ext
|
|
46
|
+
(self) (text "name")
|
|
47
|
+
)
|
|
48
|
+
(drop)
|
|
49
|
+
|
|
50
|
+
(reflect $apply<ext.ext.ext>ext
|
|
51
|
+
(ref.extern $Math.floor<ext>) (null) (array $of<f32>ext (f32.const 2.1))
|
|
52
|
+
)
|
|
53
|
+
(drop)
|
|
54
|
+
|
|
55
|
+
(reflect $construct<ext.ext>ext
|
|
56
|
+
(ref.extern $Object<ext>) (array)
|
|
57
|
+
)
|
|
58
|
+
(drop)
|
|
59
|
+
|
|
60
|
+
(reflect $ownKeys<ext>ext
|
|
61
|
+
(ref.extern $ArrayBuffer<ext>)
|
|
62
|
+
)
|
|
63
|
+
(drop)
|
|
64
|
+
|
|
65
|
+
(reflect $getPrototypeOf<ext>ext
|
|
66
|
+
(self)
|
|
67
|
+
)
|
|
68
|
+
(drop)
|
|
69
|
+
|
|
70
|
+
(reflect $getOwnPropertyDescriptor<ext.ext>ext
|
|
71
|
+
(self) (text "name")
|
|
72
|
+
)
|
|
73
|
+
(drop)
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
(func $05-string.*
|
|
77
|
+
|
|
78
|
+
(string $fromCharCode<i32.i32>ext (i32.const 46) (i32.const 47))
|
|
79
|
+
(drop)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
(func $06-number.*
|
|
83
|
+
|
|
84
|
+
(number $isSafeInteger<i32>i32 (i32.const 47))
|
|
85
|
+
(drop)
|
|
86
|
+
|
|
87
|
+
(number $isNaN<ext>i32 (self))
|
|
88
|
+
(drop)
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
(func $07-math.*
|
|
92
|
+
|
|
93
|
+
(math $max<f32.f32>f32 (f32.const 47.2) (f32.const 42.7))
|
|
94
|
+
(drop)
|
|
95
|
+
|
|
96
|
+
(math $random<>f32)
|
|
97
|
+
(drop)
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
(func $08-url.*
|
|
101
|
+
|
|
102
|
+
(url $createObjectURL<ext>ext (new $MediaSource))
|
|
103
|
+
(drop)
|
|
104
|
+
|
|
105
|
+
(url $revokeObjectURL<ext> (null))
|
|
106
|
+
(nop)
|
|
107
|
+
)
|
|
108
|
+
)
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
(module
|
|
2
|
+
(import "self" "self" (global $self externref))
|
|
3
|
+
(import "console" "log" (func $self.console.log<f32> (param f32) (result)))
|
|
4
|
+
(import "console" "log" (func $self.console.log<i32> (param i32) (result)))
|
|
5
|
+
(import "console" "log" (func $self.console.log<i64> (param i64) (result)))
|
|
6
|
+
(import "self" "Array" (func $self.Array<>ext (param) (result externref)))
|
|
7
|
+
(import "self" "Object" (func $self.Object<>ext (param) (result externref)))
|
|
8
|
+
(import "console" "log" (func $self.console.log<fun> (param funcref) (result)))
|
|
9
|
+
(import "String" "fromCharCode" (global $self.String.fromCharCode externref))
|
|
10
|
+
(import "console" "log" (func $self.console.log<ext> (param externref) (result)))
|
|
11
|
+
(import "Reflect" "set" (func $self.Reflect.set<ext.i32.i32> (param externref i32 i32) (result)))
|
|
12
|
+
(import "Reflect" "set" (func $self.Reflect.set<ext.i32.ext> (param externref i32 externref) (result)))
|
|
13
|
+
(import "Reflect" "get" (func $self.Reflect.get<ext.ext>ext (param externref externref) (result externref)))
|
|
14
|
+
(import "Reflect" "construct" (func $self.Reflect.construct<ext.ext>ext (param externref externref) (result externref)))
|
|
15
|
+
(import "Reflect" "apply" (func $self.Reflect.apply<ext.ext.ext>ext (param externref externref externref) (result externref)))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
(func $replace
|
|
19
|
+
(local $this f32)
|
|
20
|
+
|
|
21
|
+
(local.get 0)
|
|
22
|
+
(call $self.console.log<f32>)
|
|
23
|
+
|
|
24
|
+
(global.get $self)
|
|
25
|
+
(call $self.console.log<ext>)
|
|
26
|
+
|
|
27
|
+
(ref.null extern)
|
|
28
|
+
(call $self.console.log<ext>)
|
|
29
|
+
|
|
30
|
+
(ref.null func)
|
|
31
|
+
(call $self.console.log<fun>)
|
|
32
|
+
|
|
33
|
+
(i32.const 1)
|
|
34
|
+
(call $self.console.log<i32>)
|
|
35
|
+
|
|
36
|
+
(i32.const 0)
|
|
37
|
+
(call $self.console.log<i32>)
|
|
38
|
+
|
|
39
|
+
(table.get $wat4wasm (i32.const 2)) ;; $self.NaN<ext>
|
|
40
|
+
|
|
41
|
+
(call $self.console.log<ext>)
|
|
42
|
+
|
|
43
|
+
(f32.const nan)
|
|
44
|
+
(call $self.console.log<f32>)
|
|
45
|
+
|
|
46
|
+
(call $self.Array<>ext)
|
|
47
|
+
(call $self.console.log<ext>)
|
|
48
|
+
|
|
49
|
+
(call $self.Object<>ext)
|
|
50
|
+
(call $self.console.log<ext>)
|
|
51
|
+
|
|
52
|
+
(table.get $wat4wasm (i32.const 1)) ;; $self.undefined<ext>
|
|
53
|
+
|
|
54
|
+
(call $self.console.log<ext>)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
58
|
+
(global.get $self.String.fromCharCode)
|
|
59
|
+
(global.get $self)
|
|
60
|
+
(global.get $self)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
(call $self.console.log<ext>)
|
|
64
|
+
|
|
65
|
+
(local.get $this)
|
|
66
|
+
(call $self.console.log<f32>)
|
|
67
|
+
|
|
68
|
+
(global.get $wat4wasm)
|
|
69
|
+
(call $self.console.log<ext>)
|
|
70
|
+
|
|
71
|
+
(table.get $wat4wasm (i32.const 0))
|
|
72
|
+
(call $self.console.log<ext>)
|
|
73
|
+
|
|
74
|
+
(table.grow $wat4wasm (ref.null extern) (i32.const 0))
|
|
75
|
+
(drop)
|
|
76
|
+
|
|
77
|
+
(i32.const 2)
|
|
78
|
+
(call $self.console.log<i32>)
|
|
79
|
+
|
|
80
|
+
(f32.const -2)
|
|
81
|
+
(call $self.console.log<f32>)
|
|
82
|
+
|
|
83
|
+
(f32.const -2.2)
|
|
84
|
+
(call $self.console.log<f32>)
|
|
85
|
+
|
|
86
|
+
(f32.const +2.2)
|
|
87
|
+
(call $self.console.log<f32>)
|
|
88
|
+
|
|
89
|
+
(i64.const +2)
|
|
90
|
+
(call $self.console.log<i64>)
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
(global $wat4wasm (mut externref) (ref.null extern))
|
|
94
|
+
|
|
95
|
+
(table $wat4wasm 5 externref)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
(func $wat4wasm
|
|
101
|
+
(local $textDecoder externref)
|
|
102
|
+
(local $textDecoder.decode externref)
|
|
103
|
+
(local $Uint8Array externref)
|
|
104
|
+
(local $arguments externref)
|
|
105
|
+
(local $arrayBufferView externref)
|
|
106
|
+
(local $viewAt i32)
|
|
107
|
+
(local $offset i32)
|
|
108
|
+
(local $length i32)
|
|
109
|
+
(block $prepare
|
|
110
|
+
(local.set $textDecoder
|
|
111
|
+
(call $self.Reflect.construct<ext.ext>ext
|
|
112
|
+
(call $self.Reflect.get<ext.ext>ext
|
|
113
|
+
(global.get $self)
|
|
114
|
+
|
|
115
|
+
(block (; "TextDecoder" ;)
|
|
116
|
+
(result externref)
|
|
117
|
+
(global.set $wat4wasm (call $self.Array<>ext))
|
|
118
|
+
|
|
119
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 0) (i32.const 84))
|
|
120
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 1) (i32.const 101))
|
|
121
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 2) (i32.const 120))
|
|
122
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 3) (i32.const 116))
|
|
123
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 4) (i32.const 68))
|
|
124
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 5) (i32.const 101))
|
|
125
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 6) (i32.const 99))
|
|
126
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 7) (i32.const 111))
|
|
127
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 8) (i32.const 100))
|
|
128
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 9) (i32.const 101))
|
|
129
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 10) (i32.const 114))
|
|
130
|
+
|
|
131
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
132
|
+
(global.get $self.String.fromCharCode)
|
|
133
|
+
(ref.null extern)
|
|
134
|
+
(global.get $wat4wasm)
|
|
135
|
+
)
|
|
136
|
+
;; stacked
|
|
137
|
+
|
|
138
|
+
(global.set $wat4wasm (ref.null extern))
|
|
139
|
+
;; cleared
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
)
|
|
143
|
+
(global.get $self)
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
(local.set $textDecoder.decode
|
|
147
|
+
(call $self.Reflect.get<ext.ext>ext
|
|
148
|
+
(local.get $textDecoder)
|
|
149
|
+
|
|
150
|
+
(block (; "decode" ;)
|
|
151
|
+
(result externref)
|
|
152
|
+
(global.set $wat4wasm (call $self.Array<>ext))
|
|
153
|
+
|
|
154
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 0) (i32.const 100))
|
|
155
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 1) (i32.const 101))
|
|
156
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 2) (i32.const 99))
|
|
157
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 3) (i32.const 111))
|
|
158
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 4) (i32.const 100))
|
|
159
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 5) (i32.const 101))
|
|
160
|
+
|
|
161
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
162
|
+
(global.get $self.String.fromCharCode)
|
|
163
|
+
(ref.null extern)
|
|
164
|
+
(global.get $wat4wasm)
|
|
165
|
+
)
|
|
166
|
+
;; stacked
|
|
167
|
+
|
|
168
|
+
(global.set $wat4wasm (ref.null extern))
|
|
169
|
+
;; cleared
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
)
|
|
173
|
+
)
|
|
174
|
+
(local.set $Uint8Array
|
|
175
|
+
(call $self.Reflect.get<ext.ext>ext
|
|
176
|
+
(global.get $self)
|
|
177
|
+
|
|
178
|
+
(block (; "Uint8Array" ;)
|
|
179
|
+
(result externref)
|
|
180
|
+
(global.set $wat4wasm (call $self.Array<>ext))
|
|
181
|
+
|
|
182
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 0) (i32.const 85))
|
|
183
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 1) (i32.const 105))
|
|
184
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 2) (i32.const 110))
|
|
185
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 3) (i32.const 116))
|
|
186
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 4) (i32.const 56))
|
|
187
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 5) (i32.const 65))
|
|
188
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 6) (i32.const 114))
|
|
189
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 7) (i32.const 114))
|
|
190
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 8) (i32.const 97))
|
|
191
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 9) (i32.const 121))
|
|
192
|
+
|
|
193
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
194
|
+
(global.get $self.String.fromCharCode)
|
|
195
|
+
(ref.null extern)
|
|
196
|
+
(global.get $wat4wasm)
|
|
197
|
+
)
|
|
198
|
+
;; stacked
|
|
199
|
+
|
|
200
|
+
(global.set $wat4wasm (ref.null extern))
|
|
201
|
+
;; cleared
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
)
|
|
207
|
+
;;secure zero heap for memory.init
|
|
208
|
+
(i32.const 0)
|
|
209
|
+
(i32.load (i32.const 0))
|
|
210
|
+
;; offset and value stacked now
|
|
211
|
+
(block $oninit
|
|
212
|
+
(block $decodeText/4:3
|
|
213
|
+
(local.set $viewAt (i32.const 0))
|
|
214
|
+
(local.set $offset (i32.const 4))
|
|
215
|
+
(local.set $length (i32.const 3))
|
|
216
|
+
(local.set $arguments (call $self.Array<>ext))
|
|
217
|
+
|
|
218
|
+
(call $self.Reflect.set<ext.i32.i32>
|
|
219
|
+
(local.get $arguments) (i32.const 0) (local.get $length)
|
|
220
|
+
)
|
|
221
|
+
(local.set $arrayBufferView
|
|
222
|
+
(call $self.Reflect.construct<ext.ext>ext
|
|
223
|
+
(local.get $Uint8Array)
|
|
224
|
+
(local.get $arguments)
|
|
225
|
+
)
|
|
226
|
+
)
|
|
227
|
+
(loop $length--
|
|
228
|
+
(if (local.get $length)
|
|
229
|
+
(then
|
|
230
|
+
(memory.init $wat4wasm
|
|
231
|
+
(i32.const 0)
|
|
232
|
+
(local.get $offset)
|
|
233
|
+
(i32.const 1)
|
|
234
|
+
)
|
|
235
|
+
(call $self.Reflect.set<ext.i32.i32>
|
|
236
|
+
(local.get $arrayBufferView)
|
|
237
|
+
(local.get $viewAt)
|
|
238
|
+
(i32.load8_u (i32.const 0))
|
|
239
|
+
)
|
|
240
|
+
(local.set $viewAt (i32.add (local.get $viewAt) (i32.const 1)))
|
|
241
|
+
(local.set $offset (i32.add (local.get $offset) (i32.const 1)))
|
|
242
|
+
(local.set $length (i32.sub (local.get $length) (i32.const 1)))
|
|
243
|
+
(br $length--)
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
(local.set $arguments (call $self.Array<>ext))
|
|
248
|
+
(call $self.Reflect.set<ext.i32.ext>
|
|
249
|
+
(local.get $arguments)
|
|
250
|
+
(i32.const 0)
|
|
251
|
+
(local.get $arrayBufferView)
|
|
252
|
+
)
|
|
253
|
+
(table.set $wat4wasm (i32.const 3)
|
|
254
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
255
|
+
(local.get $textDecoder.decode)
|
|
256
|
+
(local.get $textDecoder)
|
|
257
|
+
(local.get $arguments) ;; NaN
|
|
258
|
+
))
|
|
259
|
+
)
|
|
260
|
+
(block $decodeText/7:9
|
|
261
|
+
(local.set $viewAt (i32.const 0))
|
|
262
|
+
(local.set $offset (i32.const 7))
|
|
263
|
+
(local.set $length (i32.const 9))
|
|
264
|
+
(local.set $arguments (call $self.Array<>ext))
|
|
265
|
+
|
|
266
|
+
(call $self.Reflect.set<ext.i32.i32>
|
|
267
|
+
(local.get $arguments) (i32.const 0) (local.get $length)
|
|
268
|
+
)
|
|
269
|
+
(local.set $arrayBufferView
|
|
270
|
+
(call $self.Reflect.construct<ext.ext>ext
|
|
271
|
+
(local.get $Uint8Array)
|
|
272
|
+
(local.get $arguments)
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
(loop $length--
|
|
276
|
+
(if (local.get $length)
|
|
277
|
+
(then
|
|
278
|
+
(memory.init $wat4wasm
|
|
279
|
+
(i32.const 0)
|
|
280
|
+
(local.get $offset)
|
|
281
|
+
(i32.const 1)
|
|
282
|
+
)
|
|
283
|
+
(call $self.Reflect.set<ext.i32.i32>
|
|
284
|
+
(local.get $arrayBufferView)
|
|
285
|
+
(local.get $viewAt)
|
|
286
|
+
(i32.load8_u (i32.const 0))
|
|
287
|
+
)
|
|
288
|
+
(local.set $viewAt (i32.add (local.get $viewAt) (i32.const 1)))
|
|
289
|
+
(local.set $offset (i32.add (local.get $offset) (i32.const 1)))
|
|
290
|
+
(local.set $length (i32.sub (local.get $length) (i32.const 1)))
|
|
291
|
+
(br $length--)
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
)
|
|
295
|
+
(local.set $arguments (call $self.Array<>ext))
|
|
296
|
+
(call $self.Reflect.set<ext.i32.ext>
|
|
297
|
+
(local.get $arguments)
|
|
298
|
+
(i32.const 0)
|
|
299
|
+
(local.get $arrayBufferView)
|
|
300
|
+
)
|
|
301
|
+
(table.set $wat4wasm (i32.const 4)
|
|
302
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
303
|
+
(local.get $textDecoder.decode)
|
|
304
|
+
(local.get $textDecoder)
|
|
305
|
+
(local.get $arguments) ;; undefined
|
|
306
|
+
))
|
|
307
|
+
)
|
|
308
|
+
)
|
|
309
|
+
(block $ontextready
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
(block $self.undefined<ext>
|
|
313
|
+
(table.set $wat4wasm (i32.const 1)
|
|
314
|
+
(call $self.Reflect.get<ext.ext>ext
|
|
315
|
+
(global.get $self)
|
|
316
|
+
(table.get $wat4wasm (i32.const 4));; undefined
|
|
317
|
+
;; undefined
|
|
318
|
+
)
|
|
319
|
+
))
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
(block $self.NaN<ext>
|
|
323
|
+
(table.set $wat4wasm (i32.const 2)
|
|
324
|
+
(call $self.Reflect.get<ext.ext>ext
|
|
325
|
+
(global.get $self)
|
|
326
|
+
(table.get $wat4wasm (i32.const 3));; NaN
|
|
327
|
+
;; NaN
|
|
328
|
+
)
|
|
329
|
+
))
|
|
330
|
+
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
;; restore zero heap value
|
|
335
|
+
(i32.store (; stack stack ;))
|
|
336
|
+
(nop)
|
|
337
|
+
|
|
338
|
+
(call $replace)
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
(data $wat4wasm "\10\00\00\00\4e\61\4e\75\6e\64\65\66\69\6e\65\64")
|
|
343
|
+
|
|
344
|
+
(memory $wat4wasm 1)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
(module
|
|
2
|
+
(main $replace
|
|
3
|
+
(local $this f32)
|
|
4
|
+
|
|
5
|
+
(this)
|
|
6
|
+
(console $log<f32>)
|
|
7
|
+
|
|
8
|
+
(self)
|
|
9
|
+
(console $log<ext>)
|
|
10
|
+
|
|
11
|
+
(null)
|
|
12
|
+
(console $log<ext>)
|
|
13
|
+
|
|
14
|
+
(func)
|
|
15
|
+
(console $log<fun>)
|
|
16
|
+
|
|
17
|
+
(true)
|
|
18
|
+
(console $log<i32>)
|
|
19
|
+
|
|
20
|
+
(false)
|
|
21
|
+
(console $log<i32>)
|
|
22
|
+
|
|
23
|
+
(NaN)
|
|
24
|
+
(console $log<ext>)
|
|
25
|
+
|
|
26
|
+
(nan)
|
|
27
|
+
(console $log<f32>)
|
|
28
|
+
|
|
29
|
+
(array)
|
|
30
|
+
(console $log<ext>)
|
|
31
|
+
|
|
32
|
+
(object)
|
|
33
|
+
(console $log<ext>)
|
|
34
|
+
|
|
35
|
+
(undefined)
|
|
36
|
+
(console $log<ext>)
|
|
37
|
+
|
|
38
|
+
(string)
|
|
39
|
+
(console $log<ext>)
|
|
40
|
+
|
|
41
|
+
(lget $this)
|
|
42
|
+
(console $log<f32>)
|
|
43
|
+
|
|
44
|
+
(gget $wat4wasm)
|
|
45
|
+
(console $log<ext>)
|
|
46
|
+
|
|
47
|
+
(tget $wat4wasm i32(0))
|
|
48
|
+
(console $log<ext>)
|
|
49
|
+
|
|
50
|
+
(grow $wat4wasm (null) i32(0))
|
|
51
|
+
(drop)
|
|
52
|
+
|
|
53
|
+
i32(2)
|
|
54
|
+
(console $log<i32>)
|
|
55
|
+
|
|
56
|
+
f32(- 2)
|
|
57
|
+
(console $log<f32>)
|
|
58
|
+
|
|
59
|
+
f32(-2.2)
|
|
60
|
+
(console $log<f32>)
|
|
61
|
+
|
|
62
|
+
f32(+ 2.2)
|
|
63
|
+
(console $log<f32>)
|
|
64
|
+
|
|
65
|
+
i64(+2)
|
|
66
|
+
(console $log<i64>)
|
|
67
|
+
)
|
|
68
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<body onload="[WebAssembly.instantiate(Uint8Array.of(0,97,115,109,1,0,0,0,1,33,6,96,0,1,111,96,3,111,127,127,0,96,3,111,127,111,0,96,2,111,111,1,111,96,3,111,111,111,1,111,96,0,0,2,128,1,8,4,115,101,108,102,4,115,101,108,102,3,111,0,4,115,101,108,102,5,65,114,114,97,121,0,0,6,83,116,114,105,110,103,12,102,114,111,109,67,104,97,114,67,111,100,101,3,111,0,7,82,101,102,108,101,99,116,3,115,101,116,0,1,7,82,101,102,108,101,99,116,3,115,101,116,0,2,7,82,101,102,108,101,99,116,3,103,101,116,0,3,7,82,101,102,108,101,99,116,9,99,111,110,115,116,114,117,99,116,0,3,7,82,101,102,108,101,99,116,5,97,112,112,108,121,0,4,3,3,2,5,5,4,4,1,111,0,4,5,3,1,0,1,6,6,1,111,1,208,111,11,12,1,2,10,218,4,2,7,0,65,1,37,0,26,11,207,4,2,5,111,3,127,2,64,35,0,2,111,16,0,36,2,35,2,65,0,65,212,0,16,1,35,2,65,1,65,229,0,16,1,35,2,65,2,65,248,0,16,1,35,2,65,3,65,244,0,16,1,35,2,65,4,65,196,0,16,1,35,2,65,5,65,229,0,16,1,35,2,65,6,65,227,0,16,1,35,2,65,7,65,239,0,16,1,35,2,65,8,65,228,0,16,1,35,2,65,9,65,229,0,16,1,35,2,65,10,65,242,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,35,0,16,4,33,0,32,0,2,111,16,0,36,2,35,2,65,0,65,228,0,16,1,35,2,65,1,65,229,0,16,1,35,2,65,2,65,227,0,16,1,35,2,65,3,65,239,0,16,1,35,2,65,4,65,228,0,16,1,35,2,65,5,65,229,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,33,1,35,0,2,111,16,0,36,2,35,2,65,0,65,213,0,16,1,35,2,65,1,65,233,0,16,1,35,2,65,2,65,238,0,16,1,35,2,65,3,65,244,0,16,1,35,2,65,4,65,56,16,1,35,2,65,5,65,193,0,16,1,35,2,65,6,65,242,0,16,1,35,2,65,7,65,242,0,16,1,35,2,65,8,65,225,0,16,1,35,2,65,9,65,249,0,16,1,35,1,208,111,35,2,16,5,208,111,36,2,11,16,3,33,2,11,65,0,65,0,40,2,0,2,64,2,64,65,0,33,5,65,4,33,6,65,10,33,7,16,0,33,3,32,3,65,0,32,7,16,1,32,2,32,3,16,4,33,4,3,64,32,7,4,64,65,0,32,6,65,1,252,8,1,0,32,4,32,5,65,0,45,0,0,16,1,32,5,65,1,106,33,5,32,6,65,1,106,33,6,32,7,65,1,107,33,7,12,1,11,11,16,0,33,3,32,3,65,0,32,4,16,2,65,3,32,1,32,0,32,3,16,5,38,0,11,11,2,64,2,64,65,2,35,0,65,3,37,0,16,3,38,0,11,11,2,64,65,1,2,111,16,0,36,2,35,2,65,0,65,45,16,1,65,2,37,0,35,2,16,4,36,2,65,45,4,64,65,0,65,0,41,3,0,2,64,65,0,65,45,54,2,0,3,64,65,0,40,2,0,4,64,65,0,65,0,40,2,0,65,1,107,54,2,0,65,4,65,0,40,2,0,65,1,252,8,0,0,35,2,65,0,40,2,0,65,4,45,0,0,16,1,12,1,11,11,11,55,3,0,11,35,2,208,111,36,2,11,38,0,11,54,2,0,1,16,6,11,11,64,2,1,45,0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,4,1,2,0,11,0,19,4,110,97,109,101,1,7,1,0,4,102,111,114,107,2,3,1,0,0,1,14,14,0,0,0,85,105,110,116,56,65,114,114,97,121,0,163,3,4,110,97,109,101,1,198,1,8,0,15,115,101,108,102,46,65,114,114,97,121,60,62,101,120,116,1,29,115,101,108,102,46,82,101,102,108,101,99,116,46,115,101,116,60,101,120,116,46,105,51,50,46,105,51,50,62,2,29,115,101,108,102,46,82,101,102,108,101,99,116,46,115,101,116,60,101,120,116,46,105,51,50,46,101,120,116,62,3,28,115,101,108,102,46,82,101,102,108,101,99,116,46,103,101,116,60,101,120,116,46,101,120,116,62,101,120,116,4,34,115,101,108,102,46,82,101,102,108,101,99,116,46,99,111,110,115,116,114,117,99,116,60,101,120,116,46,101,120,116,62,101,120,116,5,34,115,101,108,102,46,82,101,102,108,101,99,116,46,97,112,112,108,121,60,101,120,116,46,101,120,116,46,101,120,116,62,101,120,116,6,4,105,110,105,116,7,8,119,97,116,52,119,97,115,109,2,114,8,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,8,0,11,116,101,120,116,68,101,99,111,100,101,114,1,18,116,101,120,116,68,101,99,111,100,101,114,46,100,101,99,111,100,101,2,10,85,105,110,116,56,65,114,114,97,121,3,9,97,114,103,117,109,101,110,116,115,4,15,97,114,114,97,121,66,117,102,102,101,114,86,105,101,119,5,6,118,105,101,119,65,116,6,6,111,102,102,115,101,116,7,6,108,101,110,103,116,104,5,11,1,0,8,119,97,116,52,119,97,115,109,6,11,1,0,8,119,97,116,52,119,97,115,109,7,43,3,0,4,115,101,108,102,1,24,115,101,108,102,46,83,116,114,105,110,103,46,102,114,111,109,67,104,97,114,67,111,100,101,2,8,119,97,116,52,119,97,115,109,9,24,2,0,11,119,111,114,107,101,114,46,119,97,115,109,1,8,119,97,116,52,119,97,115,109), self).then(wasm => [console.warn(wasm)]),Reflect.set(document.head, String.fromCharCode(105,110,110,101,114,72,84,77,76), String.fromCharCode(60,108,105,110,107,32,114,101,108,61,105,99,111,110,32,104,114,101,102,61,100,97,116,97,58,110,117,108,108,62))]"></body>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
cd 01-text
|
|
2
|
+
cp ../../wat4wasm wat4wasm
|
|
3
|
+
./wat4wasm --input=module.wat --output=module-output.wat
|
|
4
|
+
rm wat4wasm
|
|
5
|
+
cd ..
|
|
6
|
+
|
|
7
|
+
cd 02-include
|
|
8
|
+
cp ../../wat4wasm wat4wasm
|
|
9
|
+
./wat4wasm --input=module.wat --output=module-output.wat
|
|
10
|
+
rm wat4wasm
|
|
11
|
+
cd ..
|
|
12
|
+
|
|
13
|
+
cd 03-ref.extern
|
|
14
|
+
cp ../../wat4wasm wat4wasm
|
|
15
|
+
./wat4wasm --input=module.wat --output=module-output.wat
|
|
16
|
+
rm wat4wasm
|
|
17
|
+
cd ..
|
|
18
|
+
|
|
19
|
+
cd 04-ref.func
|
|
20
|
+
cp ../../wat4wasm wat4wasm
|
|
21
|
+
./wat4wasm --input=module.wat --output=module-output.wat
|
|
22
|
+
rm wat4wasm
|
|
23
|
+
cd ..
|
|
24
|
+
|
|
25
|
+
cd 05-global.get
|
|
26
|
+
cp ../../wat4wasm wat4wasm
|
|
27
|
+
./wat4wasm --input=module.wat --output=module-output.wat
|
|
28
|
+
rm wat4wasm
|
|
29
|
+
cd ..
|
|
30
|
+
|
|
31
|
+
cd 06-async
|
|
32
|
+
cp ../../wat4wasm wat4wasm
|
|
33
|
+
./wat4wasm --input=module.wat --output=module-output.wat
|
|
34
|
+
rm wat4wasm
|
|
35
|
+
cd ..
|
|
36
|
+
|
|
37
|
+
cd 07-data
|
|
38
|
+
cp ../../wat4wasm wat4wasm
|
|
39
|
+
./wat4wasm --input=module.wat --output=module-output.wat --wat2wasm=wat2wasm
|
|
40
|
+
rm wat4wasm
|
|
41
|
+
cd ..
|
|
42
|
+
|
|
43
|
+
cd 08-reflectors
|
|
44
|
+
cp ../../wat4wasm wat4wasm
|
|
45
|
+
./wat4wasm --input=module.wat --output=module-output.wat
|
|
46
|
+
rm wat4wasm
|
|
47
|
+
cd ..
|
|
48
|
+
|
|
49
|
+
cd 09-replaceAll
|
|
50
|
+
cp ../../wat4wasm wat4wasm
|
|
51
|
+
./wat4wasm --input=module.wat --output=module-output.wat
|
|
52
|
+
rm wat4wasm
|
|
53
|
+
cd ..
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
cd 99-complex
|
|
57
|
+
cp ../../wat4wasm wat4wasm
|
|
58
|
+
./wat4wasm --input=module.wat --output=output.html --wat2wasm=wat2wasm --keep-window --keep-chrome-global --keep-document --wasm-from-numbers-array --log-instance --debug-names --enable-threads
|
|
59
|
+
rm wat4wasm
|
|
60
|
+
cd ..
|
package/lib/build
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
|
|
5
|
+
const headers = [`#!/usr/bin/env node`, `import fs from "fs";`, `import cp, { spawnSync } from "child_process";`].join("\n").concat("\n\n");
|
|
6
|
+
const index_js = fs.readFileSync("index.js", "utf8").split(/\n+/).filter(l => !l.startsWith("import") && !l.startsWith("#")).join("\n").concat("\n\n");
|
|
7
|
+
const cli_js = fs.readFileSync("cli.js", "utf8").split(/\n+/).filter(l => !l.startsWith("import")).join("\n").replaceAll("export ", "").concat("\n\n");
|
|
8
|
+
const helpers_js = fs.readFileSync("helpers.js", "utf8").split(/\n+/).filter(l => !l.startsWith("import") && !l.startsWith("export")).join("\n").concat("\n\n");
|
|
9
|
+
const clean_js = fs.readFileSync("clean.js", "utf8").split(/\n+/).filter(l => !l.startsWith("import")).join("\n").concat("\n\n").replaceAll("export default function", "function clean");
|
|
10
|
+
const imports = fs.readFileSync("index.js", "utf8").split(/\n+/).filter(l => l.startsWith("import") && l.includes("processors/")).map(i => i.split(/^import|\s+|from|\"|\.js/g).filter(Boolean))
|
|
11
|
+
.map(([NAME, path]) => [NAME, process.cwd().concat(path.substring(1).concat(".js"))])
|
|
12
|
+
.map(([NAME, path]) => [NAME, fs.readFileSync(path, "utf8")])
|
|
13
|
+
.map(([NAME, code]) => code.split(/\n+/).filter(l => !l.startsWith("import")).join("\n").replaceAll("export default function", "function " + NAME).replaceAll("export ", ""))
|
|
14
|
+
.join("\n\n");
|
|
15
|
+
|
|
16
|
+
const wat4beauty = fs.readFileSync("wat4beauty.js", "utf8");
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync("../wat4wasm") === true) {
|
|
19
|
+
fs.unlinkSync("../wat4wasm")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fs.writeFileSync("../wat4wasm",
|
|
23
|
+
headers
|
|
24
|
+
.concat(wat4beauty)
|
|
25
|
+
.concat(helpers_js)
|
|
26
|
+
.concat(imports)
|
|
27
|
+
.concat(clean_js)
|
|
28
|
+
.concat(cli_js)
|
|
29
|
+
.concat(index_js)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
fs.chmodSync("../wat4wasm", '755');
|