@scriptc/compiler 0.1.1 → 0.1.3
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 +104 -31
- package/ambient/scriptc.d.ts +2 -1
- package/dist/backend/build-cache.js.map +1 -1
- package/dist/backend/c/async.d.ts +5 -0
- package/dist/backend/c/async.js +81 -2
- package/dist/backend/c/async.js.map +1 -1
- package/dist/backend/c/c-emitter.d.ts +25 -10
- package/dist/backend/c/c-emitter.js +74 -22
- 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 +371 -18
- package/dist/backend/c/exprs.js.map +1 -1
- package/dist/backend/c/island.js.map +1 -1
- package/dist/backend/c/may-throw.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/stmts.d.ts +3 -5
- package/dist/backend/c/stmts.js +58 -17
- package/dist/backend/c/stmts.js.map +1 -1
- package/dist/backend/c/types.d.ts +4 -0
- package/dist/backend/c/types.js +18 -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 +63 -16
- package/dist/backend/c/walkers.js.map +1 -1
- package/dist/backend/external-c.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 +1 -1
- package/dist/backend/link-plan.js +5 -1
- package/dist/backend/link-plan.js.map +1 -1
- package/dist/backend/linker.js.map +1 -1
- package/dist/backend/llvm/blocks.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 +80 -16
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.js +132 -25
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-async.js +85 -3
- package/dist/backend/llvm/expr-async.js.map +1 -1
- package/dist/backend/llvm/expr-bytes.js.map +1 -1
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-context.d.ts +5 -0
- package/dist/backend/llvm/expr-control.js.map +1 -1
- package/dist/backend/llvm/expr-dispatch.js.map +1 -1
- package/dist/backend/llvm/expr-dynamic.js +15 -3
- package/dist/backend/llvm/expr-dynamic.js.map +1 -1
- package/dist/backend/llvm/expr-island.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.js +8 -0
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- 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 +222 -10
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +3 -0
- package/dist/backend/llvm/expr-stream-callbacks.js +53 -0
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -1
- package/dist/backend/llvm/lib-dispatch.js +24 -0
- package/dist/backend/llvm/lib-dispatch.js.map +1 -1
- package/dist/backend/llvm/lib-process.js +50 -5
- package/dist/backend/llvm/lib-process.js.map +1 -1
- package/dist/backend/llvm/lib-shared.js +64 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -1
- package/dist/backend/llvm/lib-stream.js +6 -3
- 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/split.js.map +1 -1
- package/dist/backend/llvm/unsupported.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-codegen.js.map +1 -1
- package/dist/backend/native-codegen.test.js +2 -0
- package/dist/backend/native-codegen.test.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 +8 -6
- package/dist/backend/native-toolchain.js +28 -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.js.map +1 -1
- package/dist/backend/runtime-pack.test.js +1 -0
- package/dist/backend/runtime-pack.test.js.map +1 -1
- package/dist/backend/targets.d.ts +5 -0
- package/dist/backend/targets.js +9 -0
- package/dist/backend/targets.js.map +1 -1
- package/dist/backend/targets.test.js +6 -1
- package/dist/backend/targets.test.js.map +1 -1
- package/dist/backend/vendor-archives.js.map +1 -1
- package/dist/compat/fetch-profile.js +4 -2
- package/dist/compat/fetch-profile.js.map +1 -1
- package/dist/coverage/report.js.map +1 -1
- package/dist/coverage/surface-manifest.js +13 -0
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +6 -5
- package/dist/diagnostics/diagnostic.js +10 -9
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/diagnostics/render.js.map +1 -1
- package/dist/executable/executable-cache.d.ts +1 -0
- package/dist/executable/executable-cache.js +1 -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/ffi/ffi-manifest.js.map +1 -1
- package/dist/frontend/cjs-lexer.js.map +1 -1
- package/dist/frontend/dts-paths.js.map +1 -1
- package/dist/frontend/input-tracker.d.ts +10 -0
- package/dist/frontend/input-tracker.js +26 -3
- package/dist/frontend/input-tracker.js.map +1 -1
- package/dist/frontend/input-tracker.test.js +8 -1
- package/dist/frontend/input-tracker.test.js.map +1 -1
- package/dist/frontend/lib-contract.js.map +1 -1
- package/dist/frontend/lowering/array-values.d.ts +4 -0
- package/dist/frontend/lowering/array-values.js +18 -2
- package/dist/frontend/lowering/array-values.js.map +1 -1
- package/dist/frontend/lowering/callback-arg.js.map +1 -1
- package/dist/frontend/lowering/containers/bytes.d.ts +31 -0
- package/dist/frontend/lowering/containers/bytes.js +1105 -0
- package/dist/frontend/lowering/containers/bytes.js.map +1 -0
- package/dist/frontend/lowering/containers/string-and-regexp.d.ts +17 -0
- package/dist/frontend/lowering/containers/string-and-regexp.js +345 -0
- package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.d.ts +13 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.js +76 -0
- package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -0
- package/dist/frontend/lowering/expressions/object-literals.d.ts +44 -0
- package/dist/frontend/lowering/expressions/object-literals.js +1815 -0
- package/dist/frontend/lowering/expressions/object-literals.js.map +1 -0
- package/dist/frontend/lowering/expressions/optional-chains.d.ts +31 -0
- package/dist/frontend/lowering/expressions/optional-chains.js +382 -0
- package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -0
- package/dist/frontend/lowering/expressions/try-lower-expression.d.ts +7 -0
- package/dist/frontend/lowering/expressions/try-lower-expression.js +26 -0
- package/dist/frontend/lowering/expressions/try-lower-expression.js.map +1 -0
- package/dist/frontend/lowering/lib-boundary.js +7 -2
- package/dist/frontend/lowering/lib-boundary.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.js +16 -10
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-async-iteration.d.ts +7 -0
- package/dist/frontend/lowering/lower-async-iteration.js +657 -0
- package/dist/frontend/lowering/lower-async-iteration.js.map +1 -0
- package/dist/frontend/lowering/lower-builtins.d.ts +40 -21
- package/dist/frontend/lowering/lower-builtins.js +611 -115
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +21 -10
- package/dist/frontend/lowering/lower-calls.js +516 -75
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +7 -13
- package/dist/frontend/lowering/lower-classes.js +128 -35
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-comptime.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +1 -47
- package/dist/frontend/lowering/lower-containers.js +147 -1475
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-event-emitter.js +51 -5
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +0 -78
- package/dist/frontend/lowering/lower-exprs.js +503 -2353
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.d.ts +18 -3
- package/dist/frontend/lowering/lower-generators.js +145 -9
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.js +10 -3
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.d.ts +6 -0
- package/dist/frontend/lowering/lower-island.js +37 -5
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +60 -15
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-node-module.d.ts +18 -0
- package/dist/frontend/lowering/lower-node-module.js +302 -0
- package/dist/frontend/lowering/lower-node-module.js.map +1 -0
- package/dist/frontend/lowering/lower-server.js +1 -1
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +10 -28
- package/dist/frontend/lowering/lower-stmts.js +542 -259
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.js +4 -4
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +41 -38
- package/dist/frontend/lowering/lowerer.js +148 -62
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/optional-arguments.d.ts +9 -0
- package/dist/frontend/lowering/optional-arguments.js +57 -0
- package/dist/frontend/lowering/optional-arguments.js.map +1 -0
- package/dist/frontend/lowering/surfaces.d.ts +5 -3
- package/dist/frontend/lowering/surfaces.js +33 -13
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm-static-declarations.d.ts +35 -0
- package/dist/frontend/npm-static-declarations.js +519 -0
- package/dist/frontend/npm-static-declarations.js.map +1 -0
- package/dist/frontend/npm-static-declarations.test.d.ts +1 -0
- package/dist/frontend/npm-static-declarations.test.js +132 -0
- package/dist/frontend/npm-static-declarations.test.js.map +1 -0
- package/dist/frontend/npm-static.d.ts +2 -0
- package/dist/frontend/npm-static.js +26 -10
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.d.ts +60 -0
- package/dist/frontend/npm.js +38 -4
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/npm.test.d.ts +1 -0
- package/dist/frontend/npm.test.js +50 -0
- package/dist/frontend/npm.test.js.map +1 -0
- package/dist/frontend/program.d.ts +3 -2
- package/dist/frontend/program.js +513 -70
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/resolve.d.ts +26 -3
- package/dist/frontend/resolve.js +166 -29
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/resolve.test.js +24 -1
- package/dist/frontend/resolve.test.js.map +1 -1
- package/dist/frontend/runtime-resolve.d.ts +22 -0
- package/dist/frontend/runtime-resolve.js +101 -0
- package/dist/frontend/runtime-resolve.js.map +1 -0
- package/dist/frontend/runtime-resolve.test.d.ts +1 -0
- package/dist/frontend/runtime-resolve.test.js +18 -0
- package/dist/frontend/runtime-resolve.test.js.map +1 -0
- package/dist/frontend/ts7/adapter.js +12 -13
- package/dist/frontend/ts7/adapter.js.map +1 -1
- package/dist/frontend/ts7/ast.js.map +1 -1
- package/dist/frontend/ts7/census-check.js +3 -3
- package/dist/frontend/ts7/census-check.js.map +1 -1
- package/dist/frontend/ts7/checker.d.ts +3 -0
- package/dist/frontend/ts7/checker.js +12 -3
- package/dist/frontend/ts7/checker.js.map +1 -1
- package/dist/frontend/ts7/enums.js.map +1 -1
- package/dist/frontend/ts7/program-adapter.js +42 -3
- package/dist/frontend/ts7/program-adapter.js.map +1 -1
- package/dist/frontend/type-mapper.js +171 -16
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/index.js +11 -5
- 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 +125 -52
- package/dist/ir/ir.js +136 -7
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +1 -1
- package/dist/ir/validate.js +120 -63
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/cache-primitives.js.map +1 -1
- package/dist/library/cache-reset.test.js.map +1 -1
- package/dist/library/compiler-self-identity.js.map +1 -1
- package/dist/library/int-infer.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/dist/library/library-profile.js.map +1 -1
- package/dist/library/sidecar-validate.js.map +1 -1
- package/dist/library/sidecar.js.map +1 -1
- package/dist/startup-cache.js.map +1 -1
- package/dist/wasi-paths.js.map +1 -1
- package/package.json +18 -18
- package/surface-manifest.json +91 -20
|
@@ -62,16 +62,16 @@ import { InternalCompilerError } from "../../errors.js";
|
|
|
62
62
|
* lazy-inflate representation as the C debugging backend.
|
|
63
63
|
*/
|
|
64
64
|
import { deflateRawSync } from "node:zlib";
|
|
65
|
-
import { endsWithJump, matchStringSelfConcat } from "../../ir/analysis.js";
|
|
65
|
+
import { endsWithJump, matchStringSelfConcat, streamTypedRefEligible } from "../../ir/analysis.js";
|
|
66
66
|
import { emitLibraryIdentityLines } from "../library-identity-markers.js";
|
|
67
|
-
import { CAUGHT, ffiCallbackType, isFfiContextParam, isRefCounted, isUnitType, moduleEmbedsBuiltin, moduleEmbedsCompressedNpm, moduleUsesDynInvoke, moduleUsesFetch, moduleUsesFsWatch, moduleUsesHttpServer, moduleUsesNet, moduleUsesNodeTest, moduleUsesProcessEvents, moduleUsesStream, moduleUsesTls, moduleUsesTlsCa, NPM_COMPRESS_MIN, POINTER_KINDS, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, VOID } from "../../ir/ir.js";
|
|
67
|
+
import { CAUGHT, ffiCallbackType, isDynTypedRefType, isFfiContextParam, isRefCounted, isUnitType, moduleEmbedsBuiltin, moduleEmbedsCompressedNpm, moduleUsesChildProcess, moduleUsesDynInvoke, moduleUsesFetch, moduleUsesFsWatch, moduleUsesHttpServer, moduleUsesNet, moduleUsesNodeTest, moduleUsesProcessEvents, moduleUsesStream, moduleUsesTls, moduleUsesTlsCa, NPM_COMPRESS_MIN, POINTER_KINDS, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, typeKey, VOID } from "../../ir/ir.js";
|
|
68
68
|
import { matchIntegerBytesForLoop } from "../../ir/integer-loops.js";
|
|
69
69
|
import { allocateFfiCallbackAdapters, hasForeignFfiCallback, hasRetainedFfiCallback } from "../ffi-callbacks.js";
|
|
70
70
|
import { RUNTIME_ABI_MARKER } from "../runtime-abi.js";
|
|
71
71
|
import { computeMayThrow } from "../c/may-throw.js";
|
|
72
72
|
import { mangleArgPack, mangleAsyncSpawn, mangleClassObj, mangleFnClosure, mangleFunction, mangleGenDrop, mangleGenSpawn, mangleGlobal, mangleLocal, mangleRecordStruct, mangleTrampoline, mangleWrapper } from "../mangle.js";
|
|
73
73
|
import { BlockBuilder } from "./blocks.js";
|
|
74
|
-
import { f64Lit, ffiNativeTypeLl } from "./common.js";
|
|
74
|
+
import { f64Lit, ffiNativeTypeLl, llvmCommentText } from "./common.js";
|
|
75
75
|
import { emitLiteralExpr, emitOperatorExpr, emitStringExpr, emitContainerExpr, emitRecordExpr } from "./expr-primitives.js";
|
|
76
76
|
import { emitControlExpr } from "./expr-control.js";
|
|
77
77
|
import { emitCallExpr } from "./expr-calls.js";
|
|
@@ -80,7 +80,7 @@ import { emitIntrinsicExpr, emitSerializationExpr, emitAsyncExpr } from "./expr-
|
|
|
80
80
|
import { emitJsInteropExpr, emitExpr } from "./expr-dispatch.js";
|
|
81
81
|
import { emitJsMarshal, emitJsOp, emitJsExit, islandAdapter, islandTypedAdapter } from "./expr-island.js";
|
|
82
82
|
import { dynKind, raceAdapterFor, genResultThunkFor, childExitThunkFor, childExitSignalThunkFor, childDataThunkFor, emitterFixedAdapter, wrapEmitterListener, unwrapNullableClosure, closeBindThunkFor, closeOverrideWrapFor } from "./expr-callbacks.js";
|
|
83
|
-
import { streamDataAdapter, streamDoneFnFor, fsRenameThunkFor, streamCbThunkFor } from "./expr-stream-callbacks.js";
|
|
83
|
+
import { streamDataAdapter, streamDoneFnFor, cryptoBytesThunkFor, fsRenameThunkFor, streamCbThunkFor } from "./expr-stream-callbacks.js";
|
|
84
84
|
import { resolveThunkFor, tagInSet, arrPush, emitArrayCopyLoop, emitStrIntrinsic, emitArrIntrinsic, wrapNullable, emitMapNew, mapSet, emitMapLikeIntrinsic, emitSetNew } from "./expr-containers.js";
|
|
85
85
|
import { emitBytesReceiver, emitIntegerLoopIndex, emitBytesIndex, emitBytesData, emitBytesLength, emitBytesGet, emitBytesU32, emitBytesSet, emitBytesIntrinsic } from "./expr-bytes.js";
|
|
86
86
|
import { emitRegexIntrinsic, emitRecordKeyGet, keyedRecordReadInto } from "./expr-records.js";
|
|
@@ -202,8 +202,8 @@ class LlEmitter {
|
|
|
202
202
|
/** ReadableStream.from adapters keep typed arrays by reference and box
|
|
203
203
|
* one current element per pull. */
|
|
204
204
|
streamFromArrayAdapters = new Map();
|
|
205
|
-
/** Identity-preserving static→dyn capsules
|
|
206
|
-
* remain directly observable
|
|
205
|
+
/** Identity-preserving static→dyn capsules for program classes and Web
|
|
206
|
+
* APIs whose values remain directly observable. */
|
|
207
207
|
liveDynRefAdapters = new Map();
|
|
208
208
|
/** Runtime-arm dispatchers for live union values. */
|
|
209
209
|
liveDynUnionRefAdapters = new Map();
|
|
@@ -256,8 +256,8 @@ class LlEmitter {
|
|
|
256
256
|
* `tryDepth` snapshots tryStack.length at region entry: a throw inside
|
|
257
257
|
* a pending-return finally copy propagates OUT of the completing try
|
|
258
258
|
* (past its own catch), so the copies emit under the truncated stack.
|
|
259
|
-
* break/continue
|
|
260
|
-
*
|
|
259
|
+
* break/continue use the same region snapshots through
|
|
260
|
+
* emitFinallysForJump. */
|
|
261
261
|
finallyStack = [];
|
|
262
262
|
/** Enclosing try contexts, innermost last — the compile-time unwind
|
|
263
263
|
* targets (CEmitter.tryStack): a pending check or `throw` inside a try
|
|
@@ -692,6 +692,7 @@ class LlEmitter {
|
|
|
692
692
|
// BEFORE the global releases (the C emitter's runExitListeners
|
|
693
693
|
// ordering — the atexit half becomes an idempotent no-op).
|
|
694
694
|
const usesEvents = moduleUsesProcessEvents(this.mod);
|
|
695
|
+
const usesChildProcess = moduleUsesChildProcess(this.mod);
|
|
695
696
|
const usesFsWatch = moduleUsesFsWatch(this.mod);
|
|
696
697
|
// Stream-surface programs fill the loop's stream hook (the deferred
|
|
697
698
|
// next-tick emissions) and the emitter's post-registration flow kick
|
|
@@ -724,6 +725,8 @@ class LlEmitter {
|
|
|
724
725
|
// Declared NOW — the extern block flushes before main assembles.
|
|
725
726
|
if (usesEvents)
|
|
726
727
|
this.declare(`declare void @scr_events_install()`);
|
|
728
|
+
if (usesChildProcess)
|
|
729
|
+
this.declare(`declare void @scr_child_dyn_install()`);
|
|
727
730
|
if (usesFsWatch)
|
|
728
731
|
this.declare(`declare void @scr_watch_install()`);
|
|
729
732
|
if (this.ffiHasForeignCallback)
|
|
@@ -1114,7 +1117,7 @@ class LlEmitter {
|
|
|
1114
1117
|
// Event-surface programs (signal/exit listeners) fill the loop's
|
|
1115
1118
|
// nullable event hooks before %main — scr_events.c links only when
|
|
1116
1119
|
// this line is emitted (native-toolchain.ts gates on the same predicate).
|
|
1117
|
-
...(usesEvents ? [` call void @scr_events_install()`] : []),
|
|
1120
|
+
...(usesEvents ? [` call void @scr_events_install()`] : []), ...(usesChildProcess ? [` call void @scr_child_dyn_install()`] : []),
|
|
1118
1121
|
// fs.watch programs fill the loop's watch hooks the same way —
|
|
1119
1122
|
// scr_watch.c links only when this line is emitted.
|
|
1120
1123
|
...(usesFsWatch ? [` call void @scr_watch_install()`] : []), ...(this.ffiHasForeignCallback ? [` call void @scr_ffi_install()`] : []), ...(snapshotsTlsCa ? [` call void @scr_tls_ca_install()`] : []), ...(usesFetch ? [` call void @scr_fetch_install()`] : []), ...(embedsZlib ? [` call void @scr_zlib_island_install()`] : []), ...(embedsNet ? [` call void @scr_net_island_install()`] : []), ...(usesNet ? [` call void @scr_net_install()`, ` call void @scr_net_dyn_install()`] : []), ...(usesHttp ? [` call void @scr_http_dyn_install()`] : []), ...(usesStream ? [` call void @scr_stream_install()`] : []), ` call void @scr_lib_init(i32 %argc, ptr %argv)`, ...(usesIsland
|
|
@@ -1537,7 +1540,7 @@ class LlEmitter {
|
|
|
1537
1540
|
out.push(`define void @scr_wasi_coro_resume(ptr %handle) ${FN_ATTRS} {`, `entry:`, ` call void @llvm.coro.resume(ptr %handle)`, ` ret void`, `}`, `define void @scr_wasi_coro_destroy(ptr %handle) ${FN_ATTRS} {`, `entry:`, ` call void @llvm.coro.destroy(ptr %handle)`, ` ret void`, `}`, ``);
|
|
1538
1541
|
}
|
|
1539
1542
|
for (const fn of this.mod.functions) {
|
|
1540
|
-
if (fn.async !== true)
|
|
1543
|
+
if (fn.async !== true || fn.generator !== undefined)
|
|
1541
1544
|
continue;
|
|
1542
1545
|
const { definitions, ret, tr, spawnParams, argPackLines } = this.emitArgPackAndTrampolinePrologue(fn);
|
|
1543
1546
|
out.push(...definitions);
|
|
@@ -1708,6 +1711,27 @@ class LlEmitter {
|
|
|
1708
1711
|
tr.push(` br label %done`, `done:`, ` ret void`, `}`, ``);
|
|
1709
1712
|
}
|
|
1710
1713
|
out.push(...tr);
|
|
1714
|
+
let settleAsync = null;
|
|
1715
|
+
if (fn.async) {
|
|
1716
|
+
this.declare(`declare ptr @scr_async_gen_new(ptr, ptr, ptr, ptr)`);
|
|
1717
|
+
const genT = {
|
|
1718
|
+
kind: "generator",
|
|
1719
|
+
async: true,
|
|
1720
|
+
yieldT: fn.generator.yieldT,
|
|
1721
|
+
retT: ret,
|
|
1722
|
+
nextT: fn.generator.nextT,
|
|
1723
|
+
};
|
|
1724
|
+
const resultT = fn.generator.resultType;
|
|
1725
|
+
const build = this.genResultThunkFor(genT, resultT);
|
|
1726
|
+
settleAsync = `${build}_async`;
|
|
1727
|
+
const settleKey = `ags:${typeKey(genT)}`;
|
|
1728
|
+
if (!this.resolveThunks.has(settleKey)) {
|
|
1729
|
+
this.resolveThunks.set(settleKey, settleAsync);
|
|
1730
|
+
const adapters = vAdapters(this, resultT);
|
|
1731
|
+
this.resolveThunkDefs.push(`define internal void @${settleAsync}(ptr %g, ptr %p) ${FN_ATTRS} {`, `entry:`, ` %r = call ptr @${build}(ptr %g)`, ` call void @scr_promise_fulfill_ref(ptr %p, ptr %r, ptr ${adapters.retain}, ptr ${adapters.release}, ptr ${traceArg(this, resultT)})`, ` ret void`, `}`, ``);
|
|
1732
|
+
}
|
|
1733
|
+
this.declare(`declare void @scr_promise_fulfill_ref(ptr, ptr, ptr, ptr, ptr)`);
|
|
1734
|
+
}
|
|
1711
1735
|
// The never-started teardown: drop the packed (+1) arguments.
|
|
1712
1736
|
const dr = [
|
|
1713
1737
|
`define internal void @${mangleGenDrop(fn.name)}(ptr %ap) ${FN_ATTRS} {`,
|
|
@@ -1739,7 +1763,9 @@ class LlEmitter {
|
|
|
1739
1763
|
`entry:`,
|
|
1740
1764
|
...argPackLines,
|
|
1741
1765
|
];
|
|
1742
|
-
sp.push(
|
|
1766
|
+
sp.push(settleAsync === null
|
|
1767
|
+
? ` %gg = call ptr @scr_gen_new(ptr @${mangleTrampoline(fn.name)}, ptr %ap, ptr @${mangleGenDrop(fn.name)})`
|
|
1768
|
+
: ` %gg = call ptr @scr_async_gen_new(ptr @${mangleTrampoline(fn.name)}, ptr %ap, ptr @${mangleGenDrop(fn.name)}, ptr @${settleAsync})`, ` ret ptr %gg`, `}`, ``);
|
|
1743
1769
|
out.push(...sp);
|
|
1744
1770
|
}
|
|
1745
1771
|
return out;
|
|
@@ -1867,6 +1893,34 @@ class LlEmitter {
|
|
|
1867
1893
|
for (let i = this.scopes.length - 1; i >= scopeDepth; i--)
|
|
1868
1894
|
this.releaseScope(this.scopes[i]);
|
|
1869
1895
|
}
|
|
1896
|
+
/** Run the finally regions an abrupt loop/block jump crosses, then
|
|
1897
|
+
* release to the already-resolved target. This is the return path's
|
|
1898
|
+
* completion walk without a parked result value. */
|
|
1899
|
+
emitFinallysForJump(finallyDepth, frameDepth, scopeDepth) {
|
|
1900
|
+
if (this.finallyStack.length <= finallyDepth) {
|
|
1901
|
+
this.releaseForJump(frameDepth, scopeDepth);
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
const savedFrames = this.frames;
|
|
1905
|
+
const savedScopes = this.scopes;
|
|
1906
|
+
const savedFinally = this.finallyStack;
|
|
1907
|
+
const savedTry = this.tryStack;
|
|
1908
|
+
for (let i = savedFinally.length - 1; i >= finallyDepth && !this.B.isTerminated(); i--) {
|
|
1909
|
+
const fin = savedFinally[i];
|
|
1910
|
+
this.releaseForJump(fin.frameDepth, fin.scopeDepth);
|
|
1911
|
+
this.frames = this.frames.slice(0, fin.frameDepth);
|
|
1912
|
+
this.scopes = this.scopes.slice(0, fin.scopeDepth);
|
|
1913
|
+
this.finallyStack = savedFinally.slice(0, i);
|
|
1914
|
+
this.tryStack = savedTry.slice(0, fin.tryDepth);
|
|
1915
|
+
this.emitBlock(fin.body);
|
|
1916
|
+
}
|
|
1917
|
+
if (!this.B.isTerminated())
|
|
1918
|
+
this.releaseForJump(frameDepth, scopeDepth);
|
|
1919
|
+
this.frames = savedFrames;
|
|
1920
|
+
this.scopes = savedScopes;
|
|
1921
|
+
this.finallyStack = savedFinally;
|
|
1922
|
+
this.tryStack = savedTry;
|
|
1923
|
+
}
|
|
1870
1924
|
/** THE unwind path at a point where an exception is pending: release
|
|
1871
1925
|
* everything between here and the innermost try handler — or the whole
|
|
1872
1926
|
* function — and branch to the handler / return a dummy value (never
|
|
@@ -1980,6 +2034,9 @@ class LlEmitter {
|
|
|
1980
2034
|
else if (arm.kind === "string") {
|
|
1981
2035
|
valueName = this.unionPeek(v.name);
|
|
1982
2036
|
}
|
|
2037
|
+
else if (arm.kind === "bigint") {
|
|
2038
|
+
valueName = this.unionPeek(v.name);
|
|
2039
|
+
}
|
|
1983
2040
|
const truthy = this.truthyOf(arm.kind, valueName, true);
|
|
1984
2041
|
B.line(`store i1 ${truthy}, ptr ${slot}`);
|
|
1985
2042
|
B.br(join);
|
|
@@ -2020,6 +2077,12 @@ class LlEmitter {
|
|
|
2020
2077
|
B.line(`${truthy} = icmp ne ${this.sizeType} ${len}, 0`);
|
|
2021
2078
|
return truthy;
|
|
2022
2079
|
}
|
|
2080
|
+
case "bigint": {
|
|
2081
|
+
this.declare(`declare zeroext i1 @scr_bigint_truthy(ptr)`);
|
|
2082
|
+
const truthy = B.tmp();
|
|
2083
|
+
B.line(`${truthy} = call zeroext i1 @scr_bigint_truthy(ptr ${valueName})`);
|
|
2084
|
+
return truthy;
|
|
2085
|
+
}
|
|
2023
2086
|
case "date":
|
|
2024
2087
|
return "true";
|
|
2025
2088
|
case "array":
|
|
@@ -2040,8 +2103,11 @@ class LlEmitter {
|
|
|
2040
2103
|
case "spawnRes":
|
|
2041
2104
|
case "child":
|
|
2042
2105
|
case "childStream":
|
|
2106
|
+
case "childWriter":
|
|
2043
2107
|
case "generator":
|
|
2044
|
-
case "fsWatcher":
|
|
2108
|
+
case "fsWatcher":
|
|
2109
|
+
case "cryptoHash":
|
|
2110
|
+
case "cryptoHmac": {
|
|
2045
2111
|
if (unionArm)
|
|
2046
2112
|
return "true";
|
|
2047
2113
|
const truthy = B.tmp();
|
|
@@ -2362,10 +2428,10 @@ class LlEmitter {
|
|
|
2362
2428
|
* fiber and returns the generator object) — CEmitter.callTargetC. */
|
|
2363
2429
|
callTarget(fnName) {
|
|
2364
2430
|
const fn = this.fnByName.get(fnName);
|
|
2365
|
-
if (fn?.async === true)
|
|
2366
|
-
return mangleAsyncSpawn(fnName);
|
|
2367
2431
|
if (fn?.generator !== undefined)
|
|
2368
2432
|
return mangleGenSpawn(fnName);
|
|
2433
|
+
if (fn?.async === true)
|
|
2434
|
+
return mangleAsyncSpawn(fnName);
|
|
2369
2435
|
return mangleFunction(fnName);
|
|
2370
2436
|
}
|
|
2371
2437
|
/** Queue the current wasm coroutine and suspend it. The runtime decides
|
|
@@ -2495,7 +2561,7 @@ class LlEmitter {
|
|
|
2495
2561
|
B.line(`call void @scr_wasi_coro_started(ptr ${handle})`);
|
|
2496
2562
|
B.line(`${self} = call ptr @scr_fiber_self()`);
|
|
2497
2563
|
this.currentWasiCoro = {
|
|
2498
|
-
kind: fn.
|
|
2564
|
+
kind: fn.generator !== undefined ? "generator" : "async",
|
|
2499
2565
|
id,
|
|
2500
2566
|
handle,
|
|
2501
2567
|
self,
|
|
@@ -2857,7 +2923,7 @@ class LlEmitter {
|
|
|
2857
2923
|
for (const f of shape.fields) {
|
|
2858
2924
|
const lit = this.internLiteral(f.name);
|
|
2859
2925
|
const hit = B.tmp();
|
|
2860
|
-
B.line(`${hit} = call zeroext i1 @scr_str_eq(ptr ${key.name}, ptr ${lit}) ; ${f.name}`);
|
|
2926
|
+
B.line(`${hit} = call zeroext i1 @scr_str_eq(ptr ${key.name}, ptr ${lit}) ; ${llvmCommentText(f.name)}`);
|
|
2861
2927
|
const lh = B.newLabel("rks.h");
|
|
2862
2928
|
const ln = B.newLabel("rks.n");
|
|
2863
2929
|
B.condBr(hit, lh, ln);
|
|
@@ -2913,7 +2979,7 @@ class LlEmitter {
|
|
|
2913
2979
|
// typeEquals(f.type, iv) — the frontend fences everything else.
|
|
2914
2980
|
const lit = this.internLiteral(f.name);
|
|
2915
2981
|
const hit = B.tmp();
|
|
2916
|
-
B.line(`${hit} = call zeroext i1 @scr_str_eq(ptr ${key.name}, ptr ${lit}) ; ${f.name}`);
|
|
2982
|
+
B.line(`${hit} = call zeroext i1 @scr_str_eq(ptr ${key.name}, ptr ${lit}) ; ${llvmCommentText(f.name)}`);
|
|
2917
2983
|
const lh = B.newLabel("rks.h");
|
|
2918
2984
|
const ln = B.newLabel("rks.n");
|
|
2919
2985
|
B.condBr(hit, lh, ln);
|
|
@@ -2964,6 +3030,7 @@ class LlEmitter {
|
|
|
2964
3030
|
labels: s.labels,
|
|
2965
3031
|
frameDepth: this.frames.length,
|
|
2966
3032
|
scopeDepth: this.scopes.length,
|
|
3033
|
+
finallyDepth: this.finallyStack.length,
|
|
2967
3034
|
});
|
|
2968
3035
|
this.emitBlock(s.body);
|
|
2969
3036
|
this.jumpTargets.pop();
|
|
@@ -3003,6 +3070,7 @@ class LlEmitter {
|
|
|
3003
3070
|
...(s.labels !== undefined && { labels: s.labels }),
|
|
3004
3071
|
frameDepth: this.frames.length,
|
|
3005
3072
|
scopeDepth: this.scopes.length,
|
|
3073
|
+
finallyDepth: this.finallyStack.length,
|
|
3006
3074
|
});
|
|
3007
3075
|
this.emitBlock(s.body);
|
|
3008
3076
|
this.jumpTargets.pop();
|
|
@@ -3024,6 +3092,7 @@ class LlEmitter {
|
|
|
3024
3092
|
...(s.labels !== undefined && { labels: s.labels }),
|
|
3025
3093
|
frameDepth: this.frames.length,
|
|
3026
3094
|
scopeDepth: this.scopes.length,
|
|
3095
|
+
finallyDepth: this.finallyStack.length,
|
|
3027
3096
|
});
|
|
3028
3097
|
this.emitBlock(s.body);
|
|
3029
3098
|
this.jumpTargets.pop();
|
|
@@ -3085,6 +3154,7 @@ class LlEmitter {
|
|
|
3085
3154
|
...(s.labels !== undefined && { labels: s.labels }),
|
|
3086
3155
|
frameDepth: this.frames.length,
|
|
3087
3156
|
scopeDepth: this.scopes.length,
|
|
3157
|
+
finallyDepth: this.finallyStack.length,
|
|
3088
3158
|
});
|
|
3089
3159
|
this.emitBlock(s.body);
|
|
3090
3160
|
this.jumpTargets.pop();
|
|
@@ -3156,6 +3226,7 @@ class LlEmitter {
|
|
|
3156
3226
|
...(s.labels !== undefined && { labels: s.labels }),
|
|
3157
3227
|
frameDepth: this.frames.length,
|
|
3158
3228
|
scopeDepth: this.scopes.length,
|
|
3229
|
+
finallyDepth: this.finallyStack.length,
|
|
3159
3230
|
});
|
|
3160
3231
|
// The loop variable is a fresh const per iteration: its scope opens
|
|
3161
3232
|
// here, holds the (for ref elements: owned +1) current element, and
|
|
@@ -3216,8 +3287,9 @@ class LlEmitter {
|
|
|
3216
3287
|
}
|
|
3217
3288
|
if (!target)
|
|
3218
3289
|
throw new InternalCompilerError("llvm emitter bug: break target not found");
|
|
3219
|
-
this.
|
|
3220
|
-
B.
|
|
3290
|
+
this.emitFinallysForJump(target.finallyDepth, target.frameDepth, target.scopeDepth);
|
|
3291
|
+
if (!B.isTerminated())
|
|
3292
|
+
B.terminate(`br label %${target.brkLabel}`);
|
|
3221
3293
|
break;
|
|
3222
3294
|
}
|
|
3223
3295
|
case "continue": {
|
|
@@ -3233,8 +3305,9 @@ class LlEmitter {
|
|
|
3233
3305
|
}
|
|
3234
3306
|
if (!target || target.contLabel === null)
|
|
3235
3307
|
throw new InternalCompilerError("llvm emitter bug: continue target not found");
|
|
3236
|
-
this.
|
|
3237
|
-
B.
|
|
3308
|
+
this.emitFinallysForJump(target.finallyDepth, target.frameDepth, target.scopeDepth);
|
|
3309
|
+
if (!B.isTerminated())
|
|
3310
|
+
B.terminate(`br label %${target.contLabel}`);
|
|
3238
3311
|
break;
|
|
3239
3312
|
}
|
|
3240
3313
|
case "return": {
|
|
@@ -3369,10 +3442,9 @@ class LlEmitter {
|
|
|
3369
3442
|
* <unwind> stash (it unwinds through the synthetic
|
|
3370
3443
|
* try.e: scope entry) — JS's semantics exactly
|
|
3371
3444
|
*
|
|
3372
|
-
*
|
|
3373
|
-
* at the return site
|
|
3374
|
-
*
|
|
3375
|
-
* backstop). */
|
|
3445
|
+
* Abrupt completions inside tryBody/catchBody ride the finallyStack:
|
|
3446
|
+
* returns inline copies at the return site, while break/continue use the
|
|
3447
|
+
* shared region walk before branching to their resolved target. */
|
|
3376
3448
|
emitTryCatch(s) {
|
|
3377
3449
|
const B = this.B;
|
|
3378
3450
|
const hasCatch = s.catchBody !== null;
|
|
@@ -3471,11 +3543,29 @@ class LlEmitter {
|
|
|
3471
3543
|
B.line(`${stash} = call ptr @scr_exc_take() ; stash across finally`);
|
|
3472
3544
|
B.line(`store ptr ${stash}, ptr ${stashSlot}`);
|
|
3473
3545
|
this.scopes.push([{ slot: stashSlot, type: CAUGHT }]);
|
|
3546
|
+
const suppressHandler = s.suppressFinallyErrors
|
|
3547
|
+
? {
|
|
3548
|
+
label: B.newLabel("try.fs"),
|
|
3549
|
+
used: false,
|
|
3550
|
+
frameDepth: this.frames.length,
|
|
3551
|
+
scopeDepth: this.scopes.length,
|
|
3552
|
+
}
|
|
3553
|
+
: null;
|
|
3554
|
+
if (suppressHandler)
|
|
3555
|
+
this.tryStack.push(suppressHandler);
|
|
3474
3556
|
this.emitBlock(s.finallyBody);
|
|
3557
|
+
if (suppressHandler)
|
|
3558
|
+
this.tryStack.pop();
|
|
3475
3559
|
this.scopes.pop(); // normal completion keeps the stash for the re-raise
|
|
3476
3560
|
B.line(`call void @scr_rethrow(ptr ${stash})`);
|
|
3477
3561
|
B.line(`call void @scr_caught_release(ptr ${stash})`);
|
|
3478
3562
|
this.emitUnwind();
|
|
3563
|
+
if (suppressHandler?.used) {
|
|
3564
|
+
B.startBlock(suppressHandler.label);
|
|
3565
|
+
this.declare(`declare void @scr_exc_suppress(ptr)`);
|
|
3566
|
+
B.line(`call void @scr_exc_suppress(ptr ${stash}) ; consumes stash`);
|
|
3567
|
+
this.emitUnwind();
|
|
3568
|
+
}
|
|
3479
3569
|
}
|
|
3480
3570
|
B.startBlock(endLabel);
|
|
3481
3571
|
}
|
|
@@ -3546,6 +3636,7 @@ class LlEmitter {
|
|
|
3546
3636
|
...(s.labels !== undefined && { labels: s.labels }),
|
|
3547
3637
|
frameDepth: this.frames.length,
|
|
3548
3638
|
scopeDepth: this.scopes.length,
|
|
3639
|
+
finallyDepth: this.finallyStack.length,
|
|
3549
3640
|
});
|
|
3550
3641
|
const scope = [];
|
|
3551
3642
|
this.scopes.push(scope);
|
|
@@ -3731,6 +3822,9 @@ class LlEmitter {
|
|
|
3731
3822
|
fsRenameThunkFor(cbT) {
|
|
3732
3823
|
return fsRenameThunkFor(this.expressionContext(), cbT);
|
|
3733
3824
|
}
|
|
3825
|
+
cryptoBytesThunkFor(cbT) {
|
|
3826
|
+
return cryptoBytesThunkFor(this.expressionContext(), cbT);
|
|
3827
|
+
}
|
|
3734
3828
|
streamCbThunkFor(kind, cbT) {
|
|
3735
3829
|
return streamCbThunkFor(this.expressionContext(), kind, cbT);
|
|
3736
3830
|
}
|
|
@@ -3809,6 +3903,19 @@ class LlEmitter {
|
|
|
3809
3903
|
streamTypedRefCommitAdapter(t, snapshot) {
|
|
3810
3904
|
return streamTypedRefCommitAdapter(this.expressionContext(), t, snapshot);
|
|
3811
3905
|
}
|
|
3906
|
+
liveDynRefAdapter(t) {
|
|
3907
|
+
const key = typeKey(t);
|
|
3908
|
+
const existing = this.liveDynRefAdapters.get(key);
|
|
3909
|
+
if (existing)
|
|
3910
|
+
return existing;
|
|
3911
|
+
if (!streamTypedRefEligible(t) && !isDynTypedRefType(t)) {
|
|
3912
|
+
throw new InternalCompilerError(`llvm emitter bug: live dyn ref of ${key}`);
|
|
3913
|
+
}
|
|
3914
|
+
const prefix = `sc_ldr_${this.liveDynRefAdapters.size}`;
|
|
3915
|
+
const adapter = streamTypedRefMaterializeAdapter(this.expressionContext(), t, { prefix, adapters: new Map() }, `${prefix}_materialize`);
|
|
3916
|
+
this.liveDynRefAdapters.set(key, adapter);
|
|
3917
|
+
return adapter;
|
|
3918
|
+
}
|
|
3812
3919
|
liveDynUnionRefAdapter(t) {
|
|
3813
3920
|
return liveDynUnionRefAdapter(this.expressionContext(), t);
|
|
3814
3921
|
}
|