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/module/schema.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* @module schema
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { typed, asF64 } from '../src/ir.js'
|
|
11
|
+
import { emit } from '../src/emit.js'
|
|
12
|
+
import { VAL, lookupValType, repOf } from '../src/analyze.js'
|
|
11
13
|
import { err, inc } from '../src/ctx.js'
|
|
12
14
|
|
|
13
15
|
/** Initialize schema helpers on ctx. Called once per compilation from core module. */
|
|
@@ -54,30 +56,27 @@ export function initSchema(ctx) {
|
|
|
54
56
|
/** Emit code to load the inner value (slot 0) of a boxed variable. */
|
|
55
57
|
ctx.schema.emitInner = (varName) => {
|
|
56
58
|
inc('__ptr_offset')
|
|
57
|
-
return typed(['f64.load', ['call', '$__ptr_offset', asF64(emit(varName))]], 'f64')
|
|
59
|
+
return typed(['f64.load', ['call', '$__ptr_offset', ['i64.reinterpret_f64', asF64(emit(varName))]]], 'f64')
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
/** Find property index by variable schema or structural subtyping.
|
|
61
|
-
* Returns -1 to signal "use dynamic lookup" in
|
|
63
|
+
* Returns -1 to signal "use dynamic lookup" in four cases:
|
|
62
64
|
* 1. Variable has precise schema but schema lacks the property
|
|
63
|
-
* 2.
|
|
64
|
-
* 3.
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
* memory (e.g. arr.loc = ... corrupting arr[slot]). Reads only return wrong
|
|
69
|
-
* values, which callers can tolerate. */
|
|
70
|
-
ctx.schema.find = (varName, prop, safe = false) => {
|
|
65
|
+
* 2. Receiver is a string variable, but its valType is unknown or not OBJECT
|
|
66
|
+
* 3. Receiver is not a string variable (varName == null) — no type evidence
|
|
67
|
+
* 4. Structural search finds the property at inconsistent offsets across schemas
|
|
68
|
+
* Case 4 is a real ambiguity — the caller must route to runtime dispatch. */
|
|
69
|
+
ctx.schema.find = (varName, prop) => {
|
|
71
70
|
// Precise: variable has known schema
|
|
72
71
|
const id = ctx.schema.idOf(varName)
|
|
73
72
|
if (id != null) return ctx.schema.list[id]?.indexOf(prop) ?? -1
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
if
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
// Structural subtyping requires positive evidence the receiver is OBJECT.
|
|
74
|
+
// Without it (varName is null, or its valType is unknown / not OBJECT) we
|
|
75
|
+
// can match HASH/ARRAY/etc. values as if they had OBJECT layout, producing
|
|
76
|
+
// slot reads on unrelated memory. Funnel those through dynamic dispatch.
|
|
77
|
+
if (typeof varName !== 'string') return -1
|
|
78
|
+
const vt = lookupValType(varName)
|
|
79
|
+
if (vt !== VAL.OBJECT) return -1
|
|
81
80
|
// Structural subtyping: walk only schemas that contain this prop.
|
|
82
81
|
// Consistent slot across all → return slot; any mismatch → -1 (dynamic lookup).
|
|
83
82
|
const bucket = byProp.get(prop)
|