nudojs 1.0.5 → 1.0.7
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/index.js +813 -265
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -61,7 +61,9 @@ function termEquals(a, b) {
|
|
|
61
61
|
}
|
|
62
62
|
function termToString(t) {
|
|
63
63
|
if (t.op === "lit") {
|
|
64
|
-
|
|
64
|
+
if (typeof t.value === "string") return JSON.stringify(t.value);
|
|
65
|
+
if (typeof t.value === "number" && Object.is(t.value, -0)) return "-0";
|
|
66
|
+
return String(t.value);
|
|
65
67
|
}
|
|
66
68
|
if (t.op === "var") return t.id;
|
|
67
69
|
if (t.op === "app" && t.fn === "get" && t.args.length === 2) {
|
|
@@ -93,12 +95,22 @@ function simplifyTerm(t) {
|
|
|
93
95
|
}
|
|
94
96
|
if (fn2 === "*" && args.length === 2) {
|
|
95
97
|
const [a, b] = args;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
const one = (t2) => t2.op === "lit" && t2.value === 1;
|
|
99
|
+
const surviveMulOne = (t2) => {
|
|
100
|
+
if (t2.op !== "lit") return t2;
|
|
101
|
+
const v2 = t2.value;
|
|
102
|
+
if (typeof v2 === "number") return t2;
|
|
103
|
+
if (typeof v2 === "boolean") return lit(v2 ? 1 : 0);
|
|
104
|
+
if (v2 === null) return lit(0);
|
|
105
|
+
if (typeof v2 === "string") return lit(Number(v2));
|
|
106
|
+
return lit(NaN);
|
|
107
|
+
};
|
|
108
|
+
if (one(b)) return surviveMulOne(a);
|
|
109
|
+
if (one(a)) return surviveMulOne(b);
|
|
98
110
|
}
|
|
99
111
|
if (fn2 === "-" && args.length === 2) {
|
|
100
112
|
const [a, b] = args;
|
|
101
|
-
if (b.op === "lit" && b.value
|
|
113
|
+
if (b.op === "lit" && Object.is(b.value, 0)) return a;
|
|
102
114
|
}
|
|
103
115
|
return app(fn2, args);
|
|
104
116
|
}
|
|
@@ -196,13 +208,10 @@ function negatePred(p) {
|
|
|
196
208
|
case "ne":
|
|
197
209
|
return eq(p.a, p.b);
|
|
198
210
|
case "lt":
|
|
199
|
-
return ge(p.a, p.b);
|
|
200
211
|
case "le":
|
|
201
|
-
return gt(p.a, p.b);
|
|
202
212
|
case "gt":
|
|
203
|
-
return le(p.a, p.b);
|
|
204
213
|
case "ge":
|
|
205
|
-
return
|
|
214
|
+
return { op: "not", arg: p };
|
|
206
215
|
case "and":
|
|
207
216
|
return or(...p.args.map(negatePred));
|
|
208
217
|
case "or":
|
|
@@ -215,6 +224,13 @@ function negatePred(p) {
|
|
|
215
224
|
);
|
|
216
225
|
}
|
|
217
226
|
}
|
|
227
|
+
function totalOrderDual(p) {
|
|
228
|
+
if (p.op === "lt") return ge(p.a, p.b);
|
|
229
|
+
if (p.op === "le") return gt(p.a, p.b);
|
|
230
|
+
if (p.op === "gt") return le(p.a, p.b);
|
|
231
|
+
if (p.op === "ge") return lt(p.a, p.b);
|
|
232
|
+
return void 0;
|
|
233
|
+
}
|
|
218
234
|
function predEquals(a, b) {
|
|
219
235
|
if (a === b) return true;
|
|
220
236
|
if (a.op !== b.op) return false;
|
|
@@ -351,14 +367,18 @@ function implies(phi2, pred) {
|
|
|
351
367
|
if (expanded.op !== "not") {
|
|
352
368
|
return implies(phi2, expanded);
|
|
353
369
|
}
|
|
370
|
+
const dual = totalOrderDual(pred.arg);
|
|
371
|
+
if (dual && implies(phi2, dual)) return true;
|
|
354
372
|
if (phi2.op === "not") {
|
|
355
373
|
return implies(pred.arg, phi2.arg);
|
|
356
374
|
}
|
|
357
375
|
if (phi2.op === "and") {
|
|
358
376
|
for (const c of phi2.args) {
|
|
359
377
|
if (c.op === "not" && implies(pred.arg, c.arg)) return true;
|
|
378
|
+
if (dual && predEquals(c, dual)) return true;
|
|
360
379
|
}
|
|
361
380
|
}
|
|
381
|
+
if (dual && predEquals(phi2, dual)) return true;
|
|
362
382
|
if (pred.arg.op === "typeof" && impliesNotTypeof(phi2, pred.arg)) return true;
|
|
363
383
|
return false;
|
|
364
384
|
}
|
|
@@ -15542,10 +15562,17 @@ function pureFnNameOf(fn2) {
|
|
|
15542
15562
|
if (impl?.pureName) return impl.pureName;
|
|
15543
15563
|
return fn2._memoize;
|
|
15544
15564
|
}
|
|
15545
|
-
function absFunction(params, impl) {
|
|
15565
|
+
function absFunction(params, impl, opts) {
|
|
15546
15566
|
const a = {
|
|
15547
|
-
shape: {
|
|
15548
|
-
|
|
15567
|
+
shape: {
|
|
15568
|
+
k: "fn",
|
|
15569
|
+
params,
|
|
15570
|
+
...opts?.name ? { name: opts.name } : {},
|
|
15571
|
+
...opts?.paramTypes ? { paramTypes: opts.paramTypes } : {},
|
|
15572
|
+
...opts?.returnType ? { returnType: opts.returnType } : {},
|
|
15573
|
+
...opts?.slots ? { slots: opts.slots } : {}
|
|
15574
|
+
},
|
|
15575
|
+
conf: opts?.conf ?? "exact"
|
|
15549
15576
|
};
|
|
15550
15577
|
attachFnImpl(a, { params, ...impl });
|
|
15551
15578
|
return a;
|
|
@@ -15600,7 +15627,8 @@ function shapeStableKey(s, seen) {
|
|
|
15600
15627
|
const pts = (s.paramTypes ?? []).map((t) => absStableKey(t, seen)).join(",");
|
|
15601
15628
|
const ret = s.returnType ? absStableKey(s.returnType, seen) : "?";
|
|
15602
15629
|
const name = s.name ? `#${s.name}` : "";
|
|
15603
|
-
|
|
15630
|
+
const slots = s.slots ? `{${Object.keys(s.slots).sort().map((k) => `${k}:${absStableKey(s.slots[k].value, seen)}`).join(",")}}` : "";
|
|
15631
|
+
return `fn${name}(${s.params.join(",")}|${pts})=>${ret}${slots}`;
|
|
15604
15632
|
}
|
|
15605
15633
|
case "sum":
|
|
15606
15634
|
return `sum(${s.members.map((m) => absStableKey(m, seen)).join("|")})`;
|
|
@@ -15822,6 +15850,13 @@ function canonicalArrayIndex(v2) {
|
|
|
15822
15850
|
}
|
|
15823
15851
|
return void 0;
|
|
15824
15852
|
}
|
|
15853
|
+
function propertyKeyOf(a) {
|
|
15854
|
+
if (a === void 0) return void 0;
|
|
15855
|
+
if (a.term?.op !== "lit") return void 0;
|
|
15856
|
+
const v2 = a.term.value;
|
|
15857
|
+
if (typeof v2 === "symbol") return void 0;
|
|
15858
|
+
return String(v2);
|
|
15859
|
+
}
|
|
15825
15860
|
function objOf(slots, opts) {
|
|
15826
15861
|
const shape2 = { k: "obj", slots };
|
|
15827
15862
|
if (opts?.index) shape2.index = opts.index;
|
|
@@ -15834,6 +15869,25 @@ function isObj(a) {
|
|
|
15834
15869
|
function getSlot(slots, key) {
|
|
15835
15870
|
return Object.prototype.hasOwnProperty.call(slots, key) ? slots[key] : void 0;
|
|
15836
15871
|
}
|
|
15872
|
+
function setSlot(slots, key, slot) {
|
|
15873
|
+
Object.defineProperty(slots, key, {
|
|
15874
|
+
value: slot,
|
|
15875
|
+
enumerable: true,
|
|
15876
|
+
writable: true,
|
|
15877
|
+
configurable: true
|
|
15878
|
+
});
|
|
15879
|
+
}
|
|
15880
|
+
function setProtoAbs(o, proto) {
|
|
15881
|
+
const pv = litValue(proto);
|
|
15882
|
+
if (pv === null) return markNullProtoObj(o);
|
|
15883
|
+
if (proto.term?.op === "lit" && (pv === void 0 || typeof pv !== "object")) {
|
|
15884
|
+
return o;
|
|
15885
|
+
}
|
|
15886
|
+
if (isObj(o)) {
|
|
15887
|
+
o.shape.open = true;
|
|
15888
|
+
}
|
|
15889
|
+
return o;
|
|
15890
|
+
}
|
|
15837
15891
|
function spread(base, over) {
|
|
15838
15892
|
if (!isObj(base) && !isObj(over)) {
|
|
15839
15893
|
if (isObj(over)) return { shape: { ...over.shape, open: true }, conf: confJoin(base.conf, over.conf) };
|
|
@@ -15852,7 +15906,7 @@ function spread(base, over) {
|
|
|
15852
15906
|
const indexSlots = spreadIndexSlots(over);
|
|
15853
15907
|
if (indexSlots && isObj(base)) {
|
|
15854
15908
|
const slots2 = { ...base.shape.slots };
|
|
15855
|
-
for (const [k, s] of Object.entries(indexSlots)) slots2
|
|
15909
|
+
for (const [k, s] of Object.entries(indexSlots)) setSlot(slots2, k, s);
|
|
15856
15910
|
const shape3 = { k: "obj", slots: slots2 };
|
|
15857
15911
|
if (base.shape.open) shape3.open = true;
|
|
15858
15912
|
return { shape: shape3, conf: confJoin(base.conf, over.conf) };
|
|
@@ -15868,7 +15922,7 @@ function spread(base, over) {
|
|
|
15868
15922
|
}
|
|
15869
15923
|
const slots = { ...base.shape.slots };
|
|
15870
15924
|
for (const [k, s] of Object.entries(over.shape.slots)) {
|
|
15871
|
-
slots
|
|
15925
|
+
setSlot(slots, k, s);
|
|
15872
15926
|
}
|
|
15873
15927
|
const open = base.shape.open || over.shape.open || false;
|
|
15874
15928
|
const shape2 = { k: "obj", slots };
|
|
@@ -15892,8 +15946,9 @@ function spreadIndexSlots(over) {
|
|
|
15892
15946
|
const sv = over.term?.op === "lit" && typeof over.term.value === "string" ? over.term.value : void 0;
|
|
15893
15947
|
if (sv !== void 0) {
|
|
15894
15948
|
const slots = {};
|
|
15895
|
-
let i = 0;
|
|
15896
|
-
|
|
15949
|
+
for (let i = 0; i < sv.length; i++) {
|
|
15950
|
+
slots[String(i)] = { value: strLit(sv[i]) };
|
|
15951
|
+
}
|
|
15897
15952
|
return slots;
|
|
15898
15953
|
}
|
|
15899
15954
|
return void 0;
|
|
@@ -15918,7 +15973,7 @@ function joinObjects(a, b) {
|
|
|
15918
15973
|
const optional = sa.optional || sb.optional;
|
|
15919
15974
|
const jv = joinValues(sa.value, sb.value);
|
|
15920
15975
|
conf = confJoin(conf, jv.conf);
|
|
15921
|
-
slots
|
|
15976
|
+
setSlot(slots, k, { value: jv, optional });
|
|
15922
15977
|
}
|
|
15923
15978
|
return { shape: { k: "obj", slots }, conf };
|
|
15924
15979
|
}
|
|
@@ -16332,7 +16387,12 @@ function snapshotAbs(a) {
|
|
|
16332
16387
|
const nextSlot = { value: snapshotAbs(slot.value) };
|
|
16333
16388
|
if (slot.optional) nextSlot.optional = true;
|
|
16334
16389
|
if (slot.readonly) nextSlot.readonly = true;
|
|
16335
|
-
slots
|
|
16390
|
+
Object.defineProperty(slots, k, {
|
|
16391
|
+
value: nextSlot,
|
|
16392
|
+
enumerable: true,
|
|
16393
|
+
writable: true,
|
|
16394
|
+
configurable: true
|
|
16395
|
+
});
|
|
16336
16396
|
}
|
|
16337
16397
|
const next = { k: "obj", slots };
|
|
16338
16398
|
if (s.index) {
|
|
@@ -16578,7 +16638,12 @@ function substShape(s, map, cache2, visiting) {
|
|
|
16578
16638
|
const nextSlot = { value: substAbsInner(slot.value, map, cache2, visiting) };
|
|
16579
16639
|
if (slot.optional) nextSlot.optional = true;
|
|
16580
16640
|
if (slot.readonly) nextSlot.readonly = true;
|
|
16581
|
-
slots
|
|
16641
|
+
Object.defineProperty(slots, k, {
|
|
16642
|
+
value: nextSlot,
|
|
16643
|
+
enumerable: true,
|
|
16644
|
+
writable: true,
|
|
16645
|
+
configurable: true
|
|
16646
|
+
});
|
|
16582
16647
|
}
|
|
16583
16648
|
const next = { k: "obj", slots };
|
|
16584
16649
|
if (s.index) {
|
|
@@ -16937,9 +17002,14 @@ function concatString(a, b) {
|
|
|
16937
17002
|
);
|
|
16938
17003
|
}
|
|
16939
17004
|
const aParts = coerceToStringParts(a);
|
|
16940
|
-
const
|
|
16941
|
-
if (!aParts || !
|
|
16942
|
-
|
|
17005
|
+
const bParts = coerceToStringParts(b);
|
|
17006
|
+
if (!aParts || !bParts) {
|
|
17007
|
+
if (isStrPrim2(a) || isStrPrim2(b)) {
|
|
17008
|
+
return abs({ k: "prim", type: "string" }, void 0, void 0, "path");
|
|
17009
|
+
}
|
|
17010
|
+
return abs({ k: "unknown" }, void 0, void 0, "partial");
|
|
17011
|
+
}
|
|
17012
|
+
return createTemplateAbs([...aParts, ...bParts]);
|
|
16943
17013
|
}
|
|
16944
17014
|
function coerceToStringParts(a) {
|
|
16945
17015
|
if (isTemplateAbs(a) || isStrPrim2(a)) return templatePartsOf(a);
|
|
@@ -17222,6 +17292,12 @@ function add(a, b, phi2 = pTrue) {
|
|
|
17222
17292
|
if (typeof va === "string" || typeof vb === "string") {
|
|
17223
17293
|
return strLitResult(String(va) + String(vb));
|
|
17224
17294
|
}
|
|
17295
|
+
if (typeof va === "bigint" && typeof vb !== "bigint" || typeof vb === "bigint" && typeof va !== "bigint") {
|
|
17296
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
17297
|
+
}
|
|
17298
|
+
}
|
|
17299
|
+
if (isStrPrim(a) || isStrPrim(b) || isTemplateLike(a) || isTemplateLike(b)) {
|
|
17300
|
+
return concatString(a, b);
|
|
17225
17301
|
}
|
|
17226
17302
|
if (coercibleLit(va) && coercibleLit(vb)) {
|
|
17227
17303
|
return numLit(Number(va) + Number(vb));
|
|
@@ -17231,9 +17307,6 @@ function add(a, b, phi2 = pTrue) {
|
|
|
17231
17307
|
if (isBigPrim(a) && isBigPrim(b)) {
|
|
17232
17308
|
return abs({ k: "prim", type: "bigint" }, void 0, void 0, confJoin(a.conf, b.conf));
|
|
17233
17309
|
}
|
|
17234
|
-
if (isStrPrim(a) || isStrPrim(b) || isTemplateLike(a) || isTemplateLike(b)) {
|
|
17235
|
-
return concatString(a, b);
|
|
17236
|
-
}
|
|
17237
17310
|
if (a.shape.k === "tuple" || a.shape.k === "arr" || b.shape.k === "tuple" || b.shape.k === "arr") {
|
|
17238
17311
|
return concatString(a, b);
|
|
17239
17312
|
}
|
|
@@ -17250,8 +17323,12 @@ function add(a, b, phi2 = pTrue) {
|
|
|
17250
17323
|
}
|
|
17251
17324
|
if (isAnyLike(a) || isAnyLike(b)) {
|
|
17252
17325
|
const term = a.term && b.term ? simplifyTerm(app("+", [a.term, b.term])) : void 0;
|
|
17326
|
+
const bigFace = isBigPrim(a) || isBigPrim(b);
|
|
17253
17327
|
return abs(
|
|
17254
|
-
{
|
|
17328
|
+
{
|
|
17329
|
+
k: "sum",
|
|
17330
|
+
members: bigFace ? [abs({ k: "prim", type: "bigint" }, void 0, void 0, "exact"), str()] : [num(), str()]
|
|
17331
|
+
},
|
|
17255
17332
|
term,
|
|
17256
17333
|
void 0,
|
|
17257
17334
|
"partial"
|
|
@@ -17284,6 +17361,15 @@ function add(a, b, phi2 = pTrue) {
|
|
|
17284
17361
|
}
|
|
17285
17362
|
return abs({ k: "unknown" }, void 0, void 0, "partial");
|
|
17286
17363
|
}
|
|
17364
|
+
function isKnownNonBigintNumeric(a) {
|
|
17365
|
+
const va = litValue(a);
|
|
17366
|
+
if (typeof va === "number" || typeof va === "boolean" || va === null) return true;
|
|
17367
|
+
if (a.term?.op === "lit" && a.term.value === void 0) return true;
|
|
17368
|
+
return a.shape.k === "prim" && (a.shape.type === "number" || a.shape.type === "boolean");
|
|
17369
|
+
}
|
|
17370
|
+
function isMaybeBigintOperand(a) {
|
|
17371
|
+
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";
|
|
17372
|
+
}
|
|
17287
17373
|
function foldBigintBinOp(a, b, op) {
|
|
17288
17374
|
const va = litValue(a);
|
|
17289
17375
|
const vb = litValue(b);
|
|
@@ -17291,13 +17377,27 @@ function foldBigintBinOp(a, b, op) {
|
|
|
17291
17377
|
if (typeof va === "bigint" && typeof vb === "bigint") {
|
|
17292
17378
|
try {
|
|
17293
17379
|
return bigintLit(op(va, vb));
|
|
17294
|
-
} catch {
|
|
17295
|
-
|
|
17380
|
+
} catch (e) {
|
|
17381
|
+
if (e instanceof RangeError) throw new NudoThrow(errorTypeAbs("RangeError"));
|
|
17382
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
17296
17383
|
}
|
|
17297
17384
|
}
|
|
17298
17385
|
const other = typeof va === "bigint" ? b : a;
|
|
17299
17386
|
if (isBigPrim(other)) return void 0;
|
|
17300
|
-
|
|
17387
|
+
if (isKnownNonBigintNumeric(other)) {
|
|
17388
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
17389
|
+
}
|
|
17390
|
+
if (isStrPrim(other)) {
|
|
17391
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
17392
|
+
}
|
|
17393
|
+
if (isMaybeBigintOperand(other)) {
|
|
17394
|
+
recordMayThrow({
|
|
17395
|
+
kind: "TypeError",
|
|
17396
|
+
cause: "mixed bigint \u2297 abstract operand"
|
|
17397
|
+
});
|
|
17398
|
+
return void 0;
|
|
17399
|
+
}
|
|
17400
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
17301
17401
|
}
|
|
17302
17402
|
function dedupAbsMembers(ms) {
|
|
17303
17403
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -17320,6 +17420,12 @@ function strLitResult(s) {
|
|
|
17320
17420
|
function normalizeNegZero(n) {
|
|
17321
17421
|
return n === 0 ? 0 : n;
|
|
17322
17422
|
}
|
|
17423
|
+
function ieeeBound(n, strict, strictZeroOk) {
|
|
17424
|
+
if (!Number.isFinite(n)) return void 0;
|
|
17425
|
+
const z = normalizeNegZero(n);
|
|
17426
|
+
if (z === 0 && strict && !strictZeroOk) return void 0;
|
|
17427
|
+
return z;
|
|
17428
|
+
}
|
|
17323
17429
|
function isAnyLike(a) {
|
|
17324
17430
|
if (a.shape.k === "any") return true;
|
|
17325
17431
|
if (a.shape.k === "unknown") return true;
|
|
@@ -17330,8 +17436,9 @@ function coercibleLit(v2) {
|
|
|
17330
17436
|
}
|
|
17331
17437
|
function toNumberResult(a, b, op) {
|
|
17332
17438
|
const term = a.term && b.term ? app(op, [a.term, b.term]) : void 0;
|
|
17439
|
+
const bigFace = isBigPrim(a) || isBigPrim(b);
|
|
17333
17440
|
return abs(
|
|
17334
|
-
{ k: "prim", type: "number" },
|
|
17441
|
+
bigFace ? { k: "prim", type: "bigint" } : { k: "prim", type: "number" },
|
|
17335
17442
|
term,
|
|
17336
17443
|
void 0,
|
|
17337
17444
|
term ? confJoin(confJoin(a.conf, b.conf), "partial") : "partial"
|
|
@@ -17346,14 +17453,18 @@ function addPred(a, b, sumTerm, phi2) {
|
|
|
17346
17453
|
if (!aBounds && !evalBounds) return void 0;
|
|
17347
17454
|
const facts = [];
|
|
17348
17455
|
if (aBounds?.lo !== void 0 && evalBounds?.lo !== void 0) {
|
|
17349
|
-
const loSum = aBounds.lo.value + evalBounds.lo.value;
|
|
17350
17456
|
const strict = aBounds.lo.strict || evalBounds.lo.strict;
|
|
17351
|
-
|
|
17457
|
+
const loSum = ieeeBound(aBounds.lo.value + evalBounds.lo.value, strict, true);
|
|
17458
|
+
if (loSum !== void 0) {
|
|
17459
|
+
facts.push(strict ? gt(sumTerm, lit(loSum)) : ge(sumTerm, lit(loSum)));
|
|
17460
|
+
}
|
|
17352
17461
|
}
|
|
17353
17462
|
if (aBounds?.hi !== void 0 && evalBounds?.hi !== void 0) {
|
|
17354
|
-
const hiSum = aBounds.hi.value + evalBounds.hi.value;
|
|
17355
17463
|
const strict = aBounds.hi.strict || evalBounds.hi.strict;
|
|
17356
|
-
|
|
17464
|
+
const hiSum = ieeeBound(aBounds.hi.value + evalBounds.hi.value, strict, true);
|
|
17465
|
+
if (hiSum !== void 0) {
|
|
17466
|
+
facts.push(strict ? lt(sumTerm, lit(hiSum)) : le(sumTerm, lit(hiSum)));
|
|
17467
|
+
}
|
|
17357
17468
|
}
|
|
17358
17469
|
if (facts.length === 0) return void 0;
|
|
17359
17470
|
return and(...facts);
|
|
@@ -17367,77 +17478,57 @@ function numericBounds(a, phi2 = pTrue) {
|
|
|
17367
17478
|
if (a.term?.op === "var") {
|
|
17368
17479
|
collectBoundsFromPhi(phi2, a.term.id, result);
|
|
17369
17480
|
}
|
|
17370
|
-
if (a.term?.op === "lit" && typeof a.term.value === "number") {
|
|
17481
|
+
if (a.term?.op === "lit" && typeof a.term.value === "number" && !Number.isNaN(a.term.value)) {
|
|
17371
17482
|
result.lo = { value: a.term.value, strict: false };
|
|
17372
17483
|
result.hi = { value: a.term.value, strict: false };
|
|
17373
17484
|
}
|
|
17374
17485
|
if (result.lo === void 0 && result.hi === void 0) return void 0;
|
|
17375
17486
|
return result;
|
|
17376
17487
|
}
|
|
17488
|
+
function tightenLo2(acc, n, strict) {
|
|
17489
|
+
if (acc.lo === void 0 || n > acc.lo.value || n === acc.lo.value && strict && !acc.lo.strict) {
|
|
17490
|
+
acc.lo = { value: n, strict };
|
|
17491
|
+
}
|
|
17492
|
+
}
|
|
17493
|
+
function tightenHi2(acc, n, strict) {
|
|
17494
|
+
if (acc.hi === void 0 || n < acc.hi.value || n === acc.hi.value && strict && !acc.hi.strict) {
|
|
17495
|
+
acc.hi = { value: n, strict };
|
|
17496
|
+
}
|
|
17497
|
+
}
|
|
17498
|
+
function noteBoundFromRel(p, isTarget, acc) {
|
|
17499
|
+
if (p.op !== "gt" && p.op !== "ge" && p.op !== "lt" && p.op !== "le") return;
|
|
17500
|
+
let op = p.op;
|
|
17501
|
+
let litSide;
|
|
17502
|
+
if (isTarget(p.a) && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
17503
|
+
litSide = p.b;
|
|
17504
|
+
} else if (isTarget(p.b) && p.a.op === "lit" && typeof p.a.value === "number") {
|
|
17505
|
+
op = op === "gt" ? "lt" : op === "lt" ? "gt" : op === "ge" ? "le" : "ge";
|
|
17506
|
+
litSide = p.a;
|
|
17507
|
+
} else {
|
|
17508
|
+
return;
|
|
17509
|
+
}
|
|
17510
|
+
const n = litSide.value;
|
|
17511
|
+
if (op === "gt") tightenLo2(acc, n, true);
|
|
17512
|
+
else if (op === "ge") tightenLo2(acc, n, false);
|
|
17513
|
+
else if (op === "lt") tightenHi2(acc, n, true);
|
|
17514
|
+
else tightenHi2(acc, n, false);
|
|
17515
|
+
}
|
|
17377
17516
|
function collectBoundsFromPred(pred, term, acc) {
|
|
17378
|
-
const
|
|
17517
|
+
const isTarget = (t) => termToString(t) === termToString(term);
|
|
17379
17518
|
const apply = (p) => {
|
|
17380
17519
|
if (p.op === "and") {
|
|
17381
17520
|
p.args.forEach(apply);
|
|
17382
17521
|
return;
|
|
17383
17522
|
}
|
|
17384
|
-
|
|
17385
|
-
const n = p.b.value;
|
|
17386
|
-
if (acc.lo === void 0 || n > acc.lo.value || n === acc.lo.value && !acc.lo.strict) {
|
|
17387
|
-
acc.lo = { value: n, strict: true };
|
|
17388
|
-
}
|
|
17389
|
-
return;
|
|
17390
|
-
}
|
|
17391
|
-
if (p.op === "ge" && match(p.a) && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
17392
|
-
const n = p.b.value;
|
|
17393
|
-
if (acc.lo === void 0 || n > acc.lo.value) {
|
|
17394
|
-
acc.lo = { value: n, strict: false };
|
|
17395
|
-
}
|
|
17396
|
-
return;
|
|
17397
|
-
}
|
|
17398
|
-
if (p.op === "lt" && match(p.a) && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
17399
|
-
const n = p.b.value;
|
|
17400
|
-
if (acc.hi === void 0 || n < acc.hi.value || n === acc.hi.value && !acc.hi.strict) {
|
|
17401
|
-
acc.hi = { value: n, strict: true };
|
|
17402
|
-
}
|
|
17403
|
-
return;
|
|
17404
|
-
}
|
|
17405
|
-
if (p.op === "le" && match(p.a) && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
17406
|
-
const n = p.b.value;
|
|
17407
|
-
if (acc.hi === void 0 || n < acc.hi.value) {
|
|
17408
|
-
acc.hi = { value: n, strict: false };
|
|
17409
|
-
}
|
|
17410
|
-
}
|
|
17523
|
+
noteBoundFromRel(p, isTarget, acc);
|
|
17411
17524
|
};
|
|
17412
17525
|
apply(pred);
|
|
17413
17526
|
}
|
|
17414
17527
|
function collectBoundsFromPhi(phi2, id, acc) {
|
|
17528
|
+
const isTarget = (t) => t.op === "var" && t.id === id;
|
|
17415
17529
|
const conjs = phi2.op === "and" ? phi2.args : [phi2];
|
|
17416
17530
|
for (const p of conjs) {
|
|
17417
|
-
|
|
17418
|
-
const n = p.b.value;
|
|
17419
|
-
if (acc.lo === void 0 || n > acc.lo.value || n === acc.lo.value && !acc.lo.strict) {
|
|
17420
|
-
acc.lo = { value: n, strict: true };
|
|
17421
|
-
}
|
|
17422
|
-
}
|
|
17423
|
-
if (p.op === "ge" && p.a.op === "var" && p.a.id === id && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
17424
|
-
const n = p.b.value;
|
|
17425
|
-
if (acc.lo === void 0 || n > acc.lo.value) {
|
|
17426
|
-
acc.lo = { value: n, strict: false };
|
|
17427
|
-
}
|
|
17428
|
-
}
|
|
17429
|
-
if (p.op === "lt" && p.a.op === "var" && p.a.id === id && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
17430
|
-
const n = p.b.value;
|
|
17431
|
-
if (acc.hi === void 0 || n < acc.hi.value || n === acc.hi.value && !acc.hi.strict) {
|
|
17432
|
-
acc.hi = { value: n, strict: true };
|
|
17433
|
-
}
|
|
17434
|
-
}
|
|
17435
|
-
if (p.op === "le" && p.a.op === "var" && p.a.id === id && p.b.op === "lit" && typeof p.b.value === "number") {
|
|
17436
|
-
const n = p.b.value;
|
|
17437
|
-
if (acc.hi === void 0 || n < acc.hi.value) {
|
|
17438
|
-
acc.hi = { value: n, strict: false };
|
|
17439
|
-
}
|
|
17440
|
-
}
|
|
17531
|
+
noteBoundFromRel(p, isTarget, acc);
|
|
17441
17532
|
}
|
|
17442
17533
|
}
|
|
17443
17534
|
function sub(a, b, phi2 = pTrue) {
|
|
@@ -17460,14 +17551,18 @@ function sub(a, b, phi2 = pTrue) {
|
|
|
17460
17551
|
const bb = numericBounds(b, phi2);
|
|
17461
17552
|
const facts = [];
|
|
17462
17553
|
if (ab?.lo !== void 0 && bb?.hi !== void 0) {
|
|
17463
|
-
const lo = ab.lo.value - bb.hi.value;
|
|
17464
17554
|
const strict = ab.lo.strict || bb.hi.strict;
|
|
17465
|
-
|
|
17555
|
+
const lo = ieeeBound(ab.lo.value - bb.hi.value, strict, true);
|
|
17556
|
+
if (lo !== void 0) {
|
|
17557
|
+
facts.push(strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
17558
|
+
}
|
|
17466
17559
|
}
|
|
17467
17560
|
if (ab?.hi !== void 0 && bb?.lo !== void 0) {
|
|
17468
|
-
const hi = ab.hi.value - bb.lo.value;
|
|
17469
17561
|
const strict = ab.hi.strict || bb.lo.strict;
|
|
17470
|
-
|
|
17562
|
+
const hi = ieeeBound(ab.hi.value - bb.lo.value, strict, true);
|
|
17563
|
+
if (hi !== void 0) {
|
|
17564
|
+
facts.push(strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
17565
|
+
}
|
|
17471
17566
|
}
|
|
17472
17567
|
const conf = term.op === "lit" ? "exact" : confJoin(confJoin(a.conf, b.conf), facts.length ? "path" : "path");
|
|
17473
17568
|
return abs({ k: "prim", type: "number" }, term, facts.length ? and(...facts) : void 0, conf);
|
|
@@ -17505,25 +17600,26 @@ function mul(a, b, phi2 = pTrue) {
|
|
|
17505
17600
|
k = a.term.value;
|
|
17506
17601
|
base = b;
|
|
17507
17602
|
}
|
|
17508
|
-
if (k !== void 0 && base !== void 0 && k !== 0) {
|
|
17603
|
+
if (k !== void 0 && base !== void 0 && k !== 0 && Number.isFinite(k)) {
|
|
17604
|
+
const strictZeroOk = Math.abs(k) >= 1;
|
|
17509
17605
|
const ab = numericBounds(base, phi2);
|
|
17510
17606
|
const facts = [];
|
|
17511
17607
|
if (ab?.lo !== void 0) {
|
|
17512
17608
|
if (k > 0) {
|
|
17513
|
-
const lo = ab.lo.value * k;
|
|
17514
|
-
facts.push(ab.lo.strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
17609
|
+
const lo = ieeeBound(ab.lo.value * k, ab.lo.strict, strictZeroOk);
|
|
17610
|
+
if (lo !== void 0) facts.push(ab.lo.strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
17515
17611
|
} else {
|
|
17516
|
-
const hi = ab.lo.value * k;
|
|
17517
|
-
facts.push(ab.lo.strict ? lt(term, lit(
|
|
17612
|
+
const hi = ieeeBound(ab.lo.value * k, ab.lo.strict, strictZeroOk);
|
|
17613
|
+
if (hi !== void 0) facts.push(ab.lo.strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
17518
17614
|
}
|
|
17519
17615
|
}
|
|
17520
17616
|
if (ab?.hi !== void 0) {
|
|
17521
17617
|
if (k > 0) {
|
|
17522
|
-
const hi = ab.hi.value * k;
|
|
17523
|
-
facts.push(ab.hi.strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
17618
|
+
const hi = ieeeBound(ab.hi.value * k, ab.hi.strict, strictZeroOk);
|
|
17619
|
+
if (hi !== void 0) facts.push(ab.hi.strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
17524
17620
|
} else {
|
|
17525
|
-
const lo = ab.hi.value * k;
|
|
17526
|
-
facts.push(ab.hi.strict ? gt(term, lit(
|
|
17621
|
+
const lo = ieeeBound(ab.hi.value * k, ab.hi.strict, strictZeroOk);
|
|
17622
|
+
if (lo !== void 0) facts.push(ab.hi.strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
17527
17623
|
}
|
|
17528
17624
|
}
|
|
17529
17625
|
return abs(
|
|
@@ -17567,19 +17663,24 @@ function div(a, b, phi2 = pTrue) {
|
|
|
17567
17663
|
}
|
|
17568
17664
|
if (isNumericLike(a) && isNumericLike(b) && a.term && b.term) {
|
|
17569
17665
|
const term = simplifyTerm(app("/", [a.term, b.term]));
|
|
17570
|
-
if (b.term.op === "lit" && typeof b.term.value === "number" && b.term.value !== 0) {
|
|
17666
|
+
if (b.term.op === "lit" && typeof b.term.value === "number" && b.term.value !== 0 && Number.isFinite(b.term.value)) {
|
|
17571
17667
|
const k = b.term.value;
|
|
17668
|
+
const strictZeroOk = Math.abs(k) <= 1;
|
|
17572
17669
|
const ab = numericBounds(a, phi2);
|
|
17573
17670
|
const facts = [];
|
|
17574
17671
|
if (ab?.lo !== void 0) {
|
|
17575
|
-
const lo = ab.lo.value / k;
|
|
17576
|
-
if (
|
|
17577
|
-
|
|
17672
|
+
const lo = ieeeBound(ab.lo.value / k, ab.lo.strict, strictZeroOk);
|
|
17673
|
+
if (lo !== void 0) {
|
|
17674
|
+
if (k > 0) facts.push(ab.lo.strict ? gt(term, lit(lo)) : ge(term, lit(lo)));
|
|
17675
|
+
else facts.push(ab.lo.strict ? lt(term, lit(lo)) : le(term, lit(lo)));
|
|
17676
|
+
}
|
|
17578
17677
|
}
|
|
17579
17678
|
if (ab?.hi !== void 0) {
|
|
17580
|
-
const hi = ab.hi.value / k;
|
|
17581
|
-
if (
|
|
17582
|
-
|
|
17679
|
+
const hi = ieeeBound(ab.hi.value / k, ab.hi.strict, strictZeroOk);
|
|
17680
|
+
if (hi !== void 0) {
|
|
17681
|
+
if (k > 0) facts.push(ab.hi.strict ? lt(term, lit(hi)) : le(term, lit(hi)));
|
|
17682
|
+
else facts.push(ab.hi.strict ? gt(term, lit(hi)) : ge(term, lit(hi)));
|
|
17683
|
+
}
|
|
17583
17684
|
}
|
|
17584
17685
|
return abs(
|
|
17585
17686
|
num().shape,
|
|
@@ -17660,8 +17761,9 @@ function cmp(op, a, b, phi2 = pTrue) {
|
|
|
17660
17761
|
if (a.term && b.term) {
|
|
17661
17762
|
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 };
|
|
17662
17763
|
if (implies(phi2, pred)) return boolLit(true);
|
|
17663
|
-
|
|
17664
|
-
|
|
17764
|
+
if (implies(phi2, negatePred(pred))) return boolLit(false);
|
|
17765
|
+
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);
|
|
17766
|
+
if (dual && implies(phi2, dual)) return boolLit(false);
|
|
17665
17767
|
const decided = decideByBounds(op, a, b, phi2);
|
|
17666
17768
|
if (decided !== void 0) return boolLit(decided);
|
|
17667
17769
|
return {
|
|
@@ -17725,24 +17827,26 @@ function decideByBounds(op, a, b, phi2) {
|
|
|
17725
17827
|
const aHi = aB?.hi;
|
|
17726
17828
|
const bLo = bB?.lo;
|
|
17727
17829
|
const bHi = bB?.hi;
|
|
17830
|
+
const tighterHi = (x, y) => x.value < y.value || x.value === y.value && (x.strict || y.strict);
|
|
17831
|
+
const tighterLo = (x, y) => x.value > y.value || x.value === y.value && (x.strict || y.strict);
|
|
17728
17832
|
if (op === "lt") {
|
|
17729
|
-
if (aHi && bLo && aHi
|
|
17833
|
+
if (aHi && bLo && tighterHi(aHi, bLo)) return true;
|
|
17730
17834
|
if (aLo && bHi && aLo.value >= bHi.value) return false;
|
|
17731
17835
|
return void 0;
|
|
17732
17836
|
}
|
|
17733
17837
|
if (op === "le") {
|
|
17734
|
-
if (aHi && bLo && aHi.value
|
|
17735
|
-
if (aLo && bHi && aLo
|
|
17838
|
+
if (aHi && bLo && aHi.value <= bLo.value) return true;
|
|
17839
|
+
if (aLo && bHi && tighterLo(aLo, bHi)) return false;
|
|
17736
17840
|
return void 0;
|
|
17737
17841
|
}
|
|
17738
17842
|
if (op === "gt") {
|
|
17739
|
-
if (aLo && bHi && aLo
|
|
17843
|
+
if (aLo && bHi && tighterLo(aLo, bHi)) return true;
|
|
17740
17844
|
if (aHi && bLo && aHi.value <= bLo.value) return false;
|
|
17741
17845
|
return void 0;
|
|
17742
17846
|
}
|
|
17743
17847
|
if (op === "ge") {
|
|
17744
17848
|
if (aLo && bHi && aLo.value >= bHi.value) return true;
|
|
17745
|
-
if (aHi && bLo && aHi
|
|
17849
|
+
if (aHi && bLo && tighterHi(aHi, bLo)) return false;
|
|
17746
17850
|
return void 0;
|
|
17747
17851
|
}
|
|
17748
17852
|
return void 0;
|
|
@@ -17827,6 +17931,13 @@ function extStateOf(o) {
|
|
|
17827
17931
|
function getPropFlags(o) {
|
|
17828
17932
|
return propFlagsTable.get(o);
|
|
17829
17933
|
}
|
|
17934
|
+
function enumOwnKeys(o, slots) {
|
|
17935
|
+
const flags = getPropFlags(o);
|
|
17936
|
+
return Object.keys(slots).filter((k) => flags?.get(k)?.enumerable !== false);
|
|
17937
|
+
}
|
|
17938
|
+
function isEnumerableView(o, key) {
|
|
17939
|
+
return getPropFlags(o)?.get(key)?.enumerable !== false;
|
|
17940
|
+
}
|
|
17830
17941
|
function setPropFlags(o, key, f) {
|
|
17831
17942
|
let m = propFlagsTable.get(o);
|
|
17832
17943
|
if (!m) {
|
|
@@ -18125,7 +18236,7 @@ function assignSourceSlots(src) {
|
|
|
18125
18236
|
const slots = {};
|
|
18126
18237
|
for (const [k, v2] of Object.entries(inner.shape.slots)) {
|
|
18127
18238
|
if (k === "length") continue;
|
|
18128
|
-
slots
|
|
18239
|
+
setSlot(slots, k, v2);
|
|
18129
18240
|
}
|
|
18130
18241
|
if (Object.keys(slots).length > 0 || !inner.shape.open) return slots;
|
|
18131
18242
|
}
|
|
@@ -18210,8 +18321,12 @@ function evalObjectMethod(name, args) {
|
|
|
18210
18321
|
);
|
|
18211
18322
|
}
|
|
18212
18323
|
if (a0?.term?.op === "lit" && typeof a0.term.value === "string") {
|
|
18324
|
+
const s = a0.term.value;
|
|
18213
18325
|
return abs(
|
|
18214
|
-
{
|
|
18326
|
+
{
|
|
18327
|
+
k: "tuple",
|
|
18328
|
+
elements: Array.from({ length: s.length }, (_, i) => strLit(s[i]))
|
|
18329
|
+
},
|
|
18215
18330
|
void 0,
|
|
18216
18331
|
void 0,
|
|
18217
18332
|
"exact"
|
|
@@ -18241,12 +18356,13 @@ function evalObjectMethod(name, args) {
|
|
|
18241
18356
|
return abs({ k: "tuple", elements: entries }, void 0, void 0, "exact");
|
|
18242
18357
|
}
|
|
18243
18358
|
if (a0?.term?.op === "lit" && typeof a0.term.value === "string") {
|
|
18359
|
+
const s = a0.term.value;
|
|
18244
18360
|
return abs(
|
|
18245
18361
|
{
|
|
18246
18362
|
k: "tuple",
|
|
18247
18363
|
elements: Array.from(
|
|
18248
|
-
|
|
18249
|
-
(
|
|
18364
|
+
{ length: s.length },
|
|
18365
|
+
(_, i) => abs({ k: "tuple", elements: [strLit(String(i)), strLit(s[i])] }, void 0, void 0, "exact")
|
|
18250
18366
|
)
|
|
18251
18367
|
},
|
|
18252
18368
|
void 0,
|
|
@@ -18281,6 +18397,21 @@ function evalObjectMethod(name, args) {
|
|
|
18281
18397
|
}
|
|
18282
18398
|
return protoOfRecv(a0);
|
|
18283
18399
|
}
|
|
18400
|
+
case "setPrototypeOf": {
|
|
18401
|
+
if (!args.length) {
|
|
18402
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
18403
|
+
}
|
|
18404
|
+
const t0 = args[0];
|
|
18405
|
+
const p0 = args[1];
|
|
18406
|
+
if (!t0 || !p0) {
|
|
18407
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
18408
|
+
}
|
|
18409
|
+
const pv = litValue(p0);
|
|
18410
|
+
if (p0.term?.op === "lit" && (pv === void 0 || pv !== null && typeof pv !== "object")) {
|
|
18411
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
18412
|
+
}
|
|
18413
|
+
return setProtoAbs(t0, p0);
|
|
18414
|
+
}
|
|
18284
18415
|
case "assign": {
|
|
18285
18416
|
if (!args.length) return unknown;
|
|
18286
18417
|
const t0 = args[0];
|
|
@@ -18297,7 +18428,11 @@ function evalObjectMethod(name, args) {
|
|
|
18297
18428
|
if (acc.shape.k === "obj" && src.shape.k === "obj") {
|
|
18298
18429
|
const base = acc.shape.slots;
|
|
18299
18430
|
const over = src.shape.slots;
|
|
18300
|
-
|
|
18431
|
+
const filtered = { ...base };
|
|
18432
|
+
for (const k of enumKeys(over, src)) {
|
|
18433
|
+
filtered[k] = over[k];
|
|
18434
|
+
}
|
|
18435
|
+
acc = abs({ k: "obj", slots: filtered }, void 0, void 0, confJoin(acc.conf, src.conf));
|
|
18301
18436
|
} else if (src.shape.k !== "obj") {
|
|
18302
18437
|
const srcSlots = assignSourceSlots(src);
|
|
18303
18438
|
if (srcSlots === void 0) {
|
|
@@ -18554,9 +18689,9 @@ function jsonValueToAbs(v2) {
|
|
|
18554
18689
|
if (Array.isArray(v2)) {
|
|
18555
18690
|
return abs({ k: "tuple", elements: v2.map(jsonValueToAbs) }, void 0, void 0, "exact");
|
|
18556
18691
|
}
|
|
18557
|
-
const slots =
|
|
18692
|
+
const slots = /* @__PURE__ */ Object.create(null);
|
|
18558
18693
|
for (const [k, sv] of Object.entries(v2)) {
|
|
18559
|
-
slots
|
|
18694
|
+
setSlot(slots, k, { value: jsonValueToAbs(sv) });
|
|
18560
18695
|
}
|
|
18561
18696
|
return abs({ k: "obj", slots }, void 0, void 0, "exact");
|
|
18562
18697
|
}
|
|
@@ -18610,9 +18745,7 @@ function evalJsonMethod(name, args) {
|
|
|
18610
18745
|
const t = spaceArg.term;
|
|
18611
18746
|
if (t?.op !== "lit") return str2("partial");
|
|
18612
18747
|
const sv = t.value;
|
|
18613
|
-
if (typeof sv === "number") {
|
|
18614
|
-
space = Number.isFinite(sv) ? Math.min(10, Math.max(0, Math.floor(sv))) : 0;
|
|
18615
|
-
} else if (typeof sv === "string") {
|
|
18748
|
+
if (typeof sv === "number" || typeof sv === "string") {
|
|
18616
18749
|
space = sv;
|
|
18617
18750
|
} else if (sv !== void 0 && sv !== null) {
|
|
18618
18751
|
return str2("partial");
|
|
@@ -18632,6 +18765,7 @@ var init_json = __esm({
|
|
|
18632
18765
|
"../core/src/algebra/builtins/json.ts"() {
|
|
18633
18766
|
"use strict";
|
|
18634
18767
|
init_abs();
|
|
18768
|
+
init_objects();
|
|
18635
18769
|
init_hof();
|
|
18636
18770
|
init_nudo_throw();
|
|
18637
18771
|
init_may_throw();
|
|
@@ -20177,6 +20311,37 @@ function evalBuiltinNew(className, args) {
|
|
|
20177
20311
|
return evalPromiseCtor(args);
|
|
20178
20312
|
case "Array":
|
|
20179
20313
|
return makeArrayCtorAbs(args);
|
|
20314
|
+
case "Number":
|
|
20315
|
+
case "Boolean":
|
|
20316
|
+
return abs(
|
|
20317
|
+
{ k: "brand", name: className, shape: objOf({}) },
|
|
20318
|
+
void 0,
|
|
20319
|
+
void 0,
|
|
20320
|
+
"path"
|
|
20321
|
+
);
|
|
20322
|
+
case "String": {
|
|
20323
|
+
const a0 = args[0] ? litValue(args[0]) : void 0;
|
|
20324
|
+
if (typeof a0 === "string") {
|
|
20325
|
+
const slots = {
|
|
20326
|
+
length: { value: numLit(a0.length) }
|
|
20327
|
+
};
|
|
20328
|
+
for (let i = 0; i < a0.length; i++) {
|
|
20329
|
+
slots[String(i)] = { value: strLit(a0[i]) };
|
|
20330
|
+
}
|
|
20331
|
+
return abs(
|
|
20332
|
+
{ k: "brand", name: "String", shape: objOf(slots) },
|
|
20333
|
+
void 0,
|
|
20334
|
+
void 0,
|
|
20335
|
+
"exact"
|
|
20336
|
+
);
|
|
20337
|
+
}
|
|
20338
|
+
return abs(
|
|
20339
|
+
{ k: "brand", name: "String", shape: objOf({}, { open: true }) },
|
|
20340
|
+
void 0,
|
|
20341
|
+
void 0,
|
|
20342
|
+
"path"
|
|
20343
|
+
);
|
|
20344
|
+
}
|
|
20180
20345
|
case "Map":
|
|
20181
20346
|
if (ctorArgDefinitelyInvalid("Map", args[0])) {
|
|
20182
20347
|
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
@@ -20452,6 +20617,7 @@ function evalObjectProtoMethod(name, thisVal, args) {
|
|
|
20452
20617
|
if (!vObjLike && vk !== "sum" && vk !== "any" && vk !== "unknown") return boolLit(false);
|
|
20453
20618
|
if (vObjLike && isNullProtoObj(v2)) return boolLit(false);
|
|
20454
20619
|
if (isObjectProtoBrand(thisVal)) {
|
|
20620
|
+
if (isObjectProtoBrand(v2)) return boolLit(false);
|
|
20455
20621
|
return vObjLike ? boolLit(true) : boolPrimB();
|
|
20456
20622
|
}
|
|
20457
20623
|
return boolPrimB();
|
|
@@ -20522,27 +20688,50 @@ var init_builtins = __esm({
|
|
|
20522
20688
|
function coercibleNumberLit(v2) {
|
|
20523
20689
|
return typeof v2 === "number" || typeof v2 === "string" || typeof v2 === "boolean" || v2 === null;
|
|
20524
20690
|
}
|
|
20525
|
-
function
|
|
20526
|
-
|
|
20691
|
+
function isKnownNonBigintNumeric2(a) {
|
|
20692
|
+
const va = litValue(a);
|
|
20693
|
+
if (typeof va === "number" || typeof va === "boolean" || va === null) return true;
|
|
20694
|
+
if (a.term?.op === "lit" && a.term.value === void 0) return true;
|
|
20695
|
+
return a.shape.k === "prim" && (a.shape.type === "number" || a.shape.type === "boolean");
|
|
20696
|
+
}
|
|
20697
|
+
function isMaybeBigintOperand2(a) {
|
|
20698
|
+
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";
|
|
20527
20699
|
}
|
|
20528
20700
|
function foldNumericBinOp(a, b, numOp, bigOp) {
|
|
20529
20701
|
const va = litValue(a);
|
|
20530
20702
|
const vb = litValue(b);
|
|
20703
|
+
if (!bigOp && (typeof va === "bigint" || typeof vb === "bigint" || isBigPrim(a) || isBigPrim(b))) {
|
|
20704
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
20705
|
+
}
|
|
20531
20706
|
if (typeof va === "bigint" || typeof vb === "bigint") {
|
|
20532
20707
|
if (typeof va === "bigint" && typeof vb === "bigint") {
|
|
20533
|
-
|
|
20708
|
+
const op = bigOp;
|
|
20534
20709
|
try {
|
|
20535
20710
|
return abs(
|
|
20536
20711
|
{ k: "prim", type: "bigint" },
|
|
20537
|
-
lit(
|
|
20712
|
+
lit(op(va, vb)),
|
|
20538
20713
|
pTrue,
|
|
20539
20714
|
"exact"
|
|
20540
20715
|
);
|
|
20541
|
-
} catch {
|
|
20542
|
-
|
|
20716
|
+
} catch (e) {
|
|
20717
|
+
if (e instanceof RangeError) throw new NudoThrow(errorTypeAbs("RangeError"));
|
|
20718
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
20543
20719
|
}
|
|
20544
20720
|
}
|
|
20545
|
-
|
|
20721
|
+
const other = typeof va === "bigint" ? b : a;
|
|
20722
|
+
if (isBigPrim(other)) return void 0;
|
|
20723
|
+
if (!bigOp) throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
20724
|
+
if (isKnownNonBigintNumeric2(other) || isStrPrim(other)) {
|
|
20725
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
20726
|
+
}
|
|
20727
|
+
if (isMaybeBigintOperand2(other)) {
|
|
20728
|
+
recordMayThrow({
|
|
20729
|
+
kind: "TypeError",
|
|
20730
|
+
cause: "mixed bigint \u2297 abstract operand"
|
|
20731
|
+
});
|
|
20732
|
+
return void 0;
|
|
20733
|
+
}
|
|
20734
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
20546
20735
|
}
|
|
20547
20736
|
if (coercibleNumberLit(va) && coercibleNumberLit(vb)) {
|
|
20548
20737
|
return abs(
|
|
@@ -20557,11 +20746,12 @@ function foldNumericBinOp(a, b, numOp, bigOp) {
|
|
|
20557
20746
|
function foldNumericUnOp(a, numOp, bigOp) {
|
|
20558
20747
|
const v2 = litValue(a);
|
|
20559
20748
|
if (typeof v2 === "bigint") {
|
|
20560
|
-
if (!bigOp)
|
|
20749
|
+
if (!bigOp) throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
20561
20750
|
try {
|
|
20562
20751
|
return abs({ k: "prim", type: "bigint" }, lit(bigOp(v2)), pTrue, "exact");
|
|
20563
|
-
} catch {
|
|
20564
|
-
|
|
20752
|
+
} catch (e) {
|
|
20753
|
+
if (e instanceof RangeError) throw new NudoThrow(errorTypeAbs("RangeError"));
|
|
20754
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
20565
20755
|
}
|
|
20566
20756
|
}
|
|
20567
20757
|
if (coercibleNumberLit(v2)) {
|
|
@@ -20614,10 +20804,65 @@ function ushrAbs(a, b) {
|
|
|
20614
20804
|
function powAbs(a, b) {
|
|
20615
20805
|
return foldNumericBinOp(a, b, (x, y) => x ** y, (x, y) => x ** y) ?? bitwiseResultShape(a, b);
|
|
20616
20806
|
}
|
|
20807
|
+
function toNumericAbs(a) {
|
|
20808
|
+
const v2 = litValue(a);
|
|
20809
|
+
if (typeof v2 === "bigint") return bigintLit(v2);
|
|
20810
|
+
if (isBigPrim(a)) return a;
|
|
20811
|
+
if (a.term?.op === "lit" && a.term.value === void 0) {
|
|
20812
|
+
return abs({ k: "prim", type: "number" }, lit(NaN), pTrue, "exact");
|
|
20813
|
+
}
|
|
20814
|
+
const n = toNumberAbs(a);
|
|
20815
|
+
if (n.shape.k === "unknown") {
|
|
20816
|
+
return abs({ k: "prim", type: "number" }, void 0, void 0, "partial");
|
|
20817
|
+
}
|
|
20818
|
+
return n;
|
|
20819
|
+
}
|
|
20820
|
+
function updateAddAbs(a) {
|
|
20821
|
+
const n = toNumericAbs(a);
|
|
20822
|
+
const one = n.shape.k === "prim" && n.shape.type === "bigint" ? bigintLit(1n) : numLit(1);
|
|
20823
|
+
if (n.shape.k === "prim" && n.shape.type === "bigint" && !n.term) {
|
|
20824
|
+
return abs({ k: "prim", type: "bigint" }, void 0, void 0, confJoin(n.conf, "exact"));
|
|
20825
|
+
}
|
|
20826
|
+
return addNumeric(n, one);
|
|
20827
|
+
}
|
|
20828
|
+
function updateSubAbs(a) {
|
|
20829
|
+
const n = toNumericAbs(a);
|
|
20830
|
+
const one = n.shape.k === "prim" && n.shape.type === "bigint" ? bigintLit(1n) : numLit(1);
|
|
20831
|
+
if (n.shape.k === "prim" && n.shape.type === "bigint" && !n.term) {
|
|
20832
|
+
return abs({ k: "prim", type: "bigint" }, void 0, void 0, confJoin(n.conf, "exact"));
|
|
20833
|
+
}
|
|
20834
|
+
return subNumeric(n, one);
|
|
20835
|
+
}
|
|
20836
|
+
function addNumeric(a, b) {
|
|
20837
|
+
const va = litValue(a);
|
|
20838
|
+
const vb = litValue(b);
|
|
20839
|
+
if (typeof va === "bigint" && typeof vb === "bigint") return bigintLit(va + vb);
|
|
20840
|
+
if (typeof va === "number" && typeof vb === "number") return numLit(va + vb);
|
|
20841
|
+
const big = a.shape.k === "prim" && a.shape.type === "bigint" || typeof va === "bigint";
|
|
20842
|
+
return abs(
|
|
20843
|
+
{ k: "prim", type: big ? "bigint" : "number" },
|
|
20844
|
+
void 0,
|
|
20845
|
+
void 0,
|
|
20846
|
+
confJoin(confJoin(a.conf, b.conf), "path")
|
|
20847
|
+
);
|
|
20848
|
+
}
|
|
20849
|
+
function subNumeric(a, b) {
|
|
20850
|
+
const va = litValue(a);
|
|
20851
|
+
const vb = litValue(b);
|
|
20852
|
+
if (typeof va === "bigint" && typeof vb === "bigint") return bigintLit(va - vb);
|
|
20853
|
+
if (typeof va === "number" && typeof vb === "number") return numLit(va - vb);
|
|
20854
|
+
const big = a.shape.k === "prim" && a.shape.type === "bigint" || typeof va === "bigint";
|
|
20855
|
+
return abs(
|
|
20856
|
+
{ k: "prim", type: big ? "bigint" : "number" },
|
|
20857
|
+
void 0,
|
|
20858
|
+
void 0,
|
|
20859
|
+
confJoin(confJoin(a.conf, b.conf), "path")
|
|
20860
|
+
);
|
|
20861
|
+
}
|
|
20617
20862
|
function toNumberAbs(a) {
|
|
20618
20863
|
const v2 = litValue(a);
|
|
20619
|
-
if (typeof v2 === "bigint") {
|
|
20620
|
-
|
|
20864
|
+
if (typeof v2 === "bigint" || isBigPrim(a)) {
|
|
20865
|
+
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
20621
20866
|
}
|
|
20622
20867
|
if (coercibleNumberLit(v2)) {
|
|
20623
20868
|
return abs({ k: "prim", type: "number" }, lit(Number(v2)), pTrue, "exact");
|
|
@@ -20881,6 +21126,8 @@ var init_surface = __esm({
|
|
|
20881
21126
|
init_symbol_id();
|
|
20882
21127
|
init_term();
|
|
20883
21128
|
init_pred();
|
|
21129
|
+
init_nudo_throw();
|
|
21130
|
+
init_may_throw();
|
|
20884
21131
|
}
|
|
20885
21132
|
});
|
|
20886
21133
|
|
|
@@ -20931,6 +21178,14 @@ function toStringArg(x) {
|
|
|
20931
21178
|
function isUndefinedArg(x) {
|
|
20932
21179
|
return x === void 0 || x.term?.op === "lit" && x.term.value === void 0;
|
|
20933
21180
|
}
|
|
21181
|
+
function toUint32Limit(v2) {
|
|
21182
|
+
if (typeof v2 === "bigint" || typeof v2 === "symbol") return void 0;
|
|
21183
|
+
const n = Number(v2);
|
|
21184
|
+
if (!Number.isFinite(n) || n === 0) return 0;
|
|
21185
|
+
const int = Math.trunc(n);
|
|
21186
|
+
const mod2 = int % 4294967296;
|
|
21187
|
+
return mod2 < 0 ? mod2 + 4294967296 : mod2;
|
|
21188
|
+
}
|
|
20934
21189
|
function callAbsMethod(recv, name, args) {
|
|
20935
21190
|
if (!isStrRecv(recv)) return void 0;
|
|
20936
21191
|
const a0 = args[0] ? litValue(args[0]) : void 0;
|
|
@@ -21003,7 +21258,9 @@ function callAbsMethod(recv, name, args) {
|
|
|
21003
21258
|
if (name === "slice") {
|
|
21004
21259
|
return strLit(lit3.slice(a0, a1));
|
|
21005
21260
|
}
|
|
21006
|
-
|
|
21261
|
+
const start = toIntegerOrInfinityLit(args[0]) ?? 0;
|
|
21262
|
+
const end = isUndefinedArg(args[1]) ? lit3.length : toIntegerOrInfinityLit(args[1]) ?? 0;
|
|
21263
|
+
return strLit(lit3.substring(start, end));
|
|
21007
21264
|
}
|
|
21008
21265
|
return strPrim("path");
|
|
21009
21266
|
case "charAt": {
|
|
@@ -21057,8 +21314,9 @@ function callAbsMethod(recv, name, args) {
|
|
|
21057
21314
|
if (isUndefinedArg(args[0])) {
|
|
21058
21315
|
const one = abs({ k: "tuple", elements: [strLit(lit3)] }, void 0, void 0, "exact");
|
|
21059
21316
|
if (lim === void 0) return one;
|
|
21060
|
-
const n =
|
|
21061
|
-
if (
|
|
21317
|
+
const n = toUint32Limit(lim);
|
|
21318
|
+
if (n === void 0) return strArr("path");
|
|
21319
|
+
if (n === 0) return abs({ k: "tuple", elements: [] }, void 0, void 0, "exact");
|
|
21062
21320
|
return one;
|
|
21063
21321
|
}
|
|
21064
21322
|
const sep5 = toStringArg(args[0]);
|
|
@@ -21268,7 +21526,12 @@ function mergeInstanceFields(instance, fields, className) {
|
|
|
21268
21526
|
const fieldObj = fields.shape.k === "brand" ? fields.shape.shape : fields;
|
|
21269
21527
|
if (fieldObj.shape.k === "obj") {
|
|
21270
21528
|
for (const [k, s] of Object.entries(fieldObj.shape.slots)) {
|
|
21271
|
-
slots
|
|
21529
|
+
Object.defineProperty(slots, k, {
|
|
21530
|
+
value: s,
|
|
21531
|
+
enumerable: true,
|
|
21532
|
+
writable: true,
|
|
21533
|
+
configurable: true
|
|
21534
|
+
});
|
|
21272
21535
|
}
|
|
21273
21536
|
}
|
|
21274
21537
|
return abs(
|
|
@@ -21427,15 +21690,23 @@ function classFromMethods(name, methods2, superClass, superShape) {
|
|
|
21427
21690
|
const slots = {};
|
|
21428
21691
|
if (superShape?.shape.k === "obj") {
|
|
21429
21692
|
for (const [k, s] of Object.entries(superShape.shape.slots)) {
|
|
21430
|
-
slots
|
|
21693
|
+
Object.defineProperty(slots, k, {
|
|
21694
|
+
value: s,
|
|
21695
|
+
enumerable: true,
|
|
21696
|
+
writable: true,
|
|
21697
|
+
configurable: true
|
|
21698
|
+
});
|
|
21431
21699
|
}
|
|
21432
21700
|
}
|
|
21433
21701
|
for (const m of methods2) {
|
|
21434
21702
|
methodMap.set(m.name, m);
|
|
21435
21703
|
if (m.kind !== "constructor") {
|
|
21436
|
-
slots
|
|
21437
|
-
value: abs({ k: "fn", params: m.params, name: m.name }, void 0, void 0, "exact")
|
|
21438
|
-
|
|
21704
|
+
Object.defineProperty(slots, m.name, {
|
|
21705
|
+
value: abs({ k: "fn", params: m.params, name: m.name }, void 0, void 0, "exact"),
|
|
21706
|
+
enumerable: true,
|
|
21707
|
+
writable: true,
|
|
21708
|
+
configurable: true
|
|
21709
|
+
});
|
|
21439
21710
|
}
|
|
21440
21711
|
}
|
|
21441
21712
|
return {
|
|
@@ -21515,21 +21786,21 @@ function leqAbs(src, tgt, opts = {}) {
|
|
|
21515
21786
|
function leqWithPred(src, tgt, phi2, env2, depth) {
|
|
21516
21787
|
if (depth > 32) return fail("leq depth exceeded");
|
|
21517
21788
|
if (src.shape.k === "never") return ok();
|
|
21518
|
-
|
|
21519
|
-
|
|
21520
|
-
|
|
21521
|
-
|
|
21522
|
-
|
|
21523
|
-
|
|
21789
|
+
const srcLitTerm = src.term?.op === "lit" ? src.term : void 0;
|
|
21790
|
+
const tgtLitTerm = tgt.term?.op === "lit" ? tgt.term : void 0;
|
|
21791
|
+
if (tgtLitTerm && srcLitTerm) {
|
|
21792
|
+
const sv = srcLitTerm.value;
|
|
21793
|
+
const tv = tgtLitTerm.value;
|
|
21794
|
+
const sameLit = sv === tv || typeof sv === "number" && typeof tv === "number" && Number.isNaN(sv) && Number.isNaN(tv);
|
|
21524
21795
|
if (sameLit) return ok();
|
|
21525
|
-
|
|
21526
|
-
|
|
21527
|
-
|
|
21528
|
-
|
|
21529
|
-
|
|
21530
|
-
return fail(`non-lit prim \u22AD lit ${String(tv)}`);
|
|
21531
|
-
}
|
|
21796
|
+
return fail(`lit ${String(sv)} \u22AD lit ${String(tv)}`);
|
|
21797
|
+
}
|
|
21798
|
+
if (tgtLitTerm && !srcLitTerm) {
|
|
21799
|
+
if (src.shape.k === "any") return ok();
|
|
21800
|
+
return fail(`non-lit \u22AD lit ${String(tgtLitTerm.value)}`);
|
|
21532
21801
|
}
|
|
21802
|
+
if (tgt.shape.k === "any" || tgt.shape.k === "unknown") return ok();
|
|
21803
|
+
if (src.shape.k === "any") return ok();
|
|
21533
21804
|
const shapeR = leqShape(src, tgt, phi2, env2, depth);
|
|
21534
21805
|
if (!shapeR.ok) return shapeR;
|
|
21535
21806
|
return leqPred(src, tgt, phi2, depth);
|
|
@@ -21754,12 +22025,16 @@ function formatShape(a) {
|
|
|
21754
22025
|
case "any":
|
|
21755
22026
|
return "any";
|
|
21756
22027
|
case "unknown": {
|
|
21757
|
-
if (a.term?.op === "lit"
|
|
22028
|
+
if (a.term?.op === "lit") {
|
|
22029
|
+
if (a.term.value === void 0) return "undefined";
|
|
22030
|
+
if (a.term.value === null) return "null";
|
|
22031
|
+
}
|
|
21758
22032
|
return "unknown";
|
|
21759
22033
|
}
|
|
21760
22034
|
case "prim": {
|
|
21761
22035
|
const lv = litValue(a);
|
|
21762
22036
|
if (typeof lv === "number" && !Number.isFinite(lv)) return String(lv);
|
|
22037
|
+
if (typeof lv === "number" && Object.is(lv, -0)) return "-0";
|
|
21763
22038
|
if (typeof lv === "bigint") return `${String(lv)}n`;
|
|
21764
22039
|
if (lv !== void 0) return JSON.stringify(lv);
|
|
21765
22040
|
return s.type;
|
|
@@ -24557,7 +24832,12 @@ function litAbsFromJs(v2, depth = 0) {
|
|
|
24557
24832
|
if (proto === Object.prototype || proto === null) {
|
|
24558
24833
|
const slots = {};
|
|
24559
24834
|
for (const [k, val] of Object.entries(v2)) {
|
|
24560
|
-
slots
|
|
24835
|
+
Object.defineProperty(slots, k, {
|
|
24836
|
+
value: { value: litAbsFromJs(val, depth + 1) },
|
|
24837
|
+
enumerable: true,
|
|
24838
|
+
writable: true,
|
|
24839
|
+
configurable: true
|
|
24840
|
+
});
|
|
24561
24841
|
}
|
|
24562
24842
|
return objOf(slots);
|
|
24563
24843
|
}
|
|
@@ -24810,6 +25090,15 @@ function $pow(a, b) {
|
|
|
24810
25090
|
function $toNumber(a) {
|
|
24811
25091
|
return toNumberAbs(a);
|
|
24812
25092
|
}
|
|
25093
|
+
function $toNumeric(a) {
|
|
25094
|
+
return toNumericAbs(a);
|
|
25095
|
+
}
|
|
25096
|
+
function $updateAdd(a) {
|
|
25097
|
+
return updateAddAbs(a);
|
|
25098
|
+
}
|
|
25099
|
+
function $updateSub(a) {
|
|
25100
|
+
return updateSubAbs(a);
|
|
25101
|
+
}
|
|
24813
25102
|
function $neg(a) {
|
|
24814
25103
|
return negAbs(a);
|
|
24815
25104
|
}
|
|
@@ -25791,7 +26080,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
|
|
|
25791
26080
|
}
|
|
25792
26081
|
if (node.type === "UpdateExpression" && node.argument) {
|
|
25793
26082
|
const arg = node.argument;
|
|
25794
|
-
const fn2 = node.operator === "++" ? "$
|
|
26083
|
+
const fn2 = node.operator === "++" ? "$updateAdd" : "$updateSub";
|
|
25795
26084
|
if (arg.type === "MemberExpression") {
|
|
25796
26085
|
const path = memberPathOf(
|
|
25797
26086
|
arg,
|
|
@@ -25799,7 +26088,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
|
|
|
25799
26088
|
);
|
|
25800
26089
|
if (path) {
|
|
25801
26090
|
const readSrc = readPathSrc(path);
|
|
25802
|
-
lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${fn2}(${readSrc}
|
|
26091
|
+
lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${fn2}(${readSrc})`)};`);
|
|
25803
26092
|
}
|
|
25804
26093
|
}
|
|
25805
26094
|
}
|
|
@@ -26553,7 +26842,7 @@ ${pad}export default ${name};`;
|
|
|
26553
26842
|
const stepPart = (u) => {
|
|
26554
26843
|
const upd = u;
|
|
26555
26844
|
if (upd.type === "UpdateExpression" && upd.argument?.type === "Identifier" && upd.argument.name) {
|
|
26556
|
-
return `${upd.argument.name} = ${upd.operator === "++" ? "$
|
|
26845
|
+
return `${upd.argument.name} = ${upd.operator === "++" ? "$updateAdd" : "$updateSub"}(${upd.argument.name})`;
|
|
26557
26846
|
}
|
|
26558
26847
|
if (upd.type === "SequenceExpression") {
|
|
26559
26848
|
return (upd.expressions ?? []).map((e) => stepPart(e)).join(", ");
|
|
@@ -27286,6 +27575,128 @@ function transpileShortCircuitExpr(opts, parts) {
|
|
|
27286
27575
|
`})()`
|
|
27287
27576
|
].join("\n");
|
|
27288
27577
|
}
|
|
27578
|
+
function isChainLink(n) {
|
|
27579
|
+
return n.type === "MemberExpression" || n.type === "OptionalMemberExpression" || n.type === "CallExpression" || n.type === "OptionalCallExpression";
|
|
27580
|
+
}
|
|
27581
|
+
function linkIsOptional(n) {
|
|
27582
|
+
return n.optional === true;
|
|
27583
|
+
}
|
|
27584
|
+
function chainNeedsShortCircuit(n) {
|
|
27585
|
+
let cur = n;
|
|
27586
|
+
while (isChainLink(cur)) {
|
|
27587
|
+
if (linkIsOptional(cur)) return true;
|
|
27588
|
+
cur = cur.callee ?? cur.object;
|
|
27589
|
+
}
|
|
27590
|
+
return false;
|
|
27591
|
+
}
|
|
27592
|
+
function flattenChain(expr, opts) {
|
|
27593
|
+
const hops = [];
|
|
27594
|
+
let cur = expr;
|
|
27595
|
+
while (isChainLink(cur)) {
|
|
27596
|
+
const optional = linkIsOptional(cur);
|
|
27597
|
+
if (cur.type === "CallExpression" || cur.type === "OptionalCallExpression") {
|
|
27598
|
+
const args = (cur.arguments ?? []).map(
|
|
27599
|
+
(a) => a.type === "SpreadElement" ? "$unknown()" : transpileExpression(a, opts)
|
|
27600
|
+
).join(", ");
|
|
27601
|
+
const loc = cur.loc;
|
|
27602
|
+
const locArg = loc ? `, [${loc.start.line}, ${loc.start.column}]` : "";
|
|
27603
|
+
const callee = cur.callee;
|
|
27604
|
+
const calleeProp = callee?.property;
|
|
27605
|
+
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;
|
|
27606
|
+
if (callee && methodName !== void 0) {
|
|
27607
|
+
const recvNode = callee.object;
|
|
27608
|
+
hops.unshift({
|
|
27609
|
+
kind: "invoke",
|
|
27610
|
+
method: JSON.stringify(methodName),
|
|
27611
|
+
argsSrc: `[${args}]`,
|
|
27612
|
+
locArg,
|
|
27613
|
+
recvOptional: linkIsOptional(callee),
|
|
27614
|
+
fnOptional: linkIsOptional(cur),
|
|
27615
|
+
recvName: recvNode?.type === "Identifier" && recvNode.name ? recvNode.name : void 0
|
|
27616
|
+
});
|
|
27617
|
+
cur = callee.object;
|
|
27618
|
+
continue;
|
|
27619
|
+
}
|
|
27620
|
+
hops.unshift({ kind: "call", argsSrc: `[${args}]`, optional: linkIsOptional(cur), locArg });
|
|
27621
|
+
cur = cur.callee ?? cur.object;
|
|
27622
|
+
continue;
|
|
27623
|
+
}
|
|
27624
|
+
const optionalM = optional;
|
|
27625
|
+
if (cur.computed) {
|
|
27626
|
+
const key = cur.property;
|
|
27627
|
+
if (key?.type === "StringLiteral") {
|
|
27628
|
+
hops.unshift({ kind: "get", key: JSON.stringify(key.value), optional: optionalM });
|
|
27629
|
+
} else if (key?.type === "NumericLiteral") {
|
|
27630
|
+
hops.unshift({ kind: "idx", keySrc: `$lit(${key.value})`, optional: optionalM });
|
|
27631
|
+
} else if (isExpression(cur.property)) {
|
|
27632
|
+
hops.unshift({
|
|
27633
|
+
kind: "idx",
|
|
27634
|
+
keySrc: transpileExpression(cur.property, opts),
|
|
27635
|
+
optional: optionalM
|
|
27636
|
+
});
|
|
27637
|
+
} else {
|
|
27638
|
+
return void 0;
|
|
27639
|
+
}
|
|
27640
|
+
cur = cur.object;
|
|
27641
|
+
continue;
|
|
27642
|
+
}
|
|
27643
|
+
const prop = cur.property;
|
|
27644
|
+
if (prop?.type !== "Identifier") return void 0;
|
|
27645
|
+
if (prop.name === "length") {
|
|
27646
|
+
hops.unshift({ kind: "len", optional: optionalM });
|
|
27647
|
+
} else {
|
|
27648
|
+
hops.unshift({ kind: "get", key: JSON.stringify(prop.name), optional: optionalM });
|
|
27649
|
+
}
|
|
27650
|
+
cur = cur.object;
|
|
27651
|
+
}
|
|
27652
|
+
if (cur.type === "Super") return void 0;
|
|
27653
|
+
const baseSrc = isExpression(cur) ? transpileExpression(cur, opts) : void 0;
|
|
27654
|
+
if (baseSrc === void 0) return void 0;
|
|
27655
|
+
return { baseSrc, hops };
|
|
27656
|
+
}
|
|
27657
|
+
function emitChainFrom(hops, i, valSrc) {
|
|
27658
|
+
if (i >= hops.length) return valSrc;
|
|
27659
|
+
const hop = hops[i];
|
|
27660
|
+
const rest = (recv) => emitChainFrom(hops, i + 1, recv);
|
|
27661
|
+
switch (hop.kind) {
|
|
27662
|
+
case "get":
|
|
27663
|
+
return hop.optional ? shortCircuitHop(valSrc, `$get($__oc, ${hop.key})`, hops, i) : rest(`$get(${valSrc}, ${hop.key})`);
|
|
27664
|
+
case "idx":
|
|
27665
|
+
return hop.optional ? shortCircuitHop(valSrc, `$idx($__oc, ${hop.keySrc})`, hops, i) : rest(`$idx(${valSrc}, ${hop.keySrc})`);
|
|
27666
|
+
case "len":
|
|
27667
|
+
return hop.optional ? shortCircuitHop(valSrc, `$len($__oc)`, hops, i) : rest(`$len(${valSrc})`);
|
|
27668
|
+
case "call":
|
|
27669
|
+
return hop.optional ? shortCircuitHop(valSrc, `$callNamed("call", $__oc, ${hop.argsSrc}${hop.locArg})`, hops, i) : rest(`$callNamed("call", ${valSrc}, ${hop.argsSrc}${hop.locArg})`);
|
|
27670
|
+
case "invoke": {
|
|
27671
|
+
const invokeOf = (recv, fnCheck) => {
|
|
27672
|
+
let call = `$invoke(${recv}, ${hop.method}, ${hop.argsSrc}${hop.locArg})`;
|
|
27673
|
+
const rawMethod = JSON.parse(hop.method);
|
|
27674
|
+
if (hop.recvName && REGEX_STATEFUL_NAMES.has(rawMethod)) {
|
|
27675
|
+
call = `(() => { const __v = ${call}; ${hop.recvName} = $reStateCall(${hop.recvName}, ${hop.method}, ${hop.argsSrc}); return __v; })()`;
|
|
27676
|
+
}
|
|
27677
|
+
if (!fnCheck) return call;
|
|
27678
|
+
return `(($__fn) => $fork($nullishTest($__fn), () => $lit(undefined), () => ${call}))($get(${recv}, ${hop.method}))`;
|
|
27679
|
+
};
|
|
27680
|
+
if (hop.recvOptional) {
|
|
27681
|
+
return shortCircuitHop(valSrc, invokeOf("$__oc", hop.fnOptional), hops, i);
|
|
27682
|
+
}
|
|
27683
|
+
return rest(invokeOf(valSrc, hop.fnOptional));
|
|
27684
|
+
}
|
|
27685
|
+
}
|
|
27686
|
+
}
|
|
27687
|
+
function shortCircuitHop(valSrc, appliedWithOc, hops, i) {
|
|
27688
|
+
return `(($__oc) => $fork($nullishTest($__oc), () => $lit(undefined), () => ${emitChainFrom(hops, i + 1, appliedWithOc)}))(${valSrc})`;
|
|
27689
|
+
}
|
|
27690
|
+
function tryTranspileOptionalChain(expr, opts) {
|
|
27691
|
+
const t = expr.type;
|
|
27692
|
+
if (t !== "MemberExpression" && t !== "OptionalMemberExpression" && t !== "CallExpression" && t !== "OptionalCallExpression") {
|
|
27693
|
+
return void 0;
|
|
27694
|
+
}
|
|
27695
|
+
if (!chainNeedsShortCircuit(expr)) return void 0;
|
|
27696
|
+
const flat = flattenChain(expr, opts);
|
|
27697
|
+
if (!flat) return void 0;
|
|
27698
|
+
return emitChainFrom(flat.hops, 0, flat.baseSrc);
|
|
27699
|
+
}
|
|
27289
27700
|
function transpileExpression(expr, opts = {}) {
|
|
27290
27701
|
const rep = matchReplacement(expr, opts);
|
|
27291
27702
|
if (rep) return rep;
|
|
@@ -27293,6 +27704,8 @@ function transpileExpression(expr, opts = {}) {
|
|
|
27293
27704
|
if (anyExpr.type === "ChainExpression" && anyExpr.expression) {
|
|
27294
27705
|
return transpileExpression(anyExpr.expression, opts);
|
|
27295
27706
|
}
|
|
27707
|
+
const chainSrc = tryTranspileOptionalChain(expr, opts);
|
|
27708
|
+
if (chainSrc !== void 0) return chainSrc;
|
|
27296
27709
|
if (anyExpr.type === "Super") {
|
|
27297
27710
|
return `/* super */`;
|
|
27298
27711
|
}
|
|
@@ -27413,19 +27826,18 @@ function transpileExpression(expr, opts = {}) {
|
|
|
27413
27826
|
}
|
|
27414
27827
|
case "UpdateExpression": {
|
|
27415
27828
|
const arg = expr.argument;
|
|
27416
|
-
const fn2 = expr.operator === "++" ? "$
|
|
27417
|
-
const undo = expr.operator === "++" ? "$sub" : "$add";
|
|
27829
|
+
const fn2 = expr.operator === "++" ? "$updateAdd" : "$updateSub";
|
|
27418
27830
|
if (arg.type === "Identifier") {
|
|
27419
|
-
if (expr.prefix) return `${arg.name} = ${fn2}(${arg.name}
|
|
27420
|
-
return `(${arg.name} = ${fn2}(
|
|
27831
|
+
if (expr.prefix) return `${arg.name} = ${fn2}(${arg.name})`;
|
|
27832
|
+
return `((__old) => (${arg.name} = ${fn2}(__old), __old))($toNumeric(${arg.name}))`;
|
|
27421
27833
|
}
|
|
27422
27834
|
if (arg.type === "MemberExpression") {
|
|
27423
27835
|
const m = arg;
|
|
27424
27836
|
const path = memberPathOf(m, opts);
|
|
27425
27837
|
if (path) {
|
|
27426
27838
|
const readSrc = readPathSrc(path);
|
|
27427
|
-
if (expr.prefix) return `${fn2}(${readSrc}
|
|
27428
|
-
return readSrc
|
|
27839
|
+
if (expr.prefix) return `${fn2}(${readSrc})`;
|
|
27840
|
+
return `$toNumeric(${readSrc})`;
|
|
27429
27841
|
}
|
|
27430
27842
|
}
|
|
27431
27843
|
return `/* update ${expr.operator} */ $lit(undefined)`;
|
|
@@ -27459,6 +27871,7 @@ function transpileExpression(expr, opts = {}) {
|
|
|
27459
27871
|
let acc = null;
|
|
27460
27872
|
const props = [];
|
|
27461
27873
|
const accRegs = [];
|
|
27874
|
+
let protoSet = null;
|
|
27462
27875
|
const flushProps = () => {
|
|
27463
27876
|
if (props.length === 0) return;
|
|
27464
27877
|
const obj2 = `$obj({ ${props.join(", ")} })`;
|
|
@@ -27480,6 +27893,7 @@ function transpileExpression(expr, opts = {}) {
|
|
|
27480
27893
|
return symbolKeyOf(prop.key);
|
|
27481
27894
|
})();
|
|
27482
27895
|
if (mkey === null) continue;
|
|
27896
|
+
const isProtoKey = mkey === '"__proto__"';
|
|
27483
27897
|
const displayNames = paramDisplayNames(prop.params);
|
|
27484
27898
|
const bindNames = methodBindNames(prop.params);
|
|
27485
27899
|
const mHasArgs = fnBodyHasOwnArguments({ body: prop.body });
|
|
@@ -27491,7 +27905,12 @@ function transpileExpression(expr, opts = {}) {
|
|
|
27491
27905
|
argsBinding: mHasArgs ? "__nudoArgs" : void 0
|
|
27492
27906
|
};
|
|
27493
27907
|
if (prop.kind === "get" || prop.kind === "set") {
|
|
27494
|
-
|
|
27908
|
+
const slotSrc = `${mkey}: $lit(undefined)`;
|
|
27909
|
+
if (isProtoKey) {
|
|
27910
|
+
acc = `$setKey(${acc ?? "$obj({})"}, $lit("__proto__"), $lit(undefined))`;
|
|
27911
|
+
} else {
|
|
27912
|
+
props.push(slotSrc);
|
|
27913
|
+
}
|
|
27495
27914
|
if (prop.kind === "get") {
|
|
27496
27915
|
const bodySrc2 = `{
|
|
27497
27916
|
${emitFnBlockBody(prop.body, 1, methodOpts)}
|
|
@@ -27524,7 +27943,11 @@ return __this;
|
|
|
27524
27943
|
${mBodyInner}
|
|
27525
27944
|
}`;
|
|
27526
27945
|
const fnValSrc = `$fnVal([${displayNames.map((p) => JSON.stringify(p)).join(", ")}], (${mParams.join(", ")}) => ${bodySrc}, { bindThis: true })`;
|
|
27527
|
-
|
|
27946
|
+
if (isProtoKey) {
|
|
27947
|
+
acc = `$setKey(${acc ?? "$obj({})"}, $lit("__proto__"), ${fnValSrc})`;
|
|
27948
|
+
} else {
|
|
27949
|
+
props.push(`${mkey}: ${fnValSrc}`);
|
|
27950
|
+
}
|
|
27528
27951
|
continue;
|
|
27529
27952
|
}
|
|
27530
27953
|
if (prop.type !== "ObjectProperty") continue;
|
|
@@ -27546,6 +27969,10 @@ ${mBodyInner}
|
|
|
27546
27969
|
return k === null ? null : JSON.stringify(k);
|
|
27547
27970
|
})();
|
|
27548
27971
|
if (key === null) continue;
|
|
27972
|
+
if (!prop.computed && key === '"__proto__"') {
|
|
27973
|
+
protoSet = transpileExpression(prop.value, opts);
|
|
27974
|
+
continue;
|
|
27975
|
+
}
|
|
27549
27976
|
if (prop.value.type === "FunctionExpression" && !prop.value.async) {
|
|
27550
27977
|
const fn2 = prop.value;
|
|
27551
27978
|
if (!fn2.generator) {
|
|
@@ -27586,6 +28013,7 @@ ${mBodyInner}
|
|
|
27586
28013
|
for (const r of accRegs) {
|
|
27587
28014
|
result = `$objAccessor(${result}, ${r.key}, ${r.get ?? "null"}, ${r.set ?? "null"})`;
|
|
27588
28015
|
}
|
|
28016
|
+
if (protoSet !== null) result = `$setProto(${result}, ${protoSet})`;
|
|
27589
28017
|
return result;
|
|
27590
28018
|
}
|
|
27591
28019
|
case "MemberExpression":
|
|
@@ -27936,13 +28364,13 @@ function transpileSource(source, opts = {}) {
|
|
|
27936
28364
|
return transpileFile(file, { ...opts, source: opts.source ?? source });
|
|
27937
28365
|
}
|
|
27938
28366
|
function runtimeImportOf(runtime) {
|
|
27939
|
-
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)};`;
|
|
28367
|
+
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)};`;
|
|
27940
28368
|
}
|
|
27941
28369
|
function transpileFile(file, opts = {}) {
|
|
27942
28370
|
const runtime = opts.runtimeImport ?? "@nudojs/core/exec";
|
|
27943
28371
|
const lines = [
|
|
27944
28372
|
`// nudo evaluator transpile \u2014 values are Abs; operators are overloaded calls`,
|
|
27945
|
-
`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)};`,
|
|
28373
|
+
`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)};`,
|
|
27946
28374
|
``
|
|
27947
28375
|
];
|
|
27948
28376
|
for (const stmt of file.program.body) {
|
|
@@ -28413,10 +28841,11 @@ function $in(key, o) {
|
|
|
28413
28841
|
if (o.shape.k === "prim" || o.shape.k === "never" || isNullishLitAbs(o)) {
|
|
28414
28842
|
return unknown;
|
|
28415
28843
|
}
|
|
28416
|
-
const
|
|
28417
|
-
if (
|
|
28418
|
-
return
|
|
28844
|
+
const keyStr = propertyKeyOf(key);
|
|
28845
|
+
if (keyStr === void 0) {
|
|
28846
|
+
return bool();
|
|
28419
28847
|
}
|
|
28848
|
+
const kv = keyStr;
|
|
28420
28849
|
if (o.shape.k === "tuple") {
|
|
28421
28850
|
if (kv === "length") return boolLit(true);
|
|
28422
28851
|
const idx = canonicalArrayIndex(kv);
|
|
@@ -28427,8 +28856,6 @@ function $in(key, o) {
|
|
|
28427
28856
|
return boolLit(false);
|
|
28428
28857
|
}
|
|
28429
28858
|
if (o.shape.k === "arr") return bool();
|
|
28430
|
-
const keyStr = typeof kv === "number" ? String(kv) : typeof kv === "string" ? kv : void 0;
|
|
28431
|
-
if (keyStr === void 0) return bool();
|
|
28432
28859
|
if (o.shape.k === "obj" || o.shape.k === "brand") {
|
|
28433
28860
|
const objShape = o.shape.k === "brand" ? o.shape.shape.shape.k === "obj" ? o.shape.shape.shape : void 0 : o.shape;
|
|
28434
28861
|
if (!objShape) return bool();
|
|
@@ -28445,6 +28872,9 @@ function $in(key, o) {
|
|
|
28445
28872
|
return boolLit(OBJECT_PROTO_NAMES.has(keyStr));
|
|
28446
28873
|
}
|
|
28447
28874
|
if (o.shape.k === "fn") {
|
|
28875
|
+
if (o.shape.slots && getSlot(o.shape.slots, keyStr) && !o.shape.slots[keyStr].optional) {
|
|
28876
|
+
return boolLit(true);
|
|
28877
|
+
}
|
|
28448
28878
|
return boolLit(OBJECT_PROTO_NAMES.has(keyStr) || FUNCTION_PROTO_NAMES.has(keyStr));
|
|
28449
28879
|
}
|
|
28450
28880
|
if (o.shape.k === "eff") {
|
|
@@ -28586,7 +29016,7 @@ function $delRes(o, _key) {
|
|
|
28586
29016
|
return bool();
|
|
28587
29017
|
}
|
|
28588
29018
|
function $del(o, key) {
|
|
28589
|
-
const
|
|
29019
|
+
const keyStr = propertyKeyOf(key);
|
|
28590
29020
|
if (o.shape.k === "sum") {
|
|
28591
29021
|
return abs(
|
|
28592
29022
|
{ k: "sum", members: o.shape.members.map((m) => $del(m, key)) },
|
|
@@ -28605,7 +29035,6 @@ function $del(o, key) {
|
|
|
28605
29035
|
if (clsName) markClassValue(next, clsName);
|
|
28606
29036
|
return next;
|
|
28607
29037
|
}
|
|
28608
|
-
const keyStr = typeof kv === "number" ? String(kv) : typeof kv === "string" ? kv : void 0;
|
|
28609
29038
|
if (o.shape.k === "obj" && keyStr !== void 0) {
|
|
28610
29039
|
if (getPropFlags(o)?.get(keyStr)?.configurable === false) throwStrictWrite();
|
|
28611
29040
|
if (o.shape.open) return o;
|
|
@@ -28620,7 +29049,7 @@ function $del(o, key) {
|
|
|
28620
29049
|
return o;
|
|
28621
29050
|
}
|
|
28622
29051
|
if (o.shape.k === "tuple") {
|
|
28623
|
-
const idx = canonicalArrayIndex(
|
|
29052
|
+
const idx = canonicalArrayIndex(keyStr);
|
|
28624
29053
|
if (idx === void 0 || idx >= o.shape.elements.length) return o;
|
|
28625
29054
|
o.shape.elements[idx] = $lit(void 0);
|
|
28626
29055
|
if (!o.shape.holes) o.shape.holes = [];
|
|
@@ -28755,7 +29184,9 @@ function toIOI(v2) {
|
|
|
28755
29184
|
return Math.trunc(lv);
|
|
28756
29185
|
}
|
|
28757
29186
|
if (typeof lv === "string" || typeof lv === "boolean") {
|
|
28758
|
-
|
|
29187
|
+
const n = Number(lv);
|
|
29188
|
+
if (Number.isNaN(n)) return 0;
|
|
29189
|
+
return Math.trunc(n);
|
|
28759
29190
|
}
|
|
28760
29191
|
return null;
|
|
28761
29192
|
}
|
|
@@ -28783,7 +29214,7 @@ function copyWithinTuple(shape2, vals) {
|
|
|
28783
29214
|
if (win) {
|
|
28784
29215
|
const els = [...shape2.elements];
|
|
28785
29216
|
const holesSet = new Set(origHoles);
|
|
28786
|
-
const backwards =
|
|
29217
|
+
const backwards = win.s < win.t && win.s + (win.e - win.s) > win.t;
|
|
28787
29218
|
const count = win.e - win.s;
|
|
28788
29219
|
for (let kk = 0; kk < count; kk++) {
|
|
28789
29220
|
const k = backwards ? count - 1 - kk : kk;
|
|
@@ -28883,7 +29314,7 @@ function $copy(a) {
|
|
|
28883
29314
|
if (s.k === "obj") {
|
|
28884
29315
|
const slots = {};
|
|
28885
29316
|
for (const [k, v2] of Object.entries(s.slots)) {
|
|
28886
|
-
slots
|
|
29317
|
+
setSlot(slots, k, { ...v2, value: $copy(v2.value) });
|
|
28887
29318
|
}
|
|
28888
29319
|
const next = objOf(slots, {
|
|
28889
29320
|
index: s.index ? { key: $copy(s.index.key), value: $copy(s.index.value) } : void 0,
|
|
@@ -29023,7 +29454,8 @@ function $arrMutContainer(arr, method, args) {
|
|
|
29023
29454
|
}
|
|
29024
29455
|
function $idx(a, i) {
|
|
29025
29456
|
if (a?.shape?.k === "any") return anyMemberResult();
|
|
29026
|
-
const
|
|
29457
|
+
const keyStr = propertyKeyOf(i);
|
|
29458
|
+
const iv = keyStr !== void 0 ? keyStr : litValue(i);
|
|
29027
29459
|
const idx = iv !== void 0 ? canonicalArrayIndex(iv) : void 0;
|
|
29028
29460
|
if (a.shape.k === "tuple") {
|
|
29029
29461
|
const els = a.shape.elements;
|
|
@@ -29060,18 +29492,11 @@ function $idx(a, i) {
|
|
|
29060
29492
|
}
|
|
29061
29493
|
const sv = litValue(a);
|
|
29062
29494
|
if (typeof sv === "string") {
|
|
29063
|
-
if (
|
|
29064
|
-
|
|
29065
|
-
|
|
29066
|
-
|
|
29067
|
-
|
|
29068
|
-
pTrue,
|
|
29069
|
-
"exact"
|
|
29070
|
-
);
|
|
29071
|
-
}
|
|
29072
|
-
return undef();
|
|
29073
|
-
}
|
|
29074
|
-
return unknown;
|
|
29495
|
+
if (i.term?.op !== "lit") return unknown;
|
|
29496
|
+
const idx2 = canonicalArrayIndex(i.term.value);
|
|
29497
|
+
if (idx2 === void 0) return undef();
|
|
29498
|
+
if (idx2 < sv.length) return $lit(sv[idx2]);
|
|
29499
|
+
return undef();
|
|
29075
29500
|
}
|
|
29076
29501
|
return unknown;
|
|
29077
29502
|
}
|
|
@@ -29082,20 +29507,26 @@ function widenTupleToArr(els, holes, value) {
|
|
|
29082
29507
|
return { k: "arr", element: joined };
|
|
29083
29508
|
}
|
|
29084
29509
|
function $idxSet(a, i, value) {
|
|
29085
|
-
const
|
|
29086
|
-
|
|
29510
|
+
const pk = propertyKeyOf(i);
|
|
29511
|
+
const raw = i.term?.op === "lit" ? i.term.value : litValue(i);
|
|
29512
|
+
let numIdx;
|
|
29513
|
+
if (typeof raw === "number") numIdx = raw;
|
|
29514
|
+
else if (typeof raw === "bigint") numIdx = Number(raw);
|
|
29515
|
+
else if (pk !== void 0) numIdx = canonicalArrayIndex(pk);
|
|
29516
|
+
const iv = pk !== void 0 ? pk : litValue(i);
|
|
29517
|
+
if (a.shape.k === "tuple" && numIdx !== void 0 && Number.isInteger(numIdx) && numIdx >= 0) {
|
|
29087
29518
|
const st = extStateOf(a);
|
|
29088
29519
|
if (st === "frozen") throwStrictWrite();
|
|
29089
|
-
if ((st === "sealed" || st === "nonext") &&
|
|
29520
|
+
if ((st === "sealed" || st === "nonext") && numIdx >= a.shape.elements.length) {
|
|
29090
29521
|
throwStrictWrite();
|
|
29091
29522
|
}
|
|
29092
|
-
if (
|
|
29523
|
+
if (numIdx >= 4294967295) {
|
|
29093
29524
|
a.shape = widenTupleToArr(a.shape.elements, a.shape.holes, value);
|
|
29094
29525
|
a.conf = confJoin(a.conf, "path");
|
|
29095
29526
|
clearStaleTermPred(a);
|
|
29096
29527
|
return a;
|
|
29097
29528
|
}
|
|
29098
|
-
if (
|
|
29529
|
+
if (numIdx + 1 > TUPLE_MATERIALIZE_CAP) {
|
|
29099
29530
|
a.shape = widenTupleToArr(a.shape.elements, a.shape.holes, value);
|
|
29100
29531
|
a.conf = confJoin(a.conf, "path");
|
|
29101
29532
|
clearStaleTermPred(a);
|
|
@@ -29103,12 +29534,12 @@ function $idxSet(a, i, value) {
|
|
|
29103
29534
|
}
|
|
29104
29535
|
const els = [...a.shape.elements];
|
|
29105
29536
|
const holes = [...a.shape.holes ?? []];
|
|
29106
|
-
while (els.length <
|
|
29537
|
+
while (els.length < numIdx) {
|
|
29107
29538
|
holes.push(els.length);
|
|
29108
29539
|
els.push(undef());
|
|
29109
29540
|
}
|
|
29110
|
-
els[
|
|
29111
|
-
const hi = holes.indexOf(
|
|
29541
|
+
els[numIdx] = asAbsVal(value);
|
|
29542
|
+
const hi = holes.indexOf(numIdx);
|
|
29112
29543
|
if (hi >= 0) holes.splice(hi, 1);
|
|
29113
29544
|
a.shape = { k: "tuple", elements: els, holes: holes.length > 0 ? holes : void 0 };
|
|
29114
29545
|
clearStaleTermPred(a);
|
|
@@ -29172,6 +29603,9 @@ function $len(a) {
|
|
|
29172
29603
|
"exact"
|
|
29173
29604
|
);
|
|
29174
29605
|
}
|
|
29606
|
+
if (a.shape.k === "prim" && a.shape.type === "string") {
|
|
29607
|
+
return abs({ k: "prim", type: "number" }, void 0, void 0, "path");
|
|
29608
|
+
}
|
|
29175
29609
|
if (a.shape.k === "brand" && a.shape.name === "String") {
|
|
29176
29610
|
const inner = a.shape.shape;
|
|
29177
29611
|
if (inner.shape.k === "obj") {
|
|
@@ -29185,10 +29619,17 @@ function $len(a) {
|
|
|
29185
29619
|
return unknown;
|
|
29186
29620
|
}
|
|
29187
29621
|
function $obj(slots) {
|
|
29188
|
-
const s =
|
|
29189
|
-
for (const
|
|
29622
|
+
const s = /* @__PURE__ */ Object.create(null);
|
|
29623
|
+
for (const k of Object.keys(slots)) {
|
|
29624
|
+
setSlot(s, k, { value: asAbsVal(slots[k]) });
|
|
29625
|
+
}
|
|
29190
29626
|
return objOf(s);
|
|
29191
29627
|
}
|
|
29628
|
+
function $setProto(o, proto) {
|
|
29629
|
+
const next = setProtoAbs(o, proto);
|
|
29630
|
+
if (next !== o) clearStaleTermPred(o);
|
|
29631
|
+
return next;
|
|
29632
|
+
}
|
|
29192
29633
|
function $spread(a, b) {
|
|
29193
29634
|
let bb = asAbsVal(b);
|
|
29194
29635
|
const acc = bb && typeof bb === "object" ? accessorTable.get(bb) : void 0;
|
|
@@ -29197,7 +29638,7 @@ function $spread(a, b) {
|
|
|
29197
29638
|
const slots = { ...bb.shape.slots };
|
|
29198
29639
|
for (const [k, fn2] of acc) {
|
|
29199
29640
|
if (fn2.get) {
|
|
29200
|
-
slots
|
|
29641
|
+
setSlot(slots, k, { value: fn2.get(bb) });
|
|
29201
29642
|
changed = true;
|
|
29202
29643
|
}
|
|
29203
29644
|
}
|
|
@@ -29233,7 +29674,7 @@ function $objRest(o, keys) {
|
|
|
29233
29674
|
let openRest = o.shape.open === true;
|
|
29234
29675
|
for (const [k, s] of Object.entries(o.shape.slots)) {
|
|
29235
29676
|
if (drop.has(k)) continue;
|
|
29236
|
-
slots
|
|
29677
|
+
setSlot(slots, k, s);
|
|
29237
29678
|
}
|
|
29238
29679
|
if (o.shape.open) openRest = true;
|
|
29239
29680
|
const shape2 = { k: "obj", slots };
|
|
@@ -29344,7 +29785,7 @@ function $forInKeys(o) {
|
|
|
29344
29785
|
return k !== "" && String(n) === k && Number.isInteger(n) && n >= 0 && n < 4294967295;
|
|
29345
29786
|
};
|
|
29346
29787
|
if (shape2.k === "obj") {
|
|
29347
|
-
const keys =
|
|
29788
|
+
const keys = enumOwnKeys(o, shape2.slots);
|
|
29348
29789
|
const intKeys = keys.filter(isArrayIndexKey).sort((a, b) => Number(a) - Number(b));
|
|
29349
29790
|
const strKeys = keys.filter((k) => !isArrayIndexKey(k));
|
|
29350
29791
|
return $arr([...intKeys, ...strKeys].map((k) => $lit(k)));
|
|
@@ -29518,6 +29959,13 @@ function $get(o, key, opts) {
|
|
|
29518
29959
|
}
|
|
29519
29960
|
return $get(inner, key, opts);
|
|
29520
29961
|
}
|
|
29962
|
+
if (o.shape.k === "fn" && o.shape.slots) {
|
|
29963
|
+
const slot = getSlot(o.shape.slots, key);
|
|
29964
|
+
if (slot) {
|
|
29965
|
+
if (slot.optional) return joinAbs(slot.value, undef());
|
|
29966
|
+
return slot.value;
|
|
29967
|
+
}
|
|
29968
|
+
}
|
|
29521
29969
|
if ((o.shape.k === "tuple" || o.shape.k === "arr") && key === "length") {
|
|
29522
29970
|
return $len(o);
|
|
29523
29971
|
}
|
|
@@ -29527,6 +29975,16 @@ function $get(o, key, opts) {
|
|
|
29527
29975
|
if (idx !== void 0) return idx < els.length ? els[idx] : undef();
|
|
29528
29976
|
if (!isPossiblyProtoMemberKey(key)) return undef();
|
|
29529
29977
|
}
|
|
29978
|
+
if (o.shape.k === "prim" && o.shape.type === "string") {
|
|
29979
|
+
const idx = canonicalArrayIndex(key);
|
|
29980
|
+
const sv = litValue(o);
|
|
29981
|
+
if (idx !== void 0) {
|
|
29982
|
+
if (typeof sv === "string") return idx < sv.length ? $lit(sv[idx]) : undef();
|
|
29983
|
+
return abs({ k: "prim", type: "string" }, void 0, void 0, "path");
|
|
29984
|
+
}
|
|
29985
|
+
if (key === "length" && typeof sv === "string") return numLit(sv.length);
|
|
29986
|
+
if (!isPossiblyProtoMemberKey(key) && key !== "length") return undef();
|
|
29987
|
+
}
|
|
29530
29988
|
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")) {
|
|
29531
29989
|
if ((o.shape.k === "tuple" || o.shape.k === "arr") && (key === "toString" || key === "toLocaleString" || key === "join")) {
|
|
29532
29990
|
return arrayMethodAbs(key === "join" ? "join" : key);
|
|
@@ -29632,7 +30090,7 @@ function $set(o, key, value) {
|
|
|
29632
30090
|
throwStrictWrite();
|
|
29633
30091
|
}
|
|
29634
30092
|
if (getPropFlags(o)?.get(key)?.writable === false) throwStrictWrite();
|
|
29635
|
-
inner2.shape.slots
|
|
30093
|
+
setSlot(inner2.shape.slots, key, { value: asAbsVal(value) });
|
|
29636
30094
|
clearStaleTermPred(o);
|
|
29637
30095
|
return o;
|
|
29638
30096
|
}
|
|
@@ -29727,7 +30185,10 @@ function $set(o, key, value) {
|
|
|
29727
30185
|
if (!acc.set) throwStrictWrite();
|
|
29728
30186
|
return acc.set(o, value);
|
|
29729
30187
|
}
|
|
29730
|
-
|
|
30188
|
+
if (key === "__proto__" && !isNullProtoObj(o)) {
|
|
30189
|
+
return $setProto(o, value);
|
|
30190
|
+
}
|
|
30191
|
+
setSlot(shape2.slots, key, { value: asAbsVal(value) });
|
|
29731
30192
|
o.conf = confJoin(o.conf, value.conf);
|
|
29732
30193
|
clearStaleTermPred(o);
|
|
29733
30194
|
return o;
|
|
@@ -30384,6 +30845,7 @@ __export(runtime_exports, {
|
|
|
30384
30845
|
$regex: () => $regex,
|
|
30385
30846
|
$rethrowIfNudoReturn: () => $rethrowIfNudoReturn,
|
|
30386
30847
|
$set: () => $set,
|
|
30848
|
+
$setProto: () => $setProto,
|
|
30387
30849
|
$shl: () => $shl,
|
|
30388
30850
|
$shr: () => $shr,
|
|
30389
30851
|
$spread: () => $spread,
|
|
@@ -30391,6 +30853,7 @@ __export(runtime_exports, {
|
|
|
30391
30853
|
$switch: () => $switch,
|
|
30392
30854
|
$throw: () => $throw,
|
|
30393
30855
|
$toNumber: () => $toNumber,
|
|
30856
|
+
$toNumeric: () => $toNumeric,
|
|
30394
30857
|
$tryCurrentMark: () => $tryCurrentMark,
|
|
30395
30858
|
$tryDetachSoftCatch: () => $tryDetachSoftCatch,
|
|
30396
30859
|
$tryDigestSoftCatch: () => $tryDigestSoftCatch,
|
|
@@ -30403,6 +30866,8 @@ __export(runtime_exports, {
|
|
|
30403
30866
|
$tryTakeSince: () => $tryTakeSince,
|
|
30404
30867
|
$typeof: () => $typeof,
|
|
30405
30868
|
$unknown: () => $unknown,
|
|
30869
|
+
$updateAdd: () => $updateAdd,
|
|
30870
|
+
$updateSub: () => $updateSub,
|
|
30406
30871
|
$ushr: () => $ushr,
|
|
30407
30872
|
$while: () => $while,
|
|
30408
30873
|
$whileSeq: () => $whileSeq,
|
|
@@ -30880,9 +31345,9 @@ function $class(name, spec) {
|
|
|
30880
31345
|
registerEvalClass(full);
|
|
30881
31346
|
const slots = {};
|
|
30882
31347
|
if (spec.statics) {
|
|
30883
|
-
for (const [k, v2] of Object.entries(spec.statics)) slots
|
|
31348
|
+
for (const [k, v2] of Object.entries(spec.statics)) setSlot(slots, k, { value: asAbsVal(v2) });
|
|
30884
31349
|
}
|
|
30885
|
-
slots
|
|
31350
|
+
setSlot(slots, "name", { value: strLit(name) });
|
|
30886
31351
|
const val = abs(
|
|
30887
31352
|
{ k: "brand", name, shape: objOf(slots) },
|
|
30888
31353
|
void 0,
|
|
@@ -30924,11 +31389,9 @@ function $new(cls, args) {
|
|
|
30924
31389
|
if (cls && typeof cls === "object" && "shape" in cls) {
|
|
30925
31390
|
const cs = cls.shape;
|
|
30926
31391
|
const ctorName = cs.k === "brand" ? cs.name : builtinCtorNameOf(cls) ?? (cs.k === "fn" ? cs.name ?? void 0 : void 0);
|
|
30927
|
-
if (ctorName
|
|
30928
|
-
|
|
30929
|
-
|
|
30930
|
-
if (ctorName === "Promise") {
|
|
30931
|
-
return evalPromiseCtor(args);
|
|
31392
|
+
if (ctorName) {
|
|
31393
|
+
const built = evalBuiltinNew(ctorName, args);
|
|
31394
|
+
if (built !== void 0) return built;
|
|
30932
31395
|
}
|
|
30933
31396
|
}
|
|
30934
31397
|
if (typeof cls === "function") {
|
|
@@ -31041,6 +31504,7 @@ function runtimeAssignObject(args) {
|
|
|
31041
31504
|
const base = accObj.shape.slots;
|
|
31042
31505
|
const flags = getPropFlags(accObj);
|
|
31043
31506
|
for (const [k, s] of Object.entries(srcAbs.shape.slots)) {
|
|
31507
|
+
if (!isEnumerableView(srcAbs, k)) continue;
|
|
31044
31508
|
if ((st === "sealed" || st === "nonext") && !Object.prototype.hasOwnProperty.call(base, k)) {
|
|
31045
31509
|
throwStrictAssign();
|
|
31046
31510
|
}
|
|
@@ -31738,7 +32202,7 @@ function $thisSet(thisVal, key, value) {
|
|
|
31738
32202
|
if (thisVal.shape.k === "brand") {
|
|
31739
32203
|
const inner = thisVal.shape.shape;
|
|
31740
32204
|
const slots = inner.shape.k === "obj" ? { ...inner.shape.slots } : {};
|
|
31741
|
-
slots
|
|
32205
|
+
setSlot(slots, key, { value: asAbsVal(value) });
|
|
31742
32206
|
return abs(
|
|
31743
32207
|
{
|
|
31744
32208
|
k: "brand",
|
|
@@ -31827,9 +32291,19 @@ function $staticInvoke(cls, method, args) {
|
|
|
31827
32291
|
}
|
|
31828
32292
|
}
|
|
31829
32293
|
function $setKey(o, key, value) {
|
|
31830
|
-
const
|
|
32294
|
+
const pk = propertyKeyOf(key);
|
|
32295
|
+
const k = pk !== void 0 ? pk : litValue(key);
|
|
31831
32296
|
if (typeof k === "string" || typeof k === "number") {
|
|
31832
|
-
|
|
32297
|
+
const ks = String(k);
|
|
32298
|
+
if (ks === "__proto__" && o.shape.k === "obj") {
|
|
32299
|
+
setSlot(o.shape.slots, ks, {
|
|
32300
|
+
value: asAbsVal(value)
|
|
32301
|
+
});
|
|
32302
|
+
o.conf = confJoin(o.conf, value.conf);
|
|
32303
|
+
clearStaleTermPred(o);
|
|
32304
|
+
return o;
|
|
32305
|
+
}
|
|
32306
|
+
return $set(o, ks, value);
|
|
31833
32307
|
}
|
|
31834
32308
|
const val = asAbsVal(value);
|
|
31835
32309
|
if (o.shape.k === "brand") {
|
|
@@ -35858,8 +36332,11 @@ function widenForAssign(a) {
|
|
|
35858
36332
|
a.conf
|
|
35859
36333
|
);
|
|
35860
36334
|
}
|
|
35861
|
-
|
|
35862
|
-
|
|
36335
|
+
if (a.term?.op === "lit") {
|
|
36336
|
+
const lv = a.term.value;
|
|
36337
|
+
if (lv === null || lv === void 0) {
|
|
36338
|
+
return abs({ k: "unknown" }, void 0, void 0, a.conf);
|
|
36339
|
+
}
|
|
35863
36340
|
if (typeof lv === "number") {
|
|
35864
36341
|
return abs({ k: "prim", type: "number" }, void 0, void 0, a.conf);
|
|
35865
36342
|
}
|
|
@@ -37349,6 +37826,7 @@ __export(src_exports, {
|
|
|
37349
37826
|
$thisSet: () => $thisSet,
|
|
37350
37827
|
$throw: () => $throw,
|
|
37351
37828
|
$toNumber: () => $toNumber,
|
|
37829
|
+
$toNumeric: () => $toNumeric,
|
|
37352
37830
|
$tryCurrentMark: () => $tryCurrentMark,
|
|
37353
37831
|
$tryDetachSoftCatch: () => $tryDetachSoftCatch,
|
|
37354
37832
|
$tryDigestSoftCatch: () => $tryDigestSoftCatch,
|
|
@@ -37361,6 +37839,8 @@ __export(src_exports, {
|
|
|
37361
37839
|
$tryTakeSince: () => $tryTakeSince,
|
|
37362
37840
|
$typeof: () => $typeof,
|
|
37363
37841
|
$unknown: () => $unknown,
|
|
37842
|
+
$updateAdd: () => $updateAdd,
|
|
37843
|
+
$updateSub: () => $updateSub,
|
|
37364
37844
|
$ushr: () => $ushr,
|
|
37365
37845
|
$while: () => $while,
|
|
37366
37846
|
$whileSeq: () => $whileSeq,
|
|
@@ -37628,6 +38108,7 @@ __export(src_exports, {
|
|
|
37628
38108
|
primToTypeof: () => primToTypeof,
|
|
37629
38109
|
projectFlatMapResult: () => projectFlatMapResult,
|
|
37630
38110
|
promoteParamShape: () => promoteParamShape,
|
|
38111
|
+
propertyKeyOf: () => propertyKeyOf,
|
|
37631
38112
|
protoBrandAbs: () => protoBrandAbs,
|
|
37632
38113
|
protoOfRecv: () => protoOfRecv,
|
|
37633
38114
|
ptypeof: () => ptypeof,
|
|
@@ -46967,12 +47448,17 @@ function errorBrandOf(name) {
|
|
|
46967
47448
|
}
|
|
46968
47449
|
function envFn(paramTypes, returnType, apply, opts) {
|
|
46969
47450
|
const params = opts?.params ?? paramTypes.map((_, i) => paramTypes.length === 1 && i === 0 ? "x" : `x${i}`);
|
|
47451
|
+
const staticSlots = opts?.slots ? slotsOf(opts.slots) : void 0;
|
|
46970
47452
|
if (!apply) {
|
|
46971
|
-
|
|
47453
|
+
const a2 = relationFn(paramTypes, returnType, {
|
|
46972
47454
|
params,
|
|
46973
47455
|
conf: opts?.conf ?? "exact",
|
|
46974
47456
|
fingerprint: opts?.name ? `${opts.name}|${relationFingerprint(paramTypes, returnType)}` : void 0
|
|
46975
47457
|
});
|
|
47458
|
+
if (staticSlots) {
|
|
47459
|
+
a2.shape = { ...a2.shape, slots: staticSlots };
|
|
47460
|
+
}
|
|
47461
|
+
return a2;
|
|
46976
47462
|
}
|
|
46977
47463
|
const implApply = apply;
|
|
46978
47464
|
const a = absFunction(params, {
|
|
@@ -46991,7 +47477,8 @@ function envFn(paramTypes, returnType, apply, opts) {
|
|
|
46991
47477
|
params,
|
|
46992
47478
|
paramTypes,
|
|
46993
47479
|
returnType,
|
|
46994
|
-
...opts?.name ? { name: opts.name } : {}
|
|
47480
|
+
...opts?.name ? { name: opts.name } : {},
|
|
47481
|
+
...staticSlots ? { slots: staticSlots } : {}
|
|
46995
47482
|
};
|
|
46996
47483
|
if (opts?.conf && opts.conf !== "exact") a.conf = opts.conf;
|
|
46997
47484
|
return a;
|
|
@@ -47066,6 +47553,17 @@ function numImpl2Abs(fn2) {
|
|
|
47066
47553
|
return a !== void 0 && b !== void 0 ? numLit(fn2(a, b)) : void 0;
|
|
47067
47554
|
};
|
|
47068
47555
|
}
|
|
47556
|
+
function numImplVAbs(fn2) {
|
|
47557
|
+
return (args) => {
|
|
47558
|
+
const nums = [];
|
|
47559
|
+
for (const a of args) {
|
|
47560
|
+
const n = absNumLit(a);
|
|
47561
|
+
if (n === void 0) return void 0;
|
|
47562
|
+
nums.push(n);
|
|
47563
|
+
}
|
|
47564
|
+
return numLit(fn2(...nums));
|
|
47565
|
+
};
|
|
47566
|
+
}
|
|
47069
47567
|
function strToStrImplAbs(fn2) {
|
|
47070
47568
|
return (args) => {
|
|
47071
47569
|
const s = absStrLit(args[0]);
|
|
@@ -47163,6 +47661,18 @@ function defineEnv() {
|
|
|
47163
47661
|
if (a.term?.op === "lit") return boolLit(false);
|
|
47164
47662
|
return void 0;
|
|
47165
47663
|
};
|
|
47664
|
+
const numberImplAbs = (args) => {
|
|
47665
|
+
return evalGlobalFn("Number", args);
|
|
47666
|
+
};
|
|
47667
|
+
const arrayImplAbs = (args) => {
|
|
47668
|
+
return makeArrayCtorAbs(args);
|
|
47669
|
+
};
|
|
47670
|
+
const promiseCtorImplAbs = (args) => {
|
|
47671
|
+
return evalPromiseCtor(args);
|
|
47672
|
+
};
|
|
47673
|
+
const dateCtorImplAbs = (args) => {
|
|
47674
|
+
return evalDateCtor(args);
|
|
47675
|
+
};
|
|
47166
47676
|
const promiseResolveImplAbs = (args) => {
|
|
47167
47677
|
if (!args[0]) return void 0;
|
|
47168
47678
|
return promiseOf2(args[0]);
|
|
@@ -47184,8 +47694,18 @@ function defineEnv() {
|
|
|
47184
47694
|
round: envFn([prim.num()], prim.num(), numImpl1Abs(Math.round)),
|
|
47185
47695
|
trunc: envFn([prim.num()], prim.num(), numImpl1Abs(Math.trunc)),
|
|
47186
47696
|
sign: envFn([prim.num()], prim.num(), numImpl1Abs(Math.sign)),
|
|
47187
|
-
max
|
|
47188
|
-
|
|
47697
|
+
// min/max/hypot 在 JS 里是变参(`Math.min(a, b, c)`)——二元声明会让
|
|
47698
|
+
// 多实参调用落进 arity 不匹配 → unknown
|
|
47699
|
+
max: envFnVariadic(prim.num(), prim.num(), {
|
|
47700
|
+
apply: numImplVAbs(Math.max),
|
|
47701
|
+
restName: "...values",
|
|
47702
|
+
name: "Math.max"
|
|
47703
|
+
}),
|
|
47704
|
+
min: envFnVariadic(prim.num(), prim.num(), {
|
|
47705
|
+
apply: numImplVAbs(Math.min),
|
|
47706
|
+
restName: "...values",
|
|
47707
|
+
name: "Math.min"
|
|
47708
|
+
}),
|
|
47189
47709
|
pow: envFn([prim.num(), prim.num()], prim.num(), numImpl2Abs(Math.pow)),
|
|
47190
47710
|
sqrt: envFn([prim.num()], prim.num(), numImpl1Abs(Math.sqrt)),
|
|
47191
47711
|
cbrt: envFn([prim.num()], prim.num(), numImpl1Abs(Math.cbrt)),
|
|
@@ -47201,7 +47721,11 @@ function defineEnv() {
|
|
|
47201
47721
|
acos: envFn([prim.num()], prim.num(), numImpl1Abs(Math.acos)),
|
|
47202
47722
|
atan: envFn([prim.num()], prim.num(), numImpl1Abs(Math.atan)),
|
|
47203
47723
|
atan2: envFn([prim.num(), prim.num()], prim.num(), numImpl2Abs(Math.atan2)),
|
|
47204
|
-
hypot:
|
|
47724
|
+
hypot: envFnVariadic(prim.num(), prim.num(), {
|
|
47725
|
+
apply: numImplVAbs(Math.hypot),
|
|
47726
|
+
restName: "...values",
|
|
47727
|
+
name: "Math.hypot"
|
|
47728
|
+
}),
|
|
47205
47729
|
clz32: envFn([prim.num()], prim.num(), numImpl1Abs(Math.clz32)),
|
|
47206
47730
|
imul: envFn([prim.num(), prim.num()], prim.num(), numImpl2Abs(Math.imul)),
|
|
47207
47731
|
fround: envFn([prim.num()], prim.num(), numImpl1Abs(Math.fround)),
|
|
@@ -47214,28 +47738,44 @@ function defineEnv() {
|
|
|
47214
47738
|
SQRT2: prim.num(),
|
|
47215
47739
|
SQRT1_2: prim.num()
|
|
47216
47740
|
}),
|
|
47217
|
-
Number
|
|
47218
|
-
|
|
47219
|
-
|
|
47220
|
-
|
|
47221
|
-
|
|
47222
|
-
|
|
47223
|
-
|
|
47224
|
-
|
|
47225
|
-
|
|
47226
|
-
|
|
47227
|
-
|
|
47228
|
-
|
|
47229
|
-
|
|
47230
|
-
|
|
47231
|
-
|
|
47741
|
+
// dual-facet:Number/Array 既可调用/构造,又带静态槽。
|
|
47742
|
+
// 此前 objAbs 遮蔽宿主全局后 $call/$new 折 unknown(issue #58)。
|
|
47743
|
+
Number: envFn([prim.unknown], prim.num(), numberImplAbs, {
|
|
47744
|
+
name: "Number",
|
|
47745
|
+
params: ["value"],
|
|
47746
|
+
slots: {
|
|
47747
|
+
isFinite: envFn([prim.unknown], prim.bool(), isFiniteImplAbs),
|
|
47748
|
+
isInteger: envFn([prim.unknown], prim.bool(), isIntegerImplAbs),
|
|
47749
|
+
isNaN: envFn([prim.unknown], prim.bool(), isNaNImplAbs),
|
|
47750
|
+
isSafeInteger: envFn([prim.unknown], prim.bool(), isSafeIntegerImplAbs),
|
|
47751
|
+
parseFloat: envFn([prim.str()], prim.num(), parseFloatImplAbs),
|
|
47752
|
+
parseInt: envFn([prim.str()], prim.num(), parseIntImplAbs),
|
|
47753
|
+
MAX_SAFE_INTEGER: prim.num(),
|
|
47754
|
+
MIN_SAFE_INTEGER: prim.num(),
|
|
47755
|
+
MAX_VALUE: prim.num(),
|
|
47756
|
+
MIN_VALUE: prim.num(),
|
|
47757
|
+
POSITIVE_INFINITY: prim.num(),
|
|
47758
|
+
NEGATIVE_INFINITY: prim.num(),
|
|
47759
|
+
NaN: prim.num(),
|
|
47760
|
+
EPSILON: prim.num()
|
|
47761
|
+
}
|
|
47762
|
+
}),
|
|
47763
|
+
Boolean: envFn([prim.unknown], prim.bool(), booleanImplAbs, {
|
|
47764
|
+
name: "Boolean",
|
|
47765
|
+
params: ["value"]
|
|
47232
47766
|
}),
|
|
47233
|
-
|
|
47234
|
-
|
|
47235
|
-
|
|
47236
|
-
|
|
47237
|
-
|
|
47238
|
-
|
|
47767
|
+
String: envFn([prim.unknown], prim.str(), stringImplAbs, {
|
|
47768
|
+
name: "String",
|
|
47769
|
+
params: ["value"]
|
|
47770
|
+
}),
|
|
47771
|
+
Array: envFn([prim.unknown], arrOf2(prim.unknown), arrayImplAbs, {
|
|
47772
|
+
name: "Array",
|
|
47773
|
+
params: ["items"],
|
|
47774
|
+
slots: {
|
|
47775
|
+
isArray: envFn([prim.unknown], prim.bool(), isArrayImplAbs),
|
|
47776
|
+
from: envFn([prim.unknown], arrOf2(prim.unknown)),
|
|
47777
|
+
of: envFn([prim.unknown], arrOf2(prim.unknown))
|
|
47778
|
+
}
|
|
47239
47779
|
}),
|
|
47240
47780
|
console: objAbs(consoleSlots),
|
|
47241
47781
|
parseInt: envFn([prim.str(), prim.num()], prim.num(), parseIntImplAbs),
|
|
@@ -47260,21 +47800,29 @@ function defineEnv() {
|
|
|
47260
47800
|
SyntaxError: envFn([prim.str()], errorBrandOf("SyntaxError")),
|
|
47261
47801
|
ReferenceError: envFn([prim.str()], errorBrandOf("ReferenceError")),
|
|
47262
47802
|
URIError: envFn([prim.str()], errorBrandOf("URIError")),
|
|
47263
|
-
Promise:
|
|
47264
|
-
|
|
47265
|
-
|
|
47266
|
-
|
|
47267
|
-
|
|
47268
|
-
[
|
|
47269
|
-
promiseOf2(arrOf2(prim.unknown))
|
|
47270
|
-
|
|
47271
|
-
|
|
47272
|
-
|
|
47803
|
+
Promise: envFn([prim.unknown], promiseOf2(prim.unknown), promiseCtorImplAbs, {
|
|
47804
|
+
name: "Promise",
|
|
47805
|
+
params: ["executor"],
|
|
47806
|
+
slots: {
|
|
47807
|
+
resolve: envFn([prim.unknown], promiseOf2(prim.unknown), promiseResolveImplAbs),
|
|
47808
|
+
reject: envFn([prim.unknown], promiseOf2(prim.never)),
|
|
47809
|
+
all: envFn([arrOf2(promiseOf2(prim.unknown))], promiseOf2(arrOf2(prim.unknown))),
|
|
47810
|
+
allSettled: envFn(
|
|
47811
|
+
[arrOf2(promiseOf2(prim.unknown))],
|
|
47812
|
+
promiseOf2(arrOf2(prim.unknown))
|
|
47813
|
+
),
|
|
47814
|
+
race: envFn([arrOf2(promiseOf2(prim.unknown))], promiseOf2(prim.unknown)),
|
|
47815
|
+
any: envFn([arrOf2(promiseOf2(prim.unknown))], promiseOf2(prim.unknown))
|
|
47816
|
+
}
|
|
47273
47817
|
}),
|
|
47274
|
-
Date:
|
|
47275
|
-
|
|
47276
|
-
|
|
47277
|
-
|
|
47818
|
+
Date: envFn([], dateAbs(), dateCtorImplAbs, {
|
|
47819
|
+
name: "Date",
|
|
47820
|
+
params: ["value"],
|
|
47821
|
+
slots: {
|
|
47822
|
+
now: envFn([], prim.num()),
|
|
47823
|
+
parse: envFn([prim.str()], prim.num()),
|
|
47824
|
+
UTC: envFn([prim.num(), prim.num()], prim.num())
|
|
47825
|
+
}
|
|
47278
47826
|
}),
|
|
47279
47827
|
Symbol: envFn([prim.str()], brandOf2("Symbol")),
|
|
47280
47828
|
Reflect: objAbs({
|
|
@@ -167255,7 +167803,7 @@ ${lanes.join("\n")}
|
|
|
167255
167803
|
return visitEachChild(node, visitor, context);
|
|
167256
167804
|
}
|
|
167257
167805
|
}
|
|
167258
|
-
function
|
|
167806
|
+
function flattenChain2(chain) {
|
|
167259
167807
|
Debug.assertNotNode(chain, isNonNullChain);
|
|
167260
167808
|
const links = [chain];
|
|
167261
167809
|
while (!chain.questionDotToken && !isTaggedTemplateExpression2(chain)) {
|
|
@@ -167335,7 +167883,7 @@ ${lanes.join("\n")}
|
|
|
167335
167883
|
}
|
|
167336
167884
|
}
|
|
167337
167885
|
function visitOptionalExpression(node, captureThisArg, isDelete) {
|
|
167338
|
-
const { expression: expression2, chain } =
|
|
167886
|
+
const { expression: expression2, chain } = flattenChain2(node);
|
|
167339
167887
|
const left = visitNonOptionalExpression(
|
|
167340
167888
|
skipPartiallyEmittedExpressions(expression2),
|
|
167341
167889
|
isCallChain(chain[0]),
|