Files
blackbird/mtc/mtc/__main__.py
T
qing 01126a5786 feat(mtc): .mt 脚本编译器落地 + pybot 扬声器静音语义
mtc 新模块:命令式动作脚本(Python DSL)→ .mt 矩阵编译器,非阻塞时间轴 IR(重叠截断/rest 静止值)+ 10ms 栅格化,产物可由 pybot/bot4cj 直接执行;34 测试全绿(含 pybot parser e2e)。

pybot speaker.py:frequency<=0 改为静音节拍(仅 sleep 保时序,不再钳到 min_f 低鸣),对齐仓颉版 sleep 占位语义;mtc Beep 通道 rest=0,段前/段间/段后回落静音,两侧语义闭环。

修复 test_actpred_compatibility 过时断言(99c1bc1 首行分解为重复微步 19→20 帧时漏改,14→15)。

文档三处同步:根 README 回填 memdb/pybot/actpred 并新增 mtc(模块表+端口一览+章节),MODULES/ARCHITECTURE 同步 mtc,新建 mtc/README.md。
2026-08-15 13:54:47 +08:00

55 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""CLI 入口:python -m mtc script.py [-o out.mt]
诊断(编译告警/错误)走 stderr,stdout 保持纯净 .mt 文本
(对齐 pybot 的 S02 日志规范,支持 mtc walk.py | pybot --dry-run 管道)。
"""
import argparse
import logging
import sys
from .dsl import CompileError, compile_script
def main(argv=None):
p = argparse.ArgumentParser(
prog="mtc",
description="命令式动作脚本(Python DSL)→ .mt 编译器")
p.add_argument("script", help="DSL 脚本路径(.py)")
p.add_argument("-o", "--output", default=None,
help="输出 .mt 路径(缺省写 stdout)")
p.add_argument("--verbose", action="store_true", help="DEBUG 日志")
args = p.parse_args(argv)
logging.basicConfig(stream=sys.stderr,
level=logging.DEBUG if args.verbose else logging.INFO,
format="%(levelname)s %(name)s: %(message)s")
try:
with open(args.script, encoding="utf-8") as f:
source = f.read()
except OSError as e:
logging.error("无法读取脚本: %s", e)
return 2
try:
text, warnings = compile_script(source, filename=args.script)
except CompileError as e:
logging.error("编译失败: %s", e)
return 2
for w in warnings:
logging.warning("%s", w)
if args.output:
with open(args.output, "w", encoding="utf-8") as f:
f.write(text)
logging.info("written: %s (%d lines)", args.output,
text.count("\n"))
else:
sys.stdout.write(text)
return 0
if __name__ == "__main__":
sys.exit(main())