aboutsummaryrefslogtreecommitdiff
path: root/crates/sloth_vm/src/value.rs
blob: 773da8916251941a9d9230f83f81d90b8e347989 (plain)
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
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),

    Free { next: usize },
}

pub struct Function {
    pub(crate) name: Option<String>,
    pub(crate) chunk: Chunk,
    pub(crate) arity: u8,
}

impl Function {
    pub(crate) fn root(chunk: Chunk) -> Self {
        Self {
            name: None,
            chunk,
            arity: 0,
        }
    }
}