diff --git a/src/mir/builder/compilation_context.rs b/src/mir/builder/compilation_context.rs index 0497666c..49dded47 100644 --- a/src/mir/builder/compilation_context.rs +++ b/src/mir/builder/compilation_context.rs @@ -93,6 +93,10 @@ pub(crate) struct CompilationContext { /// Plugin method return type signatures loaded from nyash_box.toml pub plugin_method_sigs: HashMap<(String, String), MirType>, + + /// Phase 288: REPL mode での内部ログ抑制フラグ + /// REPL mode でのみ true、file mode では常に false + pub quiet_internal_logs: bool, } impl CompilationContext { @@ -114,6 +118,7 @@ impl CompilationContext { type_registry: TypeRegistry::new(), current_slot_registry: None, plugin_method_sigs: HashMap::new(), + quiet_internal_logs: false, // File mode: 常に false } } diff --git a/src/mir/builder/decls.rs b/src/mir/builder/decls.rs index 501d32ac..a404f16b 100644 --- a/src/mir/builder/decls.rs +++ b/src/mir/builder/decls.rs @@ -129,7 +129,7 @@ impl super::MirBuilder { } } // Phase 200-C: Store fn_body_ast for inline main() lowering - if std::env::var("NYASH_QUIET_INTERNAL_LOGS").ok().as_deref() != Some("1") { + if !self.comp_ctx.quiet_internal_logs { eprintln!( "[build_static_main_box] Storing fn_body_ast with {} nodes for inline main()", body.len() diff --git a/src/mir/mod.rs b/src/mir/mod.rs index 02325e6b..9dfd5cf1 100644 --- a/src/mir/mod.rs +++ b/src/mir/mod.rs @@ -131,6 +131,11 @@ impl MirCompiler { self.builder.repl_mode = repl_mode; } + /// Phase 288: REPL mode での内部ログ抑制フラグを設定 + pub fn set_quiet_internal_logs(&mut self, quiet: bool) { + self.builder.comp_ctx.quiet_internal_logs = quiet; + } + /// Compile AST to MIR module with verification pub fn compile_with_source( &mut self, diff --git a/src/runner/repl/repl_runner.rs b/src/runner/repl/repl_runner.rs index 9b36f0c7..b7ad2a1a 100644 --- a/src/runner/repl/repl_runner.rs +++ b/src/runner/repl/repl_runner.rs @@ -17,13 +17,20 @@ pub(super) struct ReplRunnerBox { #[allow(dead_code)] config: CliConfig, session: RefCell>, + /// REPL mode での内部ログ抑制フラグ + /// verbose が false の場合に true(REPL 専用) + quiet_internal_logs: bool, } impl ReplRunnerBox { pub(super) fn new(config: CliConfig) -> Self { + // REPL mode では verbose が false なら内部ログを抑制 + let quiet_internal_logs = !crate::config::env::cli_verbose(); + Self { config, session: RefCell::new(None), + quiet_internal_logs, } } @@ -99,11 +106,8 @@ impl ReplRunnerBox { use crate::mir::MirCompiler; use crate::backend::mir_interpreter::MirInterpreter; - // REPL mode では内部デバッグログを抑制(NYASH_CLI_VERBOSE=1 で無効化) - let verbose = std::env::var("NYASH_CLI_VERBOSE").ok().as_deref() == Some("1"); - if !verbose { - std::env::set_var("NYASH_QUIET_INTERNAL_LOGS", "1"); - } + // REPL mode では内部デバッグログを自動抑制 + // (quiet_internal_logs フラグで制御、環境変数操作不要) // Initialize session on first use { @@ -122,6 +126,9 @@ impl ReplRunnerBox { let mut compiler = MirCompiler::new(); compiler.set_repl_mode(true); + // MirCompiler に quiet フラグを渡す + compiler.set_quiet_internal_logs(self.quiet_internal_logs); + let mir_result = compiler.compile_with_source(ast, Some("")) .map_err(|e| format!("Compile error: {}", e))?; @@ -145,11 +152,6 @@ impl ReplRunnerBox { // Phase 288 P3: print() output already displayed via ExternCall // Expression auto-display deferred to Phase 288.1 - // 評価完了後に環境変数をクリーンアップ - if !verbose { - std::env::remove_var("NYASH_QUIET_INTERNAL_LOGS"); - } - Ok(String::new()) } }