主要な実装: - PHI(b1)統計追跡: phi_total_slots/phi_b1_slotsをJSON出力 - 関数単位統計API: JitStatsBox.perFunction()で詳細統計取得 - JITイベントシステム: compile/execute/fallback/trapをJSONL形式で記録 - Store/Load命令対応: ローカル変数を含む関数のJIT実行が可能に 新しいBox: - JitStatsBox: JIT統計の取得 - JitConfigBox: JIT設定の管理(将来用) - JitEventsBox: イベントのJSONL出力(将来用) - JitPolicyBox: 実行ポリシー管理(将来用) CLI拡張: - --jit-exec, --jit-stats, --jit-dump等のフラグ追加 - --jit-directモードでの独立JIT実行 - NYASH_JIT_*環境変数によるきめ細かい制御 ドキュメント: - Phase 10.7実装計画の詳細化 - Phase 10.9 (ビルトインBox JIT) の計画追加 - JIT統計JSONスキーマ v1の仕様化 ChatGPT5との共同開発により、JIT基盤が大幅に強化されました。 次はPhase 10.9でビルトインBoxのJIT対応を進め、 Python統合(Phase 10.1)への道を開きます。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
2.2 KiB
Rust
63 lines
2.2 KiB
Rust
//! JIT minimal ABI types independent from VM internals
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub enum JitValue {
|
|
I64(i64),
|
|
F64(f64),
|
|
Bool(bool),
|
|
/// Opaque handle for host objects (future use)
|
|
Handle(u64),
|
|
}
|
|
|
|
impl JitValue {
|
|
pub fn as_i64(&self) -> Option<i64> { if let JitValue::I64(v) = self { Some(*v) } else { None } }
|
|
}
|
|
|
|
/// Adapter between VMValue and JitValue — keeps JIT decoupled from VM internals
|
|
pub mod adapter {
|
|
use super::JitValue;
|
|
use crate::backend::vm::VMValue;
|
|
|
|
pub fn to_jit_values(args: &[VMValue]) -> Vec<JitValue> {
|
|
args.iter().map(|v| match v {
|
|
VMValue::Integer(i) => JitValue::I64(*i),
|
|
VMValue::Float(f) => JitValue::F64(*f),
|
|
VMValue::Bool(b) => JitValue::Bool(*b),
|
|
VMValue::BoxRef(arc) => {
|
|
let h = crate::jit::rt::handles::to_handle(arc.clone());
|
|
JitValue::Handle(h)
|
|
}
|
|
// For now, map others to handle via boxing where reasonable
|
|
VMValue::String(s) => {
|
|
let bx = Box::new(crate::box_trait::StringBox::new(s));
|
|
let bx_dyn: Box<dyn crate::box_trait::NyashBox> = bx;
|
|
let arc: std::sync::Arc<dyn crate::box_trait::NyashBox> = std::sync::Arc::from(bx_dyn);
|
|
let h = crate::jit::rt::handles::to_handle(arc);
|
|
JitValue::Handle(h)
|
|
}
|
|
VMValue::Void => JitValue::Handle(0),
|
|
VMValue::Future(f) => {
|
|
let bx_dyn: Box<dyn crate::box_trait::NyashBox> = Box::new(f.clone());
|
|
let arc: std::sync::Arc<dyn crate::box_trait::NyashBox> = std::sync::Arc::from(bx_dyn);
|
|
let h = crate::jit::rt::handles::to_handle(arc);
|
|
JitValue::Handle(h)
|
|
}
|
|
}).collect()
|
|
}
|
|
|
|
pub fn from_jit_value(v: JitValue) -> VMValue {
|
|
match v {
|
|
JitValue::I64(i) => VMValue::Integer(i),
|
|
JitValue::F64(f) => VMValue::Float(f),
|
|
JitValue::Bool(b) => VMValue::Bool(b),
|
|
JitValue::Handle(h) => {
|
|
if let Some(arc) = crate::jit::rt::handles::get(h) {
|
|
VMValue::BoxRef(arc)
|
|
} else {
|
|
VMValue::Void
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|