@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,349 @@
|
|
|
1
|
+
import { Instr } from '../ir/types.js';
|
|
2
|
+
import { ClosureInfo, CodegenContext, FunctionContext } from './context/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* #1326 — Sentinel state values for `$Promise.state`. Match the JS spec
|
|
5
|
+
* tri-state: pending → fulfilled (final), or pending → rejected (final).
|
|
6
|
+
* State transitions other than from pending are illegal per spec and
|
|
7
|
+
* silently ignored by Phase 1B's resolve/reject emit code.
|
|
8
|
+
*/
|
|
9
|
+
export declare const PROMISE_STATE_PENDING = 0;
|
|
10
|
+
export declare const PROMISE_STATE_FULFILLED = 1;
|
|
11
|
+
export declare const PROMISE_STATE_REJECTED = 2;
|
|
12
|
+
/**
|
|
13
|
+
* #1326 — Default microtask queue capacity. The Phase 1C-A queue is a pair
|
|
14
|
+
* of WasmGC arrays (one funcref, one externref) sized at allocation time
|
|
15
|
+
* and grown via `__microtask_grow` on overflow. 8,192 slots covers typical
|
|
16
|
+
* async kernels (most chains are <100 entries deep) without forcing a grow
|
|
17
|
+
* on first use.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MICROTASK_QUEUE_INITIAL_SLOTS = 8192;
|
|
20
|
+
/**
|
|
21
|
+
* #1326 — Shared per-context state for the async scheduler. Cached on
|
|
22
|
+
* `ctx.asyncScheduler` (created lazily on first access) so 1B/1C
|
|
23
|
+
* emitters share registered indices without re-registering.
|
|
24
|
+
*
|
|
25
|
+
* Phase 1C-A populates the queue infrastructure fields lazily on the first
|
|
26
|
+
* `ensureMicrotaskQueue` call. Phase 1C-B will add wrapper-cache fields.
|
|
27
|
+
*/
|
|
28
|
+
export interface AsyncSchedulerState {
|
|
29
|
+
/** $Promise WasmGC struct typeIdx, or -1 until registered (Phase 1A). */
|
|
30
|
+
promiseTypeIdx: number;
|
|
31
|
+
/** $__arr_externref typeIdx (queue captures + args buffer, Phase 1A). */
|
|
32
|
+
microtaskArgsArrTypeIdx: number;
|
|
33
|
+
/** $__arr_mt_func typeIdx — funcref array for queued callbacks. -1 until queue is registered. */
|
|
34
|
+
microtaskFuncArrTypeIdx: number;
|
|
35
|
+
/** $__mt_func_type typeIdx — `(externref, externref) → externref`, the uniform wrapper signature. -1 until queue is registered. */
|
|
36
|
+
microtaskFuncTypeIdx: number;
|
|
37
|
+
/** Wasm global index for the queue head pointer (next entry to drain). -1 until registered. */
|
|
38
|
+
microtaskHeadGlobalIdx: number;
|
|
39
|
+
/** Wasm global index for the queue tail pointer (next free slot). -1 until registered. */
|
|
40
|
+
microtaskTailGlobalIdx: number;
|
|
41
|
+
/** Wasm global index for the queue's current capacity. -1 until registered. */
|
|
42
|
+
microtaskCapGlobalIdx: number;
|
|
43
|
+
/** Wasm global index for the funcref array (or ref.null until allocated). -1 until registered. */
|
|
44
|
+
microtaskFuncsGlobalIdx: number;
|
|
45
|
+
/** Wasm global index for the captures array. -1 until registered. */
|
|
46
|
+
microtaskCapsGlobalIdx: number;
|
|
47
|
+
/** Wasm global index for the args array. -1 until registered. */
|
|
48
|
+
microtaskArgsGlobalIdx: number;
|
|
49
|
+
/** Function index of `__microtask_enqueue(funcref, externref, externref)`. -1 until registered. */
|
|
50
|
+
enqueueFuncIdx: number;
|
|
51
|
+
/** Function index of `__drain_microtasks()`. -1 until registered. */
|
|
52
|
+
drainFuncIdx: number;
|
|
53
|
+
/** Function index of `__microtask_grow(i32)`. -1 until registered. */
|
|
54
|
+
growFuncIdx: number;
|
|
55
|
+
/** `$PromiseCallback` pending-callback linked-list node type. -1 until registered. */
|
|
56
|
+
promiseCallbackTypeIdx: number;
|
|
57
|
+
/** `$__then_caps` task-captures type (`callback`, `chained`). -1 until registered. */
|
|
58
|
+
thenCapsTypeIdx: number;
|
|
59
|
+
/** Function index of `__promise_fulfill((ref $Promise), externref) -> externref`. */
|
|
60
|
+
promiseFulfillFuncIdx: number;
|
|
61
|
+
/** Function index of `__promise_reject((ref $Promise), externref) -> externref`. */
|
|
62
|
+
promiseRejectFuncIdx: number;
|
|
63
|
+
/** Function index of the identity fulfillment task wrapper. */
|
|
64
|
+
identityFulfillWrapperFuncIdx: number;
|
|
65
|
+
/** Function index of the identity rejection task wrapper. */
|
|
66
|
+
identityRejectWrapperFuncIdx: number;
|
|
67
|
+
/** Counter for generated `__then_fulfill_N` / `__then_reject_N` wrappers. */
|
|
68
|
+
thenWrapperCounter: number;
|
|
69
|
+
/** Whether `__drain_microtasks` has been added to the module's exports. */
|
|
70
|
+
drainExported: boolean;
|
|
71
|
+
/** `$__arr_timer_func` funcref-array typeIdx (timer callback storage). -1 until registered. */
|
|
72
|
+
timerFuncArrTypeIdx: number;
|
|
73
|
+
/** `$__arr_i64` i64-array typeIdx (timer deadlines + interval periods). -1 until registered. */
|
|
74
|
+
timerI64ArrTypeIdx: number;
|
|
75
|
+
/** `$__arr_i32` i32-array typeIdx (timer cancelled flags). -1 until registered. */
|
|
76
|
+
timerI32ArrTypeIdx: number;
|
|
77
|
+
/** Wasm global: count of live timer slots (high-water; cancelled lazily). -1 until registered. */
|
|
78
|
+
timerCountGlobalIdx: number;
|
|
79
|
+
/** Wasm global: current capacity of the timer arrays. -1 until registered. */
|
|
80
|
+
timerCapGlobalIdx: number;
|
|
81
|
+
/** Wasm global: deadlines i64 array (ref.null until first add). -1 until registered. */
|
|
82
|
+
timerDeadlinesGlobalIdx: number;
|
|
83
|
+
/** Wasm global: callbacks funcref array. -1 until registered. */
|
|
84
|
+
timerCallbacksGlobalIdx: number;
|
|
85
|
+
/** Wasm global: captures externref array. -1 until registered. */
|
|
86
|
+
timerCapturesGlobalIdx: number;
|
|
87
|
+
/** Wasm global: interval periods i64 array (0 = one-shot). -1 until registered. */
|
|
88
|
+
timerIntervalsGlobalIdx: number;
|
|
89
|
+
/** Wasm global: cancelled i32 flags array. -1 until registered. */
|
|
90
|
+
timerCancelledGlobalIdx: number;
|
|
91
|
+
/** Func idx of `__timer_add(deadlineNs i64, cb funcref, cap externref, intervalNs i64) -> i32`. -1 until registered. */
|
|
92
|
+
timerAddFuncIdx: number;
|
|
93
|
+
/** Func idx of `__timer_cancel(id i32)`. -1 until registered. */
|
|
94
|
+
timerCancelFuncIdx: number;
|
|
95
|
+
/** Func idx of `__timer_peek_deadline() -> i64` (i64 max when none pending). -1 until registered. */
|
|
96
|
+
timerPeekDeadlineFuncIdx: number;
|
|
97
|
+
/** Func idx of `__timer_fire_due(nowNs i64)` — fires all due timers, re-arms intervals. -1 until registered. */
|
|
98
|
+
timerFireDueFuncIdx: number;
|
|
99
|
+
/** Func idx of `__run_event_loop()` — the reactor driver. -1 until registered. */
|
|
100
|
+
runLoopFuncIdx: number;
|
|
101
|
+
/** Func idx of the monotonic-now reader `__rl_now_ns() -> i64` (CLOCK_MONOTONIC). -1 until registered. */
|
|
102
|
+
runLoopNowFuncIdx: number;
|
|
103
|
+
/** Whether the timer heap was ever registered (drives run-loop emission + _start wiring). */
|
|
104
|
+
timerHeapRegistered: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the run loop should wait on fd0-readable OR the nearest timer
|
|
107
|
+
* (multi-subscription `poll_oneoff`) instead of the Phase-1 single-clock
|
|
108
|
+
* sleep, and drain fd0 into an internal stdin buffer each tick. Set BEFORE
|
|
109
|
+
* `ensureTimerHeap` runs so the run-loop body is built in the fd-reactor
|
|
110
|
+
* shape. When false, the run loop is byte-identical to Phase 1.
|
|
111
|
+
*/
|
|
112
|
+
stdinReactor: boolean;
|
|
113
|
+
/** Wasm global: 1 once fd0's non-blocking flag has been set (set-once guard). -1 until registered. */
|
|
114
|
+
stdinNonblockSetGlobalIdx: number;
|
|
115
|
+
/** Wasm global: 1 while fd0 is still subscribed (not at EOF); 0 after EOF. -1 until registered. */
|
|
116
|
+
stdinFdActiveGlobalIdx: number;
|
|
117
|
+
/** Wasm global: byte count currently buffered in the internal stdin region (write cursor). -1 until registered. */
|
|
118
|
+
stdinBufLenGlobalIdx: number;
|
|
119
|
+
/** Wasm global: read cursor into the internal stdin region (Phase-3 consumer advances it). -1 until registered. */
|
|
120
|
+
stdinBufPosGlobalIdx: number;
|
|
121
|
+
/** Func idx of `__rl_stdin_drain() -> i32` — fd_read available bytes into the internal buffer; returns bytes read (0 = EOF). -1 until registered. */
|
|
122
|
+
stdinDrainFuncIdx: number;
|
|
123
|
+
/** Func idx of `__rl_poll_fd0_or_clock(deadlineNs i64, nowNs i64) -> i32` — 1 if fd0 readable, 0 if timeout/no-fd. -1 until registered. */
|
|
124
|
+
pollFd0OrClockFuncIdx: number;
|
|
125
|
+
/**
|
|
126
|
+
* Wasm global (nullable funcref, `$__mt_func_type` signature): the
|
|
127
|
+
* `process.stdin` Readable's "pump" callback. The run loop calls it once per
|
|
128
|
+
* tick AFTER `__rl_stdin_drain` fills the internal buffer (so the pump runs as
|
|
129
|
+
* loop work, not synchronously inside `poll_oneoff`). Null until the library
|
|
130
|
+
* registers a reader via `__wasiStdinSetReader(cb)`. -1 until registered.
|
|
131
|
+
*/
|
|
132
|
+
stdinReaderHookGlobalIdx: number;
|
|
133
|
+
/**
|
|
134
|
+
* Wasm global (externref): the closure-captures struct for the reader hook
|
|
135
|
+
* (the bound Readable instance). The run loop passes it as the hook's first
|
|
136
|
+
* arg so the pump can reach its `this`. -1 until registered.
|
|
137
|
+
*/
|
|
138
|
+
stdinReaderCapGlobalIdx: number;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* #1326 — Get or register the `$Promise` WasmGC struct type. The struct
|
|
142
|
+
* has three fields:
|
|
143
|
+
* - state: i32 (0=pending, 1=fulfilled, 2=rejected)
|
|
144
|
+
* - value: externref (fulfilled value or rejection reason)
|
|
145
|
+
* - callbacks: externref (nullable `$PromiseCallback` linked list for
|
|
146
|
+
* pending `.then` continuations)
|
|
147
|
+
*
|
|
148
|
+
* Returns the registered struct's typeIdx, cached for re-use.
|
|
149
|
+
*/
|
|
150
|
+
export declare function getOrRegisterPromiseType(ctx: CodegenContext): number;
|
|
151
|
+
/**
|
|
152
|
+
* #1326 — Get or register the microtask-queue arg-vec type. Phase 1A
|
|
153
|
+
* registered the WasmGC array type; Phase 1C-A re-uses it for both the
|
|
154
|
+
* captures buffer and the args buffer (both are externref arrays).
|
|
155
|
+
*/
|
|
156
|
+
export declare function getOrRegisterMicrotaskQueueType(ctx: CodegenContext): number;
|
|
157
|
+
/**
|
|
158
|
+
* #1326 Phase 1C-A — Idempotently register the microtask queue (types,
|
|
159
|
+
* globals, helper functions). Safe to call from anywhere in the codegen
|
|
160
|
+
* pipeline, but callers must keep in mind that the new function indices
|
|
161
|
+
* land at the END of the current `ctx.mod.functions` array — registering
|
|
162
|
+
* mid-function-body emit shifts subsequent funcIdx values, so callers in
|
|
163
|
+
* Phase 1C-B should invoke this BEFORE any function bodies that reference
|
|
164
|
+
* the registered indices.
|
|
165
|
+
*/
|
|
166
|
+
export declare function ensureMicrotaskQueue(ctx: CodegenContext): void;
|
|
167
|
+
/**
|
|
168
|
+
* #1326 Phase 1C-A — Compile a call to `__microtask_enqueue(fn, caps, arg)`
|
|
169
|
+
* into the caller's body. Caller-supplied `funcRefInstrs` push a funcref;
|
|
170
|
+
* `capsInstrs` push an externref carrying any closure-state captures the
|
|
171
|
+
* drain-time callback will need; `argInstrs` push the externref value to
|
|
172
|
+
* pass to the callback.
|
|
173
|
+
*
|
|
174
|
+
* Used by the standalone `.then` integration to schedule drain-time
|
|
175
|
+
* continuations.
|
|
176
|
+
*/
|
|
177
|
+
export declare function emitMicrotaskEnqueue(ctx: CodegenContext, fctx: FunctionContext, funcRefInstrs: Instr[], capsInstrs: Instr[], argInstrs: Instr[]): void;
|
|
178
|
+
/**
|
|
179
|
+
* #1326 Phase 1C-A — Compile a call to `__drain_microtasks()` into the
|
|
180
|
+
* caller's body. Drains until the queue is empty. Safe to call when the
|
|
181
|
+
* queue was never initialised — the body short-circuits on a null funcs
|
|
182
|
+
* global.
|
|
183
|
+
*/
|
|
184
|
+
export declare function emitDrainMicrotasks(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
185
|
+
/**
|
|
186
|
+
* #1326 Phase 1C-A — If the microtask queue was registered for this
|
|
187
|
+
* compilation unit, export `__drain_microtasks` so standalone callers can
|
|
188
|
+
* invoke it after their top-level entrypoint. Idempotent.
|
|
189
|
+
*/
|
|
190
|
+
export declare function exportDrainMicrotasksIfRegistered(ctx: CodegenContext): void;
|
|
191
|
+
/**
|
|
192
|
+
* #1326 Phase 1C-A — Auto-drain hook for WASI `_start`. Returns the funcIdx
|
|
193
|
+
* of `__drain_microtasks` when the queue is registered, or `null` when not
|
|
194
|
+
* (queue was never used by this module; no drain call needed). Callers
|
|
195
|
+
* append `{ op: "call", funcIdx: <returned> }` to the `_start` body right
|
|
196
|
+
* after the main/`__module_init` call.
|
|
197
|
+
*/
|
|
198
|
+
export declare function getDrainFuncIdxForWasiStart(ctx: CodegenContext): number | null;
|
|
199
|
+
/**
|
|
200
|
+
* #2632 — Idempotently register the timer table (types, globals, helpers) and
|
|
201
|
+
* the run-loop driver. MUST be called in the deferred-helper phase (after
|
|
202
|
+
* `__wasi_sleep_ms` + `clock_time_get` are registered, before user bodies
|
|
203
|
+
* compile) so the `__timer_add` / `__timer_cancel` func indices referenced at
|
|
204
|
+
* timer call sites are final. Depends on `ensureMicrotaskQueue` (the loop
|
|
205
|
+
* drains microtasks each tick).
|
|
206
|
+
*/
|
|
207
|
+
export declare function ensureTimerHeap(ctx: CodegenContext): void;
|
|
208
|
+
/**
|
|
209
|
+
* #2632 Phase 2 — emit a `__wasiStdinReadByte()` lowering at a call site.
|
|
210
|
+
* Pushes an i32 onto the caller stack: the next buffered stdin byte (0..255),
|
|
211
|
+
* or -1 when the internal buffer is empty. The reactor (running in `_start`)
|
|
212
|
+
* drains fd0 into the buffer; a timer/microtask callback reads it one byte at a
|
|
213
|
+
* time via this primitive. This is the internal-buffer access path Phase 3's
|
|
214
|
+
* `process.stdin` Readable will build `.read()` on top of.
|
|
215
|
+
*/
|
|
216
|
+
export declare function emitStdinReadByte(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
217
|
+
/**
|
|
218
|
+
* #2632 Phase 3 — emit `__wasiStdinAvailable()` at a call site. Pushes an i32:
|
|
219
|
+
* the number of bytes currently buffered and unread (`len - pos`). The library
|
|
220
|
+
* `Readable` uses this to decide whether `.read(size)` can satisfy the request.
|
|
221
|
+
*/
|
|
222
|
+
export declare function emitStdinAvailable(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
223
|
+
/**
|
|
224
|
+
* #2632 Phase 3 — emit `__wasiStdinEof()` at a call site. Pushes an i32: 1 when
|
|
225
|
+
* fd0's readable side has hit EOF (the reactor dropped the subscription:
|
|
226
|
+
* `__stdin_fd_active == 0`) AND every buffered byte has been consumed
|
|
227
|
+
* (`pos >= len`); else 0. The library `Readable` uses this to emit `'end'` and
|
|
228
|
+
* to make `.read()` return all-remaining at EOF rather than null-on-short.
|
|
229
|
+
*/
|
|
230
|
+
export declare function emitStdinEof(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
231
|
+
/**
|
|
232
|
+
* #2735 — emit `__wasiStdinStop()` at a call site: a NON-EOF reactor exit
|
|
233
|
+
* trigger. Drops the fd0 subscription by clearing `__stdin_fd_active` (mirrors
|
|
234
|
+
* the EOF clear in `buildStdinDrainBody`), so the run loop's next `pending`
|
|
235
|
+
* test — `(next != I64_MAX) | fd0_active` — falls through and `_start` returns
|
|
236
|
+
* cleanly EVEN THOUGH stdin never reached EOF. Without this the fd-readiness
|
|
237
|
+
* reactor's ONLY termination path is stdin EOF, which hangs the real
|
|
238
|
+
* Native-Messaging case (the peer keeps the pipe open and signals shutdown
|
|
239
|
+
* in-band). Backs `process.stdin.destroy()` and the `process.exit()` pre-exit
|
|
240
|
+
* drop. Stack-neutral; a no-op (and safe to call unconditionally) when the
|
|
241
|
+
* reactor isn't active for this module (the global was never registered).
|
|
242
|
+
*/
|
|
243
|
+
export declare function emitStdinStop(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
244
|
+
/**
|
|
245
|
+
* #2735 — true when the fd0 stdin reactor is active for this module (the
|
|
246
|
+
* Phase-2 globals were registered). Lets the WASI `process.exit` lowering
|
|
247
|
+
* decide whether to drop the fd0 subscription before `proc_exit` WITHOUT
|
|
248
|
+
* forcing the reactor onto a program that only calls `process.exit` and never
|
|
249
|
+
* touches stdin.
|
|
250
|
+
*/
|
|
251
|
+
export declare function isStdinReactorActive(ctx: CodegenContext): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* #2632 Phase 3 — emit `__wasiStdinSetReader(cb)` at a call site. Stores the
|
|
254
|
+
* pump funcref + its closure captures into the reactor-tick-hook globals, so the
|
|
255
|
+
* run loop invokes `cb(captures, null)` each tick after draining fd0. The
|
|
256
|
+
* caller pushes the wrapped `$__mt_func_type` funcref (`cbFuncRefInstrs`) and
|
|
257
|
+
* the closure-captures externref (`capInstrs`). Returns nothing.
|
|
258
|
+
*/
|
|
259
|
+
export declare function emitStdinSetReader(ctx: CodegenContext, fctx: FunctionContext, cbFuncRefInstrs: Instr[], capInstrs: Instr[]): void;
|
|
260
|
+
/**
|
|
261
|
+
* #2632 Phase 2 — mark the stdin reactor active for this module. MUST be called
|
|
262
|
+
* BEFORE `ensureTimerHeap` so the run-loop body is built in the fd-reactor
|
|
263
|
+
* shape and the Phase-2 globals/helpers register. Idempotent.
|
|
264
|
+
*/
|
|
265
|
+
export declare function enableStdinReactor(ctx: CodegenContext): void;
|
|
266
|
+
/**
|
|
267
|
+
* #2632 — Emit a `setTimeout`/`setInterval` registration at a call site.
|
|
268
|
+
* Pushes the timer id (i32) onto the caller stack. `cbFuncRefInstrs` push the
|
|
269
|
+
* uniform `$__mt_func_type` funcref; `capInstrs` push the closure-captures
|
|
270
|
+
* externref; `deadlineInstrs` push the absolute deadline (i64 ns);
|
|
271
|
+
* `intervalInstrs` push the re-arm period (i64 ns, 0 = one-shot).
|
|
272
|
+
*/
|
|
273
|
+
export declare function emitTimerAdd(ctx: CodegenContext, fctx: FunctionContext, deadlineInstrs: Instr[], cbFuncRefInstrs: Instr[], capInstrs: Instr[], intervalInstrs: Instr[]): void;
|
|
274
|
+
/** #2632 — Emit a `clearTimeout`/`clearInterval` at a call site. Consumes the
|
|
275
|
+
* id already pushed by `idInstrs`. */
|
|
276
|
+
export declare function emitTimerCancel(ctx: CodegenContext, fctx: FunctionContext, idInstrs: Instr[]): void;
|
|
277
|
+
/** #2632 — The monotonic-now reader func idx (`__rl_now_ns() -> i64`), or -1.
|
|
278
|
+
* Timer call sites read it to compute `deadlineNs = now + ms*1e6`. */
|
|
279
|
+
export declare function getRunLoopNowFuncIdx(ctx: CodegenContext): number;
|
|
280
|
+
/**
|
|
281
|
+
* #2632 — Synthesise a uniform `$__mt_func_type` timer-callback wrapper for a
|
|
282
|
+
* user closure. The timer table stores the closure struct itself as the
|
|
283
|
+
* `captures` externref; this wrapper (param 0 = caps externref = the closure
|
|
284
|
+
* struct, param 1 = value externref = unused/null) decodes the struct and
|
|
285
|
+
* invokes the closure via `call_ref` with default args for every parameter
|
|
286
|
+
* (a timer callback receives no arguments in Node — extra `setTimeout` args
|
|
287
|
+
* are out of Phase-1 scope). Returns the wrapper func idx.
|
|
288
|
+
*
|
|
289
|
+
* Mirrors the `.then` wrapper shape (closure call_ref = `[self, ...args,
|
|
290
|
+
* typed_funcref]`) but without promise settlement.
|
|
291
|
+
*/
|
|
292
|
+
export declare function emitTimerCallbackWrapper(ctx: CodegenContext, info: ClosureInfo): number;
|
|
293
|
+
/**
|
|
294
|
+
* #2632 — Run-loop hook for WASI `_start`. Returns the funcIdx of
|
|
295
|
+
* `__run_event_loop` when the timer heap was registered (the loop supersedes
|
|
296
|
+
* the one-shot drain — it drains microtasks itself), else `null` so the caller
|
|
297
|
+
* falls back to the bare drain.
|
|
298
|
+
*/
|
|
299
|
+
export declare function getRunLoopFuncIdxForWasiStart(ctx: CodegenContext): number | null;
|
|
300
|
+
/**
|
|
301
|
+
* #1326 Phase 1B — emit standalone-mode `Promise.resolve(value)` as a
|
|
302
|
+
* Wasm-native `$Promise` GC struct construction. The caller has
|
|
303
|
+
* already pushed `value` (as externref) onto the Wasm stack via
|
|
304
|
+
* `valueInstrs`; this helper appends:
|
|
305
|
+
* - i32.const 1 (state = FULFILLED)
|
|
306
|
+
* - <valueInstrs> (value = caller's pushed externref)
|
|
307
|
+
* - ref.null extern (callbacks placeholder — Phase 1C-B
|
|
308
|
+
* will upgrade to a typed pending list)
|
|
309
|
+
* - struct.new $Promise (consumes 3 stack values)
|
|
310
|
+
* - extern.convert_any (lift (ref $Promise) → externref so
|
|
311
|
+
* downstream consumers keep working)
|
|
312
|
+
*
|
|
313
|
+
* The return is on the Wasm stack as `externref`. Internal helpers
|
|
314
|
+
* (`Promise.then`, `Promise.all`, etc.) `ref.cast` it back to
|
|
315
|
+
* `(ref $Promise)` to read the state/value/callbacks fields.
|
|
316
|
+
*/
|
|
317
|
+
export declare function emitStandalonePromiseResolve(ctx: CodegenContext, fctx: FunctionContext, valueInstrs: Instr[]): void;
|
|
318
|
+
/**
|
|
319
|
+
* #1326 Phase 1B — emit standalone-mode `Promise.reject(reason)` as a
|
|
320
|
+
* Wasm-native `$Promise` GC struct construction. Symmetric to
|
|
321
|
+
* `emitStandalonePromiseResolve` but with `state = REJECTED`.
|
|
322
|
+
*/
|
|
323
|
+
export declare function emitStandalonePromiseReject(ctx: CodegenContext, fctx: FunctionContext, reasonInstrs: Instr[]): void;
|
|
324
|
+
export interface StandalonePromiseThenCallback {
|
|
325
|
+
instrs: Instr[];
|
|
326
|
+
closureInfo: ClosureInfo;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* #1326 Phase 1C-B — emit standalone-mode `promise.then(onFulfilled,
|
|
330
|
+
* onRejected?)`.
|
|
331
|
+
*
|
|
332
|
+
* The emitted code constructs a new pending chained `$Promise`, captures the
|
|
333
|
+
* user closure (if callable) plus that chained promise in `$__then_caps`, then:
|
|
334
|
+
* - already-fulfilled receiver: enqueue fulfillment wrapper immediately
|
|
335
|
+
* - already-rejected receiver: enqueue rejection wrapper immediately
|
|
336
|
+
* - pending receiver: prepend a `$PromiseCallback` node to receiver.callbacks
|
|
337
|
+
*
|
|
338
|
+
* Drain-time wrappers invoke the closure through WasmGC `call_ref`, settle the
|
|
339
|
+
* chained promise, and enqueue any callbacks that were attached to the chained
|
|
340
|
+
* promise while it was pending. Missing/non-callable handlers use identity
|
|
341
|
+
* fulfill / pass-through reject wrappers.
|
|
342
|
+
*/
|
|
343
|
+
export declare function emitStandalonePromiseThen(ctx: CodegenContext, fctx: FunctionContext, promiseInstrs: Instr[], onFulfilled: StandalonePromiseThenCallback | null, onRejected?: StandalonePromiseThenCallback | null): void;
|
|
344
|
+
/**
|
|
345
|
+
* #1326 — Check whether standalone-mode Promise codegen is active.
|
|
346
|
+
* Auto-enables in WASI target mode (the JS host imports for Promise are
|
|
347
|
+
* unavailable); opt-in elsewhere via a flag.
|
|
348
|
+
*/
|
|
349
|
+
export declare function isStandalonePromiseActive(ctx: CodegenContext): boolean;
|
|
@@ -0,0 +1,78 @@
|
|
|
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 compileBinaryExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): InnerResult;
|
|
6
|
+
/**
|
|
7
|
+
* (#2058) Emit `+` for two operands where at least one is a dynamic externref
|
|
8
|
+
* (an `any`/`unknown`/boxed value). The operands are already on the Wasm stack
|
|
9
|
+
* (left below right). Per §13.15.3 ApplyStringOrNumericBinaryOperator a runtime
|
|
10
|
+
* string on either side must CONCATENATE, not coerce to f64 — so we cannot take
|
|
11
|
+
* the externref-numeric f64 fast path.
|
|
12
|
+
*
|
|
13
|
+
* JS-host mode delegates to `__host_add` (JS `+`), which gives ToPrimitive, the
|
|
14
|
+
* string-if-either-is-string rule, and object valueOf/toString ordering for
|
|
15
|
+
* free. Standalone/WASI has no JS host, so we build the operation in-module from
|
|
16
|
+
* the union-native typeof/unbox probes + native string concat. If neither host
|
|
17
|
+
* nor native-string support is available we fall back to the legacy f64 add
|
|
18
|
+
* (status quo — no regression).
|
|
19
|
+
*
|
|
20
|
+
* Returns the value type left on the stack (`externref` for the host/native
|
|
21
|
+
* paths — a boxed number-or-string the caller stores into the `any` slot — or
|
|
22
|
+
* `f64` for the legacy numeric fallback).
|
|
23
|
+
*/
|
|
24
|
+
export declare function emitAnyAdd(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): ValType;
|
|
25
|
+
/**
|
|
26
|
+
* (#2059) Emit a relational (`<`,`<=`,`>`,`>=`) for two operands where at least
|
|
27
|
+
* one is a dynamic externref (an `any`/`unknown` value). Operands are compiled
|
|
28
|
+
* here (not yet on the stack). Per §7.2.13 IsLessThan two string operands compare
|
|
29
|
+
* lexicographically and a string-vs-number compares numerically — the f64 paths
|
|
30
|
+
* would ToNumber both sides (`Number("a")` → NaN) and yield `false`.
|
|
31
|
+
*
|
|
32
|
+
* JS-host delegates to `__host_compare` (JS `<`/`>`), which returns a 4-way
|
|
33
|
+
* result -1/0/1/2 (2 = NaN/undefined-incomparable). Standalone builds §7.2.13 in
|
|
34
|
+
* module: both-string → native `__str_compare`, else ToNumber + f64. Returns i32
|
|
35
|
+
* (the boolean relational result).
|
|
36
|
+
*/
|
|
37
|
+
export declare function emitAnyRelational(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression, op: ts.SyntaxKind): ValType;
|
|
38
|
+
export declare function compileNumericBinaryOp(ctx: CodegenContext, fctx: FunctionContext, op: ts.SyntaxKind, expr: ts.BinaryExpression): ValType;
|
|
39
|
+
/**
|
|
40
|
+
* Emit JS ToInt32: reduce f64 modulo 2^32 then truncate to i32.
|
|
41
|
+
* Handles NaN→0, Infinity→0, and large values that wrap.
|
|
42
|
+
* Stack: [f64] → [i32]
|
|
43
|
+
*/
|
|
44
|
+
export declare function emitToInt32(fctx: FunctionContext): void;
|
|
45
|
+
/**
|
|
46
|
+
* (#2593) ToUint8Clamp (§7.1.x, the `Uint8ClampedArray` element conversion). Input
|
|
47
|
+
* f64 on the stack → clamped i32 in [0, 255]. NOT modulo: NaN→0, ≤0→0, ≥255→255,
|
|
48
|
+
* else round-HALF-TO-EVEN (1.5→2, 2.5→2, 0.5→0). Differs from every other integer
|
|
49
|
+
* view (which truncate modulo via the packed `array.set`), so `Uint8ClampedArray`
|
|
50
|
+
* writes route through this helper before the store.
|
|
51
|
+
*/
|
|
52
|
+
export declare function emitToUint8Clamp(fctx: FunctionContext): void;
|
|
53
|
+
/**
|
|
54
|
+
* Emit JS remainder (`a % b`) on f64 operands as a call to the Wasm-native
|
|
55
|
+
* `__fmod` helper, which computes the *exact* IEEE-754 remainder
|
|
56
|
+
* ([Number::remainder §6.1.6.1.6](https://tc39.es/ecma262/#sec-numeric-types-number-remainder)).
|
|
57
|
+
* Stack: [a_f64, b_f64] -> [result_f64].
|
|
58
|
+
*
|
|
59
|
+
* The previous inline formula `a - trunc(a/b)*b` (+ copysign) was not fmod: it
|
|
60
|
+
* drifted by ULPs, collapsed to 0 for large `a/b`, and overflowed to ±Infinity
|
|
61
|
+
* when `a/b` exceeded f64 range. `__fmod` handles all of those plus the #216
|
|
62
|
+
* edge cases (`x % Inf`, `-0 % x`, `Inf % x`, `x % 0`, `NaN % x`) internally.
|
|
63
|
+
* See `fmod.ts` for the algorithm and correctness notes (#2056).
|
|
64
|
+
*/
|
|
65
|
+
export declare function emitModulo(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
66
|
+
/**
|
|
67
|
+
* Emit `a % b` on i32 operands without the Wasm traps of bare `i32.rem_s`.
|
|
68
|
+
*
|
|
69
|
+
* `i32.rem_s` traps when `b == 0` and on the signed-overflow case
|
|
70
|
+
* `INT_MIN % -1`. JS yields NaN and 0 respectively for the corresponding
|
|
71
|
+
* Number operation; in i32 fast mode the result must be an i32 (no NaN
|
|
72
|
+
* representation), so we emit 0 for both trapping cases. 0 is the
|
|
73
|
+
* mathematically-correct value for `INT_MIN % -1`, and the i32 truncation of
|
|
74
|
+
* JS's NaN result is also 0, so this is the least-surprising i32 behaviour.
|
|
75
|
+
*
|
|
76
|
+
* Stack: [a_i32, b_i32] -> [result_i32]. See #1825.
|
|
77
|
+
*/
|
|
78
|
+
export declare function emitSafeI32Rem(fctx: FunctionContext): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Computes a function node's own locals into a caller-supplied set. Injected by
|
|
4
|
+
* `closures.ts` (which owns the actual collection logic) so this module does
|
|
5
|
+
* not duplicate the scope-walking rules. Pure function of `funcLike`.
|
|
6
|
+
*/
|
|
7
|
+
type OwnLocalsCollector = (funcLike: ts.Node, out: Set<string>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Register the own-locals collector. Called once during module init from
|
|
10
|
+
* `closures.ts`. Separating registration from use avoids an import cycle
|
|
11
|
+
* (`closures.ts` already imports a great deal; this keeps the dependency
|
|
12
|
+
* one-directional).
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerOwnLocalsCollector(fn: OwnLocalsCollector): void;
|
|
15
|
+
/**
|
|
16
|
+
* The memoized own-locals set for a function-like node.
|
|
17
|
+
*
|
|
18
|
+
* Returns the same `ReadonlySet` instance for repeated calls on the same node
|
|
19
|
+
* within a compile. Returns an empty set for non-function nodes (mirroring the
|
|
20
|
+
* underlying collector, which no-ops when the node is not a function-scope
|
|
21
|
+
* boundary). The returned set MUST NOT be mutated by callers — use
|
|
22
|
+
* {@link addFunctionOwnLocals} when you need to accumulate into your own set.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getFunctionOwnLocals(funcLike: ts.Node): ReadonlySet<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Add a function-like node's own locals to `out`, going through the memoized
|
|
27
|
+
* cache. Behavior-identical to calling the raw collector with `out`, but the
|
|
28
|
+
* per-node walk runs at most once per compile.
|
|
29
|
+
*/
|
|
30
|
+
export declare function addFunctionOwnLocals(funcLike: ts.Node, out: Set<string>): void;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Instr, ValType } from '../ir/types.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A string representation strategy: the minimal per-representation seam the
|
|
5
|
+
* shared builtin lowerings need. Each builtin lane picks one of the concrete
|
|
6
|
+
* reprs ({@link hostStringRepr} / {@link nativeStringRepr}); everything else
|
|
7
|
+
* — the fold structure, the separator placement, the empty-string fallback —
|
|
8
|
+
* is shared.
|
|
9
|
+
*/
|
|
10
|
+
export interface StringRepr {
|
|
11
|
+
/** Wasm type of a value produced by this representation's string operations. */
|
|
12
|
+
readonly resultType: ValType;
|
|
13
|
+
/**
|
|
14
|
+
* Materialize a string literal (separator, empty string, …) onto the stack.
|
|
15
|
+
* Host repr emits a `string_constants` global; native repr emits a
|
|
16
|
+
* `$NativeString` cast up to `$AnyString`.
|
|
17
|
+
*/
|
|
18
|
+
literal(value: string): Instr[];
|
|
19
|
+
/**
|
|
20
|
+
* Concatenate two operands. `a` and `b` are instruction sequences that each
|
|
21
|
+
* leave exactly one {@link resultType} value on the stack; the returned
|
|
22
|
+
* sequence leaves their concatenation. Host repr calls the `wasm:js-string`
|
|
23
|
+
* `concat` builtin; native repr calls the pure-Wasm `__str_concat` helper.
|
|
24
|
+
*/
|
|
25
|
+
concat(a: Instr[], b: Instr[]): Instr[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Host (JS-string) representation: results are `externref`, concatenation is
|
|
29
|
+
* the `wasm:js-string` `concat` builtin, literals are `string_constants`
|
|
30
|
+
* globals. Returns `undefined` if the `concat` builtin is not registered (the
|
|
31
|
+
* caller must already have ensured string support).
|
|
32
|
+
*/
|
|
33
|
+
export declare function hostStringRepr(ctx: CodegenContext): StringRepr | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Native-string (standalone / WASI) representation: results are
|
|
36
|
+
* `(ref $AnyString)`, concatenation is the pure-Wasm `__str_concat` helper,
|
|
37
|
+
* literals are inline `$NativeString` values cast up to `$AnyString`. Zero
|
|
38
|
+
* host imports. Returns `undefined` if the native string helpers cannot be
|
|
39
|
+
* provisioned.
|
|
40
|
+
*/
|
|
41
|
+
export declare function nativeStringRepr(ctx: CodegenContext): StringRepr | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Shared variadic string-concatenation primitive (#2088).
|
|
44
|
+
*
|
|
45
|
+
* Folds `parts[0] ++ parts[1] ++ … ++ parts[n-1]` left-to-right using the
|
|
46
|
+
* representation's `concat`. Each `parts[i]` is an instruction sequence that
|
|
47
|
+
* leaves exactly one `repr.resultType` value on the stack. Used by the
|
|
48
|
+
* `String.fromCharCode` / `String.fromCodePoint` lanes (each argument's code
|
|
49
|
+
* unit becomes a one-char string `part`); the spec's left-to-right argument
|
|
50
|
+
* evaluation order is preserved because the parts are already compiled in
|
|
51
|
+
* order by the caller.
|
|
52
|
+
*
|
|
53
|
+
* With a single part this is the identity (no `concat` call), matching the
|
|
54
|
+
* spec for a 1-argument call. Callers must pass at least one part.
|
|
55
|
+
*/
|
|
56
|
+
export declare function emitVariadicStringConcat(repr: StringRepr, parts: Instr[][]): Instr[];
|
|
57
|
+
/** Locals threaded through {@link emitStringJoinFold}. */
|
|
58
|
+
export interface JoinFoldLocals {
|
|
59
|
+
/** i32 — current iteration index. */
|
|
60
|
+
iTmp: number;
|
|
61
|
+
/** i32 — element count. */
|
|
62
|
+
lenTmp: number;
|
|
63
|
+
/** `repr.resultType` — accumulator (also the eventual return). */
|
|
64
|
+
resultTmp: number;
|
|
65
|
+
/** `repr.resultType` — separator. */
|
|
66
|
+
sepTmp: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Shared array-join fold (#2088).
|
|
70
|
+
*
|
|
71
|
+
* Emits, into `fctx.body`, the canonical join loop shared by every `join`
|
|
72
|
+
* representation:
|
|
73
|
+
*
|
|
74
|
+
* for (i = 0; i < len; i++)
|
|
75
|
+
* result = (i == 0) ? toStr(elem_i)
|
|
76
|
+
* : concat(concat(result, sep), toStr(elem_i))
|
|
77
|
+
*
|
|
78
|
+
* followed by the empty-array fallback (`result` left null / unset ⇒ `""`,
|
|
79
|
+
* never `null`, which downstream string consumers would render as `"null"` —
|
|
80
|
+
* the #1968 bug). `elemToStr` is the only representation- *and* element-type-
|
|
81
|
+
* specific input: an instruction sequence that loads element `iTmp` from the
|
|
82
|
+
* backing array and leaves its string form (a `repr.resultType` value) on the
|
|
83
|
+
* stack.
|
|
84
|
+
*
|
|
85
|
+
* The caller is responsible for:
|
|
86
|
+
* - allocating + initializing the locals in `locals` (sep, result="", i=0),
|
|
87
|
+
* - setting `lenTmp` from the receiver length,
|
|
88
|
+
* - emitting any post-fold conversion (e.g. native `extern.convert_any`).
|
|
89
|
+
*
|
|
90
|
+
* Because both the host and native `join` lanes emit their loop body here, a
|
|
91
|
+
* bug in this function regresses both lanes simultaneously.
|
|
92
|
+
*/
|
|
93
|
+
export declare function emitStringJoinFold(ctx: CodegenContext, fctx: FunctionContext, repr: StringRepr, locals: JoinFoldLocals, elemToStr: Instr[]): void;
|
|
94
|
+
/**
|
|
95
|
+
* Allocate the standard join-fold locals for `repr`. The accumulator and
|
|
96
|
+
* separator carry `repr.resultType`; the index/length are i32.
|
|
97
|
+
*/
|
|
98
|
+
export declare function allocJoinFoldLocals(fctx: FunctionContext, repr: StringRepr, tag: string): JoinFoldLocals;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValType } from '../ir/types.js';
|
|
2
|
+
import { ts } from '../ts-api.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
4
|
+
export declare function isSupportedBuiltinNamespace(name: string): boolean;
|
|
5
|
+
export declare function isSupportedBuiltinStaticProperty(builtinName: string, propName: string): boolean;
|
|
6
|
+
export declare function resolveBuiltinNamespaceValueName(ctx: CodegenContext, expr: ts.Expression): string | undefined;
|
|
7
|
+
export declare function emitBuiltinStaticMethodValue(ctx: CodegenContext, fctx: FunctionContext, builtinName: string, propName: string): ValType | null;
|
|
8
|
+
export declare function emitBuiltinNamespaceObject(ctx: CodegenContext, fctx: FunctionContext, builtinName: string): ValType | null;
|