Interpreter - Class values

This commit is contained in:
Emmanuel BENOîT 2023-01-07 14:15:04 +01:00
parent 6fa335b2f6
commit f834d84365

View file

@ -1,6 +1,6 @@
use std::{cell::RefCell, fmt::Display, rc::Rc}; use std::{cell::RefCell, fmt::Display, rc::Rc};
use super::Callable; use super::{Callable, class::Class};
/// A value being handled by the interpreter. /// A value being handled by the interpreter.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -10,6 +10,7 @@ pub enum Value {
String(String), String(String),
Number(f64), Number(f64),
Callable(Rc<RefCell<dyn Callable>>), Callable(Rc<RefCell<dyn Callable>>),
Class(Class),
} }
impl PartialEq for Value { impl PartialEq for Value {
@ -32,6 +33,7 @@ impl Display for Value {
Value::String(s) => s.fmt(f), Value::String(s) => s.fmt(f),
Value::Number(n) => n.fmt(f), Value::Number(n) => n.fmt(f),
Value::Callable(c) => f.write_str(&c.borrow().to_string()), Value::Callable(c) => f.write_str(&c.borrow().to_string()),
Value::Class(c) => f.write_str(&c.to_string()),
} }
} }
} }