Files
hakorune/src/interpreter/async_ops.rs
Moe Charm 53d88157aa Phase 12: 統一TypeBox ABI実装開始 - ChatGPT5による極小コアABI基盤構築
- TypeBox ABI雛形: メソッドスロット管理システム追加
- Type Registry: Array/Map/StringBoxの基本メソッド定義
- Host API: C ABI逆呼び出しシステム実装
- Phase 12ドキュメント整理: 設計文書統合・アーカイブ化
- MIR Builder: クリーンアップと分離実装完了

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-03 05:04:56 +09:00

41 lines
1.6 KiB
Rust

/*!
* Async Operations Module
*
* Extracted from expressions.rs lines 1020-1031 (~11 lines)
* Handles await expression processing for asynchronous operations
* Core philosophy: "Everything is Box" with async support
*/
use super::*;
use crate::boxes::result::NyashResultBox;
use crate::box_trait::StringBox;
impl NyashInterpreter {
/// await式を実行 - 非同期操作の結果を待機
pub(super) fn execute_await(&mut self, expression: &ASTNode) -> Result<Box<dyn NyashBox>, RuntimeError> {
let value = self.execute_expression(expression)?;
// FutureBoxなら協調待機して Result.Ok/Err を返す
if let Some(future) = value.as_any().downcast_ref::<FutureBox>() {
let max_ms: u64 = crate::config::env::await_max_ms();
let start = std::time::Instant::now();
let mut spins = 0usize;
while !future.ready() {
crate::runtime::global_hooks::safepoint_and_poll();
std::thread::yield_now();
spins += 1;
if spins % 1024 == 0 { std::thread::sleep(std::time::Duration::from_millis(1)); }
if start.elapsed() >= std::time::Duration::from_millis(max_ms) {
let err = Box::new(StringBox::new("Timeout"));
return Ok(Box::new(NyashResultBox::new_err(err)));
}
}
let v = future.get();
Ok(Box::new(NyashResultBox::new_ok(v)))
} else {
// FutureBoxでなければ Ok(value) で返す
Ok(Box::new(NyashResultBox::new_ok(value)))
}
}
}