Interpreter - Split into multiple modules
This commit is contained in:
parent
81b5f27f0a
commit
bf6e150085
3 changed files with 206 additions and 201 deletions
src/interpreter
21
src/interpreter/value.rs
Normal file
21
src/interpreter/value.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
/// A value being handled by the interpreter.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Value {
|
||||
Nil,
|
||||
Boolean(bool),
|
||||
String(String),
|
||||
Number(f64),
|
||||
}
|
||||
|
||||
impl Value {
|
||||
/// Check whether a value is truthy or not.
|
||||
pub fn is_truthy(&self) -> bool {
|
||||
if self == &Value::Nil {
|
||||
false
|
||||
} else if let Value::Boolean(b) = self {
|
||||
*b
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue