🎉 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::{BasicBlock, BasicBlockId};
|
2025-09-17 07:43:07 +09:00
|
|
|
use crate::mir::{BarrierOp, TypeOpKind, WeakRefOp};
|
2025-09-25 00:41:56 +09:00
|
|
|
// include path resolver removed (using handles modules)
|
2025-09-03 05:04:56 +09:00
|
|
|
|
|
|
|
|
// Optional builder debug logging
|
|
|
|
|
pub(super) fn builder_debug_enabled() -> bool {
|
|
|
|
|
std::env::var("NYASH_BUILDER_DEBUG").is_ok()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(super) fn builder_debug_log(msg: &str) {
|
|
|
|
|
if builder_debug_enabled() {
|
|
|
|
|
eprintln!("[BUILDER] {}", msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
🎉 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
|
|
|
impl super::MirBuilder {
|
|
|
|
|
/// Ensure a basic block exists in the current function
|
|
|
|
|
pub(crate) fn ensure_block_exists(&mut self, block_id: BasicBlockId) -> Result<(), String> {
|
|
|
|
|
if let Some(ref mut function) = self.current_function {
|
|
|
|
|
if !function.blocks.contains_key(&block_id) {
|
|
|
|
|
let block = BasicBlock::new(block_id);
|
|
|
|
|
function.add_block(block);
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
Err("No current function".to_string())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Start a new basic block and set as current
|
|
|
|
|
pub(crate) fn start_new_block(&mut self, block_id: BasicBlockId) -> Result<(), String> {
|
|
|
|
|
if let Some(ref mut function) = self.current_function {
|
|
|
|
|
function.add_block(BasicBlock::new(block_id));
|
|
|
|
|
self.current_block = Some(block_id);
|
|
|
|
|
Ok(())
|
|
|
|
|
} else {
|
|
|
|
|
Err("No current function".to_string())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-16 03:54:44 +09:00
|
|
|
|
|
|
|
|
impl super::MirBuilder {
|
|
|
|
|
/// Emit a Box method call or plugin call (unified BoxCall)
|
|
|
|
|
pub(super) fn emit_box_or_plugin_call(
|
|
|
|
|
&mut self,
|
|
|
|
|
dst: Option<super::ValueId>,
|
|
|
|
|
box_val: super::ValueId,
|
|
|
|
|
method: String,
|
|
|
|
|
method_id: Option<u16>,
|
|
|
|
|
args: Vec<super::ValueId>,
|
|
|
|
|
effects: super::EffectMask,
|
|
|
|
|
) -> Result<(), String> {
|
2025-09-24 02:11:59 +09:00
|
|
|
// Check environment variable for unified call usage
|
|
|
|
|
let use_unified = std::env::var("NYASH_MIR_UNIFIED_CALL")
|
|
|
|
|
.unwrap_or_else(|_| "0".to_string()) != "0";
|
|
|
|
|
|
|
|
|
|
if use_unified {
|
|
|
|
|
// Use unified call emission for BoxCall
|
|
|
|
|
// First, try to determine the box type
|
|
|
|
|
let mut box_type: Option<String> = self.value_origin_newbox.get(&box_val).cloned();
|
|
|
|
|
if box_type.is_none() {
|
|
|
|
|
if let Some(t) = self.value_types.get(&box_val) {
|
|
|
|
|
match t {
|
|
|
|
|
super::MirType::String => box_type = Some("StringBox".to_string()),
|
|
|
|
|
super::MirType::Box(name) => box_type = Some(name.clone()),
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use emit_unified_call with Method target
|
|
|
|
|
let target = super::builder_calls::CallTarget::Method {
|
|
|
|
|
box_type,
|
|
|
|
|
method: method.clone(),
|
|
|
|
|
receiver: box_val,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return self.emit_unified_call(dst, target, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Legacy implementation
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::BoxCall {
|
|
|
|
|
dst,
|
|
|
|
|
box_val,
|
|
|
|
|
method: method.clone(),
|
|
|
|
|
method_id,
|
|
|
|
|
args,
|
|
|
|
|
effects,
|
|
|
|
|
})?;
|
2025-09-16 03:54:44 +09:00
|
|
|
if let Some(d) = dst {
|
|
|
|
|
let mut recv_box: Option<String> = self.value_origin_newbox.get(&box_val).cloned();
|
|
|
|
|
if recv_box.is_none() {
|
|
|
|
|
if let Some(t) = self.value_types.get(&box_val) {
|
2025-09-17 07:43:07 +09:00
|
|
|
match t {
|
|
|
|
|
super::MirType::String => recv_box = Some("StringBox".to_string()),
|
|
|
|
|
super::MirType::Box(name) => recv_box = Some(name.clone()),
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
2025-09-16 03:54:44 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if let Some(bt) = recv_box {
|
|
|
|
|
if let Some(mt) = self.plugin_method_sigs.get(&(bt.clone(), method.clone())) {
|
|
|
|
|
self.value_types.insert(d, mt.clone());
|
|
|
|
|
} else {
|
2025-09-24 09:30:42 +09:00
|
|
|
// Phase 15.5: Unified plugin-based type resolution
|
|
|
|
|
// Former core boxes (StringBox, ArrayBox, MapBox) now use plugin_method_sigs only
|
|
|
|
|
// No special hardcoded inference - all boxes treated uniformly
|
2025-09-16 03:54:44 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2025-09-17 07:43:07 +09:00
|
|
|
pub(super) fn emit_type_check(
|
|
|
|
|
&mut self,
|
|
|
|
|
value: super::ValueId,
|
|
|
|
|
expected_type: String,
|
|
|
|
|
) -> Result<super::ValueId, String> {
|
2025-09-16 03:54:44 +09:00
|
|
|
let dst = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::TypeOp {
|
|
|
|
|
dst,
|
|
|
|
|
op: TypeOpKind::Check,
|
|
|
|
|
value,
|
|
|
|
|
ty: super::MirType::Box(expected_type),
|
|
|
|
|
})?;
|
2025-09-16 03:54:44 +09:00
|
|
|
Ok(dst)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2025-09-17 07:43:07 +09:00
|
|
|
pub(super) fn emit_cast(
|
|
|
|
|
&mut self,
|
|
|
|
|
value: super::ValueId,
|
|
|
|
|
target_type: super::MirType,
|
|
|
|
|
) -> Result<super::ValueId, String> {
|
2025-09-16 03:54:44 +09:00
|
|
|
let dst = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::TypeOp {
|
|
|
|
|
dst,
|
|
|
|
|
op: TypeOpKind::Cast,
|
|
|
|
|
value,
|
|
|
|
|
ty: target_type.clone(),
|
|
|
|
|
})?;
|
2025-09-16 03:54:44 +09:00
|
|
|
Ok(dst)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2025-09-17 07:43:07 +09:00
|
|
|
pub(super) fn emit_weak_new(
|
|
|
|
|
&mut self,
|
|
|
|
|
box_val: super::ValueId,
|
|
|
|
|
) -> Result<super::ValueId, String> {
|
|
|
|
|
if crate::config::env::mir_core13_pure() {
|
|
|
|
|
return Ok(box_val);
|
|
|
|
|
}
|
2025-09-16 03:54:44 +09:00
|
|
|
let dst = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::WeakRef {
|
|
|
|
|
dst,
|
|
|
|
|
op: WeakRefOp::New,
|
|
|
|
|
value: box_val,
|
|
|
|
|
})?;
|
2025-09-16 03:54:44 +09:00
|
|
|
Ok(dst)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2025-09-17 07:43:07 +09:00
|
|
|
pub(super) fn emit_weak_load(
|
|
|
|
|
&mut self,
|
|
|
|
|
weak_ref: super::ValueId,
|
|
|
|
|
) -> Result<super::ValueId, String> {
|
|
|
|
|
if crate::config::env::mir_core13_pure() {
|
|
|
|
|
return Ok(weak_ref);
|
|
|
|
|
}
|
2025-09-16 03:54:44 +09:00
|
|
|
let dst = self.value_gen.next();
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::WeakRef {
|
|
|
|
|
dst,
|
|
|
|
|
op: WeakRefOp::Load,
|
|
|
|
|
value: weak_ref,
|
|
|
|
|
})?;
|
2025-09-16 03:54:44 +09:00
|
|
|
Ok(dst)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
pub(super) fn emit_barrier_read(&mut self, ptr: super::ValueId) -> Result<(), String> {
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Barrier {
|
|
|
|
|
op: BarrierOp::Read,
|
|
|
|
|
ptr,
|
|
|
|
|
})
|
2025-09-16 03:54:44 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
pub(super) fn emit_barrier_write(&mut self, ptr: super::ValueId) -> Result<(), String> {
|
2025-09-17 07:43:07 +09:00
|
|
|
self.emit_instruction(super::MirInstruction::Barrier {
|
|
|
|
|
op: BarrierOp::Write,
|
|
|
|
|
ptr,
|
|
|
|
|
})
|
2025-09-16 03:54:44 +09:00
|
|
|
}
|
|
|
|
|
}
|