rudus/src/value.rs
2024-12-15 17:54:40 -05:00

48 lines
1.0 KiB
Rust

use crate::compiler::Chunk;
use crate::parser::Ast;
use crate::spans::Spanned;
use imbl::{HashMap, Vector};
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Clone, Debug, PartialEq)]
pub struct LBox {
pub name: usize,
pub cell: RefCell<Value>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct LFn {
pub name: &'static str,
pub body: Vec<Spanned<Ast>>,
pub doc: Option<&'static str>,
pub enclosing: Vec<(usize, Value)>,
pub has_run: bool,
pub input: &'static str,
pub src: &'static str,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Value {
Nil,
Boolean(bool),
Keyword(usize), // use an idx, rather than a raw index
Interned(usize),
FnDecl(usize),
String(Rc<String>),
Number(f64),
List(Box<Vector<Value>>),
Dict(Box<HashMap<&'static str, Value>>),
Box(Rc<LBox>),
Fn(Rc<RefCell<LFn>>),
}
impl Value {
fn show(&self, ctx: &Chunk) -> String {
use Value::*;
match &self {
Nil => format!("nil"),
}
}
}