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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use std::collections::HashMap;
use std::fmt::Debug;
use gc::{Finalize, Gc, Trace};
use ast::Expr;
use collections::GcLinkedList;
use modules::ExportedModule;
use symbol::Symbol;
use util::GcVoid;
use value::Value;
pub trait Context: Sized {
type BuiltinFunction: Clone + Debug + Finalize + Trace;
type Expr: Clone + Debug + Finalize + Trace;
type ObjectVtable: Clone + Debug + Finalize + Trace;
type UserFunction: Clone + Debug + Finalize + Trace;
type ValueMeta: Clone + Debug + Default + Finalize + Trace;
fn from_expr(expr: Gc<Expr<Self>>) -> Gc<Self::Expr>;
}
pub trait InterpreterContext: Context + Sized {
type RuntimeError: Debug;
fn eval(
expr: Gc<Self::Expr>,
env: &mut GcLinkedList<(Symbol, Gc<Value<Self>>)>,
) -> Result<Gc<Value<Self>>, Self::RuntimeError>;
fn primitives() -> HashMap<Symbol, Gc<Value<Self>>>;
}
pub trait CompilerContext: Context + Sized {
type CompileError: Debug;
fn compile(
main_mod: Symbol,
modules: HashMap<Symbol, ExportedModule<Self>>,
) -> Result<Vec<u8>, Self::CompileError>;
}
pub enum NullContext {}
impl Context for NullContext {
type BuiltinFunction = GcVoid;
type Expr = Expr<Self>;
type ObjectVtable = GcVoid;
type UserFunction = GcVoid;
type ValueMeta = ();
fn from_expr(expr: Gc<Expr<Self>>) -> Gc<Self::Expr> {
expr
}
}