@nudojs/core 0.3.0 → 0.4.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.
Files changed (123) hide show
  1. package/dist/chunk-N7E2A7IK.js +7216 -0
  2. package/dist/exec.d.ts +2 -0
  3. package/dist/exec.js +174 -0
  4. package/dist/index-DgyudAkw.d.ts +911 -0
  5. package/dist/index.d.ts +64 -710
  6. package/dist/index.js +3269 -8426
  7. package/package.json +18 -5
  8. package/CHANGELOG.md +0 -34
  9. package/src/__tests__/environment.test.ts +0 -48
  10. package/src/__tests__/fn-sig-impl.test.ts +0 -57
  11. package/src/__tests__/ops-refined.test.ts +0 -196
  12. package/src/__tests__/ops.test.ts +0 -84
  13. package/src/__tests__/type-value-phase2.test.ts +0 -117
  14. package/src/__tests__/type-value-phase3.test.ts +0 -94
  15. package/src/__tests__/type-value-refined.test.ts +0 -210
  16. package/src/__tests__/type-value.test.ts +0 -319
  17. package/src/algebra/__tests__/abs-native.test.ts +0 -176
  18. package/src/algebra/__tests__/arithmetic.test.ts +0 -170
  19. package/src/algebra/__tests__/ast-eval.test.ts +0 -154
  20. package/src/algebra/__tests__/bridge.test.ts +0 -160
  21. package/src/algebra/__tests__/call-budget.test.ts +0 -117
  22. package/src/algebra/__tests__/check-case-consistency.test.ts +0 -69
  23. package/src/algebra/__tests__/check-gold.test.ts +0 -290
  24. package/src/algebra/__tests__/check-json.test.ts +0 -57
  25. package/src/algebra/__tests__/check-mini-repo.test.ts +0 -49
  26. package/src/algebra/__tests__/check-real-commander.test.ts +0 -43
  27. package/src/algebra/__tests__/check-real-packages.test.ts +0 -165
  28. package/src/algebra/__tests__/check-recall-gold.test.ts +0 -1024
  29. package/src/algebra/__tests__/check-require-dep-memo.test.ts +0 -45
  30. package/src/algebra/__tests__/check-return-contract.test.ts +0 -90
  31. package/src/algebra/__tests__/check-shape-gold.test.ts +0 -303
  32. package/src/algebra/__tests__/check-source-memo.test.ts +0 -204
  33. package/src/algebra/__tests__/check.test.ts +0 -69
  34. package/src/algebra/__tests__/denote.test.ts +0 -77
  35. package/src/algebra/__tests__/diagnostics.test.ts +0 -64
  36. package/src/algebra/__tests__/differential.test.ts +0 -124
  37. package/src/algebra/__tests__/div-mod.test.ts +0 -38
  38. package/src/algebra/__tests__/example0.test.ts +0 -103
  39. package/src/algebra/__tests__/exec-analyze-throws.test.ts +0 -60
  40. package/src/algebra/__tests__/exec-async.test.ts +0 -46
  41. package/src/algebra/__tests__/exec-bpath.test.ts +0 -193
  42. package/src/algebra/__tests__/exec-class.test.ts +0 -56
  43. package/src/algebra/__tests__/exec-e2e.test.ts +0 -97
  44. package/src/algebra/__tests__/exec-generator.test.ts +0 -53
  45. package/src/algebra/__tests__/exec-inherit-default.test.ts +0 -111
  46. package/src/algebra/__tests__/exec-optional-nested.test.ts +0 -87
  47. package/src/algebra/__tests__/exec-rest.test.ts +0 -55
  48. package/src/algebra/__tests__/exec-spread-forof.test.ts +0 -85
  49. package/src/algebra/__tests__/exec-static-computed.test.ts +0 -61
  50. package/src/algebra/__tests__/exec-switch.test.ts +0 -74
  51. package/src/algebra/__tests__/exec-trycatch.test.ts +0 -71
  52. package/src/algebra/__tests__/fn-fp-memo.test.ts +0 -166
  53. package/src/algebra/__tests__/fn-fp-multidecl.test.ts +0 -49
  54. package/src/algebra/__tests__/format.test.ts +0 -34
  55. package/src/algebra/__tests__/generalize-memo.test.ts +0 -285
  56. package/src/algebra/__tests__/generalize.test.ts +0 -113
  57. package/src/algebra/__tests__/hash-source.test.ts +0 -19
  58. package/src/algebra/__tests__/hof.test.ts +0 -80
  59. package/src/algebra/__tests__/inlay.test.ts +0 -30
  60. package/src/algebra/__tests__/language.test.ts +0 -77
  61. package/src/algebra/__tests__/leq.test.ts +0 -109
  62. package/src/algebra/__tests__/load-deps-fp-memo.test.ts +0 -132
  63. package/src/algebra/__tests__/methods.test.ts +0 -37
  64. package/src/algebra/__tests__/node-types.test.ts +0 -26
  65. package/src/algebra/__tests__/nudo-constraints.ts +0 -46
  66. package/src/algebra/__tests__/objects.test.ts +0 -117
  67. package/src/algebra/__tests__/parse-source-cache.test.ts +0 -42
  68. package/src/algebra/__tests__/refine-import.test.ts +0 -109
  69. package/src/algebra/__tests__/stable-source-key-block.test.ts +0 -23
  70. package/src/algebra/__tests__/stable-source-key.test.ts +0 -31
  71. package/src/algebra/__tests__/surface.test.ts +0 -41
  72. package/src/algebra/__tests__/this-inherit.test.ts +0 -130
  73. package/src/algebra/abs-fn.ts +0 -49
  74. package/src/algebra/abs-modules.ts +0 -139
  75. package/src/algebra/abs.ts +0 -206
  76. package/src/algebra/arithmetic.ts +0 -691
  77. package/src/algebra/ast-eval.ts +0 -1763
  78. package/src/algebra/bridge.ts +0 -350
  79. package/src/algebra/builtins.ts +0 -373
  80. package/src/algebra/check-report.ts +0 -150
  81. package/src/algebra/check.ts +0 -1867
  82. package/src/algebra/constraint.ts +0 -304
  83. package/src/algebra/denote.ts +0 -166
  84. package/src/algebra/diagnostics.ts +0 -210
  85. package/src/algebra/exec/call.ts +0 -29
  86. package/src/algebra/exec/calls.ts +0 -96
  87. package/src/algebra/exec/class-registry.ts +0 -29
  88. package/src/algebra/exec/class.ts +0 -329
  89. package/src/algebra/exec/index.ts +0 -6
  90. package/src/algebra/exec/member-diag.ts +0 -141
  91. package/src/algebra/exec/run.ts +0 -341
  92. package/src/algebra/exec/runtime.ts +0 -583
  93. package/src/algebra/exec/transpile.ts +0 -993
  94. package/src/algebra/fn-fp.ts +0 -294
  95. package/src/algebra/format.ts +0 -91
  96. package/src/algebra/generalize.ts +0 -776
  97. package/src/algebra/hash-source.ts +0 -27
  98. package/src/algebra/index.ts +0 -34
  99. package/src/algebra/inlay.ts +0 -198
  100. package/src/algebra/language.ts +0 -289
  101. package/src/algebra/leak.ts +0 -68
  102. package/src/algebra/leq.ts +0 -301
  103. package/src/algebra/load-deps-fp.ts +0 -97
  104. package/src/algebra/methods.ts +0 -128
  105. package/src/algebra/objects.ts +0 -251
  106. package/src/algebra/parse-source.ts +0 -64
  107. package/src/algebra/phi.ts +0 -42
  108. package/src/algebra/pred.ts +0 -395
  109. package/src/algebra/refine.ts +0 -227
  110. package/src/algebra/stable-source-key.ts +0 -81
  111. package/src/algebra/surface.ts +0 -206
  112. package/src/algebra/template.ts +0 -143
  113. package/src/algebra/term.ts +0 -119
  114. package/src/environment.ts +0 -74
  115. package/src/index.ts +0 -73
  116. package/src/mock-helpers.ts +0 -166
  117. package/src/ops.ts +0 -191
  118. package/src/refinements/range.ts +0 -86
  119. package/src/refinements/template-predicates.ts +0 -11
  120. package/src/refinements/template.ts +0 -176
  121. package/src/strip-types.ts +0 -236
  122. package/src/type-value.ts +0 -513
  123. package/tsconfig.json +0 -8
