jz 0.1.0 → 0.2.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/README.md +221 -62
- package/cli.js +34 -8
- package/index.js +133 -14
- package/module/array.js +399 -131
- package/module/collection.js +457 -212
- package/module/console.js +170 -87
- package/module/core.js +247 -143
- package/module/date.js +691 -0
- package/module/function.js +84 -23
- package/module/index.js +2 -1
- package/module/json.js +485 -138
- package/module/math.js +81 -40
- package/module/number.js +189 -83
- package/module/object.js +228 -46
- package/module/regex.js +34 -30
- package/module/schema.js +17 -18
- package/module/string.js +483 -227
- package/module/symbol.js +6 -4
- package/module/timer.js +90 -32
- package/module/typedarray.js +176 -44
- package/package.json +5 -10
- package/src/analyze.js +639 -124
- package/src/autoload.js +183 -0
- package/src/compile.js +448 -1083
- package/src/ctx.js +42 -12
- package/src/emit.js +646 -147
- package/src/host.js +273 -68
- package/src/ir.js +81 -31
- package/src/jzify.js +220 -36
- package/src/narrow.js +956 -0
- package/src/optimize.js +628 -42
- package/src/plan.js +1233 -0
- package/src/prepare.js +438 -256
- package/src/vectorize.js +1016 -0
- package/wasi.js +23 -4
package/src/ctx.js
CHANGED
|
@@ -7,20 +7,38 @@
|
|
|
7
7
|
* Refactored into focused sub-contexts for better maintainability.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
// ===
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
10
|
+
// === Carrier layout ===
|
|
11
|
+
// i64 carrier holds either:
|
|
12
|
+
// - raw f64 number bits (any non-NaN-shape pattern), discriminated by
|
|
13
|
+
// `f64.eq(f, f)` — true for real numbers, false for NaN-shape pointers.
|
|
14
|
+
// - NaN-shape tagged pointer: [63:51]=NAN_PREFIX | [50:47]=tag | [46:32]=aux | [31:0]=offset.
|
|
15
|
+
//
|
|
16
|
+
// LAYOUT is the single source of truth. WAT templates reference
|
|
17
|
+
// `${LAYOUT.TAG_SHIFT}` etc. so a layout change propagates by re-evaluation.
|
|
18
|
+
// Hot dispatch (__ptr_type/__ptr_aux/__ptr_offset) keeps the inline expansion
|
|
19
|
+
// for codegen size; those sites are commented as LAYOUT-tied.
|
|
20
|
+
export const LAYOUT = {
|
|
21
|
+
TAG_SHIFT: 47,
|
|
22
|
+
TAG_MASK: 0xF, // 4-bit tag (16 type slots)
|
|
23
|
+
AUX_SHIFT: 32,
|
|
24
|
+
AUX_MASK: 0x7FFF, // 15-bit aux (schemaId, elemType, atomId, …)
|
|
25
|
+
OFFSET_MASK: 0xFFFFFFFF, // 32-bit offset (4GB heap)
|
|
26
|
+
NAN_PREFIX: 0x7FF8, // top 13 bits of any NaN-shape pointer
|
|
27
|
+
NAN_PREFIX_BITS: 0x7FF8000000000000n, // pre-shifted for i64 OR
|
|
28
|
+
SSO_BIT: 0x4000, // STRING aux bit 14: 1=inline (≤4 ASCII chars in offset), 0=heap
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// === Tagged-pointer type codes ===
|
|
32
|
+
// 4-bit tag (LAYOUT.TAG_MASK = 16 slots).
|
|
15
33
|
// To retire a type, gate emission behind a feature flag and drop its dispatch
|
|
16
|
-
// branches; to add, renumber with care —
|
|
34
|
+
// branches; to add, renumber with care — hardcoded branches in module/* must update.
|
|
17
35
|
export const PTR = {
|
|
18
|
-
ATOM: 0, // null, undefined, booleans
|
|
36
|
+
ATOM: 0, // null, undefined, booleans, symbols (aux=atomId)
|
|
19
37
|
ARRAY: 1, // heap-allocated arrays
|
|
20
38
|
BUFFER: 2, // ArrayBuffer: [-8:byteLen][-4:byteCap][bytes]
|
|
21
39
|
TYPED: 3, // TypedArrays (Float64Array, etc.)
|
|
22
|
-
STRING: 4, // heap-
|
|
23
|
-
|
|
40
|
+
STRING: 4, // strings (heap or inline-SSO; aux bit LAYOUT.SSO_BIT distinguishes)
|
|
41
|
+
// 5: free
|
|
24
42
|
OBJECT: 6, // plain objects
|
|
25
43
|
HASH: 7, // dynamic objects (Map-like)
|
|
26
44
|
SET: 8, // Set collections
|
|
@@ -97,6 +115,9 @@ export function reset(proto, globals) {
|
|
|
97
115
|
stdlib: {},
|
|
98
116
|
stdlibDeps: {}, // populated per-module at init time (was STDLIB_DEPS in this file)
|
|
99
117
|
includes: new Set(),
|
|
118
|
+
extImports: new Set(), // __ext_* helpers actually emitted as env imports —
|
|
119
|
+
// pullStdlib() removes them from `includes` after wiring,
|
|
120
|
+
// so post-compile auditors (host: 'wasi') read this instead.
|
|
100
121
|
}
|
|
101
122
|
|
|
102
123
|
|
|
@@ -109,6 +130,7 @@ export function reset(proto, globals) {
|
|
|
109
130
|
resolvedModules: new Map(),
|
|
110
131
|
moduleStack: [],
|
|
111
132
|
moduleInits: [],
|
|
133
|
+
initFacts: null,
|
|
112
134
|
currentPrefix: null,
|
|
113
135
|
}
|
|
114
136
|
|
|
@@ -194,10 +216,15 @@ export function reset(proto, globals) {
|
|
|
194
216
|
noTailCall: false, // when true, emit `return call` instead of `return_call` (wasm2c compat)
|
|
195
217
|
strict: false, // when true, dynamic features (obj[k], for-in) error at compile time
|
|
196
218
|
// instead of pulling in dynamic-dispatch stdlib. See ProgramFacts walk.
|
|
197
|
-
|
|
219
|
+
alloc: true, // when false, omit raw allocator exports like _alloc/_clear from wasm output.
|
|
198
220
|
optimize: null, // resolved {watr, hoistPtrType, ...} config — set in index.js via resolveOptimize().
|
|
199
221
|
// Read by optimizeModule() (compile.js) and the post-watr pass (index.js).
|
|
200
222
|
// null is treated as level 2 (all on) for back-compat with internal callers.
|
|
223
|
+
importMetaUrl: null, // compile-time URL for import.meta.url / import.meta.resolve static lowering.
|
|
224
|
+
host: 'js', // 'js' (default): allow `env.__ext_*` imports to be wired by the JS host at
|
|
225
|
+
// instantiation time. 'wasi': error at compile time if any `__ext_*` import
|
|
226
|
+
// would be emitted, since wasmtime/wasmer hosts have no JS runtime to satisfy
|
|
227
|
+
// them and silent fallback would corrupt output.
|
|
201
228
|
}
|
|
202
229
|
|
|
203
230
|
// Feature flags: capabilities the compiled module may exercise at runtime.
|
|
@@ -237,7 +264,10 @@ export function err(msg) {
|
|
|
237
264
|
const line = before.split('\n').length
|
|
238
265
|
const col = ctx.error.loc - before.lastIndexOf('\n')
|
|
239
266
|
const src = ctx.error.src.split('\n')[line - 1]
|
|
240
|
-
|
|
267
|
+
const detail = `${msg}\n at line ${line}:${col}\n ${src}\n ${' '.repeat(col - 1)}^`
|
|
268
|
+
const e = new Error(detail)
|
|
269
|
+
e.stack = `${e.name}: ${detail}\n${e.stack.split('\n').slice(1).join('\n')}`
|
|
270
|
+
throw e
|
|
241
271
|
}
|
|
242
|
-
throw Error(msg)
|
|
272
|
+
throw new Error(msg)
|
|
243
273
|
}
|