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
|
use crate::native::NativeFunction;
use crate::Chunk;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Primitive {
Integer(i128),
Float(f64),
Bool(bool),
/// Pointer to an object living on heap
Object(u32),
Empty,
}
pub struct Object {
/// If the object has been marked by the VM or not
pub(crate) marked: bool,
pub(crate) typ: ObjectType,
}
impl Object {
pub fn new(typ: ObjectType) -> Self {
Self { marked: false, typ }
}
}
pub enum ObjectType {
Box(Primitive),
String(String),
List(Vec<Primitive>),
Function(Function),
NativeFunction(NativeFunction),
Free { next: usize },
}
pub struct Function {
pub name: Option<String>,
pub chunk: Chunk,
pub arity: u8,
pub returns_value: bool,
}
impl Function {
pub fn root(chunk: Chunk) -> Self {
Self {
name: None,
chunk,
arity: 0,
returns_value: false,
}
}
}
|