refactor: Extract debug utilities from control_flow.rs (Phase 1)

- Created control_flow/ subdirectory
- Moved trace_varmap() to debug.rs
- All control flow logic now in control_flow/mod.rs
- Zero breaking changes, all functionality preserved
- Tests pass (binary execution verified)
This commit is contained in:
nyash-codex
2025-12-05 20:41:19 +09:00
parent 8fe0babf01
commit 41de2d20e9
2 changed files with 26 additions and 11 deletions

View File

@ -0,0 +1,16 @@
//! Debug utilities for control flow tracing
use super::super::MirBuilder;
impl MirBuilder {
/// Trace variable_map state for debugging
/// Enable with NYASH_TRACE_VARMAP=1
pub(in crate::mir::builder) fn trace_varmap(&self, context: &str) {
if std::env::var("NYASH_TRACE_VARMAP").is_ok() {
let vars: Vec<_> = self.variable_map.iter()
.map(|(k, v)| format!("{}={:?}", k, v))
.collect();
eprintln!("[varmap/{}] {{{}}}", context, vars.join(", "));
}
}
}

View File

@ -1,19 +1,18 @@
//! Control-flow entrypoints (if/loop/try/throw) centralized here. //! Control-flow entrypoints (if/loop/try/throw) centralized here.
//!
//! This module is being modularized in phases:
//! - Phase 1: Debug utilities
//! - Phase 2: Pattern lowerers
//! - Phase 3: JoinIR routing
//! - Phase 4-19: Additional modularization (future)
use super::{Effect, EffectMask, MirInstruction, ValueId}; use super::{Effect, EffectMask, MirInstruction, ValueId};
use crate::ast::ASTNode; use crate::ast::ASTNode;
impl super::MirBuilder { // Phase 1: Debug utilities
/// Trace variable_map state for debugging pub(in crate::mir::builder) mod debug;
/// Enable with NYASH_TRACE_VARMAP=1
fn trace_varmap(&self, context: &str) {
if std::env::var("NYASH_TRACE_VARMAP").is_ok() {
let vars: Vec<_> = self.variable_map.iter()
.map(|(k, v)| format!("{}={:?}", k, v))
.collect();
eprintln!("[varmap/{}] {{{}}}", context, vars.join(", "));
}
}
impl super::MirBuilder {
/// Control-flow: block /// Control-flow: block
pub(super) fn cf_block(&mut self, statements: Vec<ASTNode>) -> Result<ValueId, String> { pub(super) fn cf_block(&mut self, statements: Vec<ASTNode>) -> Result<ValueId, String> {
// identical to build_block; kept here for future policy hooks // identical to build_block; kept here for future policy hooks