@scriptc/compiler 0.3.0 → 0.3.1
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 +5 -2
- package/dist/backend/llvm/bigint-wrap.d.ts +4 -0
- package/dist/backend/llvm/bigint-wrap.js +590 -0
- package/dist/backend/llvm/bigint-wrap.js.map +1 -0
- package/dist/backend/llvm/blocks.d.ts +2 -0
- package/dist/backend/llvm/blocks.js +4 -0
- package/dist/backend/llvm/blocks.js.map +1 -1
- package/dist/backend/llvm/call-lifetimes.js +15 -4
- package/dist/backend/llvm/call-lifetimes.js.map +1 -1
- package/dist/backend/llvm/call-lifetimes.test.js +14 -3
- package/dist/backend/llvm/call-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/checked-narrows.test.js +1 -1
- package/dist/backend/llvm/checked-narrows.test.js.map +1 -1
- package/dist/backend/llvm/classes.js +57 -12
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/classes.test.js +4 -4
- package/dist/backend/llvm/classes.test.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +7 -5
- package/dist/backend/llvm/common.js +7 -5
- package/dist/backend/llvm/common.js.map +1 -1
- package/dist/backend/llvm/constant-callbacks.js +10 -28
- package/dist/backend/llvm/constant-callbacks.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.js +133 -45
- package/dist/backend/llvm/dense-array-access.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.test.js +53 -1
- package/dist/backend/llvm/dense-array-access.test.js.map +1 -1
- package/dist/backend/llvm/dyn.d.ts +2 -0
- package/dist/backend/llvm/dyn.js +4 -0
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +120 -6
- package/dist/backend/llvm/emitter.js +676 -77
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.test.js +14 -7
- package/dist/backend/llvm/emitter.test.js.map +1 -1
- package/dist/backend/llvm/expr-async.js +120 -43
- package/dist/backend/llvm/expr-async.js.map +1 -1
- package/dist/backend/llvm/expr-async.test.js +1 -1
- package/dist/backend/llvm/expr-async.test.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.js +51 -36
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-callbacks.js +72 -3
- package/dist/backend/llvm/expr-callbacks.js.map +1 -1
- package/dist/backend/llvm/expr-calls.d.ts +1 -1
- package/dist/backend/llvm/expr-calls.js +159 -30
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-calls.test.d.ts +1 -0
- package/dist/backend/llvm/expr-calls.test.js +132 -0
- package/dist/backend/llvm/expr-calls.test.js.map +1 -0
- package/dist/backend/llvm/expr-containers.js +13 -0
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-context.d.ts +2 -0
- package/dist/backend/llvm/expr-dispatch.js +3 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +26 -4
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.d.ts +7 -0
- package/dist/backend/llvm/expr-primitives.js +80 -22
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.js +95 -5
- package/dist/backend/llvm/expr-primitives.test.js.map +1 -1
- package/dist/backend/llvm/expr-records.d.ts +9 -0
- package/dist/backend/llvm/expr-records.js +134 -16
- package/dist/backend/llvm/expr-records.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.d.ts +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +80 -1
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.test.js +50 -1
- package/dist/backend/llvm/expr-stream-bridges.test.js.map +1 -1
- package/dist/backend/llvm/int32-abi.d.ts +31 -0
- package/dist/backend/llvm/int32-abi.js +62 -0
- package/dist/backend/llvm/int32-abi.js.map +1 -0
- package/dist/backend/llvm/int32-abi.test.d.ts +1 -0
- package/dist/backend/llvm/int32-abi.test.js +107 -0
- package/dist/backend/llvm/int32-abi.test.js.map +1 -0
- package/dist/backend/llvm/int32-locals.d.ts +30 -0
- package/dist/backend/llvm/int32-locals.js +95 -0
- package/dist/backend/llvm/int32-locals.js.map +1 -0
- package/dist/backend/llvm/integer-values.d.ts +4 -0
- package/dist/backend/llvm/integer-values.js +30 -1
- package/dist/backend/llvm/integer-values.js.map +1 -1
- package/dist/backend/llvm/integer-views.d.ts +8 -1
- package/dist/backend/llvm/integer-views.js +47 -2
- package/dist/backend/llvm/integer-views.js.map +1 -1
- package/dist/backend/llvm/lazy-captures.d.ts +16 -0
- package/dist/backend/llvm/lazy-captures.js +88 -2
- package/dist/backend/llvm/lazy-captures.js.map +1 -1
- package/dist/backend/llvm/lazy-captures.test.js +48 -0
- package/dist/backend/llvm/lazy-captures.test.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +14 -0
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-filesystem.js +3 -0
- package/dist/backend/llvm/lib-filesystem.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +7 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.js +21 -2
- package/dist/backend/llvm/local-array-reads.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.test.js +3 -2
- package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
- package/dist/backend/llvm/local-union-storage.test.js +2 -2
- package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
- package/dist/backend/llvm/map-read-lifetimes.test.js +2 -2
- package/dist/backend/llvm/map-read-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/reference-effects.js +2 -0
- package/dist/backend/llvm/reference-effects.js.map +1 -1
- package/dist/backend/llvm/reference-writes.d.ts +3 -0
- package/dist/backend/llvm/reference-writes.js +10 -2
- package/dist/backend/llvm/reference-writes.js.map +1 -1
- package/dist/backend/llvm/regex-matchers.d.ts +39 -0
- package/dist/backend/llvm/regex-matchers.js +1649 -0
- package/dist/backend/llvm/regex-matchers.js.map +1 -0
- package/dist/backend/llvm/regex-matchers.test.d.ts +1 -0
- package/dist/backend/llvm/regex-matchers.test.js +96 -0
- package/dist/backend/llvm/regex-matchers.test.js.map +1 -0
- package/dist/backend/llvm/shapes.d.ts +36 -1
- package/dist/backend/llvm/shapes.js +127 -14
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/stack-unions.test.js +1 -1
- package/dist/backend/llvm/stack-unions.test.js.map +1 -1
- package/dist/backend/llvm/string-construction.test.js +2 -2
- package/dist/backend/llvm/string-construction.test.js.map +1 -1
- package/dist/backend/llvm/string-lifetimes.test.js +5 -5
- package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/string-literal-equality.d.ts +22 -0
- package/dist/backend/llvm/string-literal-equality.js +78 -0
- package/dist/backend/llvm/string-literal-equality.js.map +1 -0
- package/dist/backend/llvm/switch-dispatch.js +59 -13
- package/dist/backend/llvm/switch-dispatch.js.map +1 -1
- package/dist/backend/llvm/switch-dispatch.test.js +71 -6
- package/dist/backend/llvm/switch-dispatch.test.js.map +1 -1
- package/dist/backend/llvm/union-retype.test.d.ts +1 -0
- package/dist/backend/llvm/union-retype.test.js +229 -0
- package/dist/backend/llvm/union-retype.test.js.map +1 -0
- package/dist/backend/llvm/wrapping-sums.d.ts +17 -0
- package/dist/backend/llvm/wrapping-sums.js +113 -0
- package/dist/backend/llvm/wrapping-sums.js.map +1 -0
- package/dist/backend/loop-polls.js +1 -0
- package/dist/backend/loop-polls.js.map +1 -1
- package/dist/backend/mangle.d.ts +9 -0
- package/dist/backend/mangle.js +15 -0
- package/dist/backend/mangle.js.map +1 -1
- package/dist/backend/may-throw.js +6 -3
- package/dist/backend/may-throw.js.map +1 -1
- package/dist/backend/runtime-abi.d.ts +2 -2
- package/dist/backend/runtime-abi.js +2 -2
- package/dist/backend/runtime-pack-targets.test.js +1 -1
- package/dist/backend/runtime-pack.test.js +1 -1
- package/dist/contracts/check.js +4 -0
- package/dist/contracts/check.js.map +1 -1
- package/dist/frontend/lowering/array-values.d.ts +14 -0
- package/dist/frontend/lowering/array-values.js +29 -0
- package/dist/frontend/lowering/array-values.js.map +1 -1
- package/dist/frontend/lowering/containers/array-callbacks.js +40 -0
- package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
- package/dist/frontend/lowering/containers/array-pipelines.d.ts +54 -0
- package/dist/frontend/lowering/containers/array-pipelines.js +1827 -0
- package/dist/frontend/lowering/containers/array-pipelines.js.map +1 -0
- package/dist/frontend/lowering/containers/exec-result-uses.d.ts +10 -0
- package/dist/frontend/lowering/containers/exec-result-uses.js +88 -0
- package/dist/frontend/lowering/containers/exec-result-uses.js.map +1 -0
- package/dist/frontend/lowering/containers/string-and-regexp.js +15 -7
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
- package/dist/frontend/lowering/containers/string-replacement.d.ts +2 -1
- package/dist/frontend/lowering/containers/string-replacement.js +32 -136
- package/dist/frontend/lowering/containers/string-replacement.js.map +1 -1
- package/dist/frontend/lowering/devirtualize.d.ts +33 -0
- package/dist/frontend/lowering/devirtualize.js +199 -0
- package/dist/frontend/lowering/devirtualize.js.map +1 -0
- package/dist/frontend/lowering/expressions/nullish-assignment.js +55 -7
- package/dist/frontend/lowering/expressions/nullish-assignment.js.map +1 -1
- package/dist/frontend/lowering/identifier-uses.d.ts +7 -0
- package/dist/frontend/lowering/identifier-uses.js +23 -0
- package/dist/frontend/lowering/identifier-uses.js.map +1 -0
- package/dist/frontend/lowering/iterator-adapters.js +51 -3
- package/dist/frontend/lowering/iterator-adapters.js.map +1 -1
- package/dist/frontend/lowering/lower-array-sort.js +13 -0
- package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +64 -30
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.js +1 -11
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-console.d.ts +14 -0
- package/dist/frontend/lowering/lower-console.js +195 -0
- package/dist/frontend/lowering/lower-console.js.map +1 -0
- package/dist/frontend/lowering/lower-exprs.js +135 -3
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-functions.js +7 -3
- package/dist/frontend/lowering/lower-functions.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.d.ts +10 -0
- package/dist/frontend/lowering/lower-generators.js +108 -41
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +4 -0
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.js +13 -10
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +25 -4
- package/dist/frontend/lowering/lowerer.js +120 -47
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/nan-coded-reads.d.ts +16 -0
- package/dist/frontend/lowering/nan-coded-reads.js +108 -1
- package/dist/frontend/lowering/nan-coded-reads.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-bounds.d.ts +4 -0
- package/dist/frontend/lowering/runtime-optional-bounds.js +2 -0
- package/dist/frontend/lowering/runtime-optional-bounds.js.map +1 -1
- package/dist/frontend/lowering/runtime-optional-bounds.test.js +27 -0
- package/dist/frontend/lowering/runtime-optional-bounds.test.js.map +1 -1
- package/dist/frontend/lowering/split-consumers.js +2 -18
- package/dist/frontend/lowering/split-consumers.js.map +1 -1
- package/dist/frontend/lowering/surfaces.js +3 -8
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/lowering/union-retag.d.ts +6 -1
- package/dist/frontend/lowering/union-retag.js +64 -1
- package/dist/frontend/lowering/union-retag.js.map +1 -1
- package/dist/frontend/lowering/union-retag.test.js +46 -0
- package/dist/frontend/lowering/union-retag.test.js.map +1 -1
- package/dist/frontend/type-mapper.js +16 -3
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/ir/builtin-effects.js +2 -0
- package/dist/ir/builtin-effects.js.map +1 -1
- package/dist/ir/builtin-signatures.d.ts +1 -1
- package/dist/ir/builtin-signatures.js +12 -1
- package/dist/ir/builtin-signatures.js.map +1 -1
- package/dist/ir/function-references.d.ts +12 -0
- package/dist/ir/function-references.js +29 -0
- package/dist/ir/function-references.js.map +1 -0
- package/dist/ir/function-references.test.d.ts +1 -0
- package/dist/ir/function-references.test.js +276 -0
- package/dist/ir/function-references.test.js.map +1 -0
- package/dist/ir/int32-slots.d.ts +7 -4
- package/dist/ir/int32-slots.js +214 -49
- package/dist/ir/int32-slots.js.map +1 -1
- package/dist/ir/int32-slots.test.js +38 -1
- package/dist/ir/int32-slots.test.js.map +1 -1
- package/dist/ir/integer-ranges.d.ts +4 -4
- package/dist/ir/integer-ranges.js +89 -64
- package/dist/ir/integer-ranges.js.map +1 -1
- package/dist/ir/integer-ranges.test.js +71 -9
- package/dist/ir/integer-ranges.test.js.map +1 -1
- package/dist/ir/intrinsic-signatures.js +1 -0
- package/dist/ir/intrinsic-signatures.js.map +1 -1
- package/dist/ir/ir.d.ts +52 -6
- package/dist/ir/ir.js +1 -0
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/runtime-features.js +3 -2
- package/dist/ir/runtime-features.js.map +1 -1
- package/dist/ir/traverse.js +4 -0
- package/dist/ir/traverse.js.map +1 -1
- package/dist/ir/validate.js +57 -6
- package/dist/ir/validate.js.map +1 -1
- package/dist/ir/validate.test.js +25 -7
- package/dist/ir/validate.test.js.map +1 -1
- package/package.json +20 -20
- package/surface-manifest.json +1 -17
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as ts from "../ts7/adapter.js";
|
|
2
|
+
import { type IrExpr, type SrcLoc } from "../../ir/ir.js";
|
|
3
|
+
import { type Lowerer } from "./lowerer.js";
|
|
4
|
+
/** `new Console(stdout[, stderr][, ignoreErrors])` and `new
|
|
5
|
+
* Console({ stdout, stderr, ignoreErrors })`. Arguments and option
|
|
6
|
+
* initializers evaluate in source order into hidden locals before the
|
|
7
|
+
* handle exists (Node evaluates them before the constructor body); an
|
|
8
|
+
* absent stderr shares stdout's target. */
|
|
9
|
+
export declare function lowerConsoleNew(lowerer: Lowerer, expr: ts.NewExpression): IrExpr | null;
|
|
10
|
+
/** `c.log(...)` and the other output members on a stdlib-Console-typed
|
|
11
|
+
* receiver that is not the global console itself (that path keeps its
|
|
12
|
+
* direct console lowering): the receiver evaluates first, then the
|
|
13
|
+
* util.format rendering of the arguments, then one native write. */
|
|
14
|
+
export declare function lowerConsoleInstanceCall(lowerer: Lowerer, call: ts.CallExpression, loc: SrcLoc): IrExpr | null;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import * as ts from "../ts7/adapter.js";
|
|
2
|
+
import { BOOL, DYN, VOID, } from "../../ir/ir.js";
|
|
3
|
+
import { boolLit, numLit, varRef } from "../../ir/build.js";
|
|
4
|
+
import { locOf } from "../program.js";
|
|
5
|
+
import {} from "./lowerer.js";
|
|
6
|
+
import { lowerFormatCall } from "./lower-inspect.js";
|
|
7
|
+
import { streamSidesOf } from "./lower-stream.js";
|
|
8
|
+
/** node:console Console instances: a native handle (the checked-dynamic
|
|
9
|
+
* representation the stdlib Console type maps to) over two output
|
|
10
|
+
* targets — process.stdout/process.stderr, or writable streams — plus
|
|
11
|
+
* the ignoreErrors flag. The log/info/debug (stdout) and error/warn
|
|
12
|
+
* (stderr) members lower through util.format into ONE write of the
|
|
13
|
+
* formatted line, exactly Node's kWriteToConsole; the remaining Console
|
|
14
|
+
* surface stays fenced like the global console's. */
|
|
15
|
+
const OUTPUT_MEMBERS = new Map([
|
|
16
|
+
["log", false],
|
|
17
|
+
["info", false],
|
|
18
|
+
["debug", false],
|
|
19
|
+
["error", true],
|
|
20
|
+
["warn", true],
|
|
21
|
+
]);
|
|
22
|
+
const OPTION_KEYS = new Set(["stdout", "stderr", "ignoreErrors"]);
|
|
23
|
+
function isConsoleCtor(lowerer, callee) {
|
|
24
|
+
if (ts.isIdentifier(callee)) {
|
|
25
|
+
const bi = lowerer.builtinImportOf(callee);
|
|
26
|
+
return bi?.module === "console" && bi.member === "Console";
|
|
27
|
+
}
|
|
28
|
+
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== "Console")
|
|
29
|
+
return false;
|
|
30
|
+
return (lowerer.isStdlibGlobal(callee.expression, "console") ||
|
|
31
|
+
lowerer.builtinNamespaceModuleOf(callee.expression) === "console");
|
|
32
|
+
}
|
|
33
|
+
function isUndefinedArg(node) {
|
|
34
|
+
return (node === undefined ||
|
|
35
|
+
(ts.isIdentifier(node) && node.text === "undefined") ||
|
|
36
|
+
ts.isVoidExpression(node));
|
|
37
|
+
}
|
|
38
|
+
/** `new Console(stdout[, stderr][, ignoreErrors])` and `new
|
|
39
|
+
* Console({ stdout, stderr, ignoreErrors })`. Arguments and option
|
|
40
|
+
* initializers evaluate in source order into hidden locals before the
|
|
41
|
+
* handle exists (Node evaluates them before the constructor body); an
|
|
42
|
+
* absent stderr shares stdout's target. */
|
|
43
|
+
export function lowerConsoleNew(lowerer, expr) {
|
|
44
|
+
if (!isConsoleCtor(lowerer, expr.expression))
|
|
45
|
+
return null;
|
|
46
|
+
const loc = locOf(expr);
|
|
47
|
+
const args = expr.arguments ?? [];
|
|
48
|
+
const entries = [];
|
|
49
|
+
const first = args[0];
|
|
50
|
+
if (first && ts.isObjectLiteralExpression(first)) {
|
|
51
|
+
for (const prop of first.properties) {
|
|
52
|
+
let name = null;
|
|
53
|
+
let value = null;
|
|
54
|
+
if (ts.isPropertyAssignment(prop) &&
|
|
55
|
+
(ts.isIdentifier(prop.name) || ts.isStringLiteral(prop.name))) {
|
|
56
|
+
name = prop.name.text;
|
|
57
|
+
value = prop.initializer;
|
|
58
|
+
}
|
|
59
|
+
else if (ts.isShorthandPropertyAssignment(prop)) {
|
|
60
|
+
name = prop.name.text;
|
|
61
|
+
value = prop.name;
|
|
62
|
+
}
|
|
63
|
+
if (name === null || value === null || !OPTION_KEYS.has(name)) {
|
|
64
|
+
lowerer.noLowering("Console options other than stdout, stderr, and ignoreErrors", prop, "colorMode, inspectOptions, and groupIndentation have no lowering yet");
|
|
65
|
+
}
|
|
66
|
+
entries.push({ role: name, node: value });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
entries.push({ role: "stdout", node: args[0] });
|
|
71
|
+
entries.push({ role: "stderr", node: args[1] });
|
|
72
|
+
entries.push({ role: "ignoreErrors", node: args[2] });
|
|
73
|
+
}
|
|
74
|
+
const stmts = [];
|
|
75
|
+
const target = (node, role) => {
|
|
76
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
77
|
+
const member = lowerer.stdlibGlobalMember(node, "process");
|
|
78
|
+
if (member === "stdout")
|
|
79
|
+
return { fd: 1 };
|
|
80
|
+
if (member === "stderr")
|
|
81
|
+
return { fd: 2 };
|
|
82
|
+
}
|
|
83
|
+
const value = lowerer.lowerExpr(node);
|
|
84
|
+
const info = value.type.kind === "object" ? lowerer.classes.get(value.type.className) : undefined;
|
|
85
|
+
const sides = streamSidesOf(lowerer, info);
|
|
86
|
+
if (sides !== "w" && sides !== "rw") {
|
|
87
|
+
lowerer.noLowering(`a Console ${role} of type '${lowerer.fmt(value.type)}'`, node, "process.stdout, process.stderr, and node:stream writables (Writable, Duplex, Transform, PassThrough, and their subclasses) are the supported Console streams");
|
|
88
|
+
}
|
|
89
|
+
const local = lowerer.declareHiddenLocal(`%console${role}`, value.type);
|
|
90
|
+
stmts.push({ kind: "varDecl", localId: local.id, init: value, loc });
|
|
91
|
+
return { local: local.id, type: value.type };
|
|
92
|
+
};
|
|
93
|
+
let out = null;
|
|
94
|
+
let err = null;
|
|
95
|
+
let ignore = null;
|
|
96
|
+
for (const entry of entries) {
|
|
97
|
+
const node = entry.node;
|
|
98
|
+
if (isUndefinedArg(node)) {
|
|
99
|
+
// `void expr` still evaluates its operand.
|
|
100
|
+
if (node !== undefined && ts.isVoidExpression(node)) {
|
|
101
|
+
stmts.push({ kind: "exprStmt", expr: lowerer.lowerExpr(node), loc });
|
|
102
|
+
}
|
|
103
|
+
if (entry.role === "stdout")
|
|
104
|
+
out = null;
|
|
105
|
+
else if (entry.role === "stderr")
|
|
106
|
+
err = null;
|
|
107
|
+
else
|
|
108
|
+
ignore = null;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (entry.role === "stdout") {
|
|
112
|
+
out = target(node, "stdout");
|
|
113
|
+
}
|
|
114
|
+
else if (entry.role === "stderr") {
|
|
115
|
+
err = target(node, "stderr");
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const value = lowerer.lowerExpr(node);
|
|
119
|
+
if (value.type.kind !== "bool") {
|
|
120
|
+
lowerer.noLowering(`ignoreErrors of type '${lowerer.fmt(value.type)}'`, node, "pass a boolean");
|
|
121
|
+
}
|
|
122
|
+
const local = lowerer.declareHiddenLocal("%consoleIgnoreErrors", BOOL);
|
|
123
|
+
stmts.push({ kind: "varDecl", localId: local.id, init: value, loc });
|
|
124
|
+
ignore = varRef(local.id, BOOL, loc);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (out === null) {
|
|
128
|
+
return lowerer.noLowering("new Console without a stdout stream", expr, "pass the stdout stream");
|
|
129
|
+
}
|
|
130
|
+
const stdoutTarget = out;
|
|
131
|
+
const stderrTarget = err ?? stdoutTarget;
|
|
132
|
+
const handle = lowerer.declareHiddenLocal("%console", DYN);
|
|
133
|
+
const fdOf = (t) => numLit("fd" in t ? t.fd : 0, loc);
|
|
134
|
+
stmts.push({
|
|
135
|
+
kind: "varDecl",
|
|
136
|
+
localId: handle.id,
|
|
137
|
+
init: {
|
|
138
|
+
kind: "libCall",
|
|
139
|
+
fn: "console.new",
|
|
140
|
+
args: [fdOf(stdoutTarget), fdOf(stderrTarget), ignore ?? boolLit(true, loc)],
|
|
141
|
+
type: DYN,
|
|
142
|
+
loc,
|
|
143
|
+
},
|
|
144
|
+
loc,
|
|
145
|
+
});
|
|
146
|
+
const targets = [stdoutTarget, stderrTarget];
|
|
147
|
+
for (let which = 0; which < targets.length; which++) {
|
|
148
|
+
const t = targets[which];
|
|
149
|
+
if (!("local" in t))
|
|
150
|
+
continue;
|
|
151
|
+
stmts.push({
|
|
152
|
+
kind: "exprStmt",
|
|
153
|
+
expr: {
|
|
154
|
+
kind: "libCall",
|
|
155
|
+
fn: "console.bind",
|
|
156
|
+
args: [varRef(handle.id, DYN, loc), numLit(which, loc), varRef(t.local, t.type, loc)],
|
|
157
|
+
type: VOID,
|
|
158
|
+
loc,
|
|
159
|
+
},
|
|
160
|
+
loc,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return { kind: "seqExpr", stmts, result: varRef(handle.id, DYN, loc), type: DYN, loc };
|
|
164
|
+
}
|
|
165
|
+
/** `c.log(...)` and the other output members on a stdlib-Console-typed
|
|
166
|
+
* receiver that is not the global console itself (that path keeps its
|
|
167
|
+
* direct console lowering): the receiver evaluates first, then the
|
|
168
|
+
* util.format rendering of the arguments, then one native write. */
|
|
169
|
+
export function lowerConsoleInstanceCall(lowerer, call, loc) {
|
|
170
|
+
if (call.questionDotToken || !ts.isPropertyAccessExpression(call.expression))
|
|
171
|
+
return null;
|
|
172
|
+
const access = call.expression;
|
|
173
|
+
if (access.questionDotToken)
|
|
174
|
+
return null;
|
|
175
|
+
const recvType = lowerer.typeOf(access.expression);
|
|
176
|
+
const sym = recvType.getAliasSymbol() ?? recvType.getSymbol();
|
|
177
|
+
if (!sym || sym.name !== "Console" || !lowerer.isStdlibSymbol(sym))
|
|
178
|
+
return null;
|
|
179
|
+
const toStderr = OUTPUT_MEMBERS.get(access.name.text);
|
|
180
|
+
if (toStderr === undefined) {
|
|
181
|
+
lowerer.noLowering(`Console.${access.name.text}`, call, "log, info, debug, error, and warn are the lowered Console members");
|
|
182
|
+
}
|
|
183
|
+
const receiver = lowerer.lowerExpr(access.expression);
|
|
184
|
+
if (receiver.type.kind !== "dyn")
|
|
185
|
+
return null;
|
|
186
|
+
const formatted = lowerFormatCall(lowerer, call, loc, false);
|
|
187
|
+
return {
|
|
188
|
+
kind: "libCall",
|
|
189
|
+
fn: "console.write",
|
|
190
|
+
args: [receiver, formatted, boolLit(toStderr, loc)],
|
|
191
|
+
type: VOID,
|
|
192
|
+
loc,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=lower-console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lower-console.js","sourceRoot":"","sources":["../../../src/frontend/lowering/lower-console.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EACL,IAAI,EACJ,GAAG,EAKH,IAAI,GACL,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAgB,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;qDAMqD;AAErD,MAAM,cAAc,GAAiC,IAAI,GAAG,CAAC;IAC3D,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,MAAM,EAAE,KAAK,CAAC;IACf,CAAC,OAAO,EAAE,KAAK,CAAC;IAChB,CAAC,OAAO,EAAE,IAAI,CAAC;IACf,CAAC,MAAM,EAAE,IAAI,CAAC;CACf,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;AAElE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iag, unsupportedDiag, } from "../../diagnostics/diagnostic.js";
|
|
32
32
|
import { PoisonError, dynFallbackType, jsFuncNameOf, neverTaintedJsType, own } from "./lowerer.js";
|
|
33
33
|
import { lowerCollectionSpread } from "./containers/collection-methods.js";
|
|
34
|
-
import { arrayValueRead, arrayValueStore, arrayValueType, lowerSafeIndexRead, tryLowerIndexTruthiness, tryLowerNumericIndexRead, lowerSafeBytesRead, } from "./array-values.js";
|
|
34
|
+
import { arrayNumberRead, arrayValueRead, arrayValueStore, arrayValueType, lowerSafeIndexRead, tryLowerIndexTruthiness, tryLowerNumericIndexRead, tryLowerBytesReadNumberEquality, lowerSafeBytesRead, } from "./array-values.js";
|
|
35
35
|
import { strCharsCall } from "./containers/array-construction.js";
|
|
36
36
|
import { lowerOptionalStringIndex } from "./string-index.js";
|
|
37
37
|
import { tryLowerIndexedComparison } from "./indexed-comparison.js";
|
|
@@ -2772,6 +2772,9 @@ export function maybeNarrow(lowerer, expr, node) {
|
|
|
2772
2772
|
if (symbol && lowerer.unstableSwitchBindings.has(symbol))
|
|
2773
2773
|
return expr;
|
|
2774
2774
|
}
|
|
2775
|
+
if (ts.isPropertyAccessExpression(node) &&
|
|
2776
|
+
getterResultHoldsUndeclaredUndefined(lowerer, node, expr))
|
|
2777
|
+
return expr;
|
|
2775
2778
|
const narrowedTs = lowerer.typeOf(node);
|
|
2776
2779
|
const narrowed = lowerer.mapTypeOf(narrowedTs);
|
|
2777
2780
|
// `Array.isArray(u)` on a union with one readonly array/tuple arm: the
|
|
@@ -2880,6 +2883,27 @@ export function maybeNarrow(lowerer, expr, node) {
|
|
|
2880
2883
|
loc: expr.loc,
|
|
2881
2884
|
};
|
|
2882
2885
|
}
|
|
2886
|
+
/** A getter read whose runtime result can be undefined (an unchecked
|
|
2887
|
+
* element read in its body, or in another member of its override family)
|
|
2888
|
+
* although its declared type cannot. The checker's type for the read is
|
|
2889
|
+
* then no narrowing proof, so the read keeps the getter's result. */
|
|
2890
|
+
function getterResultHoldsUndeclaredUndefined(lowerer, node, expr) {
|
|
2891
|
+
if (expr.type.kind !== "union" || lowerer.armTag(expr.type.unionId, UNDEFINED_T) < 0)
|
|
2892
|
+
return false;
|
|
2893
|
+
const getter = (expr.kind === "virtualCall" && expr.method.startsWith("get:")) ||
|
|
2894
|
+
(expr.kind === "call" && expr.callee.includes(".get:"));
|
|
2895
|
+
if (!getter)
|
|
2896
|
+
return false;
|
|
2897
|
+
const symbol = lowerer.checker.getSymbolAtLocation(node.name);
|
|
2898
|
+
if (!symbol || (symbol.flags & ts.SymbolFlags.GetAccessor) === 0)
|
|
2899
|
+
return false;
|
|
2900
|
+
const declared = lowerer.checker.getTypeOfSymbol(symbol);
|
|
2901
|
+
const holdsUndefined = (type) => (type.flags &
|
|
2902
|
+
(ts.TypeFlags.Undefined | ts.TypeFlags.Void | ts.TypeFlags.Any | ts.TypeFlags.Unknown)) !==
|
|
2903
|
+
0;
|
|
2904
|
+
return !(holdsUndefined(declared) ||
|
|
2905
|
+
(declared.isUnionType() && ts.constituentTypes(declared).some(holdsUndefined)));
|
|
2906
|
+
}
|
|
2883
2907
|
/** The checked form of maybeNarrow's arm extraction for a narrowing the
|
|
2884
2908
|
* checker may hold past code that replaced the value (a call clearing the
|
|
2885
2909
|
* property; see NarrowingStability). Every other arm throws the TypeError
|
|
@@ -6330,7 +6354,13 @@ export function lowerElementCompound(lowerer, expr, op) {
|
|
|
6330
6354
|
const receiverRef = () => varRef(receiverLocal.id, receiver.type, loc);
|
|
6331
6355
|
const indexRef = () => varRef(indexLocal.id, F64, loc);
|
|
6332
6356
|
const oldValue = receiver.type.kind === "array"
|
|
6333
|
-
?
|
|
6357
|
+
? receiver.type.elem.kind === "f64"
|
|
6358
|
+
? // Every numeric operator applies ToNumber to the old value, so a
|
|
6359
|
+
// missing element is NaN without materializing `number | undefined`.
|
|
6360
|
+
arrayNumberRead(receiverRef(), indexRef(), locOf(target))
|
|
6361
|
+
: receiver.type.elem.kind === "string" && op === "+"
|
|
6362
|
+
? arrayStringOperand(receiverRef(), indexRef(), locOf(target))
|
|
6363
|
+
: arrayValueRead(lowerer, receiverRef(), indexRef(), receiver.type.elem, locOf(target))
|
|
6334
6364
|
: {
|
|
6335
6365
|
// An invalid index reads undefined in Node, which every numeric
|
|
6336
6366
|
// compound operator turns into NaN; the write is then ignored.
|
|
@@ -6407,6 +6437,25 @@ export function lowerElementCompound(lowerer, expr, op) {
|
|
|
6407
6437
|
loc,
|
|
6408
6438
|
};
|
|
6409
6439
|
}
|
|
6440
|
+
/** ToString of one stabilized `string[]` element read for `+=`: a missing
|
|
6441
|
+
* element concatenates as "undefined". */
|
|
6442
|
+
function arrayStringOperand(arr, index, loc) {
|
|
6443
|
+
return {
|
|
6444
|
+
kind: "ternary",
|
|
6445
|
+
cond: {
|
|
6446
|
+
kind: "bin",
|
|
6447
|
+
op: "===",
|
|
6448
|
+
left: { kind: "arrayState", arr, index, type: F64, loc },
|
|
6449
|
+
right: { kind: "numLit", value: 1, type: F64, loc },
|
|
6450
|
+
type: BOOL,
|
|
6451
|
+
loc,
|
|
6452
|
+
},
|
|
6453
|
+
then: { kind: "arrayGet", arr, index, type: STRING, loc },
|
|
6454
|
+
else_: strLit("undefined", loc),
|
|
6455
|
+
type: STRING,
|
|
6456
|
+
loc,
|
|
6457
|
+
};
|
|
6458
|
+
}
|
|
6410
6459
|
/** Checked member assignment evaluates the reference before its RHS and
|
|
6411
6460
|
* yields the original assigned value, including in a chained assignment. */
|
|
6412
6461
|
function lowerDynMemberAssignment(lowerer, expr, recv) {
|
|
@@ -7443,6 +7492,13 @@ export function lowerIncDec(lowerer, expr, prefix) {
|
|
|
7443
7492
|
return varRef(local.id, value.type, loc);
|
|
7444
7493
|
};
|
|
7445
7494
|
const finish = (read, write) => {
|
|
7495
|
+
if (read.type.kind === "bigint") {
|
|
7496
|
+
const old = save(read, "%incrementOld");
|
|
7497
|
+
const next = save(bigintStep(op, old, loc), "%incrementNext");
|
|
7498
|
+
stmts.push(write(next));
|
|
7499
|
+
const result = prefix ? next : old;
|
|
7500
|
+
return { kind: "seqExpr", stmts, result, type: result.type, loc };
|
|
7501
|
+
}
|
|
7446
7502
|
const old = save(read.type.kind === "f64"
|
|
7447
7503
|
? read
|
|
7448
7504
|
: {
|
|
@@ -7486,7 +7542,9 @@ export function lowerIncDec(lowerer, expr, prefix) {
|
|
|
7486
7542
|
lowerer.unsupported("SC1090", access, "incrementing non-number array keys");
|
|
7487
7543
|
const type = raw.type;
|
|
7488
7544
|
const read = type.kind === "array"
|
|
7489
|
-
?
|
|
7545
|
+
? type.elem.kind === "f64"
|
|
7546
|
+
? arrayNumberRead(receiver, index, loc)
|
|
7547
|
+
: arrayValueRead(lowerer, receiver, index, type.elem, loc)
|
|
7490
7548
|
: {
|
|
7491
7549
|
kind: "bytesIntrinsic",
|
|
7492
7550
|
method: "get",
|
|
@@ -7633,6 +7691,26 @@ export function lowerIncDecTarget(lowerer, expr, target, prefix) {
|
|
|
7633
7691
|
};
|
|
7634
7692
|
}
|
|
7635
7693
|
}
|
|
7694
|
+
if (target.type.kind === "bigint") {
|
|
7695
|
+
const old = lowerer.declareHiddenLocal("%bigintOld", BIGINT_T);
|
|
7696
|
+
const next = lowerer.declareHiddenLocal("%bigintNext", BIGINT_T);
|
|
7697
|
+
return {
|
|
7698
|
+
kind: "seqExpr",
|
|
7699
|
+
stmts: [
|
|
7700
|
+
{ kind: "varDecl", localId: old.id, init: varRef(target.id, BIGINT_T, loc), loc },
|
|
7701
|
+
{
|
|
7702
|
+
kind: "varDecl",
|
|
7703
|
+
localId: next.id,
|
|
7704
|
+
init: bigintStep(op, varRef(old.id, BIGINT_T, loc), loc),
|
|
7705
|
+
loc,
|
|
7706
|
+
},
|
|
7707
|
+
{ kind: "assign", localId: target.id, value: varRef(next.id, BIGINT_T, loc), loc },
|
|
7708
|
+
],
|
|
7709
|
+
result: varRef(prefix ? next.id : old.id, BIGINT_T, loc),
|
|
7710
|
+
type: BIGINT_T,
|
|
7711
|
+
loc,
|
|
7712
|
+
};
|
|
7713
|
+
}
|
|
7636
7714
|
if (target.type.kind !== "f64")
|
|
7637
7715
|
lowerer.unsupported("SC1043", expr);
|
|
7638
7716
|
return { kind: "incDec", op, prefix, localId: target.id, type: F64, loc };
|
|
@@ -7663,6 +7741,43 @@ function seqExprSafeStmt(s) {
|
|
|
7663
7741
|
return false;
|
|
7664
7742
|
}
|
|
7665
7743
|
}
|
|
7744
|
+
const BIGINT_COMPOUND = {
|
|
7745
|
+
"+": "bigint.add",
|
|
7746
|
+
"-": "bigint.sub",
|
|
7747
|
+
"*": "bigint.mul",
|
|
7748
|
+
"/": "bigint.div",
|
|
7749
|
+
"%": "bigint.mod",
|
|
7750
|
+
"**": "bigint.pow",
|
|
7751
|
+
"&": "bigint.and",
|
|
7752
|
+
"|": "bigint.or",
|
|
7753
|
+
"^": "bigint.xor",
|
|
7754
|
+
"<<": "bigint.shl",
|
|
7755
|
+
">>": "bigint.shr",
|
|
7756
|
+
};
|
|
7757
|
+
/** `old op= rhs` over two bigints: the binary operator's libCall. Null
|
|
7758
|
+
* for other operand types (and `>>>`, which BigInt does not have). */
|
|
7759
|
+
function bigintCompoundValue(op, left, right, loc) {
|
|
7760
|
+
if (left.type.kind !== "bigint" || right.type.kind !== "bigint" || op === ">>>")
|
|
7761
|
+
return null;
|
|
7762
|
+
return { kind: "libCall", fn: BIGINT_COMPOUND[op], args: [left, right], type: BIGINT_T, loc };
|
|
7763
|
+
}
|
|
7764
|
+
/** `++`/`--` on a bigint value: old ± 1n. */
|
|
7765
|
+
function bigintStep(op, old, loc) {
|
|
7766
|
+
const one = {
|
|
7767
|
+
kind: "libCall",
|
|
7768
|
+
fn: "bigint.parse",
|
|
7769
|
+
args: [{ kind: "strLit", value: "1", type: STRING, loc }],
|
|
7770
|
+
type: BIGINT_T,
|
|
7771
|
+
loc,
|
|
7772
|
+
};
|
|
7773
|
+
return {
|
|
7774
|
+
kind: "libCall",
|
|
7775
|
+
fn: op === "+" ? "bigint.add" : "bigint.sub",
|
|
7776
|
+
args: [old, one],
|
|
7777
|
+
type: BIGINT_T,
|
|
7778
|
+
loc,
|
|
7779
|
+
};
|
|
7780
|
+
}
|
|
7666
7781
|
export function lowerCompoundValueToTarget(lowerer, expr, compound, target) {
|
|
7667
7782
|
const loc = locOf(expr);
|
|
7668
7783
|
const read = {
|
|
@@ -7706,6 +7821,9 @@ export function lowerCompoundValueToTarget(lowerer, expr, compound, target) {
|
|
|
7706
7821
|
};
|
|
7707
7822
|
return lowerer.coerceInto(expr, computed, target.type);
|
|
7708
7823
|
}
|
|
7824
|
+
const bigint = bigintCompoundValue(compound, read, rhs, loc);
|
|
7825
|
+
if (bigint)
|
|
7826
|
+
return bigint;
|
|
7709
7827
|
lowerer.unsupported("SC1043", expr);
|
|
7710
7828
|
}
|
|
7711
7829
|
/** Equality of two NaN-coded values (nan-coded-reads.ts), each of which may
|
|
@@ -8075,6 +8193,16 @@ export function lowerBinary(lowerer, expr) {
|
|
|
8075
8193
|
left = storedLeft;
|
|
8076
8194
|
if (storedRight !== null && left.type.kind !== "union")
|
|
8077
8195
|
right = storedRight;
|
|
8196
|
+
// A typed-array read compared with a plain number needs no
|
|
8197
|
+
// `number | undefined` box.
|
|
8198
|
+
const fusedLeft = tryLowerBytesReadNumberEquality(lowerer, left, right, expr.right);
|
|
8199
|
+
if (fusedLeft)
|
|
8200
|
+
left = fusedLeft;
|
|
8201
|
+
else {
|
|
8202
|
+
const fusedRight = tryLowerBytesReadNumberEquality(lowerer, right, left, expr.left);
|
|
8203
|
+
if (fusedRight)
|
|
8204
|
+
right = fusedRight;
|
|
8205
|
+
}
|
|
8078
8206
|
}
|
|
8079
8207
|
if (strictEquality && (left.type.kind === "caught" || right.type.kind === "caught")) {
|
|
8080
8208
|
if (left.type.kind === "caught")
|
|
@@ -12866,6 +12994,7 @@ function lowerFieldCompoundValue(lowerer, access, op, rhsNode, loc) {
|
|
|
12866
12994
|
: lowerOptionalNumber(lowerer, rhs, loc);
|
|
12867
12995
|
let value;
|
|
12868
12996
|
const numericRead = lowerOptionalNumber(lowerer, read, loc, access);
|
|
12997
|
+
const bigintValue = rhsNode ? bigintCompoundValue(op, read, rhs, loc) : null;
|
|
12869
12998
|
if (op === "+" && read.type.kind === "string") {
|
|
12870
12999
|
value = {
|
|
12871
13000
|
kind: "strConcat",
|
|
@@ -12878,6 +13007,9 @@ function lowerFieldCompoundValue(lowerer, access, op, rhsNode, loc) {
|
|
|
12878
13007
|
else if (numericRead.type.kind === "f64" && numericRhs.type.kind === "f64") {
|
|
12879
13008
|
value = { kind: "bin", op, left: numericRead, right: numericRhs, type: F64, loc };
|
|
12880
13009
|
}
|
|
13010
|
+
else if (bigintValue) {
|
|
13011
|
+
value = bigintValue;
|
|
13012
|
+
}
|
|
12881
13013
|
else if (target.fieldType.kind === "dyn" && isJsSourceFile(access.getSourceFile())) {
|
|
12882
13014
|
const numeric = ["-", "*", "/", "%", "**"].includes(op);
|
|
12883
13015
|
const left = lowerer.coerceToExpected(read, DYN);
|