diff options
| author | Cody <cody@codyq.dev> | 2023-04-12 07:39:50 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-04-12 07:39:50 -0500 |
| commit | be4294a5c60d24643ba712db4b6b4c9b2586179c (patch) | |
| tree | 22b702d7ba8a466fcc934d6abee4b4d19253736d /crates/sloth_vm/src/value.rs | |
| parent | ee079d193b6644e65543c3fa02dbfcf7b4f2f9c6 (diff) | |
| download | sloth-be4294a5c60d24643ba712db4b6b4c9b2586179c.tar.gz | |
END THIS PAIN AND SUFFERING
Diffstat (limited to 'crates/sloth_vm/src/value.rs')
| -rw-r--r-- | crates/sloth_vm/src/value.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/sloth_vm/src/value.rs b/crates/sloth_vm/src/value.rs new file mode 100644 index 0000000..773da89 --- /dev/null +++ b/crates/sloth_vm/src/value.rs @@ -0,0 +1,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, + } + } +} |
