@scriptc/compiler 0.1.2 → 0.1.4
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/ambient/scriptc-node-fallback.d.ts +258 -64
- package/dist/backend/c/async.d.ts +30 -0
- package/dist/backend/c/async.js +224 -0
- package/dist/backend/c/async.js.map +1 -1
- package/dist/backend/c/c-emitter.d.ts +13 -0
- package/dist/backend/c/c-emitter.js +28 -9
- package/dist/backend/c/c-emitter.js.map +1 -1
- package/dist/backend/c/exprs.d.ts +8 -1
- package/dist/backend/c/exprs.js +445 -60
- package/dist/backend/c/exprs.js.map +1 -1
- package/dist/backend/c/shapes.js +15 -13
- package/dist/backend/c/shapes.js.map +1 -1
- package/dist/backend/c/types.d.ts +4 -0
- package/dist/backend/c/types.js +20 -1
- package/dist/backend/c/types.js.map +1 -1
- package/dist/backend/c/types.test.js +8 -1
- package/dist/backend/c/types.test.js.map +1 -1
- package/dist/backend/c/walkers.js +32 -11
- package/dist/backend/c/walkers.js.map +1 -1
- package/dist/backend/json-literal.d.ts +7 -0
- package/dist/backend/json-literal.js +17 -0
- package/dist/backend/json-literal.js.map +1 -0
- package/dist/backend/json-literal.test.d.ts +1 -0
- package/dist/backend/json-literal.test.js +17 -0
- package/dist/backend/json-literal.test.js.map +1 -0
- package/dist/backend/link-plan.d.ts +2 -1
- package/dist/backend/link-plan.js +6 -1
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/llvm/classes.js +8 -7
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +4 -0
- package/dist/backend/llvm/common.js +6 -0
- package/dist/backend/llvm/common.js.map +1 -1
- package/dist/backend/llvm/common.test.d.ts +1 -0
- package/dist/backend/llvm/common.test.js +9 -0
- package/dist/backend/llvm/common.test.js.map +1 -0
- package/dist/backend/llvm/dyn.d.ts +4 -0
- package/dist/backend/llvm/dyn.js +24 -13
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.js +54 -12
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.d.ts +1 -1
- package/dist/backend/llvm/expr-bytes.js +8 -8
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-callbacks.d.ts +9 -0
- package/dist/backend/llvm/expr-callbacks.js +125 -0
- package/dist/backend/llvm/expr-callbacks.js.map +1 -1
- package/dist/backend/llvm/expr-context.d.ts +18 -2
- package/dist/backend/llvm/expr-dispatch.js +1 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +9 -0
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.d.ts +1 -1
- package/dist/backend/llvm/expr-primitives.js +38 -9
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.d.ts +1 -0
- package/dist/backend/llvm/expr-primitives.test.js +38 -0
- package/dist/backend/llvm/expr-primitives.test.js.map +1 -0
- package/dist/backend/llvm/expr-records.js +3 -3
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +2 -1
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +6 -0
- package/dist/backend/llvm/expr-stream-callbacks.js +122 -0
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +22 -0
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +68 -10
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-network.js +18 -2
- package/dist/backend/llvm/lib-network.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +206 -11
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +82 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/lib-stream.js +23 -0
- package/dist/backend/llvm/lib-stream.js.map +1 -1
- package/dist/backend/llvm/shapes.js +10 -8
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/walkers.js +7 -5
- package/dist/backend/llvm/walkers.js.map +1 -1
- package/dist/backend/native-link-info.d.ts +2 -1
- package/dist/backend/native-link-info.js +4 -0
- package/dist/backend/native-link-info.js.map +1 -1
- package/dist/backend/native-link-info.test.js +24 -1
- package/dist/backend/native-link-info.test.js.map +1 -1
- package/dist/backend/native-toolchain.d.ts +11 -6
- package/dist/backend/native-toolchain.js +30 -13
- package/dist/backend/native-toolchain.js.map +1 -1
- package/dist/backend/native-toolchain.test.js +36 -1
- package/dist/backend/native-toolchain.test.js.map +1 -1
- package/dist/backend/runtime-pack-targets.test.js +1 -1
- package/dist/backend/runtime-pack-targets.test.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +29 -10
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/targets.d.ts +9 -0
- package/dist/backend/targets.js +22 -0
- package/dist/backend/targets.js.map +1 -1
- package/dist/backend/targets.test.js +13 -1
- package/dist/backend/targets.test.js.map +1 -1
- package/dist/coverage/surface-manifest.js +9 -0
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.js +4 -4
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +3 -0
- package/dist/executable/executable-cache.js +4 -0
- package/dist/executable/executable-cache.js.map +1 -1
- package/dist/executable/executable-cache.test.js +1 -0
- package/dist/executable/executable-cache.test.js.map +1 -1
- package/dist/frontend/fork-target.d.ts +17 -0
- package/dist/frontend/fork-target.js +256 -0
- package/dist/frontend/fork-target.js.map +1 -0
- package/dist/frontend/lowering/abstract-equality.d.ts +6 -0
- package/dist/frontend/lowering/abstract-equality.js +250 -0
- package/dist/frontend/lowering/abstract-equality.js.map +1 -0
- package/dist/frontend/lowering/containers/bytes.d.ts +0 -4
- package/dist/frontend/lowering/containers/bytes.js +112 -28
- package/dist/frontend/lowering/containers/bytes.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.js +87 -12
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +72 -44
- package/dist/frontend/lowering/lower-builtins.js +1323 -165
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +37 -27
- package/dist/frontend/lowering/lower-calls.js +682 -132
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.js +39 -8
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.js +162 -8
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-event-emitter.js +212 -21
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.js +238 -87
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.d.ts +4 -0
- package/dist/frontend/lowering/lower-inspect.js +8 -1
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.d.ts +6 -3
- package/dist/frontend/lowering/lower-island.js +165 -6
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +6 -0
- package/dist/frontend/lowering/lower-modules.js +192 -38
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-namespaces.js +7 -0
- package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
- package/dist/frontend/lowering/lower-server.d.ts +1 -1
- package/dist/frontend/lowering/lower-server.js +130 -27
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +5 -4
- package/dist/frontend/lowering/lower-stmts.js +141 -21
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.d.ts +3 -0
- package/dist/frontend/lowering/lower-stream.js +7 -0
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +90 -13
- package/dist/frontend/lowering/lowerer.js +416 -76
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +31 -3
- package/dist/frontend/lowering/surfaces.js +173 -90
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm-static-declarations.d.ts +4 -0
- package/dist/frontend/npm-static-declarations.js +83 -14
- package/dist/frontend/npm-static-declarations.js.map +1 -1
- package/dist/frontend/npm-static-declarations.test.js +33 -2
- package/dist/frontend/npm-static-declarations.test.js.map +1 -1
- package/dist/frontend/npm-static.js +6 -5
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.d.ts +15 -3
- package/dist/frontend/npm.js +80 -8
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/npm.test.js +76 -9
- package/dist/frontend/npm.test.js.map +1 -1
- package/dist/frontend/program.js +110 -12
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/resolve.d.ts +28 -7
- package/dist/frontend/resolve.js +90 -26
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/resolve.test.js +21 -1
- package/dist/frontend/resolve.test.js.map +1 -1
- package/dist/frontend/type-mapper.d.ts +5 -0
- package/dist/frontend/type-mapper.js +115 -33
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +30 -3
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.js +1 -0
- package/dist/ir/analysis.js.map +1 -1
- package/dist/ir/ir.d.ts +155 -66
- package/dist/ir/ir.js +143 -6
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/ir.test.js +14 -1
- package/dist/ir/ir.test.js.map +1 -1
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +1 -1
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/validate.js +242 -18
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/int-infer.test.js +4 -4
- package/dist/library/int-infer.test.js.map +1 -1
- package/dist/library/library-cache.d.ts +1 -0
- package/dist/library/library-cache.js +1 -0
- package/dist/library/library-cache.js.map +1 -1
- package/dist/library/library-cache.test.js +18 -5
- package/dist/library/library-cache.test.js.map +1 -1
- package/package.json +17 -17
- package/surface-manifest.json +163 -54
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { InternalCompilerError } from "../../errors.js";
|
|
2
|
+
import { BOOL, DYN_HANDLE_KINDS, F64, isUnitType, typeEquals } from "../../ir/ir.js";
|
|
3
|
+
import { boolLit, numLit, varRef } from "../../ir/build.js";
|
|
4
|
+
/**
|
|
5
|
+
* The engine-free part of ECMAScript Abstract Equality Comparison.
|
|
6
|
+
*
|
|
7
|
+
* Every primitive pair is exact, including StringToNumber,
|
|
8
|
+
* StringToBigInt, Boolean-to-number recursion, and BigInt/Number's
|
|
9
|
+
* mathematical comparison. Object-to-primitive coercion stays outside
|
|
10
|
+
* this helper: user-defined valueOf/toString methods can execute arbitrary
|
|
11
|
+
* JavaScript, so a static build must keep that form fenced. Object pairs
|
|
12
|
+
* with one exact representation compare by identity, as == and === agree
|
|
13
|
+
* there.
|
|
14
|
+
*/
|
|
15
|
+
const IDENTITY_KINDS = new Set([
|
|
16
|
+
"array",
|
|
17
|
+
"bytes",
|
|
18
|
+
"map",
|
|
19
|
+
"set",
|
|
20
|
+
"object",
|
|
21
|
+
"record",
|
|
22
|
+
"promise",
|
|
23
|
+
"symbol",
|
|
24
|
+
"classval",
|
|
25
|
+
"moduleNs",
|
|
26
|
+
]);
|
|
27
|
+
const PRIMITIVE_KINDS = new Set([
|
|
28
|
+
"f64",
|
|
29
|
+
"string",
|
|
30
|
+
"bool",
|
|
31
|
+
"bigint",
|
|
32
|
+
"symbol",
|
|
33
|
+
]);
|
|
34
|
+
function supportsPair(lowerer, left, right) {
|
|
35
|
+
if (left.kind === "union") {
|
|
36
|
+
const def = lowerer.unions.get(left.unionId);
|
|
37
|
+
return def !== undefined && def.arms.every((arm) => supportsPair(lowerer, arm, right));
|
|
38
|
+
}
|
|
39
|
+
if (right.kind === "union") {
|
|
40
|
+
const def = lowerer.unions.get(right.unionId);
|
|
41
|
+
return def !== undefined && def.arms.every((arm) => supportsPair(lowerer, left, arm));
|
|
42
|
+
}
|
|
43
|
+
if (isUnitType(left) || isUnitType(right)) {
|
|
44
|
+
const other = isUnitType(left) ? right : left;
|
|
45
|
+
return other.kind !== "dyn" && other.kind !== "jsval" && other.kind !== "caught" && other.kind !== "void";
|
|
46
|
+
}
|
|
47
|
+
if (PRIMITIVE_KINDS.has(left.kind) && PRIMITIVE_KINDS.has(right.kind))
|
|
48
|
+
return true;
|
|
49
|
+
if (left.kind === "func" && right.kind === "func")
|
|
50
|
+
return true;
|
|
51
|
+
if (IDENTITY_KINDS.has(left.kind) && typeEquals(left, right))
|
|
52
|
+
return true;
|
|
53
|
+
if (DYN_HANDLE_KINDS.has(left.kind) && typeEquals(left, right))
|
|
54
|
+
return true;
|
|
55
|
+
if (left.kind === "object" && right.kind === "object") {
|
|
56
|
+
return lowerer.isSubclassOf(left.className, right.className) || lowerer.isSubclassOf(right.className, left.className);
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
function boolAsNumber(value, loc) {
|
|
61
|
+
return {
|
|
62
|
+
kind: "ternary",
|
|
63
|
+
cond: value,
|
|
64
|
+
then: numLit(1, loc),
|
|
65
|
+
else_: numLit(0, loc),
|
|
66
|
+
type: F64,
|
|
67
|
+
loc,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function numericEq(left, right, nanEqualsNan, loc) {
|
|
71
|
+
const ordinary = { kind: "bin", op: "===", left, right, type: BOOL, loc };
|
|
72
|
+
if (!nanEqualsNan)
|
|
73
|
+
return ordinary;
|
|
74
|
+
return {
|
|
75
|
+
kind: "logical",
|
|
76
|
+
op: "||",
|
|
77
|
+
left: ordinary,
|
|
78
|
+
right: {
|
|
79
|
+
kind: "logical",
|
|
80
|
+
op: "&&",
|
|
81
|
+
left: { kind: "libCall", fn: "num.isNaN", args: [left], type: BOOL, loc },
|
|
82
|
+
right: { kind: "libCall", fn: "num.isNaN", args: [right], type: BOOL, loc },
|
|
83
|
+
type: BOOL,
|
|
84
|
+
loc,
|
|
85
|
+
},
|
|
86
|
+
type: BOOL,
|
|
87
|
+
loc,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function primitivePair(lowerer, left, right, nanEqualsNan, loc) {
|
|
91
|
+
if (isUnitType(left.type) || isUnitType(right.type)) {
|
|
92
|
+
return boolLit(isUnitType(left.type) && isUnitType(right.type), loc);
|
|
93
|
+
}
|
|
94
|
+
if (left.type.kind === "object" && right.type.kind === "object") {
|
|
95
|
+
if (typeEquals(left.type, right.type)) {
|
|
96
|
+
return { kind: "bin", op: "===", left, right, type: BOOL, loc };
|
|
97
|
+
}
|
|
98
|
+
if (lowerer.isSubclassOf(left.type.className, right.type.className)) {
|
|
99
|
+
return { kind: "bin", op: "===", left: lowerer.upcastTo(left, right.type.className), right, type: BOOL, loc };
|
|
100
|
+
}
|
|
101
|
+
if (lowerer.isSubclassOf(right.type.className, left.type.className)) {
|
|
102
|
+
return { kind: "bin", op: "===", left, right: lowerer.upcastTo(right, left.type.className), type: BOOL, loc };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (left.type.kind === right.type.kind) {
|
|
106
|
+
switch (left.type.kind) {
|
|
107
|
+
case "f64":
|
|
108
|
+
return numericEq(left, right, nanEqualsNan, loc);
|
|
109
|
+
case "string":
|
|
110
|
+
return { kind: "strEq", negated: false, left, right, type: BOOL, loc };
|
|
111
|
+
case "bool":
|
|
112
|
+
return { kind: "bin", op: "===", left, right, type: BOOL, loc };
|
|
113
|
+
case "bigint":
|
|
114
|
+
return { kind: "libCall", fn: "bigint.eq", args: [left, right], type: BOOL, loc };
|
|
115
|
+
case "symbol":
|
|
116
|
+
case "array":
|
|
117
|
+
case "bytes":
|
|
118
|
+
case "map":
|
|
119
|
+
case "set":
|
|
120
|
+
case "record":
|
|
121
|
+
case "promise":
|
|
122
|
+
case "classval":
|
|
123
|
+
case "moduleNs":
|
|
124
|
+
return { kind: "bin", op: "===", left, right, type: BOOL, loc };
|
|
125
|
+
default:
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (left.type.kind === "func" && right.type.kind === "func") {
|
|
130
|
+
return { kind: "bin", op: "===", left, right, type: BOOL, loc };
|
|
131
|
+
}
|
|
132
|
+
if (DYN_HANDLE_KINDS.has(left.type.kind) && typeEquals(left.type, right.type)) {
|
|
133
|
+
return { kind: "bin", op: "===", left, right, type: BOOL, loc };
|
|
134
|
+
}
|
|
135
|
+
// Boolean first recurses as ToNumber(boolean), per ECMA-262 7.2.13.
|
|
136
|
+
if (left.type.kind === "bool")
|
|
137
|
+
return primitivePair(lowerer, boolAsNumber(left, loc), right, nanEqualsNan, loc);
|
|
138
|
+
if (right.type.kind === "bool")
|
|
139
|
+
return primitivePair(lowerer, left, boolAsNumber(right, loc), nanEqualsNan, loc);
|
|
140
|
+
// Symbols never equal a different primitive type. Object/symbol would
|
|
141
|
+
// require ToPrimitive and was rejected by supportsPair.
|
|
142
|
+
if (left.type.kind === "symbol" || right.type.kind === "symbol")
|
|
143
|
+
return boolLit(false, loc);
|
|
144
|
+
if (left.type.kind === "f64" && right.type.kind === "string") {
|
|
145
|
+
const parsed = { kind: "libCall", fn: "num.fromString", args: [right], type: F64, loc };
|
|
146
|
+
return numericEq(left, parsed, false, loc);
|
|
147
|
+
}
|
|
148
|
+
if (left.type.kind === "string" && right.type.kind === "f64") {
|
|
149
|
+
const parsed = { kind: "libCall", fn: "num.fromString", args: [left], type: F64, loc };
|
|
150
|
+
return numericEq(parsed, right, false, loc);
|
|
151
|
+
}
|
|
152
|
+
if (left.type.kind === "bigint" && right.type.kind === "string") {
|
|
153
|
+
return { kind: "libCall", fn: "bigint.eqString", args: [left, right], type: BOOL, loc };
|
|
154
|
+
}
|
|
155
|
+
if (left.type.kind === "string" && right.type.kind === "bigint") {
|
|
156
|
+
return { kind: "libCall", fn: "bigint.eqString", args: [right, left], type: BOOL, loc };
|
|
157
|
+
}
|
|
158
|
+
if (left.type.kind === "bigint" && right.type.kind === "f64") {
|
|
159
|
+
const cmp = { kind: "libCall", fn: "bigint.cmpNumber", args: [left, right], type: F64, loc };
|
|
160
|
+
return { kind: "bin", op: "===", left: cmp, right: numLit(0, loc), type: BOOL, loc };
|
|
161
|
+
}
|
|
162
|
+
if (left.type.kind === "f64" && right.type.kind === "bigint") {
|
|
163
|
+
const cmp = { kind: "libCall", fn: "bigint.cmpNumber", args: [right, left], type: F64, loc };
|
|
164
|
+
return { kind: "bin", op: "===", left: cmp, right: numLit(0, loc), type: BOOL, loc };
|
|
165
|
+
}
|
|
166
|
+
throw new InternalCompilerError(`abstract equality reached an unplanned pair ${left.type.kind}/${right.type.kind}`);
|
|
167
|
+
}
|
|
168
|
+
function pairExpr(lowerer, left, right, nanEqualsNan, loc) {
|
|
169
|
+
if (left.type.kind === "union") {
|
|
170
|
+
const unionId = left.type.unionId;
|
|
171
|
+
const def = lowerer.unions.get(unionId);
|
|
172
|
+
if (!def || def.arms.length === 0)
|
|
173
|
+
throw new InternalCompilerError(`abstract equality over unknown union ${unionId}`);
|
|
174
|
+
const branch = (tag) => {
|
|
175
|
+
const arm = def.arms[tag];
|
|
176
|
+
if (!arm)
|
|
177
|
+
throw new InternalCompilerError(`abstract equality union ${unionId} lacks tag ${tag}`);
|
|
178
|
+
return pairExpr(lowerer, { kind: "unionNarrow", unionId, tag, value: left, type: arm, loc }, right, nanEqualsNan, loc);
|
|
179
|
+
};
|
|
180
|
+
let out = branch(def.arms.length - 1);
|
|
181
|
+
for (let tag = def.arms.length - 2; tag >= 0; tag--) {
|
|
182
|
+
out = {
|
|
183
|
+
kind: "ternary",
|
|
184
|
+
cond: { kind: "unionIsTag", unionId, tag, negated: false, value: left, type: BOOL, loc },
|
|
185
|
+
then: branch(tag),
|
|
186
|
+
else_: out,
|
|
187
|
+
type: BOOL,
|
|
188
|
+
loc,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
if (right.type.kind === "union") {
|
|
194
|
+
const unionId = right.type.unionId;
|
|
195
|
+
const def = lowerer.unions.get(unionId);
|
|
196
|
+
if (!def || def.arms.length === 0)
|
|
197
|
+
throw new InternalCompilerError(`abstract equality over unknown union ${unionId}`);
|
|
198
|
+
const branch = (tag) => {
|
|
199
|
+
const arm = def.arms[tag];
|
|
200
|
+
if (!arm)
|
|
201
|
+
throw new InternalCompilerError(`abstract equality union ${unionId} lacks tag ${tag}`);
|
|
202
|
+
return pairExpr(lowerer, left, { kind: "unionNarrow", unionId, tag, value: right, type: arm, loc }, nanEqualsNan, loc);
|
|
203
|
+
};
|
|
204
|
+
let out = branch(def.arms.length - 1);
|
|
205
|
+
for (let tag = def.arms.length - 2; tag >= 0; tag--) {
|
|
206
|
+
out = {
|
|
207
|
+
kind: "ternary",
|
|
208
|
+
cond: { kind: "unionIsTag", unionId, tag, negated: false, value: right, type: BOOL, loc },
|
|
209
|
+
then: branch(tag),
|
|
210
|
+
else_: out,
|
|
211
|
+
type: BOOL,
|
|
212
|
+
loc,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
return primitivePair(lowerer, left, right, nanEqualsNan, loc);
|
|
218
|
+
}
|
|
219
|
+
export function abstractEqualitySupported(lowerer, left, right) {
|
|
220
|
+
return supportsPair(lowerer, left, right);
|
|
221
|
+
}
|
|
222
|
+
export function abstractEqualityExpr(lowerer, left, right, loc, nanEqualsNan = false) {
|
|
223
|
+
if (!supportsPair(lowerer, left.type, right.type)) {
|
|
224
|
+
throw new InternalCompilerError(`abstract equality expression built for unsupported ${left.type.kind}/${right.type.kind} pair`);
|
|
225
|
+
}
|
|
226
|
+
return pairExpr(lowerer, left, right, nanEqualsNan, loc);
|
|
227
|
+
}
|
|
228
|
+
/** Evaluate both operands once, left-to-right, then compare their stable values. */
|
|
229
|
+
export function lowerAbstractEquality(lowerer, left, right, negated, loc) {
|
|
230
|
+
if (!supportsPair(lowerer, left.type, right.type))
|
|
231
|
+
return null;
|
|
232
|
+
const stmts = [];
|
|
233
|
+
const stable = (value, name) => {
|
|
234
|
+
if (isUnitType(value.type)) {
|
|
235
|
+
if (value.kind !== "unitLit")
|
|
236
|
+
stmts.push({ kind: "exprStmt", expr: value, loc });
|
|
237
|
+
return { kind: "unitLit", unit: value.type.kind === "nullT" ? "null" : "undefined", type: value.type, loc };
|
|
238
|
+
}
|
|
239
|
+
const local = lowerer.declareHiddenLocal(name, value.type);
|
|
240
|
+
stmts.push({ kind: "varDecl", localId: local.id, init: value, loc });
|
|
241
|
+
return varRef(local.id, value.type, loc);
|
|
242
|
+
};
|
|
243
|
+
const a = stable(left, "%looseA");
|
|
244
|
+
const b = stable(right, "%looseB");
|
|
245
|
+
let result = pairExpr(lowerer, a, b, false, loc);
|
|
246
|
+
if (negated)
|
|
247
|
+
result = { kind: "unary", op: "!", operand: result, type: BOOL, loc };
|
|
248
|
+
return stmts.length === 0 ? result : { kind: "seqExpr", stmts, result, type: BOOL, loc };
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=abstract-equality.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-equality.js","sourceRoot":"","sources":["../../../src/frontend/lowering/abstract-equality.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAkC,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACrH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM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,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACrE,OAAO,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC,CAAC;IACF,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAClC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACnC,IAAI,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACjD,IAAI,OAAO;QAAE,MAAM,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IACnF,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAC3F,CAAC"}
|
|
@@ -28,8 +28,4 @@ export declare function knownBufEncoding(name: string): string | undefined;
|
|
|
28
28
|
/** The literal encoding argument of a Buffer surface, normalized — or a
|
|
29
29
|
* fence when it isn't a literal alias Node knows. */
|
|
30
30
|
export declare function bufEncoding(lowerer: Lowerer, what: string, encNode: ts.Expression): string;
|
|
31
|
-
/** The Buffer statics — `Buffer.from(...)`, `Buffer.alloc(n)`,
|
|
32
|
-
* `Buffer.concat(list)`, `Buffer.isBuffer(x)` — on THE stdlib Buffer
|
|
33
|
-
* global (name + provenance; fallback and @types/node alike). Null when
|
|
34
|
-
* the callee isn't a Buffer-static access. */
|
|
35
31
|
export declare function lowerBufferStaticCall(lowerer: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ts from "../../ts7/adapter.js";
|
|
2
|
-
import { BOOL, BYTES_U8, DYN, F64, STRING, UNDEFINED_T, VOID, arrayOf, bytesOf, typeEquals } from "../../../ir/ir.js";
|
|
2
|
+
import { BIGINT_T, BOOL, BYTES_U8, DYN, F64, STRING, UNDEFINED_T, VOID, arrayOf, bytesOf, typeEquals } from "../../../ir/ir.js";
|
|
3
3
|
import { locOf } from "../../program.js";
|
|
4
4
|
import { dynUndefinedExpr, own } from "../lowerer.js";
|
|
5
5
|
import { buildBytesSortFn } from "../lower-array-sort.js";
|
|
@@ -439,6 +439,26 @@ export function lowerBytesMethodCall(lowerer, call, access) {
|
|
|
439
439
|
if (bufMethod)
|
|
440
440
|
return bufMethod;
|
|
441
441
|
}
|
|
442
|
+
const bigKind = own(BUF_BIGINT_METHODS, name);
|
|
443
|
+
if (bigKind !== undefined && declOnBuffer && receiverIr.elem === "u8") {
|
|
444
|
+
const write = name.startsWith("write");
|
|
445
|
+
const required = write ? 1 : 0;
|
|
446
|
+
if (nArgs < required || nArgs > required + 1) {
|
|
447
|
+
lowerer.noLowering(`.${name} with ${nArgs} arguments`, call);
|
|
448
|
+
}
|
|
449
|
+
const receiver = lowerer.lowerExpr(access.expression);
|
|
450
|
+
const offsetNode = call.arguments[required];
|
|
451
|
+
const offset = offsetNode
|
|
452
|
+
? lowerer.lowerExprExpecting(offsetNode, F64)
|
|
453
|
+
: { kind: "numLit", value: 0, type: F64, loc };
|
|
454
|
+
const sign = { kind: "boolLit", value: bigKind.sign, type: BOOL, loc };
|
|
455
|
+
const le = { kind: "boolLit", value: bigKind.le, type: BOOL, loc };
|
|
456
|
+
if (!write) {
|
|
457
|
+
return { kind: "libCall", fn: "bigint.bufferRead", args: [receiver, offset, sign, le], type: BIGINT_T, loc };
|
|
458
|
+
}
|
|
459
|
+
const value = lowerer.lowerExprExpecting(call.arguments[0], BIGINT_T);
|
|
460
|
+
return { kind: "libCall", fn: "bigint.bufferWrite", args: [receiver, value, offset, sign, le], type: F64, loc };
|
|
461
|
+
}
|
|
442
462
|
// The Buffer numeric read/write families — every fixed-width kind in
|
|
443
463
|
// both endiannesses ("Uint" and "UInt" alike: Node aliases both), plus
|
|
444
464
|
// the variable-width read/writeUIntLE quartet. The kind token rides as
|
|
@@ -481,26 +501,20 @@ export function lowerBytesMethodCall(lowerer, call, access) {
|
|
|
481
501
|
// typed arrays and Buffers). The multi-byte kinds take the optional
|
|
482
502
|
// littleEndian bool (omitted = big-endian, the JS default). All THROW
|
|
483
503
|
// Node's RangeError on a bad offset (may-throw seeds).
|
|
504
|
+
const dvBigGetter = own(DV_BIG_GETTERS, name);
|
|
505
|
+
if (dvBigGetter !== undefined && receiverIr.elem === "u8") {
|
|
506
|
+
if (nArgs < 1 || nArgs > 2)
|
|
507
|
+
lowerer.noLowering(`.${name} with ${nArgs} arguments`, call);
|
|
508
|
+
const receiver = lowerer.lowerExpr(access.expression);
|
|
509
|
+
const offset = lowerer.lowerExprExpecting(call.arguments[0], F64);
|
|
510
|
+
const sign = { kind: "boolLit", value: dvBigGetter.sign, type: BOOL, loc };
|
|
511
|
+
const le = call.arguments[1]
|
|
512
|
+
? lowerer.lowerExprExpecting(call.arguments[1], BOOL)
|
|
513
|
+
: { kind: "boolLit", value: false, type: BOOL, loc };
|
|
514
|
+
return { kind: "libCall", fn: "bigint.dataViewGet", args: [receiver, offset, sign, le], type: BIGINT_T, loc };
|
|
515
|
+
}
|
|
484
516
|
const dvGetter = own(DV_GETTERS, name);
|
|
485
517
|
if (dvGetter !== undefined && receiverIr.elem === "u8") {
|
|
486
|
-
if (dvGetter.method === "dvGetBigUint64Number" || dvGetter.method === "dvGetBigInt64Number") {
|
|
487
|
-
// bigint values have no representation — only the COMPOSED
|
|
488
|
-
// `Number(view.getBigUint64/getBigInt64(...))` compiles (the
|
|
489
|
-
// randomBytesToString pattern): the 8-byte integer converts to
|
|
490
|
-
// double exactly as Number(bigint) would, and the bigint never
|
|
491
|
-
// exists as a value (the f64-typed intrinsic result IS what the
|
|
492
|
-
// identity Number(f64) lowering hands back).
|
|
493
|
-
const p = call.parent;
|
|
494
|
-
const composed = ts.isCallExpression(p) &&
|
|
495
|
-
p.arguments.length === 1 &&
|
|
496
|
-
p.arguments[0] === call &&
|
|
497
|
-
ts.isIdentifier(p.expression) &&
|
|
498
|
-
p.expression.text === "Number" &&
|
|
499
|
-
lowerer.isStdlibSymbol(lowerer.resolveValueSymbol(p.expression) ?? undefined);
|
|
500
|
-
if (!composed) {
|
|
501
|
-
lowerer.noLowering(`.${name} outside Number(...)`, call, `bigint values have no representation — Number(view.${name}(offset, littleEndian?)) is the lowered form`);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
518
|
const maxArgs = dvGetter.le ? 2 : 1;
|
|
505
519
|
if (nArgs < 1 || nArgs > maxArgs) {
|
|
506
520
|
lowerer.noLowering(`.${name} with ${nArgs} arguments`, call);
|
|
@@ -518,6 +532,17 @@ export function lowerBytesMethodCall(lowerer, call, access) {
|
|
|
518
532
|
// representation and no composed form exists) — they keep the member
|
|
519
533
|
// fence, as does setFloat16.
|
|
520
534
|
const dvSetter = own(DV_SETTERS, name);
|
|
535
|
+
if ((name === "setBigUint64" || name === "setBigInt64") && receiverIr.elem === "u8") {
|
|
536
|
+
if (nArgs < 2 || nArgs > 3)
|
|
537
|
+
lowerer.noLowering(`.${name} with ${nArgs} arguments`, call);
|
|
538
|
+
const receiver = lowerer.lowerExpr(access.expression);
|
|
539
|
+
const offset = lowerer.lowerExprExpecting(call.arguments[0], F64);
|
|
540
|
+
const value = lowerer.lowerExprExpecting(call.arguments[1], BIGINT_T);
|
|
541
|
+
const le = call.arguments[2]
|
|
542
|
+
? lowerer.lowerExprExpecting(call.arguments[2], BOOL)
|
|
543
|
+
: { kind: "boolLit", value: false, type: BOOL, loc };
|
|
544
|
+
return { kind: "libCall", fn: "bigint.dataViewSet", args: [receiver, offset, value, le], type: VOID, loc };
|
|
545
|
+
}
|
|
521
546
|
if (dvSetter !== undefined && receiverIr.elem === "u8") {
|
|
522
547
|
const maxArgs = dvSetter.le ? 3 : 2;
|
|
523
548
|
if (nArgs < 2 || nArgs > maxArgs) {
|
|
@@ -592,6 +617,20 @@ const BUF_NUM_METHODS = (() => {
|
|
|
592
617
|
}
|
|
593
618
|
return out;
|
|
594
619
|
})();
|
|
620
|
+
const BUF_BIGINT_METHODS = {
|
|
621
|
+
readBigInt64BE: { sign: true, le: false },
|
|
622
|
+
readBigInt64LE: { sign: true, le: true },
|
|
623
|
+
readBigUInt64BE: { sign: false, le: false },
|
|
624
|
+
readBigUInt64LE: { sign: false, le: true },
|
|
625
|
+
readBigUint64BE: { sign: false, le: false },
|
|
626
|
+
readBigUint64LE: { sign: false, le: true },
|
|
627
|
+
writeBigInt64BE: { sign: true, le: false },
|
|
628
|
+
writeBigInt64LE: { sign: true, le: true },
|
|
629
|
+
writeBigUInt64BE: { sign: false, le: false },
|
|
630
|
+
writeBigUInt64LE: { sign: false, le: true },
|
|
631
|
+
writeBigUint64BE: { sign: false, le: false },
|
|
632
|
+
writeBigUint64LE: { sign: false, le: true },
|
|
633
|
+
};
|
|
595
634
|
/** The variable-width quartet (offset + byteLength) → sign/endian token. */
|
|
596
635
|
const BUF_NUM_VAR_METHODS = {
|
|
597
636
|
readUIntBE: "ube",
|
|
@@ -800,10 +839,13 @@ function lowerBufferInstanceMethod(lowerer, call, access, name, loc) {
|
|
|
800
839
|
}
|
|
801
840
|
return null;
|
|
802
841
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
842
|
+
const DV_BIG_GETTERS = {
|
|
843
|
+
getBigInt64: { sign: true },
|
|
844
|
+
getBigUint64: { sign: false },
|
|
845
|
+
};
|
|
846
|
+
/** The number-returning DataView getter surface by source name. `le` marks
|
|
847
|
+
* the multi-byte kinds whose signature declares optional littleEndian;
|
|
848
|
+
* the BigInt pair routes through DV_BIG_GETTERS above. */
|
|
807
849
|
const DV_GETTERS = {
|
|
808
850
|
getUint8: { method: "dvGetUint8", le: false },
|
|
809
851
|
getInt8: { method: "dvGetInt8", le: false },
|
|
@@ -813,8 +855,6 @@ const DV_GETTERS = {
|
|
|
813
855
|
getInt32: { method: "dvGetInt32", le: true },
|
|
814
856
|
getFloat32: { method: "dvGetFloat32", le: true },
|
|
815
857
|
getFloat64: { method: "dvGetFloat64", le: true },
|
|
816
|
-
getBigUint64: { method: "dvGetBigUint64Number", le: true },
|
|
817
|
-
getBigInt64: { method: "dvGetBigInt64Number", le: true },
|
|
818
858
|
};
|
|
819
859
|
const DV_SETTERS = {
|
|
820
860
|
setUint8: { method: "dvSetUint8", le: false },
|
|
@@ -830,6 +870,36 @@ const DV_SETTERS = {
|
|
|
830
870
|
* `Buffer.concat(list)`, `Buffer.isBuffer(x)` — on THE stdlib Buffer
|
|
831
871
|
* global (name + provenance; fallback and @types/node alike). Null when
|
|
832
872
|
* the callee isn't a Buffer-static access. */
|
|
873
|
+
function knownBufferProducer(lowerer, source, seen = new Set()) {
|
|
874
|
+
let node = source;
|
|
875
|
+
while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertion(node))
|
|
876
|
+
node = node.expression;
|
|
877
|
+
if (ts.isIdentifier(node)) {
|
|
878
|
+
const symbol = lowerer.checker.getSymbolAtLocation(node);
|
|
879
|
+
if (!symbol || seen.has(symbol))
|
|
880
|
+
return false;
|
|
881
|
+
seen.add(symbol);
|
|
882
|
+
return lowerer.checker.declarationsOf(symbol).some((decl) => ts.isVariableDeclaration(decl) &&
|
|
883
|
+
ts.isVariableDeclarationList(decl.parent) &&
|
|
884
|
+
(decl.parent.flags & ts.NodeFlags.Const) !== 0 &&
|
|
885
|
+
decl.initializer !== undefined &&
|
|
886
|
+
knownBufferProducer(lowerer, decl.initializer, seen));
|
|
887
|
+
}
|
|
888
|
+
if (!ts.isCallExpression(node))
|
|
889
|
+
return false;
|
|
890
|
+
const callee = node.expression;
|
|
891
|
+
const bi = ts.isIdentifier(callee)
|
|
892
|
+
? lowerer.builtinImportOf(callee)
|
|
893
|
+
: ts.isPropertyAccessExpression(callee)
|
|
894
|
+
? lowerer.builtinMemberOf(callee)
|
|
895
|
+
: null;
|
|
896
|
+
if (bi?.module === "crypto" && (bi.member === "randomBytes" || bi.member === "pbkdf2Sync"))
|
|
897
|
+
return true;
|
|
898
|
+
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "digest" || node.arguments.length !== 0)
|
|
899
|
+
return false;
|
|
900
|
+
const type = lowerer.mapTypeOf(lowerer.typeOf(callee.expression));
|
|
901
|
+
return type?.kind === "cryptoHash" || type?.kind === "cryptoHmac";
|
|
902
|
+
}
|
|
833
903
|
export function lowerBufferStaticCall(lowerer, call, access) {
|
|
834
904
|
if (call.questionDotToken || access.questionDotToken)
|
|
835
905
|
return null;
|
|
@@ -972,11 +1042,25 @@ export function lowerBufferStaticCall(lowerer, call, access) {
|
|
|
972
1042
|
// The type-predicate narrowing test. Lowered where it DECIDES
|
|
973
1043
|
// something: a union-typed argument with a Buffer arm becomes a
|
|
974
1044
|
// runtime tag test (tsc's narrowing then types the branches, the
|
|
975
|
-
// discriminated-union machinery). Statically-decided arguments
|
|
976
|
-
// fenced
|
|
977
|
-
//
|
|
1045
|
+
// discriminated-union machinery). Statically-decided arguments stay
|
|
1046
|
+
// fenced except for standard-library calls (and const aliases of
|
|
1047
|
+
// them) proven to return a real Buffer; those preserve evaluation and
|
|
1048
|
+
// fold true even though Buffer and Uint8Array share one IR storage.
|
|
978
1049
|
if (args.length === 1 && !ts.isSpreadElement(args[0])) {
|
|
1050
|
+
const source = args[0];
|
|
979
1051
|
const v = lowerer.lowerExpr(args[0]);
|
|
1052
|
+
// The bytes IR intentionally unifies Buffer and Uint8Array storage,
|
|
1053
|
+
// but these standard-library producers are known to return a real
|
|
1054
|
+
// Node Buffer. Preserve source evaluation and fold the predicate.
|
|
1055
|
+
if (knownBufferProducer(lowerer, source)) {
|
|
1056
|
+
return {
|
|
1057
|
+
kind: "seqExpr",
|
|
1058
|
+
stmts: [{ kind: "exprStmt", expr: v, loc: v.loc }],
|
|
1059
|
+
result: { kind: "boolLit", value: true, type: BOOL, loc },
|
|
1060
|
+
type: BOOL,
|
|
1061
|
+
loc,
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
980
1064
|
if (v.type.kind === "union") {
|
|
981
1065
|
const def = lowerer.unions.get(v.type.unionId);
|
|
982
1066
|
const tag = def ? def.arms.findIndex((a) => a.kind === "bytes" && a.elem === "u8") : -1;
|