Phase 10.7 - JIT統計とイベント機能の完成

主要な実装:
- 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>
This commit is contained in:
Moe Charm
2025-08-28 09:26:58 +09:00
parent 99e59e24e2
commit e54561e69f
64 changed files with 4311 additions and 189 deletions

View File

@ -0,0 +1,41 @@
use crate::box_trait::{NyashBox, StringBox, BoolBox, VoidBox, BoxCore, BoxBase};
use std::any::Any;
#[derive(Debug, Clone)]
pub struct JitEventsBox { base: BoxBase }
impl JitEventsBox { pub fn new() -> Self { Self { base: BoxBase::new() } } }
impl BoxCore for JitEventsBox {
fn box_id(&self) -> u64 { self.base.id }
fn parent_type_id(&self) -> Option<std::any::TypeId> { self.base.parent_type_id }
fn fmt_box(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "JitEventsBox") }
fn as_any(&self) -> &dyn Any { self }
fn as_any_mut(&mut self) -> &mut dyn Any { self }
}
impl NyashBox for JitEventsBox {
fn to_string_box(&self) -> StringBox { StringBox::new("JitEventsBox") }
fn equals(&self, other: &dyn NyashBox) -> BoolBox { BoolBox::new(other.as_any().is::<JitEventsBox>()) }
fn type_name(&self) -> &'static str { "JitEventsBox" }
fn clone_box(&self) -> Box<dyn NyashBox> { Box::new(Self { base: self.base.clone() }) }
fn share_box(&self) -> Box<dyn NyashBox> { self.clone_box() }
}
impl JitEventsBox {
pub fn set_path(&self, path: &str) -> Box<dyn NyashBox> {
std::env::set_var("NYASH_JIT_EVENTS_PATH", path);
Box::new(VoidBox::new())
}
pub fn enable(&self, on: bool) -> Box<dyn NyashBox> {
if on { std::env::set_var("NYASH_JIT_EVENTS", "1"); }
else { std::env::remove_var("NYASH_JIT_EVENTS"); }
Box::new(VoidBox::new())
}
pub fn log(&self, kind: &str, function: &str, note_json: &str) -> Box<dyn NyashBox> {
let extra = serde_json::from_str::<serde_json::Value>(note_json).unwrap_or_else(|_| serde_json::json!({"note": note_json}));
crate::jit::events::emit(kind, function, None, None, extra);
Box::new(VoidBox::new())
}
}