@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,38 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { ValType } from '../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
4
|
+
import { InnerResult } from './shared.js';
|
|
5
|
+
/**
|
|
6
|
+
* Compile `delete expr`.
|
|
7
|
+
* - `delete obj.prop` / `delete obj[key]`: set the field to a sentinel (undefined) value, return true
|
|
8
|
+
* - `delete identifier`: return false (i32 0) — variables are not deletable
|
|
9
|
+
* - `delete otherExpr`: compile for side effects, drop, return true (i32 1)
|
|
10
|
+
*
|
|
11
|
+
* WasmGC struct fields cannot be removed at runtime, so we simulate deletion
|
|
12
|
+
* by setting the field to a sentinel value (ref.null for ref types, NaN for f64).
|
|
13
|
+
* Property reads of ref.null / NaN naturally produce undefined-like behavior.
|
|
14
|
+
*/
|
|
15
|
+
export declare function compileDeleteExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.DeleteExpression): InnerResult;
|
|
16
|
+
/**
|
|
17
|
+
* Compile a RegExp literal (e.g. /\d+/g) by desugaring it to new RegExp(pattern, flags).
|
|
18
|
+
* The pattern and flags strings are loaded from the string pool, then RegExp_new is called.
|
|
19
|
+
*/
|
|
20
|
+
export declare function compileRegExpLiteral(ctx: CodegenContext, fctx: FunctionContext, expr: ts.Expression): ValType | null;
|
|
21
|
+
/**
|
|
22
|
+
* Compile `expr instanceof ClassName`.
|
|
23
|
+
* Reads the hidden __tag field (index 0) from the struct and compares
|
|
24
|
+
* it against the class's compile-time tag value (and all descendant tags
|
|
25
|
+
* for class hierarchy support).
|
|
26
|
+
*/
|
|
27
|
+
export declare function compileInstanceOf(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): ValType | null;
|
|
28
|
+
/**
|
|
29
|
+
* Compile `typeof x` as a standalone expression that returns a type string (externref).
|
|
30
|
+
* For statically known types, emits the string constant directly.
|
|
31
|
+
* For externref/union types, calls the __typeof host helper.
|
|
32
|
+
*/
|
|
33
|
+
export declare function compileTypeofExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.TypeOfExpression): ValType | null;
|
|
34
|
+
/**
|
|
35
|
+
* Compile `typeof x === "number"` / `typeof x !== "string"` etc.
|
|
36
|
+
* Returns i32 result, or null if the expression is not a typeof comparison.
|
|
37
|
+
*/
|
|
38
|
+
export declare function compileTypeofComparison(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): ValType | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CodegenContext } from './context/types.js';
|
|
2
|
+
/** Helper-name -> mask routed at the call site (calls.ts). */
|
|
3
|
+
export declare const URI_ENCODE_MASK: Record<string, number>;
|
|
4
|
+
/**
|
|
5
|
+
* Helper-name -> reservedMask for `__uri_decode`. `decodeURIComponent` unescapes
|
|
6
|
+
* everything (reservedSet empty → 0); `decodeURI` keeps the `reservedURISet`
|
|
7
|
+
* (`; / ? : @ & = + $ , #`) escaped → re-emits those single-octet escapes
|
|
8
|
+
* verbatim (mask bit 0 set).
|
|
9
|
+
*/
|
|
10
|
+
export declare const URI_DECODE_MASK: Record<string, number>;
|
|
11
|
+
/**
|
|
12
|
+
* Emit the native `__uri_encode(s: externref, preservedMask: i32) -> externref`
|
|
13
|
+
* helper and register it in `ctx.funcMap`. Idempotent. Must run after
|
|
14
|
+
* `ensureNativeStringHelpers` (it calls it) so `__str_flatten` and the
|
|
15
|
+
* NativeString types exist, and before any function body that calls it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function emitNativeUriEncode(ctx: CodegenContext): void;
|
|
18
|
+
/**
|
|
19
|
+
* Emit the native `__uri_decode(s: externref, reservedMask: i32) -> externref`
|
|
20
|
+
* helper (ECMAScript §19.2.6.4 Decode) and register it in `ctx.funcMap`.
|
|
21
|
+
* Idempotent. Mirrors `emitNativeUriEncode`'s registration discipline (claim the
|
|
22
|
+
* funcIdx only after `emitWasiErrorConstructor` appends `__new_URIError`).
|
|
23
|
+
*
|
|
24
|
+
* Scans the flattened i16 buffer. On `%`, parses 2 hex digits → a UTF-8 leading
|
|
25
|
+
* byte, determines the sequence length (1-4), reads the continuation `%XX`
|
|
26
|
+
* octets, validates them (RFC 3629: leading-byte ranges, `10xxxxxx`
|
|
27
|
+
* continuations, no overlong forms, code point ≤ 0x10FFFF, no surrogate range),
|
|
28
|
+
* reassembles the code point, and re-encodes it to 1 or 2 UTF-16 code units.
|
|
29
|
+
* A single-octet ASCII char in the `reservedURISet` (mask bit 0, for decodeURI)
|
|
30
|
+
* is re-emitted as its original uppercased `%XX` escape verbatim. Any malformed
|
|
31
|
+
* input → catchable **URIError**.
|
|
32
|
+
*/
|
|
33
|
+
export declare function emitNativeUriDecode(ctx: CodegenContext): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { Instr, ValType } from '../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Canonical JS-type tag for the `$AnyValue` boxed representation.
|
|
6
|
+
*
|
|
7
|
+
* Invariant V1 (tag fidelity): the tag always equals the value's ECMAScript
|
|
8
|
+
* type partition (the `typeof` partition with `null` split out). No consumer may
|
|
9
|
+
* infer a JS type from a Wasm kind.
|
|
10
|
+
*
|
|
11
|
+
* Invariant V2 (numeric class): tags 2 and 3 are ONE JS type (`number`) — one
|
|
12
|
+
* uses the i32 payload, one the f64 payload. Equality / relational / typeof /
|
|
13
|
+
* ToString helpers must treat `{2,3}` as a single class.
|
|
14
|
+
*
|
|
15
|
+
* These values MUST match the runtime tags written by the `__any_box_*` helpers
|
|
16
|
+
* in `any-helpers.ts` (asserted by tests). `Function` (7) is reserved for a
|
|
17
|
+
* later phase (today closures box as `Object`).
|
|
18
|
+
*
|
|
19
|
+
* (Plain `enum`, not `const enum` — Biome's `noConstEnum` forbids the latter;
|
|
20
|
+
* the numeric values are still inlined at our use sites.)
|
|
21
|
+
*/
|
|
22
|
+
export declare enum JsTag {
|
|
23
|
+
Null = 0,
|
|
24
|
+
Undefined = 1,
|
|
25
|
+
NumberI32 = 2,
|
|
26
|
+
NumberF64 = 3,
|
|
27
|
+
Boolean = 4,
|
|
28
|
+
String = 5,
|
|
29
|
+
Object = 6,
|
|
30
|
+
Function = 7
|
|
31
|
+
}
|
|
32
|
+
/** Static JS-type classification of an expression, resolved from its TS type. */
|
|
33
|
+
export type JsStaticType = "null" | "undefined" | "boolean" | "number" | "string" | "bigint" | "object" | "function" | "unknown";
|
|
34
|
+
/**
|
|
35
|
+
* Classify a TS type into its JS-type partition. Returns `"unknown"` for
|
|
36
|
+
* `any`/`unknown`/unions that don't resolve to a single partition — callers
|
|
37
|
+
* then fall back to the Wasm-kind-keyed boxing path (behaviour-preserving).
|
|
38
|
+
*/
|
|
39
|
+
export declare function jsStaticType(t: ts.Type | undefined): JsStaticType;
|
|
40
|
+
/**
|
|
41
|
+
* The de-facto undefined-in-f64 sentinel, named once here (14 ad-hoc sites
|
|
42
|
+
* elsewhere predate this module). It is a SIGNALING NaN — JS arithmetic only
|
|
43
|
+
* ever produces the quiet NaN `0x7FF8000000000000`, so this bit pattern can
|
|
44
|
+
* carry "undefined" through an f64 carrier without colliding with a computed
|
|
45
|
+
* NaN. Observers in unsound contexts (`=== undefined`, `??`, `typeof`,
|
|
46
|
+
* ToString) test for it; sound contexts (arithmetic, relational, ToBoolean)
|
|
47
|
+
* ignore it because it already behaves as NaN. P3 (#2106) wires the observers;
|
|
48
|
+
* Phase 1 only centralizes the constant + emit helpers.
|
|
49
|
+
*/
|
|
50
|
+
export declare const UNDEF_F64_BITS = 9218868440963334366n;
|
|
51
|
+
/** Push the undefined-f64 sentinel onto the stack (`i64.const` + reinterpret). */
|
|
52
|
+
export declare function pushUndefF64(body: Instr[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Emit a test that the f64 on the stack is exactly the undefined sentinel,
|
|
55
|
+
* leaving an i32 (1 = is-undef) on the stack. Uses the i64 bit pattern compare
|
|
56
|
+
* (NOT `f64.eq`, which is false for any NaN including the sentinel).
|
|
57
|
+
*/
|
|
58
|
+
export declare function emitIsUndefF64(body: Instr[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Box a value of Wasm ValType `from` (top of stack) into a `ref $AnyValue`,
|
|
61
|
+
* the single boxing entry point. `jsType` is the static JS-type hint when
|
|
62
|
+
* resolvable; `"unknown"` reproduces the historical Wasm-kind-keyed dispatch
|
|
63
|
+
* exactly so this is behaviour-preserving by construction.
|
|
64
|
+
*
|
|
65
|
+
* Returns true if it emitted a box call (caller is done); false if no helper
|
|
66
|
+
* was available (caller falls through to its prior handling — matches the old
|
|
67
|
+
* `if (funcIdx !== undefined)` guards).
|
|
68
|
+
*
|
|
69
|
+
* `ensureAnyHelpers`/`addUnionImports` are the caller's responsibility (as in
|
|
70
|
+
* the old `coerceType` arm) — this function only selects + emits the call so it
|
|
71
|
+
* stays a pure dispatch over `ctx.funcMap` and cannot itself trigger a
|
|
72
|
+
* late-import funcIdx shift between resolution and call.
|
|
73
|
+
*/
|
|
74
|
+
export declare function boxToAny(ctx: CodegenContext, fctx: FunctionContext, from: ValType, jsType: JsStaticType): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Instr } from '../ir/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Walk all instructions in `instrs`, calling `visitor` on each one.
|
|
4
|
+
* Automatically descends into nested blocks: body, then, else, catches, catchAll.
|
|
5
|
+
*
|
|
6
|
+
* Implemented iteratively with an explicit frame stack so the JS call stack
|
|
7
|
+
* depth is O(1) regardless of Wasm block nesting. This matters because the
|
|
8
|
+
* walker runs synchronously inside already-deep codegen frames (via
|
|
9
|
+
* flushLateImportShifts → shiftLateImportIndices), and recursive composition
|
|
10
|
+
* with the compile stack tripped V8 stack limits under tight CI cgroup
|
|
11
|
+
* budgets. Pre-order semantics preserved: visit(instr) fires before recursion
|
|
12
|
+
* into its children, and siblings are visited in source order.
|
|
13
|
+
*/
|
|
14
|
+
export declare function walkInstructions(instrs: Instr[], visitor: (instr: Instr) => void): void;
|
|
15
|
+
/**
|
|
16
|
+
* Invoke `fn` on every nested instruction array (body, then, else, catches, catchAll)
|
|
17
|
+
* found on a single instruction. Does NOT recurse -- the caller is responsible for
|
|
18
|
+
* driving recursion (e.g. by calling walkChildren again inside fn).
|
|
19
|
+
*/
|
|
20
|
+
export declare function walkChildren(instr: Instr, fn: (children: Instr[]) => void): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 `__weakset_add(m, v) -> ref $Map` helper (idempotent). WeakSet.add
|
|
6
|
+
* stores the element as both key and value (so the shared Map lookup sees a
|
|
7
|
+
* normal entry) and returns the collection (chainable, spec 24.4.3.1).
|
|
8
|
+
*/
|
|
9
|
+
export declare function ensureWeakCollectionHelpers(ctx: CodegenContext): void;
|
|
10
|
+
/**
|
|
11
|
+
* (#2162) Intercept a `WeakMap.prototype.*` / `WeakSet.prototype.*` method call
|
|
12
|
+
* in standalone / `nativeStrings` mode and route it to the native Map/weak
|
|
13
|
+
* runtime. `className` selects the surface (WeakMap has get/set; WeakSet has
|
|
14
|
+
* add). Returns the result `InnerResult` when handled, else `undefined`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function tryCompileNativeWeakMethodCall(ctx: CodegenContext, fctx: FunctionContext, className: "WeakMap" | "WeakSet", propAccess: ts.PropertyAccessExpression, callExpr: ts.CallExpression): InnerResult | undefined;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { FieldDef, ValType } from '../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
4
|
+
/** A static (#1387 Tier-1) `with` scope entry. */
|
|
5
|
+
export type StaticWithScope = Extract<NonNullable<FunctionContext["withScopes"]>[number], {
|
|
6
|
+
kind: "static";
|
|
7
|
+
}>;
|
|
8
|
+
export interface WithBinding {
|
|
9
|
+
scope: StaticWithScope;
|
|
10
|
+
field: FieldDef;
|
|
11
|
+
fieldIdx: number;
|
|
12
|
+
}
|
|
13
|
+
/** A dynamic (#2663 Tier-2) `with` scope: arbitrary externref target resolved at
|
|
14
|
+
* runtime via HasBinding + Get. */
|
|
15
|
+
export type DynamicWithScope = Extract<NonNullable<FunctionContext["withScopes"]>[number], {
|
|
16
|
+
kind: "dynamic";
|
|
17
|
+
}>;
|
|
18
|
+
/** Result of resolving a bare identifier against the `with` scope stack. */
|
|
19
|
+
export type WithResolution = {
|
|
20
|
+
kind: "static";
|
|
21
|
+
binding: WithBinding;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "dynamic";
|
|
24
|
+
scope: DynamicWithScope;
|
|
25
|
+
} | null;
|
|
26
|
+
export declare function findWithBinding(fctx: FunctionContext, name: string): WithBinding | null;
|
|
27
|
+
/**
|
|
28
|
+
* (#2663 Slice 1) Resolve a bare identifier against the `with` scope stack,
|
|
29
|
+
* innermost-first, across a MIXED static/dynamic stack.
|
|
30
|
+
*
|
|
31
|
+
* - A `static` scope hit returns the proven struct field binding (Tier-1
|
|
32
|
+
* zero-overhead path) — short-circuits the walk.
|
|
33
|
+
* - A `dynamic` scope hit returns the scope for a runtime HasBinding-gated
|
|
34
|
+
* select (the absent case falls through to the next-outer scope / lexical at
|
|
35
|
+
* runtime, but statically we resolve to the innermost non-shadowing dynamic
|
|
36
|
+
* scope and let codegen emit the gate + fallback).
|
|
37
|
+
* - `blockedNames` (body-declared lexical/inner-function names) shadow a scope
|
|
38
|
+
* for that name — skip it.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveWithBinding(fctx: FunctionContext, name: string): WithResolution;
|
|
41
|
+
export declare function emitWithBindingGet(fctx: FunctionContext, binding: WithBinding): ValType;
|
|
42
|
+
export declare function compileWithBindingAssignment(ctx: CodegenContext, fctx: FunctionContext, binding: WithBinding, rhs: ts.Expression): ValType | null;
|
|
43
|
+
export declare function compileWithStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.WithStatement): void;
|
|
44
|
+
/**
|
|
45
|
+
* (#2663 Slice 1) Emit the HasBinding-gated READ select for a bare identifier
|
|
46
|
+
* that resolved to a dynamic `with` scope (§9.1.1.2.1 HasBinding +
|
|
47
|
+
* §9.1.1.2.5 GetBindingValue):
|
|
48
|
+
*
|
|
49
|
+
* if (HasBinding(recv, name)) result = Get(recv, name) else result = <outer>
|
|
50
|
+
*
|
|
51
|
+
* Both arms normalize to `externref` (the `Get` half yields externref; the outer
|
|
52
|
+
* fallback is coerced). `emitFallback` emits the name's normal (non-with)
|
|
53
|
+
* lowering into the current body and returns its ValType (or null on error).
|
|
54
|
+
*
|
|
55
|
+
* Slice 1 treats HasProperty as HasBinding (no `@@unscopables` — Slice 4). The
|
|
56
|
+
* gate uses the value-INDEPENDENT host `__extern_has` (NOT `__dyn_has`'s
|
|
57
|
+
* non-null proxy): a property present with value `undefined` MUST still shadow
|
|
58
|
+
* the outer binding (§7.3.12).
|
|
59
|
+
*/
|
|
60
|
+
export declare function emitDynamicWithGet(ctx: CodegenContext, fctx: FunctionContext, scope: DynamicWithScope, name: string, emitFallback: () => ValType | null): ValType;
|
|
61
|
+
/**
|
|
62
|
+
* (#2663 Slice 2) Emit the HasBinding-gated WRITE for `name = <value in
|
|
63
|
+
* rhsLocalIdx>` where `name` resolved to a dynamic `with` scope (§9.1.1.2.4
|
|
64
|
+
* SetMutableBinding), STATEMENT form (leaves nothing on the stack):
|
|
65
|
+
*
|
|
66
|
+
* if (HasBinding(recv, name)) __extern_set(recv, name, rhsVal) else <fallback>
|
|
67
|
+
*
|
|
68
|
+
* The RHS is pre-evaluated ONCE by the caller into the externref temp
|
|
69
|
+
* `rhsLocalIdx` (§13.15.2). `with` is sloppy-only, so the write uses
|
|
70
|
+
* `__extern_set` (silent-on-failure, not the strict variant).
|
|
71
|
+
* `emitFallbackWrite()` emits the next-outer write (another dynamic-with gate,
|
|
72
|
+
* or the lexical write) using the same temp; it must leave nothing on the stack.
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* (#2663 Slice 2 / #2061 fix) Emit `__extern_has(recv, name) -> i32` into a fresh
|
|
76
|
+
* i32 local, returning its index. §13.15.2: for a plain `=` assignment the LHS
|
|
77
|
+
* Reference is resolved (→ HasBinding) BEFORE the RHS is evaluated. So the caller
|
|
78
|
+
* captures each candidate dynamic-with scope's HasBinding with this helper BEFORE
|
|
79
|
+
* compiling the RHS; the gated write then branches on the captured i32.
|
|
80
|
+
*
|
|
81
|
+
* (Computing HasBinding AFTER the RHS — as the original Slice 2 did — let an RHS
|
|
82
|
+
* that adds the property to the with-object change the binding decision and
|
|
83
|
+
* mis-route the write: regressed test262 `S11.13.1_A6_T3` — "PutValue uses the
|
|
84
|
+
* initially-created Reference even if a more local binding is available".)
|
|
85
|
+
*/
|
|
86
|
+
export declare function emitCaptureWithHasBinding(ctx: CodegenContext, fctx: FunctionContext, scope: DynamicWithScope, name: string): number;
|
|
87
|
+
/**
|
|
88
|
+
* (#2663 Slice 2) Emit the WRITE for `name = <value in rhsLocalIdx>` gated on a
|
|
89
|
+
* PRE-CAPTURED HasBinding i32 (`hasLocalIdx`, from `emitCaptureWithHasBinding`,
|
|
90
|
+
* evaluated BEFORE the RHS per §13.15.2). Statement form (leaves nothing on the
|
|
91
|
+
* stack): `if (hasLocal) __extern_set(recv,name,rhs) else <fallback>`. `with` is
|
|
92
|
+
* sloppy-only ⇒ `__extern_set` (silent-on-failure).
|
|
93
|
+
*/
|
|
94
|
+
export declare function emitDynamicWithSet(ctx: CodegenContext, fctx: FunctionContext, scope: DynamicWithScope, name: string, rhsLocalIdx: number, hasLocalIdx: number, emitFallbackWrite: () => void): void;
|
|
95
|
+
/**
|
|
96
|
+
* (#2663 Slice 3) Emit `delete name` where `name` resolved to a dynamic `with`
|
|
97
|
+
* scope, leaving an i32 result on the stack (§13.5.1.2 / §8.5.2 DeleteBinding):
|
|
98
|
+
*
|
|
99
|
+
* if (HasBinding(recv, name)) result = __delete_property(recv, name)
|
|
100
|
+
* else result = <outer delete> // a bare variable is not deletable ⇒ 0,
|
|
101
|
+
* // unless an outer with also binds it (cascade)
|
|
102
|
+
*
|
|
103
|
+
* `emitOuterDelete()` emits the next-outer `delete name` result as i32 (another
|
|
104
|
+
* dynamic-with gate, or the plain "variables not deletable" `i32.const 0`).
|
|
105
|
+
*/
|
|
106
|
+
export declare function emitDynamicWithDelete(ctx: CodegenContext, fctx: FunctionContext, scope: DynamicWithScope, name: string, emitOuterDelete: () => void): ValType;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ValType, WasmModule } from '../ir/types.js';
|
|
2
|
+
/** Describes the TS-level semantic type of a parameter */
|
|
3
|
+
export type TsSemanticType = "number_i32" | "number_f64" | "boolean" | "string" | "array" | "object";
|
|
4
|
+
/** A parameter definition with TS semantic info */
|
|
5
|
+
export interface ParamDef {
|
|
6
|
+
name: string;
|
|
7
|
+
wasmType: ValType;
|
|
8
|
+
semantic: TsSemanticType;
|
|
9
|
+
}
|
|
10
|
+
/** A C ABI parameter (may be one of a pair for strings/arrays) */
|
|
11
|
+
export interface CabiParam {
|
|
12
|
+
name: string;
|
|
13
|
+
wasmType: ValType;
|
|
14
|
+
/** Which original param index this came from */
|
|
15
|
+
sourceParamIdx: number;
|
|
16
|
+
/** "ptr" | "len" for expanded params, "direct" for scalar */
|
|
17
|
+
role: "direct" | "ptr" | "len";
|
|
18
|
+
/**
|
|
19
|
+
* For expanded (ptr/len) params, the underlying aggregate kind so the
|
|
20
|
+
* wrapper can pick the right runtime constructor (`__str_from_data` for
|
|
21
|
+
* strings, `__arr_from_data` for arrays). Undefined for scalar/direct.
|
|
22
|
+
*/
|
|
23
|
+
aggregate?: "string" | "array";
|
|
24
|
+
}
|
|
25
|
+
/** C ABI return value descriptor */
|
|
26
|
+
export interface CabiResult {
|
|
27
|
+
wasmTypes: ValType[];
|
|
28
|
+
semantic: TsSemanticType | "void";
|
|
29
|
+
}
|
|
30
|
+
/** Information about an exported function for C header generation */
|
|
31
|
+
export interface CabiExportInfo {
|
|
32
|
+
/** Original TS function name */
|
|
33
|
+
tsName: string;
|
|
34
|
+
/** C ABI export name (e.g. MyClass_bar) */
|
|
35
|
+
cabiName: string;
|
|
36
|
+
/** C ABI parameter list */
|
|
37
|
+
params: CabiParam[];
|
|
38
|
+
/** C ABI return type */
|
|
39
|
+
result: CabiResult;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Expand TS parameter definitions into C ABI parameters.
|
|
43
|
+
* Strings and arrays become (ptr, len) pairs.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mapParamsToCabi(params: ParamDef[]): CabiParam[];
|
|
46
|
+
/**
|
|
47
|
+
* Map a TS return type to a C ABI return descriptor.
|
|
48
|
+
*/
|
|
49
|
+
export declare function mapResultToCabi(result: ValType | null, semantic: TsSemanticType | "void"): CabiResult;
|
|
50
|
+
/**
|
|
51
|
+
* Mangle a function name for C ABI export.
|
|
52
|
+
* Simple function names are unchanged; class methods use ClassName_method.
|
|
53
|
+
*/
|
|
54
|
+
export declare function mangleCabiName(name: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Emit C ABI wrapper functions for all exported functions in the module.
|
|
57
|
+
*
|
|
58
|
+
* For each exported function with string or array parameters, we generate
|
|
59
|
+
* a `__cabi_<name>` wrapper with C-compatible signatures. The wrapper
|
|
60
|
+
* marshals the (ptr, len) pairs by creating internal string/array
|
|
61
|
+
* representations, calls the original function, and returns the result
|
|
62
|
+
* in C ABI form.
|
|
63
|
+
*
|
|
64
|
+
* For functions that already have C-compatible signatures (all scalar
|
|
65
|
+
* params/returns), the original export is simply renamed — no wrapper
|
|
66
|
+
* is needed.
|
|
67
|
+
*
|
|
68
|
+
* Returns the list of CabiExportInfo describing the new C ABI exports.
|
|
69
|
+
*/
|
|
70
|
+
export declare function emitCabiWrappers(mod: WasmModule, exportInfos: CabiExportInfo[]): void;
|
|
71
|
+
/**
|
|
72
|
+
* Infer the TS semantic type from a ValType and TS type text.
|
|
73
|
+
*/
|
|
74
|
+
export declare function inferSemantic(wasmType: ValType, tsTypeText: string | undefined): TsSemanticType;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { Instr, LocalDef, ValType, WasmModule } from '../ir/types.js';
|
|
3
|
+
import { ClassLayout } from './layout.js';
|
|
4
|
+
/** Module-level context for linear-memory codegen */
|
|
5
|
+
export interface LinearContext {
|
|
6
|
+
mod: WasmModule;
|
|
7
|
+
checker: ts.TypeChecker;
|
|
8
|
+
/** Map from function name to its absolute index (imports + locals) */
|
|
9
|
+
funcMap: Map<string, number>;
|
|
10
|
+
/** Number of imported functions */
|
|
11
|
+
numImportFuncs: number;
|
|
12
|
+
/** Current function context (set during function compilation) */
|
|
13
|
+
currentFunc: LinearFuncContext | null;
|
|
14
|
+
/** Errors accumulated during codegen */
|
|
15
|
+
errors: {
|
|
16
|
+
message: string;
|
|
17
|
+
line: number;
|
|
18
|
+
column: number;
|
|
19
|
+
}[];
|
|
20
|
+
/** Class layouts for class declarations */
|
|
21
|
+
classLayouts: Map<string, ClassLayout>;
|
|
22
|
+
/** String literal data segment: string value → data segment offset */
|
|
23
|
+
stringLiterals: Map<string, number>;
|
|
24
|
+
/** Current data segment write offset */
|
|
25
|
+
dataSegmentOffset: number;
|
|
26
|
+
/** Counter for generating unique lambda function names */
|
|
27
|
+
lambdaCounter: number;
|
|
28
|
+
/** Function indices to populate in the funcref table */
|
|
29
|
+
tableEntries: number[];
|
|
30
|
+
/** Global index for __closure_env (env pointer for closures) */
|
|
31
|
+
closureEnvGlobalIdx: number;
|
|
32
|
+
/** Module-level variables → wasm global index */
|
|
33
|
+
moduleGlobals: Map<string, number>;
|
|
34
|
+
/** Module-level collection types (for Set, Map, Array globals) */
|
|
35
|
+
moduleCollectionTypes: Map<string, CollectionKind>;
|
|
36
|
+
}
|
|
37
|
+
/** Collection type tag for tracking variable types */
|
|
38
|
+
export type CollectionKind = "Array" | "Uint8Array" | "ArrayOrUint8Array" | "Map" | "Set";
|
|
39
|
+
/** (#2716) A `finally` block pending replay on early-exit paths out of its try. */
|
|
40
|
+
export interface FinallyEntry {
|
|
41
|
+
/** The `finally` block statements to replay. */
|
|
42
|
+
block: ts.Block;
|
|
43
|
+
/** `breakStack.length` at try-entry — used to decide if a `break` replays it. */
|
|
44
|
+
breakDepth: number;
|
|
45
|
+
/** `continueStack.length` at try-entry — used to decide if a `continue` replays it. */
|
|
46
|
+
continueDepth: number;
|
|
47
|
+
}
|
|
48
|
+
/** Per-function context for linear-memory codegen */
|
|
49
|
+
export interface LinearFuncContext {
|
|
50
|
+
/** Function name */
|
|
51
|
+
name: string;
|
|
52
|
+
/** Parameters (the first N locals) */
|
|
53
|
+
params: {
|
|
54
|
+
name: string;
|
|
55
|
+
type: ValType;
|
|
56
|
+
}[];
|
|
57
|
+
/** Additional locals declared in the body */
|
|
58
|
+
locals: LocalDef[];
|
|
59
|
+
/** All local names → index (params first, then locals) */
|
|
60
|
+
localMap: Map<string, number>;
|
|
61
|
+
/** Return type */
|
|
62
|
+
returnType: ValType | null;
|
|
63
|
+
/** Accumulated body instructions */
|
|
64
|
+
body: Instr[];
|
|
65
|
+
/** Block depth for br labels */
|
|
66
|
+
blockDepth: number;
|
|
67
|
+
/** Break label depth stack */
|
|
68
|
+
breakStack: number[];
|
|
69
|
+
/** Continue label depth stack */
|
|
70
|
+
continueStack: number[];
|
|
71
|
+
/**
|
|
72
|
+
* (#2716) Stack of enclosing `try { … } finally { … }` blocks whose `finally`
|
|
73
|
+
* must run on every completion path out of the try. Normal fall-through runs
|
|
74
|
+
* the finally inline; `return` / `break` / `continue` replay the applicable
|
|
75
|
+
* finally blocks before the jump. Each entry records the break/continue
|
|
76
|
+
* nesting at try-entry so a `break`/`continue` only replays the finallys that
|
|
77
|
+
* sit BETWEEN it and its target loop/switch.
|
|
78
|
+
*/
|
|
79
|
+
finallyStack: FinallyEntry[];
|
|
80
|
+
/** Track which locals are collection types (varName → kind) */
|
|
81
|
+
collectionTypes: Map<string, CollectionKind>;
|
|
82
|
+
/** Parameters that are callback/function-typed (param name → call_indirect type index) */
|
|
83
|
+
callbackParams: Map<string, number>;
|
|
84
|
+
}
|
|
85
|
+
/** Add a local variable to the current function context */
|
|
86
|
+
export declare function addLocal(fctx: LinearFuncContext, name: string, type: ValType): number;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { MultiTypedAST, TypedAST } from '../checker/index.js';
|
|
3
|
+
import { WasmModule } from '../ir/types.js';
|
|
4
|
+
import { LinearContext, LinearFuncContext } from './context.js';
|
|
5
|
+
/**
|
|
6
|
+
* Options for the linear-memory backend (#1856).
|
|
7
|
+
*/
|
|
8
|
+
export interface LinearOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Expose the explicit arena-management exports `__arena_reset` /
|
|
11
|
+
* `__arena_used` on the bump allocator. Useful for embedders that reuse a
|
|
12
|
+
* single instance across many short-lived tasks; off by default so the
|
|
13
|
+
* common "allocate-and-exit" program pays nothing for them.
|
|
14
|
+
* See {@link import("./runtime.js").ArenaOptions}.
|
|
15
|
+
*/
|
|
16
|
+
exposeArenaReset?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generate a WasmModule using the linear-memory backend.
|
|
20
|
+
* Compiles TS functions to standard Wasm with i32/f64 values.
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateLinearModule(ast: TypedAST, opts?: LinearOptions): WasmModule;
|
|
23
|
+
/**
|
|
24
|
+
* Generate a WasmModule from multiple TS source files using the linear-memory backend.
|
|
25
|
+
* Cross-file imports are resolved by the TypeScript checker; we iterate all source files.
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateLinearMultiModule(multiAst: MultiTypedAST, opts?: LinearOptions): WasmModule;
|
|
28
|
+
export declare function compileExpression(ctx: LinearContext, fctx: LinearFuncContext, expr: ts.Expression): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class layout computation for the linear-memory backend.
|
|
3
|
+
*
|
|
4
|
+
* Each class instance is stored on the heap with the following layout:
|
|
5
|
+
* [type_tag: u8 at +0][padding 3B][payload_size: u32 at +4][field0: 8B at +8][field1: 8B at +16]...
|
|
6
|
+
*
|
|
7
|
+
* The header is 8 bytes (tag + padding + payload_size).
|
|
8
|
+
* Each field occupies 8 bytes for uniform access (f64 for numbers, i32 stored in
|
|
9
|
+
* the low 4 bytes for object references).
|
|
10
|
+
*/
|
|
11
|
+
export interface ClassLayout {
|
|
12
|
+
name: string;
|
|
13
|
+
/** Total allocation size: header (8) + 8 bytes per field */
|
|
14
|
+
totalSize: number;
|
|
15
|
+
/** Map from field name to its memory offset and wasm type */
|
|
16
|
+
fields: Map<string, {
|
|
17
|
+
offset: number;
|
|
18
|
+
type: "i32" | "f64";
|
|
19
|
+
}>;
|
|
20
|
+
/** Map from field name to TS collection kind (for nested property access) */
|
|
21
|
+
fieldCollectionKinds: Map<string, "Array" | "Uint8Array" | "Map" | "Set">;
|
|
22
|
+
/** Map from method name to its wasm function name */
|
|
23
|
+
methods: Map<string, string>;
|
|
24
|
+
/** Map from getter property name to its wasm function name */
|
|
25
|
+
getters: Map<string, string>;
|
|
26
|
+
/** Wasm function name for the constructor */
|
|
27
|
+
ctorFuncName: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compute the memory layout for a class with the given fields.
|
|
31
|
+
*
|
|
32
|
+
* @param name - The class name
|
|
33
|
+
* @param fieldDefs - Array of { name, type } where type is "i32" or "f64"
|
|
34
|
+
* @returns The computed ClassLayout
|
|
35
|
+
*/
|
|
36
|
+
export declare function computeClassLayout(name: string, fieldDefs: {
|
|
37
|
+
name: string;
|
|
38
|
+
type: "i32" | "f64";
|
|
39
|
+
}[]): ClassLayout;
|