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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::error::Error;
use crate::rc_ref::RcRef;
use crate::vm::value::Value;
use crate::vm::value::symbol::{ SymbolRegistry, SymbolRegistryRef, };
use crate::vm::scope::{ Scope, ScopeRef, };
use std::rc::{ Rc, };
use std::cell::{ Cell, Ref, RefMut, RefCell, };
pub type IsolateRef = RcRef<Isolate>;
#[derive(Debug)]
pub struct Isolate {
scope_ref: Option<ScopeRef>,
symbol_register_ref: SymbolRegistryRef,
}
impl Isolate {
pub fn new() -> Self {
let symbol_register_ref = SymbolRegistryRef::new(SymbolRegistry::new());
Isolate {
scope_ref: None,
symbol_register_ref: symbol_register_ref,
}
}
pub fn set_global_scope(&mut self, scope_ref: ScopeRef) {
self.scope_ref = Some(scope_ref);
}
pub fn global(&self) -> &ScopeRef {
match self.scope_ref {
None => panic!("Should set global scope first!"),
Some(ref scope_ref) => scope_ref,
}
}
pub fn symbol_register_ref(&self) -> &SymbolRegistryRef {
&self.symbol_register_ref
}
pub fn run_script(&self, script: &str) -> Result<Value, Error> {
unimplemented!()
}
pub fn run_module(&self, module: &str) -> Result<Value, Error> {
unimplemented!()
}
}
#[test]
fn test_isolate() {
let mut isolate_ref = IsolateRef::new(Isolate::new());
let global_scope_ref = ScopeRef::new(Scope::new(isolate_ref.clone(), None));
isolate_ref.borrow_mut().set_global_scope(global_scope_ref);
}