diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2023-04-14 00:25:32 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-14 00:25:32 -0500 |
| commit | 97b7cd10d2bec408cc237e13c61562c810d8fd29 (patch) | |
| tree | 03d4151581277209f3df48c1a49a656c6c32a52b /crates/sloth_vm/src/value.rs | |
| parent | 6b25c191a4522610877898506856bd00cd1fc4d5 (diff) | |
| parent | fa0da150a5a481be3d1de448edb6f23c170da9a9 (diff) | |
| download | sloth-97b7cd10d2bec408cc237e13c61562c810d8fd29.tar.gz | |
Merge pull request #4 from slothlang/vm-basics
Basic VM
Diffstat (limited to 'crates/sloth_vm/src/value.rs')
| -rw-r--r-- | crates/sloth_vm/src/value.rs | 53 |
1 files changed, 53 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..f149c0e --- /dev/null +++ b/crates/sloth_vm/src/value.rs @@ -0,0 +1,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(crate) name: Option<String>, + pub(crate) chunk: Chunk, + pub(crate) arity: u8, + pub(crate) returns_value: bool, +} + +impl Function { + pub(crate) fn root(chunk: Chunk) -> Self { + Self { + name: None, + chunk, + arity: 0, + returns_value: false, + } + } +} |
