Three-lens static analysis pipeline (structural / type / behavioral) for MLang programs and state-machine tables
| 透镜 | 包 | 职责 | 产出 |
|---|---|---|---|
| 结构 | src/walk | 赋值即绑定、未用/未定义/参数被改、常量折叠剪枝 | 绑定表 fn_bindings |
| 类型 | src/types | 注解即契约、推断、赋值/实参/条件检查(声明取自绑定表) | 签名表 sigs |
| 行为 | src/interp | 格上抽象解释、按签名调度、虚栈(方法表取自签名表) | 行为发现 |
| 合并 | src/pipeline | 同一缺陷的多透镜回声 → 一条报告,lens 并集 | render_result |
moon run src/cli # demo:6 个样例 × 三透镜=== undefined.mlang ===
2:10 - error: undefined variable 'missing' (UndefinedName) [structural+type+behavior]
in main() at undefined.mlang:4
in g at undefined.mlang:1
Summary: 1 finding(s) (before merge: structural 1, type 2, behavior 1)| 透镜 | 机器侧语义 | 检查内容 |
|---|---|---|
| 结构 | 状态即绑定("赋值即绑定"推广到机器表) | 任何状态都必须被至少一条迁移绑定(出或入);只出不进 → never entered;从初始位置的可达性闭包;终点必须可达(机器必须能完成) |
| 类型 | 驱动槽契约("注解即契约") | 每个触发必须归位已知槽、无空槽;Block 必须带理由——无路必须说出口,不能沉默 |
| 行为 | 轨迹抽象执行(虚栈) | 修习历程每一步都必须有触发承载;断链的轨迹步带入口帧→出错帧的虚栈 |
let spec : @statecheck.MachineSpec = { name: "主体", states: [...], ... }
let findings : Array[@report.Report] = @statecheck.audit(spec)
let text : String = @statecheck.render(spec) // 合并后的文本报告182:12 - warning: state '失忆' is never entered: it appears only as a transition source (UnusedLocal) [structural]
182:12 - warning: state '失忆' is unreachable from the initial position '站立' (Unreachable) [structural]
825:37 - warning: state '浑噩' is never entered: it appears only as a transition source (UnusedLocal) [structural]
825:37 - warning: state '浑噩' is unreachable from the initial position '站立' (Unreachable) [structural]
Machine '主体' summary: 4 finding(s)src/core Span/Severity/Lens/Family(merge_group 契约)/Frame
src/report Report 结构与渲染(lens 并集标签、vst 框架)
src/lexer MLang 词法
src/parser MLang 语法 → ast
src/ast MLang 抽象语法
src/walk 透镜1:绑定表 + 结构发现
src/types 透镜2:Ty/Ty?/Sig 推断
src/interp 透镜3:AbsVal 格 + 调度 + 虚栈
src/pipeline 组装:跑三透镜 + merge_group 合并
src/statecheck 用途二:通用机器表审计(MachineSpec 纯数据桥)
src/samples demo 样例(内嵌 MLang 源)
src/cli 可执行入口(程序 demo + 示例机器审计)moon check # 0 错 0 警
moon test --target js # 12(程序语义)+ 7(机器表语义)= 19/19 全绿
moon run src/cli # 程序 demo + pyroduct 形状示例机器审计moon prove src/core --why3-config .why3.conf # 生成 12 个 VC 并交 cvc5/alt-ergo| 渠道 | 地址 |
|---|---|
| Gitee(主仓) | https://gitee.com/ren-yongxiang/moonbit_static_analysis.git |
| GitHub(镜像) | https://github.com/riantr/moonbit_static_analysis |
| mooncakes.io(包注册表) | https://mooncakes.io/docs/riantr/moonbit_static_analysis |
Install
Download zipThree-lens static analysis pipeline (structural / type / behavioral) for MLang programs and state-machine tables