Errors refactoring for the iterpreter
This commit is contained in:
parent
7961a92ad1
commit
743379c516
3 changed files with 50 additions and 40 deletions
src/interpreter
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue