@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,78 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType, WasmFunction } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
export declare function compileNestedClassDeclaration(ctx: CodegenContext, fctx: FunctionContext, decl: ts.ClassDeclaration): void;
|
|
5
|
+
interface CompileNestedFunctionOptions {
|
|
6
|
+
reuseReservedEntry?: WasmFunction;
|
|
7
|
+
}
|
|
8
|
+
export declare function compileNestedFunctionDeclaration(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.FunctionDeclaration, opts?: CompileNestedFunctionOptions): void;
|
|
9
|
+
export declare function hoistFunctionDeclarations(ctx: CodegenContext, fctx: FunctionContext, stmts: ts.NodeArray<ts.Statement> | ts.Statement[], _eagerBoxFuncNames?: Set<string>): void;
|
|
10
|
+
/**
|
|
11
|
+
* Register (on first use) a module-level mutable global that carries
|
|
12
|
+
* "extra" runtime arguments from a call site to a callee whose body reads
|
|
13
|
+
* `arguments`. The global is consumed (read + reset to null) in the
|
|
14
|
+
* callee's prologue (#1053).
|
|
15
|
+
*
|
|
16
|
+
* Type: `(mut (ref null $vec_externref))` — a WasmGC vec of externref.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ensureExtrasArgvGlobal(ctx: CodegenContext): {
|
|
19
|
+
globalIdx: number;
|
|
20
|
+
vecTypeIdx: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Lazily register a `(mut i32)` module global `__argc` that callers set
|
|
24
|
+
* to the actual call-site argument count before invoking a function whose
|
|
25
|
+
* body reads `arguments`. The callee reads this to set `arguments.length`
|
|
26
|
+
* correctly (instead of using the formal parameter count).
|
|
27
|
+
*/
|
|
28
|
+
export declare function ensureArgcGlobal(ctx: CodegenContext): number;
|
|
29
|
+
/**
|
|
30
|
+
* Cache the call-site argument count once at function entry for parameter
|
|
31
|
+
* default checks. The raw -1 sentinel is preserved in the local; callers use
|
|
32
|
+
* that to mean "unknown host/module-init caller".
|
|
33
|
+
*/
|
|
34
|
+
export declare function cacheParamDefaultArgc(ctx: CodegenContext, fctx: FunctionContext): number;
|
|
35
|
+
export declare function paramDefaultNeedsArgc(type: ValType | undefined): boolean;
|
|
36
|
+
export declare function emitParamDefaultArgMissingCheck(fctx: FunctionContext, argcLocal: number, argIndex: number): void;
|
|
37
|
+
export declare function emitF64ParamSentinelCheck(fctx: FunctionContext, paramIdx: number): void;
|
|
38
|
+
export declare function maybeSetArgcForKnownCall(ctx: CodegenContext, fctx: FunctionContext, funcName: string, actualArgCount: number, paramCount: number): void;
|
|
39
|
+
/**
|
|
40
|
+
* (#1636-S1) Lazily register a `(mut externref)` module global
|
|
41
|
+
* `__current_this` used by `__call_fn_method_N` to thread a host-supplied
|
|
42
|
+
* `this`-value into a Wasm closure body. The dispatcher save+restores the
|
|
43
|
+
* previous value across the inner `call_ref`, and `ThisKeyword` resolution
|
|
44
|
+
* reads this global when no local `this` binding is in scope (free-closure
|
|
45
|
+
* fallback). Default value is `ref.null.extern` (= JS `null`), which is
|
|
46
|
+
* compatible with the prior "undefined fallback" behaviour for the vast
|
|
47
|
+
* majority of references that compare strictly against null/undefined.
|
|
48
|
+
*/
|
|
49
|
+
export declare function ensureCurrentThisGlobal(ctx: CodegenContext): number;
|
|
50
|
+
/**
|
|
51
|
+
* Emit code to build a vec struct from `args[startIdx..]` and
|
|
52
|
+
* store it in the `__extras_argv` module global. Used at call sites when
|
|
53
|
+
* the callee reads `arguments` and the caller passes more runtime args
|
|
54
|
+
* than the callee's formal param count (#1053).
|
|
55
|
+
*/
|
|
56
|
+
export declare function emitSetExtrasArgv(ctx: CodegenContext, fctx: FunctionContext, args: ts.Expression[], startIdx: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Shared arguments-vec construction: compiles formal params, concatenates
|
|
59
|
+
* extras from the `__extras_argv` global (#1053), and stores the final vec
|
|
60
|
+
* struct in `argsLocalIdx`. Used by both emitArgumentsObject and the
|
|
61
|
+
* function-body.ts inline path.
|
|
62
|
+
*/
|
|
63
|
+
export declare function emitArgumentsVecBody(ctx: CodegenContext, fctx: FunctionContext, paramTypes: ValType[], paramOffset: number, locals: {
|
|
64
|
+
vecTypeIdx: number;
|
|
65
|
+
arrTypeIdx: number;
|
|
66
|
+
argsLocalIdx: number;
|
|
67
|
+
arrTmpIdx: number;
|
|
68
|
+
}): void;
|
|
69
|
+
/**
|
|
70
|
+
* Emit code to create an `arguments` vec struct from function parameters.
|
|
71
|
+
* paramOffset is the number of leading params to skip (e.g. captures).
|
|
72
|
+
*
|
|
73
|
+
* Uses an externref-backed vec so that all parameter types (f64, i32,
|
|
74
|
+
* externref, ref) are preserved as externref values. This matches JS
|
|
75
|
+
* semantics where `arguments[n]` returns the original value.
|
|
76
|
+
*/
|
|
77
|
+
export declare function emitArgumentsObject(ctx: CodegenContext, fctx: FunctionContext, paramTypes: ValType[], paramOffset: number, unmapped?: boolean): void;
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { Instr } from '../../ir/types.js';
|
|
3
|
+
import { FunctionContext, NullGuardFact } from '../context/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Adjust the depth of all entries in the catchRethrowStack by `delta`.
|
|
6
|
+
* Called wherever breakStack entries are bulk-adjusted for block nesting changes.
|
|
7
|
+
*/
|
|
8
|
+
export declare function adjustRethrowDepth(fctx: FunctionContext, delta: number): void;
|
|
9
|
+
/**
|
|
10
|
+
* Collect instructions emitted by `emitFn` into a separate array without
|
|
11
|
+
* appending them to the current `fctx.body`. This replaces the pervasive
|
|
12
|
+
* "save body / swap / restore" pattern that was duplicated dozens of times.
|
|
13
|
+
*/
|
|
14
|
+
export declare function collectInstrs(fctx: FunctionContext, emitFn: () => void): Instr[];
|
|
15
|
+
/** Saved state for a block scope: localMap + optional TDZ/const flags */
|
|
16
|
+
export interface BlockScopeSave {
|
|
17
|
+
locals: Map<string, number> | null;
|
|
18
|
+
tdzFlags: Map<string, number> | null;
|
|
19
|
+
constBindings: Map<string, boolean> | null;
|
|
20
|
+
nullGuardAliases: Map<string, NullGuardFact | null> | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Collect the names of block-scoped (let/const) variable declarations that
|
|
24
|
+
* are direct children of a block (not nested blocks — those handle their own).
|
|
25
|
+
*/
|
|
26
|
+
export declare function collectBlockScopedNames(stmt: ts.Block): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Save localMap (and TDZ flag) entries for block-scoped names that shadow
|
|
29
|
+
* existing locals. Also removes the shadow entries from localMap (and
|
|
30
|
+
* tdzFlagLocals) so that compileVariableStatement will allocate fresh locals.
|
|
31
|
+
* Returns the saved state to restore after the block.
|
|
32
|
+
*/
|
|
33
|
+
export declare function saveBlockScopedShadows(fctx: FunctionContext, block: ts.Block): BlockScopeSave | null;
|
|
34
|
+
/**
|
|
35
|
+
* Restore localMap (and TDZ flag) entries that were saved before entering
|
|
36
|
+
* a block scope.
|
|
37
|
+
*/
|
|
38
|
+
export declare function restoreBlockScopedShadows(fctx: FunctionContext, saved: BlockScopeSave | null): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* #1452 — Walk a binding pattern (array / object / nested / rest) and yield
|
|
5
|
+
* every identifier name that the pattern binds. `{a: y}` introduces `y`,
|
|
6
|
+
* not `a`. `[...rest]` introduces `rest`. Used to drive the bulk TDZ-flip
|
|
7
|
+
* step that runs after a binding-pattern destructure completes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function collectPatternBindingNames(name: ts.BindingName): Iterable<string>;
|
|
10
|
+
/**
|
|
11
|
+
* #1452 — After a binding-pattern destructure completes, flip every
|
|
12
|
+
* declared identifier's TDZ flag to "initialized". The dedicated
|
|
13
|
+
* destructuring helpers already emit `emitLocalTdzInit` for the
|
|
14
|
+
* struct-path object form, but the externref array fallback, the
|
|
15
|
+
* vec/tuple-struct array forms, and the rest-element branches do not.
|
|
16
|
+
* Walking the pattern once here is safer than peppering every
|
|
17
|
+
* code path with individual calls.
|
|
18
|
+
*/
|
|
19
|
+
export declare function emitTdzInitForBindingPattern(fctx: FunctionContext, pattern: ts.BindingName): void;
|
|
20
|
+
/**
|
|
21
|
+
* Emit instructions to set a TDZ flag global to 1 (initialized) for a module-level
|
|
22
|
+
* let/const variable. No-op if the variable doesn't have a TDZ flag.
|
|
23
|
+
*/
|
|
24
|
+
export declare function emitTdzInit(ctx: CodegenContext, fctx: FunctionContext, name: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Emit instructions to set a local TDZ flag to 1 (initialized) for a function-level
|
|
27
|
+
* let/const variable. No-op if the variable doesn't have a local TDZ flag.
|
|
28
|
+
*
|
|
29
|
+
* Also calls `emitTdzInit` for the module-global case — this is needed when
|
|
30
|
+
* destructuring at the module level (walkStmtForLetConst pre-pass may register
|
|
31
|
+
* a TDZ flag in either tdzGlobals or tdzFlagLocals depending on scope).
|
|
32
|
+
*
|
|
33
|
+
* If the flag has been boxed in an i32 ref cell (because it was captured by
|
|
34
|
+
* a closure — see #1177), the set must go through `struct.set` so the
|
|
35
|
+
* mutation propagates to every closure that captured the same ref cell.
|
|
36
|
+
*/
|
|
37
|
+
export declare function emitLocalTdzInit(fctx: FunctionContext, name: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Emit a TDZ check for a module-level let/const variable read.
|
|
40
|
+
* If the TDZ flag is 0 (uninitialized), throw a ReferenceError.
|
|
41
|
+
* No-op if the variable doesn't have a TDZ flag.
|
|
42
|
+
*/
|
|
43
|
+
export declare function emitTdzCheck(ctx: CodegenContext, fctx: FunctionContext, name: string): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
3
|
+
export { compileExternrefArrayDestructuringDecl, compileExternrefObjectDestructuringDecl, emitDefaultValueCheck, emitExternrefDefaultCheck, emitNestedBindingDefault, ensureBindingLocals, } from './statements/destructuring.js';
|
|
4
|
+
export { bodyUsesArguments } from './helpers/body-uses-arguments.js';
|
|
5
|
+
export { emitArgumentsObject, hoistFunctionDeclarations } from './statements/nested-declarations.js';
|
|
6
|
+
export { collectInstrs } from './statements/shared.js';
|
|
7
|
+
export { emitTdzCheck } from './statements/tdz.js';
|
|
8
|
+
/** Compile a statement, appending instructions to the function body */
|
|
9
|
+
export declare function compileStatement(ctx: CodegenContext, fctx: FunctionContext, stmt: ts.Statement): void;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { ValType } from '../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* #1761 — presize info for a string-builder whose final length is provably a
|
|
6
|
+
* runtime-known linear function of a loop bound. When the build loop is a
|
|
7
|
+
* canonical `for (let i = 0; i < BOUND; i++)` (step +1) whose body appends a
|
|
8
|
+
* statically-fixed number of code units per iteration and never exits early,
|
|
9
|
+
* the final buffer length is exactly `BOUND * unitsPerIter`. Presizing the
|
|
10
|
+
* WasmGC i16 buffer to that length up front eliminates every doubling
|
|
11
|
+
* reallocation AND lets the per-append `len+1 > cap` cap-check be removed
|
|
12
|
+
* (the capacity is proven sufficient for all appends). See #1746 lever #3.
|
|
13
|
+
*/
|
|
14
|
+
export interface StringBuilderPresizeInfo {
|
|
15
|
+
/** Loop-invariant bound expression, evaluated once at buffer-init time. */
|
|
16
|
+
boundExpr: ts.Expression;
|
|
17
|
+
/** Constant code-unit count appended per loop iteration (the exact total
|
|
18
|
+
* is `boundExpr * unitsPerIter`). */
|
|
19
|
+
unitsPerIter: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Scan a function body for `let s = ""; for (...) s += <expr>` patterns and
|
|
23
|
+
* return the set of qualifying VariableDeclaration nodes. Caller stores this
|
|
24
|
+
* as `fctx.pendingStringBuilders` so `compileVariableStatement` can detect
|
|
25
|
+
* the rewrite when it reaches the matching declarator.
|
|
26
|
+
*
|
|
27
|
+
* When `presizeOut` is provided, any builder whose final length is provably a
|
|
28
|
+
* runtime-known linear function of a loop bound (#1761) is additionally
|
|
29
|
+
* recorded there keyed by its declaration, so the init site can presize the
|
|
30
|
+
* buffer and the append sites can drop the cap-check.
|
|
31
|
+
*
|
|
32
|
+
* Only scans `nativeStrings` mode — caller should gate on `ctx.nativeStrings`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function detectStringBuilders(ctx: CodegenContext, fnBody: ts.Block | ts.SourceFile | undefined, presizeOut?: Map<ts.VariableDeclaration, StringBuilderPresizeInfo>): Set<ts.VariableDeclaration>;
|
|
35
|
+
/**
|
|
36
|
+
* Emit the buffer-init sequence for a string-builder binding. Allocates
|
|
37
|
+
* `${name}$buf`, `${name}$len`, `${name}$cap`, `${name}$mat` locals,
|
|
38
|
+
* registers them in `fctx.stringBuilders`, and emits initialization that
|
|
39
|
+
* sets `buf := array.new_default 16`, `len := 0`, `cap := 16`, `mat := null`.
|
|
40
|
+
*
|
|
41
|
+
* #1761: when `presize` is supplied, the buffer is allocated once at the
|
|
42
|
+
* provably-final length `bound * unitsPerIter` instead of the doubling
|
|
43
|
+
* initial 16, the recorded capacity matches, and `sb.presized` is set so the
|
|
44
|
+
* append sites drop the per-append `len+1 > cap` cap-check (the capacity is
|
|
45
|
+
* proven sufficient for every append). `bound` is evaluated once here, before
|
|
46
|
+
* the loop runs — sound because the analysis proved it loop-invariant. A
|
|
47
|
+
* non-positive bound yields a 0-length buffer; the loop then runs 0 times and
|
|
48
|
+
* appends nothing, so the empty buffer is correct (any later read of the
|
|
49
|
+
* never-grown builder materialises a 0-length string).
|
|
50
|
+
*
|
|
51
|
+
* Caller is responsible for calling this from the variable-statement
|
|
52
|
+
* dispatcher when it sees a decl present in `fctx.pendingStringBuilders`,
|
|
53
|
+
* and for ensuring native string helpers have been emitted (so
|
|
54
|
+
* `__str_buf_next_cap` is available when a later append needs it).
|
|
55
|
+
*/
|
|
56
|
+
export declare function compileStringBuilderInit(ctx: CodegenContext, fctx: FunctionContext, name: string, presize?: StringBuilderPresizeInfo): void;
|
|
57
|
+
/**
|
|
58
|
+
* Append a string-typed expression to a string-builder binding. The RHS
|
|
59
|
+
* value is left-on-stack as `ref $AnyString` by the caller via
|
|
60
|
+
* `coerceRhsToAnyStringRef`; this helper consumes it and emits:
|
|
61
|
+
*
|
|
62
|
+
* 1. Flatten the RHS so we have access to `data`/`off`/`len`.
|
|
63
|
+
* 2. needed = sb.len + rhs.len
|
|
64
|
+
* 3. If needed > sb.cap, grow `sb.buf` to a doubled capacity and copy
|
|
65
|
+
* the existing prefix in.
|
|
66
|
+
* 4. array.copy(sb.buf, sb.len, rhs.data, rhs.off, rhs.len)
|
|
67
|
+
* 5. sb.len = needed
|
|
68
|
+
* 6. Invalidate sb.mat (set to null) so the next read re-materializes.
|
|
69
|
+
*
|
|
70
|
+
* The result is `ref_null $AnyString` (always pushes ref.null) — for the
|
|
71
|
+
* common statement-level `s += "x";` the caller drops it. If used as an
|
|
72
|
+
* expression value, this is a behavioural change vs. the legacy concat
|
|
73
|
+
* path (which returned the new string ref). The detector only matches
|
|
74
|
+
* `s += <expr>` as a side-effecting statement — uses where the expression
|
|
75
|
+
* value is consumed are conservative and rare; they will materialize via
|
|
76
|
+
* the next identifier read.
|
|
77
|
+
*/
|
|
78
|
+
export interface StringBuilderInfo {
|
|
79
|
+
bufLocalIdx: number;
|
|
80
|
+
lenLocalIdx: number;
|
|
81
|
+
capLocalIdx: number;
|
|
82
|
+
materializedLocalIdx: number;
|
|
83
|
+
/**
|
|
84
|
+
* #1761: when true, the buffer was presized to the provably-final length, so
|
|
85
|
+
* every append's `len+N > cap` cap-check / grow branch is statically known
|
|
86
|
+
* to be unreachable and is omitted. When false (or absent), appends keep the
|
|
87
|
+
* doubling grow path.
|
|
88
|
+
*/
|
|
89
|
+
presized?: boolean;
|
|
90
|
+
}
|
|
91
|
+
export declare function compileStringBuilderAppend(ctx: CodegenContext, fctx: FunctionContext, rhsAnyStrType: ValType, sb: StringBuilderInfo): void;
|
|
92
|
+
/**
|
|
93
|
+
* #1744 — single-code-unit append fast path.
|
|
94
|
+
*
|
|
95
|
+
* Appends ONE i16 code unit to the string-builder buffer without allocating
|
|
96
|
+
* an intermediate `$NativeString`. The caller has already pushed the code
|
|
97
|
+
* unit (an `i32` in 0..0xFFFF) onto the stack; this consumes it and emits:
|
|
98
|
+
*
|
|
99
|
+
* 1. cu = <stack top> ; stash the code unit
|
|
100
|
+
* 2. if (sb.len + 1 > sb.cap) grow buffer ; same doubling policy as append
|
|
101
|
+
* 3. sb.buf[sb.len] = cu
|
|
102
|
+
* 4. sb.len = sb.len + 1
|
|
103
|
+
* 5. sb.mat = null ; invalidate the cache
|
|
104
|
+
*
|
|
105
|
+
* This is the hot path for `buf += X.charAt(i)` / `buf += "<1 char>"`: the
|
|
106
|
+
* generic `compileStringBuilderAppend` would otherwise materialise a 1-char
|
|
107
|
+
* `$NativeString` (`array.new_fixed` + `struct.new`) per iteration just to
|
|
108
|
+
* copy a single character out of it (~40k throwaway allocations on the
|
|
109
|
+
* string-hash benchmark). Reading the code unit directly and `array.set`ing
|
|
110
|
+
* it removes both the allocation and the per-iteration `__str_flatten` on the
|
|
111
|
+
* result.
|
|
112
|
+
*
|
|
113
|
+
* Correctness: this is a verbatim code-unit copy. `charAt` is itself
|
|
114
|
+
* code-unit-indexed (it returns the WTF-16 unit at the index, splitting
|
|
115
|
+
* surrogate pairs), so copying the raw unit into the i16 buffer is exactly
|
|
116
|
+
* what the string-roundtrip path does — no surrogate handling differs.
|
|
117
|
+
*/
|
|
118
|
+
export declare function emitStringBuilderAppendCodeUnit(ctx: CodegenContext, fctx: FunctionContext, sb: StringBuilderInfo): void;
|
|
119
|
+
/**
|
|
120
|
+
* Materialize the current contents of a string builder into a `ref $NativeString`
|
|
121
|
+
* (compatible with `ref $AnyString`). Pushes the materialized ref onto the
|
|
122
|
+
* stack. Caches the result in `sb.mat` so repeated reads (e.g.
|
|
123
|
+
* `s.length` then `s.charCodeAt(...)` in the same expression) reuse one
|
|
124
|
+
* struct allocation. The cache is invalidated by `compileStringBuilderAppend`.
|
|
125
|
+
*
|
|
126
|
+
* Returns the value type of the pushed ref so the caller can stitch it into
|
|
127
|
+
* the surrounding expression.
|
|
128
|
+
*/
|
|
129
|
+
export declare function emitStringBuilderRead(ctx: CodegenContext, fctx: FunctionContext, sb: StringBuilderInfo): ValType;
|
|
130
|
+
/** Helper to look up an active builder by binding name. */
|
|
131
|
+
export declare function getBuilderInfo(fctx: FunctionContext, name: string): StringBuilderInfo | undefined;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ValType } from '../ir/types.js';
|
|
2
|
+
import { ts } from '../ts-api.js';
|
|
3
|
+
import { CodegenContext, FunctionContext, HoistedCharRead } from './context/types.js';
|
|
4
|
+
export declare function compileStringLiteral(ctx: CodegenContext, fctx: FunctionContext, value: string, node?: ts.Node): ValType | null;
|
|
5
|
+
/**
|
|
6
|
+
* Materialize a string literal as a NativeString GC struct in fast mode.
|
|
7
|
+
* Emits array.new_fixed with the WTF-16 code units, then struct.new.
|
|
8
|
+
*/
|
|
9
|
+
export declare function compileNativeStringLiteral(ctx: CodegenContext, fctx: FunctionContext, value: string): ValType;
|
|
10
|
+
export declare function compileTemplateExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.TemplateExpression): ValType | null;
|
|
11
|
+
/**
|
|
12
|
+
* Compile a template expression in fast mode, using native string concat.
|
|
13
|
+
* Number substitutions are converted via number_toString (returns externref)
|
|
14
|
+
* then marshaled to native string.
|
|
15
|
+
*/
|
|
16
|
+
export declare function compileNativeTemplateExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.TemplateExpression): ValType | null;
|
|
17
|
+
/**
|
|
18
|
+
* Compile a tagged template expression: tag`hello ${x} world`
|
|
19
|
+
* Desugars to: tag(["hello ", " world"], x)
|
|
20
|
+
*
|
|
21
|
+
* Implementation: build a WasmGC externref array (vec struct) of string parts,
|
|
22
|
+
* then call the tag function with the array as first arg and substitutions
|
|
23
|
+
* as remaining args. NO host imports needed.
|
|
24
|
+
*/
|
|
25
|
+
export declare function compileTaggedTemplateExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.TaggedTemplateExpression): ValType | null;
|
|
26
|
+
/**
|
|
27
|
+
* Emit wasm code to convert a boolean (i32) on the stack to a string.
|
|
28
|
+
* Produces "true" or "false" string constant (externref) via if/else.
|
|
29
|
+
*/
|
|
30
|
+
export declare function emitBoolToString(ctx: CodegenContext, fctx: FunctionContext): ValType;
|
|
31
|
+
export declare function compileStringBinaryOp(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression, op: ts.SyntaxKind): ValType | null;
|
|
32
|
+
/**
|
|
33
|
+
* #2682: if `expr` is `recv.charCodeAt(i)` where `recv` is the loop-invariant
|
|
34
|
+
* receiver and `i` the in-bounds-proven induction variable of an active
|
|
35
|
+
* canonical string-read loop, return that loop's hoisted-descriptor proof.
|
|
36
|
+
* Otherwise return null. Both the i32-pure-leaf path (binary-ops.ts) and the
|
|
37
|
+
* f64 charCodeAt lowering below consult this. The match is deliberately exact —
|
|
38
|
+
* the argument must be the SAME induction identifier (not `i+1`, not a literal)
|
|
39
|
+
* so the dropped OOB branch stays sound.
|
|
40
|
+
*/
|
|
41
|
+
export declare function matchHoistedCharRead(fctx: FunctionContext, expr: ts.Expression): HoistedCharRead | null;
|
|
42
|
+
/**
|
|
43
|
+
* #2682: emit the hoisted-descriptor charCodeAt read, leaving an i32 char code
|
|
44
|
+
* on the stack. The receiver was flattened once before the loop and `i` is
|
|
45
|
+
* proven `0 <= i < len`, so this is a bare `array.get_u(dataLocal, offLocal + i)`
|
|
46
|
+
* — no `__str_flatten`, no `.data`/`.off` struct.get reload, no OOB/NaN branch.
|
|
47
|
+
* Caller must have matched via {@link matchHoistedCharRead}.
|
|
48
|
+
*/
|
|
49
|
+
export declare function emitHoistedCharCodeAtRead(ctx: CodegenContext, fctx: FunctionContext, entry: HoistedCharRead, idxArg: ts.Expression): void;
|
|
50
|
+
/**
|
|
51
|
+
* Compile a method call on a native string in fast mode.
|
|
52
|
+
* Handles: charCodeAt (inline), charAt, substring, slice (native helpers),
|
|
53
|
+
* and delegates other methods to host via marshal.
|
|
54
|
+
*/
|
|
55
|
+
export declare function compileNativeStringMethodCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression, method: string,
|
|
56
|
+
/**
|
|
57
|
+
* (#2576, extends #2187) Optional receiver emitter. When provided, the method
|
|
58
|
+
* arms push the receiver via this callback instead of re-compiling
|
|
59
|
+
* `propAccess.expression`. Used by {@link compileGuardedNativeStringMethodCall}
|
|
60
|
+
* to feed a pre-evaluated, guard-cast `$AnyString` receiver (so an `any`-typed
|
|
61
|
+
* receiver is evaluated exactly once and only after a runtime `ref.test
|
|
62
|
+
* $AnyString` succeeds). The callback must push one value (a native-string ref
|
|
63
|
+
* / `$AnyString`) and return its ValType, mirroring `compileExpression`.
|
|
64
|
+
*/
|
|
65
|
+
receiverOverride?: () => ValType | null): ValType | null;
|
|
66
|
+
/**
|
|
67
|
+
* (#2576, extends #2187) Runtime-guarded native string method dispatch for an
|
|
68
|
+
* `any`/unknown receiver whose value MAY be a native `$AnyString` at runtime
|
|
69
|
+
* (object property values, generator yield reads, catch bindings, indexed
|
|
70
|
+
* element reads — see `receiverMayBeNativeStringAtRuntime`). The static
|
|
71
|
+
* `isStringType` / `receiverIsNativeStringValType` gates miss these (the value
|
|
72
|
+
* is an opaque externref), so without this the call fell to the host/dynamic
|
|
73
|
+
* path (null/0 standalone).
|
|
74
|
+
*
|
|
75
|
+
* Evaluates the receiver EXACTLY ONCE into an externref temp (preserving side
|
|
76
|
+
* effects and ordering), then `ref.test $AnyString`:
|
|
77
|
+
* - hit → cast the saved externref to `$AnyString` and run the normal native
|
|
78
|
+
* method lowering against it (via `compileNativeStringMethodCall`'s
|
|
79
|
+
* receiver override — the receiver is NOT re-compiled),
|
|
80
|
+
* - miss → the method's spec default for its result type (so a non-string
|
|
81
|
+
* `any` — array, number, null — does not trap and yields a benign
|
|
82
|
+
* default rather than a wrong value).
|
|
83
|
+
*
|
|
84
|
+
* Standalone/WASI native-string mode only; the caller gates on
|
|
85
|
+
* `ctx.nativeStrings && ctx.anyStrTypeIdx >= 0`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function compileGuardedNativeStringMethodCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression, method: string): ValType | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* (#1888 S5c) Master gate — keep the struct-accessor closure rework DARK until
|
|
5
|
+
* C1-C5 are wired + validated. Flip to `true` in the C5 PR once the S5c RED
|
|
6
|
+
* tests pass and S5b/GC regression guards hold.
|
|
7
|
+
*/
|
|
8
|
+
export declare const S5C_STRUCT_ACCESSOR_CLOSURE = true;
|
|
9
|
+
/** Module-global name for a struct accessor's getter closure slot. */
|
|
10
|
+
export declare function structAccessorGetGlobalName(structName: string, propName: string): string;
|
|
11
|
+
/** Module-global name for a struct accessor's setter closure slot. */
|
|
12
|
+
export declare function structAccessorSetGlobalName(structName: string, propName: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Compile a struct accessor getter/setter as a host-free CLOSURE and leave its
|
|
15
|
+
* externref (capture-bearing `$Closure`, ready to box into a per-(struct,prop)
|
|
16
|
+
* global) on the stack. Returns `false` when the lift could not be performed
|
|
17
|
+
* (caller falls back). Mirrors the standalone branch of object-ops.ts
|
|
18
|
+
* `emitAccessorFn` so the open-`$Object` S5b arm and the struct arm share one
|
|
19
|
+
* lift; only the storage target differs (S5b → `__defineProperty_accessor`
|
|
20
|
+
* arg; S5c struct → `global.set $__acc_get/set_…`).
|
|
21
|
+
*
|
|
22
|
+
* The closure's body captures outer-scope reads into its `$self` struct
|
|
23
|
+
* (compileArrowAsClosure) and observes `this` via `__current_this` at invoke
|
|
24
|
+
* time (#1636-S1) — so the dispatched value carries the env the bare-fn lacked.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildAccessorClosure(ctx: CodegenContext, fctx: FunctionContext, fn: ts.FunctionExpression | ts.ArrowFunction): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Reserve (idempotently) the per-(struct,prop) nullable `(mut externref)` module
|
|
29
|
+
* global holding a struct accessor's getter or setter closure, and record it in
|
|
30
|
+
* `ctx.structAccessorClosure[key]`. Returns the global index. Initialised to
|
|
31
|
+
* `ref.null.extern`; the C2 define-site `global.set`s the lifted closure.
|
|
32
|
+
*
|
|
33
|
+
* `kind` selects the get vs set slot. Reusing an already-reserved slot (e.g. a
|
|
34
|
+
* redefine of the same accessor) returns the existing index.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ensureStructAccessorGlobal(ctx: CodegenContext, structName: string, propName: string, kind: "get" | "set"): number;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Ensure the symbol description table's array type and lazy global exist.
|
|
4
|
+
* Idempotent. Sets `ctx.symbolDescArrTypeIdx` and `ctx.symbolDescGlobalIdx`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function ensureSymbolDescTable(ctx: CodegenContext): void;
|
|
7
|
+
/**
|
|
8
|
+
* Emit code that stores a description for a symbol id into the native table.
|
|
9
|
+
*
|
|
10
|
+
* Stack in: `[i32 id, ref_null $AnyString desc]` (desc on top)
|
|
11
|
+
* Stack out: `[]`
|
|
12
|
+
*
|
|
13
|
+
* Allocates the table on first use and grows it (×2 until it fits, copying the
|
|
14
|
+
* existing slots) when `id >= table.len`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function emitSymbolDescStore(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
17
|
+
/**
|
|
18
|
+
* Emit code that loads the description for a symbol id from the native table.
|
|
19
|
+
*
|
|
20
|
+
* Stack in: `[i32 id]`
|
|
21
|
+
* Stack out: `[ref_null $AnyString]` (null when the table is unallocated, the
|
|
22
|
+
* id is out of range, or the slot was never set — all of which the
|
|
23
|
+
* `.description` accessor treats as `undefined`).
|
|
24
|
+
*/
|
|
25
|
+
export declare function emitSymbolDescLoad(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
26
|
+
/**
|
|
27
|
+
* (#2163) Ensure the native `Symbol.for` / `Symbol.keyFor` registry exists:
|
|
28
|
+
* two parallel growable arrays (slot→key `$AnyString`, slot→symbol id i32) plus
|
|
29
|
+
* a count global, and the two runtime helper functions `__symbol_for_native`
|
|
30
|
+
* and `__symbol_keyfor_native`. Idempotent.
|
|
31
|
+
*
|
|
32
|
+
* The registry reuses the description-table key types and the native
|
|
33
|
+
* `__str_equals` (content equality, flattens cons-strings) for the key lookup.
|
|
34
|
+
* A registered symbol's description is its key (§20.4.2.2 step 4b), so
|
|
35
|
+
* `__symbol_for_native` also stores the key in the description table.
|
|
36
|
+
*/
|
|
37
|
+
export declare function ensureSymbolRegistry(ctx: CodegenContext): {
|
|
38
|
+
forIdx: number;
|
|
39
|
+
keyForIdx: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* (#2163) Emit `Symbol.prototype.toString` (§20.4.3.3 → SymbolDescriptiveString,
|
|
43
|
+
* §20.4.3.3.1) in `noJsHost` mode, producing the native string
|
|
44
|
+
* `"Symbol(" + (desc ?? "") + ")"`.
|
|
45
|
+
*
|
|
46
|
+
* Stack in: `[i32 id]` (the symbol's i32 counter id)
|
|
47
|
+
* Stack out: `[ref $AnyString]` (the descriptive string)
|
|
48
|
+
*
|
|
49
|
+
* `desc` is read from the native description side table (`emitSymbolDescLoad`);
|
|
50
|
+
* a missing description (`undefined`) contributes the empty string, matching
|
|
51
|
+
* `Symbol().toString() === "Symbol()"`. Zero host imports — the prefix/suffix
|
|
52
|
+
* are inline native-string literals concatenated via the native `__str_concat`
|
|
53
|
+
* helper (same lowering template literals use).
|
|
54
|
+
*/
|
|
55
|
+
export declare function emitSymbolToString(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
export declare function compileTemporalNewExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.NewExpression): ValType | null | undefined;
|
|
6
|
+
export declare function tryCompileTemporalPropertyAccess(ctx: CodegenContext, fctx: FunctionContext, expr: ts.PropertyAccessExpression): ValType | undefined;
|
|
7
|
+
export declare function tryCompileTemporalStaticCall(ctx: CodegenContext, fctx: FunctionContext, propAccess: ts.PropertyAccessExpression, callExpr: ts.CallExpression): InnerResult | undefined;
|
|
8
|
+
export declare function tryCompileTemporalMethodCall(ctx: CodegenContext, fctx: FunctionContext, propAccess: ts.PropertyAccessExpression, callExpr: ts.CallExpression): InnerResult | undefined;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Instr, ValType } from '../ir/types.js';
|
|
2
|
+
import { CodegenContext, FunctionContext, OptionalParamInfo } from './context/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Emit a guarded ref.cast: use ref.test to check if the cast will succeed.
|
|
5
|
+
* If it fails, push ref.null instead of trapping with "illegal cast".
|
|
6
|
+
* The value on the stack should be an anyref (from any.convert_extern).
|
|
7
|
+
* The result is always ref_null $typeIdx (nullable) to accommodate the null fallback.
|
|
8
|
+
*
|
|
9
|
+
* Usage: push externref, call any.convert_extern, then call this function.
|
|
10
|
+
*/
|
|
11
|
+
export declare function emitGuardedRefCast(fctx: FunctionContext, typeIdx: number): void;
|
|
12
|
+
/**
|
|
13
|
+
* Emit a guarded funcref cast: use ref.test to check if the cast will succeed.
|
|
14
|
+
* If it fails, push ref.null instead of trapping with "illegal cast".
|
|
15
|
+
* The value on the stack should be a funcref (from struct.get of a closure field).
|
|
16
|
+
* The result is always ref_null $funcTypeIdx (nullable).
|
|
17
|
+
*
|
|
18
|
+
* Unlike emitGuardedRefCast, this uses funcref locals (not anyref) since
|
|
19
|
+
* funcref is NOT a subtype of anyref in the WasmGC type hierarchy.
|
|
20
|
+
*/
|
|
21
|
+
export declare function emitGuardedFuncRefCast(fctx: FunctionContext, funcTypeIdx: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Callback type for compiling a string literal onto the Wasm stack.
|
|
24
|
+
* Used by coerceType when it needs to push a @@toPrimitive hint string.
|
|
25
|
+
* The caller (expressions.ts) passes its local compileStringLiteral function.
|
|
26
|
+
* @deprecated No longer needed — coerceType now emits hint strings directly via global.get.
|
|
27
|
+
*/
|
|
28
|
+
export type CompileStringLiteralFn = (ctx: CodegenContext, fctx: FunctionContext, value: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a type index corresponds to a vec struct (__vec_*) and return its
|
|
31
|
+
* array type index and element type if so.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getVecInfo(ctx: CodegenContext, typeIdx: number): {
|
|
34
|
+
arrTypeIdx: number;
|
|
35
|
+
elemType: ValType;
|
|
36
|
+
} | null;
|
|
37
|
+
/**
|
|
38
|
+
* Build instructions to construct a vec struct from a JS array (externref).
|
|
39
|
+
* Uses __extern_length + __extern_get to read elements and build the WasmGC array.
|
|
40
|
+
* Returns instruction array producing ref_null $vecType on the stack. (#792)
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildVecFromExternref(ctx: CodegenContext, fctx: FunctionContext, externLocal: number, vecTypeIdx: number, vecInfo: {
|
|
43
|
+
arrTypeIdx: number;
|
|
44
|
+
elemType: ValType;
|
|
45
|
+
}): Instr[];
|
|
46
|
+
/**
|
|
47
|
+
* Coerce a Wasm value on the stack from one type to another.
|
|
48
|
+
*
|
|
49
|
+
* @param toPrimitiveHint Optional ToPrimitive hint ("number", "string", or "default").
|
|
50
|
+
* When converting ref → f64 or ref → externref, the hint determines which string
|
|
51
|
+
* is passed to [Symbol.toPrimitive]. If not specified, defaults to "number" for
|
|
52
|
+
* f64 targets and "string" for externref targets.
|
|
53
|
+
* @param compileStringLiteralFn Deprecated — no longer used, kept for API compat.
|
|
54
|
+
*/
|
|
55
|
+
export declare function coerceType(ctx: CodegenContext, fctx: FunctionContext, from: ValType, to: ValType, toPrimitiveHint?: "number" | "string" | "default", compileStringLiteralFn?: CompileStringLiteralFn): void;
|
|
56
|
+
/**
|
|
57
|
+
* #1806 Phase 1 (string-hint slice) — OrdinaryToPrimitive over a compile-time
|
|
58
|
+
* resolvable object struct in the **string** direction, for `--target standalone`
|
|
59
|
+
* / WASI (native-strings) mode where there is no JS host `__to_primitive`.
|
|
60
|
+
*
|
|
61
|
+
* Mirrors the closure/method dispatch of {@link tryToStringFallback} (the
|
|
62
|
+
* numeric-hint walker) but produces a string instead of an f64, so that
|
|
63
|
+
* `obj + "s"`, `` `${obj}` `` and `String(obj)` invoke the object's own
|
|
64
|
+
* `@@toPrimitive("string")` / `toString` instead of falling through to the
|
|
65
|
+
* `$__any_to_string` helper, which can only emit `"[object Object]"` for a
|
|
66
|
+
* struct it cannot introspect.
|
|
67
|
+
*
|
|
68
|
+
* Per ECMA-262 §7.1.1.1 OrdinaryToPrimitive with hint "string": try `toString`
|
|
69
|
+
* first, then `valueOf`. We dispatch (in precedence order):
|
|
70
|
+
* 1. the `toString` closure field (object-literal method) via call_ref
|
|
71
|
+
* 2. a named `${name}_toString` method in funcMap
|
|
72
|
+
* Each result is normalised to a `ref $AnyString` (the native string the concat
|
|
73
|
+
* / template path expects). On success the struct ref on top of the stack is
|
|
74
|
+
* consumed and a `ref $AnyString` is left; returns true. When neither form is
|
|
75
|
+
* statically resolvable, the struct ref is left untouched and the function
|
|
76
|
+
* returns false so the caller can fall back to `$__any_to_string`.
|
|
77
|
+
*
|
|
78
|
+
* NOTE: a user `[Symbol.toPrimitive]` ("string"-hint precedence over toString)
|
|
79
|
+
* is intentionally NOT handled here yet — its hint argument must be marshalled
|
|
80
|
+
* as a native string in standalone/native-strings mode, which the existing
|
|
81
|
+
* `pushStringHint` (externref-global) path does not satisfy. Left to a follow-up
|
|
82
|
+
* so this slice stays regression-free; objects with only `toString`/`valueOf`
|
|
83
|
+
* (the dominant cluster) are covered.
|
|
84
|
+
*
|
|
85
|
+
* Expects the struct ref on top of the Wasm stack; consumes it only on success.
|
|
86
|
+
*/
|
|
87
|
+
export declare function tryStructToString(ctx: CodegenContext, fctx: FunctionContext, from: ValType): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Emit a safe externref-to-f64 conversion that handles GC struct references.
|
|
90
|
+
*
|
|
91
|
+
* When an externref might hold a WasmGC struct (e.g., from `extern.convert_any`
|
|
92
|
+
* on an object literal), calling the JS host `Number(v)` throws
|
|
93
|
+
* "Cannot convert object to primitive value". This function emits inline Wasm
|
|
94
|
+
* that uses `__typeof_number` to check if the externref is a JS number before
|
|
95
|
+
* calling `__unbox_number`. For non-number externrefs (including GC structs),
|
|
96
|
+
* it returns NaN per JS ToNumber semantics for objects without valueOf.
|
|
97
|
+
*
|
|
98
|
+
* Expects one externref on the stack; leaves one f64.
|
|
99
|
+
*/
|
|
100
|
+
export declare function emitSafeExternrefToF64(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
101
|
+
export declare function pushDefaultValue(fctx: FunctionContext, type: ValType, ctx?: CodegenContext): void;
|
|
102
|
+
/**
|
|
103
|
+
* Push the caller-side default for a missing optional parameter (#869).
|
|
104
|
+
*
|
|
105
|
+
* For constant defaults (number literal, boolean, null, undefined):
|
|
106
|
+
* Emit the constant value directly — no sentinel needed, callee never checks.
|
|
107
|
+
*
|
|
108
|
+
* For expression defaults (non-constant initializer):
|
|
109
|
+
* Fall back to the sNaN sentinel (0x7FF00000DEADC0DE) for f64 params.
|
|
110
|
+
* The callee detects this via i64.reinterpret_f64 + i64.eq and evaluates the expression.
|
|
111
|
+
*
|
|
112
|
+
* For params without initializers (just `?`):
|
|
113
|
+
* Emit the type's zero value (0, ref.null, etc.).
|
|
114
|
+
*/
|
|
115
|
+
export declare function pushParamSentinel(fctx: FunctionContext, type: ValType, ctx?: CodegenContext, optInfo?: OptionalParamInfo): void;
|
|
116
|
+
export declare function defaultValueInstrs(vt: ValType): Instr[];
|
|
117
|
+
/**
|
|
118
|
+
* Generate Instr[] to coerce a value from one Wasm type to another.
|
|
119
|
+
* Used in pre-built instruction arrays (e.g. array method callback loops)
|
|
120
|
+
* where we can't call coerceType() which pushes to fctx.body.
|
|
121
|
+
* Returns an empty array if no coercion is needed.
|
|
122
|
+
*/
|
|
123
|
+
export declare function coercionInstrs(ctx: CodegenContext, from: ValType, to: ValType, fctx?: FunctionContext): Instr[];
|