Functions returning tuples somewhat working, but they clobber the popped ra

This commit is contained in:
2025-12-29 23:55:00 -07:00
parent b51800eb77
commit e94fc0f5de
2 changed files with 262 additions and 106 deletions

View File

@@ -170,10 +170,27 @@ mod test {
"#
);
// Basic structure check - should have the function label and main
assert!(compiled.contains("getPair:"));
assert!(compiled.contains("main:"));
assert!(compiled.contains("jal getPair"));
assert_eq!(
compiled,
indoc! {
"
j main
getPair:
push ra
push 10
push 20
move r15 1
j __internal_L1
__internal_L1:
pop ra
j ra
main:
jal getPair
pop r9
pop r8
"
}
);
Ok(())
}
@@ -190,10 +207,26 @@ mod test {
"#
);
// Basic structure check
assert!(compiled.contains("getPair:"));
assert!(compiled.contains("main:"));
assert!(compiled.contains("jal getPair"));
assert_eq!(
compiled,
indoc! {
"
j main
getPair:
push ra
push 5
push 15
move r15 1
j __internal_L1
__internal_L1:
pop ra
j ra
main:
jal getPair
pop r8
"
}
);
Ok(())
}
@@ -210,10 +243,29 @@ mod test {
"#
);
// Basic structure check
assert!(compiled.contains("getTriple:"));
assert!(compiled.contains("main:"));
assert!(compiled.contains("jal getTriple"));
assert_eq!(
compiled,
indoc! {
"
j main
getTriple:
push ra
push 1
push 2
push 3
move r15 1
j __internal_L1
__internal_L1:
pop ra
j ra
main:
jal getTriple
pop r10
pop r9
pop r8
"
}
);
Ok(())
}
@@ -232,10 +284,33 @@ mod test {
"#
);
// Basic structure check
assert!(compiled.contains("getPair:"));
assert!(compiled.contains("main:"));
assert!(compiled.contains("jal getPair"));
assert_eq!(
compiled,
indoc! {
"
j main
getPair:
push ra
push 42
push 84
move r15 1
j __internal_L1
__internal_L1:
pop ra
j ra
main:
move r8 0
move r9 0
push r8
push r9
jal getPair
pop r9
pop r8
pop r9
pop r8
"
}
);
Ok(())
}