@nudojs/core 1.2.0 → 1.3.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/dist/exec.d.ts CHANGED
@@ -1,3 +1,598 @@
1
- export { $ as $add, a as $arguments, b as $arr, c as $arrMutContainer, d as $arrRest, e as $arrWithHoles, f as $assignRecord, g as $async, h as $asyncReturn, i as $await, j as $bitand, k as $bitnot, l as $bitor, m as $bitxor, n as $call, o as $callNamed, p as $catchVal, q as $class, r as $classExpr, s as $collectionForEach, t as $concat, u as $copy, v as $del, w as $delRes, x as $div, y as $dynamicImport, z as $elems, B as $eq, C as $eqLoose, D as $fnVal, E as $for, F as $forInKeys, G as $forIter, H as $forOf, I as $fork, J as $ge, K as $gen, L as $get, M as $gt, N as $idx, O as $idxSet, P as $importMeta, Q as $in, S as $instanceof, T as $instanceofNonIdent, U as $invoke, V as $invokeSuper, W as $isBreakTo, X as $isForkExit, Y as $join, Z as $le, _ as $len, a0 as $lit, a1 as $loopBreak, a2 as $loopContinue, a3 as $loopReturn, a4 as $lt, a5 as $mod, a6 as $mul, a7 as $ne, a8 as $neLoose, a9 as $neg, aa as $new, ab as $not, ac as $nullishTest, ad as $obj, ae as $objAccessor, af as $objRest, ag as $optionalGet, ah as $optionalInvoke, ai as $orDefault, aj as $pow, ak as $pushLoopExit, al as $rawThis, am as $reStateCall, an as $recordBinding, ao as $regex, ap as $rethrowIfNudoReturn, aq as $set, ar as $setKey, as as $shl, at as $shr, au as $spread, av as $staticInvoke, aw as $sub, ax as $super, ay as $switch, az as $thisGet, aA as $thisSet, aB as $throw, aC as $toNumber, aD as $tryCurrentMark, aE as $tryDetachSoftCatch, aF as $tryDigestSoftCatch, aG as $tryDiscardSoft, aH as $tryMark, aI as $tryOrphanSoft, aJ as $tryPopMark, aK as $tryReleaseSoftCatch, aL as $tryReleaseSoftOut, aM as $tryTakeSince, aN as $typeof, aO as $unknown, aP as $ushr, aQ as $while, aR as $whileSeq, aS as $yield, aT as DEFAULT_MAX_LOOP_ITERS, aU as EvalAbsAssignRecord, aV as EvalCallRecord, aW as EvalClassSpec, aX as EvalFallback, aY as MAX_EVAL_CALL_DEPTH, aZ as MAX_EVAL_TOTAL_CALLS, a_ as NudoLoopSignal, a$ as NudoReturn, b0 as NudoThrow, b1 as NudoUnsupportedError, b2 as RUNTIME_IMPORT_RE, R as RunTranspiledOptions, b3 as TranspileOptions, b4 as TranspiledCallResult, b5 as asAbsVal, b7 as bindingsOf, b8 as callAtFunctionBoundary, b9 as callTranspiledExport, ba as callTranspiledExportFull, bb as clearBClasses, bc as clearStaleTermPred, be as currentExecPhi, bf as evalExprAbs, bg as fillTuple, bh as foldRequireSpecArg, bi as foldStaticStringExpr, bj as getEvalCallCollector, bk as getEvalClass, bl as isArrMutator, bm as isDefinitelyFalse, bn as isDefinitelyTrue, bo as isNudoBreak, bp as isNudoContinue, bq as isNudoReturn, br as isNudoThrow, bs as litTruth, bt as lookupObjAccessor, bu as namespaceNameOf, bv as noteEvalCallRecord, bw as noteEvalFallback, bx as pushLoopExit, by as pushThrowExit, bz as registerEvalClass, bA as resetEvalCallBudget, bB as runTranspiled, bC as runTranspiledOptionsMemoKey, bD as runWithLoopExits, bE as runtimeImportOf, bF as setEvalAssignCollector, bG as setEvalBindingSink, bH as setEvalCallCollector, bI as setEvalFallbackCollector, bJ as takeLoopExits, bK as takeThrowExits, bL as transpile, bM as transpileBodyNode, bN as transpileExpression, bO as transpileFile, bP as transpileSource, bQ as tryRunTranspiled, bR as withExecPhi } from './index-DMjMPLV0.js';
2
- import './hof-types-COqDeD5F.js';
3
- import '@babel/types';
1
+ import { A as Abs, M as MayThrowEffect, b as Phi } from './run-Dk08Q5zl.js';
2
+ export { K as $assignRecord, L as $callNamed, N as $recordBinding, O as EvalAbsAssignRecord, Q as EvalCallRecord, U as EvalFallback, f as EvalFallbackStats, X as MAX_EVAL_CALL_DEPTH, Y as MAX_EVAL_TOTAL_CALLS, Z as RUNTIME_IMPORT_RE, J as RunTranspiledOptions, a0 as TranspiledCallResult, ab as bindingsOf, ae as callTranspiledExport, af as callTranspiledExportFull, g as enterEvalCallBudgetSession, ak as evalExprAbs, i as exitEvalCallBudgetSession, o as getEvalCallBudgetState, an as getEvalCallCollector, p as getEvalFallbackStats, aH as noteEvalCallRecord, aI as noteEvalFallback, aW as resetEvalCallBudget, x as resetEvalFallbackStats, aX as runTranspiled, aY as runTranspiledOptionsMemoKey, aZ as setEvalAssignCollector, a_ as setEvalBindingSink, a$ as setEvalCallCollector, b0 as setEvalFallbackCollector, ba as tryRunTranspiled, F as withEvalBudgetOverride } from './run-Dk08Q5zl.js';
3
+ import { Node, Expression, File } from '@babel/types';
4
+
5
+ /**
6
+ * 求值引擎 throw 载荷(独立叶子模块):
7
+ * builtins.ts(evalJsonMethod 等 Abs builtin)需要硬抛 TypeError/SyntaxError,
8
+ * 而 exec/runtime.ts 又 import builtins.ts(evalNamespaceCall 等)——
9
+ * 直接互引成环。NudoThrow 无依赖(仅 Abs 类型 + Error),抽成叶子,
10
+ * runtime.ts re-export 保持既有 import 面不变。
11
+ */
12
+
13
+ /** 求值引擎 throw 载荷:携带 Abs 抛出值 */
14
+ declare class NudoThrow extends Error {
15
+ readonly absValue: Abs;
16
+ constructor(absValue: Abs);
17
+ }
18
+ declare function isNudoThrow(e: unknown): e is NudoThrow;
19
+
20
+ /**
21
+ * 求值引擎运行时共享状态:phi、就地写、字面量 Abs、真值、循环信号。
22
+ * 叶子模块——不依赖 runtime 其它文件(tuple/obj 字面量就地构造,避免 state↔containers 环)。
23
+ */
24
+
25
+ /** 调用方已直接改 shape 时的 term/pred 清理 */
26
+ declare function clearStaleTermPred(v: Abs): void;
27
+ declare function currentExecPhi(): Phi;
28
+ declare function withExecPhi<T>(p: Phi, body: () => T): T;
29
+ /**
30
+ * transpile 泄漏的 JS 函数值 → 一等 fn Abs。
31
+ * 求值引擎把函数声明/表达式编译成真实 JS 函数;它们流进对象槽、
32
+ * 元组、join 等 Abs 结构时不能裸存——下游(bridge/leq/join)读 `.shape`。
33
+ * 参数名无法从运行时函数恢复(用 fn.length → argN,与 analyzer 的
34
+ * extractParamNames 回退口径一致);带真实参数名走 $fnVal(transpile 侧)。
35
+ */
36
+ declare function asAbsVal(v: unknown): Abs;
37
+ /**
38
+ * 函数调用边界:callee 的 loop/early-return 不得冒泡成 caller 结果。
39
+ * 每个 求值引擎调用帧独立 ALS;NudoReturn 收成该调用的返回值。
40
+ */
41
+ declare function callAtFunctionBoundary<T>(body: () => T): T;
42
+ /** 函数表达式 → 一等 fn Abs(transpile 侧带真实参数名;异步 body 包 $async)
43
+ * opts.bindThis:对象方法——$invoke 会把 receiver 作为 impl 首参注入。 */
44
+ declare function $fnVal(params: string[], impl: (...args: Abs[]) => Abs, opts?: {
45
+ bindThis?: boolean;
46
+ }): Abs;
47
+ /**
48
+ * 宿主 this → Abs:函数体 prologue 用它承接 call/apply/bind 传入的 thisArg。
49
+ * Abs 原样返回;宿主 undefined(普通调用/call 缺 thisArg)→ $lit(undefined)。
50
+ * 求值引擎产物是 new Function 拼接(sloppy),裸调用的宿主 this 泄漏为
51
+ * globalThis——归一到 $lit(undefined)(strict 模块语义下的 this)。
52
+ */
53
+ declare function $rawThis(v: unknown): Abs;
54
+ /** 字面量 → Abs(transpile 侧数字/字符串/布尔/null/undefined) */
55
+ declare function $lit(v: unknown): Abs;
56
+ /** JS 真值:字面量按 Boolean(v);对象形恒真;不可判 → undefined */
57
+ declare function litTruth(a: Abs): boolean | undefined;
58
+ declare function isDefinitelyTrue(a: Abs): boolean;
59
+ declare function isDefinitelyFalse(a: Abs): boolean;
60
+ /** 函数求值作用域:收集抽象分支上的 early-return / throw 值;try 标记栈同边界 */
61
+ declare function runWithLoopExits<T>(body: () => T): T;
62
+ declare function takeLoopExits(): Abs[];
63
+ declare function takeThrowExits(): Abs[];
64
+ declare function pushLoopExit(v: Abs): void;
65
+ declare function pushThrowExit(v: Abs): void;
66
+ /** transpile 生成代码用:`$pushLoopExit` */
67
+ declare function $pushLoopExit(v: Abs): void;
68
+ /** try 块开始:压栈 hard/soft 标记 */
69
+ declare function $tryMark(): number;
70
+ /** 当前最内层 try 的 mark(return 时 drain 用;嵌套调用不串栈) */
71
+ declare function $tryCurrentMark(): number;
72
+ declare function $tryPopMark(): void;
73
+ /** 取出 mark 之后新记录的 throw(try 吸收 / catch 合并) */
74
+ declare function $tryTakeSince(mark: number): Abs[];
75
+ /** catch 入口消化 try 内 soft may-throw(幂等;design §3.3) */
76
+ declare function $tryDigestSoftCatch(): void;
77
+ /**
78
+ * 正常完成路径 + catch 可能 rethrow:soft 效果不得消化——假想 soft throw
79
+ * 经 catch rethrow 逃逸(try { u.name } catch (e) { throw e; } 的 L2)。
80
+ * 摘帧上浮(collector / 外层 try 帧可再消化),并清 soft 标记防二次释放。
81
+ */
82
+ declare function $tryReleaseSoftCatch(): void;
83
+ /**
84
+ * catch 入口摘下 soft 效果(不消化)。catch 正常落出口再 discard;
85
+ * catch rethrow 时 orphan 上浮(外层 try 可再消化)。
86
+ */
87
+ declare function $tryDetachSoftCatch(): MayThrowEffect[];
88
+ /** catch 无 rethrow 落出口:丢弃已摘下的 soft(design:catch 消化) */
89
+ declare function $tryDiscardSoft(_effects: MayThrowEffect[]): void;
90
+ /** catch rethrow:摘下的 soft 上浮(嵌套 try 归外层帧) */
91
+ declare function $tryOrphanSoft(effects: MayThrowEffect[]): void;
92
+ /** 无 handler / 出口:上浮未消化 soft may-throw(幂等) */
93
+ declare function $tryReleaseSoftOut(): void;
94
+ /** 求值引擎「函数提前 return」信号(区别于 throw) */
95
+ declare class NudoReturn extends Error {
96
+ readonly absValue: Abs;
97
+ constructor(absValue: Abs);
98
+ }
99
+ declare function isNudoReturn(e: unknown): e is NudoReturn;
100
+ /** transpile `return x` inside for/while → `$loopReturn(x)` */
101
+ declare function $loopReturn(v: Abs): never;
102
+ /**
103
+ * break/continue 信号:transpile 在循环体内生成 $loopBreak/$loopContinue,
104
+ * $for/$whileSeq/$forOf 在 body 调用点捕获。带标签信号只被同标签循环吸收,
105
+ * 不匹配继续冒泡到外层循环(`break outer` / `continue outer` 语义)。
106
+ */
107
+ declare class NudoLoopSignal extends Error {
108
+ readonly kind: "break" | "continue";
109
+ readonly label: string | undefined;
110
+ constructor(kind: "break" | "continue", label?: string);
111
+ }
112
+ declare function $loopBreak(label?: string): never;
113
+ declare function $loopContinue(label?: string): never;
114
+ declare function isNudoBreak(e: unknown, label?: string): boolean;
115
+ declare function isNudoContinue(e: unknown, label?: string): boolean;
116
+ /** 非循环 labeled block:判断 break 信号是否指向本标签(transpile 生成代码用) */
117
+ declare function $isBreakTo(e: unknown, label: string): boolean;
118
+ /** catch 转译辅助:控制流信号透传(生成代码只注入 `$` 前缀符号) */
119
+ declare function $rethrowIfNudoReturn(e: unknown): void;
120
+
121
+ /**
122
+ * 运算符重载面(transpile 目标):$add/$sub/…、比较/位运算。
123
+ */
124
+
125
+ declare function $unknown(): Abs;
126
+ /** `import.meta` → `{ url: string }`(宿主 URL 非字面量,不假精确) */
127
+ declare function $importMeta(): Abs;
128
+ /** `import(spec)` → Promise&lt;开放模块命名空间&gt;(动态模块图不静态解析) */
129
+ declare function $dynamicImport(_spec: Abs): Abs;
130
+ declare function $add(a: Abs, b: Abs): Abs;
131
+ declare function $sub(a: Abs, b: Abs): Abs;
132
+ declare function $mul(a: Abs, b: Abs): Abs;
133
+ declare function $div(a: Abs, b: Abs): Abs;
134
+ declare function $mod(a: Abs, b: Abs): Abs;
135
+ declare function $bitand(a: Abs, b: Abs): Abs;
136
+ declare function $bitor(a: Abs, b: Abs): Abs;
137
+ declare function $bitxor(a: Abs, b: Abs): Abs;
138
+ declare function $bitnot(a: Abs): Abs;
139
+ declare function $shl(a: Abs, b: Abs): Abs;
140
+ declare function $shr(a: Abs, b: Abs): Abs;
141
+ declare function $ushr(a: Abs, b: Abs): Abs;
142
+ declare function $pow(a: Abs, b: Abs): Abs;
143
+ declare function $toNumber(a: Abs): Abs;
144
+ /** ToNumeric(UpdateExpression):number|bigint,bigint 保持 */
145
+ declare function $toNumeric(a: Abs): Abs;
146
+ /** UpdateExpression `old+1`:ToNumeric 后按 numeric type 加 1(无 string concat) */
147
+ declare function $updateAdd(a: Abs): Abs;
148
+ /** UpdateExpression `old-1` */
149
+ declare function $updateSub(a: Abs): Abs;
150
+ declare function $neg(a: Abs): Abs;
151
+ declare function $typeof(a: Abs): Abs;
152
+ declare function $not(a: Abs): Abs;
153
+ declare function $eq(a: Abs, b: Abs): Abs;
154
+ declare function $ne(a: Abs, b: Abs): Abs;
155
+ /** `==` / `!=`(C2.3):双字面量 Abstract Equality,否则回落严格判定 */
156
+ declare function $eqLoose(a: Abs, b: Abs): Abs;
157
+ declare function $neLoose(a: Abs, b: Abs): Abs;
158
+ declare function $lt(a: Abs, b: Abs): Abs;
159
+ declare function $le(a: Abs, b: Abs): Abs;
160
+ declare function $gt(a: Abs, b: Abs): Abs;
161
+ declare function $ge(a: Abs, b: Abs): Abs;
162
+ declare function $join(a: Abs, b: Abs): Abs;
163
+
164
+ /**
165
+ * 访问器(get/set)侧表、in / instanceof / delete 路由。
166
+ */
167
+
168
+ /** 注册对象字面量访问器(transpile 调用;返回原 obj 以便链式包裹) */
169
+ declare function $objAccessor(o: Abs, key: string, get: ((t: Abs) => Abs) | null, set: ((t: Abs, v: Abs) => Abs) | null): Abs;
170
+ /** 对象字面量访问器查询(供 $get/$set/$spread/Object.assign 共用) */
171
+ declare function lookupObjAccessor(o: Abs, key: string): {
172
+ get?: (t: Abs) => Abs;
173
+ set?: (t: Abs, v: Abs) => Abs;
174
+ } | undefined;
175
+ /**
176
+ * `key in obj`:闭形状精确判定(含 Object.prototype 名、数组下标/length、
177
+ * class 方法/访问器与内建 brand 方法);prim/nullish 接收者原生抛 TypeError →
178
+ * unknown;抽象键/开形状 → boolean。
179
+ */
180
+ declare function $in(key: Abs, o: Abs): Abs;
181
+ /**
182
+ * `x instanceof Right`(Right 为标识符名):按左值形状精确判定。
183
+ * nullish 左侧原生抛 TypeError → unknown;未知用户构造器名 → boolean(不得 exact false)。
184
+ */
185
+ declare function $instanceof(left: Abs, rightName: string, rightVal?: Abs): Abs;
186
+ /** instanceof 右操作数非标识符(表达式/成员路径):构造器值未知 → 抽象 boolean */
187
+ declare function $instanceofNonIdent(_left: Abs): Abs;
188
+ /** ClassExpression 值:构造器函数形状,不得折成精确 undefined */
189
+ declare function $classExpr(): Abs;
190
+ /**
191
+ * `delete obj[key]` 的结果判定(只读,不写回)。
192
+ * frozen/sealed 或 configurable:false 键 → false;preventExtensions 可删;
193
+ * closed 目标恒 true(其余 non-configurable 形态不建模);
194
+ * prim/nullish 接收者原生抛 TypeError → unknown。
195
+ */
196
+ declare function $delRes(o: Abs, _key: Abs): Abs;
197
+ /**
198
+ * `delete obj[key]` 的写入(不可变更新):返回删键后的新容器。
199
+ * 闭对象删自有槽;tuple 规范下标置 undefined(对齐原生空洞读值);
200
+ * 抽象 arr 元素并入 undefined;无法表达的形态原样返回。
201
+ */
202
+ declare function $del(o: Abs, key: Abs): Abs;
203
+
204
+ /**
205
+ * 循环展开上限(leaf)—— 从 control.ts 拆出,打断 control ↔ containers 环。
206
+ */
207
+ declare const DEFAULT_MAX_LOOP_ITERS = 8;
208
+
209
+ declare function $fork(test: Abs, consequent: () => Abs, alternate?: () => Abs): Abs;
210
+
211
+ /**
212
+ * for 的惰性展开:生成器只负责「按上限吐状态」。
213
+ * 抽象条件无法诚实终止——消费者必须自带 maxIters。
214
+ */
215
+ declare function $forIter(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, body: (s: Abs) => Abs, maxIters?: number): Generator<{
216
+ state: Abs;
217
+ test: Abs;
218
+ afterBody: Abs;
219
+ }, void, void>;
220
+ /**
221
+ * 有界 for:unroll ≤ maxIters,每步「可能退出」的态 join;
222
+ * 相邻态 leq 视为不动点提前停。
223
+ */
224
+ declare function $for(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, body: (s: Abs) => Abs, maxIters?: number, opts?: {
225
+ pack?: () => Abs;
226
+ unpack?: (s: Abs) => void;
227
+ /** 标签循环(`outer: for …`):仅吸收同标签 break/continue 信号 */
228
+ label?: string;
229
+ }): Abs;
230
+ /**
231
+ * 有界 while:state 线程穿 test/step(与 $for 同折叠语义)。
232
+ * 抽象条件无法诚实终止——必须 maxIters。
233
+ */
234
+ declare function $while(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, maxIters?: number): Abs;
235
+ /**
236
+ * 顺序 while(具体/可变闭包):body 内对 JS 变量赋值。
237
+ * 提供 pack/unpack 时,抽象条件的可能出口会 join 回绑定(P0 健全);
238
+ * 未 instrument 的调用保持旧语义(预算截断,文档已声明)。
239
+ */
240
+ declare function $whileSeq(test: () => Abs, body: () => void, maxIters?: number, opts?: {
241
+ /** 把当前绑定收成 Abs 状态(transpile 注入) */
242
+ pack?: () => Abs;
243
+ /** 把 join 后的状态写回绑定 */
244
+ unpack?: (s: Abs) => void;
245
+ /** 标签循环:仅吸收同标签 break/continue 信号 */
246
+ label?: string;
247
+ }): void;
248
+ declare function $switch(disc: Abs, cases: Array<{
249
+ test: Abs;
250
+ run: () => Abs;
251
+ }>, dflt?: () => Abs): Abs;
252
+ /** transpile `throw x` → `$throw(x)` */
253
+ declare function $throw(v: Abs): never;
254
+ /**
255
+ * fork 臂是否以控制流退出(return / throw)。
256
+ * 生成代码用此决定 continue-path free-write 标志:退出臂的写
257
+ * 不得污染 join 后的 continue 绑定。
258
+ */
259
+ declare function $isForkExit(e: unknown): boolean;
260
+ /** catch 参数:从 NudoThrow 取出 Abs;宿主 Error 补 name/message;否则 unknown */
261
+ declare function $catchVal(e: unknown): Abs;
262
+
263
+ /**
264
+ * 数组 / 对象运行时:$arr/$idx/$len/$arrMutContainer 与 $obj/$get/$set/$spread。
265
+ */
266
+
267
+ /** 数组字面量 → ≤cap tuple(逐元素精确)/ >cap arr;策略与 containers.ts 同源 */
268
+ declare function $arr(items: Abs[]): Abs;
269
+ /**
270
+ * `arguments` 对象 → 类数组 tuple($len/$idx 投影 length/下标;typeof 为 "object")。
271
+ * strict/ESM 与形参**独立映射**:写 `arguments[i]` 不改形参,写形参不改 `arguments`。
272
+ * (sloppy 非严格是 mapped arguments object,二者互相写回——Nudo 分析按 ESM/strict。)
273
+ * 与 rest 绑定解耦:rest 仍从真实 `arguments`/rest 形参收集,本对象只服务用户写的 `arguments`。
274
+ */
275
+ declare function $arguments(items: ArrayLike<unknown>): Abs;
276
+ /**
277
+ * 带空洞的数组字面量([1,,3]):hole 槽位置为 undefined 值但 `in` 判定 false。
278
+ * 超 cap 退化 arr 时丢弃 hole 精度(元素 join,长度语义已由 arr 承接)。
279
+ */
280
+ declare function $arrWithHoles(items: Abs[], holes: number[]): Abs;
281
+ declare function isArrMutator(name: string): boolean;
282
+ declare function fillTuple(shape: {
283
+ k: "tuple";
284
+ elements: Abs[];
285
+ holes?: number[];
286
+ } | {
287
+ k: "arr";
288
+ element: Abs;
289
+ }, vals: Abs[], arr: Abs): Abs;
290
+ /**
291
+ * 深拷贝可变容器(fork/switch 快照与循环 pack 用)。
292
+ * 容器写就地进行后(引用语义),分析分支/迭代的状态分离必须靠拷贝——
293
+ * 浅引用快照会让臂间/迭代间互相污染。
294
+ */
295
+ declare function $copy(a: Abs): Abs;
296
+ /** 数组/元组方法(push/pop/shift/unshift/splice/reverse/sort/copyWithin/fill)
297
+ * 的就地 mutator:Abs 身份不变(JS 引用语义——`const b = a; b.push(4)` 对 a
298
+ * 可见);transpile 重绑 `a = $arrMutContainer(a, …)` 仍写回同一对象。 */
299
+ declare function $arrMutContainer(arr: Abs, method: string, args: Abs[]): Abs;
300
+ /** 下标读 a[i];规范数组下标走精确投影,确定非下标键 → undefined,否则并所有元素;string[i] → 单字符 */
301
+ declare function $idx(a: Abs, i: Abs): Abs;
302
+ /** 下标写 a[i]=v → 新 tuple(越界写按 JS 语义增长,空洞为 undefined) */
303
+ declare function $idxSet(a: Abs, i: Abs, value: Abs): Abs;
304
+ /** 数组/字符串长度 */
305
+ declare function $len(a: Abs): Abs;
306
+ /** 对象字面量 → Abs obj(槽位写走 setSlot,`__proto__` 不踩宿主 setter) */
307
+ declare function $obj(slots: Record<string, Abs>): Abs;
308
+ /**
309
+ * 对象字面量非计算 `__proto__: v` 的特殊原型设定(ES PropertyDefinition)。
310
+ * - v 为 null → null-proto(无 Object.prototype 回退)
311
+ * - v 为 object → 保守 open(继承读不折 exact undefined;细节不建模)
312
+ * - v 为 primitive → 原生忽略(无自有键、不改原型)
313
+ */
314
+ declare function $setProto(o: Abs, proto: Abs): Abs;
315
+ /** 对象展开 { ...a, b } */
316
+ declare function $spread(a: Abs, b: Abs): Abs;
317
+ /**
318
+ * 解构 rest:`const { a, ...rest } = o` → rest = o 去掉 named keys。
319
+ * closed obj:剩余槽 closed;open / optional 键:rest 仍 open(可能有未知键)。
320
+ */
321
+ declare function $objRest(o: Abs, keys: string[]): Abs;
322
+ /** 数组 rest:`const [a, ...rest] = arr` → rest = 从 start 起的尾段 */
323
+ declare function $arrRest(a: Abs, start: number): Abs;
324
+ /** 数组连接 [...a, ...b] / [...a, x];结果超 cap 时与字面量同策略降 arr */
325
+ declare function $concat(a: Abs, b: Abs): Abs;
326
+ /** 元素列表(tuple 展开;arr 抽象;C1 Set/Map 逐条目;matchAll 迭代器逐匹配项;
327
+ * 字符串按 code points)。Map 迭代语义是 entry `[key, value]` 元组,不是裸 value。 */
328
+ declare function $elems(a: Abs): Abs[];
329
+ /**
330
+ * for-of:对 iterable 每个元素跑 body;有界展开。
331
+ * body(item, i) 可返回 void;状态由外部 JS 变量承接。
332
+ * - 具体空 tuple:体 0 次(不得用 `length || maxIters` 展开成 maxIters)
333
+ * - 抽象 arr / 未知长度:0..maxIters 出口与 pack 状态 join
334
+ */
335
+ /**
336
+ * for-in 键序列:原生顺序为整数键升序 → 其余键按插入序;
337
+ * 数组 hole 槽不出键(读值为 undefined 但不可枚举)。仅自有可枚举键。
338
+ */
339
+ declare function $forInKeys(o: Abs): Abs;
340
+ declare function $forOf(iterable: Abs, body: (item: Abs, index: Abs) => void, maxIters?: number, opts?: {
341
+ pack?: () => Abs;
342
+ unpack?: (s: Abs) => void;
343
+ /** 标签循环:仅吸收同标签 break/continue 信号 */
344
+ label?: string;
345
+ }): void;
346
+ /**
347
+ * 命名空间身份表:transpile 后 `Math.max(0, x)` 的接收者是宿主 JS 全局对象
348
+ * (非 Abs)。按对象身份识别命名空间,路由到 Abs builtin 表。
349
+ */
350
+ declare function namespaceNameOf(v: unknown): string | undefined;
351
+ /** 正则字面量 → RegExp brand(source/flags/lastIndex 进 slots,供 exec/test 精确执行) */
352
+ declare function $regex(pattern: string, flags?: string): Abs;
353
+ /** 成员读:obj.slots[key];缺失 → undefined 字面量;brand 解包内层 */
354
+ declare function $get(o: Abs, key: string, opts?: {
355
+ silent?: boolean;
356
+ }): Abs;
357
+ /**
358
+ * Map/Set forEach:条目表逐条调用回调(value, key, recv)。
359
+ * 回调是 求值引擎 JS 函数(transpile 内联箭头)直接调用;Abs fn 走 $call。
360
+ * 回调返回值丢弃;forEach 表达式值恒 undefined。
361
+ */
362
+ declare function $collectionForEach(recv: Abs, cb: unknown): Abs | undefined;
363
+ /** 成员写:返回新 obj/brand(不可变更新);frozen/sealed/只读目标按 sloppy 静默失败 */
364
+ declare function $set(o: Abs, key: string, value: Abs): Abs;
365
+
366
+ /**
367
+ * async / await / generator / $switch / $nullishTest。
368
+ */
369
+
370
+ /**
371
+ * async 函数体包进 thunk,返回值经 wrapPromise。
372
+ */
373
+ declare function $async(thunk: () => Abs): Abs;
374
+ /** await → 解包 eff("promise") */
375
+ declare function $await(v: Abs): Abs;
376
+ /** async 直接 return 的 coerce */
377
+ declare function $asyncReturn(v: Abs): Abs;
378
+ /** function* 体:收集所有 yield 值为 tuple Abs;抽象分支时降 conf(P0-6) */
379
+ declare function $gen(body: () => void): Abs;
380
+ /** yield v:压入当前生成器收集器;表达式值用 unknown */
381
+ declare function $yield(v: Abs): Abs;
382
+ /**
383
+ * switch:具体 disc 选中匹配 case;抽象 disc 并所有分支。
384
+ * 抽象路径与 $fork 同构:集合 side-table 按臂 overlay,共享 body 只跑一次;
385
+ * 臂内 NudoReturn/NudoThrow 不冒泡污染兄弟臂。
386
+ * **无 default 时必须隐式 fall-through 臂(undef)**,否则无匹配路径被丢掉(P0-2)。
387
+ */
388
+ /** `??` / `??=` 测试:确定非 nullish → false;lit nullish → true;否则抽象 boolean */
389
+ declare function $nullishTest(v: Abs): Abs;
390
+
391
+ type TranspileOptions = {
392
+ /** 运行时 import 说明符 */
393
+ runtimeImport?: string;
394
+ maxLoopIters?: number;
395
+ /** 方法体内 this 的绑定名(transpile class 时注入) */
396
+ thisParam?: string;
397
+ /** 当前类名(super 派发用) */
398
+ className?: string;
399
+ /** 原始源码(@nudo:replace 按节点文本匹配) */
400
+ source?: string;
401
+ /** 替换表:归一化目标文本 → 注入变量名;可选语句范围 */
402
+ replacements?: Array<{
403
+ target: string;
404
+ varName: string;
405
+ /** 仅该语句范围内生效(1-based 行) */
406
+ stmtStart?: number;
407
+ stmtEnd?: number;
408
+ }>;
409
+ /** @nudo:as:覆盖紧随语句的 init / return */
410
+ asOverrides?: Array<{
411
+ varName: string;
412
+ stmtStart: number;
413
+ stmtEnd: number;
414
+ }>;
415
+ /** 循环嵌套深度(>0 时 return → $loopReturn,C2.1) */
416
+ inLoop?: number;
417
+ /** 循环体/switch 臂内:无标签 break 语义分别为跳出循环信号 / 臂结束 return */
418
+ inSwitchArm?: boolean;
419
+ /** 标签循环名(`outer: for …`):传给 $for/$whileSeq/$forOf 供信号匹配 */
420
+ loopLabel?: string;
421
+ /** 宽松全局:标识符调用 callee 未声明 → undefined($callNamed 保守
422
+ * unknown),模块不因 ReferenceError 中断——调用点发现的 exec 采集用
423
+ * (测试框架 it/describe/test 等未注入全局) */
424
+ lenientGlobals?: boolean;
425
+ /** try 嵌套深度(>0 时 return 前 drain throwExits,使 catch 能吸收抽象 throw) */
426
+ inTry?: number;
427
+ /** 当前 try 的 mark 变量名(return drain 用;避免全局栈顶污染) */
428
+ tryMarkName?: string;
429
+ /** 当前 try 是否带 catch handler(soft may-throw digest/release 分支) */
430
+ hasTryHandler?: boolean;
431
+ /** 当前 try 的 catch 体是否可能 rethrow(正常路径 soft 效果 release 而非 digest) */
432
+ tryRethrowCatch?: boolean;
433
+ /** 分支/循环体内深度(赋值记录 conditional 标记;inLoop 也计入) */
434
+ conditionalFlow?: number;
435
+ /** 函数/箭头体内(顶层绑定表只收顶层作用域) */
436
+ inFunction?: boolean;
437
+ /**
438
+ * 当前词法作用域的 `arguments` 绑定名(非箭头函数 prologue 里 `$arguments(...)`)。
439
+ * 箭头沿外层继承;无绑定(模块顶层 / 仅嵌套箭头引用)→ Identifier 分支折 $unknown()。
440
+ */
441
+ argsBinding?: string;
442
+ /**
443
+ * 当前词法作用域可见的 const 绑定名(用户层再赋值须 TypeError)。
444
+ * 成员/下标写对根的内部重绑不在用户赋值路径,不走此表。
445
+ */
446
+ constNames?: ReadonlySet<string>;
447
+ };
448
+
449
+ /**
450
+ * transpile 共享 AST 工具:形参名、match、fold、静态键、作用域收集、mutator receiver 扫描。
451
+ * 不依赖 stmt/expr 发射器(无环)。
452
+ */
453
+
454
+ /**
455
+ * 编译期常量字符串折叠(require 说明符子集):
456
+ * - StringLiteral
457
+ * - TemplateLiteral(无插值 / 插值全为可 ToString 字面量)
458
+ * - `+` 字符串拼接(至少一侧为可折叠字符串,另一侧为字符串或字面量)
459
+ * 不能折叠 → undefined(诚实动态,不假精确)。
460
+ */
461
+ declare function foldStaticStringExpr(node: unknown): string | undefined;
462
+ /** require(...) 第一个参数 → 可折叠说明符(StringLiteral / 模板 / 字面量拼接) */
463
+ declare function foldRequireSpecArg(arg: unknown): string | undefined;
464
+
465
+ /**
466
+ * 语句 / 块 / class 发射:transpileStatement、transpileBodyNode、transpileClass。
467
+ */
468
+
469
+ declare function transpileBodyNode(node: Node, opts: TranspileOptions): string;
470
+
471
+ /**
472
+ * 表达式发射:transpileExpression / transpileShortCircuitExpr。
473
+ */
474
+
475
+ declare function transpileExpression(expr: Expression, opts?: TranspileOptions): string;
476
+
477
+ /**
478
+ * 求值引擎 transpile:JS AST → 可在 Node 上执行的抽象值程序(源码字符串)。
479
+ * 运算符改为 $add/$sub/…;if 改为 $fork;for 改为 $for。
480
+ * 值类型是 Abs;副作用与模块仍由 host mock/注入。
481
+ *
482
+ * 实现按语句/表达式/模式拆在 transpile/*.ts;本文件是 re-export facade,
483
+ * 对外符号面保持不变(exec/index.ts `export * from "./transpile.ts"`)。
484
+ */
485
+
486
+ declare function transpileSource(source: string, opts?: TranspileOptions): string;
487
+ /** 运行时 import 行(body-fn 编译执行拼接用) */
488
+ declare function runtimeImportOf(runtime: string): string;
489
+ declare function transpileFile(file: File, opts?: TranspileOptions): string;
490
+ /** 解析 + transpile */
491
+ declare function transpile(source: string, opts?: TranspileOptions): string;
492
+
493
+ /**
494
+ * 调用 Abs 一等函数(absFunction impl)或 mock apply。
495
+ * 供 求值引擎 import 绑定包装:`(...args) => $call(absFn, args)`。
496
+ *
497
+ * 统一顺序:apply → body → relation → isRelFn(委托 applyAbsFn)。
498
+ * 行为对齐说明(与旧 $call 的差异,均属刻意):
499
+ * 1. 带 body 的函数也进 call-budget(递归会 truncated 而非爆栈)
500
+ * 2. body 抛错与 apply 同径 rethrow(不吞成 never 返回,调用边界决定吸收)
501
+ * 3. 无 impl 时 isRelFn 可走 E 路径(旧版恒 unknown)
502
+ */
503
+
504
+ declare function $call(fn: Abs, args: Abs[], thisVal?: Abs): Abs;
505
+
506
+ /**
507
+ * B class 规格表(无 call 依赖,避免循环)。
508
+ * Abs-eval registerClassDecl 与 transpile $class 共用。
509
+ */
510
+
511
+ type EvalClassAccessor = {
512
+ get?: (thisVal: Abs) => Abs;
513
+ set?: (thisVal: Abs, v: Abs) => Abs;
514
+ };
515
+ type EvalClassSpec = {
516
+ name: string;
517
+ superName?: string;
518
+ ctor?: (thisVal: Abs, ...args: Abs[]) => Abs;
519
+ methods?: Record<string, (thisVal: Abs, ...args: Abs[]) => Abs>;
520
+ /** 实例方法形参展示名(AST 形参名;未调用方法槽 `shape.params` 用) */
521
+ methodParams?: Record<string, string[]>;
522
+ staticMethods?: Record<string, (...args: Abs[]) => Abs>;
523
+ /** 静态方法形参展示名 */
524
+ staticMethodParams?: Record<string, string[]>;
525
+ statics?: Record<string, Abs>;
526
+ /** 实例 get/set:get 无参返回 Abs;set 收到 (thisVal, v) 返回更新后的 thisVal */
527
+ accessors?: Record<string, EvalClassAccessor>;
528
+ /** 静态 get/set:挂在类构造器上,不在实例原型链 */
529
+ staticAccessors?: Record<string, EvalClassAccessor>;
530
+ };
531
+ declare function registerEvalClass(spec: EvalClassSpec): void;
532
+ declare function getEvalClass(name: string): EvalClassSpec | undefined;
533
+ declare function clearBClasses(): void;
534
+
535
+ /**
536
+ * RegExp brand 执行面(leaf-ish):从 class.ts 拆出,避免巨型文件。
537
+ */
538
+
539
+ /**
540
+ * 语句级 RegExp 状态写回(test/exec):执行并把 lastIndex 更新后的 brand
541
+ * 返回给 transpile 重绑($reStateCall 与 $arrMutContainer 同模式)。
542
+ * 表达式位置不写回($invoke 只读执行,调用方按 JS 语义先取值)。
543
+ */
544
+ declare function $reStateCall(re: Abs, method: string, args: Abs[]): Abs;
545
+
546
+ /**
547
+ * 求值引擎 class:brand 实例 + ctor/method 闭包 + 继承链。
548
+ * 方法内 this 由 transpile 改写为 thisVal 参数。
549
+ */
550
+
551
+ /** 定义类 → 可 new 的 Abs(brand 标记;静态字段挂在 slots) */
552
+ declare function $class(name: string, spec: Omit<EvalClassSpec, "name"> & {
553
+ extends?: string | Abs | unknown;
554
+ }): Abs;
555
+ /** new C(...) → 空 brand 实例 + ctor 写字段;非类构造走 impl/$call */
556
+ declare function $new(cls: Abs | ((...a: unknown[]) => unknown), args: Abs[]): Abs;
557
+ /**
558
+ * super(...):父类构造写入字段(this 保持子类 brand)。
559
+ * transpile: super(a,b) → __this = $super(__this, "Child", [a,b])
560
+ */
561
+ declare function $super(thisVal: Abs, childName: string, args: Abs[]): Abs;
562
+
563
+ /** 实例方法调用:沿继承链;类 Abs 上回落 staticMethods;obj 上回落属性函数 */
564
+ declare function $invoke(thisVal: Abs, method: string, args: Abs[], loc?: [number, number]): Abs;
565
+ /** super.method():从父类起找(跳过自身覆盖) */
566
+ declare function $invokeSuper(thisVal: Abs, childName: string, method: string, args: Abs[]): Abs;
567
+ declare function $thisGet(thisVal: Abs, key: string): Abs;
568
+ declare function $thisSet(thisVal: Abs, key: string, value: Abs): Abs;
569
+ /** 解构默认值:undefined(含 sum 成员 / 可能缺失)时用 default 并入非 undefined 部分 */
570
+ declare function $orDefault(v: Abs, dflt: () => Abs): Abs;
571
+ /** 可选链 a?.b:nullish 短路为 undefined 字面量 */
572
+ declare function $optionalGet(o: Abs, key: string): Abs;
573
+ /** 可选链 a?.m():nullish 短路为 undefined */
574
+ declare function $optionalInvoke(thisVal: Abs, method: string, args: Abs[]): Abs;
575
+ /** 静态方法:cls.staticMethod(args) */
576
+ declare function $staticInvoke(cls: Abs, method: string, args: Abs[]): Abs;
577
+ /** 计算属性写:o[kAbs] = v。非字面量 key → open + index join(不得写成字面槽 "?") */
578
+ declare function $setKey(o: Abs, key: Abs, value: Abs): Abs;
579
+
580
+ /**
581
+ * 转译器无法正确 lowering 的构造:抛此错误(替代静默降级注释)。
582
+ * 消费方(tryRunTranspiled / body-fn)捕获后记录并 fail-closed
583
+ * 结构化回落理由(unsupported:*)——能力知识单一事实源在转译点,
584
+ * 不再依赖带外的 isEvalCapable 清单。
585
+ */
586
+ declare class NudoUnsupportedError extends Error {
587
+ readonly reason: string;
588
+ readonly loc?: {
589
+ line: number;
590
+ column: number;
591
+ };
592
+ constructor(reason: string, loc?: {
593
+ line: number;
594
+ column: number;
595
+ });
596
+ }
597
+
598
+ export { $add, $arguments, $arr, $arrMutContainer, $arrRest, $arrWithHoles, $async, $asyncReturn, $await, $bitand, $bitnot, $bitor, $bitxor, $call, $catchVal, $class, $classExpr, $collectionForEach, $concat, $copy, $del, $delRes, $div, $dynamicImport, $elems, $eq, $eqLoose, $fnVal, $for, $forInKeys, $forIter, $forOf, $fork, $ge, $gen, $get, $gt, $idx, $idxSet, $importMeta, $in, $instanceof, $instanceofNonIdent, $invoke, $invokeSuper, $isBreakTo, $isForkExit, $join, $le, $len, $lit, $loopBreak, $loopContinue, $loopReturn, $lt, $mod, $mul, $ne, $neLoose, $neg, $new, $not, $nullishTest, $obj, $objAccessor, $objRest, $optionalGet, $optionalInvoke, $orDefault, $pow, $pushLoopExit, $rawThis, $reStateCall, $regex, $rethrowIfNudoReturn, $set, $setKey, $setProto, $shl, $shr, $spread, $staticInvoke, $sub, $super, $switch, $thisGet, $thisSet, $throw, $toNumber, $toNumeric, $tryCurrentMark, $tryDetachSoftCatch, $tryDigestSoftCatch, $tryDiscardSoft, $tryMark, $tryOrphanSoft, $tryPopMark, $tryReleaseSoftCatch, $tryReleaseSoftOut, $tryTakeSince, $typeof, $unknown, $updateAdd, $updateSub, $ushr, $while, $whileSeq, $yield, DEFAULT_MAX_LOOP_ITERS, type EvalClassSpec, NudoLoopSignal, NudoReturn, NudoThrow, NudoUnsupportedError, type TranspileOptions, asAbsVal, callAtFunctionBoundary, clearBClasses, clearStaleTermPred, currentExecPhi, fillTuple, foldRequireSpecArg, foldStaticStringExpr, getEvalClass, isArrMutator, isDefinitelyFalse, isDefinitelyTrue, isNudoBreak, isNudoContinue, isNudoReturn, isNudoThrow, litTruth, lookupObjAccessor, namespaceNameOf, pushLoopExit, pushThrowExit, registerEvalClass, runWithLoopExits, runtimeImportOf, takeLoopExits, takeThrowExits, transpile, transpileBodyNode, transpileExpression, transpileFile, transpileSource, withExecPhi };