watr 4.7.2 → 5.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/dist/watr.js +876 -4780
- package/dist/watr.min.js +5 -6
- package/dist/watr.wasm +0 -0
- package/package.json +13 -3
- package/readme.md +28 -10
- package/src/compile.js +227 -109
- package/src/const.js +125 -131
- package/src/encode.js +28 -3
- package/src/optimize.js +2909 -421
- package/src/template.js +23 -5
- package/src/util.js +33 -9
- package/types/src/compile.d.ts +1 -0
- package/types/src/compile.d.ts.map +1 -1
- package/types/src/const.d.ts +2 -1
- package/types/src/const.d.ts.map +1 -1
- package/types/src/encode.d.ts +5 -26
- package/types/src/encode.d.ts.map +1 -1
- package/types/src/optimize.d.ts +41 -33
- package/types/src/optimize.d.ts.map +1 -1
- package/types/src/template.d.ts.map +1 -1
- package/types/src/util.d.ts +5 -10
- package/types/src/util.d.ts.map +1 -1
- package/types/watr.d.ts +4 -5
- package/types/watr.d.ts.map +1 -1
- package/watr.js +10 -7
package/src/template.js
CHANGED
|
@@ -19,6 +19,24 @@ import { resultType } from './const.js'
|
|
|
19
19
|
/** Private Use Area character as placeholder for interpolation */
|
|
20
20
|
const PUA = '\uE000'
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Apply a backend transform (`polyfill`/`optimize`), or throw an actionable
|
|
24
|
+
* pointer when this entry doesn't bundle it. The default `watr` build wires a
|
|
25
|
+
* lean backend (parse + compile) and leaves the heavy transforms to their own
|
|
26
|
+
* entries, so `compile(src, { optimize })` here directs you to compose instead.
|
|
27
|
+
*
|
|
28
|
+
* @param {Function|undefined} fn - transform from the backend
|
|
29
|
+
* @param {string} name - 'polyfill' | 'optimize'
|
|
30
|
+
* @param {Array} ast
|
|
31
|
+
* @param {any} opt - the option value
|
|
32
|
+
* @returns {Array} transformed AST
|
|
33
|
+
*/
|
|
34
|
+
function applyTransform(fn, name, ast, opt) {
|
|
35
|
+
if (typeof fn !== 'function')
|
|
36
|
+
throw Error(`watr: '${name}' is not bundled in this entry \u2014 import it from 'watr/${name}' and compose: compile(${name}(src))`)
|
|
37
|
+
return fn(ast, opt)
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
/**
|
|
23
41
|
* Infer type of an expression AST node.
|
|
24
42
|
* Used for auto-import parameter type inference.
|
|
@@ -209,9 +227,9 @@ export function compile(backend, source, values) {
|
|
|
209
227
|
}
|
|
210
228
|
}
|
|
211
229
|
|
|
212
|
-
// Apply transforms
|
|
213
|
-
if (opts.polyfill) ast = polyfill
|
|
214
|
-
if (opts.optimize) ast = optimize
|
|
230
|
+
// Apply transforms (heavy passes live in separate entries — see applyTransform)
|
|
231
|
+
if (opts.polyfill) ast = applyTransform(polyfill, 'polyfill', ast, opts.polyfill)
|
|
232
|
+
if (opts.optimize) ast = applyTransform(optimize, 'optimize', ast, opts.optimize)
|
|
215
233
|
|
|
216
234
|
const binary = emit(ast)
|
|
217
235
|
// Attach imports for watr() to use
|
|
@@ -222,8 +240,8 @@ export function compile(backend, source, values) {
|
|
|
222
240
|
// String/AST source with options
|
|
223
241
|
if (opts.polyfill || opts.optimize) {
|
|
224
242
|
let ast = typeof source === 'string' ? parse(source) : source
|
|
225
|
-
if (opts.polyfill) ast = polyfill
|
|
226
|
-
if (opts.optimize) ast = optimize
|
|
243
|
+
if (opts.polyfill) ast = applyTransform(polyfill, 'polyfill', ast, opts.polyfill)
|
|
244
|
+
if (opts.optimize) ast = applyTransform(optimize, 'optimize', ast, opts.optimize)
|
|
227
245
|
return emit(ast)
|
|
228
246
|
}
|
|
229
247
|
return emit(source)
|
package/src/util.js
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
|
+
// Ambient source/position for err()'s "at line:col" suffix — set by assemble()
|
|
2
|
+
// as it walks a module (err.loc/err.src used to be expando properties on the
|
|
3
|
+
// `err` function itself; a self-hosted compile-clear-compile loop bump-allocates
|
|
4
|
+
// a HASH props table the first time a property lands on a function value, and
|
|
5
|
+
// that table dangles across an arena `_clear` between compiles — corrupting the
|
|
6
|
+
// SECOND self-host compile. Plain module-level `let`s are a global-set, not a
|
|
7
|
+
// dynamic-key write, so they carry no such table and are `_clear`-safe.
|
|
8
|
+
let errLoc, errSrc
|
|
9
|
+
|
|
1
10
|
/**
|
|
2
11
|
* Throws an error with optional source position.
|
|
3
|
-
* Uses
|
|
4
|
-
* If pos provided or
|
|
12
|
+
* Uses the ambient errSrc for source and errLoc for default position.
|
|
13
|
+
* If pos provided or errLoc set, appends "at line:col".
|
|
5
14
|
*
|
|
6
15
|
* @param {string} text - Error message
|
|
7
|
-
* @param {number} [pos] - Byte offset in source (defaults to
|
|
16
|
+
* @param {number} [pos] - Byte offset in source (defaults to errLoc)
|
|
8
17
|
* @throws {Error}
|
|
9
18
|
*/
|
|
10
|
-
export const err = (text, pos=
|
|
11
|
-
if (pos != null &&
|
|
19
|
+
export const err = (text, pos=errLoc) => {
|
|
20
|
+
if (pos != null && errSrc) {
|
|
12
21
|
let line = 1, col = 1
|
|
13
|
-
for (let i = 0; i < pos && i <
|
|
14
|
-
if (
|
|
22
|
+
for (let i = 0; i < pos && i < errSrc.length; i++) {
|
|
23
|
+
if (errSrc.charCodeAt(i) === 10) line++, col = 1
|
|
15
24
|
else col++
|
|
16
25
|
}
|
|
17
26
|
text += ` at ${line}:${col}`
|
|
18
27
|
}
|
|
19
28
|
throw Error(text)
|
|
20
29
|
}
|
|
30
|
+
// Accessors for the ambient position/source (compile.js is the only writer).
|
|
31
|
+
export const setErrLoc = (loc) => { errLoc = loc }
|
|
32
|
+
export const setErrSrc = (src) => { errSrc = src }
|
|
33
|
+
export const getErrLoc = () => errLoc
|
|
34
|
+
export const getErrSrc = () => errSrc
|
|
21
35
|
|
|
22
36
|
/** Regex to detect invalid underscore placement in numbers */
|
|
23
37
|
export const sepRE = /^_|_$|[^\da-f]_|_[^\da-f]/i
|
|
@@ -97,7 +111,13 @@ export const clone = (node) => Array.isArray(node) ? node.map(clone) : node
|
|
|
97
111
|
*/
|
|
98
112
|
export const walk = (node, fn, parent, idx) => {
|
|
99
113
|
fn(node, parent, idx)
|
|
100
|
-
if (Array.isArray(node)) for (let i = 0; i < node.length; i++)
|
|
114
|
+
if (Array.isArray(node)) for (let i = 0; i < node.length; i++) {
|
|
115
|
+
const c = node[i]
|
|
116
|
+
// leaves get their visit inline — half of all nodes are strings/numbers, and a
|
|
117
|
+
// full recursive frame per leaf dominates traversal cost on big modules
|
|
118
|
+
if (Array.isArray(c)) walk(c, fn, node, i)
|
|
119
|
+
else fn(c, node, i)
|
|
120
|
+
}
|
|
101
121
|
}
|
|
102
122
|
|
|
103
123
|
/**
|
|
@@ -115,7 +135,11 @@ export const walk = (node, fn, parent, idx) => {
|
|
|
115
135
|
* @returns {any} The (possibly replaced) node
|
|
116
136
|
*/
|
|
117
137
|
export const walkPost = (node, fn, parent, idx) => {
|
|
118
|
-
if (Array.isArray(node)) for (let i = 0; i < node.length; i++)
|
|
138
|
+
if (Array.isArray(node)) for (let i = 0; i < node.length; i++) {
|
|
139
|
+
const c = node[i]
|
|
140
|
+
if (Array.isArray(c)) walkPost(c, fn, node, i)
|
|
141
|
+
else { const r = fn(c, node, i); if (r !== undefined) node[i] = r }
|
|
142
|
+
}
|
|
119
143
|
const result = fn(node, parent, idx)
|
|
120
144
|
if (result !== undefined && parent) parent[idx] = result
|
|
121
145
|
return result !== undefined ? result : node
|
package/types/src/compile.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AAsVA;;;;GAIG;AACH,iDAAiE;AAEjE;;;;GAIG;AACH,sCAA4D;AAg8BrD,0CAcN"}
|
package/types/src/const.d.ts
CHANGED
package/types/src/const.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../src/const.js"],"names":[],"mappings":"AAgKa,wBAAW;AAAE,qBAAQ;AAoB3B,+BAHI,MAAM,GACJ,MAAM,GAAC,IAAI,CAavB"}
|
package/types/src/encode.d.ts
CHANGED
|
@@ -6,14 +6,7 @@
|
|
|
6
6
|
* @returns {number[]} 5-byte array
|
|
7
7
|
*/
|
|
8
8
|
export function uleb5(value: number): number[];
|
|
9
|
-
|
|
10
|
-
* Encode signed LEB128 for i32 values.
|
|
11
|
-
*
|
|
12
|
-
* @param {number|string} n - Signed 32-bit value
|
|
13
|
-
* @param {number[]} [buffer=[]] - Output buffer
|
|
14
|
-
* @returns {number[]} Encoded bytes
|
|
15
|
-
*/
|
|
16
|
-
export function i32(n: number | string, buffer?: number[]): number[];
|
|
9
|
+
export function i32(n: any, buffer?: any[]): any[];
|
|
17
10
|
export namespace i32 {
|
|
18
11
|
function parse(n: any): any;
|
|
19
12
|
}
|
|
@@ -28,32 +21,18 @@ export function i64(n: bigint | string, buffer?: number[]): number[];
|
|
|
28
21
|
export namespace i64 {
|
|
29
22
|
function parse(n: any): any;
|
|
30
23
|
}
|
|
31
|
-
export function f32(input: any, value: any, idx: any): number[];
|
|
24
|
+
export function f32(input: any, out: any, value: any, idx: any): number[];
|
|
32
25
|
export namespace f32 {
|
|
33
26
|
function parse(input: any): number;
|
|
34
27
|
}
|
|
35
|
-
export function f64(input: any, value: any, idx: any):
|
|
28
|
+
export function f64(input: any, out: any, value: any, idx: any): any;
|
|
36
29
|
export namespace f64 {
|
|
37
30
|
function parse(input: any, max?: number): number;
|
|
38
31
|
}
|
|
39
32
|
export function uleb(n: number | bigint | string | null, buffer?: number[]): number[];
|
|
40
|
-
|
|
41
|
-
* Encode signed LEB128 for i32 values.
|
|
42
|
-
*
|
|
43
|
-
* @param {number|string} n - Signed 32-bit value
|
|
44
|
-
* @param {number[]} [buffer=[]] - Output buffer
|
|
45
|
-
* @returns {number[]} Encoded bytes
|
|
46
|
-
*/
|
|
47
|
-
export function i8(n: number | string, buffer?: number[]): number[];
|
|
33
|
+
export function i8(n: any, buffer?: any[]): any[];
|
|
48
34
|
export namespace i8 { }
|
|
49
|
-
|
|
50
|
-
* Encode signed LEB128 for i32 values.
|
|
51
|
-
*
|
|
52
|
-
* @param {number|string} n - Signed 32-bit value
|
|
53
|
-
* @param {number[]} [buffer=[]] - Output buffer
|
|
54
|
-
* @returns {number[]} Encoded bytes
|
|
55
|
-
*/
|
|
56
|
-
export function i16(n: number | string, buffer?: number[]): number[];
|
|
35
|
+
export function i16(n: any, buffer?: any[]): any[];
|
|
57
36
|
export namespace i16 { }
|
|
58
37
|
export function v128(input: any): any[];
|
|
59
38
|
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.js"],"names":[],"mappings":"AA6CA;;;;;;GAMG;AACH,6BAHW,MAAM,GACJ,MAAM,EAAE,CAapB;
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/encode.js"],"names":[],"mappings":"AA6CA;;;;;;GAMG;AACH,6BAHW,MAAM,GACJ,MAAM,EAAE,CAapB;AAYD,mDAqBC;;IAQD,4BAIC;;AAED;;;;;;GAMG;AACH,uBAJW,MAAM,GAAC,MAAM,WACb,MAAM,EAAE,GACN,MAAM,EAAE,CAoBpB;;IAID,4BAmBC;;AAGD,0EAkBC;;IAiFD,mCAA6D;;AA7E7D,qEA6BC;;IAED,iDA4CC;;AAnPM,wBAJI,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,IAAI,WACzB,MAAM,EAAE,GACN,MAAM,EAAE,CA8BpB;AAgCD,kDAqBC;;AArBD,mDAqBC;;AAsKM,wCAKN"}
|
package/types/src/optimize.d.ts
CHANGED
|
@@ -18,12 +18,8 @@ export function binarySize(ast: any[]): number;
|
|
|
18
18
|
* @returns {Array}
|
|
19
19
|
*/
|
|
20
20
|
export function treeshake(ast: any[]): any[];
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
* @param {Array} ast
|
|
24
|
-
* @returns {Array}
|
|
25
|
-
*/
|
|
26
|
-
export function fold(ast: any[]): any[];
|
|
21
|
+
/** Constant folding as a standalone pass. */
|
|
22
|
+
export function fold(ast: any): any;
|
|
27
23
|
/**
|
|
28
24
|
* Remove dead code after control flow terminators.
|
|
29
25
|
* @param {Array} ast
|
|
@@ -37,25 +33,53 @@ export function deadcode(ast: any[]): any[];
|
|
|
37
33
|
* @returns {Array}
|
|
38
34
|
*/
|
|
39
35
|
export function localReuse(ast: any[]): any[];
|
|
36
|
+
/** Identity elimination as a standalone pass. */
|
|
37
|
+
export function identity(ast: any): any;
|
|
38
|
+
/** Strength reduction as a standalone pass. */
|
|
39
|
+
export function strength(ast: any): any;
|
|
40
|
+
/**
|
|
41
|
+
* Simplify branches with constant conditions.
|
|
42
|
+
* @param {Array} ast
|
|
43
|
+
* @returns {Array}
|
|
44
|
+
*/
|
|
45
|
+
export function branch(ast: any[]): any[];
|
|
46
|
+
export function propagate(ast: any): any;
|
|
40
47
|
/**
|
|
41
|
-
*
|
|
48
|
+
* Merge alias locals: `(local.set $A (local.tee $B V))` writes the same value into
|
|
49
|
+
* two slots. When that is the ONLY write either local ever gets, their write
|
|
50
|
+
* histories are identical — every read of $A (even one sequenced before the def,
|
|
51
|
+
* which sees the zero default on both) equals the same read of $B. So $A's reads
|
|
52
|
+
* rename to $B and the alias write drops. Params are excluded ($B would carry a
|
|
53
|
+
* call-argument value where $A held zero).
|
|
42
54
|
* @param {Array} ast
|
|
43
55
|
* @returns {Array}
|
|
44
56
|
*/
|
|
45
|
-
export function
|
|
57
|
+
export function mergeLocals(ast: any[]): any[];
|
|
46
58
|
/**
|
|
47
|
-
*
|
|
59
|
+
* Local common-subexpression elimination: identical pure subtrees repeated within a
|
|
60
|
+
* straight-line scope compute once into a fresh local (first site tees, later sites
|
|
61
|
+
* get). Grouping stops at every invalidation: a statement that writes a local the
|
|
62
|
+
* expression reads, writes memory (for memory-reading exprs), or calls out (memory/
|
|
63
|
+
* global-reading exprs). Candidates come only from the unconditional part of each
|
|
64
|
+
* statement — nested control bodies are separate scopes with their own table.
|
|
65
|
+
* Fires only when the byte win is provable: (n−1)·bytes(expr) > tee+gets+decl cost.
|
|
48
66
|
* @param {Array} ast
|
|
49
67
|
* @returns {Array}
|
|
50
68
|
*/
|
|
51
|
-
export function
|
|
69
|
+
export function cse(ast: any[]): any[];
|
|
52
70
|
/**
|
|
53
|
-
*
|
|
71
|
+
* Macro inlining: a function whose whole body is ONE small expression using each
|
|
72
|
+
* param exactly once, in declaration order, expands at every call site by
|
|
73
|
+
* substituting the arguments positionally — no wrapper, no locals, argument
|
|
74
|
+
* evaluation order preserved verbatim (so impure args stay sound). The husk loses
|
|
75
|
+
* its callers and treeshake collects it; the expansion feeds fold/offset/cse.
|
|
54
76
|
* @param {Array} ast
|
|
55
77
|
* @returns {Array}
|
|
56
78
|
*/
|
|
57
|
-
export function
|
|
58
|
-
|
|
79
|
+
export function inlineMacro(ast: any[], { pin }?: {
|
|
80
|
+
pin?: any;
|
|
81
|
+
}): any[];
|
|
82
|
+
export function tailmerge(ast: any): any;
|
|
59
83
|
export function inline(ast: any, { simdOnly, pin }?: {
|
|
60
84
|
simdOnly?: boolean;
|
|
61
85
|
pin?: any;
|
|
@@ -137,12 +161,8 @@ export const OPTS: any;
|
|
|
137
161
|
* @returns {Array}
|
|
138
162
|
*/
|
|
139
163
|
export function vacuum(ast: any[]): any[];
|
|
140
|
-
/**
|
|
141
|
-
|
|
142
|
-
* @param {Array} ast
|
|
143
|
-
* @returns {Array}
|
|
144
|
-
*/
|
|
145
|
-
export function peephole(ast: any[]): any[];
|
|
164
|
+
/** Peephole rules as a standalone pass. */
|
|
165
|
+
export function peephole(ast: any): any;
|
|
146
166
|
/**
|
|
147
167
|
* Replace `global.get` of an immutable, const-initialised global with the
|
|
148
168
|
* constant — but only when it doesn't grow the module. A `global.get` costs
|
|
@@ -158,12 +178,7 @@ export function peephole(ast: any[]): any[];
|
|
|
158
178
|
export function globals(ast: any[]): any[];
|
|
159
179
|
/** Match (type.load/store (i32.add ptr (type.const N))) and fold offset */
|
|
160
180
|
export function offset(ast: any): any;
|
|
161
|
-
|
|
162
|
-
* Remove br to a block's own label when it is the last instruction.
|
|
163
|
-
* @param {Array} ast
|
|
164
|
-
* @returns {Array}
|
|
165
|
-
*/
|
|
166
|
-
export function unbranch(ast: any[]): any[];
|
|
181
|
+
export function unbranch(ast: any): any;
|
|
167
182
|
/**
|
|
168
183
|
* Collapse the `while`-emit idiom into a single loop.
|
|
169
184
|
*
|
|
@@ -196,14 +211,7 @@ export function loopify(ast: any[]): any[];
|
|
|
196
211
|
* @returns {Array}
|
|
197
212
|
*/
|
|
198
213
|
export function stripmut(ast: any[]): any[];
|
|
199
|
-
|
|
200
|
-
* Simplify (if cond (then (br $label))) → (br_if $label cond)
|
|
201
|
-
* and (if cond (then) (else (br $label))) → (br_if $label (i32.eqz cond))
|
|
202
|
-
* Only when the br is the sole instruction in the arm.
|
|
203
|
-
* @param {Array} ast
|
|
204
|
-
* @returns {Array}
|
|
205
|
-
*/
|
|
206
|
-
export function brif(ast: any[]): any[];
|
|
214
|
+
export function brif(ast: any): any;
|
|
207
215
|
/**
|
|
208
216
|
* Fold identical trailing code out of if/else arms.
|
|
209
217
|
* (if cond (then A X) (else B X)) → (if cond (then A) (else B)) X
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AA4lMA,gEA+MC;AArxMD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAOlB;AA8CD;;;;;GAKG;AACH,6CAmSC;AAgbD,6CAA6C;AAC7C,oCAA6C;AA2iB7C;;;;GAIG;AACH,4CAqBC;AAoCD;;;;;GAKG;AACH,8CAkFC;AAvlBD,iDAAiD;AACjD,wCAAqD;AAgErD,+CAA+C;AAC/C,wCAAqD;AAIrD;;;;GAIG;AACH,0CA0KC;AAotED,yCA8EC;AA7HD;;;;;;;;;GASG;AACH,+CAuBC;AA3tBD;;;;;;;;;;GAUG;AACH,uCAsJC;AAED;;;;;;;;GAQG;AACH;;UA8DC;AAkZD,yCA4DC;AAkWD;;;QAqEC;AAuQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH;;UA2JC;AA3bD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,sCAwOC;AAgjED;;;;;;;;GAQG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAc/B;AAvBD,qEAAqE;AACrE,uBAA8D;AA1iD9D;;;;;GAKG;AACH,0CAyEC;AA8FD,2CAA2C;AAC3C,wCAAqD;AAwDrD;;;;;;;;;;;GAWG;AACH,2CAiHC;AAID,2EAA2E;AAC3E,sCAgEC;AA0BD,wCA0DC;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,2CAiDC;AAID;;;;;GAKG;AACH,4CAqBC;AA6BD,oCAuCC;AAID;;;;;GAKG;AACH,4CAiDC;AAuCD;;;;;GAKG;AACH,0CAqFC;AA2cD,uCAyBC;AAheD;;;;;GAKG;AACH,8CAyEC;AAiLD;;;;GAIG;AACH,4CAsHC;AAqBD;;;;;GAKG;AACH,iDAgBC;AAtjDD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,+CAiFC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDA8JC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/template.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/template.js"],"names":[],"mappings":"AA8IA;;;;;;;;;;GAUG;AACH,8CAPW,MAAM,WAAO,oBAAoB,UACjC,GAAG,EAAE,GAIH,UAAU,CAgGtB;AAED;;;;;;;GAOG;AACH,2CAJW,MAAM,WAAO,oBAAoB,UACjC,GAAG,EAAE,GACH,WAAW,CAAC,OAAO,CAO/B"}
|
package/types/src/util.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param {string} text - Error message
|
|
7
|
-
* @param {number} [pos] - Byte offset in source (defaults to err.loc)
|
|
8
|
-
* @throws {Error}
|
|
9
|
-
*/
|
|
10
|
-
export const err: (text: string, pos?: number) => never;
|
|
1
|
+
export function err(text: string, pos?: number): never;
|
|
2
|
+
export function setErrLoc(loc: any): void;
|
|
3
|
+
export function setErrSrc(src: any): void;
|
|
4
|
+
export function getErrLoc(): any;
|
|
5
|
+
export function getErrSrc(): any;
|
|
11
6
|
/** Regex to detect invalid underscore placement in numbers */
|
|
12
7
|
export const sepRE: RegExp;
|
|
13
8
|
/** Regex to match valid integer literals (decimal or hex) */
|
package/types/src/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.js"],"names":[],"mappings":"AAkBO,0BAJI,MAAM,QACN,MAAM,SAahB;AAEM,0CAA2C;AAC3C,0CAA2C;AAC3C,iCAA8B;AAC9B,iCAA8B;AAErC,8DAA8D;AAC9D,2BAAiD;AAEjD,6DAA6D;AAC7D,2BAAiD;AAe1C,uBAHI,MAAM,GACJ,MAAM,EAAE,CA8BpB;AAUM,4BAHI,MAAM,GACJ,MAAM,CAE6C;AAUzD,4BAHI,GAAG,GACD,GAAG,CAE2D;AASpE,2BALI,GAAG,yBAEH,GAAG,QACH,MAAM,QAWhB;AAgBM,+BANI,GAAG,yBAEH,GAAG,QACH,MAAM,GACJ,GAAG,CAWf"}
|
package/types/watr.d.ts
CHANGED
|
@@ -17,18 +17,17 @@ export function watr(source: string | TemplateStringsArray, ...values: any[]): W
|
|
|
17
17
|
*
|
|
18
18
|
* @param {string|TemplateStringsArray} source - WAT source or template strings
|
|
19
19
|
* @param {...any} values - Interpolation values (for template literal).
|
|
20
|
-
* Last value can be an options object: { polyfill, optimize }.
|
|
21
20
|
* @returns {Uint8Array} WebAssembly binary
|
|
22
21
|
*
|
|
23
22
|
* @example
|
|
24
23
|
* compile('(func (export "f") (result i32) (i32.const 42))')
|
|
25
24
|
* compile`(func (export "f") (result f64) (f64.const ${Math.PI}))`
|
|
26
|
-
*
|
|
25
|
+
* // transforms ship as separate entries — compose them:
|
|
26
|
+
* // import optimize from 'watr/optimize'
|
|
27
|
+
* // compile(optimize(src))
|
|
27
28
|
*/
|
|
28
29
|
export function compile(source: string | TemplateStringsArray, ...values: any[]): Uint8Array;
|
|
29
30
|
import parse from './src/parse.js';
|
|
30
31
|
import print from './src/print.js';
|
|
31
|
-
|
|
32
|
-
import _optimize from './src/optimize.js';
|
|
33
|
-
export { parse, print, _polyfill as polyfill, _optimize as optimize };
|
|
32
|
+
export { parse, print };
|
|
34
33
|
//# sourceMappingURL=watr.d.ts.map
|
package/types/watr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watr.d.ts","sourceRoot":"","sources":["../watr.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"watr.d.ts","sourceRoot":"","sources":["../watr.js"],"names":[],"mappings":";AAoCA;;;;;;;;;;;GAWG;AACH,6BATW,MAAM,GAAC,oBAAoB,aACxB,GAAG,EAAA,GACJ,WAAW,CAAC,OAAO,CAS/B;AAhCD;;;;;;;;;;;;;GAaG;AACH,gCAXW,MAAM,GAAC,oBAAoB,aACxB,GAAG,EAAA,GACJ,UAAU,CAWtB;kBA3BiB,gBAAgB;kBAChB,gBAAgB"}
|
package/watr.js
CHANGED
|
@@ -7,25 +7,28 @@
|
|
|
7
7
|
import _compile from './src/compile.js'
|
|
8
8
|
import parse from './src/parse.js'
|
|
9
9
|
import print from './src/print.js'
|
|
10
|
-
import _polyfill from './src/polyfill.js'
|
|
11
|
-
import _optimize from './src/optimize.js'
|
|
12
10
|
import { compile as _tcompile, watr as _twatr } from './src/template.js'
|
|
13
11
|
|
|
14
|
-
/** JS-source backend primitives for the tagged-template layer.
|
|
15
|
-
|
|
12
|
+
/** JS-source backend primitives for the tagged-template layer.
|
|
13
|
+
* `polyfill` and `optimize` are intentionally NOT wired here — they're heavy
|
|
14
|
+
* (the optimizer alone is ~5× the core encoder) and ship as separate entries,
|
|
15
|
+
* `watr/polyfill` and `watr/optimize`, that you compose explicitly:
|
|
16
|
+
* `compile(optimize(src))`. This keeps the default bundle minimal. */
|
|
17
|
+
const backend = { parse, compile: _compile }
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Compile WAT to binary. Supports both string and template literal.
|
|
19
21
|
*
|
|
20
22
|
* @param {string|TemplateStringsArray} source - WAT source or template strings
|
|
21
23
|
* @param {...any} values - Interpolation values (for template literal).
|
|
22
|
-
* Last value can be an options object: { polyfill, optimize }.
|
|
23
24
|
* @returns {Uint8Array} WebAssembly binary
|
|
24
25
|
*
|
|
25
26
|
* @example
|
|
26
27
|
* compile('(func (export "f") (result i32) (i32.const 42))')
|
|
27
28
|
* compile`(func (export "f") (result f64) (f64.const ${Math.PI}))`
|
|
28
|
-
*
|
|
29
|
+
* // transforms ship as separate entries — compose them:
|
|
30
|
+
* // import optimize from 'watr/optimize'
|
|
31
|
+
* // compile(optimize(src))
|
|
29
32
|
*/
|
|
30
33
|
function compile(source, ...values) {
|
|
31
34
|
return _tcompile(backend, source, values)
|
|
@@ -48,4 +51,4 @@ function watr(source, ...values) {
|
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
export default watr
|
|
51
|
-
export { watr, compile, parse, print
|
|
54
|
+
export { watr, compile, parse, print }
|