1
0
This commit is contained in:
Jeff 2024-12-03 17:11:02 -05:00
parent e241051870
commit 8f9e285214
4 changed files with 15 additions and 19 deletions

View File

@ -150,9 +150,7 @@ impl<'src> Compiler<'src> {
.iter() .iter()
.rev() .rev()
.find_map(|(instruction, _, _)| { .find_map(|(instruction, _, _)| {
let is_get_local = matches!(instruction.operation(), Operation::GetLocal); if instruction.yields_value() {
if instruction.yields_value() && !is_get_local {
Some(instruction.a() + 1) Some(instruction.a() + 1)
} else { } else {
None None
@ -632,7 +630,11 @@ impl<'src> Compiler<'src> {
let rule = ParseRule::from(&operator); let rule = ParseRule::from(&operator);
let is_assignment = matches!( let is_assignment = matches!(
operator, operator,
Token::PlusEqual | Token::MinusEqual | Token::StarEqual | Token::SlashEqual Token::PlusEqual
| Token::MinusEqual
| Token::StarEqual
| Token::SlashEqual
| Token::PercentEqual
); );
if push_back_left { if push_back_left {
@ -1729,7 +1731,7 @@ impl<'src> Compiler<'src> {
) -> Result<(), CompileError> { ) -> Result<(), CompileError> {
if matches!( if matches!(
(left, right), (left, right),
(Type::Float, Type::Float) | (Type::Integer, Type::Integer) (Type::Byte, Type::Byte) | (Type::Float, Type::Float) | (Type::Integer, Type::Integer)
) { ) {
Ok(()) Ok(())
} else { } else {

View File

@ -120,10 +120,7 @@ fn add_character_and_string() {
), ),
(Instruction::r#return(true), Span(9, 9)) (Instruction::r#return(true), Span(9, 9))
], ],
vec![ vec![ConcreteValue::Character('a'), ConcreteValue::string("b")],
ConcreteValue::Character('a'),
ConcreteValue::String("b".to_string())
],
vec![] vec![]
)) ))
); );
@ -287,8 +284,8 @@ fn add_strings() {
(Instruction::r#return(true), Span(20, 20)) (Instruction::r#return(true), Span(20, 20))
], ],
vec![ vec![
ConcreteValue::String("Hello, ".to_string()), ConcreteValue::string("Hello, "),
ConcreteValue::String("world!".to_string()) ConcreteValue::string("world!")
], ],
vec![] vec![]
)) ))
@ -327,8 +324,5 @@ fn add_string_and_character() {
)) ))
); );
assert_eq!( assert_eq!(run(source), Ok(Some(ConcreteValue::string("ab"))));
run(source),
Ok(Some(ConcreteValue::String("ab".to_string())))
);
} }

View File

@ -18,9 +18,9 @@ fn divide_bytes() {
Instruction::divide( Instruction::divide(
Destination::Register(0), Destination::Register(0),
Argument::Constant(0), Argument::Constant(0),
Argument::Constant(0) Argument::Constant(1)
), ),
Span(0, 7) Span(5, 6)
), ),
(Instruction::r#return(true), Span(11, 11)) (Instruction::r#return(true), Span(11, 11))
], ],

View File

@ -18,13 +18,13 @@ fn multiply_floats() {
Instruction::multiply( Instruction::multiply(
Destination::Register(0), Destination::Register(0),
Argument::Constant(0), Argument::Constant(0),
Argument::Constant(1) Argument::Constant(0)
), ),
Span(4, 5) Span(4, 5)
), ),
(Instruction::r#return(true), Span(9, 9)), (Instruction::r#return(true), Span(9, 9)),
], ],
vec![ConcreteValue::Float(2.0), ConcreteValue::Float(2.0)], vec![ConcreteValue::Float(2.0)],
vec![] vec![]
)) ))
); );