Add compiler test for function calls; fix bugs; regen test expectations

This commit is contained in:
Pranav Gaddamadugu 2022-08-04 21:21:56 -07:00
parent 34be1fc39d
commit 1e4f2b1cca
14 changed files with 53 additions and 18 deletions

View File

@ -273,7 +273,7 @@ impl<'a> CodeGenerator<'a> {
}
fn visit_call(&mut self, input: &'a CallExpression) -> (String, String) {
let mut call_instruction = format!("call {} ", input.function);
let mut call_instruction = format!(" call {} ", input.function);
let mut instructions = String::new();
for argument in input.arguments.iter() {

View File

@ -77,17 +77,17 @@ impl<'a> CodeGenerator<'a> {
let function_string = self.visit_function(function);
if self.is_program_function {
closures.push_str(&function_string);
closures.push('\n');
} else {
functions.push_str(&function_string);
functions.push('\n');
} else {
closures.push_str(&function_string);
closures.push('\n');
}
// Unset the `is_program_function` flag.
self.is_program_function = false;
});
// Unset the `is_program_function` flag.
self.is_program_function = false;
// Closures must precede functions in the Aleo program.
program_string.push_str(&closures);
program_string.push('\n');
@ -164,7 +164,11 @@ impl<'a> CodeGenerator<'a> {
self.current_function = Some(function);
// Construct the header of the function.
let mut function_string = format!("function {}:\n", function.identifier);
// If a function is a program function, generate an Aleo `function`, otherwise generate an Aleo `closure`.
let mut function_string = match self.is_program_function {
true => format!("function {}:\n", function.identifier),
false => format!("closure {}:\n", function.identifier),
};
// Construct and append the input declarations of the function.
for input in function.input.iter() {

View File

@ -0,0 +1,22 @@
/*
namespace: Compile
expectation: Pass
input_file: inputs/dummy.in
*/
@program
function main(a: u32, b: u32, y: bool) -> u32 {
if y {
return adder(a, b);
} else {
return subber(a, b);
}
}
function adder(a: u32, b: u32) -> u32 {
return a + b;
}
function subber(a: u32, b: u32) -> u32 {
return a - b;
}

View File

@ -0,0 +1,9 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: 7771059685b08997e10c889f701cab07503de86515a498e7e3b332eb0499bd80
initial_ast: e4d2863962de0163515a775493ed831b2f06bb58bdbb7906de9e9a9f3c08db7c
unrolled_ast: e4d2863962de0163515a775493ed831b2f06bb58bdbb7906de9e9a9f3c08db7c
ssa_ast: 01b6f834110362be6c0c449feaac4c5957a1f0daa02df7cb872e78bf8e06f527

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 2i128 into r1;\\n output r1 as i128;\\n\\n\", Nom(Tag)), (\"\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 2i128 into r1;\\n output r1 as i128;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 2i128 into r1;\\n output r1 as i128;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 2i128 into r1;\\n output r1 as i128;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 2i128 into r1;\\n output r1 as i128;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 2i128 into r1;\\n output r1 as i128;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 2i128 into r1;\\n output r1 as i128;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 1i128 into r1;\\n neg r1 into r2;\\n output r2 as i128;\\n\\n\", Nom(Tag)), (\"\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 1i128 into r1;\\n neg r1 into r2;\\n output r2 as i128;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 1i128 into r1;\\n neg r1 into r2;\\n output r2 as i128;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 1i128 into r1;\\n neg r1 into r2;\\n output r2 as i128;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 1i128 into r1;\\n neg r1 into r2;\\n output r2 as i128;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 1i128 into r1;\\n neg r1 into r2;\\n output r2 as i128;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 170141183460469231731687303715884105727i128 into r0;\\n sub r0 1i128 into r1;\\n neg r1 into r2;\\n output r2 as i128;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 32767i16 into r0;\\n sub r0 2i16 into r1;\\n output r1 as i16;\\n\\n\", Nom(Tag)), (\"\\n neg 32767i16 into r0;\\n sub r0 2i16 into r1;\\n output r1 as i16;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 32767i16 into r0;\\n sub r0 2i16 into r1;\\n output r1 as i16;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 32767i16 into r0;\\n sub r0 2i16 into r1;\\n output r1 as i16;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 32767i16 into r0;\\n sub r0 2i16 into r1;\\n output r1 as i16;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 32767i16 into r0;\\n sub r0 2i16 into r1;\\n output r1 as i16;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 32767i16 into r0;\\n sub r0 2i16 into r1;\\n output r1 as i16;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 32767i16 into r0;\\n sub r0 1i16 into r1;\\n neg r1 into r2;\\n output r2 as i16;\\n\\n\", Nom(Tag)), (\"\\n neg 32767i16 into r0;\\n sub r0 1i16 into r1;\\n neg r1 into r2;\\n output r2 as i16;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 32767i16 into r0;\\n sub r0 1i16 into r1;\\n neg r1 into r2;\\n output r2 as i16;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 32767i16 into r0;\\n sub r0 1i16 into r1;\\n neg r1 into r2;\\n output r2 as i16;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 32767i16 into r0;\\n sub r0 1i16 into r1;\\n neg r1 into r2;\\n output r2 as i16;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 32767i16 into r0;\\n sub r0 1i16 into r1;\\n neg r1 into r2;\\n output r2 as i16;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 32767i16 into r0;\\n sub r0 1i16 into r1;\\n neg r1 into r2;\\n output r2 as i16;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 2147483647i32 into r0;\\n sub r0 2i32 into r1;\\n output r1 as i32;\\n\\n\", Nom(Tag)), (\"\\n neg 2147483647i32 into r0;\\n sub r0 2i32 into r1;\\n output r1 as i32;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 2147483647i32 into r0;\\n sub r0 2i32 into r1;\\n output r1 as i32;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 2147483647i32 into r0;\\n sub r0 2i32 into r1;\\n output r1 as i32;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 2147483647i32 into r0;\\n sub r0 2i32 into r1;\\n output r1 as i32;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 2147483647i32 into r0;\\n sub r0 2i32 into r1;\\n output r1 as i32;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 2147483647i32 into r0;\\n sub r0 2i32 into r1;\\n output r1 as i32;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 2147483647i32 into r0;\\n sub r0 1i32 into r1;\\n neg r1 into r2;\\n output r2 as i32;\\n\\n\", Nom(Tag)), (\"\\n neg 2147483647i32 into r0;\\n sub r0 1i32 into r1;\\n neg r1 into r2;\\n output r2 as i32;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 2147483647i32 into r0;\\n sub r0 1i32 into r1;\\n neg r1 into r2;\\n output r2 as i32;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 2147483647i32 into r0;\\n sub r0 1i32 into r1;\\n neg r1 into r2;\\n output r2 as i32;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 2147483647i32 into r0;\\n sub r0 1i32 into r1;\\n neg r1 into r2;\\n output r2 as i32;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 2147483647i32 into r0;\\n sub r0 1i32 into r1;\\n neg r1 into r2;\\n output r2 as i32;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 2147483647i32 into r0;\\n sub r0 1i32 into r1;\\n neg r1 into r2;\\n output r2 as i32;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 9223372036854775807i64 into r0;\\n sub r0 2i64 into r1;\\n output r1 as i64;\\n\\n\", Nom(Tag)), (\"\\n neg 9223372036854775807i64 into r0;\\n sub r0 2i64 into r1;\\n output r1 as i64;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 2i64 into r1;\\n output r1 as i64;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 2i64 into r1;\\n output r1 as i64;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 2i64 into r1;\\n output r1 as i64;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 2i64 into r1;\\n output r1 as i64;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 2i64 into r1;\\n output r1 as i64;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 9223372036854775807i64 into r0;\\n sub r0 1i64 into r1;\\n neg r1 into r2;\\n output r2 as i64;\\n\\n\", Nom(Tag)), (\"\\n neg 9223372036854775807i64 into r0;\\n sub r0 1i64 into r1;\\n neg r1 into r2;\\n output r2 as i64;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 1i64 into r1;\\n neg r1 into r2;\\n output r2 as i64;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 1i64 into r1;\\n neg r1 into r2;\\n output r2 as i64;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 1i64 into r1;\\n neg r1 into r2;\\n output r2 as i64;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 1i64 into r1;\\n neg r1 into r2;\\n output r2 as i64;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 9223372036854775807i64 into r0;\\n sub r0 1i64 into r1;\\n neg r1 into r2;\\n output r2 as i64;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 127i8 into r0;\\n sub r0 2i8 into r1;\\n output r1 as i8;\\n\\n\", Nom(Tag)), (\"\\n neg 127i8 into r0;\\n sub r0 2i8 into r1;\\n output r1 as i8;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 127i8 into r0;\\n sub r0 2i8 into r1;\\n output r1 as i8;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 127i8 into r0;\\n sub r0 2i8 into r1;\\n output r1 as i8;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 127i8 into r0;\\n sub r0 2i8 into r1;\\n output r1 as i8;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 127i8 into r0;\\n sub r0 2i8 into r1;\\n output r1 as i8;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 127i8 into r0;\\n sub r0 2i8 into r1;\\n output r1 as i8;\\n\\n\\n\", Nom(Many1))] }"

View File

@ -2,4 +2,4 @@
namespace: Compile
expectation: Fail
outputs:
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"neg 127i8 into r0;\\n sub r0 1i8 into r1;\\n neg r1 into r2;\\n output r2 as i8;\\n\\n\", Nom(Tag)), (\"\\n neg 127i8 into r0;\\n sub r0 1i8 into r1;\\n neg r1 into r2;\\n output r2 as i8;\\n\\n\", Nom(Many1)), (\"function main:\\n neg 127i8 into r0;\\n sub r0 1i8 into r1;\\n neg r1 into r2;\\n output r2 as i8;\\n\\n\", Nom(Alt)), (\"function main:\\n neg 127i8 into r0;\\n sub r0 1i8 into r1;\\n neg r1 into r2;\\n output r2 as i8;\\n\\n\", Nom(Many1))] }"
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n neg 127i8 into r0;\\n sub r0 1i8 into r1;\\n neg r1 into r2;\\n output r2 as i8;\\n\\n\\n\", Nom(Tag)), (\"closure main:\\n neg 127i8 into r0;\\n sub r0 1i8 into r1;\\n neg r1 into r2;\\n output r2 as i8;\\n\\n\\n\", Nom(Alt)), (\"closure main:\\n neg 127i8 into r0;\\n sub r0 1i8 into r1;\\n neg r1 into r2;\\n output r2 as i8;\\n\\n\\n\", Nom(Many1))] }"