🎉 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();
|
|
|
|
|
let result_val = self.value_gen.next();
|
|
|
|
|
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-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Jump {
|
|
|
|
|
target: 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();
|
|
|
|
|
self.emit_instruction(super::MirInstruction::Jump { target: else_block })?;
|
|
|
|
|
self.start_new_block(else_block)?;
|
|
|
|
|
let else_val = self.build_expression_impl(else_expr)?;
|
|
|
|
|
phi_inputs.push((else_block, else_val));
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Jump {
|
|
|
|
|
target: merge_block,
|
|
|
|
|
})?;
|
2025-09-14 20:30:38 +09:00
|
|
|
self.start_new_block(merge_block)?;
|
2025-09-16 23:49:36 +09:00
|
|
|
if self.is_no_phi_mode() {
|
|
|
|
|
for (pred, val) in phi_inputs {
|
|
|
|
|
self.insert_edge_copy(pred, result_val, val)?;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Phi {
|
|
|
|
|
dst: result_val,
|
|
|
|
|
inputs: phi_inputs,
|
|
|
|
|
})?;
|
2025-09-16 23:49:36 +09:00
|
|
|
}
|
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)?;
|
🎉 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
|
|
|
if let LiteralValue::String(s) = label {
|
|
|
|
|
let lit_id = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Const {
|
|
|
|
|
dst: lit_id,
|
|
|
|
|
value: super::ConstValue::String(s),
|
|
|
|
|
})?;
|
🎉 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 cond_id = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Compare {
|
|
|
|
|
dst: cond_id,
|
|
|
|
|
op: super::CompareOp::Eq,
|
|
|
|
|
lhs: scr_val,
|
|
|
|
|
rhs: lit_id,
|
|
|
|
|
})?;
|
|
|
|
|
self.emit_instruction(super::MirInstruction::Branch {
|
|
|
|
|
condition: cond_id,
|
|
|
|
|
then_bb: then_block,
|
|
|
|
|
else_bb: 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
|
|
|
|
|
|
|
|
// 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-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Jump {
|
|
|
|
|
target: 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-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Jump {
|
|
|
|
|
target: 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-09-16 23:49:36 +09:00
|
|
|
if self.is_no_phi_mode() {
|
|
|
|
|
for (pred, val) in phi_inputs {
|
|
|
|
|
self.insert_edge_copy(pred, result_val, val)?;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Phi {
|
|
|
|
|
dst: result_val,
|
|
|
|
|
inputs: phi_inputs,
|
|
|
|
|
})?;
|
2025-09-16 23:49:36 +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)
|
|
|
|
|
}
|
|
|
|
|
}
|