Fix register allocation bug in compiler
This commit is contained in:
parent
e19ddbe2f3
commit
95cfaecd17
@ -325,10 +325,7 @@ impl<'src> Compiler<'src> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn next_integer_register(&self) -> u16 {
|
fn next_integer_register(&self) -> u16 {
|
||||||
println!("{:?}", self.instructions);
|
self.instructions
|
||||||
|
|
||||||
let next = self
|
|
||||||
.instructions
|
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.find_map(|(instruction, r#type, _)| {
|
.find_map(|(instruction, r#type, _)| {
|
||||||
@ -338,11 +335,7 @@ impl<'src> Compiler<'src> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or(self.minimum_integer_register);
|
.unwrap_or(self.minimum_integer_register)
|
||||||
|
|
||||||
println!("{}", next);
|
|
||||||
|
|
||||||
next
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_string_register(&self) -> u16 {
|
fn next_string_register(&self) -> u16 {
|
||||||
@ -350,9 +343,7 @@ impl<'src> Compiler<'src> {
|
|||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.find_map(|(instruction, r#type, _)| {
|
.find_map(|(instruction, r#type, _)| {
|
||||||
if r#type == &Type::String
|
if r#type == &Type::String {
|
||||||
|| (instruction.b_type() == TypeCode::STRING && instruction.yields_value())
|
|
||||||
{
|
|
||||||
Some(instruction.a_field() + 1)
|
Some(instruction.a_field() + 1)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -367,11 +358,9 @@ impl<'src> Compiler<'src> {
|
|||||||
.rev()
|
.rev()
|
||||||
.find_map(|(instruction, r#type, _)| {
|
.find_map(|(instruction, r#type, _)| {
|
||||||
if let Type::List { .. } = r#type {
|
if let Type::List { .. } = r#type {
|
||||||
if instruction.yields_value() {
|
Some(instruction.a_field() + 1)
|
||||||
Some(instruction.a_field() + 1)
|
} else if instruction.operation() == Operation::LOAD_LIST {
|
||||||
} else {
|
Some(instruction.a_field() + 1)
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -962,8 +951,6 @@ impl<'src> Compiler<'src> {
|
|||||||
self.advance()?;
|
self.advance()?;
|
||||||
self.parse_sub_expression(&rule.precedence)?;
|
self.parse_sub_expression(&rule.precedence)?;
|
||||||
|
|
||||||
println!("{:?}", self.instructions);
|
|
||||||
|
|
||||||
let (right_instruction, right_type, right_position) =
|
let (right_instruction, right_type, right_position) =
|
||||||
self.instructions
|
self.instructions
|
||||||
.pop()
|
.pop()
|
||||||
@ -981,8 +968,6 @@ impl<'src> Compiler<'src> {
|
|||||||
let (left, push_back_left) = self.handle_binary_argument(&left_instruction);
|
let (left, push_back_left) = self.handle_binary_argument(&left_instruction);
|
||||||
let (right, push_back_right) = self.handle_binary_argument(&right_instruction);
|
let (right, push_back_right) = self.handle_binary_argument(&right_instruction);
|
||||||
|
|
||||||
println!("{left_instruction} {right_instruction}");
|
|
||||||
|
|
||||||
// TODO: Check if the left type is a valid type for comparison
|
// TODO: Check if the left type is a valid type for comparison
|
||||||
// TODO: Check if the right type is a valid type for comparison
|
// TODO: Check if the right type is a valid type for comparison
|
||||||
// TODO: Check if the left and right types are compatible
|
// TODO: Check if the left and right types are compatible
|
||||||
|
Loading…
x
Reference in New Issue
Block a user