@nudojs/core 0.4.0 → 1.0.1
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/{chunk-N7E2A7IK.js → chunk-P3G2TODS.js} +760 -296
- package/dist/exec.d.ts +1 -1
- package/dist/exec.js +1 -1
- package/dist/{index-DgyudAkw.d.ts → index-FITqyJ8v.d.ts} +22 -172
- package/dist/index.d.ts +727 -236
- package/dist/index.js +3788 -2676
- package/package.json +14 -2
package/dist/exec.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { $ as $add,
|
|
1
|
+
export { $ as $add, e as $arr, f as $async, g as $asyncReturn, h as $await, i as $call, j as $callNamed, k as $catchVal, l as $class, m as $concat, n as $div, o as $elems, p as $eq, q as $fnVal, r as $for, s as $forIter, t as $forOf, u as $fork, v as $ge, w as $gen, x as $get, y as $gt, z as $idx, B as $idxSet, D as $invoke, E as $invokeSuper, F as $join, G as $le, I as $len, J as $lit, K as $lt, L as $mod, M as $mul, N as $ne, O as $neg, Q as $new, U as $not, V as $obj, W as $optionalGet, X as $optionalInvoke, Y as $orDefault, Z as $regex, _ as $set, a0 as $setKey, a1 as $spread, a2 as $staticInvoke, a3 as $sub, a4 as $super, a5 as $switch, a6 as $thisGet, a7 as $thisSet, a8 as $throw, a9 as $typeof, aa as $while, ab as $whileSeq, ac as $yield, ad as BCallRecord, ae as BClassSpec, af as BMemberDiag, ag as DEFAULT_MAX_LOOP_ITERS, aj as NudoThrow, ak as RunTranspiledOptions, al as TranspileOptions, am as TranspiledCallResult, av as asAbsVal, aA as callTranspiledExport, aB as callTranspiledExportFull, aC as clearBClasses, aG as currentExecPhi, aL as getAbsOrigin, aM as getBCallCollector, aN as getBClass, aS as isDefinitelyFalse, aT as isDefinitelyTrue, aV as isNudoThrow, b0 as litTruth, b5 as namespaceNameOf, b9 as noteMemberDispatchMiss, ba as notePrimMemberMissing, bb as noteUnknownMemberMissing, bq as recordMemberDiag, br as registerBClass, bs as runTranspiled, bu as setBCallCollector, bv as setMemberDiagCollector, bF as tagAbsOrigin, bI as transpile, bJ as transpileExpression, bK as transpileFile, bL as transpileSource, bT as withExecPhi } from './index-FITqyJ8v.js';
|
|
2
2
|
import '@babel/types';
|
package/dist/exec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImportDeclaration, File,
|
|
1
|
+
import { Node, ImportDeclaration, File, Expression } from '@babel/types';
|
|
2
2
|
|
|
3
3
|
/** 项(Term):抽象值的身份。字面量是项的特例。 */
|
|
4
4
|
type LiteralValue = string | number | boolean | null | undefined;
|
|
@@ -188,29 +188,6 @@ declare function isStrPrim(a: Abs): boolean;
|
|
|
188
188
|
declare function isExactLit(a: Abs): boolean;
|
|
189
189
|
declare function litValue(a: Abs): LiteralValue | undefined;
|
|
190
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
191
|
/**
|
|
215
192
|
* HOF 关系 Abs:无 body 的外延关系(paramTypes → returnType)的判定、
|
|
216
193
|
* α 替换与应用。类型变量仍是 term var;关系仍是 fn 形状上的外延槽。
|
|
@@ -390,27 +367,10 @@ declare function projectFlatMapResult(arrConf: Confidence, mapped: Abs[]): Abs;
|
|
|
390
367
|
declare function asAbs(v: unknown): Abs | undefined;
|
|
391
368
|
|
|
392
369
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
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、块作用域、类、循环。
|
|
370
|
+
* AstEnv:抽象求值环境类型。
|
|
371
|
+
* 独立成文件:hof/language/leq/abs-fn/abs-modules 等消费方只依赖此类型,
|
|
372
|
+
* 不必再为拿一个类型 import ast-eval 巨石(TS 模块环)。
|
|
373
|
+
* ast-eval.ts 对本类型做兼容 re-export,外部消费路径不变。
|
|
414
374
|
*/
|
|
415
375
|
|
|
416
376
|
type AstEnv = {
|
|
@@ -429,135 +389,25 @@ type AstEnv = {
|
|
|
429
389
|
/** P2:generalize symbolic 跑的 HOF collector(run 局部,不进 Φ) */
|
|
430
390
|
hofCollect?: HofCollectCtx;
|
|
431
391
|
};
|
|
432
|
-
|
|
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;
|
|
392
|
+
|
|
527
393
|
/**
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
* seedVars / seedFns:host 注入(@nudo:mock 等)在求值前绑定。
|
|
532
|
-
* modules:host 已求值的依赖导出表(specifier → AbsModuleExports)。
|
|
394
|
+
* Abs 模块面(无 fs):import 绑定 + export 收集。
|
|
395
|
+
* 解析路径/读文件在 host;core 只吃「specifier → 导出表」。
|
|
533
396
|
*/
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
body: Node;
|
|
539
|
-
async?: boolean;
|
|
540
|
-
}>;
|
|
541
|
-
modules?: Record<string, AbsModuleExports>;
|
|
542
|
-
}): {
|
|
543
|
-
env: AstEnv;
|
|
544
|
-
last: Abs;
|
|
545
|
-
phi: Phi;
|
|
397
|
+
|
|
398
|
+
type AbsModuleExports = {
|
|
399
|
+
named: Record<string, Abs>;
|
|
400
|
+
default?: Abs;
|
|
546
401
|
};
|
|
402
|
+
/** 把 import 说明符绑定进 env(宿主已求值依赖) */
|
|
403
|
+
declare function bindImports(node: ImportDeclaration, env: AstEnv, modules: Record<string, AbsModuleExports>): void;
|
|
547
404
|
/**
|
|
548
|
-
*
|
|
549
|
-
*
|
|
405
|
+
* 从已求值 env + AST 收集 ESM 导出。
|
|
406
|
+
* 支持:export function/const、export { a, b as c }、export default(具名)、
|
|
407
|
+
* 以及带 source 的 re-export(`export { a } from "mod"` / `export * from "mod"`——
|
|
408
|
+
* 需 host 传入已求值 modules)。
|
|
550
409
|
*/
|
|
551
|
-
declare function
|
|
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;
|
|
410
|
+
declare function collectAbsExports(file: File, env: AstEnv, modules?: Record<string, AbsModuleExports>): AbsModuleExports;
|
|
561
411
|
|
|
562
412
|
/**
|
|
563
413
|
* B 路径运行时:transpile 后的程序在 Node 上执行时,值就是 Abs。
|
|
@@ -616,7 +466,7 @@ declare function $forIter(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Ab
|
|
|
616
466
|
* 相邻态 leq 视为不动点提前停。
|
|
617
467
|
*/
|
|
618
468
|
declare function $for(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, body: (s: Abs) => Abs, maxIters?: number): Abs;
|
|
619
|
-
/** 数组字面量 →
|
|
469
|
+
/** 数组字面量 → ≤cap tuple(逐元素精确)/ >cap arr;策略与 ast-eval 同源(containers.ts) */
|
|
620
470
|
declare function $arr(items: Abs[]): Abs;
|
|
621
471
|
/** 下标读 a[i];字面量 i 走 tuple 精确投影,否则并所有元素;string[i] → 单字符 */
|
|
622
472
|
declare function $idx(a: Abs, i: Abs): Abs;
|
|
@@ -628,7 +478,7 @@ declare function $len(a: Abs): Abs;
|
|
|
628
478
|
declare function $obj(slots: Record<string, Abs>): Abs;
|
|
629
479
|
/** 对象展开 { ...a, b } */
|
|
630
480
|
declare function $spread(a: Abs, b: Abs): Abs;
|
|
631
|
-
/** 数组连接 [...a, ...b] / [...a, x] */
|
|
481
|
+
/** 数组连接 [...a, ...b] / [...a, x];结果超 cap 时与字面量同策略降 arr */
|
|
632
482
|
declare function $concat(a: Abs, b: Abs): Abs;
|
|
633
483
|
/** 元素列表(tuple 展开;arr 抽象) */
|
|
634
484
|
declare function $elems(a: Abs): Abs[];
|
|
@@ -908,4 +758,4 @@ declare function callTranspiledExportFull(exports: Record<string, unknown>, name
|
|
|
908
758
|
/** 调用 runTranspiled 导出(仅结果) */
|
|
909
759
|
declare function callTranspiledExport(exports: Record<string, unknown>, name: string, args: Abs[]): Abs;
|
|
910
760
|
|
|
911
|
-
export { $add as $, type
|
|
761
|
+
export { $add as $, type Abs as A, $idxSet as B, type Confidence as C, $invoke as D, $invokeSuper as E, $join as F, $le as G, type HofSite as H, $len as I, $lit as J, $lt as K, $mod 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 AstEnv as a, lit 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, callTranspiledExport as aA, callTranspiledExportFull as aB, clearBClasses as aC, collectAbsExports as aD, confJoin as aE, createHofCollectCtx as aF, currentExecPhi as aG, emptyPhi as aH, eq as aI, ge as aJ, geNum as aK, getAbsOrigin as aL, getBCallCollector as aM, getBClass as aN, gt as aO, gtNum as aP, implies as aQ, instantiateReturn as aR, isDefinitelyFalse as aS, isDefinitelyTrue as aT, isExactLit as aU, isNudoThrow as aV, isNumPrim as aW, isRelFn as aX, isStrPrim as aY, le as aZ, leNum as a_, $while as aa, $whileSeq as ab, $yield as ac, type BCallRecord as ad, type BClassSpec as ae, type BMemberDiag as af, DEFAULT_MAX_LOOP_ITERS as ag, type HofCollectCtx as ah, type LiteralValue as ai, NudoThrow as aj, type RunTranspiledOptions as ak, type TranspileOptions as al, type TranspiledCallResult as am, abs as an, absToString as ao, alphaOf as ap, and as aq, anyVar as ar, app as as, applyCallbackAbs as at, asAbs as au, asAbsVal as av, betaOf as aw, bindImports as ax, bool as ay, boolLit as az, type Pred as b, litTruth as b0, litValue as b1, lt as b2, ltNum as b3, mapElementFallback as b4, namespaceNameOf as b5, ne as b6, never as b7, not as b8, noteMemberDispatchMiss as b9, str as bA, strLit as bB, substAbs as bC, substPred as bD, substPredAbs as bE, tagAbsOrigin as bF, termEquals as bG, termToString as bH, transpile as bI, transpileExpression as bJ, transpileFile as bK, transpileSource as bL, tryPromoteDirectCall as bM, tryPromoteForOfIteratee as bN, tryPromoteHofCallback as bO, tryPromoteReceiverAsArr as bP, undefAbs as bQ, unknown as bR, v as bS, withExecPhi as bT, notePrimMemberMissing as ba, noteUnknownMemberMissing as bb, num as bc, numLit as bd, numVar as be, obj as bf, or as bg, pFalse as bh, pTrue as bi, phiAnd as bj, predEquals as bk, predToString as bl, predVars as bm, projectFlatMapResult as bn, promoteParamShape as bo, ptypeof as bp, recordMemberDiag as bq, registerBClass as br, runTranspiled as bs, setApplyCallbackHost as bt, setBCallCollector as bu, setMemberDiagCollector as bv, shapeOfTerm as bw, shapeToString as bx, simplifyTerm as by, snapshotAbs as bz, type AbsModuleExports as c, type PrimName as d, $arr as e, $async as f, $asyncReturn as g, $await as h, $call as i, $callNamed as j, $catchVal as k, $class as l, $concat as m, $div as n, $elems as o, $eq as p, $fnVal as q, $for as r, $forIter as s, $forOf as t, $fork as u, $ge as v, $gen as w, $get as x, $gt as y, $idx as z };
|