This commit is contained in:
Jeff 2024-06-19 05:08:10 -04:00
parent ed4820a137
commit 51dd918789
22 changed files with 43 additions and 58 deletions

View File

@ -9,7 +9,7 @@ use crate::{
Value, 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct As { pub struct As {
@ -26,7 +26,7 @@ impl As {
} }
} }
impl AbstractNode for As { impl Evaluate for As {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -8,8 +8,7 @@ use crate::{
}; };
use super::{ use super::{
AbstractNode, Evaluation, ExpectedType, Expression, Statement, Type, TypeConstructor, Evaluate, Evaluation, ExpectedType, Expression, Statement, Type, TypeConstructor, WithPosition,
WithPosition,
}; };
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[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> { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> {
let statement_type = self.statement.expected_type(context)?; let statement_type = self.statement.expected_type(context)?;

View File

@ -8,7 +8,7 @@ use crate::{
error::{RuntimeError, RwLockPoisonError, ValidationError}, 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct AsyncBlock { 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> { fn validate(&self, _context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> {
for statement in &self.statements { for statement in &self.statements {
statement.validate(_context, manage_memory)?; statement.validate(_context, manage_memory)?;

View File

@ -5,7 +5,7 @@ use crate::{
error::{RuntimeError, ValidationError}, 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Block { pub struct Block {
@ -26,7 +26,7 @@ impl Block {
} }
} }
impl AbstractNode for Block { impl Evaluate for Block {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -14,7 +14,7 @@ use crate::{
Value, 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum BuiltInFunctionCall { pub enum BuiltInFunctionCall {
@ -26,7 +26,7 @@ pub enum BuiltInFunctionCall {
WriteLine(Expression), WriteLine(Expression),
} }
impl AbstractNode for BuiltInFunctionCall { impl Evaluate for BuiltInFunctionCall {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -7,8 +7,8 @@ use crate::{
}; };
use super::{ use super::{
AbstractNode, As, BuiltInFunctionCall, Evaluation, ExpectedType, FunctionCall, ListIndex, As, BuiltInFunctionCall, Evaluate, Evaluation, ExpectedType, FunctionCall, ListIndex, Logic,
Logic, MapIndex, Math, SourcePosition, Type, ValueNode, WithPosition, MapIndex, Math, SourcePosition, Type, ValueNode, WithPosition,
}; };
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[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> { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> {
match self { match self {
Expression::As(r#as) => r#as.node.validate(context, manage_memory), Expression::As(r#as) => r#as.node.validate(context, manage_memory),

View File

@ -6,7 +6,7 @@ use crate::{
value::ValueInner, 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)] #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct FunctionCall { 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> { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> {
self.function.validate(context, manage_memory)?; self.function.validate(context, manage_memory)?;

View File

@ -6,7 +6,7 @@ use crate::{
value::ValueInner, 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct IfElse { 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> { fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError> {
self.if_expression.validate(context, manage_memory)?; self.if_expression.validate(context, manage_memory)?;
self.if_block.node.validate(context, manage_memory)?; self.if_block.node.validate(context, manage_memory)?;

View File

@ -5,7 +5,7 @@ use crate::{
error::{RuntimeError, ValidationError}, 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct ListIndex { 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> { fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> {
self.collection.validate(context, _manage_memory)?; self.collection.validate(context, _manage_memory)?;
self.index.validate(context, _manage_memory)?; self.index.validate(context, _manage_memory)?;

View File

@ -7,7 +7,7 @@ use crate::{
Value, Value,
}; };
use super::{AbstractNode, Evaluation, ExpectedType, Expression, Type}; use super::{Evaluate, Evaluation, ExpectedType, Expression, Type};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Logic { pub enum Logic {
@ -22,7 +22,7 @@ pub enum Logic {
Not(Expression), Not(Expression),
} }
impl AbstractNode for Logic { impl Evaluate for Logic {
fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> { fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> {
match self { match self {
Logic::Equal(left, right) Logic::Equal(left, right)

View File

@ -5,7 +5,7 @@ use crate::{
error::{RuntimeError, ValidationError}, error::{RuntimeError, ValidationError},
}; };
use super::{AbstractNode, Evaluation, Statement}; use super::{Evaluate, Evaluation, Statement};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Loop { pub struct Loop {
@ -18,7 +18,7 @@ impl Loop {
} }
} }
impl AbstractNode for Loop { impl Evaluate for Loop {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -6,7 +6,7 @@ use crate::{
value::ValueInner, 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct MapIndex { pub struct MapIndex {
@ -23,7 +23,7 @@ impl MapIndex {
} }
} }
impl AbstractNode for MapIndex { impl Evaluate for MapIndex {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -7,7 +7,7 @@ use crate::{
Value, 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Math { pub enum Math {
@ -18,7 +18,7 @@ pub enum Math {
Modulo(Expression, Expression), Modulo(Expression, Expression),
} }
impl AbstractNode for Math { impl Evaluate for Math {
fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> { fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> {
match self { match self {
Math::Add(left, right) => { Math::Add(left, right) => {

View File

@ -189,7 +189,7 @@ impl Index<usize> for AbstractTree {
} }
} }
pub trait AbstractNode: Sized { pub trait Evaluate: Sized {
fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError>; fn validate(&self, context: &mut Context, manage_memory: bool) -> Result<(), ValidationError>;
fn evaluate( fn evaluate(
self, self,

View File

@ -6,8 +6,8 @@ use crate::{
}; };
use super::{ use super::{
AbstractNode, Assignment, AsyncBlock, Block, Evaluation, ExpectedType, Expression, IfElse, Assignment, AsyncBlock, Block, Evaluate, Evaluation, ExpectedType, Expression, IfElse, Loop,
Loop, SourcePosition, StructureDefinition, Type, TypeAssignment, While, WithPosition, SourcePosition, StructureDefinition, Type, TypeAssignment, While, WithPosition,
}; };
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[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( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -6,7 +6,7 @@ use crate::{
identifier::Identifier, identifier::Identifier,
}; };
use super::{AbstractNode, Evaluation, Type, TypeConstructor}; use super::{Evaluate, Evaluation, Type, TypeConstructor};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct StructureDefinition { pub struct StructureDefinition {
@ -20,7 +20,7 @@ impl StructureDefinition {
} }
} }
impl AbstractNode for StructureDefinition { impl Evaluate for StructureDefinition {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -9,7 +9,7 @@ use crate::{
identifier::Identifier, identifier::Identifier,
}; };
use super::{AbstractNode, Evaluation}; use super::{Evaluate, Evaluation};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Type { pub enum Type {
@ -203,7 +203,7 @@ impl Type {
} }
} }
impl AbstractNode for Type { impl Evaluate for Type {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -6,7 +6,7 @@ use crate::{
identifier::Identifier, identifier::Identifier,
}; };
use super::{AbstractNode, Evaluation, TypeConstructor, WithPosition}; use super::{Evaluate, Evaluation, TypeConstructor, WithPosition};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct TypeAssignment { pub struct TypeAssignment {
@ -23,7 +23,7 @@ impl TypeAssignment {
} }
} }
impl AbstractNode for TypeAssignment { impl Evaluate for TypeAssignment {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::{context::Context, error::ValidationError, identifier::Identifier}; 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)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum TypeConstructor { 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<Type, ValidationError> { pub fn construct(self, context: &Context) -> Result<Type, ValidationError> {
let r#type = match self { let r#type = match self {
TypeConstructor::Function(function_type_constructor) => { TypeConstructor::Function(function_type_constructor) => {
@ -114,12 +106,6 @@ impl TypeConstructor {
} }
} }
impl ExpectedType for TypeConstructor {
fn expected_type(&self, _: &mut Context) -> Result<Type, ValidationError> {
Ok(Type::None)
}
}
impl Display for TypeConstructor { impl Display for TypeConstructor {
fn fmt(&self, _: &mut Formatter) -> fmt::Result { fn fmt(&self, _: &mut Formatter) -> fmt::Result {
todo!() todo!()

View File

@ -10,7 +10,7 @@ use crate::{
}; };
use super::{ use super::{
AbstractNode, Block, Evaluation, ExpectedType, Expression, Type, TypeConstructor, WithPosition, Block, Evaluate, Evaluation, ExpectedType, Expression, Type, TypeConstructor, WithPosition,
}; };
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[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> { fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> {
if let ValueNode::Map(map_assignments) = self { if let ValueNode::Map(map_assignments) = self {
for (_identifier, constructor_option, expression) in map_assignments { for (_identifier, constructor_option, expression) in map_assignments {

View File

@ -7,7 +7,7 @@ use crate::{
Value, Value,
}; };
use super::{AbstractNode, Evaluation, Expression, Statement}; use super::{Evaluate, Evaluation, Expression, Statement};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct While { pub struct While {
@ -24,7 +24,7 @@ impl While {
} }
} }
impl AbstractNode for While { impl Evaluate for While {
fn validate( fn validate(
&self, &self,
_context: &mut Context, _context: &mut Context,

View File

@ -14,7 +14,7 @@ use serde::{
}; };
use crate::{ use crate::{
abstract_tree::{AbstractNode, Block, Evaluation, Type, WithPosition}, abstract_tree::{Block, Evaluate, Evaluation, Type, WithPosition},
context::Context, context::Context,
error::{RuntimeError, ValidationError}, error::{RuntimeError, ValidationError},
identifier::Identifier, identifier::Identifier,