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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Özgür, Dr.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# wat4wasm
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<br />
|
|
5
|
+
<strong><code>wat4wasm</code></strong>
|
|
6
|
+
<br />
|
|
7
|
+
<br />
|
|
8
|
+
sweet <em><strong>WebAssembly</strong></em> sugars
|
|
9
|
+
<br />
|
|
10
|
+
Designed to make you faster, smarter and aesthetically pleasing WebAssembly coder.
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License"></a>
|
|
15
|
+
<img src="https://img.shields.io/badge/node-14.0.0-green.svg" alt="Node.js Version">
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
## ...
|
|
19
|
+
<img src="ss-console.png">
|
|
20
|
+
<hr />
|
|
21
|
+
<img src="ss-terminal.png">
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
<p align="center">
|
|
29
|
+
<a target="_blank" href="https://gemini.google.com/">Gemini</a> and <a target="_blank" href="https://github.com/tokbuga">Özgür</a> created with 💚
|
|
30
|
+
</p>
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
(module
|
|
2
|
+
(import "self" "self" (global $self externref))
|
|
3
|
+
(import "self" "Array" (func $self.Array<>ext (param) (result externref)))
|
|
4
|
+
(import "String" "fromCharCode" (global $self.String.fromCharCode externref))
|
|
5
|
+
(import "Reflect" "set" (func $self.Reflect.set<ext.i32.i32> (param externref i32 i32) (result)))
|
|
6
|
+
(import "Reflect" "set" (func $self.Reflect.set<ext.i32.ext> (param externref i32 externref) (result)))
|
|
7
|
+
(import "Reflect" "get" (func $self.Reflect.get<ext.ext>ext (param externref externref) (result externref)))
|
|
8
|
+
(import "Reflect" "construct" (func $self.Reflect.construct<ext.ext>ext (param externref externref) (result externref)))
|
|
9
|
+
(import "Reflect" "apply" (func $self.Reflect.apply<ext.ext.ext>ext (param externref externref externref) (result externref)))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
(func $main
|
|
13
|
+
(table.get $wat4wasm (i32.const 1));; hello world
|
|
14
|
+
|
|
15
|
+
(drop)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
(block (; "hello world" ;)
|
|
19
|
+
(result externref)
|
|
20
|
+
(global.set $wat4wasm (call $self.Array<>ext))
|
|
21
|
+
|
|
22
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 0) (i32.const 104))
|
|
23
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 1) (i32.const 101))
|
|
24
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 2) (i32.const 108))
|
|
25
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 3) (i32.const 108))
|
|
26
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 4) (i32.const 111))
|
|
27
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 5) (i32.const 32))
|
|
28
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 6) (i32.const 119))
|
|
29
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 7) (i32.const 111))
|
|
30
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 8) (i32.const 114))
|
|
31
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 9) (i32.const 108))
|
|
32
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 10) (i32.const 100))
|
|
33
|
+
|
|
34
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
35
|
+
(global.get $self.String.fromCharCode)
|
|
36
|
+
(ref.null extern)
|
|
37
|
+
(global.get $wat4wasm)
|
|
38
|
+
)
|
|
39
|
+
;; stacked
|
|
40
|
+
|
|
41
|
+
(global.set $wat4wasm (ref.null extern))
|
|
42
|
+
;; cleared
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
(drop)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
(global $wat4wasm (mut externref) (ref.null extern))
|
|
49
|
+
|
|
50
|
+
(table $wat4wasm 2 externref)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
(func $wat4wasm
|
|
56
|
+
(local $textDecoder externref)
|
|
57
|
+
(local $textDecoder.decode externref)
|
|
58
|
+
(local $Uint8Array externref)
|
|
59
|
+
(local $arguments externref)
|
|
60
|
+
(local $arrayBufferView externref)
|
|
61
|
+
(local $viewAt i32)
|
|
62
|
+
(local $offset i32)
|
|
63
|
+
(local $length i32)
|
|
64
|
+
(block $prepare
|
|
65
|
+
(local.set $textDecoder
|
|
66
|
+
(call $self.Reflect.construct<ext.ext>ext
|
|
67
|
+
(call $self.Reflect.get<ext.ext>ext
|
|
68
|
+
(global.get $self)
|
|
69
|
+
|
|
70
|
+
(block (; "TextDecoder" ;)
|
|
71
|
+
(result externref)
|
|
72
|
+
(global.set $wat4wasm (call $self.Array<>ext))
|
|
73
|
+
|
|
74
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 0) (i32.const 84))
|
|
75
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 1) (i32.const 101))
|
|
76
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 2) (i32.const 120))
|
|
77
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 3) (i32.const 116))
|
|
78
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 4) (i32.const 68))
|
|
79
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 5) (i32.const 101))
|
|
80
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 6) (i32.const 99))
|
|
81
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 7) (i32.const 111))
|
|
82
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 8) (i32.const 100))
|
|
83
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 9) (i32.const 101))
|
|
84
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 10) (i32.const 114))
|
|
85
|
+
|
|
86
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
87
|
+
(global.get $self.String.fromCharCode)
|
|
88
|
+
(ref.null extern)
|
|
89
|
+
(global.get $wat4wasm)
|
|
90
|
+
)
|
|
91
|
+
;; stacked
|
|
92
|
+
|
|
93
|
+
(global.set $wat4wasm (ref.null extern))
|
|
94
|
+
;; cleared
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
)
|
|
98
|
+
(global.get $self)
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
(local.set $textDecoder.decode
|
|
102
|
+
(call $self.Reflect.get<ext.ext>ext
|
|
103
|
+
(local.get $textDecoder)
|
|
104
|
+
|
|
105
|
+
(block (; "decode" ;)
|
|
106
|
+
(result externref)
|
|
107
|
+
(global.set $wat4wasm (call $self.Array<>ext))
|
|
108
|
+
|
|
109
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 0) (i32.const 100))
|
|
110
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 1) (i32.const 101))
|
|
111
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 2) (i32.const 99))
|
|
112
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 3) (i32.const 111))
|
|
113
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 4) (i32.const 100))
|
|
114
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 5) (i32.const 101))
|
|
115
|
+
|
|
116
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
117
|
+
(global.get $self.String.fromCharCode)
|
|
118
|
+
(ref.null extern)
|
|
119
|
+
(global.get $wat4wasm)
|
|
120
|
+
)
|
|
121
|
+
;; stacked
|
|
122
|
+
|
|
123
|
+
(global.set $wat4wasm (ref.null extern))
|
|
124
|
+
;; cleared
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
(local.set $Uint8Array
|
|
130
|
+
(call $self.Reflect.get<ext.ext>ext
|
|
131
|
+
(global.get $self)
|
|
132
|
+
|
|
133
|
+
(block (; "Uint8Array" ;)
|
|
134
|
+
(result externref)
|
|
135
|
+
(global.set $wat4wasm (call $self.Array<>ext))
|
|
136
|
+
|
|
137
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 0) (i32.const 85))
|
|
138
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 1) (i32.const 105))
|
|
139
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 2) (i32.const 110))
|
|
140
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 3) (i32.const 116))
|
|
141
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 4) (i32.const 56))
|
|
142
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 5) (i32.const 65))
|
|
143
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 6) (i32.const 114))
|
|
144
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 7) (i32.const 114))
|
|
145
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 8) (i32.const 97))
|
|
146
|
+
(call $self.Reflect.set<ext.i32.i32> (global.get $wat4wasm) (i32.const 9) (i32.const 121))
|
|
147
|
+
|
|
148
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
149
|
+
(global.get $self.String.fromCharCode)
|
|
150
|
+
(ref.null extern)
|
|
151
|
+
(global.get $wat4wasm)
|
|
152
|
+
)
|
|
153
|
+
;; stacked
|
|
154
|
+
|
|
155
|
+
(global.set $wat4wasm (ref.null extern))
|
|
156
|
+
;; cleared
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
;;secure zero heap for memory.init
|
|
163
|
+
(i32.const 0)
|
|
164
|
+
(i32.load (i32.const 0))
|
|
165
|
+
;; offset and value stacked now
|
|
166
|
+
(block $oninit
|
|
167
|
+
(block $decodeText/4:11
|
|
168
|
+
(local.set $viewAt (i32.const 0))
|
|
169
|
+
(local.set $offset (i32.const 4))
|
|
170
|
+
(local.set $length (i32.const 11))
|
|
171
|
+
(local.set $arguments (call $self.Array<>ext))
|
|
172
|
+
|
|
173
|
+
(call $self.Reflect.set<ext.i32.i32>
|
|
174
|
+
(local.get $arguments) (i32.const 0) (local.get $length)
|
|
175
|
+
)
|
|
176
|
+
(local.set $arrayBufferView
|
|
177
|
+
(call $self.Reflect.construct<ext.ext>ext
|
|
178
|
+
(local.get $Uint8Array)
|
|
179
|
+
(local.get $arguments)
|
|
180
|
+
)
|
|
181
|
+
)
|
|
182
|
+
(loop $length--
|
|
183
|
+
(if (local.get $length)
|
|
184
|
+
(then
|
|
185
|
+
(memory.init $wat4wasm
|
|
186
|
+
(i32.const 0)
|
|
187
|
+
(local.get $offset)
|
|
188
|
+
(i32.const 1)
|
|
189
|
+
)
|
|
190
|
+
(call $self.Reflect.set<ext.i32.i32>
|
|
191
|
+
(local.get $arrayBufferView)
|
|
192
|
+
(local.get $viewAt)
|
|
193
|
+
(i32.load8_u (i32.const 0))
|
|
194
|
+
)
|
|
195
|
+
(local.set $viewAt (i32.add (local.get $viewAt) (i32.const 1)))
|
|
196
|
+
(local.set $offset (i32.add (local.get $offset) (i32.const 1)))
|
|
197
|
+
(local.set $length (i32.sub (local.get $length) (i32.const 1)))
|
|
198
|
+
(br $length--)
|
|
199
|
+
)
|
|
200
|
+
)
|
|
201
|
+
)
|
|
202
|
+
(local.set $arguments (call $self.Array<>ext))
|
|
203
|
+
(call $self.Reflect.set<ext.i32.ext>
|
|
204
|
+
(local.get $arguments)
|
|
205
|
+
(i32.const 0)
|
|
206
|
+
(local.get $arrayBufferView)
|
|
207
|
+
)
|
|
208
|
+
(table.set $wat4wasm (i32.const 1)
|
|
209
|
+
(call $self.Reflect.apply<ext.ext.ext>ext
|
|
210
|
+
(local.get $textDecoder.decode)
|
|
211
|
+
(local.get $textDecoder)
|
|
212
|
+
(local.get $arguments) ;; hello world
|
|
213
|
+
))
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
;; restore zero heap value
|
|
220
|
+
(i32.store (; stack stack ;))
|
|
221
|
+
(nop)
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
(data $wat4wasm "\0f\00\00\00\68\65\6c\6c\6f\20\77\6f\72\6c\64")
|
|
226
|
+
|
|
227
|
+
(memory $wat4wasm 1)
|
|
228
|
+
)
|