@nudojs/core 1.2.0 → 1.2.2
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/{check-report-TEOZ4cPZ.d.ts → check-report-0B9Z66n0.d.ts} +1 -1
- package/dist/{chunk-WB565PQK.js → chunk-4V3CRVSD.js} +697 -221
- package/dist/{chunk-GD5XIQQK.js → chunk-TOURNNEA.js} +1 -1
- package/dist/exec.d.ts +2 -2
- package/dist/exec.js +9 -1
- package/dist/{hof-types-COqDeD5F.d.ts → hof-types-DqDpAxfh.d.ts} +14 -0
- package/dist/{index-DMjMPLV0.d.ts → index-BNiZvVHw.d.ts} +16 -3
- package/dist/index.d.ts +26 -9
- package/dist/index.js +15 -4
- package/dist/internal.d.ts +4 -4
- package/dist/internal.js +2 -2
- package/package.json +1 -1
|
@@ -30,7 +30,9 @@ function termEquals(a, b) {
|
|
|
30
30
|
}
|
|
31
31
|
function termToString(t) {
|
|
32
32
|
if (t.op === "lit") {
|
|
33
|
-
|
|
33
|
+
if (typeof t.value === "string") return JSON.stringify(t.value);
|
|
34
|
+
if (typeof t.value === "number" && Object.is(t.value, -0)) return "-0";
|
|
35
|
+
return String(t.value);
|
|
34
36
|
}
|
|
35
37
|
if (t.op === "var") return t.id;
|
|
36
38
|
if (t.op === "app" && t.fn === "get" && t.args.length === 2) {
|
|
@@ -62,12 +64,22 @@ function simplifyTerm(t) {
|
|
|
62
64
|
}
|
|
63
65
|
if (fn === "*" && args.length === 2) {
|
|
64
66
|
const [a, b] = args;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
const one = (t2) => t2.op === "lit" && t2.value === 1;
|
|
68
|
+
const surviveMulOne = (t2) => {
|
|
69
|
+
if (t2.op !== "lit") return t2;
|
|
70
|
+
const v2 = t2.value;
|
|
71
|
+
if (typeof v2 === "number") return t2;
|
|
72
|
+
if (typeof v2 === "boolean") return lit(v2 ? 1 : 0);
|
|
73
|
+
if (v2 === null) return lit(0);
|
|
74
|
+
if (typeof v2 === "string") return lit(Number(v2));
|
|
75
|
+
return lit(NaN);
|
|
76
|
+
};
|
|
77
|
+
if (one(b)) return surviveMulOne(a);
|
|
78
|
+
if (one(a)) return surviveMulOne(b);
|
|
67
79
|
}
|
|
68
80
|
if (fn === "-" && args.length === 2) {
|
|
69
81
|
const [a, b] = args;
|
|
70
|
-
if (b.op === "lit" && b.value
|
|
82
|
+
if (b.op === "lit" && Object.is(b.value, 0)) return a;
|
|
71
83
|
}
|
|
72
84
|
return app(fn, args);
|
|
73
85
|
}
|
|
@@ -174,13 +186,10 @@ function negatePred(p) {
|
|
|
174
186
|
case "ne":
|
|
175
187
|
return eq(p.a, p.b);
|
|
176
188
|
case "lt":
|
|
177
|
-
return ge(p.a, p.b);
|
|
178
189
|
case "le":
|
|
179
|
-
return gt(p.a, p.b);
|
|
180
190
|
case "gt":
|
|
181
|
-
return le(p.a, p.b);
|
|
182
191
|
case "ge":
|
|
183
|
-
return
|
|
192
|
+
return { op: "not", arg: p };
|
|
184
193
|
case "and":
|
|
185
194
|
return or(...p.args.map(negatePred));
|
|
186
195
|
case "or":
|
|
@@ -193,6 +202,13 @@ function negatePred(p) {
|
|
|
193
202
|
);
|
|
194
203
|
}
|
|
195
204
|
}
|
|
205
|
+
function totalOrderDual(p) {
|
|
206
|
+
if (p.op === "lt") return ge(p.a, p.b);
|
|
207
|
+
if (p.op === "le") return gt(p.a, p.b);
|
|
208
|
+
if (p.op === "gt") return le(p.a, p.b);
|
|
209
|
+
if (p.op === "ge") return lt(p.a, p.b);
|
|
210
|
+
return void 0;
|
|
211
|
+
}
|
|
196
212
|
function predEquals(a, b) {
|
|
197
213
|
if (a === b) return true;
|
|
198
214
|
if (a.op !== b.op) return false;
|
|
@@ -332,14 +348,18 @@ function implies(phi2, pred) {
|
|
|
332
348
|
if (expanded.op !== "not") {
|
|
333
349
|
return implies(phi2, expanded);
|
|
334
350
|
}
|
|
351
|
+
const dual = totalOrderDual(pred.arg);
|
|
352
|
+
if (dual && implies(phi2, dual)) return true;
|
|
335
353
|
if (phi2.op === "not") {
|
|
336
354
|
return implies(pred.arg, phi2.arg);
|
|
337
355
|
}
|
|
338
356
|
if (phi2.op === "and") {
|
|
339
357
|
for (const c of phi2.args) {
|
|
340
358
|
if (c.op === "not" && implies(pred.arg, c.arg)) return true;
|
|
359
|
+
if (dual && predEquals(c, dual)) return true;
|
|
341
360
|
}
|
|
342
361
|
}
|
|
362
|
+
if (dual && predEquals(phi2, dual)) return true;
|
|
343
363
|
if (pred.arg.op === "typeof" && impliesNotTypeof(phi2, pred.arg)) return true;
|
|
344
364
|
return false;
|
|
345
365
|
}
|
|
@@ -1106,10 +1126,17 @@ function pureFnNameOf(fn) {
|
|
|
1106
1126
|
if (impl?.pureName) return impl.pureName;
|
|
1107
1127
|
return fn._memoize;
|
|
1108
1128
|
}
|
|
1109
|
-
function absFunction(params, impl) {
|
|
1129
|
+
function absFunction(params, impl, opts) {
|
|
1110
1130
|
const a = {
|
|
1111
|
-
shape: {
|
|
1112
|
-
|
|
1131
|
+
shape: {
|
|
1132
|
+
k: "fn",
|
|
1133
|
+
params,
|
|
1134
|
+
...opts?.name ? { name: opts.name } : {},
|
|
1135
|
+
...opts?.paramTypes ? { paramTypes: opts.paramTypes } : {},
|
|
1136
|
+
...opts?.returnType ? { returnType: opts.returnType } : {},
|
|
1137
|
+
...opts?.slots ? { slots: opts.slots } : {}
|
|
1138
|
+
},
|
|
1139
|
+
conf: opts?.conf ?? "exact"
|
|
1113
1140
|
};
|
|
1114
1141
|
attachFnImpl(a, { params, ...impl });
|
|
1115
1142
|
return a;
|
|
@@ -1164,7 +1191,8 @@ function shapeStableKey(s, seen) {
|
|
|
1164
1191
|
const pts = (s.paramTypes ?? []).map((t) => absStableKey(t, seen)).join(",");
|
|
1165
1192
|
const ret = s.returnType ? absStableKey(s.returnType, seen) : "?";
|
|
1166
1193
|
const name = s.name ? `#${s.name}` : "";
|
|
1167
|
-
|
|
1194
|
+
const slots = s.slots ? `{${Object.keys(s.slots).sort().map((k) => `${k}:${absStableKey(s.slots[k].value, seen)}`).join(",")}}` : "";
|
|
1195
|
+
return `fn${name}(${s.params.join(",")}|${pts})=>${ret}${slots}`;
|
|
1168
1196
|
}
|
|
1169
1197
|
case "sum":
|
|
1170
1198
|
return `sum(${s.members.map((m) => absStableKey(m, seen)).join("|")})`;
|
|
@@ -1370,6 +1398,13 @@ function canonicalArrayIndex(v2) {
|
|
|
1370
1398
|
}
|
|
1371
1399
|
return void 0;
|
|
1372
1400
|
}
|
|
1401
|
+
function propertyKeyOf(a) {
|
|
1402
|
+
if (a === void 0) return void 0;
|
|
1403
|
+
if (a.term?.op !== "lit") return void 0;
|
|
1404
|
+
const v2 = a.term.value;
|
|
1405
|
+
if (typeof v2 === "symbol") return void 0;
|
|
1406
|
+
return String(v2);
|
|
1407
|
+
}
|
|
1373
1408
|
function objOf(slots, opts) {
|
|
1374
1409
|
const shape = { k: "obj", slots };
|
|
1375
1410
|
if (opts?.index) shape.index = opts.index;
|
|
@@ -1382,6 +1417,25 @@ function isObj(a) {
|
|
|
1382
1417
|
function getSlot(slots, key) {
|
|
1383
1418
|
return Object.prototype.hasOwnProperty.call(slots, key) ? slots[key] : void 0;
|
|
1384
1419
|
}
|
|
1420
|
+
function setSlot(slots, key, slot) {
|
|
1421
|
+
Object.defineProperty(slots, key, {
|
|
1422
|
+
value: slot,
|
|
1423
|
+
enumerable: true,
|
|
1424
|
+
writable: true,
|
|
1425
|
+
configurable: true
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
function setProtoAbs(o, proto) {
|
|
1429
|
+
const pv = litValue(proto);
|
|
1430
|
+
if (pv === null) return markNullProtoObj(o);
|
|
1431
|
+
if (proto.term?.op === "lit" && (pv === void 0 || typeof pv !== "object")) {
|
|
1432
|
+
return o;
|
|
1433
|
+
}
|
|
1434
|
+
if (isObj(o)) {
|
|
1435
|
+
o.shape.open = true;
|
|
1436
|
+
}
|
|
1437
|
+
return o;
|
|
1438
|
+
}
|
|
1385
1439
|
function spread(base, over) {
|
|
1386
1440
|
if (!isObj(base) && !isObj(over)) {
|
|
1387
1441
|
if (isObj(over)) return { shape: { ...over.shape, open: true }, conf: confJoin(base.conf, over.conf) };
|
|
@@ -1400,7 +1454,7 @@ function spread(base, over) {
|
|
|
1400
1454
|
const indexSlots = spreadIndexSlots(over);
|
|
1401
1455
|
if (indexSlots && isObj(base)) {
|
|
1402
1456
|
const slots2 = { ...base.shape.slots };
|
|
1403
|
-
for (const [k, s] of Object.entries(indexSlots)) slots2
|
|
1457
|
+
for (const [k, s] of Object.entries(indexSlots)) setSlot(slots2, k, s);
|
|
1404
1458
|
const shape2 = { k: "obj", slots: slots2 };
|
|
1405
1459
|
if (base.shape.open) shape2.open = true;
|
|
1406
1460
|
return { shape: shape2, conf: confJoin(base.conf, over.conf) };
|
|
@@ -1416,7 +1470,7 @@ function spread(base, over) {
|
|
|
1416
1470
|
}
|
|
1417
1471
|
const slots = { ...base.shape.slots };
|
|
1418
1472
|
for (const [k, s] of Object.entries(over.shape.slots)) {
|
|
1419
|
-
slots
|
|
1473
|
+
setSlot(slots, k, s);
|
|
1420
1474
|
}
|
|
1421
1475
|
const open = base.shape.open || over.shape.open || false;
|
|
1422
1476
|
const shape = { k: "obj", slots };
|
|
@@ -1440,8 +1494,9 @@ function spreadIndexSlots(over) {
|
|
|
1440
1494
|
const sv = over.term?.op === "lit" && typeof over.term.value === "string" ? over.term.value : void 0;
|
|
1441
1495
|
if (sv !== void 0) {
|
|
1442
1496
|
const slots = {};
|
|
1443
|
-
let i = 0;
|
|
1444
|
-
|
|
1497
|
+
for (let i = 0; i < sv.length; i++) {
|
|
1498
|
+
slots[String(i)] = { value: strLit(sv[i]) };
|
|
1499
|
+
}
|
|
1445
1500
|
return slots;
|
|
1446
1501
|
}
|
|
1447
1502
|
return void 0;
|
|
@@ -1466,7 +1521,7 @@ function joinObjects(a, b) {
|
|
|
1466
1521
|
const optional = sa.optional || sb.optional;
|
|
1467
1522
|
const jv = joinValues(sa.value, sb.value);
|
|
1468
1523
|
conf = confJoin(conf, jv.conf);
|
|
1469
|
-
slots
|
|
1524
|
+
setSlot(slots, k, { value: jv, optional });
|
|
1470
1525
|
}
|
|
1471
1526
|
return { shape: { k: "obj", slots }, conf };
|
|
1472
1527
|
}
|
|
@@ -1871,7 +1926,12 @@ function snapshotAbs(a) {
|
|
|
1871
1926
|
const nextSlot = { value: snapshotAbs(slot.value) };
|
|
1872
1927
|
if (slot.optional) nextSlot.optional = true;
|
|
1873
1928
|
if (slot.readonly) nextSlot.readonly = true;
|
|
1874
|
-
slots
|
|
1929
|
+
Object.defineProperty(slots, k, {
|
|
1930
|
+
value: nextSlot,
|
|
1931
|
+
enumerable: true,
|
|
1932
|
+
writable: true,
|
|
1933
|
+
configurable: true
|
|
1934
|
+
});
|
|
1875
1935
|
}
|
|
1876
1936
|
const next = { k: "obj", slots };
|
|
1877
1937
|
if (s.index) {
|
|
@@ -2117,7 +2177,12 @@ function substShape(s, map, cache, visiting) {
|
|
|
2117
2177
|
const nextSlot = { value: substAbsInner(slot.value, map, cache, visiting) };
|
|
2118
2178
|
if (slot.optional) nextSlot.optional = true;
|
|
2119
2179
|
if (slot.readonly) nextSlot.readonly = true;
|
|
2120
|
-
slots
|
|
2180
|
+
Object.defineProperty(slots, k, {
|
|
2181
|
+
value: nextSlot,
|
|
2182
|
+
enumerable: true,
|
|
2183
|
+
writable: true,
|
|
2184
|
+
configurable: true
|
|
2185
|
+
});
|
|
2121
2186
|
}
|
|
2122
2187
|
const next = { k: "obj", slots };
|
|
2123
2188
|
if (s.index) {
|
|
@@ -2465,9 +2530,14 @@ function concatString(a, b) {
|
|
|
2465
2530
|
);
|
|
2466
2531
|
}
|
|
2467
2532
|
const aParts = coerceToStringParts(a);
|
|
2468
|
-
const
|
|
2469
|
-
if (!aParts || !
|
|
2470
|
-
|
|
2533
|
+
const bParts = coerceToStringParts(b);
|
|
2534
|
+
if (!aParts || !bParts) {
|
|
2535
|
+
if (isStrPrim2(a) || isStrPrim2(b)) {
|
|
2536
|
+
return abs({ k: "prim", type: "string" }, void 0, void 0, "path");
|
|
2537
|
+
}
|
|
2538
|
+
return abs({ k: "unknown" }, void 0, void 0, "partial");
|
|
2539
|
+
}
|
|
2540
|
+
return createTemplateAbs([...aParts, ...bParts]);
|
|
2471
2541
|
}
|
|
2472
2542
|
function coerceToStringParts(a) {
|
|
2473
2543
|
if (isTemplateAbs(a) || isStrPrim2(a)) return templatePartsOf(a);
|
|
@@ -2723,6 +2793,12 @@ function add(a, b, phi2 = pTrue) {
|
|
|
2723
2793
|
if (typeof va === "string" || typeof vb === "string") {
|
|
2724
2794
|
return strLitResult(String(va) + String(vb));
|
|
2725
2795
|
}
|
|
2796
|
+
if (typeof va === "bigint" && typeof vb !== "bigint" || typeof vb === "bigint" && typeof va !== "bigint") {
|
|
2797
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
if (isStrPrim(a) || isStrPrim(b) || isTemplateLike(a) || isTemplateLike(b)) {
|
|
2801
|
+
return concatString(a, b);
|
|
2726
2802
|
}
|
|
2727
2803
|
if (coercibleLit(va) && coercibleLit(vb)) {
|
|
2728
2804
|
return numLit(Number(va) + Number(vb));
|
|
@@ -2732,9 +2808,6 @@ function add(a, b, phi2 = pTrue) {
|
|
|
2732
2808
|
if (isBigPrim(a) && isBigPrim(b)) {
|
|
2733
2809
|
return abs({ k: "prim", type: "bigint" }, void 0, void 0, confJoin(a.conf, b.conf));
|
|
2734
2810
|
}
|
|
2735
|
-
if (isStrPrim(a) || isStrPrim(b) || isTemplateLike(a) || isTemplateLike(b)) {
|
|
2736
|
-
return concatString(a, b);
|
|
2737
|
-
}
|
|
2738
2811
|
if (a.shape.k === "tuple" || a.shape.k === "arr" || b.shape.k === "tuple" || b.shape.k === "arr") {
|
|
2739
2812
|
return concatString(a, b);
|
|
2740
2813
|
}
|
|
@@ -2751,8 +2824,12 @@ function add(a, b, phi2 = pTrue) {
|
|
|
2751
2824
|
}
|
|
2752
2825
|
if (isAnyLike(a) || isAnyLike(b)) {
|
|
2753
2826
|
const term = a.term && b.term ? simplifyTerm(app("+", [a.term, b.term])) : void 0;
|
|
2827
|
+
const bigFace = isBigPrim(a) || isBigPrim(b);
|
|
2754
2828
|
return abs(
|
|
2755
|
-
{
|
|
2829
|
+
{
|
|
2830
|
+
k: "sum",
|
|
2831
|
+
members: bigFace ? [abs({ k: "prim", type: "bigint" }, void 0, void 0, "exact"), str()] : [num(), str()]
|
|
2832
|
+
},
|
|
2756
2833
|
term,
|
|
2757
2834
|
void 0,
|
|
2758
2835
|
"partial"
|
|
@@ -2785,6 +2862,15 @@ function add(a, b, phi2 = pTrue) {
|
|
|
2785
2862
|
}
|
|
2786
2863
|
return abs({ k: "unknown" }, void 0, void 0, "partial");
|
|
2787
2864
|
}
|
|
2865
|
+
function isKnownNonBigintNumeric(a) {
|
|
2866
|
+
const va = litValue(a);
|
|
2867
|
+
if (typeof va === "number" || typeof va === "boolean" || va === null) return true;
|
|
2868
|
+
if (a.term?.op === "lit" && a.term.value === void 0) return true;
|
|
2869
|
+
return a.shape.k === "prim" && (a.shape.type === "number" || a.shape.type === "boolean");
|
|
2870
|
+
}
|
|
2871
|
+
function isMaybeBigintOperand(a) {
|
|
2872
|
+
return a.shape.k === "any" || a.shape.k === "unknown" || a.shape.k === "obj" || a.shape.k === "fn" || a.shape.k === "brand" || a.shape.k === "sum";
|
|
2873
|
+
}
|
|
2788
2874
|
function foldBigintBinOp(a, b, op) {
|
|
2789
2875
|
const va = litValue(a);
|
|
2790
2876
|
const vb = litValue(b);
|
|
@@ -2792,13 +2878,27 @@ function foldBigintBinOp(a, b, op) {
|
|
|
2792
2878
|
if (typeof va === "bigint" && typeof vb === "bigint") {
|
|
2793
2879
|
try {
|
|
2794
2880
|
return bigintLit(op(va, vb));
|
|
2795
|
-
} catch {
|
|
2796
|
-
|
|
2881
|
+
} catch (e) {
|
|
2882
|
+
if (e instanceof RangeError) throw new NudoThrow(errorTypeAbs("RangeError"));
|
|
2883
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
2797
2884
|
}
|
|
2798
2885
|
}
|
|
2799
2886
|
const other = typeof va === "bigint" ? b : a;
|
|
2800
2887
|
if (isBigPrim(other)) return void 0;
|
|
2801
|
-
|
|
2888
|
+
if (isKnownNonBigintNumeric(other)) {
|
|
2889
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
2890
|
+
}
|
|
2891
|
+
if (isStrPrim(other)) {
|
|
2892
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
2893
|
+
}
|
|
2894
|
+
if (isMaybeBigintOperand(other)) {
|
|
2895
|
+
recordMayThrow({
|
|
2896
|
+
kind: "TypeError",
|
|
2897
|
+
cause: "mixed bigint \u2297 abstract operand"
|
|
2898
|
+
});
|
|
2899
|
+
return void 0;
|
|
2900
|
+
}
|
|
2901
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
2802
2902
|
}
|
|
2803
2903
|
function dedupAbsMembers(ms) {
|
|
2804
2904
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -2821,6 +2921,12 @@ function strLitResult(s) {
|
|
|
2821
2921
|
function normalizeNegZero(n) {
|
|
2822
2922
|
return n === 0 ? 0 : n;
|
|
2823
2923
|
}
|
|
2924
|
+
function ieeeBound(n, strict, strictZeroOk) {
|
|
2925
|
+
if (!Number.isFinite(n)) return void 0;
|
|
2926
|
+
const z = normalizeNegZero(n);
|
|
2927
|
+
if (z === 0 && strict && !strictZeroOk) return void 0;
|
|
2928
|
+
return z;
|
|
2929
|
+
}
|
|
2824
2930
|
function isAnyLike(a) {
|
|
2825
2931
|
if (a.shape.k === "any") return true;
|
|
2826
2932
|
if (a.shape.k === "unknown") return true;
|
|
@@ -2831,8 +2937,9 @@ function coercibleLit(v2) {
|
|
|
2831
2937
|
}
|
|
2832
2938
|
function toNumberResult(a, b, op) {
|
|
2833
2939
|
const term = a.term && b.term ? app(op, [a.term, b.term]) : void 0;
|
|
2940
|
+
const bigFace = isBigPrim(a) || isBigPrim(b);
|
|
2834
2941
|
return abs(
|
|
2835
|
-
{ k: "prim", type: "number" },
|
|
2942
|
+
bigFace ? { k: "prim", type: "bigint" } : { k: "prim", type: "number" },
|
|
2836
2943
|
term,
|
|
2837
2944
|
void 0,
|
|
2838
2945
|
term ? confJoin(confJoin(a.conf, b.conf), "partial") : "partial"
|
|
@@ -2847,14 +2954,18 @@ function addPred(a, b, sumTerm, phi2) {
|
|
|
2847
2954
|
if (!aBounds && !evalBounds) return void 0;
|
|
2848
2955
|
const facts = [];
|
|
2849
2956
|
if (aBounds?.lo !== void 0 && evalBounds?.lo !== void 0) {
|
|
2850
|
-
const loSum = aBounds.lo.value + evalBounds.lo.value;
|
|
2851
2957
|
const strict = aBounds.lo.strict || evalBounds.lo.strict;
|
|
2852
|
-
|
|
2958
|
+
const loSum = ieeeBound(aBounds.lo.value + evalBounds.lo.value, strict, true);
|
|
2959
|
+
if (loSum !== void 0) {
|
|
2960
|
+
facts.push(strict ? gt(sumTerm, lit(loSum)) : ge(sumTerm, lit(loSum)));
|
|
2961
|
+
}
|
|
2853
2962
|
}
|
|
2854
2963
|
if (aBounds?.hi !== void 0 && evalBounds?.hi !== void 0) {
|
|
2855
|
-
const hiSum = aBounds.hi.value + evalBounds.hi.value;
|
|
2856
2964
|
const strict = aBounds.hi.strict || evalBounds.hi.strict;
|
|
2857
|
-
|
|
2965
|
+
const hiSum = ieeeBound(aBounds.hi.value + evalBounds.hi.value, strict, true);
|
|
2966
|
+
if (hiSum !== void 0) {
|
|
2967
|
+
facts.push(strict ? lt(sumTerm, lit(hiSum)) : le(sumTerm, lit(hiSum)));
|
|
2968
|
+
}
|
|
2858
2969
|
}
|
|
2859
2970
|
if (facts.length === 0) return void 0;
|
|
2860
2971
|
return and(...facts);
|
|
@@ -2868,77 +2979,57 @@ function numericBounds(a, phi2 = pTrue) {
|
|
|
2868
2979
|
if (a.term?.op === "var") {
|
|
2869
2980
|
collectBoundsFromPhi(phi2, a.term.id, result);
|
|
2870
2981
|
}
|
|
2871
|
-
if (a.term?.op === "lit" && typeof a.term.value === "number") {
|
|
2982
|
+
if (a.term?.op === "lit" && typeof a.term.value === "number" && !Number.isNaN(a.term.value)) {
|
|
2872
2983
|
result.lo = { value: a.term.value, strict: false };
|
|
2873
2984
|
result.hi = { value: a.term.value, strict: false };
|
|
2874
2985
|
}
|
|
2875
2986
|
if (result.lo === void 0 && result.hi === void 0) return void 0;
|
|
2876
2987
|
return result;
|
|
2877
2988
|
}
|
|
2989
|
+
function tightenLo2(acc, n, strict) {
|
|
2990
|
+
if (acc.lo === void 0 || n > acc.lo.value || n === acc.lo.value && strict && !acc.lo.strict) {
|
|
2991
|
+
acc.lo = { value: n, strict };
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
function tightenHi2(acc, n, strict) {
|
|
2995
|
+
if (acc.hi === void 0 || n < acc.hi.value || n === acc.hi.value && strict && !acc.hi.strict) {
|
|
2996
|
+
acc.hi = { value: n, strict };
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
function noteBoundFromRel(p, isTarget, acc) {
|
|
3000
|
+
if (p.op !== "gt" && p.op !== "ge" && p.op !== "lt" && p.op !== "le") return;
|
|
3001
|
+
let op = p.op;
|
|
3002
|
+
let litSide;
|
|
3003
|
+
if (isTarget(p.a) && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
3004
|
+
litSide = p.b;
|
|
3005
|
+
} else if (isTarget(p.b) && p.a.op === "lit" && typeof p.a.value === "number") {
|
|
3006
|
+
op = op === "gt" ? "lt" : op === "lt" ? "gt" : op === "ge" ? "le" : "ge";
|
|
3007
|
+
litSide = p.a;
|
|
3008
|
+
} else {
|
|
3009
|
+
return;
|
|
3010
|
+
}
|
|
3011
|
+
const n = litSide.value;
|
|
3012
|
+
if (op === "gt") tightenLo2(acc, n, true);
|
|
3013
|
+
else if (op === "ge") tightenLo2(acc, n, false);
|
|
3014
|
+
else if (op === "lt") tightenHi2(acc, n, true);
|
|
3015
|
+
else tightenHi2(acc, n, false);
|
|
3016
|
+
}
|
|
2878
3017
|
function collectBoundsFromPred(pred, term, acc) {
|
|
2879
|
-
const
|
|
3018
|
+
const isTarget = (t) => termToString(t) === termToString(term);
|
|
2880
3019
|
const apply = (p) => {
|
|
2881
3020
|
if (p.op === "and") {
|
|
2882
3021
|
p.args.forEach(apply);
|
|
2883
3022
|
return;
|
|
2884
3023
|
}
|
|
2885
|
-
|
|
2886
|
-
const n = p.b.value;
|
|
2887
|
-
if (acc.lo === void 0 || n > acc.lo.value || n === acc.lo.value && !acc.lo.strict) {
|
|
2888
|
-
acc.lo = { value: n, strict: true };
|
|
2889
|
-
}
|
|
2890
|
-
return;
|
|
2891
|
-
}
|
|
2892
|
-
if (p.op === "ge" && match(p.a) && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
2893
|
-
const n = p.b.value;
|
|
2894
|
-
if (acc.lo === void 0 || n > acc.lo.value) {
|
|
2895
|
-
acc.lo = { value: n, strict: false };
|
|
2896
|
-
}
|
|
2897
|
-
return;
|
|
2898
|
-
}
|
|
2899
|
-
if (p.op === "lt" && match(p.a) && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
2900
|
-
const n = p.b.value;
|
|
2901
|
-
if (acc.hi === void 0 || n < acc.hi.value || n === acc.hi.value && !acc.hi.strict) {
|
|
2902
|
-
acc.hi = { value: n, strict: true };
|
|
2903
|
-
}
|
|
2904
|
-
return;
|
|
2905
|
-
}
|
|
2906
|
-
if (p.op === "le" && match(p.a) && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
2907
|
-
const n = p.b.value;
|
|
2908
|
-
if (acc.hi === void 0 || n < acc.hi.value) {
|
|
2909
|
-
acc.hi = { value: n, strict: false };
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
3024
|
+
noteBoundFromRel(p, isTarget, acc);
|
|
2912
3025
|
};
|
|
2913
3026
|
apply(pred);
|
|
2914
3027
|
}
|
|
2915
3028
|
function collectBoundsFromPhi(phi2, id, acc) {
|
|
3029
|
+
const isTarget = (t) => t.op === "var" && t.id === id;
|
|
2916
3030
|
const conjs = phi2.op === "and" ? phi2.args : [phi2];
|
|
2917
3031
|
for (const p of conjs) {
|
|
2918
|
-
|
|
2919
|
-
const n = p.b.value;
|
|
2920
|
-
if (acc.lo === void 0 || n > acc.lo.value || n === acc.lo.value && !acc.lo.strict) {
|
|
2921
|
-
acc.lo = { value: n, strict: true };
|
|
2922
|
-
}
|
|
2923
|
-
}
|
|
2924
|
-
if (p.op === "ge" && p.a.op === "var" && p.a.id === id && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
2925
|
-
const n = p.b.value;
|
|
2926
|
-
if (acc.lo === void 0 || n > acc.lo.value) {
|
|
2927
|
-
acc.lo = { value: n, strict: false };
|
|
2928
|
-
}
|
|
2929
|
-
}
|
|
2930
|
-
if (p.op === "lt" && p.a.op === "var" && p.a.id === id && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
2931
|
-
const n = p.b.value;
|
|
2932
|
-
if (acc.hi === void 0 || n < acc.hi.value || n === acc.hi.value && !acc.hi.strict) {
|
|
2933
|
-
acc.hi = { value: n, strict: true };
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
if (p.op === "le" && p.a.op === "var" && p.a.id === id && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
2937
|
-
const n = p.b.value;
|
|
2938
|
-
if (acc.hi === void 0 || n < acc.hi.value) {
|
|
2939
|
-
acc.hi = { value: n, strict: false };
|
|
2940
|
-
}
|
|
2941
|
-
}
|
|
3032
|
+
noteBoundFromRel(p, isTarget, acc);
|
|
2942
3033
|
}
|
|
2943
3034
|
}
|
|
2944
3035
|
function sub(a, b, phi2 = pTrue) {
|
|
@@ -2961,14 +3052,18 @@ function sub(a, b, phi2 = pTrue) {
|
|
|
2961
3052
|
const bb = numericBounds(b, phi2);
|
|
2962
3053
|
const facts = [];
|
|
2963
3054
|
if (ab?.lo !== void 0 && bb?.hi !== void 0) {
|
|
2964
|
-
const lo = ab.lo.value - bb.hi.value;
|
|
2965
3055
|
const strict = ab.lo.strict || bb.hi.strict;
|
|
2966
|
-
|
|
3056
|
+
const lo = ieeeBound(ab.lo.value - bb.hi.value, strict, true);
|
|
3057
|
+
if (lo !== void 0) {
|
|
3058
|
+
facts.push(strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
3059
|
+
}
|
|
2967
3060
|
}
|
|
2968
3061
|
if (ab?.hi !== void 0 && bb?.lo !== void 0) {
|
|
2969
|
-
const hi = ab.hi.value - bb.lo.value;
|
|
2970
3062
|
const strict = ab.hi.strict || bb.lo.strict;
|
|
2971
|
-
|
|
3063
|
+
const hi = ieeeBound(ab.hi.value - bb.lo.value, strict, true);
|
|
3064
|
+
if (hi !== void 0) {
|
|
3065
|
+
facts.push(strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
3066
|
+
}
|
|
2972
3067
|
}
|
|
2973
3068
|
const conf = term.op === "lit" ? "exact" : confJoin(confJoin(a.conf, b.conf), facts.length ? "path" : "path");
|
|
2974
3069
|
return abs({ k: "prim", type: "number" }, term, facts.length ? and(...facts) : void 0, conf);
|
|
@@ -3006,25 +3101,26 @@ function mul(a, b, phi2 = pTrue) {
|
|
|
3006
3101
|
k = a.term.value;
|
|
3007
3102
|
base = b;
|
|
3008
3103
|
}
|
|
3009
|
-
if (k !== void 0 && base !== void 0 && k !== 0) {
|
|
3104
|
+
if (k !== void 0 && base !== void 0 && k !== 0 && Number.isFinite(k)) {
|
|
3105
|
+
const strictZeroOk = Math.abs(k) >= 1;
|
|
3010
3106
|
const ab = numericBounds(base, phi2);
|
|
3011
3107
|
const facts = [];
|
|
3012
3108
|
if (ab?.lo !== void 0) {
|
|
3013
3109
|
if (k > 0) {
|
|
3014
|
-
const lo = ab.lo.value * k;
|
|
3015
|
-
facts.push(ab.lo.strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
3110
|
+
const lo = ieeeBound(ab.lo.value * k, ab.lo.strict, strictZeroOk);
|
|
3111
|
+
if (lo !== void 0) facts.push(ab.lo.strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
3016
3112
|
} else {
|
|
3017
|
-
const hi = ab.lo.value * k;
|
|
3018
|
-
facts.push(ab.lo.strict ? lt(term, lit(
|
|
3113
|
+
const hi = ieeeBound(ab.lo.value * k, ab.lo.strict, strictZeroOk);
|
|
3114
|
+
if (hi !== void 0) facts.push(ab.lo.strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
3019
3115
|
}
|
|
3020
3116
|
}
|
|
3021
3117
|
if (ab?.hi !== void 0) {
|
|
3022
3118
|
if (k > 0) {
|
|
3023
|
-
const hi = ab.hi.value * k;
|
|
3024
|
-
facts.push(ab.hi.strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
3119
|
+
const hi = ieeeBound(ab.hi.value * k, ab.hi.strict, strictZeroOk);
|
|
3120
|
+
if (hi !== void 0) facts.push(ab.hi.strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
3025
3121
|
} else {
|
|
3026
|
-
const lo = ab.hi.value * k;
|
|
3027
|
-
facts.push(ab.hi.strict ? gt(term, lit(
|
|
3122
|
+
const lo = ieeeBound(ab.hi.value * k, ab.hi.strict, strictZeroOk);
|
|
3123
|
+
if (lo !== void 0) facts.push(ab.hi.strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
3028
3124
|
}
|
|
3029
3125
|
}
|
|
3030
3126
|
return abs(
|
|
@@ -3068,19 +3164,24 @@ function div(a, b, phi2 = pTrue) {
|
|
|
3068
3164
|
}
|
|
3069
3165
|
if (isNumericLike(a) && isNumericLike(b) && a.term && b.term) {
|
|
3070
3166
|
const term = simplifyTerm(app("/", [a.term, b.term]));
|
|
3071
|
-
if (b.term.op === "lit" && typeof b.term.value === "number" && b.term.value !== 0) {
|
|
3167
|
+
if (b.term.op === "lit" && typeof b.term.value === "number" && b.term.value !== 0 && Number.isFinite(b.term.value)) {
|
|
3072
3168
|
const k = b.term.value;
|
|
3169
|
+
const strictZeroOk = Math.abs(k) <= 1;
|
|
3073
3170
|
const ab = numericBounds(a, phi2);
|
|
3074
3171
|
const facts = [];
|
|
3075
3172
|
if (ab?.lo !== void 0) {
|
|
3076
|
-
const lo = ab.lo.value / k;
|
|
3077
|
-
if (
|
|
3078
|
-
|
|
3173
|
+
const lo = ieeeBound(ab.lo.value / k, ab.lo.strict, strictZeroOk);
|
|
3174
|
+
if (lo !== void 0) {
|
|
3175
|
+
if (k > 0) facts.push(ab.lo.strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
3176
|
+
else facts.push(ab.lo.strict ? lt(term, lit(lo)) : le(term, lit(lo)));
|
|
3177
|
+
}
|
|
3079
3178
|
}
|
|
3080
3179
|
if (ab?.hi !== void 0) {
|
|
3081
|
-
const hi = ab.hi.value / k;
|
|
3082
|
-
if (
|
|
3083
|
-
|
|
3180
|
+
const hi = ieeeBound(ab.hi.value / k, ab.hi.strict, strictZeroOk);
|
|
3181
|
+
if (hi !== void 0) {
|
|
3182
|
+
if (k > 0) facts.push(ab.hi.strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
3183
|
+
else facts.push(ab.hi.strict ? gt(term, lit(hi)) : ge(term, lit(hi)));
|
|
3184
|
+
}
|
|
3084
3185
|
}
|
|
3085
3186
|
return abs(
|
|
3086
3187
|
num().shape,
|
|
@@ -3161,8 +3262,9 @@ function cmp(op, a, b, phi2 = pTrue) {
|
|
|
3161
3262
|
if (a.term && b.term) {
|
|
3162
3263
|
const pred = op === "lt" ? lt(a.term, b.term) : op === "le" ? le(a.term, b.term) : op === "gt" ? gt(a.term, b.term) : op === "ge" ? ge(a.term, b.term) : op === "eq" ? { op: "eq", a: a.term, b: b.term } : { op: "ne", a: a.term, b: b.term };
|
|
3163
3264
|
if (implies(phi2, pred)) return boolLit(true);
|
|
3164
|
-
|
|
3165
|
-
|
|
3265
|
+
if (implies(phi2, negatePred(pred))) return boolLit(false);
|
|
3266
|
+
const dual = totalOrderDual(pred) ?? (op === "eq" ? { op: "ne", a: a.term, b: b.term } : op === "ne" ? { op: "eq", a: a.term, b: b.term } : void 0);
|
|
3267
|
+
if (dual && implies(phi2, dual)) return boolLit(false);
|
|
3166
3268
|
const decided = decideByBounds(op, a, b, phi2);
|
|
3167
3269
|
if (decided !== void 0) return boolLit(decided);
|
|
3168
3270
|
return {
|
|
@@ -3226,24 +3328,26 @@ function decideByBounds(op, a, b, phi2) {
|
|
|
3226
3328
|
const aHi = aB?.hi;
|
|
3227
3329
|
const bLo = bB?.lo;
|
|
3228
3330
|
const bHi = bB?.hi;
|
|
3331
|
+
const tighterHi = (x, y) => x.value < y.value || x.value === y.value && (x.strict || y.strict);
|
|
3332
|
+
const tighterLo = (x, y) => x.value > y.value || x.value === y.value && (x.strict || y.strict);
|
|
3229
3333
|
if (op === "lt") {
|
|
3230
|
-
if (aHi && bLo && aHi
|
|
3334
|
+
if (aHi && bLo && tighterHi(aHi, bLo)) return true;
|
|
3231
3335
|
if (aLo && bHi && aLo.value >= bHi.value) return false;
|
|
3232
3336
|
return void 0;
|
|
3233
3337
|
}
|
|
3234
3338
|
if (op === "le") {
|
|
3235
|
-
if (aHi && bLo && aHi.value
|
|
3236
|
-
if (aLo && bHi && aLo
|
|
3339
|
+
if (aHi && bLo && aHi.value <= bLo.value) return true;
|
|
3340
|
+
if (aLo && bHi && tighterLo(aLo, bHi)) return false;
|
|
3237
3341
|
return void 0;
|
|
3238
3342
|
}
|
|
3239
3343
|
if (op === "gt") {
|
|
3240
|
-
if (aLo && bHi && aLo
|
|
3344
|
+
if (aLo && bHi && tighterLo(aLo, bHi)) return true;
|
|
3241
3345
|
if (aHi && bLo && aHi.value <= bLo.value) return false;
|
|
3242
3346
|
return void 0;
|
|
3243
3347
|
}
|
|
3244
3348
|
if (op === "ge") {
|
|
3245
3349
|
if (aLo && bHi && aLo.value >= bHi.value) return true;
|
|
3246
|
-
if (aHi && bLo && aHi
|
|
3350
|
+
if (aHi && bLo && tighterHi(aHi, bLo)) return false;
|
|
3247
3351
|
return void 0;
|
|
3248
3352
|
}
|
|
3249
3353
|
return void 0;
|
|
@@ -3301,6 +3405,13 @@ function extStateOf(o) {
|
|
|
3301
3405
|
function getPropFlags(o) {
|
|
3302
3406
|
return propFlagsTable.get(o);
|
|
3303
3407
|
}
|
|
3408
|
+
function enumOwnKeys(o, slots) {
|
|
3409
|
+
const flags = getPropFlags(o);
|
|
3410
|
+
return Object.keys(slots).filter((k) => flags?.get(k)?.enumerable !== false);
|
|
3411
|
+
}
|
|
3412
|
+
function isEnumerableView(o, key) {
|
|
3413
|
+
return getPropFlags(o)?.get(key)?.enumerable !== false;
|
|
3414
|
+
}
|
|
3304
3415
|
function setPropFlags(o, key, f) {
|
|
3305
3416
|
let m = propFlagsTable.get(o);
|
|
3306
3417
|
if (!m) {
|
|
@@ -3568,7 +3679,7 @@ function assignSourceSlots(src) {
|
|
|
3568
3679
|
const slots = {};
|
|
3569
3680
|
for (const [k, v2] of Object.entries(inner.shape.slots)) {
|
|
3570
3681
|
if (k === "length") continue;
|
|
3571
|
-
slots
|
|
3682
|
+
setSlot(slots, k, v2);
|
|
3572
3683
|
}
|
|
3573
3684
|
if (Object.keys(slots).length > 0 || !inner.shape.open) return slots;
|
|
3574
3685
|
}
|
|
@@ -3653,8 +3764,12 @@ function evalObjectMethod(name, args) {
|
|
|
3653
3764
|
);
|
|
3654
3765
|
}
|
|
3655
3766
|
if (a0?.term?.op === "lit" && typeof a0.term.value === "string") {
|
|
3767
|
+
const s = a0.term.value;
|
|
3656
3768
|
return abs(
|
|
3657
|
-
{
|
|
3769
|
+
{
|
|
3770
|
+
k: "tuple",
|
|
3771
|
+
elements: Array.from({ length: s.length }, (_, i) => strLit(s[i]))
|
|
3772
|
+
},
|
|
3658
3773
|
void 0,
|
|
3659
3774
|
void 0,
|
|
3660
3775
|
"exact"
|
|
@@ -3684,12 +3799,13 @@ function evalObjectMethod(name, args) {
|
|
|
3684
3799
|
return abs({ k: "tuple", elements: entries }, void 0, void 0, "exact");
|
|
3685
3800
|
}
|
|
3686
3801
|
if (a0?.term?.op === "lit" && typeof a0.term.value === "string") {
|
|
3802
|
+
const s = a0.term.value;
|
|
3687
3803
|
return abs(
|
|
3688
3804
|
{
|
|
3689
3805
|
k: "tuple",
|
|
3690
3806
|
elements: Array.from(
|
|
3691
|
-
|
|
3692
|
-
(
|
|
3807
|
+
{ length: s.length },
|
|
3808
|
+
(_, i) => abs({ k: "tuple", elements: [strLit(String(i)), strLit(s[i])] }, void 0, void 0, "exact")
|
|
3693
3809
|
)
|
|
3694
3810
|
},
|
|
3695
3811
|
void 0,
|
|
@@ -3724,6 +3840,21 @@ function evalObjectMethod(name, args) {
|
|
|
3724
3840
|
}
|
|
3725
3841
|
return protoOfRecv(a0);
|
|
3726
3842
|
}
|
|
3843
|
+
case "setPrototypeOf": {
|
|
3844
|
+
if (!args.length) {
|
|
3845
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
3846
|
+
}
|
|
3847
|
+
const t0 = args[0];
|
|
3848
|
+
const p0 = args[1];
|
|
3849
|
+
if (!t0 || !p0) {
|
|
3850
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
3851
|
+
}
|
|
3852
|
+
const pv = litValue(p0);
|
|
3853
|
+
if (p0.term?.op === "lit" && (pv === void 0 || pv !== null && typeof pv !== "object")) {
|
|
3854
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
3855
|
+
}
|
|
3856
|
+
return setProtoAbs(t0, p0);
|
|
3857
|
+
}
|
|
3727
3858
|
case "assign": {
|
|
3728
3859
|
if (!args.length) return unknown;
|
|
3729
3860
|
const t0 = args[0];
|
|
@@ -3740,7 +3871,11 @@ function evalObjectMethod(name, args) {
|
|
|
3740
3871
|
if (acc.shape.k === "obj" && src.shape.k === "obj") {
|
|
3741
3872
|
const base = acc.shape.slots;
|
|
3742
3873
|
const over = src.shape.slots;
|
|
3743
|
-
|
|
3874
|
+
const filtered = { ...base };
|
|
3875
|
+
for (const k of enumKeys(over, src)) {
|
|
3876
|
+
filtered[k] = over[k];
|
|
3877
|
+
}
|
|
3878
|
+
acc = abs({ k: "obj", slots: filtered }, void 0, void 0, confJoin(acc.conf, src.conf));
|
|
3744
3879
|
} else if (src.shape.k !== "obj") {
|
|
3745
3880
|
const srcSlots = assignSourceSlots(src);
|
|
3746
3881
|
if (srcSlots === void 0) {
|
|
@@ -3985,9 +4120,9 @@ function jsonValueToAbs(v2) {
|
|
|
3985
4120
|
if (Array.isArray(v2)) {
|
|
3986
4121
|
return abs({ k: "tuple", elements: v2.map(jsonValueToAbs) }, void 0, void 0, "exact");
|
|
3987
4122
|
}
|
|
3988
|
-
const slots =
|
|
4123
|
+
const slots = /* @__PURE__ */ Object.create(null);
|
|
3989
4124
|
for (const [k, sv] of Object.entries(v2)) {
|
|
3990
|
-
slots
|
|
4125
|
+
setSlot(slots, k, { value: jsonValueToAbs(sv) });
|
|
3991
4126
|
}
|
|
3992
4127
|
return abs({ k: "obj", slots }, void 0, void 0, "exact");
|
|
3993
4128
|
}
|
|
@@ -4041,9 +4176,7 @@ function evalJsonMethod(name, args) {
|
|
|
4041
4176
|
const t = spaceArg.term;
|
|
4042
4177
|
if (t?.op !== "lit") return str2("partial");
|
|
4043
4178
|
const sv = t.value;
|
|
4044
|
-
if (typeof sv === "number") {
|
|
4045
|
-
space = Number.isFinite(sv) ? Math.min(10, Math.max(0, Math.floor(sv))) : 0;
|
|
4046
|
-
} else if (typeof sv === "string") {
|
|
4179
|
+
if (typeof sv === "number" || typeof sv === "string") {
|
|
4047
4180
|
space = sv;
|
|
4048
4181
|
} else if (sv !== void 0 && sv !== null) {
|
|
4049
4182
|
return str2("partial");
|
|
@@ -5480,6 +5613,37 @@ function evalBuiltinNew(className, args) {
|
|
|
5480
5613
|
return evalPromiseCtor(args);
|
|
5481
5614
|
case "Array":
|
|
5482
5615
|
return makeArrayCtorAbs(args);
|
|
5616
|
+
case "Number":
|
|
5617
|
+
case "Boolean":
|
|
5618
|
+
return abs(
|
|
5619
|
+
{ k: "brand", name: className, shape: objOf({}) },
|
|
5620
|
+
void 0,
|
|
5621
|
+
void 0,
|
|
5622
|
+
"path"
|
|
5623
|
+
);
|
|
5624
|
+
case "String": {
|
|
5625
|
+
const a0 = args[0] ? litValue(args[0]) : void 0;
|
|
5626
|
+
if (typeof a0 === "string") {
|
|
5627
|
+
const slots = {
|
|
5628
|
+
length: { value: numLit(a0.length) }
|
|
5629
|
+
};
|
|
5630
|
+
for (let i = 0; i < a0.length; i++) {
|
|
5631
|
+
slots[String(i)] = { value: strLit(a0[i]) };
|
|
5632
|
+
}
|
|
5633
|
+
return abs(
|
|
5634
|
+
{ k: "brand", name: "String", shape: objOf(slots) },
|
|
5635
|
+
void 0,
|
|
5636
|
+
void 0,
|
|
5637
|
+
"exact"
|
|
5638
|
+
);
|
|
5639
|
+
}
|
|
5640
|
+
return abs(
|
|
5641
|
+
{ k: "brand", name: "String", shape: objOf({}, { open: true }) },
|
|
5642
|
+
void 0,
|
|
5643
|
+
void 0,
|
|
5644
|
+
"path"
|
|
5645
|
+
);
|
|
5646
|
+
}
|
|
5483
5647
|
case "Map":
|
|
5484
5648
|
if (ctorArgDefinitelyInvalid("Map", args[0])) {
|
|
5485
5649
|
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
@@ -5723,6 +5887,7 @@ function evalObjectProtoMethod(name, thisVal, args) {
|
|
|
5723
5887
|
if (!vObjLike && vk !== "sum" && vk !== "any" && vk !== "unknown") return boolLit(false);
|
|
5724
5888
|
if (vObjLike && isNullProtoObj(v2)) return boolLit(false);
|
|
5725
5889
|
if (isObjectProtoBrand(thisVal)) {
|
|
5890
|
+
if (isObjectProtoBrand(v2)) return boolLit(false);
|
|
5726
5891
|
return vObjLike ? boolLit(true) : boolPrimB();
|
|
5727
5892
|
}
|
|
5728
5893
|
return boolPrimB();
|
|
@@ -5756,27 +5921,50 @@ function objectProtoMethodAbs(name) {
|
|
|
5756
5921
|
function coercibleNumberLit(v2) {
|
|
5757
5922
|
return typeof v2 === "number" || typeof v2 === "string" || typeof v2 === "boolean" || v2 === null;
|
|
5758
5923
|
}
|
|
5759
|
-
function
|
|
5760
|
-
|
|
5924
|
+
function isKnownNonBigintNumeric2(a) {
|
|
5925
|
+
const va = litValue(a);
|
|
5926
|
+
if (typeof va === "number" || typeof va === "boolean" || va === null) return true;
|
|
5927
|
+
if (a.term?.op === "lit" && a.term.value === void 0) return true;
|
|
5928
|
+
return a.shape.k === "prim" && (a.shape.type === "number" || a.shape.type === "boolean");
|
|
5929
|
+
}
|
|
5930
|
+
function isMaybeBigintOperand2(a) {
|
|
5931
|
+
return a.shape.k === "any" || a.shape.k === "unknown" || a.shape.k === "obj" || a.shape.k === "fn" || a.shape.k === "brand" || a.shape.k === "sum";
|
|
5761
5932
|
}
|
|
5762
5933
|
function foldNumericBinOp(a, b, numOp, bigOp) {
|
|
5763
5934
|
const va = litValue(a);
|
|
5764
5935
|
const vb = litValue(b);
|
|
5936
|
+
if (!bigOp && (typeof va === "bigint" || typeof vb === "bigint" || isBigPrim(a) || isBigPrim(b))) {
|
|
5937
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
5938
|
+
}
|
|
5765
5939
|
if (typeof va === "bigint" || typeof vb === "bigint") {
|
|
5766
5940
|
if (typeof va === "bigint" && typeof vb === "bigint") {
|
|
5767
|
-
|
|
5941
|
+
const op = bigOp;
|
|
5768
5942
|
try {
|
|
5769
5943
|
return abs(
|
|
5770
5944
|
{ k: "prim", type: "bigint" },
|
|
5771
|
-
lit(
|
|
5945
|
+
lit(op(va, vb)),
|
|
5772
5946
|
pTrue,
|
|
5773
5947
|
"exact"
|
|
5774
5948
|
);
|
|
5775
|
-
} catch {
|
|
5776
|
-
|
|
5949
|
+
} catch (e) {
|
|
5950
|
+
if (e instanceof RangeError) throw new NudoThrow(errorTypeAbs("RangeError"));
|
|
5951
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
5777
5952
|
}
|
|
5778
5953
|
}
|
|
5779
|
-
|
|
5954
|
+
const other = typeof va === "bigint" ? b : a;
|
|
5955
|
+
if (isBigPrim(other)) return void 0;
|
|
5956
|
+
if (!bigOp) throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
5957
|
+
if (isKnownNonBigintNumeric2(other) || isStrPrim(other)) {
|
|
5958
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
5959
|
+
}
|
|
5960
|
+
if (isMaybeBigintOperand2(other)) {
|
|
5961
|
+
recordMayThrow({
|
|
5962
|
+
kind: "TypeError",
|
|
5963
|
+
cause: "mixed bigint \u2297 abstract operand"
|
|
5964
|
+
});
|
|
5965
|
+
return void 0;
|
|
5966
|
+
}
|
|
5967
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
5780
5968
|
}
|
|
5781
5969
|
if (coercibleNumberLit(va) && coercibleNumberLit(vb)) {
|
|
5782
5970
|
return abs(
|
|
@@ -5791,11 +5979,12 @@ function foldNumericBinOp(a, b, numOp, bigOp) {
|
|
|
5791
5979
|
function foldNumericUnOp(a, numOp, bigOp) {
|
|
5792
5980
|
const v2 = litValue(a);
|
|
5793
5981
|
if (typeof v2 === "bigint") {
|
|
5794
|
-
if (!bigOp)
|
|
5982
|
+
if (!bigOp) throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
5795
5983
|
try {
|
|
5796
5984
|
return abs({ k: "prim", type: "bigint" }, lit(bigOp(v2)), pTrue, "exact");
|
|
5797
|
-
} catch {
|
|
5798
|
-
|
|
5985
|
+
} catch (e) {
|
|
5986
|
+
if (e instanceof RangeError) throw new NudoThrow(errorTypeAbs("RangeError"));
|
|
5987
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
5799
5988
|
}
|
|
5800
5989
|
}
|
|
5801
5990
|
if (coercibleNumberLit(v2)) {
|
|
@@ -5848,10 +6037,65 @@ function ushrAbs(a, b) {
|
|
|
5848
6037
|
function powAbs(a, b) {
|
|
5849
6038
|
return foldNumericBinOp(a, b, (x, y) => x ** y, (x, y) => x ** y) ?? bitwiseResultShape(a, b);
|
|
5850
6039
|
}
|
|
6040
|
+
function toNumericAbs(a) {
|
|
6041
|
+
const v2 = litValue(a);
|
|
6042
|
+
if (typeof v2 === "bigint") return bigintLit(v2);
|
|
6043
|
+
if (isBigPrim(a)) return a;
|
|
6044
|
+
if (a.term?.op === "lit" && a.term.value === void 0) {
|
|
6045
|
+
return abs({ k: "prim", type: "number" }, lit(NaN), pTrue, "exact");
|
|
6046
|
+
}
|
|
6047
|
+
const n = toNumberAbs(a);
|
|
6048
|
+
if (n.shape.k === "unknown") {
|
|
6049
|
+
return abs({ k: "prim", type: "number" }, void 0, void 0, "partial");
|
|
6050
|
+
}
|
|
6051
|
+
return n;
|
|
6052
|
+
}
|
|
6053
|
+
function updateAddAbs(a) {
|
|
6054
|
+
const n = toNumericAbs(a);
|
|
6055
|
+
const one = n.shape.k === "prim" && n.shape.type === "bigint" ? bigintLit(1n) : numLit(1);
|
|
6056
|
+
if (n.shape.k === "prim" && n.shape.type === "bigint" && !n.term) {
|
|
6057
|
+
return abs({ k: "prim", type: "bigint" }, void 0, void 0, confJoin(n.conf, "exact"));
|
|
6058
|
+
}
|
|
6059
|
+
return addNumeric(n, one);
|
|
6060
|
+
}
|
|
6061
|
+
function updateSubAbs(a) {
|
|
6062
|
+
const n = toNumericAbs(a);
|
|
6063
|
+
const one = n.shape.k === "prim" && n.shape.type === "bigint" ? bigintLit(1n) : numLit(1);
|
|
6064
|
+
if (n.shape.k === "prim" && n.shape.type === "bigint" && !n.term) {
|
|
6065
|
+
return abs({ k: "prim", type: "bigint" }, void 0, void 0, confJoin(n.conf, "exact"));
|
|
6066
|
+
}
|
|
6067
|
+
return subNumeric(n, one);
|
|
6068
|
+
}
|
|
6069
|
+
function addNumeric(a, b) {
|
|
6070
|
+
const va = litValue(a);
|
|
6071
|
+
const vb = litValue(b);
|
|
6072
|
+
if (typeof va === "bigint" && typeof vb === "bigint") return bigintLit(va + vb);
|
|
6073
|
+
if (typeof va === "number" && typeof vb === "number") return numLit(va + vb);
|
|
6074
|
+
const big = a.shape.k === "prim" && a.shape.type === "bigint" || typeof va === "bigint";
|
|
6075
|
+
return abs(
|
|
6076
|
+
{ k: "prim", type: big ? "bigint" : "number" },
|
|
6077
|
+
void 0,
|
|
6078
|
+
void 0,
|
|
6079
|
+
confJoin(confJoin(a.conf, b.conf), "path")
|
|
6080
|
+
);
|
|
6081
|
+
}
|
|
6082
|
+
function subNumeric(a, b) {
|
|
6083
|
+
const va = litValue(a);
|
|
6084
|
+
const vb = litValue(b);
|
|
6085
|
+
if (typeof va === "bigint" && typeof vb === "bigint") return bigintLit(va - vb);
|
|
6086
|
+
if (typeof va === "number" && typeof vb === "number") return numLit(va - vb);
|
|
6087
|
+
const big = a.shape.k === "prim" && a.shape.type === "bigint" || typeof va === "bigint";
|
|
6088
|
+
return abs(
|
|
6089
|
+
{ k: "prim", type: big ? "bigint" : "number" },
|
|
6090
|
+
void 0,
|
|
6091
|
+
void 0,
|
|
6092
|
+
confJoin(confJoin(a.conf, b.conf), "path")
|
|
6093
|
+
);
|
|
6094
|
+
}
|
|
5851
6095
|
function toNumberAbs(a) {
|
|
5852
6096
|
const v2 = litValue(a);
|
|
5853
|
-
if (typeof v2 === "bigint") {
|
|
5854
|
-
|
|
6097
|
+
if (typeof v2 === "bigint" || isBigPrim(a)) {
|
|
6098
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
5855
6099
|
}
|
|
5856
6100
|
if (coercibleNumberLit(v2)) {
|
|
5857
6101
|
return abs({ k: "prim", type: "number" }, lit(Number(v2)), pTrue, "exact");
|
|
@@ -6154,6 +6398,14 @@ function toStringArg(x) {
|
|
|
6154
6398
|
function isUndefinedArg(x) {
|
|
6155
6399
|
return x === void 0 || x.term?.op === "lit" && x.term.value === void 0;
|
|
6156
6400
|
}
|
|
6401
|
+
function toUint32Limit(v2) {
|
|
6402
|
+
if (typeof v2 === "bigint" || typeof v2 === "symbol") return void 0;
|
|
6403
|
+
const n = Number(v2);
|
|
6404
|
+
if (!Number.isFinite(n) || n === 0) return 0;
|
|
6405
|
+
const int = Math.trunc(n);
|
|
6406
|
+
const mod2 = int % 4294967296;
|
|
6407
|
+
return mod2 < 0 ? mod2 + 4294967296 : mod2;
|
|
6408
|
+
}
|
|
6157
6409
|
function callAbsMethod(recv, name, args) {
|
|
6158
6410
|
if (!isStrRecv(recv)) return void 0;
|
|
6159
6411
|
const a0 = args[0] ? litValue(args[0]) : void 0;
|
|
@@ -6226,7 +6478,9 @@ function callAbsMethod(recv, name, args) {
|
|
|
6226
6478
|
if (name === "slice") {
|
|
6227
6479
|
return strLit(lit3.slice(a0, a1));
|
|
6228
6480
|
}
|
|
6229
|
-
|
|
6481
|
+
const start = toIntegerOrInfinityLit(args[0]) ?? 0;
|
|
6482
|
+
const end = isUndefinedArg(args[1]) ? lit3.length : toIntegerOrInfinityLit(args[1]) ?? 0;
|
|
6483
|
+
return strLit(lit3.substring(start, end));
|
|
6230
6484
|
}
|
|
6231
6485
|
return strPrim("path");
|
|
6232
6486
|
case "charAt": {
|
|
@@ -6280,8 +6534,9 @@ function callAbsMethod(recv, name, args) {
|
|
|
6280
6534
|
if (isUndefinedArg(args[0])) {
|
|
6281
6535
|
const one = abs({ k: "tuple", elements: [strLit(lit3)] }, void 0, void 0, "exact");
|
|
6282
6536
|
if (lim === void 0) return one;
|
|
6283
|
-
const n =
|
|
6284
|
-
if (
|
|
6537
|
+
const n = toUint32Limit(lim);
|
|
6538
|
+
if (n === void 0) return strArr("path");
|
|
6539
|
+
if (n === 0) return abs({ k: "tuple", elements: [] }, void 0, void 0, "exact");
|
|
6285
6540
|
return one;
|
|
6286
6541
|
}
|
|
6287
6542
|
const sep = toStringArg(args[0]);
|
|
@@ -6479,7 +6734,12 @@ function mergeInstanceFields(instance, fields, className) {
|
|
|
6479
6734
|
const fieldObj = fields.shape.k === "brand" ? fields.shape.shape : fields;
|
|
6480
6735
|
if (fieldObj.shape.k === "obj") {
|
|
6481
6736
|
for (const [k, s] of Object.entries(fieldObj.shape.slots)) {
|
|
6482
|
-
slots
|
|
6737
|
+
Object.defineProperty(slots, k, {
|
|
6738
|
+
value: s,
|
|
6739
|
+
enumerable: true,
|
|
6740
|
+
writable: true,
|
|
6741
|
+
configurable: true
|
|
6742
|
+
});
|
|
6483
6743
|
}
|
|
6484
6744
|
}
|
|
6485
6745
|
return abs(
|
|
@@ -6674,15 +6934,23 @@ function classFromMethods(name, methods, superClass, superShape) {
|
|
|
6674
6934
|
const slots = {};
|
|
6675
6935
|
if (superShape?.shape.k === "obj") {
|
|
6676
6936
|
for (const [k, s] of Object.entries(superShape.shape.slots)) {
|
|
6677
|
-
slots
|
|
6937
|
+
Object.defineProperty(slots, k, {
|
|
6938
|
+
value: s,
|
|
6939
|
+
enumerable: true,
|
|
6940
|
+
writable: true,
|
|
6941
|
+
configurable: true
|
|
6942
|
+
});
|
|
6678
6943
|
}
|
|
6679
6944
|
}
|
|
6680
6945
|
for (const m of methods) {
|
|
6681
6946
|
methodMap.set(m.name, m);
|
|
6682
6947
|
if (m.kind !== "constructor") {
|
|
6683
|
-
slots
|
|
6684
|
-
value: abs({ k: "fn", params: m.params, name: m.name }, void 0, void 0, "exact")
|
|
6685
|
-
|
|
6948
|
+
Object.defineProperty(slots, m.name, {
|
|
6949
|
+
value: abs({ k: "fn", params: m.params, name: m.name }, void 0, void 0, "exact"),
|
|
6950
|
+
enumerable: true,
|
|
6951
|
+
writable: true,
|
|
6952
|
+
configurable: true
|
|
6953
|
+
});
|
|
6686
6954
|
}
|
|
6687
6955
|
}
|
|
6688
6956
|
return {
|
|
@@ -6717,21 +6985,21 @@ function leqAbs(src, tgt, opts = {}) {
|
|
|
6717
6985
|
function leqWithPred(src, tgt, phi2, env, depth) {
|
|
6718
6986
|
if (depth > 32) return fail("leq depth exceeded");
|
|
6719
6987
|
if (src.shape.k === "never") return ok();
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6988
|
+
const srcLitTerm = src.term?.op === "lit" ? src.term : void 0;
|
|
6989
|
+
const tgtLitTerm = tgt.term?.op === "lit" ? tgt.term : void 0;
|
|
6990
|
+
if (tgtLitTerm && srcLitTerm) {
|
|
6991
|
+
const sv = srcLitTerm.value;
|
|
6992
|
+
const tv = tgtLitTerm.value;
|
|
6993
|
+
const sameLit = sv === tv || typeof sv === "number" && typeof tv === "number" && Number.isNaN(sv) && Number.isNaN(tv);
|
|
6726
6994
|
if (sameLit) return ok();
|
|
6727
|
-
|
|
6728
|
-
return fail(`lit ${String(sv)} \u22AD lit ${String(tv)}`);
|
|
6729
|
-
}
|
|
6730
|
-
} else if (tv !== void 0 && sv === void 0) {
|
|
6731
|
-
if (tgt.shape.k === "prim") {
|
|
6732
|
-
return fail(`non-lit prim \u22AD lit ${String(tv)}`);
|
|
6733
|
-
}
|
|
6995
|
+
return fail(`lit ${String(sv)} \u22AD lit ${String(tv)}`);
|
|
6734
6996
|
}
|
|
6997
|
+
if (tgtLitTerm && !srcLitTerm) {
|
|
6998
|
+
if (src.shape.k === "any") return ok();
|
|
6999
|
+
return fail(`non-lit \u22AD lit ${String(tgtLitTerm.value)}`);
|
|
7000
|
+
}
|
|
7001
|
+
if (tgt.shape.k === "any" || tgt.shape.k === "unknown") return ok();
|
|
7002
|
+
if (src.shape.k === "any") return ok();
|
|
6735
7003
|
const shapeR = leqShape(src, tgt, phi2, env, depth);
|
|
6736
7004
|
if (!shapeR.ok) return shapeR;
|
|
6737
7005
|
return leqPred(src, tgt, phi2, depth);
|
|
@@ -6946,12 +7214,16 @@ function formatShape(a) {
|
|
|
6946
7214
|
case "any":
|
|
6947
7215
|
return "any";
|
|
6948
7216
|
case "unknown": {
|
|
6949
|
-
if (a.term?.op === "lit"
|
|
7217
|
+
if (a.term?.op === "lit") {
|
|
7218
|
+
if (a.term.value === void 0) return "undefined";
|
|
7219
|
+
if (a.term.value === null) return "null";
|
|
7220
|
+
}
|
|
6950
7221
|
return "unknown";
|
|
6951
7222
|
}
|
|
6952
7223
|
case "prim": {
|
|
6953
7224
|
const lv = litValue(a);
|
|
6954
7225
|
if (typeof lv === "number" && !Number.isFinite(lv)) return String(lv);
|
|
7226
|
+
if (typeof lv === "number" && Object.is(lv, -0)) return "-0";
|
|
6955
7227
|
if (typeof lv === "bigint") return `${String(lv)}n`;
|
|
6956
7228
|
if (lv !== void 0) return JSON.stringify(lv);
|
|
6957
7229
|
return s.type;
|
|
@@ -7309,7 +7581,12 @@ function litAbsFromJs(v2, depth = 0) {
|
|
|
7309
7581
|
if (proto === Object.prototype || proto === null) {
|
|
7310
7582
|
const slots = {};
|
|
7311
7583
|
for (const [k, val] of Object.entries(v2)) {
|
|
7312
|
-
slots
|
|
7584
|
+
Object.defineProperty(slots, k, {
|
|
7585
|
+
value: { value: litAbsFromJs(val, depth + 1) },
|
|
7586
|
+
enumerable: true,
|
|
7587
|
+
writable: true,
|
|
7588
|
+
configurable: true
|
|
7589
|
+
});
|
|
7313
7590
|
}
|
|
7314
7591
|
return objOf(slots);
|
|
7315
7592
|
}
|
|
@@ -7547,6 +7824,15 @@ function $pow(a, b) {
|
|
|
7547
7824
|
function $toNumber(a) {
|
|
7548
7825
|
return toNumberAbs(a);
|
|
7549
7826
|
}
|
|
7827
|
+
function $toNumeric(a) {
|
|
7828
|
+
return toNumericAbs(a);
|
|
7829
|
+
}
|
|
7830
|
+
function $updateAdd(a) {
|
|
7831
|
+
return updateAddAbs(a);
|
|
7832
|
+
}
|
|
7833
|
+
function $updateSub(a) {
|
|
7834
|
+
return updateSubAbs(a);
|
|
7835
|
+
}
|
|
7550
7836
|
function $neg(a) {
|
|
7551
7837
|
return negAbs(a);
|
|
7552
7838
|
}
|
|
@@ -8476,7 +8762,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
|
|
|
8476
8762
|
}
|
|
8477
8763
|
if (node.type === "UpdateExpression" && node.argument) {
|
|
8478
8764
|
const arg = node.argument;
|
|
8479
|
-
const fn = node.operator === "++" ? "$
|
|
8765
|
+
const fn = node.operator === "++" ? "$updateAdd" : "$updateSub";
|
|
8480
8766
|
if (arg.type === "MemberExpression") {
|
|
8481
8767
|
const path = memberPathOf(
|
|
8482
8768
|
arg,
|
|
@@ -8484,7 +8770,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
|
|
|
8484
8770
|
);
|
|
8485
8771
|
if (path) {
|
|
8486
8772
|
const readSrc = readPathSrc(path);
|
|
8487
|
-
lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${fn}(${readSrc}
|
|
8773
|
+
lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${fn}(${readSrc})`)};`);
|
|
8488
8774
|
}
|
|
8489
8775
|
}
|
|
8490
8776
|
}
|
|
@@ -9224,7 +9510,7 @@ ${pad}export default ${name};`;
|
|
|
9224
9510
|
const stepPart = (u) => {
|
|
9225
9511
|
const upd = u;
|
|
9226
9512
|
if (upd.type === "UpdateExpression" && upd.argument?.type === "Identifier" && upd.argument.name) {
|
|
9227
|
-
return `${upd.argument.name} = ${upd.operator === "++" ? "$
|
|
9513
|
+
return `${upd.argument.name} = ${upd.operator === "++" ? "$updateAdd" : "$updateSub"}(${upd.argument.name})`;
|
|
9228
9514
|
}
|
|
9229
9515
|
if (upd.type === "SequenceExpression") {
|
|
9230
9516
|
return (upd.expressions ?? []).map((e) => stepPart(e)).join(", ");
|
|
@@ -9943,6 +10229,128 @@ function transpileShortCircuitExpr(opts, parts) {
|
|
|
9943
10229
|
`})()`
|
|
9944
10230
|
].join("\n");
|
|
9945
10231
|
}
|
|
10232
|
+
function isChainLink(n) {
|
|
10233
|
+
return n.type === "MemberExpression" || n.type === "OptionalMemberExpression" || n.type === "CallExpression" || n.type === "OptionalCallExpression";
|
|
10234
|
+
}
|
|
10235
|
+
function linkIsOptional(n) {
|
|
10236
|
+
return n.optional === true;
|
|
10237
|
+
}
|
|
10238
|
+
function chainNeedsShortCircuit(n) {
|
|
10239
|
+
let cur = n;
|
|
10240
|
+
while (isChainLink(cur)) {
|
|
10241
|
+
if (linkIsOptional(cur)) return true;
|
|
10242
|
+
cur = cur.callee ?? cur.object;
|
|
10243
|
+
}
|
|
10244
|
+
return false;
|
|
10245
|
+
}
|
|
10246
|
+
function flattenChain(expr, opts) {
|
|
10247
|
+
const hops = [];
|
|
10248
|
+
let cur = expr;
|
|
10249
|
+
while (isChainLink(cur)) {
|
|
10250
|
+
const optional = linkIsOptional(cur);
|
|
10251
|
+
if (cur.type === "CallExpression" || cur.type === "OptionalCallExpression") {
|
|
10252
|
+
const args = (cur.arguments ?? []).map(
|
|
10253
|
+
(a) => a.type === "SpreadElement" ? "$unknown()" : transpileExpression(a, opts)
|
|
10254
|
+
).join(", ");
|
|
10255
|
+
const loc = cur.loc;
|
|
10256
|
+
const locArg = loc ? `, [${loc.start.line}, ${loc.start.column}]` : "";
|
|
10257
|
+
const callee = cur.callee;
|
|
10258
|
+
const calleeProp = callee?.property;
|
|
10259
|
+
const methodName = callee && (callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") ? !callee.computed && calleeProp?.type === "Identifier" ? calleeProp.name : callee.computed && calleeProp?.type === "StringLiteral" ? String(calleeProp.value) : void 0 : void 0;
|
|
10260
|
+
if (callee && methodName !== void 0) {
|
|
10261
|
+
const recvNode = callee.object;
|
|
10262
|
+
hops.unshift({
|
|
10263
|
+
kind: "invoke",
|
|
10264
|
+
method: JSON.stringify(methodName),
|
|
10265
|
+
argsSrc: `[${args}]`,
|
|
10266
|
+
locArg,
|
|
10267
|
+
recvOptional: linkIsOptional(callee),
|
|
10268
|
+
fnOptional: linkIsOptional(cur),
|
|
10269
|
+
recvName: recvNode?.type === "Identifier" && recvNode.name ? recvNode.name : void 0
|
|
10270
|
+
});
|
|
10271
|
+
cur = callee.object;
|
|
10272
|
+
continue;
|
|
10273
|
+
}
|
|
10274
|
+
hops.unshift({ kind: "call", argsSrc: `[${args}]`, optional: linkIsOptional(cur), locArg });
|
|
10275
|
+
cur = cur.callee ?? cur.object;
|
|
10276
|
+
continue;
|
|
10277
|
+
}
|
|
10278
|
+
const optionalM = optional;
|
|
10279
|
+
if (cur.computed) {
|
|
10280
|
+
const key = cur.property;
|
|
10281
|
+
if (key?.type === "StringLiteral") {
|
|
10282
|
+
hops.unshift({ kind: "get", key: JSON.stringify(key.value), optional: optionalM });
|
|
10283
|
+
} else if (key?.type === "NumericLiteral") {
|
|
10284
|
+
hops.unshift({ kind: "idx", keySrc: `$lit(${key.value})`, optional: optionalM });
|
|
10285
|
+
} else if (isExpression(cur.property)) {
|
|
10286
|
+
hops.unshift({
|
|
10287
|
+
kind: "idx",
|
|
10288
|
+
keySrc: transpileExpression(cur.property, opts),
|
|
10289
|
+
optional: optionalM
|
|
10290
|
+
});
|
|
10291
|
+
} else {
|
|
10292
|
+
return void 0;
|
|
10293
|
+
}
|
|
10294
|
+
cur = cur.object;
|
|
10295
|
+
continue;
|
|
10296
|
+
}
|
|
10297
|
+
const prop = cur.property;
|
|
10298
|
+
if (prop?.type !== "Identifier") return void 0;
|
|
10299
|
+
if (prop.name === "length") {
|
|
10300
|
+
hops.unshift({ kind: "len", optional: optionalM });
|
|
10301
|
+
} else {
|
|
10302
|
+
hops.unshift({ kind: "get", key: JSON.stringify(prop.name), optional: optionalM });
|
|
10303
|
+
}
|
|
10304
|
+
cur = cur.object;
|
|
10305
|
+
}
|
|
10306
|
+
if (cur.type === "Super") return void 0;
|
|
10307
|
+
const baseSrc = isExpression(cur) ? transpileExpression(cur, opts) : void 0;
|
|
10308
|
+
if (baseSrc === void 0) return void 0;
|
|
10309
|
+
return { baseSrc, hops };
|
|
10310
|
+
}
|
|
10311
|
+
function emitChainFrom(hops, i, valSrc) {
|
|
10312
|
+
if (i >= hops.length) return valSrc;
|
|
10313
|
+
const hop = hops[i];
|
|
10314
|
+
const rest = (recv) => emitChainFrom(hops, i + 1, recv);
|
|
10315
|
+
switch (hop.kind) {
|
|
10316
|
+
case "get":
|
|
10317
|
+
return hop.optional ? shortCircuitHop(valSrc, `$get($__oc, ${hop.key})`, hops, i) : rest(`$get(${valSrc}, ${hop.key})`);
|
|
10318
|
+
case "idx":
|
|
10319
|
+
return hop.optional ? shortCircuitHop(valSrc, `$idx($__oc, ${hop.keySrc})`, hops, i) : rest(`$idx(${valSrc}, ${hop.keySrc})`);
|
|
10320
|
+
case "len":
|
|
10321
|
+
return hop.optional ? shortCircuitHop(valSrc, `$len($__oc)`, hops, i) : rest(`$len(${valSrc})`);
|
|
10322
|
+
case "call":
|
|
10323
|
+
return hop.optional ? shortCircuitHop(valSrc, `$callNamed("call", $__oc, ${hop.argsSrc}${hop.locArg})`, hops, i) : rest(`$callNamed("call", ${valSrc}, ${hop.argsSrc}${hop.locArg})`);
|
|
10324
|
+
case "invoke": {
|
|
10325
|
+
const invokeOf = (recv, fnCheck) => {
|
|
10326
|
+
let call = `$invoke(${recv}, ${hop.method}, ${hop.argsSrc}${hop.locArg})`;
|
|
10327
|
+
const rawMethod = JSON.parse(hop.method);
|
|
10328
|
+
if (hop.recvName && REGEX_STATEFUL_NAMES.has(rawMethod)) {
|
|
10329
|
+
call = `(() => { const __v = ${call}; ${hop.recvName} = $reStateCall(${hop.recvName}, ${hop.method}, ${hop.argsSrc}); return __v; })()`;
|
|
10330
|
+
}
|
|
10331
|
+
if (!fnCheck) return call;
|
|
10332
|
+
return `(($__fn) => $fork($nullishTest($__fn), () => $lit(undefined), () => ${call}))($get(${recv}, ${hop.method}))`;
|
|
10333
|
+
};
|
|
10334
|
+
if (hop.recvOptional) {
|
|
10335
|
+
return shortCircuitHop(valSrc, invokeOf("$__oc", hop.fnOptional), hops, i);
|
|
10336
|
+
}
|
|
10337
|
+
return rest(invokeOf(valSrc, hop.fnOptional));
|
|
10338
|
+
}
|
|
10339
|
+
}
|
|
10340
|
+
}
|
|
10341
|
+
function shortCircuitHop(valSrc, appliedWithOc, hops, i) {
|
|
10342
|
+
return `(($__oc) => $fork($nullishTest($__oc), () => $lit(undefined), () => ${emitChainFrom(hops, i + 1, appliedWithOc)}))(${valSrc})`;
|
|
10343
|
+
}
|
|
10344
|
+
function tryTranspileOptionalChain(expr, opts) {
|
|
10345
|
+
const t = expr.type;
|
|
10346
|
+
if (t !== "MemberExpression" && t !== "OptionalMemberExpression" && t !== "CallExpression" && t !== "OptionalCallExpression") {
|
|
10347
|
+
return void 0;
|
|
10348
|
+
}
|
|
10349
|
+
if (!chainNeedsShortCircuit(expr)) return void 0;
|
|
10350
|
+
const flat = flattenChain(expr, opts);
|
|
10351
|
+
if (!flat) return void 0;
|
|
10352
|
+
return emitChainFrom(flat.hops, 0, flat.baseSrc);
|
|
10353
|
+
}
|
|
9946
10354
|
function transpileExpression(expr, opts = {}) {
|
|
9947
10355
|
const rep = matchReplacement(expr, opts);
|
|
9948
10356
|
if (rep) return rep;
|
|
@@ -9950,6 +10358,8 @@ function transpileExpression(expr, opts = {}) {
|
|
|
9950
10358
|
if (anyExpr.type === "ChainExpression" && anyExpr.expression) {
|
|
9951
10359
|
return transpileExpression(anyExpr.expression, opts);
|
|
9952
10360
|
}
|
|
10361
|
+
const chainSrc = tryTranspileOptionalChain(expr, opts);
|
|
10362
|
+
if (chainSrc !== void 0) return chainSrc;
|
|
9953
10363
|
if (anyExpr.type === "Super") {
|
|
9954
10364
|
return `/* super */`;
|
|
9955
10365
|
}
|
|
@@ -10070,19 +10480,18 @@ function transpileExpression(expr, opts = {}) {
|
|
|
10070
10480
|
}
|
|
10071
10481
|
case "UpdateExpression": {
|
|
10072
10482
|
const arg = expr.argument;
|
|
10073
|
-
const fn = expr.operator === "++" ? "$
|
|
10074
|
-
const undo = expr.operator === "++" ? "$sub" : "$add";
|
|
10483
|
+
const fn = expr.operator === "++" ? "$updateAdd" : "$updateSub";
|
|
10075
10484
|
if (arg.type === "Identifier") {
|
|
10076
|
-
if (expr.prefix) return `${arg.name} = ${fn}(${arg.name}
|
|
10077
|
-
return `(${arg.name} = ${fn}(
|
|
10485
|
+
if (expr.prefix) return `${arg.name} = ${fn}(${arg.name})`;
|
|
10486
|
+
return `((__old) => (${arg.name} = ${fn}(__old), __old))($toNumeric(${arg.name}))`;
|
|
10078
10487
|
}
|
|
10079
10488
|
if (arg.type === "MemberExpression") {
|
|
10080
10489
|
const m = arg;
|
|
10081
10490
|
const path = memberPathOf(m, opts);
|
|
10082
10491
|
if (path) {
|
|
10083
10492
|
const readSrc = readPathSrc(path);
|
|
10084
|
-
if (expr.prefix) return `${fn}(${readSrc}
|
|
10085
|
-
return readSrc
|
|
10493
|
+
if (expr.prefix) return `${fn}(${readSrc})`;
|
|
10494
|
+
return `$toNumeric(${readSrc})`;
|
|
10086
10495
|
}
|
|
10087
10496
|
}
|
|
10088
10497
|
return `/* update ${expr.operator} */ $lit(undefined)`;
|
|
@@ -10116,6 +10525,7 @@ function transpileExpression(expr, opts = {}) {
|
|
|
10116
10525
|
let acc = null;
|
|
10117
10526
|
const props = [];
|
|
10118
10527
|
const accRegs = [];
|
|
10528
|
+
let protoSet = null;
|
|
10119
10529
|
const flushProps = () => {
|
|
10120
10530
|
if (props.length === 0) return;
|
|
10121
10531
|
const obj2 = `$obj({ ${props.join(", ")} })`;
|
|
@@ -10137,6 +10547,7 @@ function transpileExpression(expr, opts = {}) {
|
|
|
10137
10547
|
return symbolKeyOf(prop.key);
|
|
10138
10548
|
})();
|
|
10139
10549
|
if (mkey === null) continue;
|
|
10550
|
+
const isProtoKey = mkey === '"__proto__"';
|
|
10140
10551
|
const displayNames = paramDisplayNames(prop.params);
|
|
10141
10552
|
const bindNames = methodBindNames(prop.params);
|
|
10142
10553
|
const mHasArgs = fnBodyHasOwnArguments({ body: prop.body });
|
|
@@ -10148,7 +10559,12 @@ function transpileExpression(expr, opts = {}) {
|
|
|
10148
10559
|
argsBinding: mHasArgs ? "__nudoArgs" : void 0
|
|
10149
10560
|
};
|
|
10150
10561
|
if (prop.kind === "get" || prop.kind === "set") {
|
|
10151
|
-
|
|
10562
|
+
const slotSrc = `${mkey}: $lit(undefined)`;
|
|
10563
|
+
if (isProtoKey) {
|
|
10564
|
+
acc = `$setKey(${acc ?? "$obj({})"}, $lit("__proto__"), $lit(undefined))`;
|
|
10565
|
+
} else {
|
|
10566
|
+
props.push(slotSrc);
|
|
10567
|
+
}
|
|
10152
10568
|
if (prop.kind === "get") {
|
|
10153
10569
|
const bodySrc2 = `{
|
|
10154
10570
|
${emitFnBlockBody(prop.body, 1, methodOpts)}
|
|
@@ -10181,7 +10597,11 @@ return __this;
|
|
|
10181
10597
|
${mBodyInner}
|
|
10182
10598
|
}`;
|
|
10183
10599
|
const fnValSrc = `$fnVal([${displayNames.map((p) => JSON.stringify(p)).join(", ")}], (${mParams.join(", ")}) => ${bodySrc}, { bindThis: true })`;
|
|
10184
|
-
|
|
10600
|
+
if (isProtoKey) {
|
|
10601
|
+
acc = `$setKey(${acc ?? "$obj({})"}, $lit("__proto__"), ${fnValSrc})`;
|
|
10602
|
+
} else {
|
|
10603
|
+
props.push(`${mkey}: ${fnValSrc}`);
|
|
10604
|
+
}
|
|
10185
10605
|
continue;
|
|
10186
10606
|
}
|
|
10187
10607
|
if (prop.type !== "ObjectProperty") continue;
|
|
@@ -10203,6 +10623,10 @@ ${mBodyInner}
|
|
|
10203
10623
|
return k === null ? null : JSON.stringify(k);
|
|
10204
10624
|
})();
|
|
10205
10625
|
if (key === null) continue;
|
|
10626
|
+
if (!prop.computed && key === '"__proto__"') {
|
|
10627
|
+
protoSet = transpileExpression(prop.value, opts);
|
|
10628
|
+
continue;
|
|
10629
|
+
}
|
|
10206
10630
|
if (prop.value.type === "FunctionExpression" && !prop.value.async) {
|
|
10207
10631
|
const fn = prop.value;
|
|
10208
10632
|
if (!fn.generator) {
|
|
@@ -10243,6 +10667,7 @@ ${mBodyInner}
|
|
|
10243
10667
|
for (const r of accRegs) {
|
|
10244
10668
|
result = `$objAccessor(${result}, ${r.key}, ${r.get ?? "null"}, ${r.set ?? "null"})`;
|
|
10245
10669
|
}
|
|
10670
|
+
if (protoSet !== null) result = `$setProto(${result}, ${protoSet})`;
|
|
10246
10671
|
return result;
|
|
10247
10672
|
}
|
|
10248
10673
|
case "MemberExpression":
|
|
@@ -10581,13 +11006,13 @@ function transpileSource(source, opts = {}) {
|
|
|
10581
11006
|
return transpileFile(file, { ...opts, source: opts.source ?? source });
|
|
10582
11007
|
}
|
|
10583
11008
|
function runtimeImportOf(runtime) {
|
|
10584
|
-
return `import { $add, $sub, $mul, $div, $mod, $bitand, $bitor, $bitxor, $bitnot, $shl, $shr, $ushr, $pow, $toNumber, $in, $instanceof, $instanceofNonIdent, $classExpr, $del, $delRes, $objAccessor, $neg, $typeof, $not, $eq, $ne, $eqLoose, $neLoose, $lt, $le, $gt, $ge, $join, $lit, $fork, $for, $forIter, $obj, $get, $set, $while, $whileSeq, $arr, $arrWithHoles, $arrMutContainer, $idx, $idxSet, $len, $call, $throw, $loopReturn, $loopBreak, $loopContinue, $class, $new, $invoke, $invokeSuper, $super, $async, $copy, $await, $asyncReturn, $orDefault, $callNamed, $optionalGet, $optionalInvoke, $spread, $concat, $forOf, $forInKeys, $catchVal, $switch, $staticInvoke, $setKey, $gen, $yield, $fnVal, $regex, $reStateCall, $rethrowIfNudoReturn, $nullishTest, $tryMark, $assignRecord, $recordBinding, $unknown, $importMeta, $dynamicImport, $tryTakeSince, $tryCurrentMark, $tryPopMark, $tryDigestSoftCatch, $tryReleaseSoftOut, $tryDetachSoftCatch, $tryDiscardSoft, $tryOrphanSoft, $pushLoopExit, $objRest, $arrRest, $arguments, $isForkExit, $rawThis, $isBreakTo } from ${JSON.stringify(runtime)};`;
|
|
11009
|
+
return `import { $add, $sub, $mul, $div, $mod, $bitand, $bitor, $bitxor, $bitnot, $shl, $shr, $ushr, $pow, $toNumber, $toNumeric, $updateAdd, $updateSub, $in, $instanceof, $instanceofNonIdent, $classExpr, $del, $delRes, $objAccessor, $neg, $typeof, $not, $eq, $ne, $eqLoose, $neLoose, $lt, $le, $gt, $ge, $join, $lit, $fork, $for, $forIter, $obj, $get, $set, $setProto, $while, $whileSeq, $arr, $arrWithHoles, $arrMutContainer, $idx, $idxSet, $len, $call, $throw, $loopReturn, $loopBreak, $loopContinue, $class, $new, $invoke, $invokeSuper, $super, $async, $copy, $await, $asyncReturn, $orDefault, $callNamed, $optionalGet, $optionalInvoke, $spread, $concat, $forOf, $forInKeys, $catchVal, $switch, $staticInvoke, $setKey, $gen, $yield, $fnVal, $regex, $reStateCall, $rethrowIfNudoReturn, $nullishTest, $tryMark, $assignRecord, $recordBinding, $unknown, $importMeta, $dynamicImport, $tryTakeSince, $tryCurrentMark, $tryPopMark, $tryDigestSoftCatch, $tryReleaseSoftOut, $tryDetachSoftCatch, $tryDiscardSoft, $tryOrphanSoft, $pushLoopExit, $objRest, $arrRest, $arguments, $isForkExit, $rawThis, $isBreakTo } from ${JSON.stringify(runtime)};`;
|
|
10585
11010
|
}
|
|
10586
11011
|
function transpileFile(file, opts = {}) {
|
|
10587
11012
|
const runtime = opts.runtimeImport ?? "@nudojs/core/exec";
|
|
10588
11013
|
const lines = [
|
|
10589
11014
|
`// nudo evaluator transpile \u2014 values are Abs; operators are overloaded calls`,
|
|
10590
|
-
`import { $add, $sub, $mul, $div, $mod, $bitand, $bitor, $bitxor, $bitnot, $shl, $shr, $ushr, $pow, $toNumber, $in, $instanceof, $instanceofNonIdent, $classExpr, $del, $delRes, $objAccessor, $neg, $typeof, $not, $eq, $ne, $eqLoose, $neLoose, $lt, $le, $gt, $ge, $join, $lit, $fork, $for, $forIter, $obj, $get, $set, $while, $whileSeq, $arr, $arrWithHoles, $arrMutContainer, $idx, $idxSet, $len, $call, $throw, $loopReturn, $loopBreak, $loopContinue, $class, $new, $invoke, $invokeSuper, $super, $async, $copy, $await, $asyncReturn, $orDefault, $callNamed, $optionalGet, $optionalInvoke, $spread, $concat, $forOf, $forInKeys, $catchVal, $switch, $staticInvoke, $setKey, $gen, $yield, $fnVal, $regex, $reStateCall, $rethrowIfNudoReturn, $nullishTest, $tryMark, $assignRecord, $recordBinding, $unknown, $importMeta, $dynamicImport, $tryTakeSince, $tryCurrentMark, $tryPopMark, $tryDigestSoftCatch, $tryReleaseSoftOut, $tryDetachSoftCatch, $tryDiscardSoft, $tryOrphanSoft, $pushLoopExit, $objRest, $arrRest, $arguments, $isForkExit, $rawThis, $isBreakTo } from ${JSON.stringify(runtime)};`,
|
|
11015
|
+
`import { $add, $sub, $mul, $div, $mod, $bitand, $bitor, $bitxor, $bitnot, $shl, $shr, $ushr, $pow, $toNumber, $toNumeric, $updateAdd, $updateSub, $in, $instanceof, $instanceofNonIdent, $classExpr, $del, $delRes, $objAccessor, $neg, $typeof, $not, $eq, $ne, $eqLoose, $neLoose, $lt, $le, $gt, $ge, $join, $lit, $fork, $for, $forIter, $obj, $get, $set, $setProto, $while, $whileSeq, $arr, $arrWithHoles, $arrMutContainer, $idx, $idxSet, $len, $call, $throw, $loopReturn, $loopBreak, $loopContinue, $class, $new, $invoke, $invokeSuper, $super, $async, $copy, $await, $asyncReturn, $orDefault, $callNamed, $optionalGet, $optionalInvoke, $spread, $concat, $forOf, $forInKeys, $catchVal, $switch, $staticInvoke, $setKey, $gen, $yield, $fnVal, $regex, $reStateCall, $rethrowIfNudoReturn, $nullishTest, $tryMark, $assignRecord, $recordBinding, $unknown, $importMeta, $dynamicImport, $tryTakeSince, $tryCurrentMark, $tryPopMark, $tryDigestSoftCatch, $tryReleaseSoftOut, $tryDetachSoftCatch, $tryDiscardSoft, $tryOrphanSoft, $pushLoopExit, $objRest, $arrRest, $arguments, $isForkExit, $rawThis, $isBreakTo } from ${JSON.stringify(runtime)};`,
|
|
10591
11016
|
``
|
|
10592
11017
|
];
|
|
10593
11018
|
for (const stmt of file.program.body) {
|
|
@@ -10783,6 +11208,7 @@ __export(runtime_exports, {
|
|
|
10783
11208
|
$regex: () => $regex,
|
|
10784
11209
|
$rethrowIfNudoReturn: () => $rethrowIfNudoReturn,
|
|
10785
11210
|
$set: () => $set,
|
|
11211
|
+
$setProto: () => $setProto,
|
|
10786
11212
|
$shl: () => $shl,
|
|
10787
11213
|
$shr: () => $shr,
|
|
10788
11214
|
$spread: () => $spread,
|
|
@@ -10790,6 +11216,7 @@ __export(runtime_exports, {
|
|
|
10790
11216
|
$switch: () => $switch,
|
|
10791
11217
|
$throw: () => $throw,
|
|
10792
11218
|
$toNumber: () => $toNumber,
|
|
11219
|
+
$toNumeric: () => $toNumeric,
|
|
10793
11220
|
$tryCurrentMark: () => $tryCurrentMark,
|
|
10794
11221
|
$tryDetachSoftCatch: () => $tryDetachSoftCatch,
|
|
10795
11222
|
$tryDigestSoftCatch: () => $tryDigestSoftCatch,
|
|
@@ -10802,6 +11229,8 @@ __export(runtime_exports, {
|
|
|
10802
11229
|
$tryTakeSince: () => $tryTakeSince,
|
|
10803
11230
|
$typeof: () => $typeof,
|
|
10804
11231
|
$unknown: () => $unknown,
|
|
11232
|
+
$updateAdd: () => $updateAdd,
|
|
11233
|
+
$updateSub: () => $updateSub,
|
|
10805
11234
|
$ushr: () => $ushr,
|
|
10806
11235
|
$while: () => $while,
|
|
10807
11236
|
$whileSeq: () => $whileSeq,
|
|
@@ -10905,10 +11334,11 @@ function $in(key, o) {
|
|
|
10905
11334
|
if (o.shape.k === "prim" || o.shape.k === "never" || isNullishLitAbs(o)) {
|
|
10906
11335
|
return unknown;
|
|
10907
11336
|
}
|
|
10908
|
-
const
|
|
10909
|
-
if (
|
|
10910
|
-
return
|
|
11337
|
+
const keyStr = propertyKeyOf(key);
|
|
11338
|
+
if (keyStr === void 0) {
|
|
11339
|
+
return bool();
|
|
10911
11340
|
}
|
|
11341
|
+
const kv = keyStr;
|
|
10912
11342
|
if (o.shape.k === "tuple") {
|
|
10913
11343
|
if (kv === "length") return boolLit(true);
|
|
10914
11344
|
const idx = canonicalArrayIndex(kv);
|
|
@@ -10919,8 +11349,6 @@ function $in(key, o) {
|
|
|
10919
11349
|
return boolLit(false);
|
|
10920
11350
|
}
|
|
10921
11351
|
if (o.shape.k === "arr") return bool();
|
|
10922
|
-
const keyStr = typeof kv === "number" ? String(kv) : typeof kv === "string" ? kv : void 0;
|
|
10923
|
-
if (keyStr === void 0) return bool();
|
|
10924
11352
|
if (o.shape.k === "obj" || o.shape.k === "brand") {
|
|
10925
11353
|
const objShape = o.shape.k === "brand" ? o.shape.shape.shape.k === "obj" ? o.shape.shape.shape : void 0 : o.shape;
|
|
10926
11354
|
if (!objShape) return bool();
|
|
@@ -10937,6 +11365,9 @@ function $in(key, o) {
|
|
|
10937
11365
|
return boolLit(OBJECT_PROTO_NAMES.has(keyStr));
|
|
10938
11366
|
}
|
|
10939
11367
|
if (o.shape.k === "fn") {
|
|
11368
|
+
if (o.shape.slots && getSlot(o.shape.slots, keyStr) && !o.shape.slots[keyStr].optional) {
|
|
11369
|
+
return boolLit(true);
|
|
11370
|
+
}
|
|
10940
11371
|
return boolLit(OBJECT_PROTO_NAMES.has(keyStr) || FUNCTION_PROTO_NAMES.has(keyStr));
|
|
10941
11372
|
}
|
|
10942
11373
|
if (o.shape.k === "eff") {
|
|
@@ -11124,7 +11555,7 @@ function $delRes(o, _key) {
|
|
|
11124
11555
|
return bool();
|
|
11125
11556
|
}
|
|
11126
11557
|
function $del(o, key) {
|
|
11127
|
-
const
|
|
11558
|
+
const keyStr = propertyKeyOf(key);
|
|
11128
11559
|
if (o.shape.k === "sum") {
|
|
11129
11560
|
return abs(
|
|
11130
11561
|
{ k: "sum", members: o.shape.members.map((m) => $del(m, key)) },
|
|
@@ -11143,7 +11574,6 @@ function $del(o, key) {
|
|
|
11143
11574
|
if (clsName) markClassValue(next, clsName);
|
|
11144
11575
|
return next;
|
|
11145
11576
|
}
|
|
11146
|
-
const keyStr = typeof kv === "number" ? String(kv) : typeof kv === "string" ? kv : void 0;
|
|
11147
11577
|
if (o.shape.k === "obj" && keyStr !== void 0) {
|
|
11148
11578
|
if (getPropFlags(o)?.get(keyStr)?.configurable === false) throwStrictWrite();
|
|
11149
11579
|
if (o.shape.open) return o;
|
|
@@ -11158,7 +11588,7 @@ function $del(o, key) {
|
|
|
11158
11588
|
return o;
|
|
11159
11589
|
}
|
|
11160
11590
|
if (o.shape.k === "tuple") {
|
|
11161
|
-
const idx = canonicalArrayIndex(
|
|
11591
|
+
const idx = canonicalArrayIndex(keyStr);
|
|
11162
11592
|
if (idx === void 0 || idx >= o.shape.elements.length) return o;
|
|
11163
11593
|
o.shape.elements[idx] = $lit(void 0);
|
|
11164
11594
|
if (!o.shape.holes) o.shape.holes = [];
|
|
@@ -11233,7 +11663,9 @@ function toIOI(v2) {
|
|
|
11233
11663
|
return Math.trunc(lv);
|
|
11234
11664
|
}
|
|
11235
11665
|
if (typeof lv === "string" || typeof lv === "boolean") {
|
|
11236
|
-
|
|
11666
|
+
const n = Number(lv);
|
|
11667
|
+
if (Number.isNaN(n)) return 0;
|
|
11668
|
+
return Math.trunc(n);
|
|
11237
11669
|
}
|
|
11238
11670
|
return null;
|
|
11239
11671
|
}
|
|
@@ -11261,7 +11693,7 @@ function copyWithinTuple(shape, vals) {
|
|
|
11261
11693
|
if (win) {
|
|
11262
11694
|
const els = [...shape.elements];
|
|
11263
11695
|
const holesSet = new Set(origHoles);
|
|
11264
|
-
const backwards =
|
|
11696
|
+
const backwards = win.s < win.t && win.s + (win.e - win.s) > win.t;
|
|
11265
11697
|
const count = win.e - win.s;
|
|
11266
11698
|
for (let kk = 0; kk < count; kk++) {
|
|
11267
11699
|
const k = backwards ? count - 1 - kk : kk;
|
|
@@ -11361,7 +11793,7 @@ function $copy(a) {
|
|
|
11361
11793
|
if (s.k === "obj") {
|
|
11362
11794
|
const slots = {};
|
|
11363
11795
|
for (const [k, v2] of Object.entries(s.slots)) {
|
|
11364
|
-
slots
|
|
11796
|
+
setSlot(slots, k, { ...v2, value: $copy(v2.value) });
|
|
11365
11797
|
}
|
|
11366
11798
|
const next = objOf(slots, {
|
|
11367
11799
|
index: s.index ? { key: $copy(s.index.key), value: $copy(s.index.value) } : void 0,
|
|
@@ -11501,7 +11933,8 @@ function $arrMutContainer(arr, method, args) {
|
|
|
11501
11933
|
}
|
|
11502
11934
|
function $idx(a, i) {
|
|
11503
11935
|
if (a?.shape?.k === "any") return anyMemberResult();
|
|
11504
|
-
const
|
|
11936
|
+
const keyStr = propertyKeyOf(i);
|
|
11937
|
+
const iv = keyStr !== void 0 ? keyStr : litValue(i);
|
|
11505
11938
|
const idx = iv !== void 0 ? canonicalArrayIndex(iv) : void 0;
|
|
11506
11939
|
if (a.shape.k === "tuple") {
|
|
11507
11940
|
const els = a.shape.elements;
|
|
@@ -11538,18 +11971,11 @@ function $idx(a, i) {
|
|
|
11538
11971
|
}
|
|
11539
11972
|
const sv = litValue(a);
|
|
11540
11973
|
if (typeof sv === "string") {
|
|
11541
|
-
if (
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
pTrue,
|
|
11547
|
-
"exact"
|
|
11548
|
-
);
|
|
11549
|
-
}
|
|
11550
|
-
return undef();
|
|
11551
|
-
}
|
|
11552
|
-
return unknown;
|
|
11974
|
+
if (i.term?.op !== "lit") return unknown;
|
|
11975
|
+
const idx2 = canonicalArrayIndex(i.term.value);
|
|
11976
|
+
if (idx2 === void 0) return undef();
|
|
11977
|
+
if (idx2 < sv.length) return $lit(sv[idx2]);
|
|
11978
|
+
return undef();
|
|
11553
11979
|
}
|
|
11554
11980
|
return unknown;
|
|
11555
11981
|
}
|
|
@@ -11560,20 +11986,26 @@ function widenTupleToArr(els, holes, value) {
|
|
|
11560
11986
|
return { k: "arr", element: joined };
|
|
11561
11987
|
}
|
|
11562
11988
|
function $idxSet(a, i, value) {
|
|
11563
|
-
const
|
|
11564
|
-
|
|
11989
|
+
const pk = propertyKeyOf(i);
|
|
11990
|
+
const raw = i.term?.op === "lit" ? i.term.value : litValue(i);
|
|
11991
|
+
let numIdx;
|
|
11992
|
+
if (typeof raw === "number") numIdx = raw;
|
|
11993
|
+
else if (typeof raw === "bigint") numIdx = Number(raw);
|
|
11994
|
+
else if (pk !== void 0) numIdx = canonicalArrayIndex(pk);
|
|
11995
|
+
const iv = pk !== void 0 ? pk : litValue(i);
|
|
11996
|
+
if (a.shape.k === "tuple" && numIdx !== void 0 && Number.isInteger(numIdx) && numIdx >= 0) {
|
|
11565
11997
|
const st = extStateOf(a);
|
|
11566
11998
|
if (st === "frozen") throwStrictWrite();
|
|
11567
|
-
if ((st === "sealed" || st === "nonext") &&
|
|
11999
|
+
if ((st === "sealed" || st === "nonext") && numIdx >= a.shape.elements.length) {
|
|
11568
12000
|
throwStrictWrite();
|
|
11569
12001
|
}
|
|
11570
|
-
if (
|
|
12002
|
+
if (numIdx >= 4294967295) {
|
|
11571
12003
|
a.shape = widenTupleToArr(a.shape.elements, a.shape.holes, value);
|
|
11572
12004
|
a.conf = confJoin(a.conf, "path");
|
|
11573
12005
|
clearStaleTermPred(a);
|
|
11574
12006
|
return a;
|
|
11575
12007
|
}
|
|
11576
|
-
if (
|
|
12008
|
+
if (numIdx + 1 > TUPLE_MATERIALIZE_CAP) {
|
|
11577
12009
|
a.shape = widenTupleToArr(a.shape.elements, a.shape.holes, value);
|
|
11578
12010
|
a.conf = confJoin(a.conf, "path");
|
|
11579
12011
|
clearStaleTermPred(a);
|
|
@@ -11581,12 +12013,12 @@ function $idxSet(a, i, value) {
|
|
|
11581
12013
|
}
|
|
11582
12014
|
const els = [...a.shape.elements];
|
|
11583
12015
|
const holes = [...a.shape.holes ?? []];
|
|
11584
|
-
while (els.length <
|
|
12016
|
+
while (els.length < numIdx) {
|
|
11585
12017
|
holes.push(els.length);
|
|
11586
12018
|
els.push(undef());
|
|
11587
12019
|
}
|
|
11588
|
-
els[
|
|
11589
|
-
const hi = holes.indexOf(
|
|
12020
|
+
els[numIdx] = asAbsVal(value);
|
|
12021
|
+
const hi = holes.indexOf(numIdx);
|
|
11590
12022
|
if (hi >= 0) holes.splice(hi, 1);
|
|
11591
12023
|
a.shape = { k: "tuple", elements: els, holes: holes.length > 0 ? holes : void 0 };
|
|
11592
12024
|
clearStaleTermPred(a);
|
|
@@ -11650,6 +12082,9 @@ function $len(a) {
|
|
|
11650
12082
|
"exact"
|
|
11651
12083
|
);
|
|
11652
12084
|
}
|
|
12085
|
+
if (a.shape.k === "prim" && a.shape.type === "string") {
|
|
12086
|
+
return abs({ k: "prim", type: "number" }, void 0, void 0, "path");
|
|
12087
|
+
}
|
|
11653
12088
|
if (a.shape.k === "brand" && a.shape.name === "String") {
|
|
11654
12089
|
const inner = a.shape.shape;
|
|
11655
12090
|
if (inner.shape.k === "obj") {
|
|
@@ -11663,10 +12098,17 @@ function $len(a) {
|
|
|
11663
12098
|
return unknown;
|
|
11664
12099
|
}
|
|
11665
12100
|
function $obj(slots) {
|
|
11666
|
-
const s =
|
|
11667
|
-
for (const
|
|
12101
|
+
const s = /* @__PURE__ */ Object.create(null);
|
|
12102
|
+
for (const k of Object.keys(slots)) {
|
|
12103
|
+
setSlot(s, k, { value: asAbsVal(slots[k]) });
|
|
12104
|
+
}
|
|
11668
12105
|
return objOf(s);
|
|
11669
12106
|
}
|
|
12107
|
+
function $setProto(o, proto) {
|
|
12108
|
+
const next = setProtoAbs(o, proto);
|
|
12109
|
+
if (next !== o) clearStaleTermPred(o);
|
|
12110
|
+
return next;
|
|
12111
|
+
}
|
|
11670
12112
|
function $spread(a, b) {
|
|
11671
12113
|
let bb = asAbsVal(b);
|
|
11672
12114
|
const acc = bb && typeof bb === "object" ? accessorTable.get(bb) : void 0;
|
|
@@ -11675,7 +12117,7 @@ function $spread(a, b) {
|
|
|
11675
12117
|
const slots = { ...bb.shape.slots };
|
|
11676
12118
|
for (const [k, fn] of acc) {
|
|
11677
12119
|
if (fn.get) {
|
|
11678
|
-
slots
|
|
12120
|
+
setSlot(slots, k, { value: fn.get(bb) });
|
|
11679
12121
|
changed = true;
|
|
11680
12122
|
}
|
|
11681
12123
|
}
|
|
@@ -11711,7 +12153,7 @@ function $objRest(o, keys) {
|
|
|
11711
12153
|
let openRest = o.shape.open === true;
|
|
11712
12154
|
for (const [k, s] of Object.entries(o.shape.slots)) {
|
|
11713
12155
|
if (drop.has(k)) continue;
|
|
11714
|
-
slots
|
|
12156
|
+
setSlot(slots, k, s);
|
|
11715
12157
|
}
|
|
11716
12158
|
if (o.shape.open) openRest = true;
|
|
11717
12159
|
const shape = { k: "obj", slots };
|
|
@@ -11822,7 +12264,7 @@ function $forInKeys(o) {
|
|
|
11822
12264
|
return k !== "" && String(n) === k && Number.isInteger(n) && n >= 0 && n < 4294967295;
|
|
11823
12265
|
};
|
|
11824
12266
|
if (shape.k === "obj") {
|
|
11825
|
-
const keys =
|
|
12267
|
+
const keys = enumOwnKeys(o, shape.slots);
|
|
11826
12268
|
const intKeys = keys.filter(isArrayIndexKey).sort((a, b) => Number(a) - Number(b));
|
|
11827
12269
|
const strKeys = keys.filter((k) => !isArrayIndexKey(k));
|
|
11828
12270
|
return $arr([...intKeys, ...strKeys].map((k) => $lit(k)));
|
|
@@ -12033,6 +12475,13 @@ function $get(o, key, opts) {
|
|
|
12033
12475
|
}
|
|
12034
12476
|
return $get(inner, key, opts);
|
|
12035
12477
|
}
|
|
12478
|
+
if (o.shape.k === "fn" && o.shape.slots) {
|
|
12479
|
+
const slot = getSlot(o.shape.slots, key);
|
|
12480
|
+
if (slot) {
|
|
12481
|
+
if (slot.optional) return joinAbs(slot.value, undef());
|
|
12482
|
+
return slot.value;
|
|
12483
|
+
}
|
|
12484
|
+
}
|
|
12036
12485
|
if ((o.shape.k === "tuple" || o.shape.k === "arr") && key === "length") {
|
|
12037
12486
|
return $len(o);
|
|
12038
12487
|
}
|
|
@@ -12042,6 +12491,16 @@ function $get(o, key, opts) {
|
|
|
12042
12491
|
if (idx !== void 0) return idx < els.length ? els[idx] : undef();
|
|
12043
12492
|
if (!isPossiblyProtoMemberKey(key)) return undef();
|
|
12044
12493
|
}
|
|
12494
|
+
if (o.shape.k === "prim" && o.shape.type === "string") {
|
|
12495
|
+
const idx = canonicalArrayIndex(key);
|
|
12496
|
+
const sv = litValue(o);
|
|
12497
|
+
if (idx !== void 0) {
|
|
12498
|
+
if (typeof sv === "string") return idx < sv.length ? $lit(sv[idx]) : undef();
|
|
12499
|
+
return abs({ k: "prim", type: "string" }, void 0, void 0, "path");
|
|
12500
|
+
}
|
|
12501
|
+
if (key === "length" && typeof sv === "string") return numLit(sv.length);
|
|
12502
|
+
if (!isPossiblyProtoMemberKey(key) && key !== "length") return undef();
|
|
12503
|
+
}
|
|
12045
12504
|
if ((o.shape.k === "tuple" || o.shape.k === "arr" || o.shape.k === "prim") && (OBJECT_PROTO_METHOD_NAMES.has(key) || o.shape.k !== "prim" && ARRAY_PROTO_METHOD_NAMES.has(key)) && !(o.shape.k === "prim" && o.shape.type === "string" && key === "toString")) {
|
|
12046
12505
|
if ((o.shape.k === "tuple" || o.shape.k === "arr") && (key === "toString" || key === "toLocaleString" || key === "join")) {
|
|
12047
12506
|
return arrayMethodAbs(key === "join" ? "join" : key);
|
|
@@ -12147,7 +12606,7 @@ function $set(o, key, value) {
|
|
|
12147
12606
|
throwStrictWrite();
|
|
12148
12607
|
}
|
|
12149
12608
|
if (getPropFlags(o)?.get(key)?.writable === false) throwStrictWrite();
|
|
12150
|
-
inner2.shape.slots
|
|
12609
|
+
setSlot(inner2.shape.slots, key, { value: asAbsVal(value) });
|
|
12151
12610
|
clearStaleTermPred(o);
|
|
12152
12611
|
return o;
|
|
12153
12612
|
}
|
|
@@ -12242,7 +12701,10 @@ function $set(o, key, value) {
|
|
|
12242
12701
|
if (!acc.set) throwStrictWrite();
|
|
12243
12702
|
return acc.set(o, value);
|
|
12244
12703
|
}
|
|
12245
|
-
|
|
12704
|
+
if (key === "__proto__" && !isNullProtoObj(o)) {
|
|
12705
|
+
return $setProto(o, value);
|
|
12706
|
+
}
|
|
12707
|
+
setSlot(shape.slots, key, { value: asAbsVal(value) });
|
|
12246
12708
|
o.conf = confJoin(o.conf, value.conf);
|
|
12247
12709
|
clearStaleTermPred(o);
|
|
12248
12710
|
return o;
|
|
@@ -13143,9 +13605,9 @@ function $class(name, spec) {
|
|
|
13143
13605
|
registerEvalClass(full);
|
|
13144
13606
|
const slots = {};
|
|
13145
13607
|
if (spec.statics) {
|
|
13146
|
-
for (const [k, v2] of Object.entries(spec.statics)) slots
|
|
13608
|
+
for (const [k, v2] of Object.entries(spec.statics)) setSlot(slots, k, { value: asAbsVal(v2) });
|
|
13147
13609
|
}
|
|
13148
|
-
slots
|
|
13610
|
+
setSlot(slots, "name", { value: strLit(name) });
|
|
13149
13611
|
const val = abs(
|
|
13150
13612
|
{ k: "brand", name, shape: objOf(slots) },
|
|
13151
13613
|
void 0,
|
|
@@ -13187,11 +13649,9 @@ function $new(cls, args) {
|
|
|
13187
13649
|
if (cls && typeof cls === "object" && "shape" in cls) {
|
|
13188
13650
|
const cs = cls.shape;
|
|
13189
13651
|
const ctorName = cs.k === "brand" ? cs.name : builtinCtorNameOf(cls) ?? (cs.k === "fn" ? cs.name ?? void 0 : void 0);
|
|
13190
|
-
if (ctorName
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
if (ctorName === "Promise") {
|
|
13194
|
-
return evalPromiseCtor(args);
|
|
13652
|
+
if (ctorName) {
|
|
13653
|
+
const built = evalBuiltinNew(ctorName, args);
|
|
13654
|
+
if (built !== void 0) return built;
|
|
13195
13655
|
}
|
|
13196
13656
|
}
|
|
13197
13657
|
if (typeof cls === "function") {
|
|
@@ -13304,6 +13764,7 @@ function runtimeAssignObject(args) {
|
|
|
13304
13764
|
const base = accObj.shape.slots;
|
|
13305
13765
|
const flags = getPropFlags(accObj);
|
|
13306
13766
|
for (const [k, s] of Object.entries(srcAbs.shape.slots)) {
|
|
13767
|
+
if (!isEnumerableView(srcAbs, k)) continue;
|
|
13307
13768
|
if ((st === "sealed" || st === "nonext") && !Object.prototype.hasOwnProperty.call(base, k)) {
|
|
13308
13769
|
throwStrictAssign();
|
|
13309
13770
|
}
|
|
@@ -14001,7 +14462,7 @@ function $thisSet(thisVal, key, value) {
|
|
|
14001
14462
|
if (thisVal.shape.k === "brand") {
|
|
14002
14463
|
const inner = thisVal.shape.shape;
|
|
14003
14464
|
const slots = inner.shape.k === "obj" ? { ...inner.shape.slots } : {};
|
|
14004
|
-
slots
|
|
14465
|
+
setSlot(slots, key, { value: asAbsVal(value) });
|
|
14005
14466
|
return abs(
|
|
14006
14467
|
{
|
|
14007
14468
|
k: "brand",
|
|
@@ -14090,9 +14551,19 @@ function $staticInvoke(cls, method, args) {
|
|
|
14090
14551
|
}
|
|
14091
14552
|
}
|
|
14092
14553
|
function $setKey(o, key, value) {
|
|
14093
|
-
const
|
|
14554
|
+
const pk = propertyKeyOf(key);
|
|
14555
|
+
const k = pk !== void 0 ? pk : litValue(key);
|
|
14094
14556
|
if (typeof k === "string" || typeof k === "number") {
|
|
14095
|
-
|
|
14557
|
+
const ks = String(k);
|
|
14558
|
+
if (ks === "__proto__" && o.shape.k === "obj") {
|
|
14559
|
+
setSlot(o.shape.slots, ks, {
|
|
14560
|
+
value: asAbsVal(value)
|
|
14561
|
+
});
|
|
14562
|
+
o.conf = confJoin(o.conf, value.conf);
|
|
14563
|
+
clearStaleTermPred(o);
|
|
14564
|
+
return o;
|
|
14565
|
+
}
|
|
14566
|
+
return $set(o, ks, value);
|
|
14096
14567
|
}
|
|
14097
14568
|
const val = asAbsVal(value);
|
|
14098
14569
|
if (o.shape.k === "brand") {
|
|
@@ -14883,6 +15354,7 @@ export {
|
|
|
14883
15354
|
projectDerivationDsl,
|
|
14884
15355
|
termKey3 as termKey,
|
|
14885
15356
|
canonicalArrayIndex,
|
|
15357
|
+
propertyKeyOf,
|
|
14886
15358
|
objOf,
|
|
14887
15359
|
isObj,
|
|
14888
15360
|
getSlot,
|
|
@@ -15151,6 +15623,9 @@ export {
|
|
|
15151
15623
|
$ushr,
|
|
15152
15624
|
$pow,
|
|
15153
15625
|
$toNumber,
|
|
15626
|
+
$toNumeric,
|
|
15627
|
+
$updateAdd,
|
|
15628
|
+
$updateSub,
|
|
15154
15629
|
$neg,
|
|
15155
15630
|
$typeof,
|
|
15156
15631
|
$not,
|
|
@@ -15237,6 +15712,7 @@ export {
|
|
|
15237
15712
|
$idxSet,
|
|
15238
15713
|
$len,
|
|
15239
15714
|
$obj,
|
|
15715
|
+
$setProto,
|
|
15240
15716
|
$spread,
|
|
15241
15717
|
$objRest,
|
|
15242
15718
|
$arrRest,
|