feat: MIR Call命令統一Phase 3.1-3.2完了!統一Call実装進行中

 Phase 3.1-3.2実装完了
- build_indirect_call_expressionでCallTarget::Value使用
- print関数をcall_global print()として統一
- build_function_callでemit_unified_call使用
- ExternCall(env.console.log)→Callee::Global(print)完全移行

🏗️ MIR統一基盤構築
- src/mir/definitions/call_unified.rs: 統一定義(297行)
- emit_unified_call()と便利メソッド3種実装
- NYASH_MIR_UNIFIED_CALL=1で段階移行制御
- VM実行器でCallee対応実装済み

📊 進捗状況(26%削減見込み)
- Phase 1-2:  基盤構築完了
- Phase 3.1-3.2:  基本関数統一完了
- Phase 3.3: 🔄 BoxCall統一中
- Phase 4: 📅 Python LLVM(最優先・63%削減)
- Phase 5: 📅 PyVM/VM統一

📚 ドキュメント更新
- CLAUDE.md: テストスクリプト参考集追加
- CURRENT_TASK.md: Phase 3進捗更新
- python-llvm-priority-rationale.md: 優先順位戦略文書化
- mir-call-unification-master-plan.md: スケジュール最新化

🎯 6種類→1種類: Call/BoxCall/PluginInvoke/ExternCall/NewBox/NewClosure → MirCall統一へ

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Selfhosting Dev
2025-09-24 01:05:44 +09:00
parent 96fd74916c
commit 81211c22ad
29 changed files with 2850 additions and 113 deletions

View File

@ -5,9 +5,11 @@
*/
use super::{Effect, EffectMask, ValueId};
use crate::mir::definitions::Callee; // Import Callee from unified definitions
use crate::mir::types::{
BarrierOp, BinaryOp, CompareOp, ConstValue, MirType, TypeOpKind, UnaryOp, WeakRefOp,
};
// use crate::value::NyashValue; // Commented out to avoid circular dependency
use std::fmt;
@ -60,19 +62,25 @@ pub enum MirInstruction {
Store { value: ValueId, ptr: ValueId },
// === Function Calls ===
/// Call a function
/// `%dst = call %func(%args...)`
/// Call a function with type-safe target resolution
/// `%dst = call %func(%args...)` (legacy)
/// `%dst = call Global("print")(%args...)` (new)
///
/// Phase 1 Migration: Both func and callee fields present
/// - callee: Some(_) -> Use new type-safe resolution (preferred)
/// - callee: None -> Fall back to legacy string-based resolution
Call {
dst: Option<ValueId>,
func: ValueId,
func: ValueId, // Legacy: string-based resolution (deprecated)
callee: Option<Callee>, // New: type-safe resolution (preferred)
args: Vec<ValueId>,
effects: EffectMask,
},
/// Create a function value (FunctionBox) from params/body and optional captures
/// `%dst = function_new [params] {body} [captures...]`
/// `%dst = new_closure [params] {body} [captures...]`
/// Minimal lowering support: captures may be empty; 'me' is optional.
FunctionNew {
NewClosure {
dst: ValueId,
params: Vec<String>,
body: Vec<crate::ast::ASTNode>,
@ -370,7 +378,7 @@ impl MirInstruction {
// Phase 9.7: External Function Calls
MirInstruction::ExternCall { effects, .. } => *effects, // Use provided effect mask
// Function value construction: treat as pure with allocation
MirInstruction::FunctionNew { .. } => EffectMask::PURE.add(Effect::Alloc),
MirInstruction::NewClosure { .. } => EffectMask::PURE.add(Effect::Alloc),
}
}
@ -399,7 +407,7 @@ impl MirInstruction {
| MirInstruction::WeakRef { dst, .. }
| MirInstruction::FutureNew { dst, .. }
| MirInstruction::Await { dst, .. } => Some(*dst),
MirInstruction::FunctionNew { dst, .. } => Some(*dst),
MirInstruction::NewClosure { dst, .. } => Some(*dst),
MirInstruction::Call { dst, .. }
| MirInstruction::BoxCall { dst, .. }
@ -472,7 +480,7 @@ impl MirInstruction {
used.extend(args);
used
}
MirInstruction::FunctionNew { captures, me, .. } => {
MirInstruction::NewClosure { captures, me, .. } => {
let mut used: Vec<ValueId> = Vec::new();
used.extend(captures.iter().map(|(_, v)| *v));
if let Some(m) = me {
@ -576,6 +584,7 @@ impl fmt::Display for MirInstruction {
MirInstruction::Call {
dst,
func,
callee: _, // TODO: Use callee for type-safe resolution display
args,
effects,
} => {