@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,46 @@
|
|
|
1
|
+
import { Import } from '../../ir/types.js';
|
|
2
|
+
import { CodegenContext } from '../context/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Register an import (`module.name`) on the current module.
|
|
5
|
+
*
|
|
6
|
+
* Under `ctx.strictNoHostImports` (auto-on for `--target wasi`, controllable
|
|
7
|
+
* via `--no-host-imports` / `--allow-host-imports` on the CLI; see #1524),
|
|
8
|
+
* any `env`-module import that is not on the dual-mode allowlist
|
|
9
|
+
* (`src/codegen/host-import-allowlist.ts`) is rejected with a structured
|
|
10
|
+
* compile error referencing the tracking issue. The error is pushed onto
|
|
11
|
+
* `ctx.errors`; the import itself is silently dropped to avoid producing a
|
|
12
|
+
* module that references a nonexistent function index. Downstream code that
|
|
13
|
+
* attempts to `call` the dropped function will fail validation if the
|
|
14
|
+
* caller did not check `result.success` before consuming the binary.
|
|
15
|
+
*
|
|
16
|
+
* `wasi_snapshot_preview1` imports are always allowed; they are the canonical
|
|
17
|
+
* WASI ABI, not JS-host bindings.
|
|
18
|
+
*
|
|
19
|
+
* `wasm:js-string` / `string_constants` are JS-host bindings but are usually
|
|
20
|
+
* not requested under strict mode because `nativeStrings` is auto-enabled.
|
|
21
|
+
* If they ARE requested under strict mode, the gate rejects them with a
|
|
22
|
+
* dedicated error pointing the user at the nativeStrings option.
|
|
23
|
+
*/
|
|
24
|
+
export declare function addImport(ctx: CodegenContext, module: string, name: string, desc: Import["desc"]): void;
|
|
25
|
+
/**
|
|
26
|
+
* Register a string literal as a global import from the "string_constants"
|
|
27
|
+
* namespace and repair already-compiled module-global references if needed.
|
|
28
|
+
*
|
|
29
|
+
* In `nativeStrings` mode (auto-on for `--target wasi`), no JS host runtime
|
|
30
|
+
* exists to satisfy the import, so we skip the import and just record the
|
|
31
|
+
* string in `stringGlobalMap` with the sentinel `-1` (the same convention
|
|
32
|
+
* used by `collectStringLiterals` finalize). Call sites that materialize a
|
|
33
|
+
* string constant onto the stack must check the sentinel and use the native
|
|
34
|
+
* string path (`compileNativeStringLiteral` + `extern.convert_any` for the
|
|
35
|
+
* externref-typed throw payload) instead of `global.get`. (#1174)
|
|
36
|
+
*/
|
|
37
|
+
export declare function addStringConstantGlobal(ctx: CodegenContext, value: string): void;
|
|
38
|
+
/** Return the absolute Wasm global index for a new module-defined global. */
|
|
39
|
+
export declare function nextModuleGlobalIdx(ctx: CodegenContext): number;
|
|
40
|
+
/** Convert an absolute Wasm global index to a local module-globals array index. */
|
|
41
|
+
export declare function localGlobalIdx(ctx: CodegenContext, absIdx: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Lazily register the exception tag used by throw/try-catch.
|
|
44
|
+
* The tag has signature (externref) — all thrown values are externref.
|
|
45
|
+
*/
|
|
46
|
+
export declare function ensureExnTag(ctx: CodegenContext): number;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FuncTypeDef, ValType } from '../../ir/types.js';
|
|
2
|
+
import { CodegenContext } from '../context/types.js';
|
|
3
|
+
export declare function addFuncType(ctx: CodegenContext, params: ValType[], results: ValType[], name?: string): number;
|
|
4
|
+
export declare function funcTypeEq(t: FuncTypeDef, params: ValType[], results: ValType[]): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Get or register a Wasm array type for a given element kind.
|
|
7
|
+
* Reuses existing registrations so each element type only gets one array type.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getOrRegisterArrayType(ctx: CodegenContext, elemKind: string, elemTypeOverride?: ValType): number;
|
|
10
|
+
/**
|
|
11
|
+
* (#2186) Get or register the shared `$__vec_base` supertype struct — a single
|
|
12
|
+
* `(length i32)` field that every concrete `__vec_<elemKind>` subtypes. This
|
|
13
|
+
* gives standalone runtime helpers a uniform `ref.test $__vec_base` /
|
|
14
|
+
* `ref.cast $__vec_base` → `struct.get 0` path to read a boxed array's length
|
|
15
|
+
* regardless of its element kind (the array-length-through-externref boundary
|
|
16
|
+
* fix). Declared open (`superTypeIdx: -1`) so vecs can extend it. Idempotent.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getOrRegisterVecBaseType(ctx: CodegenContext): number;
|
|
19
|
+
/**
|
|
20
|
+
* Get or register a vec struct type wrapping a Wasm GC array.
|
|
21
|
+
* The vec struct has {length: i32, data: (ref $__arr_<elemKind>)}.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getOrRegisterVecType(ctx: CodegenContext, elemKind: string, elemTypeOverride?: ValType): number;
|
|
24
|
+
/**
|
|
25
|
+
* (#2159 / #2357 / #47) Get or register the `$__subview_<elemKind>` struct — a
|
|
26
|
+
* TypedArray `subarray` view that SHARES the parent's backing array:
|
|
27
|
+
* `{length: i32, data: (ref null $__arr_<elemKind>), byteOffset: i32}`.
|
|
28
|
+
*
|
|
29
|
+
* `length` is field 0 (subtypes `$__vec_base`) so uniform `.length` reads and the
|
|
30
|
+
* externref-length helper keep working. `data` holds the PARENT's backing array
|
|
31
|
+
* DIRECTLY (shared — no copy); `byteOffset` is the element offset of the window
|
|
32
|
+
* into that array. We deliberately store the array type (`$__arr_<elemKind>`,
|
|
33
|
+
* uniquely deduped per element kind) rather than a concrete vec struct idx,
|
|
34
|
+
* because the same element kind can be registered behind multiple vec struct
|
|
35
|
+
* indices in a module (hoist-time vs body-time) — pinning to the array type makes
|
|
36
|
+
* the subview idx-stable. Element access on a `$__subview` receiver reads
|
|
37
|
+
* `data[byteOffset + i]`; a plain vec reads `vec.data[i]` unchanged. The
|
|
38
|
+
* discrimination is by the receiver's static ValType.typeIdx at COMPILE time, so
|
|
39
|
+
* the plain-array hot path is untouched. Keyed per element kind. Idempotent.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getOrRegisterSubviewType(ctx: CodegenContext, elemKind: string, elemTypeOverride?: ValType): number;
|
|
42
|
+
/** (#2357) The backing array type idx for a `$__subview_<elem>` struct (field 1). */
|
|
43
|
+
export declare function getSubviewArrTypeIdx(ctx: CodegenContext, subviewTypeIdx: number): number;
|
|
44
|
+
/** (#2357) True iff `typeIdx` is a registered `$__subview_<elem>` struct. */
|
|
45
|
+
export declare function isSubviewTypeIdx(ctx: CodegenContext, typeIdx: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Get or register the template vec struct type for tagged template string arrays.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getOrRegisterTemplateVecType(ctx: CodegenContext): number;
|
|
50
|
+
/**
|
|
51
|
+
* Get or register a ref cell struct type for mutable closure captures.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getOrRegisterRefCellType(ctx: CodegenContext, valType: ValType): number;
|
|
54
|
+
/** Get the raw array type index from a vec struct type index. */
|
|
55
|
+
export declare function getArrTypeIdxFromVec(ctx: CodegenContext, vecTypeIdx: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Register the WasmGC types for native strings (rope/cons-string support).
|
|
58
|
+
*/
|
|
59
|
+
export declare function registerNativeStringTypes(ctx: CodegenContext): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
3
|
+
import { InnerResult } from './shared.js';
|
|
4
|
+
/**
|
|
5
|
+
* Emit the 7 set-algebra helpers (idempotent). Names registered in
|
|
6
|
+
* `ctx.mapHelpers`: `__set_union` / `__set_intersection` / `__set_difference` /
|
|
7
|
+
* `__set_symmetricDifference` / `__set_isSubsetOf` / `__set_isSupersetOf` /
|
|
8
|
+
* `__set_isDisjointFrom`. Each is `(ref $Map, ref $Map) -> {ref $Map | i32}`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function ensureSetAlgebraHelpers(ctx: CodegenContext): void;
|
|
11
|
+
/**
|
|
12
|
+
* (#2162) Intercept an ES2025 Set set-algebra method call in standalone /
|
|
13
|
+
* nativeStrings mode. Both the receiver and the single argument must type as a
|
|
14
|
+
* Set (the WasmGC `$Map` struct); otherwise return undefined to let the generic
|
|
15
|
+
* path try. Receiver + arg are compiled here.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tryCompileNativeSetAlgebraCall(ctx: CodegenContext, fctx: FunctionContext, propAccess: ts.PropertyAccessExpression, callExpr: ts.CallExpression): InnerResult | undefined;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ValType } from '../ir/types.js';
|
|
2
|
+
import { ts } from '../ts-api.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
4
|
+
import { InnerResult } from './shared.js';
|
|
5
|
+
/**
|
|
6
|
+
* Emit the `__set_add(m, v) -> ref $Map` helper (idempotent). `Set.add` stores
|
|
7
|
+
* the element as both key and value so the shared Map lookup/iteration sees a
|
|
8
|
+
* normal entry; the return value is the map itself (Set.add is chainable and
|
|
9
|
+
* returns the Set, spec 24.2.3.1).
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureSetHelpers(ctx: CodegenContext): void;
|
|
12
|
+
/**
|
|
13
|
+
* (#2604) `[[SetData]]` brand-check for a reflectively-invoked Set method
|
|
14
|
+
* receiver (`Set.prototype.METHOD.call(recv, …)` / `inst.METHOD.call(recv, …)`).
|
|
15
|
+
* Consumes the just-compiled receiver value (`recvType` describes what is on the
|
|
16
|
+
* stack) and leaves a non-null `(ref $Map)` — the validated backing struct — on
|
|
17
|
+
* the stack.
|
|
18
|
+
*
|
|
19
|
+
* Spec 24.2.3.* step "If S does not have a [[SetData]] internal slot, throw a
|
|
20
|
+
* TypeError": uses a NON-TRAPPING `ref.test $Map` (0/1, never traps on
|
|
21
|
+
* null/primitive/wrong-struct) then branches — a miss throws a *catchable*
|
|
22
|
+
* `TypeError` (NOT `ref.cast`, which would trap `illegal cast`, which test262
|
|
23
|
+
* `assert.throws(TypeError, …)` does not accept). On a hit the value is
|
|
24
|
+
* `ref.cast`-ed (safe — the test passed) to `(ref $Map)`.
|
|
25
|
+
*
|
|
26
|
+
* NOTE: a real `Map`/`WeakSet` is ALSO `$Map`-backed and passes `ref.test $Map`;
|
|
27
|
+
* distinguishing Set from Map/Weak by struct alone is not possible without a
|
|
28
|
+
* kind tag (the `does-not-have-setdata-internal-slot-{map,weakset}.js` sub-rows,
|
|
29
|
+
* a documented stretch — #2604). The primitive / plain-object / array / null
|
|
30
|
+
* rows (the bulk) flip here.
|
|
31
|
+
*/
|
|
32
|
+
export declare function emitSetBrandCheck(ctx: CodegenContext, fctx: FunctionContext, recvType: ValType | null): void;
|
|
33
|
+
/**
|
|
34
|
+
* (#2162) Intercept a `Set.prototype.*` method call in standalone /
|
|
35
|
+
* `nativeStrings` mode and route it to the WasmGC-native Set/Map runtime.
|
|
36
|
+
* Returns the result `InnerResult` when handled, or `undefined` to let the
|
|
37
|
+
* generic extern/host path proceed (JS-host mode, or unsupported methods).
|
|
38
|
+
*
|
|
39
|
+
* Receiver and arguments are compiled here.
|
|
40
|
+
*/
|
|
41
|
+
export declare function tryCompileNativeSetMethodCall(ctx: CodegenContext, fctx: FunctionContext, propAccess: ts.PropertyAccessExpression, callExpr: ts.CallExpression): InnerResult | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* (#2604) Reflective `Set.prototype.METHOD.call(recv, …)` /
|
|
44
|
+
* `inst.METHOD.call(recv, …)` dispatch with a `[[SetData]]` brand-check.
|
|
45
|
+
*
|
|
46
|
+
* The direct `s.METHOD(v)` shape is handled by {@link tryCompileNativeSetMethodCall}
|
|
47
|
+
* (gated on the receiver's static `className === "Set"`); the reflective `.call`
|
|
48
|
+
* shape never reaches it, so neither the native dispatch nor the spec brand-check
|
|
49
|
+
* (24.2.3.* "If S does not have a [[SetData]] internal slot, throw a TypeError")
|
|
50
|
+
* fires. This handler recognises the `.call` form, compiles the FIRST `.call`
|
|
51
|
+
* argument as the receiver, brand-checks it ({@link emitSetBrandCheck} →
|
|
52
|
+
* catchable TypeError on a non-Set), then routes the remaining args to the same
|
|
53
|
+
* `__set_add`/`__map_has`/`__map_delete`/`__map_clear` helpers.
|
|
54
|
+
*
|
|
55
|
+
* Returns the result `InnerResult` when handled, or `undefined` to fall through.
|
|
56
|
+
* Scoped to add/has/delete/clear (the bulk of the ~84-row brand-check bucket);
|
|
57
|
+
* forEach/keys/values/entries reflective forms fall through (rarer). `.apply`
|
|
58
|
+
* (packed-args) is deferred — only `.call` is intercepted here.
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* (#2604) Cheap syntactic predicate (NO codegen): does `expr` match the
|
|
62
|
+
* reflective Set data-method `.call` shape this module dispatches? The caller
|
|
63
|
+
* (calls.ts) uses it to gate an `addUnionImports` BEFORE invoking
|
|
64
|
+
* {@link tryCompileSetReflectiveCall} — the arg-boxing (`__box_number`) the
|
|
65
|
+
* dispatch emits must be registered up-front (the direct path relies on
|
|
66
|
+
* extern.ts doing the same), since adding it mid-body would shift indices.
|
|
67
|
+
*/
|
|
68
|
+
export declare function isSetReflectiveCallShape(ctx: CodegenContext, expr: ts.CallExpression): boolean;
|
|
69
|
+
export declare function tryCompileSetReflectiveCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* (#2162) Intercept the `Set.prototype.size` accessor in standalone /
|
|
72
|
+
* `nativeStrings` mode → `__map_size` (returns i32). Receiver compiled here.
|
|
73
|
+
*/
|
|
74
|
+
export declare function tryCompileNativeSetSizeGet(ctx: CodegenContext, fctx: FunctionContext, receiver: ts.Expression): InnerResult | undefined;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { ValType } from '../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
4
|
+
/** Sentinel: expression compiled successfully but produces no value (void) */
|
|
5
|
+
export declare const VOID_RESULT: unique symbol;
|
|
6
|
+
export type InnerResult = ValType | null | typeof VOID_RESULT;
|
|
7
|
+
/**
|
|
8
|
+
* When `this` is typed as `any` (e.g., in function constructors), resolve the
|
|
9
|
+
* struct name from the local's ref type index. Used as a fallback when
|
|
10
|
+
* resolveStructName returns undefined for `this`-property accesses/assignments.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Skip "transparent" wrapper expressions that have no runtime effect — parens,
|
|
14
|
+
* `as`/`<T>` casts, `satisfies`, and non-null `!` — to reach the underlying
|
|
15
|
+
* expression. The local stand-in for `ts.skipOuterExpressions` (not surfaced by
|
|
16
|
+
* the project's ts-api shim). Used to let `(this as any).x` / `(B as any).c`
|
|
17
|
+
* resolve to the same receiver as `this.x` / `B.c` (#2020/#2027).
|
|
18
|
+
*/
|
|
19
|
+
export declare function skipTransparentExpressions(expr: ts.Expression): ts.Expression;
|
|
20
|
+
export declare function resolveThisStructName(ctx: CodegenContext, fctx: FunctionContext): string | undefined;
|
|
21
|
+
/** Check if two ValTypes are structurally equal */
|
|
22
|
+
export declare function valTypesMatch(a: ValType, b: ValType): boolean;
|
|
23
|
+
export declare function getLine(node: ts.Node): number;
|
|
24
|
+
export declare function getCol(node: ts.Node): number;
|
|
25
|
+
/**
|
|
26
|
+
* Fail fast at compile entry if any required codegen delegate is still its
|
|
27
|
+
* throwing stub (#2146). Without this, a missing registration surfaces only
|
|
28
|
+
* deep inside codegen — as an obscure "X not yet registered" — when (and if)
|
|
29
|
+
* the relevant feature happens to be exercised by the input program.
|
|
30
|
+
*
|
|
31
|
+
* Call this once per top-level codegen entry (`generateModule` /
|
|
32
|
+
* `generateMultiModule`). It is O(slots) and has no effect in the normal path
|
|
33
|
+
* where `src/compiler.ts` eagerly imports the registrar modules.
|
|
34
|
+
*/
|
|
35
|
+
export declare function assertCodegenRegistrationsComplete(): void;
|
|
36
|
+
type CompileExpressionFn = (ctx: CodegenContext, fctx: FunctionContext, expr: ts.Expression, expectedType?: ValType) => ValType | null;
|
|
37
|
+
export declare function registerCompileExpression(fn: CompileExpressionFn): void;
|
|
38
|
+
export declare function compileExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.Expression, expectedType?: ValType): ValType | null;
|
|
39
|
+
type CompileArrowAsClosureFn = (ctx: CodegenContext, fctx: FunctionContext, arrow: ts.ArrowFunction | ts.FunctionExpression) => ValType | null;
|
|
40
|
+
export declare function registerCompileArrowAsClosure(fn: CompileArrowAsClosureFn): void;
|
|
41
|
+
export declare function compileArrowAsClosure(ctx: CodegenContext, fctx: FunctionContext, arrow: ts.ArrowFunction | ts.FunctionExpression): ValType | null;
|
|
42
|
+
type EmitBoundsCheckedArrayGetFn = (fctx: FunctionContext, arrTypeIdx: number, elementType: ValType, ctx?: CodegenContext, useUndefinedSentinel?: boolean) => void;
|
|
43
|
+
export declare function registerEmitBoundsCheckedArrayGet(fn: EmitBoundsCheckedArrayGetFn): void;
|
|
44
|
+
export declare function emitBoundsCheckedArrayGet(fctx: FunctionContext, arrTypeIdx: number, elementType: ValType, ctx?: CodegenContext, useUndefinedSentinel?: boolean): void;
|
|
45
|
+
/**
|
|
46
|
+
* Best-effort name of the class lexically enclosing `fctx`. Prefers the
|
|
47
|
+
* explicit `enclosingClassName` carried on the context; otherwise falls back to
|
|
48
|
+
* the `${Class}_${method}` naming convention baked into compiled method names.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveEnclosingClassName(fctx: FunctionContext): string | undefined;
|
|
51
|
+
type CoerceTypeFn = (ctx: CodegenContext, fctx: FunctionContext, from: ValType, to: ValType, toPrimitiveHint?: "number" | "string" | "default") => void;
|
|
52
|
+
export declare function registerCoerceType(fn: CoerceTypeFn): void;
|
|
53
|
+
export declare function coerceType(ctx: CodegenContext, fctx: FunctionContext, from: ValType, to: ValType, toPrimitiveHint?: "number" | "string" | "default"): void;
|
|
54
|
+
type MaterializeStructAsObjectFn = (ctx: CodegenContext, fctx: FunctionContext, structTypeIdx: number) => boolean;
|
|
55
|
+
export declare function registerMaterializeStructAsObject(fn: MaterializeStructAsObjectFn): void;
|
|
56
|
+
export declare function materializeStructAsObject(ctx: CodegenContext, fctx: FunctionContext, structTypeIdx: number): boolean;
|
|
57
|
+
type EnsureLateImportFn = (ctx: CodegenContext, name: string, paramTypes: ValType[], resultTypes: ValType[]) => number | undefined;
|
|
58
|
+
type FlushLateImportShiftsFn = (ctx: CodegenContext, fctx: FunctionContext | null) => void;
|
|
59
|
+
export declare function registerEnsureLateImport(fn: EnsureLateImportFn): void;
|
|
60
|
+
export declare function registerFlushLateImportShifts(fn: FlushLateImportShiftsFn): void;
|
|
61
|
+
export declare function ensureLateImport(ctx: CodegenContext, name: string, paramTypes: ValType[], resultTypes: ValType[]): number | undefined;
|
|
62
|
+
export declare function flushLateImportShifts(ctx: CodegenContext, fctx: FunctionContext | null): void;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a ValType is the any-value boxed type used for TS `any`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function isAnyValue(type: ValType, ctx: CodegenContext): boolean;
|
|
67
|
+
type EnsureAnyHelpersFn = (ctx: CodegenContext) => void;
|
|
68
|
+
export declare function registerEnsureAnyHelpers(fn: EnsureAnyHelpersFn): void;
|
|
69
|
+
type AddUnionImportsFn = (ctx: CodegenContext) => void;
|
|
70
|
+
export declare function registerAddUnionImports(fn: AddUnionImportsFn): void;
|
|
71
|
+
export declare function addUnionImportsViaRegistry(ctx: CodegenContext): void;
|
|
72
|
+
export declare function ensureAnyHelpers(ctx: CodegenContext): void;
|
|
73
|
+
type ResolveComputedKeyExpressionFn = (ctx: CodegenContext, expr: ts.Expression) => string | undefined;
|
|
74
|
+
export declare function registerResolveComputedKeyExpression(fn: ResolveComputedKeyExpressionFn): void;
|
|
75
|
+
export declare function resolveComputedKeyExpression(ctx: CodegenContext, expr: ts.Expression): string | undefined;
|
|
76
|
+
type CompileStatementFn = (ctx: CodegenContext, fctx: FunctionContext, stmt: ts.Statement) => void;
|
|
77
|
+
export declare function registerCompileStatement(fn: CompileStatementFn): void;
|
|
78
|
+
export declare function compileStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.Statement): void;
|
|
79
|
+
type EnsureBindingLocalsFn = (ctx: CodegenContext, fctx: FunctionContext, pattern: ts.BindingPattern) => void;
|
|
80
|
+
export declare function registerEnsureBindingLocals(fn: EnsureBindingLocalsFn): void;
|
|
81
|
+
export declare function ensureBindingLocals(ctx: CodegenContext, fctx: FunctionContext, pattern: ts.BindingPattern): void;
|
|
82
|
+
type HoistFunctionDeclarationsFn = (ctx: CodegenContext, fctx: FunctionContext, stmts: ts.NodeArray<ts.Statement> | ts.Statement[]) => void;
|
|
83
|
+
export declare function registerHoistFunctionDeclarations(fn: HoistFunctionDeclarationsFn): void;
|
|
84
|
+
export declare function hoistFunctionDeclarations(ctx: CodegenContext, fctx: FunctionContext, stmts: ts.NodeArray<ts.Statement> | ts.Statement[]): void;
|
|
85
|
+
type EmitNestedBindingDefaultFn = (ctx: CodegenContext, fctx: FunctionContext, nestedLocal: number, valueType: ValType, initializer: ts.Expression) => void;
|
|
86
|
+
export declare function registerEmitNestedBindingDefault(fn: EmitNestedBindingDefaultFn): void;
|
|
87
|
+
export declare function emitNestedBindingDefault(ctx: CodegenContext, fctx: FunctionContext, nestedLocal: number, valueType: ValType, initializer: ts.Expression): void;
|
|
88
|
+
type EmitDefaultValueCheckFn = (ctx: CodegenContext, fctx: FunctionContext, fieldType: ValType, localIdx: number, initializer: ts.Expression, targetType?: ValType, objectPropertySemantics?: boolean) => void;
|
|
89
|
+
export declare function registerEmitDefaultValueCheck(fn: EmitDefaultValueCheckFn): void;
|
|
90
|
+
export declare function emitDefaultValueCheck(ctx: CodegenContext, fctx: FunctionContext, fieldType: ValType, localIdx: number, initializer: ts.Expression, targetType?: ValType, objectPropertySemantics?: boolean): void;
|
|
91
|
+
type EmitArgumentsObjectFn = (ctx: CodegenContext, fctx: FunctionContext, paramTypes: ValType[], paramOffset: number, unmapped?: boolean) => void;
|
|
92
|
+
export declare function registerEmitArgumentsObject(fn: EmitArgumentsObjectFn): void;
|
|
93
|
+
/**
|
|
94
|
+
* `unmapped`: when true (strict-mode functions, §10.4.4) the param↔arguments
|
|
95
|
+
* sync is suppressed so writes to `arguments[i]` do not flow back into the
|
|
96
|
+
* named parameter (#779e). Defaults to false (sloppy, mapped).
|
|
97
|
+
*/
|
|
98
|
+
export declare function emitArgumentsObject(ctx: CodegenContext, fctx: FunctionContext, paramTypes: ValType[], paramOffset: number, unmapped?: boolean): void;
|
|
99
|
+
type CompileStringLiteralFn = (ctx: CodegenContext, fctx: FunctionContext, value: string, node?: ts.Node) => ValType | null;
|
|
100
|
+
export declare function registerCompileStringLiteral(fn: CompileStringLiteralFn): void;
|
|
101
|
+
export declare function compileStringLiteral(ctx: CodegenContext, fctx: FunctionContext, value: string, node?: ts.Node): ValType | null;
|
|
102
|
+
type CompileSuperPropertyAccessFn = (ctx: CodegenContext, fctx: FunctionContext, expr: ts.PropertyAccessExpression, propName: string) => ValType | null;
|
|
103
|
+
export declare function registerCompileSuperPropertyAccess(fn: CompileSuperPropertyAccessFn): void;
|
|
104
|
+
export declare function compileSuperPropertyAccess(ctx: CodegenContext, fctx: FunctionContext, expr: ts.PropertyAccessExpression, propName: string): ValType | null;
|
|
105
|
+
type CompileSuperElementAccessFn = (ctx: CodegenContext, fctx: FunctionContext, expr: ts.ElementAccessExpression) => ValType | null;
|
|
106
|
+
export declare function registerCompileSuperElementAccess(fn: CompileSuperElementAccessFn): void;
|
|
107
|
+
export declare function compileSuperElementAccess(ctx: CodegenContext, fctx: FunctionContext, expr: ts.ElementAccessExpression): ValType | null;
|
|
108
|
+
type AddStringImportsFn = (ctx: CodegenContext) => void;
|
|
109
|
+
export declare function registerAddStringImports(fn: AddStringImportsFn): void;
|
|
110
|
+
export declare function addStringImportsDelegate(ctx: CodegenContext): void;
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { WasmModule } from '../ir/types.js';
|
|
2
|
+
export type FixupKind = "drop-excess" | "default-value-lossy" | "branch-type-coerce" | "branch-type-cast" | "call-arg-coerce" | "struct-field-coerce" | "local-set-coerce";
|
|
3
|
+
/** A single located fixup the pass applied while repairing emitter output. */
|
|
4
|
+
export interface FixupEvent {
|
|
5
|
+
readonly kind: FixupKind;
|
|
6
|
+
/** Name of the function (or `func#N`) the fixup was applied in. */
|
|
7
|
+
readonly func: string;
|
|
8
|
+
/** Human-readable detail (e.g. `f64 default for missing branch value`). */
|
|
9
|
+
readonly detail: string;
|
|
10
|
+
/** True for repairs that can change runtime semantics (currently the const-default arm). */
|
|
11
|
+
readonly lossy: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Events collected during the most recent `stackBalance(mod)` run (#1918).
|
|
15
|
+
* Returns a copy so callers can't mutate the collector. `stackBalance` resets
|
|
16
|
+
* it at the start of every run, so this reflects exactly one module's repairs.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getFixupEvents(): FixupEvent[];
|
|
19
|
+
/** Aggregate fixup events into per-kind counts (#1918). Always includes every kind. */
|
|
20
|
+
export declare function summarizeFixups(events: readonly FixupEvent[]): Record<FixupKind, number>;
|
|
21
|
+
/** A strict-balance diagnostic ready to push onto a codegen error sink (#1918). */
|
|
22
|
+
export interface StrictBalanceDiagnostic {
|
|
23
|
+
readonly message: string;
|
|
24
|
+
readonly line: 0;
|
|
25
|
+
readonly column: 0;
|
|
26
|
+
readonly severity: "error" | "warning";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Strict-balance mode (#1918). Controlled by `JS2WASM_STRICT_BALANCE`:
|
|
30
|
+
*
|
|
31
|
+
* unset / "0" / "off" — silent (default; preserves existing behaviour)
|
|
32
|
+
* "1" / "true" / "warn" — every fixup becomes a located severity-"warning"
|
|
33
|
+
* "error" / "strict" — every fixup becomes a severity-"error" (fails the
|
|
34
|
+
* compile); for CI experiments and new code that
|
|
35
|
+
* should never need a repair.
|
|
36
|
+
*
|
|
37
|
+
* Returns the diagnostics to surface. The caller (`src/codegen/index.ts`,
|
|
38
|
+
* which holds `ctx`) pushes them onto `ctx.errors` — strict errors then fail
|
|
39
|
+
* the WasmGC compile through the existing `severity === "error"` gate, which
|
|
40
|
+
* `mod.codegenErrors` does NOT reach on the WasmGC path (see #2090).
|
|
41
|
+
*/
|
|
42
|
+
export declare function strictBalanceDiagnostics(events: readonly FixupEvent[]): StrictBalanceDiagnostic[];
|
|
43
|
+
export declare function stackBalance(mod: WasmModule): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
export declare function compileReturnStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.ReturnStatement): void;
|
|
4
|
+
export declare function compileIfStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.IfStatement): void;
|
|
5
|
+
export declare function compileSwitchStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.SwitchStatement): void;
|
|
6
|
+
/**
|
|
7
|
+
* Destructure a for-of element stored in `elemLocal` into the bindings of a
|
|
8
|
+
* destructuring pattern. Handles both object and array binding patterns with
|
|
9
|
+
* default values.
|
|
10
|
+
*/
|
|
11
|
+
export declare function compileLabeledStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.LabeledStatement): void;
|
|
12
|
+
export declare function compileBreakStatement(_ctx: CodegenContext, fctx: FunctionContext, stmt: ts.BreakStatement): void;
|
|
13
|
+
export declare function compileContinueStatement(_ctx: CodegenContext, fctx: FunctionContext, stmt: ts.ContinueStatement): void;
|
|
14
|
+
/**
|
|
15
|
+
* Evaluate a condition expression at compile time if possible.
|
|
16
|
+
* Returns true/false for constant conditions, undefined if not constant.
|
|
17
|
+
*
|
|
18
|
+
* Handles:
|
|
19
|
+
* - `"x" === "y"`, `"x" !== "y"` (string literal comparisons)
|
|
20
|
+
* - `true`, `false` literals
|
|
21
|
+
* - `!<constant>` (prefix logical not)
|
|
22
|
+
* - `"x" == "y"`, `"x" != "y"` (loose equality on string literals)
|
|
23
|
+
* - `&&` and `||` with constant operands
|
|
24
|
+
*/
|
|
25
|
+
export declare function evaluateConstantCondition(expr: ts.Expression): boolean | undefined;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* (#1719 S1) Gate predicate for the array object-value representation track.
|
|
6
|
+
*
|
|
7
|
+
* Returns true iff array destructuring of a **typed vec / tuple RHS** must
|
|
8
|
+
* route through the host-Array reflection + host `GetIterator` lane instead of
|
|
9
|
+
* the backing-store fast path — i.e. when the program's `ITER_OVERRIDDEN`
|
|
10
|
+
* whole-program brand (`ctx.arrayIteratorMaybeOverridden`, set by
|
|
11
|
+
* `sourceOverridesArrayIterator`) is set AND the RHS is not a string.
|
|
12
|
+
*
|
|
13
|
+
* The string exclusion is load-bearing: a string is not an Array, so a
|
|
14
|
+
* monkeypatched `Array.prototype[@@iterator]` cannot affect string
|
|
15
|
+
* destructuring, and routing a string through the array iterator lane would
|
|
16
|
+
* regress string dstr (per the architecture spec).
|
|
17
|
+
*
|
|
18
|
+
* **S1 status (this PR):** this predicate establishes the *placement and
|
|
19
|
+
* string guard* the architecture spec mandates keeping from dev-a's
|
|
20
|
+
* scaffolding, but the routing target it gates is supplied by **S2** (the
|
|
21
|
+
* host-Array reflection helper + host `GetIterator`). Until S2 lands, callers
|
|
22
|
+
* evaluate this predicate but fall through to the existing fast path — so the
|
|
23
|
+
* predicate is correct and unit-tested while the codegen is behaviorally a
|
|
24
|
+
* no-op (zero test delta, the spec's S1 requirement). When
|
|
25
|
+
* `ctx.arrayIteratorMaybeOverridden` is false (the common case) this is always
|
|
26
|
+
* false, guaranteeing byte-identical output.
|
|
27
|
+
*
|
|
28
|
+
* Spec: §7.4.2 GetIterator, §8.5.2 IteratorBindingInitialization.
|
|
29
|
+
*/
|
|
30
|
+
export declare function arrayDstrNeedsIdentity(ctx: CodegenContext, isStringRHS: boolean): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* (#1719 CPR read-drive) Drive a captured `Array.prototype[@@iterator]` override
|
|
33
|
+
* for a typed-vec/tuple array-destructuring RHS, so the override's custom
|
|
34
|
+
* iterator (not the backing store) supplies the binding values
|
|
35
|
+
* (§8.5.2 IteratorBindingInitialization). PRECONDITION: the vec ref is on the
|
|
36
|
+
* stack and the caller gated on `arrayDstrNeedsIdentity && override-captured`.
|
|
37
|
+
*
|
|
38
|
+
* Scope (CPR-1): the binding pattern is all **identifier** elements (with optional
|
|
39
|
+
* `= default`) and elisions, **no rest / no nested** pattern — exactly the shape
|
|
40
|
+
* of the 71 `*-iter-val-array-prototype.js` tests. Returns `false` (caller falls
|
|
41
|
+
* through to the backing-store fast path) for rest/nested patterns so those are
|
|
42
|
+
* not regressed; CPR-2 widens the shape.
|
|
43
|
+
*
|
|
44
|
+
* Lowering: drive override → iterator (in-Wasm, `__drive_proto_iterator`), then
|
|
45
|
+
* per element `__iterator_next` → `(i32 done, externref value)`; on `done` the
|
|
46
|
+
* element takes its default (or `undefined`), else `value` coerced to the binding
|
|
47
|
+
* local's type. The brand only fires at this observation boundary, so internal
|
|
48
|
+
* array iterations inside the override body stay on the typed-vec fast path — no
|
|
49
|
+
* re-entrancy / no infinite loop.
|
|
50
|
+
*/
|
|
51
|
+
export declare function tryEmitArrayProtoIteratorReadDrive(ctx: CodegenContext, fctx: FunctionContext, pattern: ts.ArrayBindingPattern, resultType: ValType,
|
|
52
|
+
/**
|
|
53
|
+
* (#1719 CPR-2) When provided, the array value is read from this local instead
|
|
54
|
+
* of consumed from the stack — lets the for-of-head / parameter dstr sites
|
|
55
|
+
* (whose value lives in a local) reuse this exact drive+drain. `undefined` ⇒
|
|
56
|
+
* the decl-dstr caller's convention (vec ref already on the stack).
|
|
57
|
+
*/
|
|
58
|
+
srcLocal?: number): boolean;
|
|
59
|
+
export declare function ensureBindingLocals(ctx: CodegenContext, fctx: FunctionContext, pattern: ts.BindingPattern): void;
|
|
60
|
+
/**
|
|
61
|
+
* After destructuring, sync any bound locals that have corresponding module
|
|
62
|
+
* globals. Destructuring stores values into locals, but module-level variables
|
|
63
|
+
* need to also be written via global.set so other functions can read them.
|
|
64
|
+
*/
|
|
65
|
+
export declare function syncDestructuredLocalsToGlobals(ctx: CodegenContext, fctx: FunctionContext, pattern: ts.BindingPattern): void;
|
|
66
|
+
/**
|
|
67
|
+
* Wrap a set of destructuring instructions in a null guard.
|
|
68
|
+
*
|
|
69
|
+
* For `ref_null` source types the instructions are only executed when the
|
|
70
|
+
* reference is non-null:
|
|
71
|
+
*
|
|
72
|
+
* local.get $srcLocal
|
|
73
|
+
* ref.is_null
|
|
74
|
+
* if (then: [] else: <instrs>)
|
|
75
|
+
*
|
|
76
|
+
* For non-nullable refs the instructions are emitted directly.
|
|
77
|
+
*
|
|
78
|
+
* `emitFn` should populate `fctx.body` with the instructions to guard.
|
|
79
|
+
* The helper temporarily swaps `fctx.body` so the caller's body is not
|
|
80
|
+
* modified by `emitFn`.
|
|
81
|
+
*/
|
|
82
|
+
export declare function emitNullGuard(ctx: CodegenContext, fctx: FunctionContext, srcLocal: number, isNullable: boolean, emitFn: () => void, srcKind?: ValType["kind"]): void;
|
|
83
|
+
/**
|
|
84
|
+
* Ensure __async_iterator is available; return its function index.
|
|
85
|
+
*
|
|
86
|
+
* JS-host mode: register `env.__async_iterator`
|
|
87
|
+
* (obj) => obj[Symbol.asyncIterator]?.() ?? obj[Symbol.iterator]()
|
|
88
|
+
*
|
|
89
|
+
* (#2038) Standalone / WASI: there is no JS host to satisfy that import, and
|
|
90
|
+
* feeding the host carrier to the native `__iterator_next` traps `illegal cast`.
|
|
91
|
+
* Per §7.4.3 GetIterator(async) + §27.1.4.1 CreateAsyncFromSyncIterator, for a
|
|
92
|
+
* **sync-backed** async iterable (the dominant test262 shape — `for await (x of
|
|
93
|
+
* [literals])` and `for await (x of syncIterable)`) the async iterator is the
|
|
94
|
+
* sync iterator with each value `Await`-ed; for an already-settled value
|
|
95
|
+
* `Await(v) = v`, so the async wrapper degenerates to the *identity* native
|
|
96
|
+
* iterator. So in standalone we return the SAME native `__iterator` the sync
|
|
97
|
+
* for-of consumer uses (now USER-`{next()}`-carrier aware). The per-element
|
|
98
|
+
* `Await` is layered by the for-await CPS lowering around the loop body and is a
|
|
99
|
+
* no-op for settled values — no `env.__async_iterator` / `env.Promise_resolve`
|
|
100
|
+
* leak. Genuinely-pending-Promise async iterables stay deferred to the standalone
|
|
101
|
+
* Promise runtime (PR-C).
|
|
102
|
+
*/
|
|
103
|
+
export declare function ensureAsyncIterator(ctx: CodegenContext, fctx: FunctionContext): number | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Ensure __extern_is_undefined import is available.
|
|
106
|
+
* Returns the function index, or undefined if registration failed.
|
|
107
|
+
* JS impl: (v: unknown) => v === undefined ? 1 : 0
|
|
108
|
+
*/
|
|
109
|
+
export declare function ensureExternIsUndefined(ctx: CodegenContext, fctx: FunctionContext): number | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Emit a check for whether an externref value should trigger a default value.
|
|
112
|
+
* Per JS spec, destructuring defaults apply when the value is `undefined`.
|
|
113
|
+
* We check both ref.is_null (wasm null, e.g. uninitialized array slots) and
|
|
114
|
+
* JS undefined (non-null externref wrapping the JS undefined value).
|
|
115
|
+
*
|
|
116
|
+
* Precondition: externref value on the stack and saved in tmpLocal.
|
|
117
|
+
* Postcondition: i32 on the stack (1 = use default, 0 = has value).
|
|
118
|
+
*/
|
|
119
|
+
export declare function emitExternrefDefaultCheck(ctx: CodegenContext, fctx: FunctionContext, tmpLocal: number): void;
|
|
120
|
+
/**
|
|
121
|
+
* Emit a default-value check for a nested binding pattern in array destructuring.
|
|
122
|
+
*
|
|
123
|
+
* When an array element is a nested binding pattern with a default initializer
|
|
124
|
+
* (e.g. `[{ x, y } = defaults]`), we need to check if the extracted value is
|
|
125
|
+
* null/undefined and if so, compile the initializer and store it as the value
|
|
126
|
+
* before the nested destructuring runs.
|
|
127
|
+
*/
|
|
128
|
+
export declare function emitNestedBindingDefault(ctx: CodegenContext, fctx: FunctionContext, nestedLocal: number, valueType: ValType, initializer: ts.Expression): void;
|
|
129
|
+
/**
|
|
130
|
+
* Emit a default-value check for a destructured binding.
|
|
131
|
+
*
|
|
132
|
+
* The stack must contain the extracted field/element value. For externref
|
|
133
|
+
* types we check `ref.is_null || __extern_is_undefined` — JS destructuring
|
|
134
|
+
* defaults apply when the value is `undefined`. For f64 we check for NaN
|
|
135
|
+
* (the "undefined" sentinel). For i32 there is no reliable sentinel so we
|
|
136
|
+
* just assign directly.
|
|
137
|
+
*
|
|
138
|
+
* @param fieldType - the Wasm type of the value currently on the stack
|
|
139
|
+
* @param localIdx - destination local for the bound variable
|
|
140
|
+
* @param initializer - the TS default-value expression
|
|
141
|
+
* @param targetType - optional override for the type hint passed to compileExpression
|
|
142
|
+
* @param objectPropertySemantics - when true, the value originates from an
|
|
143
|
+
* object property read (KeyedBindingInitialization §13.3.3.7), where every
|
|
144
|
+
* declared field exists and a `null` value is a genuine JS `null` — NOT a
|
|
145
|
+
* "missing" hole. Per spec the default fires only on `undefined`, so JS
|
|
146
|
+
* `null` (encoded as wasm-null / ref.null.extern) must NOT trigger it. For
|
|
147
|
+
* `ref`/`ref_null` fields we therefore convert to externref and use the
|
|
148
|
+
* strict `__extern_is_undefined` predicate instead of `ref.is_null` (which
|
|
149
|
+
* would wrongly fire for `null`). Array/iterator binding (§13.3.3.6) leaves
|
|
150
|
+
* this false: a wasm-null element there can mean "iterator exhausted /
|
|
151
|
+
* missing", which DOES fire the default.
|
|
152
|
+
*/
|
|
153
|
+
export declare function emitDefaultValueCheck(ctx: CodegenContext, fctx: FunctionContext, fieldType: ValType, localIdx: number, initializer: ts.Expression, targetType?: ValType, objectPropertySemantics?: boolean): void;
|
|
154
|
+
export declare function compileObjectDestructuring(ctx: CodegenContext, fctx: FunctionContext, decl: ts.VariableDeclaration): void;
|
|
155
|
+
/**
|
|
156
|
+
* Destructure an externref value using the shared param-destructure helper
|
|
157
|
+
* (`destructureParamObject` in decl mode).
|
|
158
|
+
*
|
|
159
|
+
* Fallback for when the source type is unknown/any/externref (no struct info
|
|
160
|
+
* available). The externref on the WasmGC stack is stashed into a temp local
|
|
161
|
+
* and handed to `destructureParamObject`, which routes through its externref
|
|
162
|
+
* branch — including the `ref.test`/`struct.get` fast path for known struct
|
|
163
|
+
* types, per-element null/undefined guards, NamedEvaluation of function/class
|
|
164
|
+
* defaults, and enumerable-correct rest collection. This replaces the legacy
|
|
165
|
+
* twin that had drifted from the param path (#1553c — root causes 1, 2, 4, 8).
|
|
166
|
+
*
|
|
167
|
+
* @deprecated Internal callers (nested patterns, for-of/for-in heads) still
|
|
168
|
+
* reach this shim; the export is retained for compile compatibility until
|
|
169
|
+
* #1553d removes it. New code should call `destructureParamObject` directly.
|
|
170
|
+
*/
|
|
171
|
+
export declare function compileExternrefObjectDestructuringDecl(ctx: CodegenContext, fctx: FunctionContext, pattern: ts.ObjectBindingPattern, resultType: ValType): void;
|
|
172
|
+
/**
|
|
173
|
+
* Destructure an externref value using __extern_get(obj, boxed_index) for each element.
|
|
174
|
+
* Handles cases where the RHS is dynamically typed (e.g. arguments, iterators, function returns).
|
|
175
|
+
*/
|
|
176
|
+
export declare function compileExternrefArrayDestructuringDecl(ctx: CodegenContext, fctx: FunctionContext, pattern: ts.ArrayBindingPattern, resultType: ValType): void;
|
|
177
|
+
export declare function compileArrayDestructuring(ctx: CodegenContext, fctx: FunctionContext, decl: ts.VariableDeclaration): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
export declare function compileThrowStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.ThrowStatement): void;
|
|
4
|
+
export declare function compileTryStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.TryStatement): void;
|
|
5
|
+
/** Compile a function declaration nested inside another function.
|
|
6
|
+
* Lifts the function to module level. If it captures outer-scope variables,
|
|
7
|
+
* uses a closure struct (like arrow closures). Otherwise uses a direct call. */
|
|
8
|
+
/**
|
|
9
|
+
* Handle a ClassDeclaration in statement position (inside for loops, if blocks, etc.).
|
|
10
|
+
* Collects the class struct/methods and compiles their bodies immediately.
|
|
11
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
export declare function compileWhileStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.WhileStatement): void;
|
|
4
|
+
export declare function compileForStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.ForStatement): void;
|
|
5
|
+
export declare function compileDoWhileStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.DoStatement): void;
|
|
6
|
+
export declare function compileForOfStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.ForOfStatement): void;
|
|
7
|
+
export declare function compileForInStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.ForInStatement): void;
|