From f2e5b8d499e9eb9f0b22355bea5c332dedda7e0b Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 30 Aug 2024 19:58:07 -0400 Subject: [PATCH] Clean up; Fix tests --- dust-lang/src/context.rs | 2 +- dust-lang/src/parser.rs | 5 +++-- dust-lang/src/vm.rs | 33 ++++++++++++++------------------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/dust-lang/src/context.rs b/dust-lang/src/context.rs index 207bdf7..3d1b5c8 100644 --- a/dust-lang/src/context.rs +++ b/dust-lang/src/context.rs @@ -376,7 +376,7 @@ impl Display for ContextError { #[cfg(test)] mod tests { - use crate::{parse, run, Vm}; + use crate::{parse, Vm}; use super::*; diff --git a/dust-lang/src/parser.rs b/dust-lang/src/parser.rs index ffaf8c9..2944fd1 100644 --- a/dust-lang/src/parser.rs +++ b/dust-lang/src/parser.rs @@ -11,7 +11,8 @@ use std::{ }; use crate::{ - ast::*, Context, DustError, Identifier, LexError, Lexer, Token, TokenKind, TokenOwned, Type, + ast::*, core_library, Context, DustError, Identifier, LexError, Lexer, Token, TokenKind, + TokenOwned, Type, }; /// Parses the input into an abstract syntax tree. @@ -110,7 +111,7 @@ impl<'src> Parser<'src> { current_token, current_position, mode: ParserMode::Normal, - context: Context::new(), + context: core_library().create_child(), } } diff --git a/dust-lang/src/vm.rs b/dust-lang/src/vm.rs index 723c7d9..380223e 100644 --- a/dust-lang/src/vm.rs +++ b/dust-lang/src/vm.rs @@ -21,9 +21,9 @@ use crate::{ StructDefinition, StructExpression, }, constructor::ConstructError, - core_library, parse, Analyzer, BuiltInFunctionError, Context, ContextData, ContextError, - DustError, Evaluation, Expression, Function, FunctionCallError, Identifier, ParseError, - StructType, Type, Value, ValueData, ValueError, + parse, Analyzer, BuiltInFunctionError, Context, ContextData, ContextError, DustError, + Evaluation, Expression, Function, FunctionCallError, Identifier, ParseError, StructType, Type, + Value, ValueData, ValueError, }; /// Run the source code and return the result. @@ -1424,7 +1424,7 @@ impl Display for RuntimeError { mod tests { use std::collections::HashMap; - use crate::Struct; + use crate::{AnalysisError, Struct}; use super::*; @@ -1493,13 +1493,12 @@ mod tests { assert_eq!( run(source), - Err(DustError::Runtime { - runtime_error: RuntimeError::UnassociatedIdentifier { - identifier: Identifier::new("x"), - position: (16, 17) - }, + Err(DustError::analysis( + [AnalysisError::UndefinedVariable { + identifier: Node::new(Identifier::new("x"), (16, 17)) + }], source - }) + )) ); } @@ -1509,16 +1508,12 @@ mod tests { assert_eq!( run(source), - Err(DustError::Runtime { - runtime_error: RuntimeError::Expression { - error: Box::new(RuntimeError::UnassociatedIdentifier { - identifier: Identifier::new("x"), - position: (18, 19) - }), - position: (16, 21) - }, + Err(DustError::analysis( + [AnalysisError::UndefinedVariable { + identifier: Node::new(Identifier::new("x"), (18, 19)) + }], source - }) + )) ); }