jz 0.1.1 → 0.2.1
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 +256 -90
- package/cli.js +34 -8
- package/index.js +100 -14
- package/module/array.js +396 -133
- package/module/collection.js +455 -212
- package/module/console.js +169 -88
- package/module/core.js +246 -144
- package/module/date.js +783 -0
- package/module/function.js +81 -21
- package/module/index.js +2 -1
- package/module/json.js +483 -138
- package/module/math.js +79 -39
- package/module/number.js +188 -78
- package/module/object.js +227 -47
- package/module/regex.js +33 -30
- package/module/schema.js +14 -17
- package/module/string.js +439 -235
- package/module/symbol.js +4 -3
- package/module/timer.js +89 -31
- package/module/typedarray.js +174 -44
- package/package.json +3 -10
- package/src/analyze.js +627 -133
- package/src/autoload.js +15 -7
- package/src/compile.js +399 -70
- package/src/ctx.js +41 -12
- package/src/emit.js +658 -145
- package/src/host.js +244 -51
- package/src/ir.js +87 -31
- package/src/jzify.js +181 -24
- package/src/narrow.js +32 -4
- package/src/optimize.js +628 -42
- package/src/plan.js +1167 -4
- package/src/prepare.js +322 -75
- package/src/vectorize.js +1016 -0
- package/wasi.js +13 -0
- package/src/key.js +0 -73
- package/src/source.js +0 -76
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
|
|
|
@@ -195,10 +216,15 @@ export function reset(proto, globals) {
|
|
|
195
216
|
noTailCall: false, // when true, emit `return call` instead of `return_call` (wasm2c compat)
|
|
196
217
|
strict: false, // when true, dynamic features (obj[k], for-in) error at compile time
|
|
197
218
|
// instead of pulling in dynamic-dispatch stdlib. See ProgramFacts walk.
|
|
198
|
-
|
|
219
|
+
alloc: true, // when false, omit raw allocator exports like _alloc/_clear from wasm output.
|
|
199
220
|
optimize: null, // resolved {watr, hoistPtrType, ...} config — set in index.js via resolveOptimize().
|
|
200
221
|
// Read by optimizeModule() (compile.js) and the post-watr pass (index.js).
|
|
201
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.
|
|
202
228
|
}
|
|
203
229
|
|
|
204
230
|
// Feature flags: capabilities the compiled module may exercise at runtime.
|
|
@@ -238,7 +264,10 @@ export function err(msg) {
|
|
|
238
264
|
const line = before.split('\n').length
|
|
239
265
|
const col = ctx.error.loc - before.lastIndexOf('\n')
|
|
240
266
|
const src = ctx.error.src.split('\n')[line - 1]
|
|
241
|
-
|
|
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
|
|
242
271
|
}
|
|
243
|
-
throw Error(msg)
|
|
272
|
+
throw new Error(msg)
|
|
244
273
|
}
|