From 51dd9187892f97f3968c6bf3039182206bace2a3 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 19 Jun 2024 05:08:10 -0400 Subject: [PATCH] Clean up --- dust-lang/src/abstract_tree/as.rs | 4 ++-- dust-lang/src/abstract_tree/assignment.rs | 5 ++--- dust-lang/src/abstract_tree/async_block.rs | 4 ++-- dust-lang/src/abstract_tree/block.rs | 4 ++-- .../src/abstract_tree/built_in_function_call.rs | 4 ++-- dust-lang/src/abstract_tree/expression.rs | 6 +++--- dust-lang/src/abstract_tree/function_call.rs | 4 ++-- dust-lang/src/abstract_tree/if_else.rs | 4 ++-- dust-lang/src/abstract_tree/list_index.rs | 4 ++-- dust-lang/src/abstract_tree/logic.rs | 4 ++-- dust-lang/src/abstract_tree/loop.rs | 4 ++-- dust-lang/src/abstract_tree/map_index.rs | 4 ++-- dust-lang/src/abstract_tree/math.rs | 4 ++-- dust-lang/src/abstract_tree/mod.rs | 2 +- dust-lang/src/abstract_tree/statement.rs | 6 +++--- .../src/abstract_tree/structure_definition.rs | 4 ++-- dust-lang/src/abstract_tree/type.rs | 4 ++-- dust-lang/src/abstract_tree/type_alias.rs | 4 ++-- dust-lang/src/abstract_tree/type_constructor.rs | 16 +--------------- dust-lang/src/abstract_tree/value_node.rs | 4 ++-- dust-lang/src/abstract_tree/while.rs | 4 ++-- dust-lang/src/value.rs | 2 +- 22 files changed, 43 insertions(+), 58 deletions(-) diff --git a/dust-lang/src/abstract_tree/as.rs b/dust-lang/src/abstract_tree/as.rs index 7cf2558..cc170bd 100644 --- a/dust-lang/src/abstract_tree/as.rs +++ b/dust-lang/src/abstract_tree/as.rs @@ -9,7 +9,7 @@ use crate::{ Value, }; -use super::{AbstractNode, Evaluation, ExpectedType, Expression, Type, TypeConstructor}; +use super::{Evaluate, Evaluation, ExpectedType, Expression, Type, TypeConstructor}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct As { @@ -26,7 +26,7 @@ impl As { } } -impl AbstractNode for As { +impl Evaluate for As { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/assignment.rs b/dust-lang/src/abstract_tree/assignment.rs index 2789b22..2afe6e2 100644 --- a/dust-lang/src/abstract_tree/assignment.rs +++ b/dust-lang/src/abstract_tree/assignment.rs @@ -8,8 +8,7 @@ use crate::{ }; use super::{ - AbstractNode, Evaluation, ExpectedType, Expression, Statement, Type, TypeConstructor, - WithPosition, + Evaluate, Evaluation, ExpectedType, Expression, Statement, Type, TypeConstructor, WithPosition, }; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] @@ -43,7 +42,7 @@ impl Assignment { } } -impl AbstractNode for Assignment { +impl Evaluate for Assignment { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> { let statement_type = self.statement.expected_type(context)?; diff --git a/dust-lang/src/abstract_tree/async_block.rs b/dust-lang/src/abstract_tree/async_block.rs index aa25f32..9638eb7 100644 --- a/dust-lang/src/abstract_tree/async_block.rs +++ b/dust-lang/src/abstract_tree/async_block.rs @@ -8,7 +8,7 @@ use crate::{ error::{RuntimeError, RwLockPoisonError, ValidationError}, }; -use super::{AbstractNode, Evaluation, ExpectedType, Statement, Type}; +use super::{Evaluate, Evaluation, ExpectedType, Statement, Type}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct AsyncBlock { @@ -21,7 +21,7 @@ impl AsyncBlock { } } -impl AbstractNode for AsyncBlock { +impl Evaluate for AsyncBlock { fn validate(&self, _context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> { for statement in &self.statements { statement.validate(_context, manage_memory)?; diff --git a/dust-lang/src/abstract_tree/block.rs b/dust-lang/src/abstract_tree/block.rs index e9d4d72..3371211 100644 --- a/dust-lang/src/abstract_tree/block.rs +++ b/dust-lang/src/abstract_tree/block.rs @@ -5,7 +5,7 @@ use crate::{ error::{RuntimeError, ValidationError}, }; -use super::{AbstractNode, Evaluation, ExpectedType, Statement, Type}; +use super::{Evaluate, Evaluation, ExpectedType, Statement, Type}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct Block { @@ -26,7 +26,7 @@ impl Block { } } -impl AbstractNode for Block { +impl Evaluate for Block { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/built_in_function_call.rs b/dust-lang/src/abstract_tree/built_in_function_call.rs index 51fb8a6..66fc59d 100644 --- a/dust-lang/src/abstract_tree/built_in_function_call.rs +++ b/dust-lang/src/abstract_tree/built_in_function_call.rs @@ -14,7 +14,7 @@ use crate::{ Value, }; -use super::{AbstractNode, Evaluation, ExpectedType, Expression, Type, TypeConstructor}; +use super::{Evaluate, Evaluation, ExpectedType, Expression, Type, TypeConstructor}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub enum BuiltInFunctionCall { @@ -26,7 +26,7 @@ pub enum BuiltInFunctionCall { WriteLine(Expression), } -impl AbstractNode for BuiltInFunctionCall { +impl Evaluate for BuiltInFunctionCall { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/expression.rs b/dust-lang/src/abstract_tree/expression.rs index ce714b1..6d77c73 100644 --- a/dust-lang/src/abstract_tree/expression.rs +++ b/dust-lang/src/abstract_tree/expression.rs @@ -7,8 +7,8 @@ use crate::{ }; use super::{ - AbstractNode, As, BuiltInFunctionCall, Evaluation, ExpectedType, FunctionCall, ListIndex, - Logic, MapIndex, Math, SourcePosition, Type, ValueNode, WithPosition, + As, BuiltInFunctionCall, Evaluate, Evaluation, ExpectedType, FunctionCall, ListIndex, Logic, + MapIndex, Math, SourcePosition, Type, ValueNode, WithPosition, }; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] @@ -40,7 +40,7 @@ impl Expression { } } -impl AbstractNode for Expression { +impl Evaluate for Expression { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> { match self { Expression::As(r#as) => r#as.node.validate(context, manage_memory), diff --git a/dust-lang/src/abstract_tree/function_call.rs b/dust-lang/src/abstract_tree/function_call.rs index 1300923..9fa6fa4 100644 --- a/dust-lang/src/abstract_tree/function_call.rs +++ b/dust-lang/src/abstract_tree/function_call.rs @@ -6,7 +6,7 @@ use crate::{ value::ValueInner, }; -use super::{AbstractNode, Evaluation, ExpectedType, Expression, Type, TypeConstructor}; +use super::{Evaluate, Evaluation, ExpectedType, Expression, Type, TypeConstructor}; #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct FunctionCall { @@ -33,7 +33,7 @@ impl FunctionCall { } } -impl AbstractNode for FunctionCall { +impl Evaluate for FunctionCall { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> { self.function.validate(context, manage_memory)?; diff --git a/dust-lang/src/abstract_tree/if_else.rs b/dust-lang/src/abstract_tree/if_else.rs index 5ae8640..610a02f 100644 --- a/dust-lang/src/abstract_tree/if_else.rs +++ b/dust-lang/src/abstract_tree/if_else.rs @@ -6,7 +6,7 @@ use crate::{ value::ValueInner, }; -use super::{AbstractNode, Block, Evaluation, ExpectedType, Expression, Type, WithPosition}; +use super::{Block, Evaluate, Evaluation, ExpectedType, Expression, Type, WithPosition}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct IfElse { @@ -32,7 +32,7 @@ impl IfElse { } } -impl AbstractNode for IfElse { +impl Evaluate for IfElse { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> { self.if_expression.validate(context, manage_memory)?; self.if_block.node.validate(context, manage_memory)?; diff --git a/dust-lang/src/abstract_tree/list_index.rs b/dust-lang/src/abstract_tree/list_index.rs index 6963cb2..0bbe1e7 100644 --- a/dust-lang/src/abstract_tree/list_index.rs +++ b/dust-lang/src/abstract_tree/list_index.rs @@ -5,7 +5,7 @@ use crate::{ error::{RuntimeError, ValidationError}, }; -use super::{AbstractNode, Evaluation, ExpectedType, Expression, Type, ValueNode, WithPosition}; +use super::{Evaluate, Evaluation, ExpectedType, Expression, Type, ValueNode, WithPosition}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct ListIndex { @@ -22,7 +22,7 @@ impl ListIndex { } } -impl AbstractNode for ListIndex { +impl Evaluate for ListIndex { fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> { self.collection.validate(context, _manage_memory)?; self.index.validate(context, _manage_memory)?; diff --git a/dust-lang/src/abstract_tree/logic.rs b/dust-lang/src/abstract_tree/logic.rs index 28231a2..3397d9b 100644 --- a/dust-lang/src/abstract_tree/logic.rs +++ b/dust-lang/src/abstract_tree/logic.rs @@ -7,7 +7,7 @@ use crate::{ Value, }; -use super::{AbstractNode, Evaluation, ExpectedType, Expression, Type}; +use super::{Evaluate, Evaluation, ExpectedType, Expression, Type}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub enum Logic { @@ -22,7 +22,7 @@ pub enum Logic { Not(Expression), } -impl AbstractNode for Logic { +impl Evaluate for Logic { fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> { match self { Logic::Equal(left, right) diff --git a/dust-lang/src/abstract_tree/loop.rs b/dust-lang/src/abstract_tree/loop.rs index 543e377..1a51b4e 100644 --- a/dust-lang/src/abstract_tree/loop.rs +++ b/dust-lang/src/abstract_tree/loop.rs @@ -5,7 +5,7 @@ use crate::{ error::{RuntimeError, ValidationError}, }; -use super::{AbstractNode, Evaluation, Statement}; +use super::{Evaluate, Evaluation, Statement}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct Loop { @@ -18,7 +18,7 @@ impl Loop { } } -impl AbstractNode for Loop { +impl Evaluate for Loop { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/map_index.rs b/dust-lang/src/abstract_tree/map_index.rs index 440a850..3453bdb 100644 --- a/dust-lang/src/abstract_tree/map_index.rs +++ b/dust-lang/src/abstract_tree/map_index.rs @@ -6,7 +6,7 @@ use crate::{ value::ValueInner, }; -use super::{AbstractNode, Evaluation, ExpectedType, Expression, Type, ValueNode, WithPosition}; +use super::{Evaluate, Evaluation, ExpectedType, Expression, Type, ValueNode, WithPosition}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct MapIndex { @@ -23,7 +23,7 @@ impl MapIndex { } } -impl AbstractNode for MapIndex { +impl Evaluate for MapIndex { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/math.rs b/dust-lang/src/abstract_tree/math.rs index bd69a23..ee2b9bd 100644 --- a/dust-lang/src/abstract_tree/math.rs +++ b/dust-lang/src/abstract_tree/math.rs @@ -7,7 +7,7 @@ use crate::{ Value, }; -use super::{AbstractNode, Evaluation, ExpectedType, Expression, SourcePosition, Type}; +use super::{Evaluate, Evaluation, ExpectedType, Expression, SourcePosition, Type}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub enum Math { @@ -18,7 +18,7 @@ pub enum Math { Modulo(Expression, Expression), } -impl AbstractNode for Math { +impl Evaluate for Math { fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> { match self { Math::Add(left, right) => { diff --git a/dust-lang/src/abstract_tree/mod.rs b/dust-lang/src/abstract_tree/mod.rs index 6356a69..048d247 100644 --- a/dust-lang/src/abstract_tree/mod.rs +++ b/dust-lang/src/abstract_tree/mod.rs @@ -189,7 +189,7 @@ impl Index for AbstractTree { } } -pub trait AbstractNode: Sized { +pub trait Evaluate: Sized { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError>; fn evaluate( self, diff --git a/dust-lang/src/abstract_tree/statement.rs b/dust-lang/src/abstract_tree/statement.rs index 31c3854..4c8e34d 100644 --- a/dust-lang/src/abstract_tree/statement.rs +++ b/dust-lang/src/abstract_tree/statement.rs @@ -6,8 +6,8 @@ use crate::{ }; use super::{ - AbstractNode, Assignment, AsyncBlock, Block, Evaluation, ExpectedType, Expression, IfElse, - Loop, SourcePosition, StructureDefinition, Type, TypeAssignment, While, WithPosition, + Assignment, AsyncBlock, Block, Evaluate, Evaluation, ExpectedType, Expression, IfElse, Loop, + SourcePosition, StructureDefinition, Type, TypeAssignment, While, WithPosition, }; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] @@ -41,7 +41,7 @@ impl Statement { } } -impl AbstractNode for Statement { +impl Evaluate for Statement { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/structure_definition.rs b/dust-lang/src/abstract_tree/structure_definition.rs index 49de88d..24408af 100644 --- a/dust-lang/src/abstract_tree/structure_definition.rs +++ b/dust-lang/src/abstract_tree/structure_definition.rs @@ -6,7 +6,7 @@ use crate::{ identifier::Identifier, }; -use super::{AbstractNode, Evaluation, Type, TypeConstructor}; +use super::{Evaluate, Evaluation, Type, TypeConstructor}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct StructureDefinition { @@ -20,7 +20,7 @@ impl StructureDefinition { } } -impl AbstractNode for StructureDefinition { +impl Evaluate for StructureDefinition { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/type.rs b/dust-lang/src/abstract_tree/type.rs index 35d961b..fe921c2 100644 --- a/dust-lang/src/abstract_tree/type.rs +++ b/dust-lang/src/abstract_tree/type.rs @@ -9,7 +9,7 @@ use crate::{ identifier::Identifier, }; -use super::{AbstractNode, Evaluation}; +use super::{Evaluate, Evaluation}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub enum Type { @@ -203,7 +203,7 @@ impl Type { } } -impl AbstractNode for Type { +impl Evaluate for Type { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/type_alias.rs b/dust-lang/src/abstract_tree/type_alias.rs index e1e8785..326aef5 100644 --- a/dust-lang/src/abstract_tree/type_alias.rs +++ b/dust-lang/src/abstract_tree/type_alias.rs @@ -6,7 +6,7 @@ use crate::{ identifier::Identifier, }; -use super::{AbstractNode, Evaluation, TypeConstructor, WithPosition}; +use super::{Evaluate, Evaluation, TypeConstructor, WithPosition}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct TypeAssignment { @@ -23,7 +23,7 @@ impl TypeAssignment { } } -impl AbstractNode for TypeAssignment { +impl Evaluate for TypeAssignment { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/abstract_tree/type_constructor.rs b/dust-lang/src/abstract_tree/type_constructor.rs index 49764c0..fd952ea 100644 --- a/dust-lang/src/abstract_tree/type_constructor.rs +++ b/dust-lang/src/abstract_tree/type_constructor.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{context::Context, error::ValidationError, identifier::Identifier}; -use super::{ExpectedType, SourcePosition, Type, WithPosition}; +use super::{SourcePosition, Type, WithPosition}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub enum TypeConstructor { @@ -39,14 +39,6 @@ impl TypeConstructor { } } - pub fn validate( - &self, - _context: &mut Context, - _manage_memory: bool, - ) -> Result<(), ValidationError> { - todo!() - } - pub fn construct(self, context: &Context) -> Result { let r#type = match self { TypeConstructor::Function(function_type_constructor) => { @@ -114,12 +106,6 @@ impl TypeConstructor { } } -impl ExpectedType for TypeConstructor { - fn expected_type(&self, _: &mut Context) -> Result { - Ok(Type::None) - } -} - impl Display for TypeConstructor { fn fmt(&self, _: &mut Formatter) -> fmt::Result { todo!() diff --git a/dust-lang/src/abstract_tree/value_node.rs b/dust-lang/src/abstract_tree/value_node.rs index 0899bc0..33b50bf 100644 --- a/dust-lang/src/abstract_tree/value_node.rs +++ b/dust-lang/src/abstract_tree/value_node.rs @@ -10,7 +10,7 @@ use crate::{ }; use super::{ - AbstractNode, Block, Evaluation, ExpectedType, Expression, Type, TypeConstructor, WithPosition, + Block, Evaluate, Evaluation, ExpectedType, Expression, Type, TypeConstructor, WithPosition, }; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -34,7 +34,7 @@ pub enum ValueNode { }, } -impl AbstractNode for ValueNode { +impl Evaluate for ValueNode { fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> { if let ValueNode::Map(map_assignments) = self { for (_identifier, constructor_option, expression) in map_assignments { diff --git a/dust-lang/src/abstract_tree/while.rs b/dust-lang/src/abstract_tree/while.rs index eeea140..cf662d6 100644 --- a/dust-lang/src/abstract_tree/while.rs +++ b/dust-lang/src/abstract_tree/while.rs @@ -7,7 +7,7 @@ use crate::{ Value, }; -use super::{AbstractNode, Evaluation, Expression, Statement}; +use super::{Evaluate, Evaluation, Expression, Statement}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub struct While { @@ -24,7 +24,7 @@ impl While { } } -impl AbstractNode for While { +impl Evaluate for While { fn validate( &self, _context: &mut Context, diff --git a/dust-lang/src/value.rs b/dust-lang/src/value.rs index 15643f6..abe5d2c 100644 --- a/dust-lang/src/value.rs +++ b/dust-lang/src/value.rs @@ -14,7 +14,7 @@ use serde::{ }; use crate::{ - abstract_tree::{AbstractNode, Block, Evaluation, Type, WithPosition}, + abstract_tree::{Block, Evaluate, Evaluation, Type, WithPosition}, context::Context, error::{RuntimeError, ValidationError}, identifier::Identifier,