feat(joinir): Phase 47-A prep - P3 fixture and test stub
Preparation for Phase 47-A (P3 Normalized minimal implementation). Added fixture and test stub for pattern3_if_sum_minimal. Changes: - fixtures.rs: Added pattern3_if_sum_minimal fixture - Source: phase212_if_sum_min.hako - Pattern: Single carrier (sum), simple condition (i > 0) - Dev-only fixture for P3 Normalized development - normalized_joinir_min.rs: Added test stub - test_normalized_pattern3_if_sum_minimal_runner - Currently returns early (implementation pending) - Feature-gated: #[cfg(feature = "normalized_dev")] - Documentation updates: - CURRENT_TASK.md: Phase 47-A status - PHASE_43_245B_NORMALIZED_COMPLETION.md: P3 forward reference - joinir-architecture-overview.md: Minor formatting - phase47-norm-p3-design.md: Implementation notes Next steps (Phase 47-A implementation): 1. Rename pattern2_step_schedule.rs → step_schedule.rs 2. Add P3 StepKind (IfCond, ThenUpdates, ElseUpdates) 3. Implement Normalized→MIR(direct) for P3 4. Complete test implementation Tests: 937/937 PASS (no behavioral changes yet)
This commit is contained in:
@ -7,6 +7,7 @@ use crate::mir::join_ir::lowering::join_value_space::JoinValueSpace;
|
||||
use crate::mir::join_ir::lowering::loop_scope_shape::LoopScopeShape;
|
||||
use crate::mir::join_ir::lowering::loop_update_analyzer::UpdateExpr;
|
||||
use crate::mir::join_ir::lowering::loop_with_break_minimal::lower_loop_with_break_minimal;
|
||||
use crate::mir::join_ir::lowering::loop_with_if_phi_if_sum::lower_if_sum_pattern;
|
||||
use crate::mir::join_ir::JoinModule;
|
||||
use crate::mir::{BasicBlockId, ValueId};
|
||||
use crate::{config::env::joinir_dev_enabled, config::env::joinir_test_debug_enabled};
|
||||
@ -210,6 +211,91 @@ pub fn build_jsonparser_atoi_real_structured_for_normalized_dev() -> JoinModule
|
||||
module
|
||||
}
|
||||
|
||||
/// Pattern3 if-sum minimal ループ(phase212_if_sum_min.hako 相当)を Structured で組み立てるヘルパー。
|
||||
///
|
||||
/// Phase 47-A: P3 Normalized の最小ケース検証用(dev-only)。
|
||||
pub fn build_pattern3_if_sum_min_structured_for_normalized_dev() -> JoinModule {
|
||||
fn var(name: &str) -> ASTNode {
|
||||
ASTNode::Variable {
|
||||
name: name.to_string(),
|
||||
span: Span::unknown(),
|
||||
}
|
||||
}
|
||||
|
||||
fn int_lit(value: i64) -> ASTNode {
|
||||
ASTNode::Literal {
|
||||
value: LiteralValue::Integer(value),
|
||||
span: Span::unknown(),
|
||||
}
|
||||
}
|
||||
|
||||
fn bin(op: BinaryOperator, left: ASTNode, right: ASTNode) -> ASTNode {
|
||||
ASTNode::BinaryOp {
|
||||
operator: op,
|
||||
left: Box::new(left),
|
||||
right: Box::new(right),
|
||||
span: Span::unknown(),
|
||||
}
|
||||
}
|
||||
|
||||
fn assignment(target: ASTNode, value: ASTNode) -> ASTNode {
|
||||
ASTNode::Assignment {
|
||||
target: Box::new(target),
|
||||
value: Box::new(value),
|
||||
span: Span::unknown(),
|
||||
}
|
||||
}
|
||||
|
||||
// Minimal if-sum pattern:
|
||||
// loop(i < 3) {
|
||||
// if (i > 0) { sum = sum + 1 } else { sum = sum + 0 }
|
||||
// i = i + 1
|
||||
// }
|
||||
let loop_condition = bin(BinaryOperator::Less, var("i"), int_lit(3));
|
||||
let if_condition = bin(BinaryOperator::Greater, var("i"), int_lit(0));
|
||||
|
||||
let then_update = assignment(
|
||||
var("sum"),
|
||||
bin(BinaryOperator::Add, var("sum"), int_lit(1)),
|
||||
);
|
||||
let else_update = assignment(
|
||||
var("sum"),
|
||||
bin(BinaryOperator::Add, var("sum"), int_lit(0)),
|
||||
);
|
||||
let counter_update = assignment(
|
||||
var("i"),
|
||||
bin(BinaryOperator::Add, var("i"), int_lit(1)),
|
||||
);
|
||||
|
||||
let if_stmt = ASTNode::If {
|
||||
condition: Box::new(if_condition),
|
||||
then_body: vec![then_update],
|
||||
else_body: Some(vec![else_update]),
|
||||
span: Span::unknown(),
|
||||
};
|
||||
let body = vec![if_stmt.clone(), counter_update];
|
||||
|
||||
let mut join_value_space = JoinValueSpace::new();
|
||||
let mut cond_env = ConditionEnv::new();
|
||||
|
||||
// Phase 220-D: ConditionEnv には少なくともループ変数 i を登録しておく。
|
||||
let i_id = join_value_space.alloc_param();
|
||||
cond_env.insert("i".to_string(), i_id);
|
||||
|
||||
let (module, _meta) =
|
||||
lower_if_sum_pattern(&loop_condition, &if_stmt, &body, &cond_env, &mut join_value_space)
|
||||
.expect("if-sum lowering should succeed for minimal pattern3");
|
||||
|
||||
if joinir_dev_enabled() && joinir_test_debug_enabled() {
|
||||
eprintln!(
|
||||
"[joinir/normalized-dev] pattern3_if_sum_min structured module: {:#?}",
|
||||
module
|
||||
);
|
||||
}
|
||||
|
||||
module
|
||||
}
|
||||
|
||||
/// まとめて import したいとき用のプレリュード。
|
||||
pub mod prelude {
|
||||
pub use super::{
|
||||
@ -219,5 +305,6 @@ pub mod prelude {
|
||||
build_jsonparser_skip_ws_real_structured_for_normalized_dev,
|
||||
build_jsonparser_skip_ws_structured_for_normalized_dev,
|
||||
build_pattern2_break_fixture_structured, build_pattern2_minimal_structured,
|
||||
build_pattern3_if_sum_min_structured_for_normalized_dev,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user