From 2871fd125a282bc0e86431c382d72688ee74edb1 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 24 Mar 2024 15:47:23 -0400 Subject: [PATCH] Pass all tests --- dust-lang/src/abstract_tree/type.rs | 13 ++++++++++++- dust-lang/src/lib.rs | 21 +++++++++++---------- dust-shell/src/cli.rs | 3 +-- dust-shell/src/main.rs | 4 ++-- std/io.ds | 2 +- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/dust-lang/src/abstract_tree/type.rs b/dust-lang/src/abstract_tree/type.rs index 3cd04ff..b110ce5 100644 --- a/dust-lang/src/abstract_tree/type.rs +++ b/dust-lang/src/abstract_tree/type.rs @@ -113,7 +113,18 @@ impl Type { return_type: right_return, }, ) => { - if left_return == right_return && left_parameters == right_parameters { + if left_return.node == right_return.node { + for (left_parameter, right_parameter) in + left_parameters.iter().zip(right_parameters.iter()) + { + if left_parameter.node != right_parameter.node { + return Err(TypeConflict { + actual: other.clone(), + expected: self.clone(), + }); + } + } + return Ok(()); } } diff --git a/dust-lang/src/lib.rs b/dust-lang/src/lib.rs index f9cc274..08e1e3c 100644 --- a/dust-lang/src/lib.rs +++ b/dust-lang/src/lib.rs @@ -19,7 +19,8 @@ pub use value::Value; pub fn interpret<'src>(source_id: &str, source: &str) -> Result, InterpreterError> { let mut interpreter = Interpreter::new(Context::new()); - interpreter.run(Rc::new(source_id.to_string()), Rc::from(source)) + interpreter.load_std()?; + interpreter.run(Rc::from(source_id), Rc::from(source)) } pub fn interpret_without_std( @@ -28,12 +29,12 @@ pub fn interpret_without_std( ) -> Result, InterpreterError> { let mut interpreter = Interpreter::new(Context::new()); - interpreter.run(Rc::new(source_id.to_string()), Rc::from(source)) + interpreter.run(Rc::from(source_id.to_string()), Rc::from(source)) } pub struct Interpreter { context: Context, - sources: Rc, Rc)>>>, + sources: Rc, Rc)>>>, } impl Interpreter { @@ -46,7 +47,7 @@ impl Interpreter { pub fn run( &mut self, - source_id: Rc, + source_id: Rc, source: Rc, ) -> Result, InterpreterError> { let tokens = lex(source.as_ref()).map_err(|errors| InterpreterError { @@ -69,7 +70,7 @@ impl Interpreter { Ok(value_option) } - pub fn run_all, Rc)>>( + pub fn run_all, Rc)>>( &mut self, sources: T, ) -> Result, InterpreterError> { @@ -85,24 +86,24 @@ impl Interpreter { pub fn load_std(&mut self) -> Result, InterpreterError> { self.run_all([ ( - Rc::new("std/io.ds".to_string()), + Rc::from("std/io.ds"), Rc::from(include_str!("../../std/io.ds")), ), ( - Rc::new("std/thread.ds".to_string()), + Rc::from("std/thread.ds"), Rc::from(include_str!("../../std/thread.ds")), ), ]) } - pub fn sources(&self) -> vec::IntoIter<(Rc, Rc)> { + pub fn sources(&self) -> vec::IntoIter<(Rc, Rc)> { self.sources.borrow().clone().into_iter() } } #[derive(Debug, PartialEq)] pub struct InterpreterError { - source_id: Rc, + source_id: Rc, errors: Vec, } @@ -113,7 +114,7 @@ impl InterpreterError { } impl InterpreterError { - pub fn build_reports<'a>(self) -> Vec, Range)>> { + pub fn build_reports<'a>(self) -> Vec, Range)>> { let mut reports = Vec::new(); for error in self.errors { diff --git a/dust-shell/src/cli.rs b/dust-shell/src/cli.rs index 48a1c52..e6b2ba2 100644 --- a/dust-shell/src/cli.rs +++ b/dust-shell/src/cli.rs @@ -80,8 +80,7 @@ pub fn run_shell(context: Context) -> Result<(), io::Error> { continue; } - let run_result = - interpreter.run(Rc::new("input".to_string()), Rc::from(buffer.as_str())); + let run_result = interpreter.run(Rc::from("input"), Rc::from(buffer.as_str())); match run_result { Ok(Some(value)) => { diff --git a/dust-shell/src/main.rs b/dust-shell/src/main.rs index cb07177..e9b4cd5 100644 --- a/dust-shell/src/main.rs +++ b/dust-shell/src/main.rs @@ -49,9 +49,9 @@ fn main() { let (source_id, source) = if let Some(path) = args.path { let source = read_to_string(&path).unwrap(); - (Rc::new(path.to_string()), source) + (Rc::from(path), source) } else if let Some(command) = args.command { - (Rc::new("input".to_string()), command) + (Rc::from("input"), command) } else { match run_shell(context) { Ok(_) => {} diff --git a/std/io.ds b/std/io.ds index 3659f1e..b47d873 100644 --- a/std/io.ds +++ b/std/io.ds @@ -3,7 +3,7 @@ io = { __READ_LINE__() } - write_line = (T)(output: T) none { + write_line = (output: str) none { __WRITE_LINE__(output) } }