Fix function invocation stack underflow

This commit is contained in:
2025-12-11 01:03:43 -07:00
parent 0732f68bcf
commit 342b1ab107
13 changed files with 295 additions and 167 deletions

View File

@@ -94,19 +94,21 @@ impl<'a, 'b> VariableScope<'a, 'b> {
pub const RETURN_REGISTER: u8 = 15;
pub const TEMP_STACK_REGISTER: u8 = 0;
pub fn registers(&self) -> impl Iterator<Item = &u8> {
self.var_lookup_table
.values()
.filter(|val| {
matches!(
val,
VariableLocation::Temporary(_) | VariableLocation::Persistant(_)
)
})
.map(|loc| match loc {
VariableLocation::Persistant(reg) | VariableLocation::Temporary(reg) => reg,
_ => unreachable!(),
})
pub fn registers(&self) -> Vec<u8> {
let mut used = Vec::new();
for r in TEMP {
if !self.temporary_vars.contains(&r) {
used.push(r);
}
}
for r in PERSIST {
if !self.persistant_vars.contains(&r) {
used.push(r);
}
}
used
}
pub fn scoped(parent: &'b VariableScope<'a, 'b>) -> Self {