Phase 12 TypeBox統合ABI設計完了: C ABI + Nyash ABI革命的統合
主な成果: - TypeBox(型情報をBoxとして扱う)による統合ABI設計 - C ABI + Nyash ABIの完全統合仕様書作成 - 3大AI専門家(Gemini/Codex/ChatGPT5)による検証済み - ChatGPT5の10個の安全性改善提案を反映 - README.mdのドキュメント更新(全起点から到達可能) MapBox拡張: - string型キーサポート(従来のi64に加えて) - remove/clear/getOr/keysStr/valuesStr/toJson実装 - keys()/values()のランタイムシムサポート(TypeBox待ち) その他の改善: - Phase 11.9(文法統一化)ドキュメント追加 - Phase 16(FoldLang)ドキュメント追加 - 非同期タイムアウトテスト追加 - 各種ビルド警告(未使用import等)は次のリファクタリングで対応予定 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -112,6 +112,9 @@ impl NyashInterpreter {
|
||||
discard_context: false,
|
||||
};
|
||||
|
||||
// Bind runtime services (GC/scheduler/token scope) to global hooks for async/safepoints
|
||||
crate::runtime::global_hooks::set_from_runtime(&this.runtime);
|
||||
|
||||
// Register MethodBox invoker once (idempotent)
|
||||
self::register_methodbox_invoker();
|
||||
|
||||
@ -149,6 +152,8 @@ impl NyashInterpreter {
|
||||
runtime,
|
||||
discard_context: false,
|
||||
};
|
||||
// Bind runtime services (GC/scheduler/token scope) to global hooks for async/safepoints
|
||||
crate::runtime::global_hooks::set_from_runtime(&this.runtime);
|
||||
self::register_methodbox_invoker();
|
||||
this
|
||||
}
|
||||
|
||||
@ -61,18 +61,27 @@ impl NyashInterpreter {
|
||||
// Main static boxを初期化
|
||||
self.ensure_static_box_initialized("Main")?;
|
||||
|
||||
// Main.main() を呼び出し
|
||||
// Main.main(args?) を呼び出し(引数が1つなら空配列をデフォルト注入)
|
||||
let mut default_args: Vec<ASTNode> = Vec::new();
|
||||
if let Ok(defs) = self.shared.static_box_definitions.read() {
|
||||
if let Some(main_def) = defs.get("Main") {
|
||||
if let Some(m) = main_def.methods.get("main") {
|
||||
if let ASTNode::FunctionDeclaration { params, .. } = m {
|
||||
if params.len() == 1 {
|
||||
default_args.push(ASTNode::New { class: "ArrayBox".to_string(), arguments: vec![], type_arguments: vec![], span: crate::ast::Span::unknown() });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let main_call_ast = ASTNode::MethodCall {
|
||||
object: Box::new(ASTNode::FieldAccess {
|
||||
object: Box::new(ASTNode::Variable {
|
||||
name: "statics".to_string(),
|
||||
span: crate::ast::Span::unknown(),
|
||||
}),
|
||||
object: Box::new(ASTNode::Variable { name: "statics".to_string(), span: crate::ast::Span::unknown() }),
|
||||
field: "Main".to_string(),
|
||||
span: crate::ast::Span::unknown(),
|
||||
}),
|
||||
method: "main".to_string(),
|
||||
arguments: vec![],
|
||||
arguments: default_args,
|
||||
span: crate::ast::Span::unknown(),
|
||||
};
|
||||
|
||||
@ -86,4 +95,3 @@ impl NyashInterpreter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -219,33 +219,50 @@ impl NyashInterpreter {
|
||||
/// nowait文を実行 - 非同期実行(真の非同期実装) - Async execution
|
||||
pub(super) fn execute_nowait(&mut self, variable: &str, expression: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||
use crate::boxes::FutureBox;
|
||||
use std::thread;
|
||||
|
||||
// FutureBoxを作成
|
||||
let future_box = FutureBox::new();
|
||||
let future_box_clone = future_box.clone();
|
||||
// 個別のクローンを用意(スケジュール経路とフォールバック経路で別々に使う)
|
||||
let future_for_sched = future_box.clone();
|
||||
let future_for_thread = future_box.clone();
|
||||
|
||||
// 式をクローンして別スレッドで実行
|
||||
let expr_clone = expression.clone();
|
||||
let shared_state = self.shared.clone();
|
||||
|
||||
// 別スレッドで非同期実行
|
||||
thread::spawn(move || {
|
||||
// 新しいインタープリタインスタンスを作成(SharedStateを使用)
|
||||
let mut async_interpreter = NyashInterpreter::with_shared(shared_state);
|
||||
|
||||
// 式を評価
|
||||
match async_interpreter.execute_expression(&expr_clone) {
|
||||
Ok(result) => {
|
||||
future_box_clone.set_result(result);
|
||||
// 式をクローンしてスケジューラ(なければフォールバック)で実行
|
||||
// それぞれの経路で独立に所有させるためクローンを分けておく
|
||||
let expr_for_sched = expression.clone();
|
||||
let expr_for_thread = expression.clone();
|
||||
let shared_for_sched = self.shared.clone();
|
||||
let shared_for_thread = self.shared.clone();
|
||||
// Phase-2: try scheduler first (bound to current TaskGroup token); fallback to thread
|
||||
let token = crate::runtime::global_hooks::current_group_token();
|
||||
let scheduled = crate::runtime::global_hooks::spawn_task_with_token(
|
||||
"nowait",
|
||||
token,
|
||||
Box::new(move || {
|
||||
// 新しいインタープリタインスタンスを作成(SharedStateを使用)
|
||||
let mut async_interpreter = NyashInterpreter::with_shared(shared_for_sched);
|
||||
// 式を評価
|
||||
match async_interpreter.execute_expression(&expr_for_sched) {
|
||||
Ok(result) => { future_for_sched.set_result(result); }
|
||||
Err(e) => {
|
||||
// エラーをErrorBoxとして設定
|
||||
let error_box = Box::new(ErrorBox::new("RuntimeError", &format!("{:?}", e)));
|
||||
future_for_sched.set_result(error_box);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
// エラーをErrorBoxとして設定
|
||||
let error_box = Box::new(ErrorBox::new("RuntimeError", &format!("{:?}", e)));
|
||||
future_box_clone.set_result(error_box);
|
||||
})
|
||||
);
|
||||
if !scheduled {
|
||||
std::thread::spawn(move || {
|
||||
let mut async_interpreter = NyashInterpreter::with_shared(shared_for_thread);
|
||||
match async_interpreter.execute_expression(&expr_for_thread) {
|
||||
Ok(result) => { future_for_thread.set_result(result); }
|
||||
Err(e) => {
|
||||
let error_box = Box::new(ErrorBox::new("RuntimeError", &format!("{:?}", e)));
|
||||
future_for_thread.set_result(error_box);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// FutureBoxを現在のTaskGroupに登録(暗黙グループ best-effort)
|
||||
crate::runtime::global_hooks::register_future_to_current_group(&future_box);
|
||||
|
||||
Reference in New Issue
Block a user