🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
use super::{BasicBlockId, ValueId};
|
|
|
|
|
|
use crate::ast::{ASTNode, LiteralValue};
|
|
|
|
|
|
|
|
|
|
|
|
impl super::MirBuilder {
|
|
|
|
|
|
// Peek expression lowering
|
|
|
|
|
|
pub(super) fn build_peek_expression(
|
|
|
|
|
|
&mut self,
|
|
|
|
|
|
scrutinee: ASTNode,
|
|
|
|
|
|
arms: Vec<(LiteralValue, ASTNode)>,
|
|
|
|
|
|
else_expr: ASTNode,
|
|
|
|
|
|
) -> Result<ValueId, String> {
|
2025-09-14 20:30:38 +09:00
|
|
|
|
// Evaluate scrutinee in the current block
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
let scr_val = self.build_expression_impl(scrutinee)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
|
|
|
|
|
|
// Prepare merge and result
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
let merge_block: BasicBlockId = self.block_gen.next();
|
2025-11-17 00:48:18 +09:00
|
|
|
|
let result_val = self.next_value_id();
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
let mut phi_inputs: Vec<(BasicBlockId, ValueId)> = Vec::new();
|
|
|
|
|
|
|
2025-09-14 20:30:38 +09:00
|
|
|
|
// Create dispatch block where we start comparing arms
|
|
|
|
|
|
let dispatch_block = self.block_gen.next();
|
|
|
|
|
|
// Jump from current block to dispatch (ensure terminator exists)
|
|
|
|
|
|
let need_jump = {
|
|
|
|
|
|
let cur = self.current_block;
|
|
|
|
|
|
if let (Some(cb), Some(ref func)) = (cur, &self.current_function) {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
if let Some(bb) = func.blocks.get(&cb) {
|
|
|
|
|
|
!bb.is_terminated()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
true
|
|
|
|
|
|
}
|
2025-09-14 20:30:38 +09:00
|
|
|
|
};
|
|
|
|
|
|
if need_jump {
|
2025-09-28 20:38:09 +09:00
|
|
|
|
crate::mir::builder::emission::branch::emit_jump(self, dispatch_block)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
}
|
|
|
|
|
|
self.start_new_block(dispatch_block)?;
|
|
|
|
|
|
|
|
|
|
|
|
// If there are no arms, fall through to else directly
|
|
|
|
|
|
if arms.is_empty() {
|
|
|
|
|
|
let else_block = self.block_gen.next();
|
2025-09-28 20:38:09 +09:00
|
|
|
|
crate::mir::builder::emission::branch::emit_jump(self, else_block)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
self.start_new_block(else_block)?;
|
|
|
|
|
|
let else_val = self.build_expression_impl(else_expr)?;
|
|
|
|
|
|
phi_inputs.push((else_block, else_val));
|
2025-09-28 20:38:09 +09:00
|
|
|
|
crate::mir::builder::emission::branch::emit_jump(self, merge_block)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
self.start_new_block(merge_block)?;
|
2025-11-05 18:57:03 +09:00
|
|
|
|
// フェーズM: PHI はブロック先頭に配置(cf_common 統一)
|
2025-11-06 23:57:24 +09:00
|
|
|
|
self.insert_phi_with_dst(result_val, phi_inputs)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
return Ok(result_val);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Else block to handle default case
|
|
|
|
|
|
let else_block = self.block_gen.next();
|
|
|
|
|
|
|
|
|
|
|
|
// Chain dispatch blocks for each arm
|
|
|
|
|
|
let mut cur_dispatch = dispatch_block;
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
for (i, (label, arm_expr)) in arms.iter().cloned().enumerate() {
|
|
|
|
|
|
let then_block = self.block_gen.next();
|
2025-09-14 20:30:38 +09:00
|
|
|
|
// Next dispatch (only for non-last arm)
|
2025-09-17 07:43:07 +09:00
|
|
|
|
let next_dispatch = if i + 1 < arms.len() {
|
|
|
|
|
|
Some(self.block_gen.next())
|
|
|
|
|
|
} else {
|
|
|
|
|
|
None
|
|
|
|
|
|
};
|
2025-09-14 20:30:38 +09:00
|
|
|
|
let else_target = next_dispatch.unwrap_or(else_block);
|
|
|
|
|
|
|
|
|
|
|
|
// In current dispatch block, compare and branch
|
|
|
|
|
|
self.start_new_block(cur_dispatch)?;
|
2025-09-28 20:38:09 +09:00
|
|
|
|
let lit_id = match label {
|
2025-11-21 06:25:17 +09:00
|
|
|
|
LiteralValue::String(s) => {
|
|
|
|
|
|
crate::mir::builder::emission::constant::emit_string(self, s)
|
|
|
|
|
|
}
|
|
|
|
|
|
LiteralValue::Integer(i) => {
|
|
|
|
|
|
crate::mir::builder::emission::constant::emit_integer(self, i)
|
|
|
|
|
|
}
|
|
|
|
|
|
LiteralValue::Bool(b) => {
|
|
|
|
|
|
crate::mir::builder::emission::constant::emit_bool(self, b)
|
|
|
|
|
|
}
|
|
|
|
|
|
LiteralValue::Float(f) => {
|
|
|
|
|
|
crate::mir::builder::emission::constant::emit_float(self, f)
|
|
|
|
|
|
}
|
2025-09-28 20:38:09 +09:00
|
|
|
|
LiteralValue::Null => crate::mir::builder::emission::constant::emit_null(self),
|
|
|
|
|
|
LiteralValue::Void => crate::mir::builder::emission::constant::emit_void(self),
|
2025-09-23 11:22:16 +09:00
|
|
|
|
};
|
2025-11-17 00:48:18 +09:00
|
|
|
|
let cond_id = self.next_value_id();
|
2025-11-21 06:25:17 +09:00
|
|
|
|
crate::mir::builder::emission::compare::emit_to(
|
|
|
|
|
|
self,
|
|
|
|
|
|
cond_id,
|
|
|
|
|
|
super::CompareOp::Eq,
|
|
|
|
|
|
scr_val,
|
|
|
|
|
|
lit_id,
|
|
|
|
|
|
)?;
|
|
|
|
|
|
crate::mir::builder::emission::branch::emit_conditional(
|
|
|
|
|
|
self,
|
|
|
|
|
|
cond_id,
|
|
|
|
|
|
then_block,
|
|
|
|
|
|
else_target,
|
|
|
|
|
|
)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
|
|
|
|
|
|
// then arm
|
|
|
|
|
|
self.start_new_block(then_block)?;
|
|
|
|
|
|
let then_val = self.build_expression_impl(arm_expr)?;
|
|
|
|
|
|
phi_inputs.push((then_block, then_val));
|
2025-09-28 20:38:09 +09:00
|
|
|
|
crate::mir::builder::emission::branch::emit_jump(self, merge_block)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
|
|
|
|
|
|
// Move to next dispatch or else block
|
|
|
|
|
|
cur_dispatch = else_target;
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-14 20:30:38 +09:00
|
|
|
|
// Lower else expression in else_block
|
|
|
|
|
|
self.start_new_block(else_block)?;
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
let else_val = self.build_expression_impl(else_expr)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
phi_inputs.push((else_block, else_val));
|
2025-09-28 20:38:09 +09:00
|
|
|
|
crate::mir::builder::emission::branch::emit_jump(self, merge_block)?;
|
2025-09-14 20:30:38 +09:00
|
|
|
|
|
|
|
|
|
|
// Merge and yield result
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
self.start_new_block(merge_block)?;
|
2025-11-05 18:57:03 +09:00
|
|
|
|
// フェーズM: PHI はブロック先頭に配置(cf_common 統一)
|
|
|
|
|
|
if let (Some(func), Some(cur_bb)) = (self.current_function.as_mut(), self.current_block) {
|
2025-11-24 15:02:51 +09:00
|
|
|
|
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
|
|
|
|
|
|
func,
|
|
|
|
|
|
cur_bb,
|
|
|
|
|
|
result_val,
|
|
|
|
|
|
phi_inputs,
|
|
|
|
|
|
self.current_span,
|
|
|
|
|
|
);
|
2025-11-05 18:57:03 +09:00
|
|
|
|
} else {
|
2025-11-21 06:25:17 +09:00
|
|
|
|
self.emit_instruction(super::MirInstruction::Phi {
|
|
|
|
|
|
dst: result_val,
|
|
|
|
|
|
inputs: phi_inputs,
|
|
|
|
|
|
})?;
|
2025-11-05 18:57:03 +09:00
|
|
|
|
}
|
🎉 Phase 11.8/12.7: MIR Core-13 完全実装 + 糖衣構文ドキュメント更新
主要な変更:
- MIR Core-13命令セット確定(Load/Store削除の革命的設計)
- Const, BinOp, Compare(値・計算)
- Jump, Branch, Return, Phi(制御)
- Call, BoxCall, ExternCall(呼び出し)
- TypeOp, Safepoint, Barrier(メタ)
- Phase 12.7糖衣構文ドキュメント整理(超圧縮重視、可逆変換保証)
- MIRビルダーのモジュール分割完了
- vtableテストスイート拡充
- AI協調開発ツール追加(並列リファクタリング支援)
詳細:
- src/mir/instruction_introspection.rs: core13_instruction_names()追加
- MIRビルダー分割: decls.rs, exprs_*.rs, fields.rs
- plugin_loader_v2: errors.rs, host_bridge.rs分離
- 論文用データ: mir13-final.md作成
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-04 11:34:15 +09:00
|
|
|
|
Ok(result_val)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|