1
0

Continue fixing compiler for new instructions

This commit is contained in:
Jeff 2024-11-28 01:37:31 -05:00
parent 54ae05844d
commit 8b360d0825
2 changed files with 22 additions and 13 deletions

View File

@ -632,7 +632,15 @@ impl<'src> Compiler<'src> {
.push((right_instruction, right_type, right_position));
}
let destination = Destination::Register(self.next_register());
let destination = if is_assignment {
match left {
Argument::Register(register) => Destination::Register(register),
Argument::Local(local_index) => Destination::Local(local_index),
Argument::Constant(_) => Destination::Register(self.next_register()),
}
} else {
Destination::Register(self.next_register())
};
let instruction = match operator {
Token::Plus | Token::PlusEqual => Instruction::add(destination, left, right),
Token::Minus | Token::MinusEqual => Instruction::subtract(destination, left, right),
@ -1268,6 +1276,7 @@ impl<'src> Compiler<'src> {
should_return_value,
});
self.update_return_type(previous_expression_type)?;
self.emit_instruction(r#return, Type::None, self.current_position);
}

View File

@ -59,11 +59,11 @@ fn add_assign() {
),
(
Instruction::add(
Destination::Register(0),
Argument::Register(0),
Destination::Local(0),
Argument::Local(0),
Argument::Constant(2)
),
Type::Integer,
Type::None,
Span(17, 19)
),
(
@ -176,11 +176,11 @@ fn divide_assign() {
),
(
Instruction::divide(
Destination::Register(0),
Argument::Register(0),
Destination::Local(0),
Argument::Local(0),
Argument::Constant(0)
),
Type::Integer,
Type::None,
Span(17, 19)
),
(
@ -339,11 +339,11 @@ fn multiply_assign() {
),
(
Instruction::multiply(
Destination::Register(0),
Argument::Register(0),
Destination::Local(0),
Argument::Local(0),
Argument::Constant(2)
),
Type::Integer,
Type::None,
Span(17, 19)
),
(
@ -440,11 +440,11 @@ fn subtract_assign() {
),
(
Instruction::subtract(
Destination::Register(0),
Argument::Register(0),
Destination::Local(0),
Argument::Local(0),
Argument::Constant(2)
),
Type::Integer,
Type::None,
Span(18, 20)
),
(