📚 Phase 12.5 最適化戦略 & Phase 15 セルフホスティング計画

Phase 12.5: MIR15最適化戦略 - コンパイラ丸投げ作戦
- optimization-strategy.txt: 詳細戦略(MIR側は軽量、コンパイラに丸投げ)
- implementation-examples.md: 具体的な実装例
- debug-safety-comparison.md: 現在のDebugBox vs ChatGPT5提案の比較分析

Phase 15: Nyashセルフホスティング - 究極の目標
- self-hosting-plan.txt: 内蔵Craneliftによる実現計画
- technical-details.md: CompilerBox設計とブートストラップ手順
- README.md: セルフホスティングのビジョン

重要な知見:
- LLVM統合完了済み(Phase 11)だが依存が重すぎる
- Craneliftが現実的な選択肢(3-5MB vs LLVM 50-100MB)
- 「コンパイラもBox、すべてがBox」の夢へ

MASTERロードマップ更新済み
This commit is contained in:
Moe Charm
2025-09-02 05:11:10 +09:00
parent c9366d5c54
commit da96bcb906
37 changed files with 2454 additions and 58 deletions

View File

@ -105,6 +105,8 @@ pub fn push_task_scope() {
if let Ok(mut st) = group_stack_cell().write() {
st.push(std::sync::Arc::new(crate::boxes::task_group_box::TaskGroupInner { strong: std::sync::Mutex::new(Vec::new()) }));
}
// Set a fresh cancellation token for this scope (best-effort)
set_current_group_token(CancellationToken::new());
}
/// Pop a task scope. When depth reaches 0, join outstanding futures.
@ -137,6 +139,8 @@ pub fn pop_task_scope() {
join_all_registered_futures(ms);
}
}
// Reset token (best-effort)
set_current_group_token(CancellationToken::new());
}
/// Perform a runtime safepoint and poll the scheduler if available.
@ -174,3 +178,19 @@ pub fn spawn_task_with_token(name: &str, token: crate::runtime::scheduler::Cance
f();
false
}
/// Spawn a delayed task via scheduler if available; returns true if scheduled.
pub fn spawn_task_after(delay_ms: u64, name: &str, f: Box<dyn FnOnce() + Send + 'static>) -> bool {
if let Ok(s) = sched_cell().read() {
if let Some(sched) = s.as_ref() {
sched.spawn_after(delay_ms, name, f);
return true;
}
}
// Fallback: run inline after blocking sleep
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(delay_ms));
f();
});
false
}

View File

@ -468,6 +468,17 @@ impl PluginLoaderV2 {
}
Ok(None)
}
("env.task", "cancelCurrent") => {
let tok = crate::runtime::global_hooks::current_group_token();
tok.cancel();
Ok(None)
}
("env.task", "currentToken") => {
// Return a TokenBox representing current task group's cancellation token
let tok = crate::runtime::global_hooks::current_group_token();
let tb = crate::boxes::token_box::TokenBox::from_token(tok);
Ok(Some(Box::new(tb)))
}
("env.debug", "trace") => {
// Minimal debug trace; prints to stderr when enabled
if std::env::var("NYASH_DEBUG_TRACE").ok().as_deref() == Some("1") {
@ -530,6 +541,21 @@ impl PluginLoaderV2 {
}
Ok(Some(Box::new(crate::boxes::result::NyashResultBox::new_err(Box::new(crate::box_trait::StringBox::new("InvalidArgs"))))))
}
("env.future", "delay") => {
// delay(ms) -> FutureBox resolved to void after ms
use crate::box_trait::NyashBox as _;
let fut = crate::boxes::future::FutureBox::new();
let ms = if let Some(arg0) = args.get(0) {
if let Some(i) = arg0.as_any().downcast_ref::<crate::box_trait::IntegerBox>() { i.value.max(0) as u64 }
else { arg0.to_string_box().value.trim().parse::<i64>().unwrap_or(0).max(0) as u64 }
} else { 0 };
let fut_setter = fut.clone();
let _scheduled = crate::runtime::global_hooks::spawn_task_after(ms, "env.future.delay", Box::new(move || {
fut_setter.set_result(Box::new(crate::box_trait::VoidBox::new()));
}));
crate::runtime::global_hooks::register_future_to_current_group(&fut);
Ok(Some(Box::new(fut)))
}
("env.future", "spawn_instance") => {
// spawn_instance(recv, method_name, args...) -> FutureBox
// If a scheduler is available, schedule the call; else invoke synchronously.