@loopdive/js2 0.57.0
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/CHANGELOG.md +1425 -0
- package/LICENSE +189 -0
- package/README.md +451 -0
- package/dist/checker/index.d.ts +117 -0
- package/dist/checker/language-service.d.ts +39 -0
- package/dist/checker/node-capability-map.d.ts +63 -0
- package/dist/checker/type-mapper.d.ts +84 -0
- package/dist/cjs-rewrite.d.ts +19 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +363 -0
- package/dist/codegen/accessor-driver.d.ts +97 -0
- package/dist/codegen/any-helpers.d.ts +72 -0
- package/dist/codegen/array-element-typing.d.ts +46 -0
- package/dist/codegen/array-holes.d.ts +69 -0
- package/dist/codegen/array-methods.d.ts +68 -0
- package/dist/codegen/array-object-proto.d.ts +64 -0
- package/dist/codegen/array-reduce-fusion.d.ts +31 -0
- package/dist/codegen/array-to-primitive.d.ts +28 -0
- package/dist/codegen/async-cps.d.ts +239 -0
- package/dist/codegen/async-scheduler.d.ts +349 -0
- package/dist/codegen/binary-ops.d.ts +78 -0
- package/dist/codegen/binding-info.d.ts +31 -0
- package/dist/codegen/builtin-scaffold.d.ts +98 -0
- package/dist/codegen/builtin-static-globals.d.ts +8 -0
- package/dist/codegen/builtin-tags.d.ts +189 -0
- package/dist/codegen/case-convert-native.d.ts +12 -0
- package/dist/codegen/case-tables.d.ts +4 -0
- package/dist/codegen/class-bodies.d.ts +41 -0
- package/dist/codegen/class-member-keys.d.ts +33 -0
- package/dist/codegen/class-to-primitive.d.ts +39 -0
- package/dist/codegen/closed-method-dispatch.d.ts +42 -0
- package/dist/codegen/closures.d.ts +285 -0
- package/dist/codegen/coercion-engine.d.ts +154 -0
- package/dist/codegen/coercion-plan.d.ts +29 -0
- package/dist/codegen/context/bodies.d.ts +4 -0
- package/dist/codegen/context/create-context.d.ts +4 -0
- package/dist/codegen/context/errors.d.ts +39 -0
- package/dist/codegen/context/locals.d.ts +69 -0
- package/dist/codegen/context/source-pos.d.ts +5 -0
- package/dist/codegen/context/speculative.d.ts +95 -0
- package/dist/codegen/context/types.d.ts +1936 -0
- package/dist/codegen/custom-iterable.d.ts +34 -0
- package/dist/codegen/dataview-native.d.ts +51 -0
- package/dist/codegen/date-parse-native.d.ts +13 -0
- package/dist/codegen/dead-elimination.d.ts +26 -0
- package/dist/codegen/declarations.d.ts +147 -0
- package/dist/codegen/deno-api.d.ts +11 -0
- package/dist/codegen/destructuring-params.d.ts +102 -0
- package/dist/codegen/dyn-read.d.ts +26 -0
- package/dist/codegen/eval-tiering.d.ts +19 -0
- package/dist/codegen/expressions/assignment.d.ts +61 -0
- package/dist/codegen/expressions/builtins.d.ts +26 -0
- package/dist/codegen/expressions/calls-closures.d.ts +54 -0
- package/dist/codegen/expressions/calls-guards.d.ts +49 -0
- package/dist/codegen/expressions/calls-optional.d.ts +4 -0
- package/dist/codegen/expressions/calls.d.ts +83 -0
- package/dist/codegen/expressions/eval-inline.d.ts +24 -0
- package/dist/codegen/expressions/extern.d.ts +67 -0
- package/dist/codegen/expressions/fnctor-prototype.d.ts +52 -0
- package/dist/codegen/expressions/helpers.d.ts +212 -0
- package/dist/codegen/expressions/identifiers.d.ts +57 -0
- package/dist/codegen/expressions/late-imports.d.ts +81 -0
- package/dist/codegen/expressions/logical-ops.d.ts +18 -0
- package/dist/codegen/expressions/misc.d.ts +27 -0
- package/dist/codegen/expressions/new-super.d.ts +25 -0
- package/dist/codegen/expressions/promise-subclass.d.ts +38 -0
- package/dist/codegen/expressions/proto-override.d.ts +63 -0
- package/dist/codegen/expressions/unary-updates.d.ts +21 -0
- package/dist/codegen/expressions/unary.d.ts +6 -0
- package/dist/codegen/expressions.d.ts +31 -0
- package/dist/codegen/fallback-telemetry.d.ts +53 -0
- package/dist/codegen/fixups.d.ts +80 -0
- package/dist/codegen/fmod.d.ts +10 -0
- package/dist/codegen/fnctor-escape-gate.d.ts +92 -0
- package/dist/codegen/function-body.d.ts +52 -0
- package/dist/codegen/generators-native.d.ts +92 -0
- package/dist/codegen/helpers/body-references-own-this.d.ts +22 -0
- package/dist/codegen/helpers/body-uses-arguments.d.ts +12 -0
- package/dist/codegen/helpers/is-strict-function.d.ts +52 -0
- package/dist/codegen/host-import-allowlist.d.ts +140 -0
- package/dist/codegen/index.d.ts +500 -0
- package/dist/codegen/ir-tail-call.d.ts +8 -0
- package/dist/codegen/iterator-native.d.ts +44 -0
- package/dist/codegen/json-codec-native.d.ts +78 -0
- package/dist/codegen/json-runtime.d.ts +35 -0
- package/dist/codegen/json-standalone.d.ts +25 -0
- package/dist/codegen/linear-uint8-analysis.d.ts +46 -0
- package/dist/codegen/linear-uint8-arena.d.ts +7 -0
- package/dist/codegen/linear-uint8-codegen.d.ts +103 -0
- package/dist/codegen/linear-uint8-signatures.d.ts +26 -0
- package/dist/codegen/literals.d.ts +115 -0
- package/dist/codegen/map-runtime.d.ts +142 -0
- package/dist/codegen/math-helpers.d.ts +7 -0
- package/dist/codegen/member-get-dispatch.d.ts +42 -0
- package/dist/codegen/member-set-dispatch.d.ts +28 -0
- package/dist/codegen/native-proto.d.ts +98 -0
- package/dist/codegen/native-regex.d.ts +158 -0
- package/dist/codegen/native-strings.d.ts +146 -0
- package/dist/codegen/new-target.d.ts +30 -0
- package/dist/codegen/node-fs-api.d.ts +47 -0
- package/dist/codegen/number-format-native.d.ts +9 -0
- package/dist/codegen/number-ryu.d.ts +27 -0
- package/dist/codegen/object-ops.d.ts +94 -0
- package/dist/codegen/object-runtime.d.ts +171 -0
- package/dist/codegen/parse-number-native.d.ts +10 -0
- package/dist/codegen/peephole.d.ts +6 -0
- package/dist/codegen/property-access.d.ts +294 -0
- package/dist/codegen/raw-wasi-api.d.ts +13 -0
- package/dist/codegen/regex/bytecode.d.ts +140 -0
- package/dist/codegen/regex/casefold.d.ts +41 -0
- package/dist/codegen/regex/compile.d.ts +51 -0
- package/dist/codegen/regex/parse.d.ts +76 -0
- package/dist/codegen/regex/unicode.d.ts +42 -0
- package/dist/codegen/regex/vm.d.ts +24 -0
- package/dist/codegen/regexp-standalone.d.ts +350 -0
- package/dist/codegen/registry/error-types.d.ts +38 -0
- package/dist/codegen/registry/imports.d.ts +46 -0
- package/dist/codegen/registry/types.d.ts +59 -0
- package/dist/codegen/set-algebra.d.ts +17 -0
- package/dist/codegen/set-runtime.d.ts +74 -0
- package/dist/codegen/shared.d.ts +111 -0
- package/dist/codegen/stack-balance.d.ts +43 -0
- package/dist/codegen/statements/control-flow.d.ts +25 -0
- package/dist/codegen/statements/destructuring.d.ts +177 -0
- package/dist/codegen/statements/exceptions.d.ts +11 -0
- package/dist/codegen/statements/functions.d.ts +1 -0
- package/dist/codegen/statements/index.d.ts +1 -0
- package/dist/codegen/statements/loops.d.ts +7 -0
- package/dist/codegen/statements/nested-declarations.d.ts +78 -0
- package/dist/codegen/statements/shared.d.ts +38 -0
- package/dist/codegen/statements/tdz.d.ts +43 -0
- package/dist/codegen/statements/variables.d.ts +3 -0
- package/dist/codegen/statements.d.ts +9 -0
- package/dist/codegen/string-builder.d.ts +131 -0
- package/dist/codegen/string-ops.d.ts +87 -0
- package/dist/codegen/struct-accessor-closure.d.ts +36 -0
- package/dist/codegen/symbol-native.d.ts +55 -0
- package/dist/codegen/temporal-native.d.ts +8 -0
- package/dist/codegen/timsort.d.ts +2 -0
- package/dist/codegen/type-coercion.d.ts +123 -0
- package/dist/codegen/typeof-delete.d.ts +38 -0
- package/dist/codegen/uri-encoding-native.d.ts +33 -0
- package/dist/codegen/value-tags.d.ts +74 -0
- package/dist/codegen/walk-instructions.d.ts +20 -0
- package/dist/codegen/weak-collections-runtime.d.ts +16 -0
- package/dist/codegen/with-scope.d.ts +106 -0
- package/dist/codegen-linear/c-abi.d.ts +74 -0
- package/dist/codegen-linear/context.d.ts +86 -0
- package/dist/codegen-linear/index.d.ts +28 -0
- package/dist/codegen-linear/layout.d.ts +39 -0
- package/dist/codegen-linear/runtime.d.ts +161 -0
- package/dist/codegen-linear/simd.d.ts +7 -0
- package/dist/compiler/define-substitution.d.ts +27 -0
- package/dist/compiler/early-errors/assignment.d.ts +26 -0
- package/dist/compiler/early-errors/context.d.ts +17 -0
- package/dist/compiler/early-errors/duplicates.d.ts +20 -0
- package/dist/compiler/early-errors/index.d.ts +11 -0
- package/dist/compiler/early-errors/labels.d.ts +13 -0
- package/dist/compiler/early-errors/module-rules.d.ts +36 -0
- package/dist/compiler/early-errors/node-checks.d.ts +7 -0
- package/dist/compiler/early-errors/predicates.d.ts +140 -0
- package/dist/compiler/early-errors/tdz.d.ts +17 -0
- package/dist/compiler/import-manifest.d.ts +18 -0
- package/dist/compiler/output.d.ts +46 -0
- package/dist/compiler/validation.d.ts +45 -0
- package/dist/compiler.d.ts +48 -0
- package/dist/define-substitution-BcUeKC2A.js +109 -0
- package/dist/emit/binary.d.ts +50 -0
- package/dist/emit/c-header.d.ts +23 -0
- package/dist/emit/canonical-recgroup.d.ts +86 -0
- package/dist/emit/encoder.d.ts +28 -0
- package/dist/emit/object.d.ts +14 -0
- package/dist/emit/opcodes.d.ts +464 -0
- package/dist/emit/sourcemap.d.ts +33 -0
- package/dist/emit/wat.d.ts +6 -0
- package/dist/env.d.ts +46 -0
- package/dist/import-resolver.d.ts +68 -0
- package/dist/index.d.ts +486 -0
- package/dist/index.js +755 -0
- package/dist/ir/alloc-registry.d.ts +75 -0
- package/dist/ir/analysis/encoding.d.ts +38 -0
- package/dist/ir/analysis/escape.d.ts +32 -0
- package/dist/ir/analysis/lattice.d.ts +72 -0
- package/dist/ir/analysis/ownership.d.ts +31 -0
- package/dist/ir/analysis/stack-alloc.d.ts +20 -0
- package/dist/ir/backend/bytecode-emitter.d.ts +237 -0
- package/dist/ir/backend/bytecode-vm.d.ts +74 -0
- package/dist/ir/backend/emitter.d.ts +121 -0
- package/dist/ir/backend/handles.d.ts +133 -0
- package/dist/ir/backend/legality.d.ts +9 -0
- package/dist/ir/backend/linear-emitter.d.ts +41 -0
- package/dist/ir/backend/wasmgc-emitter.d.ts +43 -0
- package/dist/ir/builder.d.ts +401 -0
- package/dist/ir/from-ast.d.ts +192 -0
- package/dist/ir/index.d.ts +16 -0
- package/dist/ir/integration.d.ts +27 -0
- package/dist/ir/lower.d.ts +203 -0
- package/dist/ir/nodes.d.ts +1452 -0
- package/dist/ir/passes/alloc-discipline.d.ts +19 -0
- package/dist/ir/passes/constant-fold.d.ts +7 -0
- package/dist/ir/passes/dead-code.d.ts +18 -0
- package/dist/ir/passes/inline-small.d.ts +7 -0
- package/dist/ir/passes/monomorphize.d.ts +21 -0
- package/dist/ir/passes/simplify-cfg.d.ts +19 -0
- package/dist/ir/passes/tagged-union-types.d.ts +45 -0
- package/dist/ir/passes/tagged-unions.d.ts +22 -0
- package/dist/ir/propagate.d.ts +135 -0
- package/dist/ir/select.d.ts +81 -0
- package/dist/ir/types.d.ts +832 -0
- package/dist/ir/verify-alloc.d.ts +18 -0
- package/dist/ir/verify.d.ts +7 -0
- package/dist/link/index.d.ts +11 -0
- package/dist/link/isolation.d.ts +24 -0
- package/dist/link/linker.d.ts +37 -0
- package/dist/link/reader.d.ts +158 -0
- package/dist/link/resolver.d.ts +19 -0
- package/dist/optimize.d.ts +54 -0
- package/dist/optimize.js +262 -0
- package/dist/position-map.d.ts +64 -0
- package/dist/process-stdin-prelude.d.ts +16 -0
- package/dist/resolve.d.ts +82 -0
- package/dist/runtime/builtins.d.ts +1 -0
- package/dist/runtime-C-4q_KwU.js +164438 -0
- package/dist/runtime-containment.d.ts +6 -0
- package/dist/runtime-eval.d.ts +132 -0
- package/dist/runtime-instantiate.d.ts +16 -0
- package/dist/runtime.d.ts +128 -0
- package/dist/runtime.js +12 -0
- package/dist/shape-inference.d.ts +20 -0
- package/dist/treeshake.d.ts +17 -0
- package/dist/ts-api.d.ts +30 -0
- package/dist/wit-generator.d.ts +18 -0
- package/package.json +187 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { MultiTypedAST, TypedAST } from '../checker/index.js';
|
|
3
|
+
import { ValType, WasmModule } from '../ir/types.js';
|
|
4
|
+
import { IrIntegrationError } from '../ir/integration.js';
|
|
5
|
+
import { FallbackCounts } from './fallback-telemetry.js';
|
|
6
|
+
import { CodegenContext, CodegenError, CodegenOptions, ExternClassInfo, FunctionContext, OptionalParamInfo } from './context/types.js';
|
|
7
|
+
import { ensureAnyFromExternHelper, ensureAnyHelpers, ensureAnyToExternHelper, ensureAnyValueType, ensureWrapperTypes, isAnyValue } from './any-helpers.js';
|
|
8
|
+
import { collectClassDeclaration, compileClassBodies } from './class-bodies.js';
|
|
9
|
+
import { destructureParamArray, destructureParamObject, destructureParamObjectExternref } from './destructuring-params.js';
|
|
10
|
+
import { ensureNativeStringExternBridge, ensureNativeStringHelpers, flatStringType, nativeStringType, nativeStringTypeNullable } from './native-strings.js';
|
|
11
|
+
export { collectClassDeclaration, compileClassBodies, destructureParamArray, destructureParamObject, destructureParamObjectExternref, ensureAnyFromExternHelper, ensureAnyHelpers, ensureAnyToExternHelper, ensureAnyValueType, ensureNativeStringExternBridge, ensureNativeStringHelpers, ensureWrapperTypes, flatStringType, isAnyValue, nativeStringType, nativeStringTypeNullable, };
|
|
12
|
+
/**
|
|
13
|
+
* Report a codegen error with source location extracted from an AST node.
|
|
14
|
+
* Pushes the error into ctx.errors so it can be propagated to the caller.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Extract a compile-time constant from a parameter initializer (#869).
|
|
18
|
+
* Returns the constant default info if the initializer is a numeric/boolean literal,
|
|
19
|
+
* undefined/null, or a unary minus on a numeric literal. Returns undefined otherwise.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* TypedArray constructor names. Most still lower to `(ref null $Vec[f64])`;
|
|
23
|
+
* native Uint8Array lowers to packed byte storage.
|
|
24
|
+
*/
|
|
25
|
+
export declare const TYPED_ARRAY_NAMES: ReadonlySet<string>;
|
|
26
|
+
export declare function typedArrayVecStorage(ctx: CodegenContext, name: string): {
|
|
27
|
+
key: string;
|
|
28
|
+
type: ValType;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* (#2593) The signedness of a packed integer typed-array element, driving the
|
|
32
|
+
* read opcode: `array.get_s` for signed views (`Int8`/`Int16`/`Int32`),
|
|
33
|
+
* `array.get_u` for unsigned (`Uint8`/`Uint8Clamped`/`Uint16`/`Uint32`). MUST be
|
|
34
|
+
* keyed on the TS view NAME, not the storage kind — a signed `Int8Array` and an
|
|
35
|
+
* unsigned `Uint8Array` share `i8` storage but read with opposite extension.
|
|
36
|
+
* Returns undefined for non-integer views (Float*, or a non-typed-array name).
|
|
37
|
+
*/
|
|
38
|
+
export declare function typedArrayPackedSignedness(name: string): "s" | "u" | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* (#1700) Classify a TS type at an export boundary for the runtime
|
|
41
|
+
* `wrapExports` marshalling step. The Wasm signature for `Uint8Array` and
|
|
42
|
+
* `number[]` is identical (`(ref null $Vec[f64])`), so we surface the
|
|
43
|
+
* TS-level distinction as metadata.
|
|
44
|
+
*
|
|
45
|
+
* - "uint8array" → caller may pass JS Uint8Array; result-side wraps as Uint8Array
|
|
46
|
+
* - "typed-array" → any other TypedArray (Int8Array / Float32Array / ...) — v1
|
|
47
|
+
* treats these like number[] on the return path; tracked for
|
|
48
|
+
* element-fidelity follow-up
|
|
49
|
+
* - "other" → not a typed array; wrapper is a no-op for this slot
|
|
50
|
+
*/
|
|
51
|
+
export declare function classifyTypedArrayType(tsType: ts.Type, checker: ts.TypeChecker): import('../ir/types.js').TypedArrayKind;
|
|
52
|
+
/**
|
|
53
|
+
* (#1719 S1) Whole-program pre-scan for the `ITER_OVERRIDDEN` brand of the
|
|
54
|
+
* array object-value representation track. Returns true iff the source may
|
|
55
|
+
* monkeypatch `Array.prototype`'s iterator surface, i.e. it contains:
|
|
56
|
+
* (i) an assignment `Array.prototype[Symbol.iterator] = …` or
|
|
57
|
+
* `Array.prototype.values = …` (any element/property access whose
|
|
58
|
+
* object is `Array.prototype`), OR
|
|
59
|
+
* (ii) `Object.defineProperty(Array.prototype, …)` /
|
|
60
|
+
* `Object.defineProperties(Array.prototype, …)`.
|
|
61
|
+
*
|
|
62
|
+
* When this returns false (the overwhelming common case), the array
|
|
63
|
+
* destructuring / spread / for-of fast paths are provably unaffected by any
|
|
64
|
+
* prototype override and stay byte-identical (see `arrayDstrNeedsIdentity`).
|
|
65
|
+
* When true, the S2 slice routes a branded array RHS through the host-Array
|
|
66
|
+
* reflection + host `GetIterator` so the override's `@@iterator` is observed
|
|
67
|
+
* (§7.4.2 GetIterator, §8.5.2 IteratorBindingInitialization).
|
|
68
|
+
*
|
|
69
|
+
* Reused verbatim from the dev-a `issue-1719-impl` scaffolding (the front-end
|
|
70
|
+
* half the architecture spec endorses keeping). Conservative by design: it
|
|
71
|
+
* over-approximates (a false positive only costs the S2 slow path, never
|
|
72
|
+
* correctness) and never under-approximates a literal `Array.prototype` LHS.
|
|
73
|
+
*/
|
|
74
|
+
export declare function sourceOverridesArrayIterator(sourceFile: ts.SourceFile): boolean;
|
|
75
|
+
export declare function extractConstantDefault(initializer: ts.Expression, paramType: ValType): OptionalParamInfo["constantDefault"];
|
|
76
|
+
export declare function irVerifierHardFailureEnabled(env?: Record<string, string | undefined>): boolean;
|
|
77
|
+
export declare function formatIrPathFallbackDiagnostic(err: IrIntegrationError): {
|
|
78
|
+
readonly message: string;
|
|
79
|
+
readonly severity: "error" | "warning";
|
|
80
|
+
};
|
|
81
|
+
/** Compile a typed AST into a WasmModule IR */
|
|
82
|
+
export declare function generateModule(ast: TypedAST, options?: CodegenOptions): {
|
|
83
|
+
module: WasmModule;
|
|
84
|
+
errors: CodegenError[];
|
|
85
|
+
fallbackCounts?: FallbackCounts;
|
|
86
|
+
irPostClaimErrors?: {
|
|
87
|
+
kind: string;
|
|
88
|
+
func: string;
|
|
89
|
+
message: string;
|
|
90
|
+
}[];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Compile multiple typed source files into a single WasmModule IR.
|
|
94
|
+
* All source files share the same codegen context (funcMap, structMap, etc.).
|
|
95
|
+
* Only functions exported from the entry file become Wasm exports.
|
|
96
|
+
*/
|
|
97
|
+
export declare function generateMultiModule(multiAst: MultiTypedAST, options?: CodegenOptions): {
|
|
98
|
+
module: WasmModule;
|
|
99
|
+
errors: CodegenError[];
|
|
100
|
+
fallbackCounts?: FallbackCounts;
|
|
101
|
+
irPostClaimErrors?: {
|
|
102
|
+
kind: string;
|
|
103
|
+
func: string;
|
|
104
|
+
message: string;
|
|
105
|
+
}[];
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* (#1483) Emit deferred WASI helper functions. Called after
|
|
109
|
+
* `collectExternDeclarations` (and any other direct-`addImport` callers)
|
|
110
|
+
* have registered all module imports, so the funcMap entries written here
|
|
111
|
+
* are stable for subsequent lookups by lazily-registered helpers.
|
|
112
|
+
*/
|
|
113
|
+
export declare function emitDeferredWasiHelpers(ctx: CodegenContext): void;
|
|
114
|
+
/**
|
|
115
|
+
* WASI linear-memory layout constants (#1618 collision fix).
|
|
116
|
+
*
|
|
117
|
+
* The iovec lives at memory[0..7] and nwritten at memory[8..11] (shared by all
|
|
118
|
+
* __wasi_write_* helpers). String-literal data segments are bump-allocated in
|
|
119
|
+
* page 0 from offset 1024 (`wasiAllocStringData`). To avoid aliasing those
|
|
120
|
+
* segments, the stdin read buffer and the raw-byte write scratch live in
|
|
121
|
+
* dedicated higher pages:
|
|
122
|
+
* - WASI_STDIN_BUF_START = 64KB (page 1) — fd_read accumulation buffer
|
|
123
|
+
* - WASI_WRITE_SCRATCH_START = 128KB (page 2) — fd_write staging buffer
|
|
124
|
+
* `registerWasiImports` reserves 3 pages so both always exist.
|
|
125
|
+
*/
|
|
126
|
+
export declare const WASI_STDIN_BUF_START: number;
|
|
127
|
+
export declare const WASI_WRITE_SCRATCH_START: number;
|
|
128
|
+
/**
|
|
129
|
+
* #2655 — DIRECT `readSync` iovec + nread scratch (page 0). The blocking
|
|
130
|
+
* `wasi_snapshot_preview1.fd_read(fd, iovs, iovs_len, nread)` syscall needs a
|
|
131
|
+
* `{ base, len }` iovec (8 bytes) and a `nread` out-slot (4 bytes) in linear
|
|
132
|
+
* memory. These deliberately use DEDICATED page-0 offsets — NOT the async
|
|
133
|
+
* reactor's `RL_FDREAD_IOV_OFFSET` (324) / `RL_FDREAD_NREAD_OFFSET` (332) — so a
|
|
134
|
+
* program that uses BOTH synchronous `readSync` AND the async stdin reactor
|
|
135
|
+
* never has its two iovec scratches alias. They sit above the reactor's
|
|
136
|
+
* 160–336 poll/iovec region and below the 1024 string-literal data base, so
|
|
137
|
+
* they collide with neither the iovec write scratch (0–24), the reactor, nor any
|
|
138
|
+
* string-literal segment. The read DATA lands in the page-1 stdin buffer
|
|
139
|
+
* (`WASI_STDIN_BUF_START`) for the GC-array copy path, or straight into the
|
|
140
|
+
* caller's `ptr+offset` for the linear-backed zero-copy path.
|
|
141
|
+
*/
|
|
142
|
+
export declare const WASI_READSYNC_IOV_OFFSET = 340;
|
|
143
|
+
export declare const WASI_READSYNC_NREAD_OFFSET = 348;
|
|
144
|
+
/**
|
|
145
|
+
* #1886 Slice B — Ensure the `__lin_u8_alloc(len: i32) -> i32` bump allocator
|
|
146
|
+
* exists and return its function index (lazy, emitted on first linear-backed
|
|
147
|
+
* `new Uint8Array`). Allocates `align8(len)` bytes from the page-4 linear arena
|
|
148
|
+
* pointed at by `$__lin_u8_arena_ptr`, growing memory on demand, and returns
|
|
149
|
+
* the (8-byte-aligned) base pointer. Mirrors the #1856 align8 + page-grow idiom
|
|
150
|
+
* from `codegen-linear/runtime.ts`; emitted here because the WasmGC front-end
|
|
151
|
+
* owns its own memory/globals and cannot call the linear backend bootstrap.
|
|
152
|
+
*
|
|
153
|
+
* NOTE: the returned region is NOT explicitly zero-filled — `memory.grow`
|
|
154
|
+
* zeroes fresh pages, and the arena today only ever grows (no reset yet, see
|
|
155
|
+
* Slice D), so every byte handed out is freshly-grown zero memory, satisfying
|
|
156
|
+
* the `new Uint8Array(n)` zero-fill contract. A future arena reset (Slice D)
|
|
157
|
+
* that reuses slots must `memory.fill` callers' buffers.
|
|
158
|
+
*/
|
|
159
|
+
export declare function reserveLinearU8AllocType(ctx: CodegenContext): void;
|
|
160
|
+
/**
|
|
161
|
+
* (#2357/#47) Reserve the standalone `$__subview_<elem>` struct types up-front so
|
|
162
|
+
* their indices are deterministic across codegen passes (see the call site in
|
|
163
|
+
* `generateModule`). Covers the element kinds standalone TypedArrays use for their
|
|
164
|
+
* backing arrays: `i8_byte` (Int8/Uint8/Uint8Clamped), `i16_byte`
|
|
165
|
+
* (Int16/Uint16), `i32_byte` (Int32/Uint32), and `f64` (the float views). (#2593
|
|
166
|
+
* added the i16/i32 byte views — before that only integer Uint8Array was packed.)
|
|
167
|
+
* `getOrRegisterSubviewType` only forces the backing ARRAY type (uniquely deduped
|
|
168
|
+
* per element kind) — it does NOT register or reorder the vec struct, so plain
|
|
169
|
+
* typed-array resolution is unaffected. Idempotent.
|
|
170
|
+
*/
|
|
171
|
+
export declare function reserveTypedArraySubviewTypes(ctx: CodegenContext): void;
|
|
172
|
+
/**
|
|
173
|
+
* (#2026 #53) Reserve the `$ObjVecArr` = `(array (mut externref))` type up-front,
|
|
174
|
+
* at the deterministic type-init point, so the dynamic-`new` runtime-argv path
|
|
175
|
+
* (`emitDynamicNewFallback`, for `new K(...someVar)`) can reference a STABLE type
|
|
176
|
+
* index. Minting this type lazily mid-expression — via `ensureObjectRuntime` —
|
|
177
|
+
* registered it after the deterministic type prefix had been baked, leaving an
|
|
178
|
+
* unresolved `-1` heap-type ref at binary-emit (the #2043 / subview
|
|
179
|
+
* type-idx-stability hazard). The type is self-contained (element `externref`,
|
|
180
|
+
* no type deps), so reserving it alone is zero-helper, zero-import, additive.
|
|
181
|
+
* `ensureObjectRuntime` adopts this slot (see object-runtime.ts) when present so
|
|
182
|
+
* the two never collide. Gated to class-bearing sources only (the dynamic-new
|
|
183
|
+
* fallback can't fire without a class).
|
|
184
|
+
*/
|
|
185
|
+
export declare function reserveObjVecArrType(ctx: CodegenContext): void;
|
|
186
|
+
export declare function ensureLinearU8AllocHelper(ctx: CodegenContext): number;
|
|
187
|
+
/**
|
|
188
|
+
* #1618: Ensure __wasi_write_any_string(s: ref NativeString) -> void exists and
|
|
189
|
+
* return its function index (lazy, emitted during expression compilation).
|
|
190
|
+
*
|
|
191
|
+
* Writes a *runtime* string (variable, concatenation, template span) to fd=1
|
|
192
|
+
* (stdout) or fd=2 (stderr). Previously these refs fell through to the
|
|
193
|
+
* `[object]` placeholder in emitWasiValueToStdout, corrupting the stream.
|
|
194
|
+
*
|
|
195
|
+
* Strategy: flatten any AnyString (FlatString / ConsString / Utf8String) to a
|
|
196
|
+
* NativeString via the existing __str_flatten helper, then encode the WTF-16
|
|
197
|
+
* code units as UTF-8 bytes directly into linear memory before issuing
|
|
198
|
+
* fd_write. This keeps WASI string output on the pure-Wasm path (#1470) without
|
|
199
|
+
* routing through the JS-host `__str_to_mem` / `TextEncoder` bridge.
|
|
200
|
+
*
|
|
201
|
+
* Param 0 is typed `ref NativeString` so callers can hand us a value compiled
|
|
202
|
+
* as `{ kind: "ref", typeIdx: ctx.nativeStrTypeIdx }` directly; __str_flatten
|
|
203
|
+
* accepts the NativeString supertype (AnyString) and returns the flat form.
|
|
204
|
+
*/
|
|
205
|
+
export declare function ensureWasiWriteAnyStringHelper(ctx: CodegenContext, useStderr?: boolean): number;
|
|
206
|
+
/**
|
|
207
|
+
* #2639: Ensure `__wasi_write_any_string_fd(s: ref AnyString, fd: i32) -> i32`
|
|
208
|
+
* exists and return its function index (lazy). Encodes the string to UTF-8 in
|
|
209
|
+
* the shared linear scratch (the same encoder as the fixed-fd writer) and writes
|
|
210
|
+
* it to the *runtime* fd. This backs the STRING overload of `node:fs`
|
|
211
|
+
* `writeSync(fd, str, position?, encoding?)`, where the fd is an arbitrary
|
|
212
|
+
* integer (not just stdout/stderr). Two modes (#2655):
|
|
213
|
+
* - shim (`--link-node-shims`): `writeSync(fd, ptr, len)` returns the byte count.
|
|
214
|
+
* - direct (standalone `--target wasi`): build a `{ base=ptr, len }` iovec at
|
|
215
|
+
* memory[0..7], call `fd_write(fd, iovs=0, 1, nwritten=8)`, load nwritten.
|
|
216
|
+
*/
|
|
217
|
+
export declare function ensureWasiWriteAnyStringFdHelper(ctx: CodegenContext): number;
|
|
218
|
+
/**
|
|
219
|
+
* #1617/#1651: Ensure __wasi_write_uint8array(arr: ref __vec_*) -> void
|
|
220
|
+
* exists and return its function index (lazy).
|
|
221
|
+
*
|
|
222
|
+
* Writes raw bytes from a typed-array (Uint8Array) GC object to fd=1 (stdout)
|
|
223
|
+
* or fd=2 (stderr) with NO trailing newline. Backs the
|
|
224
|
+
* `process.stdout.write(new Uint8Array([...]))` path (the standard Node API
|
|
225
|
+
* that supersedes the bespoke `writeStdout` builtin from #1617). A native
|
|
226
|
+
* Uint8Array compiles to a "vec" struct:
|
|
227
|
+
* field 0: length (i32)
|
|
228
|
+
* field 1: data (ref array<i8>) — each element is a byte value
|
|
229
|
+
*
|
|
230
|
+
* Legacy f64-backed typed arrays are still accepted; each element is converted
|
|
231
|
+
* to a byte before staging in linear memory at WASI_WRITE_SCRATCH_START.
|
|
232
|
+
*/
|
|
233
|
+
export declare function ensureWasiWriteUint8ArrayHelper(ctx: CodegenContext, vecTypeIdx: number, useStderr?: boolean): number;
|
|
234
|
+
/**
|
|
235
|
+
* #1655: Ensure __wasi_write_arraybuffer(buf: ref __vec_i32_byte) -> void
|
|
236
|
+
* exists and return its function index (lazy).
|
|
237
|
+
*
|
|
238
|
+
* Companion to `ensureWasiWriteUint8ArrayHelper` for the ArrayBuffer-backing
|
|
239
|
+
* representation. Under `--target wasi` / `--target standalone`, an
|
|
240
|
+
* `ArrayBuffer` is lowered to a vec struct of i32 bytes (one byte per
|
|
241
|
+
* element, values 0..255 — see dataview-native.ts comment block) rather than
|
|
242
|
+
* the Uint8Array f64-element shape. The element conversion is therefore a
|
|
243
|
+
* direct i32 read (no `i32.trunc_sat_f64_s`).
|
|
244
|
+
*/
|
|
245
|
+
export declare function ensureWasiWriteArrayBufferHelper(ctx: CodegenContext, vecTypeIdx: number, useStderr?: boolean): number;
|
|
246
|
+
export declare const STRING_METHODS: Record<string, {
|
|
247
|
+
params: ValType[];
|
|
248
|
+
result: ValType;
|
|
249
|
+
}>;
|
|
250
|
+
/** Register wasm:js-string builtin imports (called on demand when strings are used) */
|
|
251
|
+
export declare function addStringImports(ctx: CodegenContext): void;
|
|
252
|
+
/** Parse a RegExp literal text (e.g. "/\\d+/gi") into pattern and flags */
|
|
253
|
+
export declare function parseRegExpLiteral(text: string): {
|
|
254
|
+
pattern: string;
|
|
255
|
+
flags: string;
|
|
256
|
+
};
|
|
257
|
+
/** Math methods that need host imports (no native Wasm opcode) */
|
|
258
|
+
export declare const MATH_HOST_METHODS_1ARG: Set<string>;
|
|
259
|
+
export declare const MATH_HOST_METHODS_2ARG: Set<string>;
|
|
260
|
+
/**
|
|
261
|
+
* Emit the __toUint32 Wasm helper function. Must be called AFTER all imports
|
|
262
|
+
* that are added directly via addImport (bypassing ensureLateImport's shift
|
|
263
|
+
* mechanism) have been registered, and BEFORE any user function body that
|
|
264
|
+
* calls Math.clz32 or Math.imul is compiled. Emitting earlier leaves a stale
|
|
265
|
+
* funcMap entry because addImport does not shift defined-function indices.
|
|
266
|
+
*
|
|
267
|
+
* Implements ES §7.1.7: NaN/±Infinity → 0, otherwise trunc(x) modulo 2^32.
|
|
268
|
+
*/
|
|
269
|
+
export declare function emitToUint32Helper(ctx: CodegenContext): void;
|
|
270
|
+
/** Known constructors handled natively (not needing __new_ imports) */
|
|
271
|
+
export declare const KNOWN_CONSTRUCTORS: Set<string>;
|
|
272
|
+
/** Functional array methods that need host callback bridges */
|
|
273
|
+
export declare const FUNCTIONAL_ARRAY_METHODS: Set<string>;
|
|
274
|
+
/** Register union type helper imports (typeof checks, boxing/unboxing) */
|
|
275
|
+
export declare function addUnionImports(ctx: CodegenContext): void;
|
|
276
|
+
/** Register the iterator protocol host imports if not already registered */
|
|
277
|
+
export declare function addIteratorImports(ctx: CodegenContext): void;
|
|
278
|
+
/** Register array iterator host imports (entries/keys/values) if not already registered */
|
|
279
|
+
export declare function addArrayIteratorImports(ctx: CodegenContext): void;
|
|
280
|
+
/**
|
|
281
|
+
* Register the generator host imports if not already registered.
|
|
282
|
+
*
|
|
283
|
+
* The legacy generator codegen (eager-buffer model) uses these imports to
|
|
284
|
+
* push yielded values into a JS array on the host side, then wrap that
|
|
285
|
+
* buffer with `__create_generator` (or `__create_async_generator`) to
|
|
286
|
+
* produce a Generator-like / AsyncGenerator-like object. The IR path
|
|
287
|
+
* (slice 7 — #1169f) reuses the same set of imports — extracting this
|
|
288
|
+
* registration out of `declarations.ts:1014-1062` into a standalone
|
|
289
|
+
* exported helper so both legacy and IR can call it without duplicating
|
|
290
|
+
* the import-shape declarations.
|
|
291
|
+
*
|
|
292
|
+
* Imports registered (all under `env`):
|
|
293
|
+
* - `__gen_create_buffer` () → externref
|
|
294
|
+
* - `__gen_push_f64` (externref, f64) → ()
|
|
295
|
+
* - `__gen_push_i32` (externref, i32) → ()
|
|
296
|
+
* - `__gen_push_ref` (externref, externref) → ()
|
|
297
|
+
* - `__gen_yield_star` (externref, externref) → () (same shape as push_ref)
|
|
298
|
+
* - `__create_generator` (externref, externref) → externref (buf, pendingThrow)
|
|
299
|
+
* - `__create_async_generator` (externref, externref) → externref (same shape)
|
|
300
|
+
* - `__gen_next` (externref) → externref
|
|
301
|
+
* - `__gen_return` (externref, externref) → externref
|
|
302
|
+
* - `__gen_throw` (externref, externref) → externref
|
|
303
|
+
* - `__gen_result_value` (externref) → externref
|
|
304
|
+
* - `__gen_result_value_f64` (externref) → f64
|
|
305
|
+
* - `__gen_result_done` (externref) → i32
|
|
306
|
+
* - `__get_caught_exception` () → externref (for the body's try/catch wrapper)
|
|
307
|
+
*/
|
|
308
|
+
export declare function addGeneratorImports(ctx: CodegenContext, options?: {
|
|
309
|
+
allowNoJsHost?: boolean;
|
|
310
|
+
}): void;
|
|
311
|
+
/** Register for-in key enumeration host imports if not already registered */
|
|
312
|
+
export declare function addForInImports(ctx: CodegenContext): void;
|
|
313
|
+
/**
|
|
314
|
+
* Check if a ts.Type is a TypeScript tuple type (e.g. [number, string]).
|
|
315
|
+
* Tuples are TypeReference types whose target has the Tuple object flag.
|
|
316
|
+
* The Tuple flag is on the target, not the reference itself.
|
|
317
|
+
*/
|
|
318
|
+
export declare function isTupleType(type: ts.Type): boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Get the element types of a tuple type.
|
|
321
|
+
* Returns the resolved ValType for each element position.
|
|
322
|
+
*/
|
|
323
|
+
export declare function getTupleElementTypes(ctx: CodegenContext, tsType: ts.Type): ValType[];
|
|
324
|
+
/**
|
|
325
|
+
* Get or register a Wasm GC struct type for a tuple type.
|
|
326
|
+
* Each unique tuple signature (e.g. [f64, externref]) maps to one struct type
|
|
327
|
+
* with fields named _0, _1, etc.
|
|
328
|
+
*/
|
|
329
|
+
export declare function getOrRegisterTupleType(ctx: CodegenContext, elemTypes: ValType[]): number;
|
|
330
|
+
/**
|
|
331
|
+
* Detect native type annotations (e.g., `type i32 = number`) from a TS type's
|
|
332
|
+
* alias symbol. Returns the corresponding Wasm ValType, or null if not a native
|
|
333
|
+
* type annotation.
|
|
334
|
+
*
|
|
335
|
+
* TypeScript preserves the alias symbol on types at the usage site, so
|
|
336
|
+
* `let x: i32` where `type i32 = number` will have aliasSymbol.name === "i32"
|
|
337
|
+
* even though the resolved type is `number`.
|
|
338
|
+
*/
|
|
339
|
+
export declare function resolveNativeTypeAnnotation(tsType: ts.Type): ValType | null;
|
|
340
|
+
/**
|
|
341
|
+
* (#2176) Resolve the type of an identifier reference, preferring the user's
|
|
342
|
+
* own declaration over an ambient lib (`.d.ts`) global of the same name.
|
|
343
|
+
*
|
|
344
|
+
* Root cause: js2wasm analyzes a top-level program as a **script** (no
|
|
345
|
+
* import/export ⇒ not a module). In script mode a top-level `const name = …`
|
|
346
|
+
* does NOT shadow the writable global `var name: string` declared in
|
|
347
|
+
* `lib.dom.d.ts` (both live in the global scope, and TypeScript resolves a
|
|
348
|
+
* bare reference to the ambient symbol). So `const y = name` types `y` as
|
|
349
|
+
* `void` (the ambient `name`) instead of `string`, and the colliding-name
|
|
350
|
+
* read (`` `${name}` ``, `"x" + name`, `const y = name`) loses its real type —
|
|
351
|
+
* the codegen then registers `y` as an i32 global and the value reads back as
|
|
352
|
+
* `0`/`undefined`. Runtime values are stored correctly under `$__mod_name`;
|
|
353
|
+
* only the *type* is poisoned. Common colliders: `name` (→ undefined),
|
|
354
|
+
* `length`, `top`, `status`, `origin`, etc. from lib.dom.
|
|
355
|
+
*
|
|
356
|
+
* Fix: when `getTypeAtLocation(id)` binds to a symbol whose declarations live
|
|
357
|
+
* ONLY in lib `.d.ts` files, but a user-level binding of that exact name is in
|
|
358
|
+
* scope (a non-lib declaration), re-derive the type from the user binding so
|
|
359
|
+
* the read/declaration sees the real type. Falls back to the original type
|
|
360
|
+
* when no user binding shadows the ambient — zero behavior change for genuine
|
|
361
|
+
* host-global reads (`window.name`, bare `length` with no user binding).
|
|
362
|
+
*/
|
|
363
|
+
export declare function resolveIdentifierType(ctx: CodegenContext, id: ts.Identifier): ts.Type;
|
|
364
|
+
/**
|
|
365
|
+
* Resolve a ts.Type to a ValType, using the struct registry and anonymous type map.
|
|
366
|
+
* Use this instead of mapTsTypeToWasm in the codegen to get real type indices.
|
|
367
|
+
*/
|
|
368
|
+
export declare function resolveWasmType(ctx: CodegenContext, tsType: ts.Type, _depth?: number, _visited?: Set<ts.Type>): ValType;
|
|
369
|
+
/**
|
|
370
|
+
* Ensure a ts.Type that's an object type is registered as a struct.
|
|
371
|
+
* For named types already in structMap, this is a no-op.
|
|
372
|
+
* For anonymous types, auto-registers them with a generated name.
|
|
373
|
+
*/
|
|
374
|
+
export declare function ensureStructForType(ctx: CodegenContext, tsType: ts.Type): void;
|
|
375
|
+
/**
|
|
376
|
+
* Register built-in collection types (Set, Map, WeakMap, WeakSet) as extern classes
|
|
377
|
+
* if they weren't already collected from lib .d.ts files. This ensures these types
|
|
378
|
+
* are available for extern class method dispatch even when lib file scanning fails
|
|
379
|
+
* (e.g., bundled/browser environments where readLibFile returns empty strings).
|
|
380
|
+
*/
|
|
381
|
+
export declare function registerBuiltinExternClasses(ctx: CodegenContext): void;
|
|
382
|
+
/**
|
|
383
|
+
* #1238 — Look up a pseudo-extern-class entry by className. Returns
|
|
384
|
+
* `undefined` when the className isn't registered as a pseudo-extern
|
|
385
|
+
* class (i.e., it's either a real extern class — query
|
|
386
|
+
* `ctx.externClasses` for those — or unknown).
|
|
387
|
+
*
|
|
388
|
+
* This is the canonical accessor for the synthetic String/Array
|
|
389
|
+
* registry. Existing consumers of `ctx.externClasses` are intentionally
|
|
390
|
+
* NOT updated to consult this map: the legacy `new ClassName()` /
|
|
391
|
+
* extern-method dispatch paths must keep their existing behaviour for
|
|
392
|
+
* String / Array (they're handled via inline special cases or
|
|
393
|
+
* `__new_<name>` / `string_<method>` lowercase imports). The pseudo
|
|
394
|
+
* registry is the IR-only seam, queried by #1232 (String dispatch) and
|
|
395
|
+
* #1233 (Array dispatch).
|
|
396
|
+
*/
|
|
397
|
+
export declare function getPseudoExternClassInfo(ctx: CodegenContext, className: string): ExternClassInfo | undefined;
|
|
398
|
+
/**
|
|
399
|
+
* #1238 — TypeMap-keyed receiver-type → extern className lookup. Given an
|
|
400
|
+
* `IrType` resolved from the propagator's `TypeMap`, return the className
|
|
401
|
+
* of the matching synthetic extern class (or `null` if no match).
|
|
402
|
+
*
|
|
403
|
+
* This is the **MLIR-seam-friendly** dispatch helper: callers route
|
|
404
|
+
* receiver IrTypes here instead of pattern-matching `atom.kind ===
|
|
405
|
+
* "string"` inline. A future MLIR optimizer producing the same `IrType`
|
|
406
|
+
* shape would hit the same lookup, unchanged.
|
|
407
|
+
*
|
|
408
|
+
* Returns:
|
|
409
|
+
* - `"String"` for `IrType.string` and `IrType.val<externref>`
|
|
410
|
+
* (the externref arm covers post-#1169i extern-tagged strings)
|
|
411
|
+
* - `"Array"` for `IrType.val<ref|ref_null>` whose typeIdx points at
|
|
412
|
+
* a registered vec type (callers must check via their vec resolver)
|
|
413
|
+
* - `null` for anything else (including primitives, classes, objects)
|
|
414
|
+
*
|
|
415
|
+
* Note: the array path is only metadata. Confirming the receiver IS a
|
|
416
|
+
* vec (vs. a generic ref) requires the lowerer's vec resolver — this
|
|
417
|
+
* helper just identifies the target className so the lowerer can pick
|
|
418
|
+
* which extern entry to consult. Callers should pair this with
|
|
419
|
+
* `getPseudoExternClassInfo(ctx, target)` to get the method metadata.
|
|
420
|
+
*/
|
|
421
|
+
export declare function resolveMethodDispatchTarget(t: import('../ir/nodes.js').IrType): "String" | "Array" | null;
|
|
422
|
+
/** Collect enum declarations into ctx.enumValues / ctx.enumStringValues */
|
|
423
|
+
export declare function collectEnumDeclarations(ctx: CodegenContext, sourceFile: ts.SourceFile): void;
|
|
424
|
+
/**
|
|
425
|
+
* Resolve a class member's PropertyName to a static string.
|
|
426
|
+
* Handles identifiers, private identifiers, string literals, numeric literals,
|
|
427
|
+
* and computed property names that can be evaluated at compile time.
|
|
428
|
+
*/
|
|
429
|
+
/**
|
|
430
|
+
* Pre-pass: hoist all `var` declarations in a function body.
|
|
431
|
+
* Walks statements recursively and pre-allocates a local for each `var`
|
|
432
|
+
* variable not yet in localMap, so identifiers are valid before their
|
|
433
|
+
* declaration site (JavaScript var-hoisting semantics).
|
|
434
|
+
*/
|
|
435
|
+
export declare function hoistVarDeclarations(ctx: CodegenContext, fctx: FunctionContext, stmts: ts.NodeArray<ts.Statement> | ts.Statement[]): void;
|
|
436
|
+
/**
|
|
437
|
+
* Allocate TDZ flags for a let/const destructuring binding pattern so that
|
|
438
|
+
* `let { x = x } = {}` and similar self/forward references in default
|
|
439
|
+
* initializers throw ReferenceError per ECMA-262 §13.3.3.7 (#1128).
|
|
440
|
+
*
|
|
441
|
+
* Called from `compileObjectDestructuring` / `compileArrayDestructuring` at
|
|
442
|
+
* entry — BEFORE the binding-element loop allocates the actual binding locals.
|
|
443
|
+
* Only the TDZ flag is allocated here; the destructuring's own `allocLocal`
|
|
444
|
+
* for the binding runs later (line ~648 of destructuring.ts) and registers
|
|
445
|
+
* the binding name in `localMap`. By the time the default initializer is
|
|
446
|
+
* compiled (after that `allocLocal`), `compileIdentifier` will see both
|
|
447
|
+
* `localMap.has(name)` and `tdzFlagLocals.get(name)` and apply the TDZ check.
|
|
448
|
+
*
|
|
449
|
+
* The TDZ flag is allocated unconditionally for destructured bindings —
|
|
450
|
+
* +1 i32 local per binding is cheap, and unconditionality avoids subtle
|
|
451
|
+
* static-analysis gaps inside default initializers where `analyzeTdzAccess`
|
|
452
|
+
* could otherwise mis-classify the access as "skip".
|
|
453
|
+
*/
|
|
454
|
+
export declare function ensureLetConstBindingPatternTdzFlags(ctx: CodegenContext, fctx: FunctionContext, pattern: ts.BindingPattern): void;
|
|
455
|
+
/**
|
|
456
|
+
* Pre-pass: hoist all `let`/`const` declarations in a function body with TDZ flags.
|
|
457
|
+
* Unlike var-hoisting (which makes variables immediately accessible), let/const
|
|
458
|
+
* hoisting only pre-allocates the local + a TDZ flag so nested functions can
|
|
459
|
+
* capture the variable. The variable is still in TDZ until the declaration runs.
|
|
460
|
+
*/
|
|
461
|
+
export declare function hoistLetConstWithTdz(ctx: CodegenContext, fctx: FunctionContext, stmts: ts.NodeArray<ts.Statement> | ts.Statement[]): void;
|
|
462
|
+
/**
|
|
463
|
+
* Check if a let/const variable needs a TDZ flag by analyzing all references.
|
|
464
|
+
* Returns false if every access to the symbol is provably after the declaration
|
|
465
|
+
* in straight-line code (same function, no closures, loop-local safe).
|
|
466
|
+
*/
|
|
467
|
+
export declare function needsTdzFlag(ctx: CodegenContext, decl: ts.VariableDeclaration): boolean;
|
|
468
|
+
/**
|
|
469
|
+
* Check if a function body references the `arguments` identifier.
|
|
470
|
+
* Skips nested function declarations and function expressions (which have
|
|
471
|
+
* their own `arguments` binding), but traverses into arrow functions
|
|
472
|
+
* because arrows inherit the enclosing function's `arguments`.
|
|
473
|
+
*/
|
|
474
|
+
export declare function cacheStringLiterals(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
475
|
+
export declare function hasExportModifier(node: ts.Node): boolean;
|
|
476
|
+
export declare function hasDeclareModifier(node: ts.Node): boolean;
|
|
477
|
+
export declare function hasAsyncModifier(node: ts.Node): boolean;
|
|
478
|
+
export declare function hasAbstractModifier(node: ts.Node): boolean;
|
|
479
|
+
export declare function hasStaticModifier(node: ts.Node): boolean;
|
|
480
|
+
/** Check if a function declaration is a generator (function*) */
|
|
481
|
+
export declare function isGeneratorFunction(node: ts.FunctionDeclaration): boolean;
|
|
482
|
+
/**
|
|
483
|
+
* Unwrap Generator<T> return type to get the yield element type T.
|
|
484
|
+
* Falls back to externref if the type cannot be unwrapped.
|
|
485
|
+
*/
|
|
486
|
+
export declare function unwrapGeneratorYieldType(type: ts.Type, ctx: CodegenContext): ValType;
|
|
487
|
+
/**
|
|
488
|
+
* Ensure the stack top is an i32 suitable for use as a condition.
|
|
489
|
+
* Handles: f64 (truthy != 0), externref (JS truthiness via __is_truthy), null (push 0).
|
|
490
|
+
*/
|
|
491
|
+
export declare function ensureI32Condition(fctx: FunctionContext, condType: ValType | null, ctx?: CodegenContext): void;
|
|
492
|
+
export { popBody, pushBody } from './context/bodies.js';
|
|
493
|
+
export { createCodegenContext } from './context/create-context.js';
|
|
494
|
+
export { reportError } from './context/errors.js';
|
|
495
|
+
export { allocLocal, allocTempLocal, getLocalType, releaseTempLocal } from './context/locals.js';
|
|
496
|
+
export { attachSourcePos, getSourcePos } from './context/source-pos.js';
|
|
497
|
+
export type { ClosureInfo, CodegenContext, CodegenOptions, CodegenResult, ExternClassInfo, FunctionContext, InlinableFunctionInfo, OptionalParamInfo, RestParamInfo, } from './context/types.js';
|
|
498
|
+
export { addImport, addStringConstantGlobal, ensureExnTag, localGlobalIdx, nextModuleGlobalIdx, } from './registry/imports.js';
|
|
499
|
+
export { addFuncType, funcTypeEq, getArrTypeIdxFromVec, getOrRegisterArrayType, getOrRegisterRefCellType, getOrRegisterTemplateVecType, getOrRegisterVecType, } from './registry/types.js';
|
|
500
|
+
export { compileExpression, compileStatement } from './shared.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CodegenContext } from './context/types.js';
|
|
2
|
+
import { Instr } from '../ir/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Apply tail-call optimization to an IR-lowered function body in place.
|
|
5
|
+
* `funcTypeIdx` is the lowered function's own type index. Returns the rewritten
|
|
6
|
+
* body (a new top-level array; nested arms are mutated in place).
|
|
7
|
+
*/
|
|
8
|
+
export declare function applyIrTailCalls(ctx: CodegenContext, body: Instr[], funcTypeIdx: number): Instr[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CodegenContext } from './context/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Lazily register (or fetch) the `$__IterRec` GC struct type. Mirrors
|
|
4
|
+
* `ensureNativeGeneratorResultType` (generators-native.ts) — one struct per
|
|
5
|
+
* module, cached via `ctx.structMap`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getOrRegisterIterRecType(ctx: CodegenContext): number;
|
|
8
|
+
/**
|
|
9
|
+
* #1320 Slice 1 — register the four iteration-protocol operations as native
|
|
10
|
+
* Wasm functions (standalone/WASI). Idempotent: guards on `funcMap.has`.
|
|
11
|
+
*
|
|
12
|
+
* Signatures match the JS-host imports exactly so consumer codegen is
|
|
13
|
+
* byte-identical:
|
|
14
|
+
* __iterator(externref) -> externref (GetIterator)
|
|
15
|
+
* __iterator_next(externref) -> (i32 done, externref value) (IteratorStep)
|
|
16
|
+
* __iterator_return(externref) -> () (IteratorClose)
|
|
17
|
+
* __iterator_rest(externref) -> externref (drain remainder → vec)
|
|
18
|
+
*
|
|
19
|
+
* The argument to `__iterator` is, in Slice 1, an externref-wrapped canonical
|
|
20
|
+
* externref `$Vec` (the caller box-builds it). `__iterator` wraps it in an
|
|
21
|
+
* `$IterRec`; `__iterator_next` walks the vec by index.
|
|
22
|
+
*
|
|
23
|
+
* (#2038) The `__iterator` / `__iterator_next` bodies are emitted **vec-only**
|
|
24
|
+
* here — byte-identical to the pre-USER runtime — and `nativeIteratorUserArmPending`
|
|
25
|
+
* is set so `fillNativeIteratorUserArms` (finalize) rebuilds them with the USER
|
|
26
|
+
* arm once the closed-struct dispatchers exist. A non-vec subject keeps trapping
|
|
27
|
+
* (the legacy hard cast) until that fill runs, so a module where the fill is
|
|
28
|
+
* skipped (e.g. multi-module) never ships a broken iterator.
|
|
29
|
+
*/
|
|
30
|
+
export declare function ensureNativeIteratorRuntime(ctx: CodegenContext): void;
|
|
31
|
+
/**
|
|
32
|
+
* (#2038, reserve-then-fill #1719) Rebuild the `__iterator` / `__iterator_next`
|
|
33
|
+
* bodies with the USER `{next()}`-protocol arm, now that the closed-struct
|
|
34
|
+
* dispatchers (`__call_@@iterator`, `__call_next`, `__sget_value`, `__sget_done`)
|
|
35
|
+
* and `__is_truthy` have been emitted at finalize. No-op when:
|
|
36
|
+
* - the native runtime was never registered (`!nativeIteratorUserArmPending`),
|
|
37
|
+
* - any dispatcher is absent (e.g. no custom iterable / `{value,done}` struct in
|
|
38
|
+
* the module) — the carrier stays vec-only and byte-identical.
|
|
39
|
+
*
|
|
40
|
+
* MUST be called AFTER `emitStructFieldGetters` + `emitIteratorMethodExport` in
|
|
41
|
+
* the finalize sequence. Storing the carrier funcIdx in `funcMap` (and looking it
|
|
42
|
+
* up post-shift here) keeps it in lockstep with any late-import index shift.
|
|
43
|
+
*/
|
|
44
|
+
export declare function fillNativeIteratorUserArms(ctx: CodegenContext): void;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CodegenContext } from './context/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Emit `__json_stringify_value(v: anyref, depth: i32) -> ref null $AnyString`
|
|
4
|
+
* and register it in `ctx.funcMap`. Idempotent. Standalone / WASI only.
|
|
5
|
+
*
|
|
6
|
+
* A null result encodes "value serialises to JS `undefined`" (function /
|
|
7
|
+
* symbol / unsupported ref) — the caller's array/object arms apply the §25.5.2
|
|
8
|
+
* omit-vs-`null` rule.
|
|
9
|
+
*
|
|
10
|
+
* Returns the funcIdx.
|
|
11
|
+
*/
|
|
12
|
+
export declare function emitJsonStringifyValue(ctx: CodegenContext): number;
|
|
13
|
+
/**
|
|
14
|
+
* Emit the pure-Wasm recursive-descent `JSON.parse` codec (#2166 PR-C) and
|
|
15
|
+
* register `__json_parse_text(s: externref) -> anyref` in `ctx.funcMap`.
|
|
16
|
+
* Idempotent. Standalone / WASI only.
|
|
17
|
+
*
|
|
18
|
+
* The grammar is ECMA-404 / ECMA-262 §25.5.1 (strict JSON — no comments, no
|
|
19
|
+
* trailing commas, no single quotes). The output uses the SAME value
|
|
20
|
+
* representation the standalone object runtime and the `__json_stringify_value`
|
|
21
|
+
* codec consume, so a round-trip `JSON.parse(JSON.stringify(o))` and downstream
|
|
22
|
+
* property reads (`__extern_get`) work without conversion:
|
|
23
|
+
*
|
|
24
|
+
* - object → a fresh `$Object` (built via `__new_plain_object` +
|
|
25
|
+
* `__extern_set`), widened to `anyref`. Members preserve insertion order.
|
|
26
|
+
* - array → a fresh `$ObjVec` (built via `__objvec_new` + `__objvec_push`),
|
|
27
|
+
* widened to `anyref`.
|
|
28
|
+
* - string → a native `$AnyString` (the unescaped code units), widened to
|
|
29
|
+
* `anyref` — the same carrier object/array element reads already see.
|
|
30
|
+
* - number → boxed into the `$AnyValue` tagged union (tag 3, f64).
|
|
31
|
+
* - true / false → `$AnyValue` tag 4; null → `$AnyValue` tag 0.
|
|
32
|
+
*
|
|
33
|
+
* A grammar violation (or trailing non-whitespace) throws a runtime
|
|
34
|
+
* `SyntaxError` via the standalone `__new_SyntaxError` constructor — matching
|
|
35
|
+
* §25.5.1 step 3 — instead of trapping. The result `anyref` flows through the
|
|
36
|
+
* existing `$AnyValue`/object coercion paths in type-coercion.ts.
|
|
37
|
+
*
|
|
38
|
+
* Implementation note: the mutually-recursive value/string parsers share a
|
|
39
|
+
* cursor through a `$JsonP` parser-state struct (`{ data, pos(mut), end }`).
|
|
40
|
+
* That struct is passed as a bare **`anyref`** parameter (and `ref.cast` back
|
|
41
|
+
* inside each helper) rather than as `ref $JsonP`. A fresh GC struct type that
|
|
42
|
+
* appears in a *function-signature* parameter has tripped the dead-type-
|
|
43
|
+
* elimination remap in this codebase (the func-type param and the in-body
|
|
44
|
+
* `struct.get` operand can diverge after compaction); keeping the fresh
|
|
45
|
+
* `$JsonP` index off every signature and confined to `struct.new`/`struct.get`/
|
|
46
|
+
* `struct.set`/`ref.cast` instruction operands — which `remapTypeIdxInBody`
|
|
47
|
+
* rewrites uniformly — sidesteps that hazard.
|
|
48
|
+
*
|
|
49
|
+
* Returns the `__json_parse_text` funcIdx.
|
|
50
|
+
*/
|
|
51
|
+
export declare function emitJsonParseText(ctx: CodegenContext): number;
|
|
52
|
+
/**
|
|
53
|
+
* (#2166 PR-D1) Emit the standalone `JSON.parse(text, reviver)` codec —
|
|
54
|
+
* `__json_parse_text_reviver(text: externref, reviver: externref) -> anyref` —
|
|
55
|
+
* and the recursive §25.5.1 InternalizeJSONProperty walk
|
|
56
|
+
* `__internalize_json_property(holder: externref, key: externref,
|
|
57
|
+
* reviver: externref) -> externref`. Idempotent. Standalone / WASI only.
|
|
58
|
+
*
|
|
59
|
+
* The reviver itself is a USER closure (externref). It is invoked via the
|
|
60
|
+
* reserve/fill `__call_reviver` driver (accessor-driver.ts) which wraps
|
|
61
|
+
* `__call_fn_method_2(holder, reviver, key, value)` — binding `holder` as `this`
|
|
62
|
+
* and passing `key`/`value` as the two reviver args (§25.5.1 step 2.c). The fill
|
|
63
|
+
* runs in finalize after `__call_fn_method_2` is registered; when no arity-2
|
|
64
|
+
* closure exists the driver degrades to an identity (returns the value), so a
|
|
65
|
+
* module with no reviver closure still verifies.
|
|
66
|
+
*
|
|
67
|
+
* Walk (§25.5.1 InternalizeJSONProperty(holder, key, reviver)):
|
|
68
|
+
* val = holder[key]
|
|
69
|
+
* if val is an Object: for each own key k (snapshot taken BEFORE recursion,
|
|
70
|
+
* §25.5.1 step 2.a.i — a reviver that adds keys doesn't see them):
|
|
71
|
+
* elem = InternalizeJSONProperty(val, k, reviver)
|
|
72
|
+
* if elem is undefined → delete val[k] else → val[k] = elem
|
|
73
|
+
* if val is an Array ($ObjVec): same over numeric indices with string keys.
|
|
74
|
+
* return reviver.call(holder, key, val)
|
|
75
|
+
*
|
|
76
|
+
* Returns the funcIdx of `__json_parse_text_reviver`.
|
|
77
|
+
*/
|
|
78
|
+
export declare function emitJsonParseTextReviver(ctx: CodegenContext): number;
|