Update tests to reflect new changes with stack cleanup in functions that return tuples
This commit is contained in:
@@ -59,6 +59,7 @@ fn nested_binary_expressions() -> Result<()> {
|
||||
pop r8
|
||||
pop r9
|
||||
pop r10
|
||||
push sp
|
||||
push ra
|
||||
add r1 r10 r9
|
||||
mul r2 r1 r8
|
||||
@@ -66,6 +67,7 @@ fn nested_binary_expressions() -> Result<()> {
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
push 10
|
||||
|
||||
@@ -21,9 +21,11 @@ fn no_arguments() -> anyhow::Result<()> {
|
||||
"
|
||||
j main
|
||||
doSomething:
|
||||
push sp
|
||||
push ra
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
jal doSomething
|
||||
@@ -65,12 +67,14 @@ fn let_var_args() -> anyhow::Result<()> {
|
||||
j main
|
||||
mul2:
|
||||
pop r8
|
||||
push sp
|
||||
push ra
|
||||
mul r1 r8 2
|
||||
move r15 r1
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
__internal_L2:
|
||||
@@ -136,11 +140,13 @@ fn inline_literal_args() -> anyhow::Result<()> {
|
||||
doSomething:
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
move r15 5
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
move r8 123
|
||||
@@ -182,9 +188,11 @@ fn mixed_args() -> anyhow::Result<()> {
|
||||
doSomething:
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
move r8 123
|
||||
@@ -227,11 +235,13 @@ fn with_return_statement() -> anyhow::Result<()> {
|
||||
j main
|
||||
doSomething:
|
||||
pop r8
|
||||
push sp
|
||||
push ra
|
||||
move r15 456
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
push 123
|
||||
@@ -268,10 +278,12 @@ fn with_negative_return_literal() -> anyhow::Result<()> {
|
||||
"
|
||||
j main
|
||||
doSomething:
|
||||
push sp
|
||||
push ra
|
||||
move r15 -1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
jal doSomething
|
||||
|
||||
@@ -161,11 +161,13 @@ fn test_boolean_return() -> anyhow::Result<()> {
|
||||
"
|
||||
j main
|
||||
getTrue:
|
||||
push sp
|
||||
push ra
|
||||
move r15 1
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
jal getTrue
|
||||
|
||||
@@ -189,12 +189,14 @@ fn device_used_in_function() -> anyhow::Result<()> {
|
||||
"
|
||||
j main
|
||||
check_power:
|
||||
push sp
|
||||
push ra
|
||||
l r1 d0 On
|
||||
move r15 r1
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
jal check_power
|
||||
|
||||
@@ -315,10 +315,12 @@ fn function_with_no_return() -> anyhow::Result<()> {
|
||||
"
|
||||
j main
|
||||
no_return:
|
||||
push sp
|
||||
push ra
|
||||
move r8 5
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
jal no_return
|
||||
@@ -576,8 +578,9 @@ fn function_with_many_parameters() -> anyhow::Result<()> {
|
||||
pop r12
|
||||
pop r13
|
||||
pop r14
|
||||
push sp
|
||||
push ra
|
||||
sub r0 sp 2
|
||||
sub r0 sp 3
|
||||
get r1 db r0
|
||||
add r2 r1 r14
|
||||
add r3 r2 r13
|
||||
@@ -590,7 +593,7 @@ fn function_with_many_parameters() -> anyhow::Result<()> {
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 1
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
push 1
|
||||
@@ -635,21 +638,25 @@ fn tuple_declaration_with_functions() -> anyhow::Result<()> {
|
||||
indoc! {"
|
||||
j main
|
||||
doSomething:
|
||||
push sp
|
||||
push ra
|
||||
l r0 db Setting
|
||||
push r0
|
||||
l r0 db Temperature
|
||||
push r0
|
||||
l r1 db Setting
|
||||
push r1
|
||||
l r2 db Temperature
|
||||
push r2
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal doSomething
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"}
|
||||
);
|
||||
|
||||
@@ -679,19 +686,23 @@ fn tuple_from_simple_function() -> anyhow::Result<()> {
|
||||
indoc! {"
|
||||
j main
|
||||
get_pair:
|
||||
push sp
|
||||
push ra
|
||||
push 1
|
||||
push 2
|
||||
move r15 2
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal get_pair
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"}
|
||||
);
|
||||
|
||||
|
||||
@@ -31,10 +31,11 @@ fn test_function_declaration_with_spillover_params() -> anyhow::Result<()> {
|
||||
pop r12
|
||||
pop r13
|
||||
pop r14
|
||||
push sp
|
||||
push ra
|
||||
sub r0 sp 3
|
||||
sub r0 sp 4
|
||||
get r1 db r0
|
||||
sub r0 sp 2
|
||||
sub r0 sp 3
|
||||
get r2 db r0
|
||||
add r3 r1 r2
|
||||
add r4 r3 r14
|
||||
@@ -48,7 +49,7 @@ fn test_function_declaration_with_spillover_params() -> anyhow::Result<()> {
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
move r8 1
|
||||
@@ -97,6 +98,7 @@ fn test_early_return() -> anyhow::Result<()> {
|
||||
"
|
||||
j main
|
||||
doSomething:
|
||||
push sp
|
||||
push ra
|
||||
seq r1 1 1
|
||||
beqz r1 __internal_L2
|
||||
@@ -106,6 +108,7 @@ fn test_early_return() -> anyhow::Result<()> {
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
jal doSomething
|
||||
@@ -138,9 +141,11 @@ fn test_function_declaration_with_register_params() -> anyhow::Result<()> {
|
||||
doSomething:
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
"}
|
||||
);
|
||||
|
||||
@@ -95,12 +95,14 @@ fn function_parameter_scope() -> anyhow::Result<()> {
|
||||
j main
|
||||
double:
|
||||
pop r8
|
||||
push sp
|
||||
push ra
|
||||
mul r1 r8 2
|
||||
move r15 r1
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
push 5
|
||||
@@ -334,20 +336,24 @@ fn function_scope_isolation() -> anyhow::Result<()> {
|
||||
"
|
||||
j main
|
||||
func1:
|
||||
push sp
|
||||
push ra
|
||||
move r8 10
|
||||
move r15 r8
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
func2:
|
||||
push sp
|
||||
push ra
|
||||
move r8 20
|
||||
move r15 r8
|
||||
j __internal_L2
|
||||
__internal_L2:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
jal func1
|
||||
@@ -390,19 +396,23 @@ fn tuple_unpacking_scope() -> anyhow::Result<()> {
|
||||
"
|
||||
j main
|
||||
pair:
|
||||
push sp
|
||||
push ra
|
||||
push 1
|
||||
push 2
|
||||
move r15 2
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal pair
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
add r1 r8 r9
|
||||
move r10 r1
|
||||
"
|
||||
|
||||
@@ -218,19 +218,23 @@ mod test {
|
||||
"
|
||||
j main
|
||||
getPair:
|
||||
push sp
|
||||
push ra
|
||||
push 10
|
||||
push 20
|
||||
move r15 20
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal getPair
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"
|
||||
}
|
||||
);
|
||||
@@ -262,19 +266,23 @@ mod test {
|
||||
"
|
||||
j main
|
||||
getPair:
|
||||
push sp
|
||||
push ra
|
||||
push 5
|
||||
push 15
|
||||
move r15 15
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal getPair
|
||||
pop r0
|
||||
pop r8
|
||||
move sp r15
|
||||
"
|
||||
}
|
||||
);
|
||||
@@ -306,21 +314,25 @@ mod test {
|
||||
"
|
||||
j main
|
||||
getTriple:
|
||||
push sp
|
||||
push ra
|
||||
push 1
|
||||
push 2
|
||||
push 3
|
||||
move r15 3
|
||||
sub r0 sp 5
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 3
|
||||
sub r0 sp 4
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal getTriple
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"
|
||||
}
|
||||
);
|
||||
@@ -354,14 +366,17 @@ mod test {
|
||||
"
|
||||
j main
|
||||
getPair:
|
||||
push sp
|
||||
push ra
|
||||
push 42
|
||||
push 84
|
||||
move r15 84
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
move r8 1
|
||||
@@ -369,6 +384,7 @@ mod test {
|
||||
jal getPair
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"
|
||||
}
|
||||
);
|
||||
@@ -433,24 +449,30 @@ mod test {
|
||||
"
|
||||
j main
|
||||
doSomething:
|
||||
push sp
|
||||
push ra
|
||||
push 1
|
||||
push 2
|
||||
move r15 2
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
doSomethingElse:
|
||||
push sp
|
||||
push ra
|
||||
jal doSomething
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
move r15 r9
|
||||
j __internal_L2
|
||||
__internal_L2:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
jal doSomethingElse
|
||||
@@ -492,28 +514,34 @@ mod test {
|
||||
"
|
||||
j main
|
||||
getValue:
|
||||
push sp
|
||||
push ra
|
||||
move r15 42
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
getTuple:
|
||||
push sp
|
||||
push ra
|
||||
jal getValue
|
||||
move r8 r15
|
||||
push r8
|
||||
push r8
|
||||
move r15 r8
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L2
|
||||
__internal_L2:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal getTuple
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"
|
||||
}
|
||||
);
|
||||
@@ -542,6 +570,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_multiple_tuple_returns_in_function() -> anyhow::Result<()> {
|
||||
// Test multiple return paths in tuple-returning function
|
||||
let compiled = compile!(
|
||||
check
|
||||
r#"
|
||||
@@ -570,28 +599,34 @@ mod test {
|
||||
j main
|
||||
getValue:
|
||||
pop r8
|
||||
push sp
|
||||
push ra
|
||||
beqz r8 __internal_L3
|
||||
push 1
|
||||
push 2
|
||||
move r15 2
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
j __internal_L2
|
||||
__internal_L3:
|
||||
push 3
|
||||
push 4
|
||||
move r15 4
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L2:
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
push 1
|
||||
jal getValue
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"
|
||||
},
|
||||
);
|
||||
@@ -626,14 +661,17 @@ mod test {
|
||||
add:
|
||||
pop r8
|
||||
pop r9
|
||||
push sp
|
||||
push ra
|
||||
push r9
|
||||
push r8
|
||||
move r15 r8
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
push 5
|
||||
@@ -641,6 +679,7 @@ mod test {
|
||||
jal add
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"
|
||||
}
|
||||
);
|
||||
@@ -678,32 +717,40 @@ mod test {
|
||||
"
|
||||
j main
|
||||
inner:
|
||||
push sp
|
||||
push ra
|
||||
push 1
|
||||
push 2
|
||||
move r15 2
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
outer:
|
||||
push sp
|
||||
push ra
|
||||
jal inner
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
push r9
|
||||
push r8
|
||||
move r15 r8
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L2
|
||||
__internal_L2:
|
||||
pop ra
|
||||
sub sp sp 2
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal outer
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
"
|
||||
}
|
||||
);
|
||||
@@ -839,18 +886,22 @@ mod test {
|
||||
"
|
||||
j main
|
||||
getValue:
|
||||
push sp
|
||||
push ra
|
||||
move r15 42
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
getOther:
|
||||
push sp
|
||||
push ra
|
||||
move r15 99
|
||||
j __internal_L2
|
||||
__internal_L2:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
push r8
|
||||
@@ -1006,11 +1057,13 @@ mod test {
|
||||
"
|
||||
j main
|
||||
getY:
|
||||
push sp
|
||||
push ra
|
||||
move r15 42
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
l r1 db Setting
|
||||
@@ -1053,18 +1106,22 @@ mod test {
|
||||
"
|
||||
j main
|
||||
getValue:
|
||||
push sp
|
||||
push ra
|
||||
move r15 10
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
getOther:
|
||||
push sp
|
||||
push ra
|
||||
move r15 20
|
||||
j __internal_L2
|
||||
__internal_L2:
|
||||
pop ra
|
||||
pop sp
|
||||
j ra
|
||||
main:
|
||||
push r8
|
||||
@@ -1114,6 +1171,7 @@ mod test {
|
||||
"
|
||||
j main
|
||||
get8:
|
||||
push sp
|
||||
push ra
|
||||
push 1
|
||||
push 2
|
||||
@@ -1123,11 +1181,13 @@ mod test {
|
||||
push 6
|
||||
push 7
|
||||
push 8
|
||||
move r15 8
|
||||
sub r0 sp 10
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
sub sp sp 8
|
||||
sub r0 sp 9
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
jal get8
|
||||
@@ -1141,6 +1201,7 @@ mod test {
|
||||
pop r10
|
||||
pop r9
|
||||
pop r8
|
||||
move sp r15
|
||||
sub r0 sp 1
|
||||
get r1 db r0
|
||||
add r2 r8 r1
|
||||
@@ -1152,4 +1213,79 @@ mod test {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_return_in_loop() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
check
|
||||
r#"
|
||||
fn getValues(i) {
|
||||
return (i, i * 2);
|
||||
};
|
||||
|
||||
let sum = 0;
|
||||
let i = 0;
|
||||
loop {
|
||||
let (a, b) = getValues(i);
|
||||
sum = sum + a + b;
|
||||
i = i + 1;
|
||||
if (i > 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
getValues:
|
||||
pop r8
|
||||
push sp
|
||||
push ra
|
||||
push r8
|
||||
mul r1 r8 2
|
||||
push r1
|
||||
sub r0 sp 4
|
||||
get r0 db r0
|
||||
move r15 r0
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
sub r0 sp 3
|
||||
get ra db r0
|
||||
j ra
|
||||
main:
|
||||
move r8 0
|
||||
move r9 0
|
||||
__internal_L2:
|
||||
push r9
|
||||
jal getValues
|
||||
pop r11
|
||||
pop r10
|
||||
move sp r15
|
||||
add r1 r8 r10
|
||||
add r2 r1 r11
|
||||
move r8 r2
|
||||
add r3 r9 1
|
||||
move r9 r3
|
||||
sgt r4 r9 3
|
||||
beqz r4 __internal_L4
|
||||
j __internal_L3
|
||||
__internal_L4:
|
||||
j __internal_L2
|
||||
__internal_L3:
|
||||
"
|
||||
}
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user