watr 2.1.1 → 2.1.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watr",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Ligth & fast WAT compiler",
5
5
  "main": "watr.js",
6
6
  "exports": {
package/readme.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # watr [![test](https://github.com/audio-lab/watr/actions/workflows/test.js.yml/badge.svg)](https://github.com/audio-lab/watr/actions/workflows/test.js.yml) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/watr/latest?color=brightgreen&label=gzip)](https://bundlephobia.com/package/watr)
2
2
 
3
- > Bare minimum wasm text compiler & formatter.
4
-
5
- Light & fast alternative for [wat2wasm](https://github.com/AssemblyScript/wabt.js), useful for hi-level languages or dynamic (in-browser) compilation.<br>
3
+ Bare minimum wasm text compiler & formatter, light & fast alternative for [wat2wasm](https://github.com/AssemblyScript/wabt.js).<br/>
4
+ Useful for hi-level languages or dynamic (in-browser) compilation.<br>
6
5
 
7
6
  <!-- See [REPL](https://audio-lab.github.io/watr/repl.html).-->
8
7
 
@@ -101,12 +100,15 @@ parse(`(func (export "double") (param f64) (result f64) (f64.mul (local.get 0) (
101
100
 
102
101
  No floating HEX support, eg. `(f32.const 0x1.fffffep+127)`.
103
102
 
103
+ <!--
104
104
  ## Projects using watr
105
105
 
106
106
  * [auro](https://github.com/audio-lab/auro) – audio processing language
107
+ -->
107
108
 
108
109
  ## Useful links
109
110
 
111
+ * [watlings](https://github.com/EmNudge/watlings) – learn Wasm text by examples.
110
112
  * [MDN: control flow](https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow)
111
113
  * [WASM reference manual](https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#loop)
112
114
  * [WASM binary encoding](https://github.com/WebAssembly/design/blob/main/BinaryEncoding.md)
package/src/compile.js CHANGED
@@ -4,7 +4,12 @@ import parse from './parse.js'
4
4
 
5
5
  const OP_END = 0xb, OP_I32_CONST = 0x41, OP_I64_CONST = 0x42, OP_F32_CONST = 0x43, OP_F64_CONST = 0x44
6
6
 
7
- // convert wat tree to wasm binary
7
+ /**
8
+ * Converts a WebAssembly Text Format (WAT) tree to a WebAssembly binary format (Wasm).
9
+ *
10
+ * @param {string|Array} nodes - The WAT tree or string to be compiled to Wasm binary.
11
+ * @returns {Uint8Array} The compiled Wasm binary data.
12
+ */
8
13
  export default (nodes) => {
9
14
  if (typeof nodes === 'string') nodes = parse(nodes);
10
15
 
package/src/parse.js CHANGED
@@ -1,6 +1,12 @@
1
1
  const OPAREN = 40, CPAREN = 41, OBRACK = 91, CBRACK = 93, SPACE = 32, DQUOTE = 34, PERIOD = 46,
2
2
  _0 = 48, _9 = 57, SEMIC = 59, NEWLINE = 32, PLUS = 43, MINUS = 45, COLON = 58
3
3
 
4
+ /**
5
+ * Parses a wasm text string and constructs a nested array structure (AST).
6
+ *
7
+ * @param {string} str - The input string with WAT code to parse.
8
+ * @returns {Array} An array representing the nested syntax tree (AST).
9
+ */
4
10
  export default (str) => {
5
11
  let i = 0, level = [], buf = ''
6
12
 
package/src/print.js CHANGED
@@ -2,6 +2,15 @@ import parse from './parse.js';
2
2
 
3
3
  let indent = '', newline = '\n'
4
4
 
5
+ /**
6
+ * Formats a tree or a WAT string.
7
+ *
8
+ * @param {string | Array} tree - The code to print. If a string is provided, it will be parsed first.
9
+ * @param {Object} [options] - Printing options.
10
+ * @param {string} [options.indent=' '] - The string used for one level of indentation.
11
+ * @param {string} [options.newline='\n'] - The string used for line breaks.
12
+ * @returns {string} The formatted WAT string.
13
+ */
5
14
  export default function print(tree, options = {}) {
6
15
  if (typeof tree === 'string') tree = parse(tree);
7
16
 
package/watr.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * WebAssembly Text Format (WAT) compiler, parser, printer.
3
+ *
4
+ * @module watr
5
+ */
6
+
1
7
  import compile from './src/compile.js'
2
8
  import parse from './src/parse.js'
3
9
  import print from './src/print.js'