feat(cli): route print through the bundled stdlib (Compat-B)

- Add Program.print_override and lazy stdlib injection: only programs that
  call 打印/print load std:io and route to io.写值 (ADR-0030).
- Record resource.open/read/write/close as trace effect events so the stdlib
  print path is auditable; HostOp::Print no longer runs on that path.
- Permit only stdio/stdout (existing console) in strict; file/network
  resource opens remain permission.denied.
- Exclude std: modules from the human-readable checked-module count; update
  the Python analysis consumer to accept std: instance ids.
- Add print-routing and strict-console tests, ADR-0030 and evidence.

Gate: fmt, clippy -D warnings, 418 tests passed.
This commit is contained in:
cflmy committed 2026-11-20 22:10:59 +08:00
1 parent e119727c5d
commit e26971f489
21 files changed
+560 -36

No files matched your search

+19
View File
@@ -656,6 +656,25 @@ impl<'a> Interpreter<'a> {
let args = self.eval_args(args, frame)?;
return self.call_value(program, value, args, Some(span), Some(&caller_module));
}
if matches!(ident.name.as_str(), "打印" | "print") {
if let Some(target) = program.print_override.clone() {
let args = self.eval_args(args, frame)?;
let Some(function) = program.function(&target) else {
return Err(RuntimeError::new(
ErrorCategory::UnknownSymbol,
Some(span),
format!("print override `{target}` does not exist"),
));
};
return self.call_function(
program,
function,
args,
Some(span),
Some(&caller_module),
);
}
}
if let Some(builtin) = builtins::find(&ident.name) {
let args = self.eval_args(args, frame)?;
return self.call_builtin(builtin, args, Some(span), frame);