Files
hakorune/src/interpreter/state.rs

47 lines
1.8 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::instance_v2::InstanceBox;
use std::collections::{HashMap, HashSet};
use std::sync::{Arc, Mutex, RwLock};
use super::{BoxDeclaration, StaticBoxDefinition};
/// スレッド間で共有される状態
#[derive(Clone)]
pub struct SharedState {
/// 🌍 GlobalBox - すべてのトップレベル関数とグローバル変数を管理
pub global_box: Arc<Mutex<InstanceBox>>,
/// Box宣言のレジストリ読み込みが多いのでRwLock
pub box_declarations: Arc<RwLock<HashMap<String, BoxDeclaration>>>,
/// 🔥 静的関数のレジストリ読み込みが多いのでRwLock
pub static_functions: Arc<RwLock<HashMap<String, HashMap<String, crate::ast::ASTNode>>>>,
/// 🔥 Static Box定義レジストリ遅延初期化用
pub static_box_definitions: Arc<RwLock<HashMap<String, StaticBoxDefinition>>>,
/// 読み込み済みファイル(重複防止)
pub included_files: Arc<Mutex<HashSet<String>>>,
/// includeロード中スタック循環検出用: A -> B -> A を検出)
pub include_stack: Arc<Mutex<Vec<String>>>,
}
impl SharedState {
/// 新しい共有状態を作成
pub fn new() -> Self {
let global_box = InstanceBox::new(
"Global".to_string(),
vec![], // フィールド名(空から始める)
HashMap::new(), // メソッド(グローバル関数)
);
Self {
global_box: Arc::new(Mutex::new(global_box)),
box_declarations: Arc::new(RwLock::new(HashMap::new())),
static_functions: Arc::new(RwLock::new(HashMap::new())),
static_box_definitions: Arc::new(RwLock::new(HashMap::new())),
included_files: Arc::new(Mutex::new(HashSet::new())),
include_stack: Arc::new(Mutex::new(Vec::new())),
}
}
}