mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 13:56:58 +03:00
Merge pull request #2121 from AleoHQ/fix/codegen-on-arc3
Codegen for ARC-003
This commit is contained in:
commit
a026cc69bc
@ -74,9 +74,9 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
.join("\n"),
|
.join("\n"),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Store closures and functions in separate strings.
|
// Store functions and transitions in separate strings.
|
||||||
let mut closures = String::new();
|
|
||||||
let mut functions = String::new();
|
let mut functions = String::new();
|
||||||
|
let mut transitions = String::new();
|
||||||
|
|
||||||
// Visit each `Function` in the Leo AST and produce Aleo instructions.
|
// Visit each `Function` in the Leo AST and produce Aleo instructions.
|
||||||
program_scope.functions.values().for_each(|function| {
|
program_scope.functions.values().for_each(|function| {
|
||||||
@ -85,11 +85,11 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
let function_string = self.visit_function(function);
|
let function_string = self.visit_function(function);
|
||||||
|
|
||||||
if self.is_transition_function {
|
if self.is_transition_function {
|
||||||
|
transitions.push_str(&function_string);
|
||||||
|
transitions.push('\n');
|
||||||
|
} else {
|
||||||
functions.push_str(&function_string);
|
functions.push_str(&function_string);
|
||||||
functions.push('\n');
|
functions.push('\n');
|
||||||
} else {
|
|
||||||
closures.push_str(&function_string);
|
|
||||||
closures.push('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unset the `is_transition_function` flag.
|
// Unset the `is_transition_function` flag.
|
||||||
@ -97,9 +97,9 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Closures must precede functions in the Aleo program.
|
// Closures must precede functions in the Aleo program.
|
||||||
program_string.push_str(&closures);
|
|
||||||
program_string.push('\n');
|
|
||||||
program_string.push_str(&functions);
|
program_string.push_str(&functions);
|
||||||
|
program_string.push('\n');
|
||||||
|
program_string.push_str(&transitions);
|
||||||
|
|
||||||
program_string
|
program_string
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
self.composite_mapping
|
self.composite_mapping
|
||||||
.insert(&struct_.identifier.name, (false, String::from("private"))); // todo: private by default here.
|
.insert(&struct_.identifier.name, (false, String::from("private"))); // todo: private by default here.
|
||||||
|
|
||||||
let mut output_string = format!("interface {}:\n", struct_.identifier); // todo: check if this is safe from name conflicts.
|
let mut output_string = format!("struct {}:\n", struct_.identifier); // todo: check if this is safe from name conflicts.
|
||||||
|
|
||||||
// Construct and append the record variables.
|
// Construct and append the record variables.
|
||||||
for var in struct_.members.iter() {
|
for var in struct_.members.iter() {
|
||||||
@ -165,10 +165,10 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
self.current_function = Some(function);
|
self.current_function = Some(function);
|
||||||
|
|
||||||
// Construct the header of the function.
|
// Construct the header of the function.
|
||||||
// If a function is a program function, generate an Aleo `function`, otherwise generate an Aleo `closure`.
|
// If a function is a transition function, generate an Aleo `transition`, otherwise generate an Aleo `function`.
|
||||||
let mut function_string = match self.is_transition_function {
|
let mut function_string = match self.is_transition_function {
|
||||||
true => format!("function {}:\n", function.identifier),
|
true => format!("transition {}:\n", function.identifier),
|
||||||
false => format!("closure {}:\n", function.identifier),
|
false => format!("function {}:\n", function.identifier),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Construct and append the input declarations of the function.
|
// Construct and append the input declarations of the function.
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n input r0 as boolean;\\n input r1 as boolean;\\n output r0 as boolean;\\n\\n\\n\", Nom(Tag)), (\"\\n\\n\\nclosure main:\\n input r0 as boolean;\\n input r1 as boolean;\\n output r0 as boolean;\\n\\n\\n\", Nom(Alt)), (\"\\n\\n\\nclosure main:\\n input r0 as boolean;\\n input r1 as boolean;\\n output r0 as boolean;\\n\\n\\n\", Nom(Many1))] }"
|
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"function main:\\n input r0 as boolean;\\n input r1 as boolean;\\n output r0 as boolean;\\n\\n\\n\", Nom(Tag)), (\"\\n\\n\\nfunction main:\\n input r0 as boolean;\\n input r1 as boolean;\\n output r0 as boolean;\\n\\n\\n\", Nom(Alt)), (\"\\n\\n\\nfunction main:\\n input r0 as boolean;\\n input r1 as boolean;\\n output r0 as boolean;\\n\\n\\n\", Nom(Many1))] }"
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"closure main:\\n input r0 as boolean;\\n input r1 as boolean;\\n\\n\\n\", Nom(Tag)), (\"\\n\\n\\nclosure main:\\n input r0 as boolean;\\n input r1 as boolean;\\n\\n\\n\", Nom(Alt)), (\"\\n\\n\\nclosure main:\\n input r0 as boolean;\\n input r1 as boolean;\\n\\n\\n\", Nom(Many1))] }"
|
- "Failed to parse string. Parsing Error: VerboseError { errors: [(\"function main:\\n input r0 as boolean;\\n input r1 as boolean;\\n\\n\\n\", Nom(Tag)), (\"\\n\\n\\nfunction main:\\n input r0 as boolean;\\n input r1 as boolean;\\n\\n\\n\", Nom(Alt)), (\"\\n\\n\\nfunction main:\\n input r0 as boolean;\\n input r1 as boolean;\\n\\n\\n\", Nom(Many1))] }"
|
||||||
|
Loading…
Reference in New Issue
Block a user