Function invocations working, stack unwinding correctly

This commit is contained in:
2024-11-29 01:17:12 -07:00
parent 2200df4977
commit 0bda3fb60d
3 changed files with 15 additions and 9 deletions

View File

@@ -7,12 +7,14 @@ push 1
push 2 push 2
push 3 push 3
j 1 j 1
sub sp sp 3 sub sp sp 0
pop ra
j ra
push 14
j 4
sub sp sp 0
pop ra pop ra
j ra j ra
main: main:
push 19 push 20
push 1 j 12
push 2
push 3
j 4

View File

@@ -172,7 +172,7 @@ impl<'a> Compiler<'a> {
let return_addr = self.current_line + to_write.lines().count() + 2; let return_addr = self.current_line + to_write.lines().count() + 2;
self.write_output(format!("push {return_addr}"))?; self.write_output(format!("push {return_addr}"))?;
self.output.write(to_write.as_bytes())?; self.output.write(to_write.as_bytes())?;
self.current_line = return_addr; self.current_line = return_addr - 1;
self.write_output(format!("j {function_line}"))?; self.write_output(format!("j {function_line}"))?;

View File

@@ -2,8 +2,12 @@ fn test(a, b, c) {
}; };
fn test2(x, y, z) { fn test2() {
test(1, 2, 3); test(1, 2, 3);
}; };
test2(1, 2, 3); fn test3() {
test2();
};
test3();