jz 0.1.1 → 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/module/schema.js CHANGED
@@ -56,30 +56,27 @@ export function initSchema(ctx) {
56
56
  /** Emit code to load the inner value (slot 0) of a boxed variable. */
57
57
  ctx.schema.emitInner = (varName) => {
58
58
  inc('__ptr_offset')
59
- 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')
60
60
  }
61
61
 
62
62
  /** Find property index by variable schema or structural subtyping.
63
- * Returns -1 to signal "use dynamic lookup" in three cases:
63
+ * Returns -1 to signal "use dynamic lookup" in four cases:
64
64
  * 1. Variable has precise schema but schema lacks the property
65
- * 2. Variable's valType is known and is not an object
66
- * 3. Structural search finds the property at inconsistent offsets across schemas
67
- * Case 3 is a real ambiguity — the caller must route to runtime dispatch.
68
- * `safe=true` disables structural subtyping when the variable's type is not
69
- * known to be VAL.OBJECT. Use for writes: a wrong slot clobbers unrelated
70
- * memory (e.g. arr.loc = ... corrupting arr[slot]). Reads only return wrong
71
- * values, which callers can tolerate. */
72
- 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) => {
73
70
  // Precise: variable has known schema
74
71
  const id = ctx.schema.idOf(varName)
75
72
  if (id != null) return ctx.schema.list[id]?.indexOf(prop) ?? -1
76
- // Known non-object pointer-backed values must use dynamic property lookup,
77
- // not structural object schemas registered elsewhere in the function.
78
- if (typeof varName === 'string') {
79
- const vt = lookupValType(varName)
80
- if (vt != null && vt !== VAL.OBJECT) return -1
81
- if (safe && vt !== VAL.OBJECT) return -1
82
- }
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
83
80
  // Structural subtyping: walk only schemas that contain this prop.
84
81
  // Consistent slot across all → return slot; any mismatch → -1 (dynamic lookup).
85
82
  const bucket = byProp.get(prop)