diff --git a/dust-lang/src/chunk/mod.rs b/dust-lang/src/chunk/mod.rs index e7d3495..bde6c2a 100644 --- a/dust-lang/src/chunk/mod.rs +++ b/dust-lang/src/chunk/mod.rs @@ -135,8 +135,8 @@ impl Debug for Chunk { let string = String::from_utf8_lossy(&output); - if cfg!(test) { - f.write_char('\n')?; + if cfg!(debug_assertions) { + f.write_char('\n')?; // Improves readability in Cargo test output } write!(f, "{string}") diff --git a/dust-lang/src/native_function/assertion.rs b/dust-lang/src/native_function/assertion.rs index 7eb5bb4..7fe89d0 100644 --- a/dust-lang/src/native_function/assertion.rs +++ b/dust-lang/src/native_function/assertion.rs @@ -1,15 +1,15 @@ -use std::panic::{self, Location, PanicHookInfo}; +use std::panic; use annotate_snippets::{Level, Renderer, Snippet}; use smallvec::SmallVec; -use crate::{NativeFunctionError, Value, ValueRef, Vm}; +use crate::{DustString, NativeFunctionError, Value, ValueRef, Vm}; pub fn panic( vm: &Vm, arguments: SmallVec<[ValueRef; 4]>, ) -> Result, NativeFunctionError> { - let mut message = String::new(); + let mut message: Option = None; for value_ref in arguments { let string = match value_ref.display(vm) { @@ -17,7 +17,10 @@ pub fn panic( Err(error) => return Err(NativeFunctionError::Vm(Box::new(error))), }; - message.push_str(&string); + match message { + Some(ref mut message) => message.push_str(&string), + None => message = Some(string), + } } let position = vm.current_position(); @@ -33,7 +36,10 @@ pub fn panic( panic::set_hook(Box::new(move |_| { println!("{}", report); - println!("Panic Message: {}", message); + + if let Some(message) = &message { + println!("{}", message); + } })); panic!(); diff --git a/dust-lang/tests/basic.rs b/dust-lang/tests/basic.rs index 5a3018c..442592c 100644 --- a/dust-lang/tests/basic.rs +++ b/dust-lang/tests/basic.rs @@ -36,7 +36,7 @@ fn empty() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }, vec![(Instruction::r#return(false), Span(0, 0))], vec![], @@ -57,23 +57,15 @@ fn parentheses_precedence() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer) + return_type: Type::Integer }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(3, 4) ), ( - Instruction::multiply( - Destination::Register(1), - Argument::Register(0), - Argument::Constant(2) - ), + Instruction::multiply(1, Argument::Register(0), Argument::Constant(2)), Span(8, 9) ), (Instruction::r#return(true), Span(11, 11)), @@ -101,39 +93,23 @@ fn math_operator_precedence() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(2, 3) ), ( - Instruction::multiply( - Destination::Register(1), - Argument::Constant(2), - Argument::Constant(3) - ), + Instruction::multiply(1, Argument::Constant(2), Argument::Constant(3)), Span(10, 11) ), ( - Instruction::divide( - Destination::Register(2), - Argument::Register(1), - Argument::Constant(4) - ), + Instruction::divide(2, Argument::Register(1), Argument::Constant(4)), Span(14, 15) ), ( - Instruction::subtract( - Destination::Register(3), - Argument::Register(0), - Argument::Register(2) - ), + Instruction::subtract(3, Argument::Register(0), Argument::Register(2)), Span(6, 7) ), (Instruction::r#return(true), Span(17, 17)), diff --git a/dust-lang/tests/comparison.rs b/dust-lang/tests/comparison.rs index 095a184..ae19d6c 100644 --- a/dust-lang/tests/comparison.rs +++ b/dust-lang/tests/comparison.rs @@ -11,20 +11,11 @@ fn equal() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean) + return_type: Type::Boolean }, vec![ ( - Instruction::equal(true, Argument::Constant(0), Argument::Constant(1)), - Span(2, 4) - ), - (Instruction::jump(1, true), Span(2, 4)), - ( - Instruction::load_boolean(Destination::Register(0), true, true), - Span(2, 4) - ), - ( - Instruction::load_boolean(Destination::Register(0), false, false), + Instruction::equal(0, true, Argument::Constant(0), Argument::Constant(1)), Span(2, 4) ), (Instruction::r#return(true), Span(6, 6)), @@ -48,20 +39,11 @@ fn greater() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean) + return_type: Type::Boolean }, vec![ ( - Instruction::less_equal(false, Argument::Constant(0), Argument::Constant(1)), - Span(2, 3) - ), - (Instruction::jump(1, true), Span(2, 3)), - ( - Instruction::load_boolean(Destination::Register(0), true, true), - Span(2, 3) - ), - ( - Instruction::load_boolean(Destination::Register(0), false, false), + Instruction::less_equal(0, false, Argument::Constant(0), Argument::Constant(1)), Span(2, 3) ), (Instruction::r#return(true), Span(5, 5)), @@ -85,20 +67,11 @@ fn greater_than_or_equal() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean) + return_type: Type::Boolean }, vec![ ( - Instruction::less(false, Argument::Constant(0), Argument::Constant(1)), - Span(2, 4) - ), - (Instruction::jump(1, true), Span(2, 4)), - ( - Instruction::load_boolean(Destination::Register(0), true, true), - Span(2, 4) - ), - ( - Instruction::load_boolean(Destination::Register(0), false, false), + Instruction::less(0, false, Argument::Constant(0), Argument::Constant(1)), Span(2, 4) ), (Instruction::r#return(true), Span(6, 6)), @@ -122,20 +95,11 @@ fn less_than() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean) + return_type: Type::Boolean }, vec![ ( - Instruction::less(true, Argument::Constant(0), Argument::Constant(1)), - Span(2, 3) - ), - (Instruction::jump(1, true), Span(2, 3)), - ( - Instruction::load_boolean(Destination::Register(0), true, true), - Span(2, 3) - ), - ( - Instruction::load_boolean(Destination::Register(0), false, false), + Instruction::less(0, true, Argument::Constant(0), Argument::Constant(1)), Span(2, 3) ), (Instruction::r#return(true), Span(5, 5)), @@ -159,20 +123,11 @@ fn less_than_or_equal() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean) + return_type: Type::Boolean }, vec![ ( - Instruction::less_equal(true, Argument::Constant(0), Argument::Constant(1)), - Span(2, 4) - ), - (Instruction::jump(1, true), Span(2, 4)), - ( - Instruction::load_boolean(Destination::Register(0), true, true), - Span(2, 4) - ), - ( - Instruction::load_boolean(Destination::Register(0), false, false), + Instruction::less_equal(0, true, Argument::Constant(0), Argument::Constant(1)), Span(2, 4) ), (Instruction::r#return(true), Span(6, 6)), @@ -196,20 +151,11 @@ fn not_equal() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean) + return_type: Type::Boolean }, vec![ ( - Instruction::equal(false, Argument::Constant(0), Argument::Constant(1)), - Span(2, 4) - ), - (Instruction::jump(1, true), Span(2, 4)), - ( - Instruction::load_boolean(Destination::Register(0), true, true), - Span(2, 4) - ), - ( - Instruction::load_boolean(Destination::Register(0), false, false), + Instruction::equal(0, false, Argument::Constant(0), Argument::Constant(1)), Span(2, 4) ), (Instruction::r#return(true), Span(6, 6)), diff --git a/dust-lang/tests/functions.rs b/dust-lang/tests/functions.rs index 419361b..1ffdcfa 100644 --- a/dust-lang/tests/functions.rs +++ b/dust-lang/tests/functions.rs @@ -1,4 +1,5 @@ use dust_lang::*; +use smallvec::smallvec; #[test] fn function() { @@ -11,27 +12,23 @@ fn function() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Function(FunctionType { + return_type: Type::function(FunctionType { type_parameters: None, - value_parameters: Some(vec![(0, Type::Integer), (1, Type::Integer)]), - return_type: Box::new(Type::Integer), - })) + value_parameters: Some(smallvec![(0, Type::Integer), (1, Type::Integer)]), + return_type: Type::Integer, + }) }, vec![ ( - Instruction::add( - Destination::Register(2), - Argument::Local(0), - Argument::Local(1) - ), + Instruction::add(2, Argument::Register(0), Argument::Register(1)), Span(30, 31) ), (Instruction::r#return(true), Span(34, 35)), ], vec![ConcreteValue::string("a"), ConcreteValue::string("b"),], vec![ - Local::new(0, Type::Integer, false, Scope::default()), - Local::new(1, Type::Integer, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()) ] )))) ); @@ -48,25 +45,13 @@ fn function_call() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer) + return_type: Type::Integer }, vec![ - ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(0, 35) - ), - ( - Instruction::load_constant(Destination::Register(1), 1, false), - Span(36, 37) - ), - ( - Instruction::load_constant(Destination::Register(2), 2, false), - Span(39, 40) - ), - ( - Instruction::call(Destination::Register(3), Argument::Constant(0), 2), - Span(35, 41) - ), + (Instruction::load_constant(0, 0, false), Span(0, 35)), + (Instruction::load_constant(1, 1, false), Span(36, 37)), + (Instruction::load_constant(2, 2, false), Span(39, 40)), + (Instruction::call(3, Argument::Constant(0), 2), Span(35, 41)), (Instruction::r#return(true), Span(41, 41)), ], vec![ @@ -74,24 +59,20 @@ fn function_call() { None, FunctionType { type_parameters: None, - value_parameters: Some(vec![(0, Type::Integer), (1, Type::Integer)]), - return_type: Box::new(Type::Integer) + value_parameters: Some(smallvec![(0, Type::Integer), (1, Type::Integer)]), + return_type: Type::Integer }, vec![ ( - Instruction::add( - Destination::Register(2), - Argument::Local(0), - Argument::Local(1) - ), + Instruction::add(2, Argument::Register(0), Argument::Register(1)), Span(30, 31) ), (Instruction::r#return(true), Span(34, 35)), ], vec![ConcreteValue::string("a"), ConcreteValue::string("b"),], vec![ - Local::new(0, Type::Integer, false, Scope::default()), - Local::new(1, Type::Integer, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()) ] )), ConcreteValue::Integer(1), @@ -115,14 +96,10 @@ fn function_declaration() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }, vec![ - ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(0, 40) - ), - (Instruction::define_local(0, 0, false), Span(3, 6)), + (Instruction::load_constant(0, 0, false), Span(0, 40)), (Instruction::r#return(false), Span(40, 40)) ], vec![ @@ -130,38 +107,25 @@ fn function_declaration() { Some("add".into()), FunctionType { type_parameters: None, - value_parameters: Some(vec![(0, Type::Integer), (1, Type::Integer)]), - return_type: Box::new(Type::Integer) + value_parameters: Some(smallvec![(0, Type::Integer), (1, Type::Integer)]), + return_type: Type::Integer }, vec![ ( - Instruction::add( - Destination::Register(2), - Argument::Local(0), - Argument::Local(1) - ), + Instruction::add(2, Argument::Register(0), Argument::Register(1)), Span(35, 36) ), (Instruction::r#return(true), Span(39, 40)), ], vec![ConcreteValue::string("a"), ConcreteValue::string("b")], vec![ - Local::new(0, Type::Integer, false, Scope::default()), - Local::new(1, Type::Integer, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()) ] )), ConcreteValue::string("add"), ], - vec![Local::new( - 1, - Type::Function(FunctionType { - type_parameters: None, - value_parameters: Some(vec![(0, Type::Integer), (1, Type::Integer)]), - return_type: Box::new(Type::Integer), - }), - false, - Scope::default(), - ),], + vec![Local::new(1, 0, false, Scope::default(),),], )), ); diff --git a/dust-lang/tests/lists.rs b/dust-lang/tests/lists.rs index aa6eaac..b8d8aac 100644 --- a/dust-lang/tests/lists.rs +++ b/dust-lang/tests/lists.rs @@ -11,13 +11,10 @@ fn empty_list() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::List(Box::new(Type::Any))), + return_type: Type::List(Box::new(Type::Any)), }, vec![ - ( - Instruction::load_list(Destination::Register(0), 0), - Span(0, 2) - ), + (Instruction::load_list(0, 0), Span(0, 2)), (Instruction::r#return(true), Span(2, 2)), ], vec![], @@ -39,25 +36,13 @@ fn list() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::List(Box::new(Type::Integer))), + return_type: Type::List(Box::new(Type::Integer)), }, vec![ - ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(1, 2) - ), - ( - Instruction::load_constant(Destination::Register(1), 1, false), - Span(4, 5) - ), - ( - Instruction::load_constant(Destination::Register(2), 2, false), - Span(7, 8) - ), - ( - Instruction::load_list(Destination::Register(3), 0), - Span(0, 9) - ), + (Instruction::load_constant(0, 0, false), Span(1, 2)), + (Instruction::load_constant(1, 1, false), Span(4, 5)), + (Instruction::load_constant(2, 2, false), Span(7, 8)), + (Instruction::load_list(3, 0), Span(0, 9)), (Instruction::r#return(true), Span(9, 9)), ], vec![ @@ -90,42 +75,24 @@ fn list_with_complex_expression() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::List(Box::new(Type::Integer))), + return_type: Type::List(Box::new(Type::Integer)), }, vec![ + (Instruction::load_constant(0, 0, false), Span(1, 2)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(1, 2) - ), - ( - Instruction::add( - Destination::Register(1), - Argument::Constant(1), - Argument::Constant(2) - ), + Instruction::add(1, Argument::Constant(1), Argument::Constant(2)), Span(6, 7) ), ( - Instruction::multiply( - Destination::Register(2), - Argument::Constant(3), - Argument::Constant(4) - ), + Instruction::multiply(2, Argument::Constant(3), Argument::Constant(4)), Span(14, 15) ), ( - Instruction::subtract( - Destination::Register(3), - Argument::Register(1), - Argument::Register(2) - ), + Instruction::subtract(3, Argument::Register(1), Argument::Register(2)), Span(10, 11) ), (Instruction::close(1, 3), Span(17, 18)), - ( - Instruction::load_list(Destination::Register(4), 0), - Span(0, 18) - ), + (Instruction::load_list(4, 0), Span(0, 18)), (Instruction::r#return(true), Span(18, 18)), ], vec![ @@ -159,29 +126,16 @@ fn list_with_simple_expression() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::List(Box::new(Type::Integer))), + return_type: Type::List(Box::new(Type::Integer)), }, vec![ + (Instruction::load_constant(0, 0, false), Span(1, 2)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(1, 2) - ), - ( - Instruction::add( - Destination::Register(1), - Argument::Constant(1), - Argument::Constant(2) - ), + Instruction::add(1, Argument::Constant(1), Argument::Constant(2)), Span(6, 7) ), - ( - Instruction::load_constant(Destination::Register(2), 3, false), - Span(11, 12) - ), - ( - Instruction::load_list(Destination::Register(3), 0), - Span(0, 13) - ), + (Instruction::load_constant(2, 3, false), Span(11, 12)), + (Instruction::load_list(3, 0), Span(0, 13)), (Instruction::r#return(true), Span(13, 13)), ], vec![ diff --git a/dust-lang/tests/logic_and.rs b/dust-lang/tests/logic_and.rs index 7c56b07..ec5920e 100644 --- a/dust-lang/tests/logic_and.rs +++ b/dust-lang/tests/logic_and.rs @@ -11,19 +11,13 @@ fn true_and_true() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(0, 4) - ), + (Instruction::load_boolean(0, true, false), Span(0, 4)), (Instruction::test(Argument::Register(0), true), Span(5, 7)), (Instruction::jump(1, true), Span(5, 7)), - ( - Instruction::load_boolean(Destination::Register(1), true, false), - Span(8, 12) - ), + (Instruction::load_boolean(1, true, false), Span(8, 12)), (Instruction::r#return(true), Span(12, 12)), ], vec![], @@ -45,19 +39,13 @@ fn false_and_false() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), false, false), - Span(0, 5) - ), + (Instruction::load_boolean(0, false, false), Span(0, 5)), (Instruction::test(Argument::Register(0), true), Span(6, 8)), (Instruction::jump(1, true), Span(6, 8)), - ( - Instruction::load_boolean(Destination::Register(1), false, false), - Span(9, 14) - ), + (Instruction::load_boolean(1, false, false), Span(9, 14)), (Instruction::r#return(true), Span(14, 14)), ], vec![], @@ -79,19 +67,13 @@ fn false_and_true() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), false, false), - Span(0, 5) - ), + (Instruction::load_boolean(0, false, false), Span(0, 5)), (Instruction::test(Argument::Register(0), true), Span(6, 8)), (Instruction::jump(1, true), Span(6, 8)), - ( - Instruction::load_boolean(Destination::Register(1), true, false), - Span(9, 13) - ), + (Instruction::load_boolean(1, true, false), Span(9, 13)), (Instruction::r#return(true), Span(13, 13)), ], vec![], @@ -113,19 +95,13 @@ fn true_and_false() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(0, 4) - ), + (Instruction::load_boolean(0, true, false), Span(0, 4)), (Instruction::test(Argument::Register(0), true), Span(5, 7)), (Instruction::jump(1, true), Span(5, 7)), - ( - Instruction::load_boolean(Destination::Register(1), false, false), - Span(8, 13) - ), + (Instruction::load_boolean(1, false, false), Span(8, 13)), (Instruction::r#return(true), Span(13, 13)), ], vec![], diff --git a/dust-lang/tests/logic_and_and.rs b/dust-lang/tests/logic_and_and.rs index afb51f2..352753b 100644 --- a/dust-lang/tests/logic_and_and.rs +++ b/dust-lang/tests/logic_and_and.rs @@ -11,25 +11,16 @@ fn true_and_true_and_true() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(0, 4) - ), + (Instruction::load_boolean(0, true, false), Span(0, 4)), (Instruction::test(Argument::Register(0), true), Span(5, 7)), (Instruction::jump(1, true), Span(5, 7)), - ( - Instruction::load_boolean(Destination::Register(1), true, false), - Span(8, 12) - ), + (Instruction::load_boolean(1, true, false), Span(8, 12)), (Instruction::test(Argument::Register(1), true), Span(13, 15)), (Instruction::jump(1, true), Span(13, 15)), - ( - Instruction::load_boolean(Destination::Register(2), true, false), - Span(16, 20) - ), + (Instruction::load_boolean(2, true, false), Span(16, 20)), (Instruction::r#return(true), Span(20, 20)), ], vec![], diff --git a/dust-lang/tests/logic_or.rs b/dust-lang/tests/logic_or.rs index 11f2bc2..b62ed74 100644 --- a/dust-lang/tests/logic_or.rs +++ b/dust-lang/tests/logic_or.rs @@ -11,19 +11,13 @@ fn true_or_false() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(0, 4) - ), + (Instruction::load_boolean(0, true, false), Span(0, 4)), (Instruction::test(Argument::Register(0), false), Span(5, 7)), (Instruction::jump(1, true), Span(5, 7)), - ( - Instruction::load_boolean(Destination::Register(1), false, false), - Span(8, 13) - ), + (Instruction::load_boolean(1, false, false), Span(8, 13)), (Instruction::r#return(true), Span(13, 13)), ], vec![], diff --git a/dust-lang/tests/logic_variables.rs b/dust-lang/tests/logic_variables.rs index e2519c8..208740a 100644 --- a/dust-lang/tests/logic_variables.rs +++ b/dust-lang/tests/logic_variables.rs @@ -11,35 +11,21 @@ fn true_and_true() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(8, 12) - ), - (Instruction::define_local(0, 0, false), Span(4, 5)), - ( - Instruction::load_boolean(Destination::Register(1), true, false), - Span(22, 26) - ), - (Instruction::define_local(1, 1, false), Span(18, 19)), - ( - Instruction::get_local(Destination::Register(2), 0), - Span(28, 29) - ), - (Instruction::test(Argument::Local(0), true), Span(30, 32)), + (Instruction::load_boolean(0, true, false), Span(8, 12)), + (Instruction::load_boolean(1, true, false), Span(22, 26)), + (Instruction::get_local(2, 0), Span(28, 29)), + (Instruction::test(Argument::Register(0), true), Span(30, 32)), (Instruction::jump(1, true), Span(30, 32)), - ( - Instruction::get_local(Destination::Register(3), 1), - Span(33, 34) - ), + (Instruction::get_local(3, 1), Span(33, 34)), (Instruction::r#return(true), Span(34, 34)), ], vec![ConcreteValue::string("a"), ConcreteValue::string("b")], vec![ - Local::new(0, Type::Boolean, false, Scope::default()), - Local::new(1, Type::Boolean, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()) ] )) ); @@ -58,35 +44,21 @@ fn false_and_false() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), false, false), - Span(8, 13) - ), - (Instruction::define_local(0, 0, false), Span(4, 5)), - ( - Instruction::load_boolean(Destination::Register(1), false, false), - Span(23, 28) - ), - (Instruction::define_local(1, 1, false), Span(19, 20)), - ( - Instruction::get_local(Destination::Register(2), 0), - Span(30, 31) - ), - (Instruction::test(Argument::Local(0), true), Span(32, 34)), + (Instruction::load_boolean(0, false, false), Span(8, 13)), + (Instruction::load_boolean(1, false, false), Span(23, 28)), + (Instruction::get_local(2, 0), Span(30, 31)), + (Instruction::test(Argument::Register(0), true), Span(32, 34)), (Instruction::jump(1, true), Span(32, 34)), - ( - Instruction::get_local(Destination::Register(3), 1), - Span(35, 36) - ), + (Instruction::get_local(3, 1), Span(35, 36)), (Instruction::r#return(true), Span(36, 36)), ], vec![ConcreteValue::string("a"), ConcreteValue::string("b")], vec![ - Local::new(0, Type::Boolean, false, Scope::default()), - Local::new(1, Type::Boolean, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 0, false, Scope::default()) ] )) ); @@ -105,35 +77,21 @@ fn true_and_false() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(8, 12) - ), - (Instruction::define_local(0, 0, false), Span(4, 5)), - ( - Instruction::load_boolean(Destination::Register(1), false, false), - Span(22, 27) - ), - (Instruction::define_local(1, 1, false), Span(18, 19)), - ( - Instruction::get_local(Destination::Register(2), 0), - Span(29, 30) - ), - (Instruction::test(Argument::Local(0), true), Span(31, 33)), + (Instruction::load_boolean(0, true, false), Span(8, 12)), + (Instruction::load_boolean(1, false, false), Span(22, 27)), + (Instruction::get_local(2, 0), Span(29, 30)), + (Instruction::test(Argument::Register(0), true), Span(31, 33)), (Instruction::jump(1, true), Span(31, 33)), - ( - Instruction::get_local(Destination::Register(3), 1), - Span(34, 35) - ), + (Instruction::get_local(3, 1), Span(34, 35)), (Instruction::r#return(true), Span(35, 35)), ], vec![ConcreteValue::string("a"), ConcreteValue::string("b")], vec![ - Local::new(0, Type::Boolean, false, Scope::default()), - Local::new(1, Type::Boolean, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()) ] )) ); @@ -152,35 +110,21 @@ fn false_and_true() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), false, false), - Span(8, 13) - ), - (Instruction::define_local(0, 0, false), Span(4, 5)), - ( - Instruction::load_boolean(Destination::Register(1), true, false), - Span(23, 27) - ), - (Instruction::define_local(1, 1, false), Span(19, 20)), - ( - Instruction::get_local(Destination::Register(2), 0), - Span(29, 30) - ), - (Instruction::test(Argument::Local(0), true), Span(31, 33)), + (Instruction::load_boolean(0, false, false), Span(8, 13)), + (Instruction::load_boolean(1, true, false), Span(23, 27)), + (Instruction::get_local(2, 0), Span(29, 30)), + (Instruction::test(Argument::Register(0), true), Span(31, 33)), (Instruction::jump(1, true), Span(31, 33)), - ( - Instruction::get_local(Destination::Register(3), 1), - Span(34, 35) - ), + (Instruction::get_local(3, 1), Span(34, 35)), (Instruction::r#return(true), Span(35, 35)), ], vec![ConcreteValue::string("a"), ConcreteValue::string("b")], vec![ - Local::new(0, Type::Boolean, false, Scope::default()), - Local::new(1, Type::Boolean, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()) ] )) ); @@ -199,40 +143,19 @@ fn true_and_true_and_true() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(8, 12) - ), - (Instruction::define_local(0, 0, false), Span(4, 5)), - ( - Instruction::load_boolean(Destination::Register(1), true, false), - Span(22, 26) - ), - (Instruction::define_local(1, 1, false), Span(18, 19)), - ( - Instruction::load_boolean(Destination::Register(2), true, false), - Span(36, 40) - ), - (Instruction::define_local(2, 2, false), Span(32, 33)), - ( - Instruction::get_local(Destination::Register(3), 0), - Span(42, 43) - ), - (Instruction::test(Argument::Local(0), true), Span(44, 46)), + (Instruction::load_boolean(0, true, false), Span(8, 12)), + (Instruction::load_boolean(1, true, false), Span(22, 26)), + (Instruction::load_boolean(2, true, false), Span(36, 40)), + (Instruction::get_local(3, 0), Span(42, 43)), + (Instruction::test(Argument::Register(0), true), Span(44, 46)), (Instruction::jump(1, true), Span(44, 46)), - ( - Instruction::get_local(Destination::Register(4), 1), - Span(47, 48) - ), - (Instruction::test(Argument::Local(1), true), Span(49, 51)), + (Instruction::get_local(4, 1), Span(47, 48)), + (Instruction::test(Argument::Register(1), true), Span(49, 51)), (Instruction::jump(1, true), Span(49, 51)), - ( - Instruction::get_local(Destination::Register(5), 2), - Span(52, 53) - ), + (Instruction::get_local(5, 2), Span(52, 53)), (Instruction::r#return(true), Span(53, 53)), ], vec![ @@ -241,9 +164,9 @@ fn true_and_true_and_true() { ConcreteValue::string("c") ], vec![ - Local::new(0, Type::Boolean, false, Scope::default()), - Local::new(1, Type::Boolean, false, Scope::default()), - Local::new(2, Type::Boolean, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()), + Local::new(2, 2, false, Scope::default()) ] )) ); @@ -262,40 +185,19 @@ fn false_and_false_and_false() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), false, false), - Span(8, 13) - ), - (Instruction::define_local(0, 0, false), Span(4, 5)), - ( - Instruction::load_boolean(Destination::Register(1), false, false), - Span(23, 28) - ), - (Instruction::define_local(1, 1, false), Span(19, 20)), - ( - Instruction::load_boolean(Destination::Register(2), false, false), - Span(38, 43) - ), - (Instruction::define_local(2, 2, false), Span(34, 35)), - ( - Instruction::get_local(Destination::Register(3), 0), - Span(45, 46) - ), - (Instruction::test(Argument::Local(0), true), Span(47, 49)), + (Instruction::load_boolean(0, false, false), Span(8, 13)), + (Instruction::load_boolean(1, false, false), Span(23, 28)), + (Instruction::load_boolean(2, false, false), Span(38, 43)), + (Instruction::get_local(3, 0), Span(45, 46)), + (Instruction::test(Argument::Register(0), true), Span(47, 49)), (Instruction::jump(1, true), Span(47, 49)), - ( - Instruction::get_local(Destination::Register(4), 1), - Span(50, 51) - ), - (Instruction::test(Argument::Local(1), true), Span(52, 54)), + (Instruction::get_local(4, 1), Span(50, 51)), + (Instruction::test(Argument::Register(1), true), Span(52, 54)), (Instruction::jump(1, true), Span(52, 54)), - ( - Instruction::get_local(Destination::Register(5), 2), - Span(55, 56) - ), + (Instruction::get_local(5, 2), Span(55, 56)), (Instruction::r#return(true), Span(56, 56)), ], vec![ @@ -304,9 +206,9 @@ fn false_and_false_and_false() { ConcreteValue::string("c") ], vec![ - Local::new(0, Type::Boolean, false, Scope::default()), - Local::new(1, Type::Boolean, false, Scope::default()), - Local::new(2, Type::Boolean, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()), + Local::new(2, 2, false, Scope::default()) ] )) ); @@ -325,40 +227,22 @@ fn true_and_true_or_false() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(8, 12) - ), - (Instruction::define_local(0, 0, false), Span(4, 5)), - ( - Instruction::load_boolean(Destination::Register(1), true, false), - Span(22, 26) - ), - (Instruction::define_local(1, 1, false), Span(18, 19)), - ( - Instruction::load_boolean(Destination::Register(2), false, false), - Span(36, 41) - ), - (Instruction::define_local(2, 2, false), Span(32, 33)), - ( - Instruction::get_local(Destination::Register(3), 0), - Span(43, 44) - ), - (Instruction::test(Argument::Local(0), true), Span(45, 47)), + (Instruction::load_boolean(0, true, false), Span(8, 12)), + (Instruction::load_boolean(1, true, false), Span(22, 26)), + (Instruction::load_boolean(2, false, false), Span(36, 41)), + (Instruction::get_local(3, 0), Span(43, 44)), + (Instruction::test(Argument::Register(0), true), Span(45, 47)), (Instruction::jump(1, true), Span(45, 47)), + (Instruction::get_local(4, 1), Span(48, 49)), ( - Instruction::get_local(Destination::Register(4), 1), - Span(48, 49) + Instruction::test(Argument::Register(1), false), + Span(50, 52) ), - (Instruction::test(Argument::Local(1), false), Span(50, 52)), (Instruction::jump(1, true), Span(50, 52)), - ( - Instruction::get_local(Destination::Register(5), 2), - Span(53, 54) - ), + (Instruction::get_local(5, 2), Span(53, 54)), (Instruction::r#return(true), Span(54, 54)), ], vec![ @@ -367,9 +251,9 @@ fn true_and_true_or_false() { ConcreteValue::string("c") ], vec![ - Local::new(0, Type::Boolean, false, Scope::default()), - Local::new(1, Type::Boolean, false, Scope::default()), - Local::new(2, Type::Boolean, false, Scope::default()) + Local::new(0, 0, false, Scope::default()), + Local::new(1, 1, false, Scope::default()), + Local::new(2, 2, false, Scope::default()) ] )) ); diff --git a/dust-lang/tests/loops.rs b/dust-lang/tests/loops.rs index c8bbbf4..252478c 100644 --- a/dust-lang/tests/loops.rs +++ b/dust-lang/tests/loops.rs @@ -11,32 +11,21 @@ fn r#while() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ + (Instruction::load_constant(0, 0, false), Span(12, 13)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(12, 13) - ), - (Instruction::define_local(0, 0, true), Span(8, 9)), - ( - Instruction::less(true, Argument::Local(0), Argument::Constant(2)), + Instruction::less(0, true, Argument::Register(0), Argument::Constant(2)), Span(23, 24) ), (Instruction::jump(2, true), Span(41, 42)), ( - Instruction::add( - Destination::Local(0), - Argument::Local(0), - Argument::Constant(3) - ), + Instruction::add(0, Argument::Register(0), Argument::Constant(3)), Span(35, 36) ), (Instruction::jump(3, false), Span(41, 42)), - ( - Instruction::get_local(Destination::Register(1), 0), - Span(41, 42) - ), + (Instruction::get_local(1, 0), Span(41, 42)), (Instruction::r#return(true), Span(42, 42)), ], vec![ @@ -45,7 +34,7 @@ fn r#while() { ConcreteValue::Integer(5), ConcreteValue::Integer(1), ], - vec![Local::new(1, Type::Integer, true, Scope::default())] + vec![Local::new(1, 0, true, Scope::default())] )), ); diff --git a/dust-lang/tests/math_add.rs b/dust-lang/tests/math_add.rs index 8006e3a..21e916e 100644 --- a/dust-lang/tests/math_add.rs +++ b/dust-lang/tests/math_add.rs @@ -11,15 +11,11 @@ fn add_bytes() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Byte), + return_type: Type::Byte, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(5, 6) ), (Instruction::r#return(true), Span(11, 11)) @@ -43,15 +39,11 @@ fn add_bytes_saturate() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Byte), + return_type: Type::Byte, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(5, 6) ), (Instruction::r#return(true), Span(11, 11)) @@ -75,15 +67,11 @@ fn add_characters() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::String), + return_type: Type::String, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(4, 5) ), (Instruction::r#return(true), Span(9, 9)) @@ -107,15 +95,11 @@ fn add_character_and_string() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::String), + return_type: Type::String, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(4, 5) ), (Instruction::r#return(true), Span(9, 9)) @@ -139,15 +123,11 @@ fn add_floats() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Float), + return_type: Type::Float, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(4, 5) ), (Instruction::r#return(true), Span(9, 9)) @@ -171,15 +151,11 @@ fn add_floats_saturatate() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Float), + return_type: Type::Float, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(24, 25) ), (Instruction::r#return(true), Span(36, 36)) @@ -206,15 +182,11 @@ fn add_integers() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(2, 3) ), (Instruction::r#return(true), Span(5, 5)) @@ -238,15 +210,11 @@ fn add_integers_saturate() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(20, 21) ), (Instruction::r#return(true), Span(23, 23)) @@ -270,15 +238,11 @@ fn add_strings() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::String), + return_type: Type::String, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(10, 11) ), (Instruction::r#return(true), Span(20, 20)) @@ -303,15 +267,11 @@ fn add_string_and_character() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::String), + return_type: Type::String, }, vec![ ( - Instruction::add( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::add(0, Argument::Constant(0), Argument::Constant(1)), Span(4, 5) ), (Instruction::r#return(true), Span(9, 9)) diff --git a/dust-lang/tests/math_add_assign.rs b/dust-lang/tests/math_add_assign.rs index 8b7c834..55e6808 100644 --- a/dust-lang/tests/math_add_assign.rs +++ b/dust-lang/tests/math_add_assign.rs @@ -11,26 +11,15 @@ fn add_assign() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ + (Instruction::load_constant(0, 0, false), Span(12, 13)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(12, 13) - ), - (Instruction::define_local(0, 0, true), Span(8, 9)), - ( - Instruction::add( - Destination::Local(0), - Argument::Local(0), - Argument::Constant(2) - ), + Instruction::add(0, Argument::Register(0), Argument::Constant(2)), Span(17, 19) ), - ( - Instruction::get_local(Destination::Register(1), 0), - Span(23, 24) - ), + (Instruction::get_local(1, 0), Span(23, 24)), (Instruction::r#return(true), Span(24, 24)) ], vec![ @@ -38,7 +27,7 @@ fn add_assign() { ConcreteValue::string("a"), ConcreteValue::Integer(2) ], - vec![Local::new(1, Type::Integer, true, Scope::default())] + vec![Local::new(1, 0, true, Scope::default())] )) ); diff --git a/dust-lang/tests/math_add_errors.rs b/dust-lang/tests/math_add_errors.rs index dd7802a..6268790 100644 --- a/dust-lang/tests/math_add_errors.rs +++ b/dust-lang/tests/math_add_errors.rs @@ -6,7 +6,7 @@ fn add_boolean_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddType { argument_type: Type::Boolean, position: Span(0, 4) @@ -22,7 +22,7 @@ fn add_boolean_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddType { argument_type: Type::Boolean, position: Span(4, 8) @@ -38,12 +38,12 @@ fn add_function_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(0, 6) }, @@ -58,12 +58,12 @@ fn add_function_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(4, 10) }, @@ -78,7 +78,7 @@ fn add_list_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(0, 6) @@ -94,7 +94,7 @@ fn add_list_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(4, 10) @@ -121,7 +121,7 @@ fn add_byte_and_character() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Byte, right_type: Type::Character, @@ -138,7 +138,7 @@ fn add_byte_and_integer() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Byte, right_type: Type::Integer, @@ -155,7 +155,7 @@ fn add_byte_and_string() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Byte, right_type: Type::String, @@ -172,7 +172,7 @@ fn add_character_and_byte() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Character, right_type: Type::Byte, @@ -189,7 +189,7 @@ fn add_character_and_float() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Character, right_type: Type::Float, @@ -206,7 +206,7 @@ fn add_character_and_integer() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Character, right_type: Type::Integer, @@ -223,7 +223,7 @@ fn add_float_and_byte() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Float, right_type: Type::Byte, @@ -240,7 +240,7 @@ fn add_float_and_character() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Float, right_type: Type::Character, @@ -257,7 +257,7 @@ fn add_float_and_integer() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Float, right_type: Type::Integer, @@ -274,7 +274,7 @@ fn add_float_and_string() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Float, right_type: Type::String, @@ -291,7 +291,7 @@ fn add_integer_and_byte() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Integer, right_type: Type::Byte, @@ -308,7 +308,7 @@ fn add_integer_and_character() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Integer, right_type: Type::Character, @@ -325,7 +325,7 @@ fn add_integer_and_float() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Integer, right_type: Type::Float, @@ -342,7 +342,7 @@ fn add_integer_and_string() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::Integer, right_type: Type::String, @@ -359,7 +359,7 @@ fn add_string_and_byte() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::String, right_type: Type::Byte, @@ -376,7 +376,7 @@ fn add_string_and_float() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::String, right_type: Type::Float, @@ -393,7 +393,7 @@ fn add_string_and_integer() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotAddArguments { left_type: Type::String, right_type: Type::Integer, diff --git a/dust-lang/tests/math_divide.rs b/dust-lang/tests/math_divide.rs index f58eba4..d81dfb8 100644 --- a/dust-lang/tests/math_divide.rs +++ b/dust-lang/tests/math_divide.rs @@ -11,15 +11,11 @@ fn divide_bytes() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Byte), + return_type: Type::Byte, }, vec![ ( - Instruction::divide( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::divide(0, Argument::Constant(0), Argument::Constant(1)), Span(5, 6) ), (Instruction::r#return(true), Span(11, 11)) @@ -43,15 +39,11 @@ fn divide_floats() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Float), + return_type: Type::Float, }, vec![ ( - Instruction::divide( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(0) - ), + Instruction::divide(0, Argument::Constant(0), Argument::Constant(0)), Span(4, 5) ), (Instruction::r#return(true), Span(9, 9)) @@ -75,15 +67,11 @@ fn divide_integers() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ ( - Instruction::divide( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(0) - ), + Instruction::divide(0, Argument::Constant(0), Argument::Constant(0)), Span(2, 3) ), (Instruction::r#return(true), Span(5, 5)) diff --git a/dust-lang/tests/math_divide_assign.rs b/dust-lang/tests/math_divide_assign.rs index 9f9dcc6..943feee 100644 --- a/dust-lang/tests/math_divide_assign.rs +++ b/dust-lang/tests/math_divide_assign.rs @@ -11,30 +11,19 @@ fn divide_assign() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ + (Instruction::load_constant(0, 0, false), Span(12, 13)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(12, 13) - ), - (Instruction::define_local(0, 0, true), Span(8, 9)), - ( - Instruction::divide( - Destination::Local(0), - Argument::Local(0), - Argument::Constant(0) - ), + Instruction::divide(0, Argument::Register(0), Argument::Constant(0)), Span(17, 19) ), - ( - Instruction::get_local(Destination::Register(1), 0), - Span(23, 24) - ), + (Instruction::get_local(1, 0), Span(23, 24)), (Instruction::r#return(true), Span(24, 24)) ], vec![ConcreteValue::Integer(2), ConcreteValue::string("a")], - vec![Local::new(1, Type::Integer, true, Scope::default())] + vec![Local::new(1, 0, true, Scope::default())] )) ); diff --git a/dust-lang/tests/math_divide_errors.rs b/dust-lang/tests/math_divide_errors.rs index c8ec01d..a3118cc 100644 --- a/dust-lang/tests/math_divide_errors.rs +++ b/dust-lang/tests/math_divide_errors.rs @@ -6,7 +6,7 @@ fn divide_boolean_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::Boolean, position: Span(0, 4) @@ -22,7 +22,7 @@ fn divide_boolean_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::Boolean, position: Span(4, 8) @@ -38,7 +38,7 @@ fn divide_character_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::Character, position: Span(0, 3) @@ -54,7 +54,7 @@ fn divide_character_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::Character, position: Span(4, 7) @@ -70,7 +70,7 @@ fn divide_float_and_character() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::Character, position: Span(6, 9) @@ -86,7 +86,7 @@ fn divide_float_and_integer() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideArguments { left_type: Type::Float, right_type: Type::Integer, @@ -103,12 +103,12 @@ fn divide_function_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(0, 6) }, @@ -123,12 +123,12 @@ fn divide_function_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(4, 10) }, @@ -143,7 +143,7 @@ fn divide_integer_and_float() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideArguments { left_type: Type::Integer, right_type: Type::Float, @@ -160,7 +160,7 @@ fn divide_list_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(0, 6) @@ -176,7 +176,7 @@ fn divide_list_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(4, 10) @@ -202,7 +202,7 @@ fn divide_string_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::String, position: Span(0, 7) @@ -218,7 +218,7 @@ fn divide_string_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotDivideType { argument_type: Type::String, position: Span(4, 11) diff --git a/dust-lang/tests/math_modulo.rs b/dust-lang/tests/math_modulo.rs index 05d1da4..b1ee83e 100644 --- a/dust-lang/tests/math_modulo.rs +++ b/dust-lang/tests/math_modulo.rs @@ -11,15 +11,11 @@ fn modulo_floats() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Float), + return_type: Type::Float, }, vec![ ( - Instruction::modulo( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(0) - ), + Instruction::modulo(0, Argument::Constant(0), Argument::Constant(0)), Span(4, 5) ), (Instruction::r#return(true), Span(9, 9)) @@ -43,15 +39,11 @@ fn modulo_integers() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ ( - Instruction::modulo( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(0) - ), + Instruction::modulo(0, Argument::Constant(0), Argument::Constant(0)), Span(2, 3) ), (Instruction::r#return(true), Span(5, 5)) diff --git a/dust-lang/tests/math_modulo_errors.rs b/dust-lang/tests/math_modulo_errors.rs index c4363ca..d283ec4 100644 --- a/dust-lang/tests/math_modulo_errors.rs +++ b/dust-lang/tests/math_modulo_errors.rs @@ -6,7 +6,7 @@ fn modulo_boolean_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::Boolean, position: Span(0, 4) @@ -22,7 +22,7 @@ fn modulo_boolean_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::Boolean, position: Span(4, 8) @@ -38,7 +38,7 @@ fn modulo_character_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::Character, position: Span(0, 3) @@ -54,7 +54,7 @@ fn modulo_character_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::Character, position: Span(4, 7) @@ -70,7 +70,7 @@ fn modulo_float_and_character() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::Character, position: Span(6, 9) @@ -86,7 +86,7 @@ fn modulo_float_and_integer() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloArguments { left_type: Type::Float, right_type: Type::Integer, @@ -103,12 +103,12 @@ fn modulo_function_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(0, 6) }, @@ -123,12 +123,12 @@ fn modulo_function_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(4, 10) }, @@ -143,7 +143,7 @@ fn modulo_integer_and_float() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloArguments { left_type: Type::Integer, right_type: Type::Float, @@ -160,7 +160,7 @@ fn modulo_list_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(0, 6) @@ -176,7 +176,7 @@ fn modulo_list_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(4, 10) @@ -202,7 +202,7 @@ fn modulo_string_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::String, position: Span(0, 7) @@ -218,7 +218,7 @@ fn modulo_string_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotModuloType { argument_type: Type::String, position: Span(4, 11) diff --git a/dust-lang/tests/math_multiply.rs b/dust-lang/tests/math_multiply.rs index 8d53537..a3241c0 100644 --- a/dust-lang/tests/math_multiply.rs +++ b/dust-lang/tests/math_multiply.rs @@ -11,15 +11,11 @@ fn multiply_floats() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Float), + return_type: Type::Float }, vec![ ( - Instruction::multiply( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(0) - ), + Instruction::multiply(0, Argument::Constant(0), Argument::Constant(0)), Span(4, 5) ), (Instruction::r#return(true), Span(9, 9)), @@ -43,15 +39,11 @@ fn multiply_integers() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ ( - Instruction::multiply( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::multiply(0, Argument::Constant(0), Argument::Constant(1)), Span(2, 3) ), (Instruction::r#return(true), Span(5, 5)), diff --git a/dust-lang/tests/math_multiply_assign.rs b/dust-lang/tests/math_multiply_assign.rs index 0ae299a..ec6f87d 100644 --- a/dust-lang/tests/math_multiply_assign.rs +++ b/dust-lang/tests/math_multiply_assign.rs @@ -11,26 +11,15 @@ fn multiply_assign() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ + (Instruction::load_constant(0, 0, false), Span(12, 13)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(12, 13) - ), - (Instruction::define_local(0, 0, true), Span(8, 9)), - ( - Instruction::multiply( - Destination::Local(0), - Argument::Local(0), - Argument::Constant(2) - ), + Instruction::multiply(0, Argument::Register(0), Argument::Constant(2)), Span(17, 19) ), - ( - Instruction::get_local(Destination::Register(1), 0), - Span(22, 23) - ), + (Instruction::get_local(1, 0), Span(22, 23)), (Instruction::r#return(true), Span(23, 23)) ], vec![ @@ -38,7 +27,7 @@ fn multiply_assign() { ConcreteValue::string("a"), ConcreteValue::Integer(3) ], - vec![Local::new(1, Type::Integer, true, Scope::default())] + vec![Local::new(1, 0, true, Scope::default())] )) ); diff --git a/dust-lang/tests/math_multiply_errors.rs b/dust-lang/tests/math_multiply_errors.rs index 700c334..5c03033 100644 --- a/dust-lang/tests/math_multiply_errors.rs +++ b/dust-lang/tests/math_multiply_errors.rs @@ -6,7 +6,7 @@ fn multiply_boolean_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::Boolean, position: Span(0, 4) @@ -22,7 +22,7 @@ fn multiply_boolean_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::Boolean, position: Span(4, 8) @@ -38,7 +38,7 @@ fn multiply_character_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::Character, position: Span(0, 3) @@ -54,7 +54,7 @@ fn multiply_character_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::Character, position: Span(4, 7) @@ -70,7 +70,7 @@ fn multiply_float_and_character() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::Character, position: Span(6, 9) @@ -86,7 +86,7 @@ fn multiply_float_and_integer() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyArguments { left_type: Type::Float, right_type: Type::Integer, @@ -103,12 +103,12 @@ fn multiply_function_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(0, 6) }, @@ -123,12 +123,12 @@ fn multiply_function_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(4, 10) }, @@ -143,7 +143,7 @@ fn multiply_integer_and_float() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyArguments { left_type: Type::Integer, right_type: Type::Float, @@ -160,7 +160,7 @@ fn multiply_list_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(0, 6) @@ -176,7 +176,7 @@ fn multiply_list_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(4, 10) @@ -202,7 +202,7 @@ fn multiply_string_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::String, position: Span(0, 7) @@ -218,7 +218,7 @@ fn multiply_string_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotMultiplyType { argument_type: Type::String, position: Span(4, 11) diff --git a/dust-lang/tests/math_subtract.rs b/dust-lang/tests/math_subtract.rs index 9834035..2fc5b84 100644 --- a/dust-lang/tests/math_subtract.rs +++ b/dust-lang/tests/math_subtract.rs @@ -11,15 +11,11 @@ fn subtract_floats() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Float), + return_type: Type::Float, }, vec![ ( - Instruction::subtract( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(0) - ), + Instruction::subtract(0, Argument::Constant(0), Argument::Constant(0)), Span(4, 5) ), (Instruction::r#return(true), Span(9, 9)), @@ -43,15 +39,11 @@ fn subtract_floats_saturate() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Float), + return_type: Type::Float, }, vec![ ( - Instruction::subtract( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::subtract(0, Argument::Constant(0), Argument::Constant(1)), Span(25, 26) ), (Instruction::r#return(true), Span(36, 36)), @@ -78,15 +70,11 @@ fn subtract_integers() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ ( - Instruction::subtract( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::subtract(0, Argument::Constant(0), Argument::Constant(1)), Span(2, 3) ), (Instruction::r#return(true), Span(5, 5)), @@ -110,15 +98,11 @@ fn subtract_integers_saturate() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ ( - Instruction::subtract( - Destination::Register(0), - Argument::Constant(0), - Argument::Constant(1) - ), + Instruction::subtract(0, Argument::Constant(0), Argument::Constant(1)), Span(21, 22) ), (Instruction::r#return(true), Span(24, 24)), diff --git a/dust-lang/tests/math_subtract_assign.rs b/dust-lang/tests/math_subtract_assign.rs index c796fdf..733eded 100644 --- a/dust-lang/tests/math_subtract_assign.rs +++ b/dust-lang/tests/math_subtract_assign.rs @@ -11,26 +11,15 @@ fn subtract_assign() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ + (Instruction::load_constant(0, 0, false), Span(12, 14)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(12, 14) - ), - (Instruction::define_local(0, 0, true), Span(8, 9)), - ( - Instruction::subtract( - Destination::Local(0), - Argument::Local(0), - Argument::Constant(2) - ), + Instruction::subtract(0, Argument::Register(0), Argument::Constant(2)), Span(18, 20) ), - ( - Instruction::get_local(Destination::Register(1), 0), - Span(24, 25) - ), + (Instruction::get_local(1, 0), Span(24, 25)), (Instruction::r#return(true), Span(25, 25)), ], vec![ @@ -38,7 +27,7 @@ fn subtract_assign() { ConcreteValue::string("x"), ConcreteValue::Integer(2) ], - vec![Local::new(1, Type::Integer, true, Scope::default())] + vec![Local::new(1, 0, true, Scope::default())] )), ); diff --git a/dust-lang/tests/math_subtract_errors.rs b/dust-lang/tests/math_subtract_errors.rs index cb8fa7c..1d73bde 100644 --- a/dust-lang/tests/math_subtract_errors.rs +++ b/dust-lang/tests/math_subtract_errors.rs @@ -6,7 +6,7 @@ fn subtract_boolean_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::Boolean, position: Span(0, 4) @@ -22,7 +22,7 @@ fn subtract_boolean_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::Boolean, position: Span(4, 8) @@ -38,7 +38,7 @@ fn subtract_character_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::Character, position: Span(0, 3) @@ -54,7 +54,7 @@ fn subtract_character_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::Character, position: Span(4, 7) @@ -70,7 +70,7 @@ fn subtract_float_and_character() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::Character, position: Span(6, 9) @@ -86,7 +86,7 @@ fn subtract_float_and_integer() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractArguments { left_type: Type::Float, right_type: Type::Integer, @@ -103,12 +103,12 @@ fn subtract_function_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(0, 6) }, @@ -123,12 +123,12 @@ fn subtract_function_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { - argument_type: Type::Function(FunctionType { + argument_type: Type::function(FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None) + return_type: Type::None }), position: Span(4, 10) }, @@ -143,7 +143,7 @@ fn subtract_integer_and_float() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractArguments { left_type: Type::Integer, right_type: Type::Float, @@ -160,7 +160,7 @@ fn subtract_list_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(0, 6) @@ -176,7 +176,7 @@ fn subtract_list_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::List(Box::new(Type::Integer)), position: Span(4, 10) @@ -202,7 +202,7 @@ fn subtract_string_left() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::String, position: Span(0, 7) @@ -218,7 +218,7 @@ fn subtract_string_right() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::CannotSubtractType { argument_type: Type::String, position: Span(4, 11) diff --git a/dust-lang/tests/native_functions.rs b/dust-lang/tests/native_functions.rs index b40140e..e6d13db 100644 --- a/dust-lang/tests/native_functions.rs +++ b/dust-lang/tests/native_functions.rs @@ -11,19 +11,13 @@ fn panic() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None), + return_type: Type::None, }, vec![ + (Instruction::load_constant(0, 0, false), Span(6, 22)), + (Instruction::load_constant(1, 1, false), Span(24, 26)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(6, 22) - ), - ( - Instruction::load_constant(Destination::Register(1), 1, false), - Span(24, 26) - ), - ( - Instruction::call_native(Destination::Register(2), NativeFunction::Panic, 2), + Instruction::call_native(2, NativeFunction::Panic, 2), Span(0, 27) ), (Instruction::r#return(false), Span(27, 27)) @@ -38,7 +32,7 @@ fn panic() { assert_eq!( run(source), - Err(CreateReport::Runtime { + Err(DustError::Runtime { error: VmError::NativeFunction(NativeFunctionError::Panic { message: Some("Goodbye world! 42".to_string()), position: Span(0, 27) @@ -59,15 +53,12 @@ fn to_string() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::String), + return_type: Type::String, }, vec![ + (Instruction::load_constant(0, 0, false), Span(10, 12)), ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(10, 12) - ), - ( - Instruction::call_native(Destination::Register(1), NativeFunction::ToString, 1), + Instruction::call_native(1, NativeFunction::ToString, 1), Span(0, 13) ), (Instruction::r#return(true), Span(13, 13)) diff --git a/dust-lang/tests/scopes.rs b/dust-lang/tests/scopes.rs index f38e3ad..d9e14e3 100644 --- a/dust-lang/tests/scopes.rs +++ b/dust-lang/tests/scopes.rs @@ -33,34 +33,14 @@ fn block_scope() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None), + return_type: Type::None, }, vec![ - ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(17, 18) - ), - (Instruction::define_local(0, 0, false), Span(13, 14)), - ( - Instruction::load_constant(Destination::Register(1), 2, false), - Span(50, 52) - ), - (Instruction::define_local(1, 1, false), Span(46, 47)), - ( - Instruction::load_constant(Destination::Register(2), 4, false), - Span(92, 93) - ), - (Instruction::define_local(2, 2, false), Span(88, 89)), - ( - Instruction::load_constant(Destination::Register(3), 6, false), - Span(129, 130) - ), - (Instruction::define_local(3, 3, false), Span(125, 126)), - ( - Instruction::load_constant(Destination::Register(4), 4, false), - Span(158, 159) - ), - (Instruction::define_local(4, 4, false), Span(154, 155)), + (Instruction::load_constant(0, 0, false), Span(17, 18)), + (Instruction::load_constant(1, 2, false), Span(50, 52)), + (Instruction::load_constant(2, 4, false), Span(92, 93)), + (Instruction::load_constant(3, 6, false), Span(129, 130)), + (Instruction::load_constant(4, 4, false), Span(158, 159)), (Instruction::r#return(false), Span(165, 165)) ], vec![ @@ -75,11 +55,11 @@ fn block_scope() { ConcreteValue::string("e"), ], vec![ - Local::new(1, Type::Integer, false, Scope::new(0, 0)), - Local::new(3, Type::Integer, false, Scope::new(1, 1)), - Local::new(5, Type::Integer, false, Scope::new(2, 2)), - Local::new(7, Type::Integer, false, Scope::new(1, 1)), - Local::new(8, Type::Integer, false, Scope::new(0, 0)), + Local::new(1, 0, false, Scope::new(0, 0)), + Local::new(3, 2, false, Scope::new(1, 1)), + Local::new(5, 4, false, Scope::new(2, 2)), + Local::new(7, 6, false, Scope::new(1, 1)), + Local::new(8, 7, false, Scope::new(0, 0)), ] )), ); @@ -116,54 +96,18 @@ fn multiple_block_scopes() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None), + return_type: Type::None, }, vec![ - ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(17, 18) - ), - (Instruction::define_local(0, 0, false), Span(13, 14)), - ( - Instruction::load_constant(Destination::Register(1), 2, false), - Span(50, 52) - ), - (Instruction::define_local(1, 1, false), Span(46, 47)), - ( - Instruction::load_constant(Destination::Register(2), 4, false), - Span(92, 93) - ), - (Instruction::define_local(2, 2, false), Span(88, 89)), - ( - Instruction::get_local(Destination::Register(3), 1), - Span(129, 130) - ), - (Instruction::define_local(3, 3, false), Span(125, 126)), - ( - Instruction::get_local(Destination::Register(4), 0), - Span(158, 159) - ), - (Instruction::define_local(4, 4, false), Span(154, 155)), - ( - Instruction::load_constant(Destination::Register(5), 2, false), - Span(191, 193) - ), - (Instruction::define_local(5, 5, false), Span(187, 188)), - ( - Instruction::load_constant(Destination::Register(6), 4, false), - Span(233, 234) - ), - (Instruction::define_local(6, 6, false), Span(229, 230)), - ( - Instruction::get_local(Destination::Register(7), 5), - Span(270, 271) - ), - (Instruction::define_local(7, 7, false), Span(266, 267)), - ( - Instruction::get_local(Destination::Register(8), 0), - Span(299, 300) - ), - (Instruction::define_local(8, 8, false), Span(295, 296)), + (Instruction::load_constant(0, 0, false), Span(17, 18)), + (Instruction::load_constant(1, 2, false), Span(50, 52)), + (Instruction::load_constant(2, 4, false), Span(92, 93)), + (Instruction::get_local(3, 1), Span(129, 130)), + (Instruction::get_local(4, 0), Span(158, 159)), + (Instruction::load_constant(5, 2, false), Span(191, 193)), + (Instruction::load_constant(4, 4, false), Span(233, 234)), + (Instruction::get_local(7, 5), Span(270, 271)), + (Instruction::get_local(8, 0), Span(299, 300)), (Instruction::r#return(false), Span(306, 306)) ], vec![ @@ -178,15 +122,15 @@ fn multiple_block_scopes() { ConcreteValue::string("e"), ], vec![ - Local::new(1, Type::Integer, false, Scope::new(0, 0)), - Local::new(3, Type::Integer, false, Scope::new(1, 1)), - Local::new(5, Type::Integer, false, Scope::new(2, 2)), - Local::new(6, Type::Integer, false, Scope::new(1, 1)), - Local::new(7, Type::Integer, false, Scope::new(0, 0)), - Local::new(3, Type::Integer, false, Scope::new(1, 3)), - Local::new(5, Type::Integer, false, Scope::new(2, 4)), - Local::new(6, Type::Integer, false, Scope::new(1, 3)), - Local::new(8, Type::Integer, false, Scope::new(0, 0)), + Local::new(1, 0, false, Scope::new(0, 0)), + Local::new(3, 2, false, Scope::new(1, 1)), + Local::new(5, 4, false, Scope::new(2, 2)), + Local::new(6, 5, false, Scope::new(1, 1)), + Local::new(7, 6, false, Scope::new(0, 0)), + Local::new(3, 1, false, Scope::new(1, 3)), + Local::new(5, 1, false, Scope::new(2, 4)), + Local::new(6, 1, false, Scope::new(1, 3)), + Local::new(8, 1, false, Scope::new(0, 0)), ] )), ); @@ -205,7 +149,7 @@ fn disallow_access_to_child_scope() { assert_eq!( run(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::VariableOutOfScope { identifier: "x".to_string(), position: Span(52, 53), @@ -230,7 +174,7 @@ fn disallow_access_to_child_scope_nested() { assert_eq!( run(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::VariableOutOfScope { identifier: "x".to_string(), position: Span(78, 79), @@ -255,7 +199,7 @@ fn disallow_access_to_sibling_scope() { assert_eq!( run(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::VariableOutOfScope { identifier: "x".to_string(), variable_scope: Scope::new(1, 1), @@ -282,7 +226,7 @@ fn disallow_access_to_sibling_scope_nested() { assert_eq!( run(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::VariableOutOfScope { identifier: "x".to_string(), variable_scope: Scope::new(2, 2), diff --git a/dust-lang/tests/unary_operations.rs b/dust-lang/tests/unary_operations.rs index f60f7d0..c04486e 100644 --- a/dust-lang/tests/unary_operations.rs +++ b/dust-lang/tests/unary_operations.rs @@ -11,13 +11,10 @@ fn negate() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ - ( - Instruction::negate(Destination::Register(0), Argument::Constant(0)), - Span(0, 1) - ), + (Instruction::negate(0, Argument::Constant(0)), Span(0, 1)), (Instruction::r#return(true), Span(5, 5)), ], vec![ConcreteValue::Integer(42)], @@ -39,17 +36,11 @@ fn not() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Boolean), + return_type: Type::Boolean, }, vec![ - ( - Instruction::load_boolean(Destination::Register(0), true, false), - Span(1, 5) - ), - ( - Instruction::not(Destination::Register(1), Argument::Register(0)), - Span(0, 1) - ), + (Instruction::load_boolean(0, true, false), Span(1, 5)), + (Instruction::not(1, Argument::Register(0)), Span(0, 1)), (Instruction::r#return(true), Span(5, 5)), ], vec![], diff --git a/dust-lang/tests/variables.rs b/dust-lang/tests/variables.rs index 97af2a6..b1f67d0 100644 --- a/dust-lang/tests/variables.rs +++ b/dust-lang/tests/variables.rs @@ -11,18 +11,14 @@ fn define_local() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::None), + return_type: Type::None, }, vec![ - ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(8, 10) - ), - (Instruction::define_local(0, 0, false), Span(4, 5)), + (Instruction::load_constant(0, 0, false), Span(8, 10)), (Instruction::r#return(false), Span(11, 11)) ], vec![ConcreteValue::Integer(42), ConcreteValue::string("x")], - vec![Local::new(1, Type::Integer, false, Scope::default())] + vec![Local::new(1, 0, false, Scope::default())] )), ); @@ -35,7 +31,7 @@ fn let_statement_expects_identifier() { assert_eq!( compile(source), - Err(CreateReport::Compile { + Err(DustError::Compile { error: CompileError::ExpectedToken { expected: TokenKind::Identifier, found: Token::Integer("1").to_owned(), @@ -57,23 +53,13 @@ fn set_local() { FunctionType { type_parameters: None, value_parameters: None, - return_type: Box::new(Type::Integer), + return_type: Type::Integer, }, vec![ - ( - Instruction::load_constant(Destination::Register(0), 0, false), - Span(12, 14) - ), - (Instruction::define_local(0, 0, true), Span(8, 9)), - ( - Instruction::load_constant(Destination::Register(1), 2, false), - Span(20, 22) - ), + (Instruction::load_constant(0, 0, false), Span(12, 14)), + (Instruction::load_constant(1, 2, false), Span(20, 22)), (Instruction::set_local(1, 0), Span(16, 17)), - ( - Instruction::get_local(Destination::Register(2), 0), - Span(24, 25) - ), + (Instruction::get_local(2, 0), Span(24, 25)), (Instruction::r#return(true), Span(25, 25)), ], vec![ @@ -81,7 +67,7 @@ fn set_local() { ConcreteValue::string("x"), ConcreteValue::Integer(42) ], - vec![Local::new(1, Type::Integer, true, Scope::default())] + vec![Local::new(1, 0, true, Scope::default())] )), );