watr 2.4.1 → 3.1.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/package.json +6 -3
- package/readme.md +40 -41
- package/src/compile.js +673 -389
- package/src/const.js +30 -33
- package/src/encode.js +48 -12
- package/src/parse.js +15 -7
- package/src/util.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "watr",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Ligth & fast WAT compiler",
|
|
5
5
|
"main": "watr.js",
|
|
6
6
|
"exports": {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"test": "node test"
|
|
14
|
+
"test": "node test",
|
|
15
|
+
"postinstall": "git submodule update --init --recursive"
|
|
15
16
|
},
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
@@ -30,7 +31,9 @@
|
|
|
30
31
|
"wabt",
|
|
31
32
|
"pretty-print",
|
|
32
33
|
"webassembly",
|
|
33
|
-
"wasm-text"
|
|
34
|
+
"wasm-text",
|
|
35
|
+
"wast",
|
|
36
|
+
"wat-compiler"
|
|
34
37
|
],
|
|
35
38
|
"author": "Dmitry Iv",
|
|
36
39
|
"license": "MIT",
|
package/readme.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# watr [](https://github.com/audio-lab/watr/actions/workflows/test.js.yml) [](https://bundlephobia.com/package/watr) [](https://npmjs.org/watr)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Useful for
|
|
3
|
+
Light & fast WASM compiler. An alternative to [wabt/wat2wasm](https://github.com/AssemblyScript/wabt.js) or [spec/wast]().<br/>
|
|
4
|
+
Useful for high-level languages or dynamic (in-browser) compilation.<br>
|
|
5
|
+
Supports full [spec text syntax](https://webassembly.github.io/spec/core/text/index.html) and [official testsuite](https://github.com/WebAssembly/testsuite).
|
|
5
6
|
|
|
6
7
|
## Usage
|
|
7
8
|
|
|
@@ -10,7 +11,7 @@ Useful for hi-level languages or dynamic (in-browser) compilation.<br>
|
|
|
10
11
|
Compile wasm text or syntax tree into wasm binary.
|
|
11
12
|
|
|
12
13
|
```js
|
|
13
|
-
import
|
|
14
|
+
import { compile } from 'watr'
|
|
14
15
|
|
|
15
16
|
const buffer = compile(`(func (export "double")
|
|
16
17
|
(param f64) (result f64)
|
|
@@ -23,6 +24,20 @@ const {double} = instance.exports
|
|
|
23
24
|
double(108) // 216
|
|
24
25
|
```
|
|
25
26
|
|
|
27
|
+
### Parse
|
|
28
|
+
|
|
29
|
+
Parse input wasm text into syntax tree.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { parse } from 'watr'
|
|
33
|
+
|
|
34
|
+
parse(`(func (export "double") (param f64) (result f64) (f64.mul (local.get 0) (f64.const 2)))`)
|
|
35
|
+
// [
|
|
36
|
+
// 'func', ['export', '"double"'], ['param', 'f64'], ['result', 'f64'],
|
|
37
|
+
// ['f64.mul', ['local.get', 0], ['f64.const', 2]]
|
|
38
|
+
// ]
|
|
39
|
+
```
|
|
40
|
+
|
|
26
41
|
### Print
|
|
27
42
|
|
|
28
43
|
Format input wasm text or syntax tree into minified or pretty form.
|
|
@@ -54,69 +69,53 @@ print(src, {
|
|
|
54
69
|
// (func (export "double")(param f64)(result f64)(f64.mul (local.get 0)(f64.const 2)))
|
|
55
70
|
```
|
|
56
71
|
|
|
57
|
-
### Parse
|
|
58
|
-
|
|
59
|
-
Parse input wasm text into syntax tree.
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
import { parse } from 'watr'
|
|
63
|
-
|
|
64
|
-
parse(`(func (export "double") (param f64) (result f64) (f64.mul (local.get 0) (f64.const 2)))`)
|
|
65
|
-
// [
|
|
66
|
-
// 'func', ['export', '"double"'], ['param', 'f64'], ['result', 'f64'],
|
|
67
|
-
// ['f64.mul', ['local.get', 0], ['f64.const', 2]]
|
|
68
|
-
// ]
|
|
69
|
-
```
|
|
70
|
-
|
|
71
72
|
<!-- See [REPL](https://audio-lab.github.io/watr/repl.html).-->
|
|
72
73
|
|
|
73
74
|
## Status
|
|
74
75
|
|
|
75
76
|
* [x] core
|
|
77
|
+
* [x] [mutable globals](https://github.com/WebAssembly/mutable-global)
|
|
78
|
+
* [x] [extended const](https://github.com/WebAssembly/extended-const/blob/main/proposals/extended-const/Overview.md)
|
|
79
|
+
* [x] [nontrapping float to int](https://github.com/WebAssembly/nontrapping-float-to-int-conversions)
|
|
80
|
+
* [x] [sign extension](https://github.com/WebAssembly/sign-extension-ops)
|
|
76
81
|
* [x] [multi-value](https://github.com/WebAssembly/spec/blob/master/proposals/multi-value/Overview.md)
|
|
77
82
|
* [x] [bulk memory ops](https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md)
|
|
83
|
+
* [x] [multiple memories](https://github.com/WebAssembly/multi-memory/blob/master/proposals/multi-memory/Overview.md)
|
|
78
84
|
* [x] [simd](https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md)
|
|
79
|
-
* [x] [
|
|
80
|
-
* [
|
|
81
|
-
* [
|
|
85
|
+
* [x] [relaxed simd](https://github.com/WebAssembly/relaxed-simd)
|
|
86
|
+
* [x] [fixed-width simd](https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md)
|
|
87
|
+
* [x] [tail_call](https://github.com/WebAssembly/tail-call)
|
|
88
|
+
* [x] [ref types](https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md)
|
|
89
|
+
* [x] [func refs](https://github.com/WebAssembly/function-references/blob/main/proposals/function-references/Overview.md)
|
|
82
90
|
* [ ] [gc](https://github.com/WebAssembly/gc)
|
|
91
|
+
* [ ] [exceptions](https://github.com/WebAssembly/exception-handling)
|
|
92
|
+
* [ ] [memory64](https://github.com/WebAssembly/memory64)
|
|
93
|
+
* [ ] [annotations](https://github.com/WebAssembly/annotations)
|
|
94
|
+
* [ ] [code_metadata](https://github.com/WebAssembly/tool-conventions/blob/main/CodeMetadata.md)
|
|
95
|
+
* [ ] [js strings](https://github.com/WebAssembly/js-string-builtins/blob/main/proposals/js-string-builtins/Overview.md)
|
|
83
96
|
|
|
84
97
|
## Alternatives
|
|
85
98
|
|
|
86
|
-
| Size (gzipped) | Performance
|
|
99
|
+
| Size (gzipped) | Performance
|
|
87
100
|
---|---|---
|
|
88
|
-
watr |
|
|
89
|
-
[
|
|
90
|
-
[wabt](https://github.com/
|
|
91
|
-
|
|
101
|
+
watr | 6.2 kb | 11.6 op/s
|
|
102
|
+
[spec/wast.js](https://github.com/WebAssembly/spec/tree/main/interpreter#javascript-library) | 216 kb | 7.1 op/s
|
|
103
|
+
[wabt](https://github.com/WebAssembly/wabt) | 282 kb | 2.3 op/s
|
|
104
|
+
[wat-compiler](https://github.com/stagas/wat-compiler) | 7.7 kb | 1.34 op/s
|
|
92
105
|
|
|
93
106
|
<!--
|
|
94
107
|
## Projects using watr
|
|
95
108
|
|
|
96
|
-
* [
|
|
109
|
+
* [piezo](https://github.com/audio-lab/piezo) – audio processing language
|
|
97
110
|
-->
|
|
98
111
|
|
|
112
|
+
<!--
|
|
99
113
|
## Useful links
|
|
100
114
|
|
|
101
115
|
* [watlings](https://github.com/EmNudge/watlings) – learn Wasm text by examples.
|
|
102
116
|
* [MDN: control flow](https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow)
|
|
103
117
|
* [WASM reference manual](https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#loop)
|
|
104
118
|
* [WASM binary encoding](https://github.com/WebAssembly/design/blob/main/BinaryEncoding.md)
|
|
105
|
-
|
|
106
|
-
<!--
|
|
107
|
-
## Refs
|
|
108
|
-
|
|
109
|
-
* [mdn wasm text format](https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format)
|
|
110
|
-
* [wasm reference manual](https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md)
|
|
111
|
-
* [wabt source search](https://github.com/WebAssembly/wabt/search?p=5&q=then)
|
|
112
|
-
* [wat control flow](https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow)
|
|
113
|
-
* [ontouchstart wasm book](https://ontouchstart.pages.dev/chapter_wasm_binary)
|
|
114
|
-
* [hackernoon](https://web.archive.org/web/20210215171830/https://hackernoon.com/webassembly-binary-format-explained-part-2-hj1t33yp?source=rss)
|
|
115
|
-
* [webassemblyjs](https://github.com/xtuc/webassemblyjs)
|
|
116
|
-
* [chasm](https://github.com/ColinEberhardt/chasm/blob/master/src/encoding.ts)
|
|
117
|
-
* [WebBS](https://github.com/j-s-n/WebBS)
|
|
118
|
-
* [leb128a](https://github.com/minhducsun2002/leb128/blob/master/src/index.ts)
|
|
119
|
-
* [leb128b](https://github.com/shmishtopher/wasm-LEB128/tree/master/esm)
|
|
120
119
|
-->
|
|
121
120
|
|
|
122
121
|
<p align=center><a href="https://github.com/krsnzd/license/">🕉</a></p>
|