From edded5043db96b0bb6c5bb5178d5e3068f17071e Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 15 Feb 2024 16:30:47 -0500 Subject: [PATCH] Fix infintite loop --- src/abstract_tree/expression.rs | 13 +++---------- src/abstract_tree/identifier.rs | 4 ++++ src/abstract_tree/mod.rs | 11 +++-------- src/built_in_identifiers.rs | 16 ++++++++++------ src/interpret.rs | 4 ++++ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/abstract_tree/expression.rs b/src/abstract_tree/expression.rs index 78fa5fd..775bb19 100644 --- a/src/abstract_tree/expression.rs +++ b/src/abstract_tree/expression.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::{ error::{RuntimeError, SyntaxError, ValidationError}, value_node::ValueNode, - AbstractTree, As, Command, Context, Format, FunctionCall, Identifier, Index, Logic, Math, New, + AbstractTree, As, Command, Context, Format, FunctionCall, Identifier, Index, Logic, Math, SyntaxNode, Type, Value, }; @@ -20,7 +20,6 @@ pub enum Expression { Math(Box), Logic(Box), FunctionCall(Box), - New(New), Command(Command), As(Box), } @@ -51,13 +50,11 @@ impl AbstractTree for Expression { "function_call" => Expression::FunctionCall(Box::new(FunctionCall::from_syntax( child, source, _context, )?)), - "new" => Expression::New(New::from_syntax(child, source, _context)?), "command" => Expression::Command(Command::from_syntax(child, source, _context)?), _ => { return Err(SyntaxError::UnexpectedSyntaxNode { - expected: - "value, identifier, index, math, logic, function call, new, as or command" - .to_string(), + expected: "value, identifier, index, math, logic, function call, as or command" + .to_string(), actual: child.kind().to_string(), location: child.start_position(), relevant_source: source[child.byte_range()].to_string(), @@ -76,7 +73,6 @@ impl AbstractTree for Expression { Expression::Logic(logic) => logic.expected_type(_context), Expression::FunctionCall(function_call) => function_call.expected_type(_context), Expression::Index(index) => index.expected_type(_context), - Expression::New(new) => new.expected_type(_context), Expression::Command(command) => command.expected_type(_context), Expression::As(r#as) => r#as.expected_type(_context), } @@ -90,7 +86,6 @@ impl AbstractTree for Expression { Expression::Logic(logic) => logic.validate(_source, _context), Expression::FunctionCall(function_call) => function_call.validate(_source, _context), Expression::Index(index) => index.validate(_source, _context), - Expression::New(new) => new.validate(_source, _context), Expression::Command(command) => command.validate(_source, _context), Expression::As(r#as) => r#as.validate(_source, _context), } @@ -104,7 +99,6 @@ impl AbstractTree for Expression { Expression::Logic(logic) => logic.run(_source, _context), Expression::FunctionCall(function_call) => function_call.run(_source, _context), Expression::Index(index) => index.run(_source, _context), - Expression::New(new) => new.run(_source, _context), Expression::Command(command) => command.run(_source, _context), Expression::As(r#as) => r#as.run(_source, _context), } @@ -120,7 +114,6 @@ impl Format for Expression { Expression::Logic(logic) => logic.format(_output, _indent_level), Expression::FunctionCall(function_call) => function_call.format(_output, _indent_level), Expression::Index(index) => index.format(_output, _indent_level), - Expression::New(new) => new.format(_output, _indent_level), Expression::Command(command) => command.format(_output, _indent_level), Expression::As(r#as) => r#as.format(_output, _indent_level), } diff --git a/src/abstract_tree/identifier.rs b/src/abstract_tree/identifier.rs index e0edd0c..900960b 100644 --- a/src/abstract_tree/identifier.rs +++ b/src/abstract_tree/identifier.rs @@ -31,6 +31,10 @@ impl Identifier { Identifier(Arc::new(key.to_string())) } + pub fn from_raw_parts(arc: Arc) -> Self { + Identifier(arc) + } + pub fn inner(&self) -> &Arc { &self.0 } diff --git a/src/abstract_tree/mod.rs b/src/abstract_tree/mod.rs index 27b19e8..37fe9a3 100644 --- a/src/abstract_tree/mod.rs +++ b/src/abstract_tree/mod.rs @@ -30,7 +30,6 @@ pub mod r#match; pub mod match_pattern; pub mod math; pub mod math_operator; -pub mod new; pub mod statement; pub mod struct_definition; pub mod r#type; @@ -43,8 +42,8 @@ pub use { assignment::*, assignment_operator::*, block::*, command::*, enum_defintion::*, enum_pattern::*, expression::*, function_call::*, function_expression::*, function_node::*, identifier::*, if_else::*, index::*, index_assignment::IndexAssignment, index_expression::*, - logic::*, logic_operator::*, map_node::*, match_pattern::*, math::*, math_operator::*, new::*, - r#as::*, r#for::*, r#match::*, r#type::*, r#while::*, statement::*, struct_definition::*, + logic::*, logic_operator::*, map_node::*, match_pattern::*, math::*, math_operator::*, r#as::*, + r#for::*, r#match::*, r#type::*, r#while::*, statement::*, struct_definition::*, type_definition::*, type_specification::*, value_node::*, }; @@ -120,11 +119,7 @@ impl AbstractTree for Root { let mut value = Value::none(); for statement in &self.statements { - if let Statement::Return(inner_statement) = statement { - return inner_statement.run(source, context); - } else { - value = statement.run(source, context)?; - } + value = statement.run(source, context)?; } Ok(value) diff --git a/src/built_in_identifiers.rs b/src/built_in_identifiers.rs index c25b4b2..c6f5061 100644 --- a/src/built_in_identifiers.rs +++ b/src/built_in_identifiers.rs @@ -1,4 +1,4 @@ -use std::sync::OnceLock; +use std::sync::{Arc, OnceLock}; use enum_iterator::{all, Sequence}; @@ -8,10 +8,10 @@ pub fn all_built_in_identifiers() -> impl Iterator { all() } -const OPTION: OnceLock = OnceLock::new(); -const NONE: OnceLock = OnceLock::new(); +static OPTION: OnceLock = OnceLock::new(); +static NONE: OnceLock = OnceLock::new(); -#[derive(Sequence)] +#[derive(Sequence, Debug)] pub enum BuiltInIdentifier { Option, None, @@ -20,8 +20,12 @@ pub enum BuiltInIdentifier { impl BuiltInIdentifier { pub fn get(&self) -> Identifier { match self { - BuiltInIdentifier::Option => OPTION.get_or_init(|| Identifier::new("Option")).clone(), - BuiltInIdentifier::None => NONE.get_or_init(|| Identifier::new("None")).clone(), + BuiltInIdentifier::Option => OPTION + .get_or_init(|| Identifier::from_raw_parts(Arc::new("Option".to_string()))) + .clone(), + BuiltInIdentifier::None => NONE + .get_or_init(|| Identifier::from_raw_parts(Arc::new("None".to_string()))) + .clone(), } } } diff --git a/src/interpret.rs b/src/interpret.rs index 0e4775d..003a057 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -149,10 +149,14 @@ impl Interpreter { check_for_error(root, source, &mut cursor)?; + println!("abstracting..."); + let abstract_tree = Root::from_syntax(syntax_tree.root_node(), source, &self.context)?; abstract_tree.validate(source, &self.context)?; + println!("{abstract_tree:?}"); + Ok(abstract_tree) }