diff --git a/src/evaluator/mod.rs b/src/evaluator/mod.rs index b86efdb..7aa2192 100644 --- a/src/evaluator/mod.rs +++ b/src/evaluator/mod.rs @@ -17,8 +17,8 @@ use crate::object::null::Null; use crate::object::r#macro::quote::Quote; use crate::object::return_value::ReturnValue; use crate::object::string::StringObj; -use crate::object::ObjectType::{ArrayObj, HashObj, IntegerObj}; -use crate::object::{Object, ObjectInterface, ObjectType}; +use crate::object::ObjectType; +use crate::object::{Object, ObjectInterface}; use crate::{FALSE, NULL, TRUE}; use log::trace; use std::collections::BTreeMap; @@ -191,7 +191,7 @@ fn eval_block_statement(block: &BlockStatement, env: &mut Environment) -> anyhow trace!("[eval_block_statement] result is ({:?})", result); match result.clone() { Object::ReturnValue(value) => { - if value.object_type() == ObjectType::ReturnObj { + if value.object_type() == ObjectType::Return { return Ok(value.into()); } } @@ -288,7 +288,7 @@ fn eval_bang_operator_expression(right: Object) -> anyhow::Result { fn eval_minus_prefix_operator_expression(right: Object) -> anyhow::Result { match right { Object::Integer(value) => Ok(Integer::new(-value.value()).into()), - value if value.object_type() != IntegerObj => Ok(Null.into()), + value if value.object_type() != ObjectType::Integer => Ok(Null.into()), _ => unimplemented!(), } } @@ -317,9 +317,9 @@ fn eval_index_expression(left: Object, index: Object) -> anyhow::Result left, index ); - if left.object_type() == ArrayObj && index.object_type() == IntegerObj { + if left.object_type() == ObjectType::Array && index.object_type() == ObjectType::Integer { eval_array_index_expression(left, index) - } else if left.object_type() == HashObj { + } else if left.object_type() == ObjectType::Hash { eval_hash_index_expression(left, index) } else { Err(Error::IndexOperatorNotSupported(left.object_type().to_string()).into()) diff --git a/src/object/array.rs b/src/object/array.rs index a26b0d1..b17bd44 100644 --- a/src/object/array.rs +++ b/src/object/array.rs @@ -50,7 +50,7 @@ impl NodeInterface for Array { impl ObjectInterface for Array { fn object_type(&self) -> ObjectType { - ObjectType::ArrayObj + ObjectType::Array } fn inspect(&self) -> String { diff --git a/src/object/boolean.rs b/src/object/boolean.rs index f58f5e2..99d507b 100644 --- a/src/object/boolean.rs +++ b/src/object/boolean.rs @@ -20,7 +20,7 @@ impl Boolean { impl ObjectInterface for Boolean { fn object_type(&self) -> ObjectType { - ObjectType::BooleanObj + ObjectType::Boolean } fn inspect(&self) -> String { diff --git a/src/object/built_in_function.rs b/src/object/built_in_function.rs index f83b360..3e294d8 100644 --- a/src/object/built_in_function.rs +++ b/src/object/built_in_function.rs @@ -2,8 +2,8 @@ use crate::ast::NodeInterface; use crate::error::Error; use crate::object::array::Array; use crate::object::integer::Integer; -use crate::object::ObjectType::ArrayObj; -use crate::object::{Object, ObjectInterface, ObjectType}; +use crate::object::ObjectType; +use crate::object::{Object, ObjectInterface}; use crate::NULL; use std::fmt::{Display, Formatter}; @@ -63,7 +63,7 @@ pub fn array_first_element(args: Vec) -> anyhow::Result { .into()); } - if args[0].object_type() != ArrayObj { + if args[0].object_type() != ObjectType::Array { return Err(Error::ArgumentFirstMustArray { got: args[0].object_type().to_string(), } @@ -85,7 +85,7 @@ pub fn array_last_element(args: Vec) -> anyhow::Result { .into()); } - if args[0].object_type() != ArrayObj { + if args[0].object_type() != ObjectType::Array { return Err(Error::ArgumentFirstMustArray { got: args[0].object_type().to_string(), } @@ -110,7 +110,7 @@ pub fn array_rest_element(args: Vec) -> anyhow::Result { .into()); } - if args[0].object_type() != ArrayObj { + if args[0].object_type() != ObjectType::Array { return Err(Error::ArgumentFirstMustArray { got: args[0].object_type().to_string(), } @@ -136,7 +136,7 @@ pub fn array_push_element(args: Vec) -> anyhow::Result { .into()); } - if args[0].object_type() != ArrayObj { + if args[0].object_type() != ObjectType::Array { return Err(Error::ArgumentFirstMustArray { got: args[0].object_type().to_string(), } @@ -162,7 +162,7 @@ pub fn puts(args: Vec) -> anyhow::Result { impl ObjectInterface for Builtin { fn object_type(&self) -> ObjectType { - ObjectType::ArrayObj + ObjectType::Array } fn inspect(&self) -> String { diff --git a/src/object/function.rs b/src/object/function.rs index fc7759b..8da71f1 100644 --- a/src/object/function.rs +++ b/src/object/function.rs @@ -50,7 +50,7 @@ impl Display for Function { impl ObjectInterface for Function { fn object_type(&self) -> ObjectType { - ObjectType::FunctionObj + ObjectType::Function } fn inspect(&self) -> String { diff --git a/src/object/hash.rs b/src/object/hash.rs index 42732fc..33af4a5 100644 --- a/src/object/hash.rs +++ b/src/object/hash.rs @@ -46,7 +46,7 @@ impl Display for Hash { impl ObjectInterface for Hash { fn object_type(&self) -> ObjectType { - ObjectType::HashObj + ObjectType::Hash } fn inspect(&self) -> String { diff --git a/src/object/integer.rs b/src/object/integer.rs index ea1e18a..05fccee 100644 --- a/src/object/integer.rs +++ b/src/object/integer.rs @@ -20,7 +20,7 @@ impl Integer { impl ObjectInterface for Integer { fn object_type(&self) -> ObjectType { - ObjectType::IntegerObj + ObjectType::Integer } fn inspect(&self) -> String { diff --git a/src/object/macro/quote.rs b/src/object/macro/quote.rs index e9173f2..898cb6c 100644 --- a/src/object/macro/quote.rs +++ b/src/object/macro/quote.rs @@ -1,7 +1,7 @@ use crate::ast::Node; use crate::ast::NodeInterface; use crate::error::Error; -use crate::object::ObjectType::QueueObj; +use crate::object::ObjectType::Queue; use crate::object::{Object, ObjectInterface, ObjectType}; use std::fmt::{Display, Formatter}; @@ -38,7 +38,7 @@ impl NodeInterface for Quote { impl ObjectInterface for Quote { fn object_type(&self) -> ObjectType { - QueueObj + Queue } fn inspect(&self) -> String { diff --git a/src/object/mod.rs b/src/object/mod.rs index c0a34e8..3c4d267 100644 --- a/src/object/mod.rs +++ b/src/object/mod.rs @@ -25,31 +25,31 @@ pub mod string; #[derive(Debug, PartialEq, Eq)] pub enum ObjectType { - IntegerObj, - BooleanObj, - NullObj, - ReturnObj, - FunctionObj, - StringObj, - BuiltinObj, - ArrayObj, - HashObj, - QueueObj, + Integer, + Boolean, + Null, + Return, + Function, + String, + Builtin, + Array, + Hash, + Queue, } impl Display for ObjectType { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { - Self::IntegerObj => write!(f, "INTEGER"), - Self::BooleanObj => write!(f, "BOOLEAN"), - Self::NullObj => write!(f, "NULL"), - Self::ReturnObj => write!(f, "RETURN"), - Self::FunctionObj => write!(f, "FUNCTION"), - Self::StringObj => write!(f, "STRING"), - Self::BuiltinObj => write!(f, "BUILTIN"), - Self::ArrayObj => write!(f, "ARRAY"), - Self::HashObj => write!(f, "HASH"), - Self::QueueObj => write!(f, "QUOTE"), + Self::Integer => write!(f, "INTEGER"), + Self::Boolean => write!(f, "BOOLEAN"), + Self::Null => write!(f, "NULL"), + Self::Return => write!(f, "RETURN"), + Self::Function => write!(f, "FUNCTION"), + Self::String => write!(f, "STRING"), + Self::Builtin => write!(f, "BUILTIN"), + Self::Array => write!(f, "ARRAY"), + Self::Hash => write!(f, "HASH"), + Self::Queue => write!(f, "QUOTE"), } } } diff --git a/src/object/null.rs b/src/object/null.rs index 5f7470e..b0143fe 100644 --- a/src/object/null.rs +++ b/src/object/null.rs @@ -22,7 +22,7 @@ impl NodeInterface for Null { impl ObjectInterface for Null { fn object_type(&self) -> ObjectType { - ObjectType::NullObj + ObjectType::Null } fn inspect(&self) -> String { diff --git a/src/object/return_value.rs b/src/object/return_value.rs index c279df2..4c8c9d1 100644 --- a/src/object/return_value.rs +++ b/src/object/return_value.rs @@ -34,7 +34,7 @@ impl NodeInterface for ReturnValue { impl ObjectInterface for ReturnValue { fn object_type(&self) -> ObjectType { - ObjectType::ReturnObj + ObjectType::Return } fn inspect(&self) -> String { diff --git a/src/object/string.rs b/src/object/string.rs index b3cba97..c695974 100644 --- a/src/object/string.rs +++ b/src/object/string.rs @@ -26,7 +26,7 @@ impl Display for StringObj { impl ObjectInterface for StringObj { fn object_type(&self) -> ObjectType { - ObjectType::StringObj + ObjectType::String } fn inspect(&self) -> String {