1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::{any::Any, cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};

use crate::data::Data;
use function::{CallScope, Function};

pub mod block_scope;
pub mod function;

pub type ScopeRef = Rc<RefCell<dyn Scope>>;

pub trait Scope: Debug {
	fn has_function(&self, name: &str) -> bool;
	fn get_function(&self, name: &str) -> Option<Function>;
	fn set_function(&mut self, name: &str, function: Function);
	fn delete_function(&mut self, name: &str);

	fn parent(&self) -> Option<ScopeRef> {
		None
	}

	fn get_call_scope(&self) -> Option<Rc<RefCell<CallScope>>>;
	fn set_return_value(&mut self, value: Data);
	fn get_function_list(&self) -> HashMap<String, Function>;

	fn as_any(&self) -> &dyn Any;
	fn as_mut(&mut self) -> &mut dyn Any;

	fn to_string(&self) -> String {
		String::from("[scope]")
	}
}