evaluator
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
pub enum ObjectType {
|
||||
INTEGER,
|
||||
BOOLEAN,
|
||||
NULL,
|
||||
}
|
||||
|
||||
pub trait Object {
|
||||
fn object_type(&self) -> ObjectType;
|
||||
fn inspect(&self) -> String;
|
||||
}
|
||||
|
||||
pub struct Integer {
|
||||
pub value: i64,
|
||||
}
|
||||
|
||||
impl Object for Integer {
|
||||
fn object_type(&self) -> ObjectType {
|
||||
ObjectType::INTEGER
|
||||
}
|
||||
|
||||
fn inspect(&self) -> String {
|
||||
self.value.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Boolean {
|
||||
pub value: bool,
|
||||
}
|
||||
|
||||
impl Object for Boolean {
|
||||
fn object_type(&self) -> ObjectType {
|
||||
ObjectType::BOOLEAN
|
||||
}
|
||||
|
||||
fn inspect(&self) -> String {
|
||||
self.value.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Null;
|
||||
|
||||
impl Object for Null {
|
||||
fn object_type(&self) -> ObjectType {
|
||||
ObjectType::NULL
|
||||
}
|
||||
|
||||
fn inspect(&self) -> String {
|
||||
"null".to_string()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user