@@ -0,0 +1,911 @@
1
+ import { ImportDeclaration, File, Node, Expression } from '@babel/types';
2
+
3
+ /** 项(Term):抽象值的身份。字面量是项的特例。 */
4
+ type LiteralValue = string | number | boolean | null | undefined;
5
+ type Term = {
6
+ op: "lit";
7
+ value: LiteralValue;
8
+ } | {
9
+ op: "var";
10
+ id: string;
11
+ } | {
12
+ op: "app";
13
+ fn: string;
14
+ args: Term[];
15
+ };
16
+ declare const lit: (value: LiteralValue) => Term;
17
+ declare const v: (id: string) => Term;
18
+ declare const app: (fn: string, args: Term[]) => Term;
19
+ declare function termEquals(a: Term, b: Term): boolean;
20
+ declare function termToString(t: Term): string;
21
+ /** 常量折叠 + 简单代数化简 */
22
+ declare function simplifyTerm(t: Term): Term;
23
+
24
+ /** 约束(Pred):附着在项上的事实,可传播。 */
25
+
26
+ type PrimName = "number" | "string" | "boolean" | "bigint" | "symbol";
27
+ type Pred = {
28
+ op: "true";
29
+ } | {
30
+ op: "false";
31
+ } | {
32
+ op: "eq";
33
+ a: Term;
34
+ b: Term;
35
+ } | {
36
+ op: "ne";
37
+ a: Term;
38
+ b: Term;
39
+ } | {
40
+ op: "lt";
41
+ a: Term;
42
+ b: Term;
43
+ } | {
44
+ op: "le";
45
+ a: Term;
46
+ b: Term;
47
+ } | {
48
+ op: "gt";
49
+ a: Term;
50
+ b: Term;
51
+ } | {
52
+ op: "ge";
53
+ a: Term;
54
+ b: Term;
55
+ } | {
56
+ op: "and";
57
+ args: Pred[];
58
+ } | {
59
+ op: "or";
60
+ args: Pred[];
61
+ } | {
62
+ op: "not";
63
+ arg: Pred;
64
+ } | {
65
+ op: "typeof";
66
+ t: Term;
67
+ type: PrimName;
68
+ };
69
+ declare const pTrue: Pred;
70
+ declare const pFalse: Pred;
71
+ declare const eq: (a: Term, b: Term) => Pred;
72
+ declare const ne: (a: Term, b: Term) => Pred;
73
+ declare const lt: (a: Term, b: Term) => Pred;
74
+ declare const le: (a: Term, b: Term) => Pred;
75
+ declare const gt: (a: Term, b: Term) => Pred;
76
+ declare const ge: (a: Term, b: Term) => Pred;
77
+ declare const ptypeof: (t: Term, type: PrimName) => Pred;
78
+ declare function and(...preds: Pred[]): Pred;
79
+ declare function or(...preds: Pred[]): Pred;
80
+ declare function not(p: Pred): Pred;
81
+ declare function predEquals(a: Pred, b: Pred): boolean;
82
+ declare function predToString(p: Pred): string;
83
+ /** 把 pred 里的 Term 用 subst 替换(用于 bound 变量重命名等) */
84
+ declare function substPred(p: Pred, subst: (t: Term) => Term): Pred;
85
+ /** 收集 pred 中出现的自由变量 */
86
+ declare function predVars(p: Pred): Set<string>;
87
+ /** 约束环境 Φ:Pred 的合取 */
88
+ type Phi = Pred;
89
+ declare const emptyPhi: Phi;
90
+ declare const phiAnd: typeof and;
91
+ /** 简单蕴含:在区间/字面量可判定范围内判断 Φ ⊢ pred */
92
+ declare function implies(phi: Phi, pred: Pred): boolean;
93
+ /** 便捷:数字下界 */
94
+ declare function gtNum(term: Term, n: number): Pred;
95
+ declare function geNum(term: Term, n: number): Pred;
96
+ declare function ltNum(term: Term, n: number): Pred;
97
+ declare function leNum(term: Term, n: number): Pred;
98
+
99
+ /** 抽象值 Abs = 形状 × 项 × 约束 × 置信度 */
100
+
101
+ type Confidence = "exact" | "path" | "widened" | "mock" | "partial" | "opaque";
102
+ type Shape = {
103
+ k: "never";
104
+ }
105
+ /**
106
+ * any:JS 里可以是任意值(无约束参数)。
107
+ * 运算按真实 JS 语义取并集,不是「分析失败」。
108
+ */
109
+ | {
110
+ k: "any";
111
+ }
112
+ /** unknown:分析拿不到信息(求值失败/泄漏),不是「任意值」 */
113
+ | {
114
+ k: "unknown";
115
+ } | {
116
+ k: "prim";
117
+ type: PrimName;
118
+ } | {
119
+ k: "obj";
120
+ slots: Record<string, {
121
+ value: Abs;
122
+ optional?: boolean;
123
+ readonly?: boolean;
124
+ }>;
125
+ index?: {
126
+ key: Abs;
127
+ value: Abs;
128
+ };
129
+ open?: boolean;
130
+ } | {
131
+ k: "arr";
132
+ element: Abs;
133
+ } | {
134
+ k: "tuple";
135
+ elements: Abs[];
136
+ rest?: Abs;
137
+ } | {
138
+ k: "fn";
139
+ params: string[];
140
+ name?: string;
141
+ paramTypes?: Abs[];
142
+ returnType?: Abs;
143
+ } | {
144
+ k: "brand";
145
+ name: string;
146
+ shape: Abs;
147
+ } | {
148
+ k: "eff";
149
+ eff: "promise" | "generator";
150
+ inner: Abs;
151
+ } | {
152
+ k: "sum";
153
+ members: Abs[];
154
+ };
155
+ type Abs = {
156
+ shape: Shape;
157
+ term?: Term;
158
+ pred?: Pred;
159
+ conf: Confidence;
160
+ };
161
+ declare const never: Abs;
162
+ /** 分析无信息 */
163
+ declare const unknown: Abs;
164
+ /** 带 term 的 any(generalize type-var) */
165
+ declare function anyVar(id: string, conf?: Confidence): Abs;
166
+ declare function num(): Abs;
167
+ declare function str(): Abs;
168
+ declare function bool(): Abs;
169
+ declare function numLit(value: number): Abs;
170
+ declare function strLit(value: string): Abs;
171
+ declare function boolLit(value: boolean): Abs;
172
+ /** 带项的符号数,例如参数 x */
173
+ declare function numVar(id: string, pred?: Pred, conf?: Confidence): Abs;
174
+ declare function obj(slots: Record<string, {
175
+ value: Abs;
176
+ optional?: boolean;
177
+ }>): Abs;
178
+ declare function confJoin(a: Confidence, b: Confidence): Confidence;
179
+ declare function absToString(a: Abs): string;
180
+ declare function shapeToString(s: Shape): string;
181
+ /** 从 term 反推 prim shape */
182
+ declare function shapeOfTerm(t: Term): Shape;
183
+ /** 构造带项的结果 Abs;pred 相对 term */
184
+ declare function abs(shape: Shape, term: Term | undefined, pred: Pred | undefined, conf: Confidence): Abs;
185
+ declare function isNumPrim(a: Abs): boolean;
186
+ declare function isStrPrim(a: Abs): boolean;
187
+ /** 置信度:字面量全确定 */
188
+ declare function isExactLit(a: Abs): boolean;
189
+ declare function litValue(a: Abs): LiteralValue | undefined;
190
+
191
+ /**
192
+ * 项(Term)防爆炸:深度/宽度阈值 → leak 为新鲜 var + 等式约束。
193
+ */
194
+
195
+ type LeakBudget = {
196
+ maxDepth: number;
197
+ maxNodes: number;
198
+ };
199
+ declare const defaultLeakBudget: LeakBudget;
200
+ declare function termDepth(t: Term): number;
201
+ declare function termNodes(t: Term): number;
202
+ declare function exceedsBudget(t: Term, budget?: LeakBudget): boolean;
203
+ declare function resetLeakCounter(): void;
204
+ /**
205
+ * 若项超预算,替换为新鲜变量,并返回附加等式 pred:fresh = originalTerm。
206
+ * 未超预算则原样返回。
207
+ */
208
+ declare function maybeLeak(a: Abs, budget?: LeakBudget, label?: string): Abs;
209
+ /**
210
+ * 批量:在算术结果上应用 leak。
211
+ */
212
+ declare function leakIfNeeded(a: Abs, budget?: LeakBudget, label?: string): Abs;
213
+
214
+ /**
215
+ * HOF 关系 Abs:无 body 的外延关系(paramTypes → returnType)的判定、
216
+ * α 替换与应用。类型变量仍是 term var;关系仍是 fn 形状上的外延槽。
217
+ */
218
+
219
+ /**
220
+ * 关系来源标记:P4 豁免与 diagnostics 依赖它,禁止隐式猜。
221
+ * - promote:使用驱动提升(generalize symbolic / instantiate 局部)
222
+ * - refine:@nudo:refine 契约
223
+ * - relationFn:harvest/mock/测试直接写入 fnRels 时的预留来源(P4 error 路径)
224
+ */
225
+ type RelSource = "promote" | "refine" | "relationFn";
226
+ type HofSite = {
227
+ /** 形参名(函数形参) */
228
+ param: string;
229
+ /** 输入侧 term:实参的 term(element 的 var/lit/app);map 1 个、reduce 2 个 */
230
+ argTerms: Term[];
231
+ /** 输出侧:归纳出的返回 Abs */
232
+ result: Abs;
233
+ /** 源位置,便于 diagnostics */
234
+ loc?: {
235
+ line: number;
236
+ column: number;
237
+ };
238
+ };
239
+ /**
240
+ * run 局部 collector(与 Phi 并列,不进 Φ 合并)。
241
+ * symbolic 一次跑:安装并沉淀到 PolyFn;instantiate 重跑:装 throwaway
242
+ * 副本——形状提升仍生效,结果不写回共享状态(见 generalize.ts run())。
243
+ */
244
+ type HofCollectCtx = {
245
+ /** 本次归纳的形参名集合(身份判定用) */
246
+ paramNames: ReadonlySet<string>;
247
+ /** 本次 typeParams 的 α id 集合(term 复用白名单) */
248
+ alphaIds: Set<string>;
249
+ /** fresh α 计数 */
250
+ freshSeq: {
251
+ n: number;
252
+ };
253
+ sites: HofSite[];
254
+ fnRels: Map<string, {
255
+ abs: Abs;
256
+ source: RelSource;
257
+ }>;
258
+ entryShapes: Map<string, {
259
+ abs: Abs;
260
+ source: RelSource;
261
+ }>;
262
+ };
263
+ declare function createHofCollectCtx(paramNames: ReadonlySet<string>, alphaIds: Iterable<string>): HofCollectCtx;
264
+ /**
265
+ * 仅当 term 是 var 且 id ∈ alphaIds(本次 typeParams)时复用;否则 fresh α。
266
+ * 绝不把调用点具体值/字面量冻进关系。
267
+ */
268
+ declare function alphaOf(absOrTerm: Abs | Term | undefined, ctx: HofCollectCtx): Term;
269
+ /** 共享输出变量 B:${param}(§5.1 P2 钉死) */
270
+ declare function betaOf(param: string): Term;
271
+ /**
272
+ * 提升写入载体:替换 env.vars map 项,禁止 mutate 共享 Abs。
273
+ * arrival-first:已有 fn/arr 形状 → 拒绝新观测。
274
+ * 返回是否真正写入。
275
+ */
276
+ declare function promoteParamShape(env: AstEnv, param: string, promotedShape: Shape, opts?: {
277
+ loc?: {
278
+ line: number;
279
+ column: number;
280
+ };
281
+ recordSite?: boolean;
282
+ }): boolean;
283
+ /**
284
+ * 挂载点①:方法派发 miss。receiver 是形参 Identifier 且 shape 为 any/未知,
285
+ * 方法名为 filter/map/reduce/flatMap → 提升为 arr(自身 var)。
286
+ */
287
+ declare function tryPromoteReceiverAsArr(env: AstEnv, receiverName: string, method: string, loc?: {
288
+ line: number;
289
+ column: number;
290
+ }): Abs | undefined;
291
+ /**
292
+ * for-of 迭代对象提升(applyEach 型):`for (const x of items)`,
293
+ * items 为形参且仍是 any/unknown → arr(自身 var)。不依赖方法名。
294
+ */
295
+ declare function tryPromoteForOfIteratee(env: AstEnv, iterateeName: string, loc?: {
296
+ line: number;
297
+ column: number;
298
+ }): Abs | undefined;
299
+ /**
300
+ * 挂载点②:CallExpression callee = 形参 Identifier 直接调用 p(x) / p(a,b)。
301
+ * 提升为 fn(paramTypes=[αOf(args)], returnType=B:param)。
302
+ */
303
+ declare function tryPromoteDirectCall(env: AstEnv, calleeName: string, args: Abs[], loc?: {
304
+ line: number;
305
+ column: number;
306
+ }): Abs | undefined;
307
+ /**
308
+ * 挂载点③:HOF 回调实参。回调是 Identifier ∈ paramNames 且尚未有 fn 形状。
309
+ * 按方法名提升:map/flatMap → fn([αOf(el)], B:param);filter → fn([αOf(el)], bool);
310
+ * reduce → fn([αOf(init), αOf(el)], B:param)。
311
+ */
312
+ declare function tryPromoteHofCallback(env: AstEnv, cbName: string, method: string, argAbses: Abs[], loc?: {
313
+ line: number;
314
+ column: number;
315
+ }): Abs | undefined;
316
+ /** deep-ish copy for snapshot(新对象,不是 env.vars 同一引用) */
317
+ declare function snapshotAbs(a: Abs): Abs;
318
+ /**
319
+ * 「有可用外延签名」判定:唯一权威定义。
320
+ *
321
+ * 名实说明:isRelFn **不要求** term 是 var。完全单态的具体签名
322
+ * (paramTypes=[number], returnType=string)同样满足——map 有槽就用。
323
+ * 多态(term=var)只是其中一种形态;名字里的 Rel 指「关系槽可用」。
324
+ *
325
+ * 收紧条件——仅有 returnType 而 paramTypes 与 arity 不对齐时,不算 rel,
326
+ * 防止半截签名在 map 里冒充关系。
327
+ */
328
+ declare function isRelFn(a: Abs | undefined | null): boolean;
329
+ /**
330
+ * pred 三条规则:
331
+ * 1. var ∈ map + 实参有 term → 换 term,可归约则归约,否则残余保留
332
+ * 2. var ∈ map + 实参无 term → pred → true(conf 由调用方降级)
333
+ * 3. var ∉ map(自由 α)→ 原样保留
334
+ */
335
+ declare function substPredAbs(p: Pred, map: ReadonlyMap<string, Abs>): {
336
+ pred: Pred;
337
+ dropped: boolean;
338
+ };
339
+ /**
340
+ * α 替换:map 的 key 是 term var id,value 是替换 Abs。
341
+ * var ∉ map 原样保留(含自由 α 上的 term/pred)。
342
+ */
343
+ declare function substAbs(a: Abs, map: ReadonlyMap<string, Abs>): Abs;
344
+ /**
345
+ * relation-only / isRelFn 的应用:按 paramTypes 做 α 替换得到 returnType。
346
+ * impl.relation 槽优先于 shape.returnType。重复 α 先绑定保留。
347
+ */
348
+ declare function instantiateReturn(fn: Abs, args: Abs[]): Abs;
349
+ /**
350
+ * 回调统一入口(单点定义)。A–F + sum:
351
+ * A Node inline | B apply | C body | D relation | E isRelFn | F unknown
352
+ *
353
+ * 实现委托 ast-eval 的 applyAbsFn(已含 sum / D / E / body 优先)。
354
+ * Identifier 解析层:env.vars 有 Abs → B–E;env.fns 有 → callFunction;否则 unknown。
355
+ *
356
+ * 为避免 hof ↔ ast-eval 循环依赖,本函数由宿主在运行时绑定。
357
+ *
358
+ * 依赖说明:宿主在 `ast-eval.ts` 模块加载时注册(副作用)。
359
+ * 只 import hof.ts 而未加载 ast-eval 时,fallback 仅认 relation/isRelFn。
360
+ * 与 §5.1 的「禁止全局 collector」不同——这里是无状态委托钩子,不是 run 局部状态。
361
+ */
362
+ type ApplyCallbackHost = (cb: Abs | {
363
+ type: string;
364
+ }, args: Abs[], env: unknown, phi: unknown, budget: unknown) => Abs;
365
+ /**
366
+ * ast-eval 模块加载时注册(副作用)。
367
+ * 必须经 `ast-eval.ts`(或其依赖方:exec/call、exec/class、generalize)加载,
368
+ * 才能启用 Identifier/env.fns/inline body 路径;只 import hof.ts 时 fallback
369
+ * 仅认 relation/isRelFn。勿在多份 ast-eval 实例下各写各的——双包/双副本会覆盖。
370
+ */
371
+ declare function setApplyCallbackHost(fn: ApplyCallbackHost): void;
372
+ declare function applyCallbackAbs(cb: Abs | {
373
+ type: string;
374
+ }, args: Abs[], env: unknown, phi: unknown, budget: unknown): Abs;
375
+ /** undefined 值的统一 Abs 表示(forEach/find 等) */
376
+ declare function undefAbs(): Abs;
377
+ /**
378
+ * map 元素投影:body 在符号实参上跑出 unknown 时,
379
+ * 用 shape.returnType 槽,conf 由调用方按 path/partial 处理。
380
+ * rel 回调不会走到这里(instantiateReturn 已给出结果)。
381
+ */
382
+ declare function mapElementFallback(cbAbs: Abs | undefined, elem: Abs, out: Abs): Abs;
383
+ /**
384
+ * flatMap 统一结果:展开后的元素 join 成 arr(γ)。
385
+ * JS flatMap 永远返回 Array;双路径共用此投影,禁止一边 tuple 一边 arr。
386
+ * 同 term 元素 first-wins(joinAbs 会丢 β 身份,见 design §5.1)。
387
+ */
388
+ declare function projectFlatMapResult(arrConf: Confidence, mapped: Abs[]): Abs;
389
+ /** 从 map/filter/reduce 回调实参里取出 Abs(Identifier 已绑定或直接 Abs) */
390
+ declare function asAbs(v: unknown): Abs | undefined;
391
+
392
+ /**
393
+ * Abs 模块面(无 fs):import 绑定 + export 收集。
394
+ * 解析路径/读文件在 host;core 只吃「specifier → 导出表」。
395
+ */
396
+
397
+ type AbsModuleExports = {
398
+ named: Record<string, Abs>;
399
+ default?: Abs;
400
+ };
401
+ /** 把 import 说明符绑定进 env(宿主已求值依赖) */
402
+ declare function bindImports(node: ImportDeclaration, env: AstEnv, modules: Record<string, AbsModuleExports>): void;
403
+ /**
404
+ * 从已求值 env + AST 收集 ESM 导出。
405
+ * 支持:export function/const、export { a, b as c }、export default(具名)、
406
+ * 以及带 source 的 re-export(`export { a } from "mod"` / `export * from "mod"`——
407
+ * 需 host 传入已求值 modules)。
408
+ */
409
+ declare function collectAbsExports(file: File, env: AstEnv, modules?: Record<string, AbsModuleExports>): AbsModuleExports;
410
+
411
+ /**
412
+ * Babel AST 抽象求值:把「类型即计算」接到真实 JS 源码。
413
+ * 支持表达式、函数声明/箭头、return、if、const/let、块作用域、类、循环。
414
+ */
415
+
416
+ type AstEnv = {
417
+ vars: Map<string, Abs>;
418
+ /** 用户函数:name → { params, body } */
419
+ fns: Map<string, {
420
+ params: string[];
421
+ body: Node;
422
+ async?: boolean;
423
+ kind?: string;
424
+ }>;
425
+ /** class 表(旁路,withVar 必须保留) */
426
+ classes?: Map<string, unknown>;
427
+ /** 当前正在求值的方法所属类名(super.x() 从它的父类派发) */
428
+ currentOwner?: string;
429
+ /** P2:generalize symbolic 跑的 HOF collector(run 局部,不进 Φ) */
430
+ hofCollect?: HofCollectCtx;
431
+ };
432
+ declare function emptyEnv(): AstEnv;
433
+ declare function withVar(env: AstEnv, name: string, value: Abs): AstEnv;
434
+ type EvalOptions = {
435
+ phi?: Phi;
436
+ budget?: LeakBudget;
437
+ /** 预解析 AST(check 等批量场景避免重复 parse) */
438
+ file?: File;
439
+ /** host 已求值的相对依赖导出表 */
440
+ modules?: Record<string, AbsModuleExports>;
441
+ };
442
+ declare const MAX_CALL_DEPTH = 64;
443
+ declare const MAX_TOTAL_CALLS = 200000;
444
+ /** 宿主入口(evalProgramAbs / analyzeFn / check)前重置 */
445
+ declare function resetAbsCallBudget(): void;
446
+ /** 记录被截断的递归(service 可映射为 nudo:recursion-truncated) */
447
+ declare function setAbsTruncationCollector(collector: ((fnLabel: string) => void) | null): void;
448
+ /** Abs 域调用记录(自包含程序可不经 TypeValue evaluator) */
449
+ type AbsCallRecord = {
450
+ fnName: string;
451
+ args: Abs[];
452
+ result: Abs;
453
+ callLoc?: {
454
+ line: number;
455
+ column: number;
456
+ };
457
+ threw?: boolean;
458
+ };
459
+ declare function setAbsCallCollector(collector: ((r: AbsCallRecord) => void) | null): void;
460
+ declare function setAbsNodeCollector(collector: ((node: Node, value: Abs) => void) | null): void;
461
+ /** 赋值记录:结构可赋值检查用 */
462
+ type AbsAssignRecord = {
463
+ name: string;
464
+ prev?: Abs;
465
+ next: Abs;
466
+ line?: number;
467
+ column?: number;
468
+ };
469
+ declare function setAbsAssignCollector(collector: ((r: AbsAssignRecord) => void) | null): void;
470
+ type EvalResult = {
471
+ value: Abs;
472
+ phi: Phi;
473
+ env: AstEnv;
474
+ /** 函数已通过 return 跳出,块内后续语句不可达 */
475
+ returned?: boolean;
476
+ /** break 跳出最近循环 */
477
+ brk?: boolean;
478
+ /** continue 进入下一轮 */
479
+ cont?: boolean;
480
+ /** throw 了 value(未捕获时向上传播) */
481
+ threw?: boolean;
482
+ /**
483
+ * if 无 else 且 consequent 已 return/throw:真分支已产出 value,
484
+ * 假分支 fall-through 仍可能走后续语句。evalBlock 需与后续结果 join。
485
+ */
486
+ partialReturn?: boolean;
487
+ };
488
+ /**
489
+ * 分析一段 JS 源码。
490
+ * 若含多个顶层函数声明,先注册全部,再对 `main` 或最后一个有调用的函数求值。
491
+ * 更简单:提供 `analyzeFunction(source, fnName, args)`。
492
+ */
493
+ declare function evalSource(source: string, entry: {
494
+ fn: string;
495
+ args: Abs[];
496
+ }, opts?: EvalOptions): EvalResult;
497
+ declare function callFunction(env: AstEnv, name: string, args: Abs[], phi?: Phi, budget?: LeakBudget): Abs;
498
+ /**
499
+ * 在 this=receiver 下求值方法体。
500
+ * constructor 无显式 return 时返回更新后的 this(字段写入已并入 env)。
501
+ */
502
+ declare function evalMethodBody(method: {
503
+ params: string[];
504
+ body: Node;
505
+ async?: boolean;
506
+ kind?: string;
507
+ }, args: Abs[], thisVal: Abs, env: AstEnv, phi?: Phi, budget?: LeakBudget,
508
+ /** 方法定义所在类名(用于 super 派发) */
509
+ ownerClass?: string): Abs;
510
+ /** 对外入口:求值并记入节点表(Map<Node, Abs> 由 collector 消费) */
511
+ declare function evalNode(node: Node, env: AstEnv, phi: Phi, budget: LeakBudget): EvalResult;
512
+ /**
513
+ * 应用 Abs 一等函数。统一顺序:apply → body → relation → isRelFn。
514
+ * 调用门须扩为 `getFnImpl || isRelFn`,否则 E 路径永远进不来。
515
+ */
516
+ declare function applyAbsFn(fnVal: Abs, args: Abs[], env: AstEnv, phi: Phi, budget: LeakBudget): Abs;
517
+ /**
518
+ * 从源码分析指定函数在给定实参下的抽象结果。
519
+ *
520
+ * @example
521
+ * analyzeFn(`
522
+ * const add = (a, b) => a + b;
523
+ * function scale(x) { return add(x, 1); }
524
+ * `, "scale", [numVar("x", gtNum(v("x"), 0))], gtNum(v("x"), 0))
525
+ */
526
+ declare function analyzeFn(source: string, fnName: string, args: Abs[], phi?: Phi, budget?: LeakBudget, file?: File, modules?: Record<string, AbsModuleExports>): Abs;
527
+ /**
528
+ * 程序级 Abs 求值:注册全部顶层函数/class,再顺序执行语句。
529
+ * 返回最终 env(vars 含导出绑定)。TypeValue 仅在调用方 bridge 时出现。
530
+ *
531
+ * seedVars / seedFns:host 注入(@nudo:mock 等)在求值前绑定。
532
+ * modules:host 已求值的依赖导出表(specifier → AbsModuleExports)。
533
+ */
534
+ declare function evalProgramAbs(source: string, opts?: EvalOptions & {
535
+ seedVars?: Record<string, Abs>;
536
+ seedFns?: Record<string, {
537
+ params: string[];
538
+ body: Node;
539
+ async?: boolean;
540
+ }>;
541
+ modules?: Record<string, AbsModuleExports>;
542
+ }): {
543
+ env: AstEnv;
544
+ last: Abs;
545
+ phi: Phi;
546
+ };
547
+ /**
548
+ * 收集整文件的节点 → Abs 表(LSP 无损信息源)。
549
+ * 自包含源码上一次 evalProgramAbs 即可;失败返回空表。
550
+ */
551
+ declare function collectAbsNodeTypes(source: string, opts?: EvalOptions & {
552
+ seedVars?: Record<string, Abs>;
553
+ seedFns?: Record<string, {
554
+ params: string[];
555
+ body: Node;
556
+ async?: boolean;
557
+ }>;
558
+ }): Map<Node, Abs>;
559
+ /** 按 loc 找最紧的节点 Abs(hover 用) */
560
+ declare function findAbsAtPosition(nodeTypes: Map<Node, Abs>, line: number, column: number): Abs | undefined;
561
+
562
+ /**
563
+ * B 路径运行时:transpile 后的程序在 Node 上执行时,值就是 Abs。
564
+ * 与 AST 解释器语义同构;TypeValue 不再是求值载体。
565
+ */
566
+
567
+ declare function currentExecPhi(): Phi;
568
+ declare function withExecPhi<T>(p: Phi, body: () => T): T;
569
+ declare function $add(a: Abs, b: Abs): Abs;
570
+ declare function $sub(a: Abs, b: Abs): Abs;
571
+ declare function $mul(a: Abs, b: Abs): Abs;
572
+ declare function $div(a: Abs, b: Abs): Abs;
573
+ declare function $mod(a: Abs, b: Abs): Abs;
574
+ declare function $neg(a: Abs): Abs;
575
+ declare function $typeof(a: Abs): Abs;
576
+ declare function $not(a: Abs): Abs;
577
+ declare function $eq(a: Abs, b: Abs): Abs;
578
+ declare function $ne(a: Abs, b: Abs): Abs;
579
+ declare function $lt(a: Abs, b: Abs): Abs;
580
+ declare function $le(a: Abs, b: Abs): Abs;
581
+ declare function $gt(a: Abs, b: Abs): Abs;
582
+ declare function $ge(a: Abs, b: Abs): Abs;
583
+ declare function $join(a: Abs, b: Abs): Abs;
584
+ /**
585
+ * transpile 泄漏的 JS 函数值 → 一等 fn Abs。
586
+ * B 路径把函数声明/表达式编译成真实 JS 函数;它们流进对象槽、
587
+ * 元组、join 等 Abs 结构时不能裸存——下游(bridge/leq/join)读 `.shape`。
588
+ * 参数名无法从运行时函数恢复(用 fn.length → argN,与 analyzer 的
589
+ * extractParamNames 回退口径一致);带真实参数名走 $fnVal(transpile 侧)。
590
+ */
591
+ declare function asAbsVal(v: unknown): Abs;
592
+ /** 函数表达式 → 一等 fn Abs(transpile 侧带真实参数名;异步 body 包 $async) */
593
+ declare function $fnVal(params: string[], impl: (...args: Abs[]) => Abs): Abs;
594
+ /** 字面量 → Abs(transpile 侧数字/字符串/布尔/null/undefined) */
595
+ declare function $lit(v: unknown): Abs;
596
+ /** JS 真值:字面量按 Boolean(v);对象形恒真;不可判 → undefined */
597
+ declare function litTruth(a: Abs): boolean | undefined;
598
+ declare function isDefinitelyTrue(a: Abs): boolean;
599
+ declare function isDefinitelyFalse(a: Abs): boolean;
600
+ /**
601
+ * if:两侧都探索(抽象条件),具体条件短路。
602
+ */
603
+ declare function $fork(test: Abs, consequent: () => Abs, alternate?: () => Abs): Abs;
604
+ declare const DEFAULT_MAX_LOOP_ITERS = 8;
605
+ /**
606
+ * for 的惰性展开:生成器只负责「按上限吐状态」。
607
+ * 抽象条件无法诚实终止——消费者必须自带 maxIters。
608
+ */
609
+ declare function $forIter(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, body: (s: Abs) => Abs, maxIters?: number): Generator<{
610
+ state: Abs;
611
+ test: Abs;
612
+ afterBody: Abs;
613
+ }, void, void>;
614
+ /**
615
+ * 有界 for:unroll ≤ maxIters,每步「可能退出」的态 join;
616
+ * 相邻态 leq 视为不动点提前停。
617
+ */
618
+ declare function $for(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, body: (s: Abs) => Abs, maxIters?: number): Abs;
619
+ /** 数组字面量 → Abs tuple(长度已知) */
620
+ declare function $arr(items: Abs[]): Abs;
621
+ /** 下标读 a[i];字面量 i 走 tuple 精确投影,否则并所有元素;string[i] → 单字符 */
622
+ declare function $idx(a: Abs, i: Abs): Abs;
623
+ /** 下标写 a[i]=v → 新 tuple(越界写按 JS 语义增长,空洞为 undefined) */
624
+ declare function $idxSet(a: Abs, i: Abs, value: Abs): Abs;
625
+ /** 数组/字符串长度 */
626
+ declare function $len(a: Abs): Abs;
627
+ /** 对象字面量 → Abs obj */
628
+ declare function $obj(slots: Record<string, Abs>): Abs;
629
+ /** 对象展开 { ...a, b } */
630
+ declare function $spread(a: Abs, b: Abs): Abs;
631
+ /** 数组连接 [...a, ...b] / [...a, x] */
632
+ declare function $concat(a: Abs, b: Abs): Abs;
633
+ /** 元素列表(tuple 展开;arr 抽象) */
634
+ declare function $elems(a: Abs): Abs[];
635
+ /**
636
+ * for-of:对 iterable 每个元素跑 body;有界展开。
637
+ * body(item, i) 可返回 void;状态由外部 JS 变量承接。
638
+ */
639
+ declare function $forOf(iterable: Abs, body: (item: Abs, index: Abs) => void, maxIters?: number): void;
640
+ /**
641
+ * 命名空间身份表:transpile 后 `Math.max(0, x)` 的接收者是宿主 JS 全局对象
642
+ * (非 Abs)。按对象身份识别命名空间,路由到 Abs builtin 表。
643
+ */
644
+ declare function namespaceNameOf(v: unknown): string | undefined;
645
+ /** 正则字面量 → RegExp brand(source/flags 进 slots,供 exec/test 精确执行) */
646
+ declare function $regex(pattern: string, flags?: string): Abs;
647
+ /** 成员读:obj.slots[key];缺失 → undefined 字面量;brand 解包内层 */
648
+ declare function $get(o: Abs, key: string, opts?: {
649
+ silent?: boolean;
650
+ }): Abs;
651
+ /** 成员写:返回新 obj/brand(不可变更新) */
652
+ declare function $set(o: Abs, key: string, value: Abs): Abs;
653
+ /**
654
+ * 有界 while:state 线程穿 test/step(与 $for 同折叠语义)。
655
+ * 抽象条件无法诚实终止——必须 maxIters。
656
+ */
657
+ declare function $while(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, maxIters?: number): Abs;
658
+ /**
659
+ * 顺序 while(具体/可变闭包):body 内对 JS 变量赋值。
660
+ * 适合 transpile `let i; while (…) { i = … }`;抽象条件仍靠预算截断,
661
+ * 不保证 exit-join 健全——健全路径用 $while/$for + 状态对象。
662
+ */
663
+ declare function $whileSeq(test: () => Abs, body: () => void, maxIters?: number): void;
664
+ /** B 路径 throw 载荷:携带 Abs 抛出值 */
665
+ declare class NudoThrow extends Error {
666
+ readonly absValue: Abs;
667
+ constructor(absValue: Abs);
668
+ }
669
+ /** transpile `throw x` → `$throw(x)` */
670
+ declare function $throw(v: Abs): never;
671
+ declare function isNudoThrow(e: unknown): e is NudoThrow;
672
+ /** catch 参数:从 NudoThrow 取出 Abs,否则 unknown */
673
+ declare function $catchVal(e: unknown): Abs;
674
+ /**
675
+ * async 函数体包进 thunk,返回值经 wrapPromise。
676
+ */
677
+ declare function $async(thunk: () => Abs): Abs;
678
+ /** await → 解包 eff("promise") */
679
+ declare function $await(v: Abs): Abs;
680
+ /** async 直接 return 的 coerce */
681
+ declare function $asyncReturn(v: Abs): Abs;
682
+ /** function* 体:收集所有 yield 值为 tuple Abs */
683
+ declare function $gen(body: () => void): Abs;
684
+ /** yield v:压入当前生成器收集器;表达式值用 unknown */
685
+ declare function $yield(v: Abs): Abs;
686
+ /**
687
+ * switch:具体 disc 选中匹配 case;抽象 disc 并所有分支。
688
+ */
689
+ declare function $switch(disc: Abs, cases: Array<{
690
+ test: Abs;
691
+ run: () => Abs;
692
+ }>, dflt?: () => Abs): Abs;
693
+
694
+ /**
695
+ * B 路径 transpile:JS AST → 可在 Node 上执行的抽象值程序(源码字符串)。
696
+ * 运算符改为 $add/$sub/…;if 改为 $fork;for 改为 $for。
697
+ * 值类型是 Abs;副作用与模块仍由 host mock/注入。
698
+ */
699
+
700
+ type TranspileOptions = {
701
+ /** 运行时 import 说明符 */
702
+ runtimeImport?: string;
703
+ maxLoopIters?: number;
704
+ /** 方法体内 this 的绑定名(transpile class 时注入) */
705
+ thisParam?: string;
706
+ /** 当前类名(super 派发用) */
707
+ className?: string;
708
+ /** 原始源码(@nudo:replace 按节点文本匹配) */
709
+ source?: string;
710
+ /** 替换表:归一化目标文本 → 注入变量名;可选语句范围 */
711
+ replacements?: Array<{
712
+ target: string;
713
+ varName: string;
714
+ /** 仅该语句范围内生效(1-based 行) */
715
+ stmtStart?: number;
716
+ stmtEnd?: number;
717
+ }>;
718
+ /** @nudo:as:覆盖紧随语句的 init / return */
719
+ asOverrides?: Array<{
720
+ varName: string;
721
+ stmtStart: number;
722
+ stmtEnd: number;
723
+ }>;
724
+ };
725
+ declare function transpileSource(source: string, opts?: TranspileOptions): string;
726
+ declare function transpileFile(file: File, opts?: TranspileOptions): string;
727
+ declare function transpileExpression(expr: Expression, opts?: TranspileOptions): string;
728
+ /** 解析 + transpile */
729
+ declare function transpile(source: string, opts?: TranspileOptions): string;
730
+
731
+ /**
732
+ * 调用 Abs 一等函数(absFunction impl)或 mock apply。
733
+ * 供 B 路径 import 绑定包装:`(...args) => $call(absFn, args)`。
734
+ *
735
+ * 统一顺序:apply → body → relation → isRelFn(委托 applyAbsFn)。
736
+ * 行为对齐说明(与旧 $call 的差异,均属刻意):
737
+ * 1. 带 body 的函数也进 call-budget(与 ast-eval 同轨;递归会 truncated 而非爆栈)
738
+ * 2. body 抛错 → never(applyAbsFn 内恢复,不返回中间值)
739
+ * 3. 无 impl 时 isRelFn 可走 E 路径(旧版恒 unknown)
740
+ */
741
+
742
+ declare function $call(fn: Abs, args: Abs[]): Abs;
743
+
744
+ /**
745
+ * B class 规格表(无 call/ast-eval 依赖,避免循环)。
746
+ * Abs-eval registerClassDecl 与 transpile $class 共用。
747
+ */
748
+
749
+ type BClassSpec = {
750
+ name: string;
751
+ superName?: string;
752
+ ctor?: (thisVal: Abs, ...args: Abs[]) => Abs;
753
+ methods?: Record<string, (thisVal: Abs, ...args: Abs[]) => Abs>;
754
+ staticMethods?: Record<string, (...args: Abs[]) => Abs>;
755
+ statics?: Record<string, Abs>;
756
+ };
757
+ declare function registerBClass(spec: BClassSpec): void;
758
+ declare function getBClass(name: string): BClassSpec | undefined;
759
+ declare function clearBClasses(): void;
760
+
761
+ /**
762
+ * B 路径 class:brand 实例 + ctor/method 闭包 + 继承链。
763
+ * 方法内 this 由 transpile 改写为 thisVal 参数。
764
+ */
765
+
766
+ /** 定义类 → 可 new 的 Abs(brand 标记;静态字段挂在 slots) */
767
+ declare function $class(name: string, spec: Omit<BClassSpec, "name"> & {
768
+ extends?: string;
769
+ }): Abs;
770
+ /** new C(...) → 空 brand 实例 + ctor 写字段;非类构造走 impl/$call */
771
+ declare function $new(cls: Abs | ((...a: unknown[]) => unknown), args: Abs[]): Abs;
772
+ /**
773
+ * super(...):父类构造写入字段(this 保持子类 brand)。
774
+ * transpile: super(a,b) → __this = $super(__this, "Child", [a,b])
775
+ */
776
+ declare function $super(thisVal: Abs, childName: string, args: Abs[]): Abs;
777
+ /** 实例方法调用:沿继承链;类 Abs 上回落 staticMethods;obj 上回落属性函数 */
778
+ declare function $invoke(thisVal: Abs, method: string, args: Abs[], loc?: [number, number]): Abs;
779
+ /** super.method():从父类起找(跳过自身覆盖) */
780
+ declare function $invokeSuper(thisVal: Abs, childName: string, method: string, args: Abs[]): Abs;
781
+ declare function $thisGet(thisVal: Abs, key: string): Abs;
782
+ declare function $thisSet(thisVal: Abs, key: string, value: Abs): Abs;
783
+ /** 解构默认值:undefined 时用 default */
784
+ declare function $orDefault(v: Abs, dflt: () => Abs): Abs;
785
+ /** 可选链 a?.b:nullish 短路为 undefined 字面量 */
786
+ declare function $optionalGet(o: Abs, key: string): Abs;
787
+ /** 可选链 a?.m():nullish 短路为 undefined */
788
+ declare function $optionalInvoke(thisVal: Abs, method: string, args: Abs[]): Abs;
789
+ /** 静态方法:cls.staticMethod(args) */
790
+ declare function $staticInvoke(cls: Abs, method: string, args: Abs[]): Abs;
791
+ /** 计算属性写:o[kAbs] = v */
792
+ declare function $setKey(o: Abs, key: Abs, value: Abs): Abs;
793
+
794
+ /**
795
+ * 成员缺失诊断(B 路径 + Abs ast-eval 共用)。
796
+ * 无 $call / transpile 依赖,避免 ast-eval ↔ calls 循环。
797
+ */
798
+
799
+ type BMemberDiag = {
800
+ kind: "method" | "property";
801
+ name: string;
802
+ /** 接收者 prim 类型名,或 "unknown" */
803
+ receiver: string;
804
+ line?: number;
805
+ column?: number;
806
+ /** 调用点来源(provenance):实参字面量 loc 优先,否则最近 $callNamed loc */
807
+ origin?: {
808
+ line: number;
809
+ column: number;
810
+ };
811
+ };
812
+ /** 给实参 Abs 打 provenance(调用点参数字面量) */
813
+ declare function tagAbsOrigin(a: Abs, loc: {
814
+ line: number;
815
+ column: number;
816
+ }): void;
817
+ declare function getAbsOrigin(a: Abs | undefined): {
818
+ line: number;
819
+ column: number;
820
+ } | undefined;
821
+ declare function setMemberDiagCollector(c: ((d: BMemberDiag) => void) | null): void;
822
+ declare function recordMemberDiag(d: BMemberDiag): void;
823
+ /**
824
+ * prim 接收者上的未知成员 → 诊断。
825
+ * 返回 true 表示确定缺失(number 上任意方法;string 上表外方法)。
826
+ */
827
+ declare function notePrimMemberMissing(recv: Abs | undefined, name: string, kind: "method" | "property", loc?: [number, number]): boolean;
828
+ /**
829
+ * unknown 接收者上的成员访问 → unknown-recv(与 TypeValue 口径对齐:
830
+ * object/instance/refined/promise 静默;其余记一条)。
831
+ */
832
+ declare function noteUnknownMemberMissing(recv: Abs | undefined, name: string, kind: "method" | "property", loc?: [number, number]): boolean;
833
+ /** 方法分派失败时的统一记账(prim / unknown;obj/brand/promise 静默) */
834
+ declare function noteMemberDispatchMiss(recv: Abs | undefined, name: string, kind: "method" | "property", loc?: [number, number]): void;
835
+
836
+ /**
837
+ * B 路径调用点记录:transpile 把 `f(args)` 改成 $callNamed,
838
+ * 分析时可收集 call@ 所需的 AbsCallRecord。
839
+ * 成员缺失诊断见 member-diag.ts(与 ast-eval 共用,避免循环依赖)。
840
+ */
841
+
842
+ type BCallRecord = {
843
+ fnName: string;
844
+ args: Abs[];
845
+ result: Abs;
846
+ callLoc?: {
847
+ line: number;
848
+ column: number;
849
+ };
850
+ threw?: boolean;
851
+ };
852
+ declare function setBCallCollector(collector: ((r: BCallRecord) => void) | null): void;
853
+ declare function getBCallCollector(): ((r: BCallRecord) => void) | null;
854
+ /**
855
+ * 按名调用并记录。
856
+ * loc: [line, column](1-based line,0-based column,与 Babel 一致)
857
+ * argLocs: 与 args 对齐的实参字面量源位置(provenance;无 loc 用 null)
858
+ */
859
+ declare function $callNamed(name: string, fn: unknown, args: Abs[], loc?: [number, number], argLocs?: Array<[number, number] | null | undefined>): Abs;
860
+
861
+ /**
862
+ * 进程内 B 路径执行:transpile 源码 → new Function 跑在 runtime 上。
863
+ * 不写临时文件;相对 import 用注入的 AbsModuleExports / JS 导出绑定。
864
+ *
865
+ * mode:
866
+ * - "exec"(默认):执行全部顶层(含副作用)
867
+ * - "analyze":只保留函数声明与纯字面量 const;跳过顶层表达式/循环/if
868
+ * ——分析入口安全,不触发 fetch 等顶层副作用
869
+ */
870
+
871
+ type RunTranspiledOptions = {
872
+ /** 说明符 → 依赖导出(host 模块图或 runTranspiled 产物) */
873
+ modules?: Record<string, AbsModuleExports | Record<string, unknown>>;
874
+ maxLoopIters?: number;
875
+ /** analyze = 跳过效应性顶层语句 */
876
+ mode?: "exec" | "analyze";
877
+ /** @nudo:replace 注入值:varName → Abs */
878
+ replacements?: Record<string, Abs>;
879
+ /** @nudo:replace 匹配表:传给 transpile */
880
+ replacementTargets?: Array<{
881
+ target: string;
882
+ varName: string;
883
+ stmtStart?: number;
884
+ stmtEnd?: number;
885
+ }>;
886
+ /** @nudo:as 注入值:varName → Abs */
887
+ asOverrides?: Record<string, Abs>;
888
+ /** @nudo:as 语句范围表 */
889
+ asOverrideTargets?: Array<{
890
+ varName: string;
891
+ stmtStart: number;
892
+ stmtEnd: number;
893
+ }>;
894
+ /** @nudo:env 全局 Abs(JSON/Math/console…)→ 作用域绑定 */
895
+ envGlobals?: Record<string, Abs>;
896
+ };
897
+ /**
898
+ * 执行一段 B 路径程序,返回顶层 `export function` / `export const`。
899
+ */
900
+ declare function runTranspiled(source: string, opts?: RunTranspiledOptions): Record<string, unknown>;
901
+ type TranspiledCallResult = {
902
+ result: Abs;
903
+ /** 非 never 表示函数可能 throw 该类型 */
904
+ throws: Abs;
905
+ };
906
+ /** 调用 runTranspiled 导出(捕获 $throw) */
907
+ declare function callTranspiledExportFull(exports: Record<string, unknown>, name: string, args: Abs[]): TranspiledCallResult;
908
+ /** 调用 runTranspiled 导出(仅结果) */
909
+ declare function callTranspiledExport(exports: Record<string, unknown>, name: string, args: Abs[]): Abs;
910
+
911
+ export { $add as $, type AstEnv as A, $invoke as B, type Confidence as C, $invokeSuper as D, $join as E, $le as F, $len as G, type HofSite as H, $lit as I, $lt as J, $mod as K, type LeakBudget as L, $mul as M, $ne as N, $neg as O, type Phi as P, $new as Q, type RelSource as R, type Shape as S, type Term as T, $not as U, $obj as V, $optionalGet as W, $optionalInvoke as X, $orDefault as Y, $regex as Z, $set as _, type Abs as a, ge as a$, $setKey as a0, $spread as a1, $staticInvoke as a2, $sub as a3, $super as a4, $switch as a5, $thisGet as a6, $thisSet as a7, $throw as a8, $typeof as a9, applyAbsFn as aA, applyCallbackAbs as aB, asAbs as aC, asAbsVal as aD, betaOf as aE, bindImports as aF, bool as aG, boolLit as aH, callFunction as aI, callTranspiledExport as aJ, callTranspiledExportFull as aK, clearBClasses as aL, collectAbsExports as aM, collectAbsNodeTypes as aN, confJoin as aO, createHofCollectCtx as aP, currentExecPhi as aQ, defaultLeakBudget as aR, emptyEnv as aS, emptyPhi as aT, eq as aU, evalMethodBody as aV, evalNode as aW, evalProgramAbs as aX, evalSource as aY, exceedsBudget as aZ, findAbsAtPosition as a_, $while as aa, $whileSeq as ab, $yield as ac, type AbsAssignRecord as ad, type AbsCallRecord as ae, type AbsModuleExports as af, type BCallRecord as ag, type BClassSpec as ah, type BMemberDiag as ai, DEFAULT_MAX_LOOP_ITERS as aj, type EvalOptions as ak, type EvalResult as al, type HofCollectCtx as am, MAX_CALL_DEPTH as an, MAX_TOTAL_CALLS as ao, NudoThrow as ap, type RunTranspiledOptions as aq, type TranspileOptions as ar, type TranspiledCallResult as as, abs as at, absToString as au, alphaOf as av, analyzeFn as aw, and as ax, anyVar as ay, app as az, type Pred as b, strLit as b$, geNum as b0, getAbsOrigin as b1, getBCallCollector as b2, getBClass as b3, gt as b4, gtNum as b5, implies as b6, instantiateReturn as b7, isDefinitelyFalse as b8, isDefinitelyTrue as b9, or as bA, pFalse as bB, pTrue as bC, phiAnd as bD, predEquals as bE, predToString as bF, predVars as bG, projectFlatMapResult as bH, promoteParamShape as bI, ptypeof as bJ, recordMemberDiag as bK, registerBClass as bL, resetAbsCallBudget as bM, resetLeakCounter as bN, runTranspiled as bO, setAbsAssignCollector as bP, setAbsCallCollector as bQ, setAbsNodeCollector as bR, setAbsTruncationCollector as bS, setApplyCallbackHost as bT, setBCallCollector as bU, setMemberDiagCollector as bV, shapeOfTerm as bW, shapeToString as bX, simplifyTerm as bY, snapshotAbs as bZ, str as b_, isExactLit as ba, isNudoThrow as bb, isNumPrim as bc, isRelFn as bd, isStrPrim as be, le as bf, leNum as bg, leakIfNeeded as bh, lit as bi, litTruth as bj, litValue as bk, lt as bl, ltNum as bm, mapElementFallback as bn, maybeLeak as bo, namespaceNameOf as bp, ne as bq, never as br, not as bs, noteMemberDispatchMiss as bt, notePrimMemberMissing as bu, noteUnknownMemberMissing as bv, num as bw, numLit as bx, numVar as by, obj as bz, type PrimName as c, substAbs as c0, substPred as c1, substPredAbs as c2, tagAbsOrigin as c3, termDepth as c4, termEquals as c5, termNodes as c6, termToString as c7, transpile as c8, transpileExpression as c9, transpileFile as ca, transpileSource as cb, tryPromoteDirectCall as cc, tryPromoteForOfIteratee as cd, tryPromoteHofCallback as ce, tryPromoteReceiverAsArr as cf, undefAbs as cg, unknown as ch, v as ci, withExecPhi as cj, withVar as ck, $arr as d, $async as e, $asyncReturn as f, $await as g, $call as h, $callNamed as i, $catchVal as j, $class as k, $concat as l, $div as m, $elems as n, $eq as o, $fnVal as p, $for as q, $forIter as r, $forOf as s, $fork as t, $ge as u, $gen as v, $get as w, $gt as x, $idx as y, $idxSet as z };