Errors refactoring for the iterpreter

This commit is contained in:
Emmanuel BENOîT 2023-01-04 07:49:28 +01:00
parent 7961a92ad1
commit 743379c516
3 changed files with 50 additions and 40 deletions
src/interpreter

View file

@ -1,4 +1,4 @@
use std::{cell::RefCell, rc::Rc};
use std::{cell::RefCell, fmt::Display, rc::Rc};
use super::Callable;
@ -24,6 +24,18 @@ impl PartialEq for Value {
}
}
impl Display for Value {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Value::Nil => f.write_str("nil"),
Value::Boolean(b) => b.fmt(f),
Value::String(s) => s.fmt(f),
Value::Number(n) => n.fmt(f),
Value::Callable(c) => f.write_str(&c.borrow().to_string()),
}
}
}
impl Value {
/// Check whether a value is truthy or not.
pub fn is_truthy(&self) -> bool {