1
0

Fix tests

This commit is contained in:
Jeff 2024-11-27 21:13:35 -05:00
parent cc963c544f
commit a57268fcba
11 changed files with 528 additions and 149 deletions

View File

@ -14,8 +14,12 @@ fn constant() {
return_type: Box::new(Type::Integer)
},
vec![
(Instruction::load_constant(0, 0, false), Span(0, 2)),
(Instruction::r#return(true), Span(2, 2))
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(0, 2)
),
(Instruction::r#return(true), Type::None, Span(2, 2))
],
vec![ConcreteValue::Integer(42)],
vec![]
@ -38,7 +42,7 @@ fn empty() {
value_parameters: None,
return_type: Box::new(Type::None)
},
vec![(Instruction::r#return(false), Span(0, 0))],
vec![(Instruction::r#return(false), Type::None, Span(0, 0))],
vec![],
vec![]
))
@ -62,13 +66,15 @@ fn parentheses_precedence() {
vec![
(
Instruction::add(0, Argument::Constant(0), Argument::Constant(1)),
Type::Integer,
Span(3, 4)
),
(
Instruction::multiply(1, Argument::Register(0), Argument::Constant(2)),
Type::Integer,
Span(8, 9)
),
(Instruction::r#return(true), Span(11, 11)),
(Instruction::r#return(true), Type::None, Span(11, 11)),
],
vec![
ConcreteValue::Integer(1),

View File

@ -16,12 +16,21 @@ fn equal() {
vec![
(
Instruction::equal(true, Argument::Constant(0), Argument::Constant(1)),
Type::None,
Span(2, 4)
),
(Instruction::jump(1, true), Span(2, 4)),
(Instruction::load_boolean(0, true, true), Span(2, 4)),
(Instruction::load_boolean(0, false, false), Span(2, 4)),
(Instruction::r#return(true), Span(6, 6)),
(Instruction::jump(1, true), Type::None, Span(2, 4)),
(
Instruction::load_boolean(0, true, true),
Type::Boolean,
Span(2, 4)
),
(
Instruction::load_boolean(0, false, false),
Type::Boolean,
Span(2, 4)
),
(Instruction::r#return(true), Type::None, Span(6, 6)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
@ -47,12 +56,21 @@ fn greater() {
vec![
(
Instruction::less_equal(false, Argument::Constant(0), Argument::Constant(1)),
Type::None,
Span(2, 3)
),
(Instruction::jump(1, true), Span(2, 3)),
(Instruction::load_boolean(0, true, true), Span(2, 3)),
(Instruction::load_boolean(0, false, false), Span(2, 3)),
(Instruction::r#return(true), Span(5, 5)),
(Instruction::jump(1, true), Type::None, Span(2, 3)),
(
Instruction::load_boolean(0, true, true),
Type::Boolean,
Span(2, 3)
),
(
Instruction::load_boolean(0, false, false),
Type::Boolean,
Span(2, 3)
),
(Instruction::r#return(true), Type::None, Span(5, 5)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
@ -78,12 +96,21 @@ fn greater_than_or_equal() {
vec![
(
Instruction::less(false, Argument::Constant(0), Argument::Constant(1)),
Type::None,
Span(2, 4)
),
(Instruction::jump(1, true), Span(2, 4)),
(Instruction::load_boolean(0, true, true), Span(2, 4)),
(Instruction::load_boolean(0, false, false), Span(2, 4)),
(Instruction::r#return(true), Span(6, 6)),
(Instruction::jump(1, true), Type::None, Span(2, 4)),
(
Instruction::load_boolean(0, true, true),
Type::Boolean,
Span(2, 4)
),
(
Instruction::load_boolean(0, false, false),
Type::Boolean,
Span(2, 4)
),
(Instruction::r#return(true), Type::None, Span(6, 6)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
@ -109,12 +136,21 @@ fn less_than() {
vec![
(
Instruction::less(true, Argument::Constant(0), Argument::Constant(1)),
Type::None,
Span(2, 3)
),
(Instruction::jump(1, true), Span(2, 3)),
(Instruction::load_boolean(0, true, true), Span(2, 3)),
(Instruction::load_boolean(0, false, false), Span(2, 3)),
(Instruction::r#return(true), Span(5, 5)),
(Instruction::jump(1, true), Type::None, Span(2, 3)),
(
Instruction::load_boolean(0, true, true),
Type::Boolean,
Span(2, 3)
),
(
Instruction::load_boolean(0, false, false),
Type::Boolean,
Span(2, 3)
),
(Instruction::r#return(true), Type::None, Span(5, 5)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
@ -140,12 +176,21 @@ fn less_than_or_equal() {
vec![
(
Instruction::less_equal(true, Argument::Constant(0), Argument::Constant(1)),
Type::None,
Span(2, 4)
),
(Instruction::jump(1, true), Span(2, 4)),
(Instruction::load_boolean(0, true, true), Span(2, 4)),
(Instruction::load_boolean(0, false, false), Span(2, 4)),
(Instruction::r#return(true), Span(6, 6)),
(Instruction::jump(1, true), Type::None, Span(2, 4)),
(
Instruction::load_boolean(0, true, true),
Type::Boolean,
Span(2, 4)
),
(
Instruction::load_boolean(0, false, false),
Type::Boolean,
Span(2, 4)
),
(Instruction::r#return(true), Type::None, Span(6, 6)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
@ -171,12 +216,21 @@ fn not_equal() {
vec![
(
Instruction::equal(false, Argument::Constant(0), Argument::Constant(1)),
Type::None,
Span(2, 4)
),
(Instruction::jump(1, true), Span(2, 4)),
(Instruction::load_boolean(0, true, true), Span(2, 4)),
(Instruction::load_boolean(0, false, false), Span(2, 4)),
(Instruction::r#return(true), Span(6, 6)),
(Instruction::jump(1, true), Type::None, Span(2, 4)),
(
Instruction::load_boolean(0, true, true),
Type::Boolean,
Span(2, 4)
),
(
Instruction::load_boolean(0, false, false),
Type::Boolean,
Span(2, 4)
),
(Instruction::r#return(true), Type::None, Span(6, 6)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]

View File

@ -20,9 +20,10 @@ fn function() {
vec![
(
Instruction::add(2, Argument::Local(0), Argument::Local(1)),
Type::Integer,
Span(30, 31)
),
(Instruction::r#return(true), Span(35, 35)),
(Instruction::r#return(true), Type::None, Span(35, 35)),
],
vec![ConcreteValue::string("a"), ConcreteValue::string("b"),],
vec![
@ -47,11 +48,31 @@ fn function_call() {
return_type: Box::new(Type::Integer)
},
vec![
(Instruction::load_constant(0, 0, false), Span(0, 36)),
(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)),
(
Instruction::load_constant(0, 0, false),
Type::Function(FunctionType {
type_parameters: None,
value_parameters: Some(vec![(0, Type::Integer), (1, Type::Integer)]),
return_type: Box::new(Type::Integer),
}),
Span(0, 36)
),
(
Instruction::load_constant(1, 1, false),
Type::Integer,
Span(36, 37)
),
(
Instruction::load_constant(2, 2, false),
Type::Integer,
Span(39, 40)
),
(
Instruction::call(3, Argument::Constant(0), 2),
Type::Integer,
Span(35, 41)
),
(Instruction::r#return(true), Type::None, Span(41, 41)),
],
vec![
ConcreteValue::Function(Chunk::with_data(
@ -64,9 +85,10 @@ fn function_call() {
vec![
(
Instruction::add(2, Argument::Local(0), Argument::Local(1)),
Type::Integer,
Span(30, 31)
),
(Instruction::r#return(true), Span(35, 36)),
(Instruction::r#return(true), Type::None, Span(35, 36)),
],
vec![ConcreteValue::string("a"), ConcreteValue::string("b"),],
vec![
@ -98,9 +120,21 @@ fn function_declaration() {
return_type: Box::new(Type::None)
},
vec![
(Instruction::load_constant(0, 0, false), Span(0, 40)),
(Instruction::define_local(0, 0, false), Span(3, 6)),
(Instruction::r#return(false), Span(40, 40))
(
Instruction::load_constant(0, 0, false),
Type::Function(FunctionType {
type_parameters: None,
value_parameters: Some(vec![(0, Type::Integer), (1, Type::Integer)]),
return_type: Box::new(Type::Integer),
}),
Span(0, 40)
),
(
Instruction::define_local(0, 0, false),
Type::None,
Span(3, 6)
),
(Instruction::r#return(false), Type::None, Span(40, 40))
],
vec![
ConcreteValue::Function(Chunk::with_data(
@ -113,9 +147,10 @@ fn function_declaration() {
vec![
(
Instruction::add(2, Argument::Local(0), Argument::Local(1)),
Type::Integer,
Span(35, 36)
),
(Instruction::r#return(true), Span(40, 40)),
(Instruction::r#return(true), Type::None, Span(40, 40)),
],
vec![ConcreteValue::string("a"), ConcreteValue::string("b")],
vec![

View File

@ -14,8 +14,12 @@ fn empty_list() {
return_type: Box::new(Type::List(Box::new(Type::Any))),
},
vec![
(Instruction::load_list(0, 0), Span(0, 2)),
(Instruction::r#return(true), Span(2, 2)),
(
Instruction::load_list(0, 0),
Type::List(Box::new(Type::Any)),
Span(0, 2)
),
(Instruction::r#return(true), Type::None, Span(2, 2)),
],
vec![],
vec![]
@ -39,11 +43,27 @@ fn list() {
return_type: Box::new(Type::List(Box::new(Type::Integer))),
},
vec![
(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)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(1, 2)
),
(
Instruction::load_constant(1, 1, false),
Type::Integer,
Span(4, 5)
),
(
Instruction::load_constant(2, 2, false),
Type::Integer,
Span(7, 8)
),
(
Instruction::load_list(3, 0),
Type::List(Box::new(Type::Integer)),
Span(0, 9)
),
(Instruction::r#return(true), Type::None, Span(9, 9)),
],
vec![
ConcreteValue::Integer(1),
@ -78,22 +98,33 @@ fn list_with_complex_expression() {
return_type: Box::new(Type::List(Box::new(Type::Integer))),
},
vec![
(Instruction::load_constant(0, 0, false), Span(1, 2)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(1, 2)
),
(
Instruction::add(1, Argument::Constant(1), Argument::Constant(2)),
Type::Integer,
Span(6, 7)
),
(
Instruction::multiply(2, Argument::Constant(3), Argument::Constant(4)),
Type::Integer,
Span(14, 15)
),
(
Instruction::subtract(3, Argument::Register(1), Argument::Register(2)),
Type::Integer,
Span(10, 11)
),
(Instruction::close(1, 3), Span(17, 18)),
(Instruction::load_list(4, 0), Span(0, 18)),
(Instruction::r#return(true), Span(18, 18)),
(Instruction::close(1, 3), Type::None, Span(17, 18)),
(
Instruction::load_list(4, 0),
Type::List(Box::new(Type::Integer)),
Span(0, 18)
),
(Instruction::r#return(true), Type::None, Span(18, 18)),
],
vec![
ConcreteValue::Integer(1),
@ -129,14 +160,27 @@ fn list_with_simple_expression() {
return_type: Box::new(Type::List(Box::new(Type::Integer))),
},
vec![
(Instruction::load_constant(0, 0, false), Span(1, 2)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(1, 2)
),
(
Instruction::add(1, Argument::Constant(1), Argument::Constant(2)),
Type::Integer,
Span(6, 7)
),
(Instruction::load_constant(2, 3, false), Span(11, 12)),
(Instruction::load_list(3, 0), Span(0, 13)),
(Instruction::r#return(true), Span(13, 13)),
(
Instruction::load_constant(2, 3, false),
Type::Integer,
Span(11, 12)
),
(
Instruction::load_list(3, 0),
Type::List(Box::new(Type::Integer)),
Span(0, 13)
),
(Instruction::r#return(true), Type::None, Span(13, 13)),
],
vec![
ConcreteValue::Integer(1),

View File

@ -14,11 +14,23 @@ fn and() {
return_type: Box::new(Type::Boolean),
},
vec![
(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(1, false, false), Span(8, 13)),
(Instruction::r#return(true), Span(13, 13)),
(
Instruction::load_boolean(0, true, false),
Type::Boolean,
Span(0, 4)
),
(
Instruction::test(Argument::Register(0), true),
Type::None,
Span(5, 7)
),
(Instruction::jump(1, true), Type::None, Span(5, 7)),
(
Instruction::load_boolean(1, false, false),
Type::Boolean,
Span(8, 13)
),
(Instruction::r#return(true), Type::None, Span(13, 13)),
],
vec![],
vec![]
@ -42,11 +54,23 @@ fn or() {
return_type: Box::new(Type::Boolean),
},
vec![
(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(1, false, false), Span(8, 13)),
(Instruction::r#return(true), Span(13, 13)),
(
Instruction::load_boolean(0, true, false),
Type::Boolean,
Span(0, 4)
),
(
Instruction::test(Argument::Register(0), false),
Type::None,
Span(5, 7)
),
(Instruction::jump(1, true), Type::None, Span(5, 7)),
(
Instruction::load_boolean(1, false, false),
Type::Boolean,
Span(8, 13)
),
(Instruction::r#return(true), Type::None, Span(13, 13)),
],
vec![],
vec![]
@ -70,15 +94,35 @@ fn variable_and() {
return_type: Box::new(Type::Boolean),
},
vec![
(Instruction::load_boolean(0, true, false), Span(8, 12)),
(Instruction::define_local(0, 0, false), Span(4, 5)),
(Instruction::load_boolean(1, false, false), Span(22, 27)),
(Instruction::define_local(1, 1, false), Span(18, 19)),
(Instruction::get_local(2, 0), Span(29, 30)),
(Instruction::test(Argument::Register(2), true), Span(31, 33)),
(Instruction::jump(1, true), Span(31, 33)),
(Instruction::get_local(3, 1), Span(34, 35)),
(Instruction::r#return(true), Span(35, 35)),
(
Instruction::load_boolean(0, true, false),
Type::Boolean,
Span(8, 12)
),
(
Instruction::define_local(0, 0, false),
Type::None,
Span(4, 5)
),
(
Instruction::load_boolean(1, false, false),
Type::Boolean,
Span(22, 27)
),
(
Instruction::define_local(1, 1, false),
Type::None,
Span(18, 19)
),
(Instruction::get_local(2, 0), Type::Boolean, Span(29, 30)),
(
Instruction::test(Argument::Register(2), true),
Type::None,
Span(31, 33)
),
(Instruction::jump(1, true), Type::None, Span(31, 33)),
(Instruction::get_local(3, 1), Type::Boolean, Span(34, 35)),
(Instruction::r#return(true), Type::None, Span(35, 35)),
],
vec![ConcreteValue::string("a"), ConcreteValue::string("b"),],
vec![

View File

@ -14,20 +14,30 @@ fn r#while() {
return_type: Box::new(Type::Integer),
},
vec![
(Instruction::load_constant(0, 0, false), Span(12, 13)),
(Instruction::define_local(0, 0, true), Span(8, 9)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(12, 13)
),
(
Instruction::define_local(0, 0, true),
Type::None,
Span(8, 9)
),
(
Instruction::less(true, Argument::Register(0), Argument::Constant(2)),
Type::Integer,
Span(23, 24)
),
(Instruction::jump(2, true), Span(41, 42)),
(Instruction::jump(2, true), Type::None, Span(41, 42)),
(
Instruction::add(0, Argument::Register(0), Argument::Constant(3)),
Type::Integer,
Span(35, 36)
),
(Instruction::jump(3, false), Span(41, 42)),
(Instruction::get_local(1, 0), Span(41, 42)),
(Instruction::r#return(true), Span(42, 42)),
(Instruction::jump(3, false), Type::None, Span(41, 42)),
(Instruction::get_local(1, 0), Type::Integer, Span(41, 42)),
(Instruction::r#return(true), Type::None, Span(42, 42)),
],
vec![
ConcreteValue::Integer(0),

View File

@ -16,9 +16,10 @@ fn add() {
vec![
(
Instruction::add(0, Argument::Constant(0), Argument::Constant(1)),
Type::Integer,
Span(2, 3)
),
(Instruction::r#return(true), Span(5, 5))
(Instruction::r#return(true), Type::None, Span(5, 5))
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
@ -42,14 +43,23 @@ fn add_assign() {
return_type: Box::new(Type::Integer),
},
vec![
(Instruction::load_constant(0, 0, false), Span(12, 13)),
(Instruction::define_local(0, 0, true), Span(8, 9)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(12, 13)
),
(
Instruction::define_local(0, 0, true),
Type::None,
Span(8, 9)
),
(
Instruction::add(0, Argument::Register(0), Argument::Constant(2)),
Type::Integer,
Span(17, 19)
),
(Instruction::get_local(1, 0), Span(23, 24)),
(Instruction::r#return(true), Span(24, 24))
(Instruction::get_local(1, 0), Type::Integer, Span(23, 24)),
(Instruction::r#return(true), Type::None, Span(24, 24))
],
vec![
ConcreteValue::Integer(1),
@ -111,9 +121,10 @@ fn divide() {
vec![
(
Instruction::divide(0, Argument::Constant(0), Argument::Constant(0)),
Type::Integer,
Span(2, 3)
),
(Instruction::r#return(true), Span(5, 5))
(Instruction::r#return(true), Type::None, Span(5, 5))
],
vec![ConcreteValue::Integer(2)],
vec![]
@ -137,14 +148,23 @@ fn divide_assign() {
return_type: Box::new(Type::Integer),
},
vec![
(Instruction::load_constant(0, 0, false), Span(12, 13)),
(Instruction::define_local(0, 0, true), Span(8, 9)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(12, 13)
),
(
Instruction::define_local(0, 0, true),
Type::None,
Span(8, 9)
),
(
Instruction::divide(0, Argument::Register(0), Argument::Constant(0)),
Type::Integer,
Span(17, 19)
),
(Instruction::get_local(1, 0), Span(23, 24)),
(Instruction::r#return(true), Span(24, 24))
(Instruction::get_local(1, 0), Type::Integer, Span(23, 24)),
(Instruction::r#return(true), Type::None, Span(24, 24))
],
vec![ConcreteValue::Integer(2), ConcreteValue::string("a")],
vec![Local::new(1, Type::Integer, true, Scope::default())]
@ -186,21 +206,25 @@ fn math_operator_precedence() {
vec![
(
Instruction::add(0, Argument::Constant(0), Argument::Constant(1)),
Type::Integer,
Span(2, 3)
),
(
Instruction::multiply(1, Argument::Constant(2), Argument::Constant(3)),
Type::Integer,
Span(10, 11)
),
(
Instruction::divide(2, Argument::Register(1), Argument::Constant(4)),
Type::Integer,
Span(14, 15)
),
(
Instruction::subtract(3, Argument::Register(0), Argument::Register(2)),
Type::Integer,
Span(6, 7)
),
(Instruction::r#return(true), Span(17, 17)),
(Instruction::r#return(true), Type::None, Span(17, 17)),
],
vec![
ConcreteValue::Integer(1),
@ -232,9 +256,10 @@ fn multiply() {
vec![
(
Instruction::multiply(0, Argument::Constant(0), Argument::Constant(1)),
Type::Integer,
Span(2, 3)
),
(Instruction::r#return(true), Span(5, 5)),
(Instruction::r#return(true), Type::None, Span(5, 5)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
@ -258,14 +283,23 @@ fn multiply_assign() {
return_type: Box::new(Type::Integer),
},
vec![
(Instruction::load_constant(0, 0, false), Span(12, 13)),
(Instruction::define_local(0, 0, true), Span(8, 9)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(12, 13)
),
(
Instruction::define_local(0, 0, true),
Type::None,
Span(8, 9)
),
(
Instruction::multiply(0, Argument::Register(0), Argument::Constant(2)),
Type::Integer,
Span(17, 19)
),
(Instruction::get_local(1, 0), Span(22, 23)),
(Instruction::r#return(true), Span(23, 23))
(Instruction::get_local(1, 0), Type::Integer, Span(22, 23)),
(Instruction::r#return(true), Type::None, Span(23, 23))
],
vec![
ConcreteValue::Integer(2),
@ -311,9 +345,10 @@ fn subtract() {
vec![
(
Instruction::subtract(0, Argument::Constant(0), Argument::Constant(1)),
Type::Integer,
Span(2, 3)
),
(Instruction::r#return(true), Span(5, 5)),
(Instruction::r#return(true), Type::None, Span(5, 5)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
@ -337,14 +372,23 @@ fn subtract_assign() {
return_type: Box::new(Type::Integer),
},
vec![
(Instruction::load_constant(0, 0, false), Span(12, 14)),
(Instruction::define_local(0, 0, true), Span(8, 9)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(12, 14)
),
(
Instruction::define_local(0, 0, true),
Type::None,
Span(8, 9)
),
(
Instruction::subtract(0, Argument::Register(0), Argument::Constant(2)),
Type::Integer,
Span(18, 20)
),
(Instruction::get_local(1, 0), Span(24, 25)),
(Instruction::r#return(true), Span(25, 25)),
(Instruction::get_local(1, 0), Type::Integer, Span(24, 25)),
(Instruction::r#return(true), Type::None, Span(25, 25)),
],
vec![
ConcreteValue::Integer(42),

View File

@ -14,13 +14,22 @@ fn panic() {
return_type: Box::new(Type::None),
},
vec![
(Instruction::load_constant(0, 0, false), Span(6, 22)),
(Instruction::load_constant(1, 1, false), Span(24, 26)),
(
Instruction::load_constant(0, 0, false),
Type::String,
Span(6, 22)
),
(
Instruction::load_constant(1, 1, false),
Type::Integer,
Span(24, 26)
),
(
Instruction::call_native(2, NativeFunction::Panic, 2),
Type::None,
Span(0, 27)
),
(Instruction::r#return(false), Span(27, 27))
(Instruction::r#return(false), Type::None, Span(27, 27))
],
vec![
ConcreteValue::string("Goodbye world!"),
@ -56,12 +65,17 @@ fn to_string() {
return_type: Box::new(Type::String),
},
vec![
(Instruction::load_constant(0, 0, false), Span(10, 12)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(10, 12)
),
(
Instruction::call_native(1, NativeFunction::ToString, 1),
Type::String,
Span(0, 13)
),
(Instruction::r#return(true), Span(13, 13))
(Instruction::r#return(true), Type::None, Span(13, 13))
],
vec![ConcreteValue::Integer(42)],
vec![]

View File

@ -36,17 +36,57 @@ fn block_scope() {
return_type: Box::new(Type::None),
},
vec![
(Instruction::load_constant(0, 0, false), Span(17, 18)),
(Instruction::define_local(0, 0, false), Span(13, 14)),
(Instruction::load_constant(1, 2, false), Span(50, 52)),
(Instruction::define_local(1, 1, false), Span(46, 47)),
(Instruction::load_constant(2, 4, false), Span(92, 93)),
(Instruction::define_local(2, 2, false), Span(88, 89)),
(Instruction::load_constant(3, 6, false), Span(129, 130)),
(Instruction::define_local(3, 3, false), Span(125, 126)),
(Instruction::load_constant(4, 4, false), Span(158, 159)),
(Instruction::define_local(4, 4, false), Span(154, 155)),
(Instruction::r#return(false), Span(165, 165))
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(17, 18)
),
(
Instruction::define_local(0, 0, false),
Type::None,
Span(13, 14)
),
(
Instruction::load_constant(1, 2, false),
Type::Integer,
Span(50, 52)
),
(
Instruction::define_local(1, 1, false),
Type::None,
Span(46, 47)
),
(
Instruction::load_constant(2, 4, false),
Type::Integer,
Span(92, 93)
),
(
Instruction::define_local(2, 2, false),
Type::None,
Span(88, 89)
),
(
Instruction::load_constant(3, 6, false),
Type::Integer,
Span(129, 130)
),
(
Instruction::define_local(3, 3, false),
Type::None,
Span(125, 126)
),
(
Instruction::load_constant(4, 4, false),
Type::Integer,
Span(158, 159)
),
(
Instruction::define_local(4, 4, false),
Type::None,
Span(154, 155)
),
(Instruction::r#return(false), Type::None, Span(165, 165))
],
vec![
ConcreteValue::Integer(0),
@ -104,25 +144,81 @@ fn multiple_block_scopes() {
return_type: Box::new(Type::None),
},
vec![
(Instruction::load_constant(0, 0, false), Span(17, 18)),
(Instruction::define_local(0, 0, false), Span(13, 14)),
(Instruction::load_constant(1, 2, false), Span(50, 52)),
(Instruction::define_local(1, 1, false), Span(46, 47)),
(Instruction::load_constant(2, 4, false), Span(92, 93)),
(Instruction::define_local(2, 2, false), Span(88, 89)),
(Instruction::get_local(3, 1), Span(129, 130)),
(Instruction::define_local(3, 3, false), Span(125, 126)),
(Instruction::get_local(4, 0), Span(158, 159)),
(Instruction::define_local(4, 4, false), Span(154, 155)),
(Instruction::load_constant(5, 2, false), Span(191, 193)),
(Instruction::define_local(5, 5, false), Span(187, 188)),
(Instruction::load_constant(6, 4, false), Span(233, 234)),
(Instruction::define_local(6, 6, false), Span(229, 230)),
(Instruction::get_local(7, 5), Span(270, 271)),
(Instruction::define_local(7, 7, false), Span(266, 267)),
(Instruction::get_local(8, 0), Span(299, 300)),
(Instruction::define_local(8, 8, false), Span(295, 296)),
(Instruction::r#return(false), Span(306, 306))
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(17, 18)
),
(
Instruction::define_local(0, 0, false),
Type::None,
Span(13, 14)
),
(
Instruction::load_constant(1, 2, false),
Type::Integer,
Span(50, 52)
),
(
Instruction::define_local(1, 1, false),
Type::None,
Span(46, 47)
),
(
Instruction::load_constant(2, 4, false),
Type::Integer,
Span(92, 93)
),
(
Instruction::define_local(2, 2, false),
Type::None,
Span(88, 89)
),
(Instruction::get_local(3, 1), Type::Integer, Span(129, 130)),
(
Instruction::define_local(3, 3, false),
Type::None,
Span(125, 126)
),
(Instruction::get_local(4, 0), Type::Integer, Span(158, 159)),
(
Instruction::define_local(4, 4, false),
Type::None,
Span(154, 155)
),
(
Instruction::load_constant(5, 2, false),
Type::Integer,
Span(191, 193)
),
(
Instruction::define_local(5, 5, false),
Type::None,
Span(187, 188)
),
(
Instruction::load_constant(6, 4, false),
Type::Integer,
Span(233, 234)
),
(
Instruction::define_local(6, 6, false),
Type::None,
Span(229, 230)
),
(Instruction::get_local(7, 5), Type::Integer, Span(270, 271)),
(
Instruction::define_local(7, 7, false),
Type::None,
Span(266, 267)
),
(Instruction::get_local(8, 0), Type::Integer, Span(299, 300)),
(
Instruction::define_local(8, 8, false),
Type::None,
Span(295, 296)
),
(Instruction::r#return(false), Type::None, Span(306, 306))
],
vec![
ConcreteValue::Integer(0),

View File

@ -14,8 +14,12 @@ fn negate() {
return_type: Box::new(Type::Integer),
},
vec![
(Instruction::negate(0, Argument::Constant(0)), Span(0, 1)),
(Instruction::r#return(true), Span(5, 5)),
(
Instruction::negate(0, Argument::Constant(0)),
Type::Integer,
Span(0, 1)
),
(Instruction::r#return(true), Type::None, Span(5, 5)),
],
vec![ConcreteValue::Integer(42)],
vec![]
@ -39,9 +43,17 @@ fn not() {
return_type: Box::new(Type::Boolean),
},
vec![
(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)),
(
Instruction::load_boolean(0, true, false),
Type::Boolean,
Span(1, 5)
),
(
Instruction::not(1, Argument::Register(0)),
Type::Boolean,
Span(0, 1)
),
(Instruction::r#return(true), Type::None, Span(5, 5)),
],
vec![],
vec![]

View File

@ -14,9 +14,17 @@ fn define_local() {
return_type: Box::new(Type::None),
},
vec![
(Instruction::load_constant(0, 0, false), Span(8, 10)),
(Instruction::define_local(0, 0, false), Span(4, 5)),
(Instruction::r#return(false), Span(11, 11))
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(8, 10)
),
(
Instruction::define_local(0, 0, false),
Type::None,
Span(4, 5)
),
(Instruction::r#return(false), Type::None, Span(11, 11))
],
vec![ConcreteValue::Integer(42), ConcreteValue::string("x")],
vec![Local::new(1, Type::Integer, false, Scope::default())]
@ -57,12 +65,24 @@ fn set_local() {
return_type: Box::new(Type::Integer),
},
vec![
(Instruction::load_constant(0, 0, false), Span(12, 14)),
(Instruction::define_local(0, 0, true), Span(8, 9)),
(Instruction::load_constant(1, 2, false), Span(20, 22)),
(Instruction::set_local(1, 0), Span(16, 17)),
(Instruction::get_local(2, 0), Span(24, 25)),
(Instruction::r#return(true), Span(25, 25)),
(
Instruction::load_constant(0, 0, false),
Type::Integer,
Span(12, 14)
),
(
Instruction::define_local(0, 0, true),
Type::None,
Span(8, 9)
),
(
Instruction::load_constant(1, 2, false),
Type::Integer,
Span(20, 22)
),
(Instruction::set_local(1, 0), Type::None, Span(16, 17)),
(Instruction::get_local(2, 0), Type::Integer, Span(24, 25)),
(Instruction::r#return(true), Type::None, Span(25, 25)),
],
vec![
ConcreteValue::Integer(41),