mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-21 12:07:56 +03:00
Update codegen
This commit is contained in:
parent
1a129ac375
commit
be3c58cf53
@ -258,7 +258,7 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
// Helper function to construct the instruction associated with a simple function call.
|
// Helper function to construct the instruction associated with a simple function call.
|
||||||
// This assumes that the function call has one output.
|
// This assumes that the function call has one output.
|
||||||
let mut construct_simple_function_call = |opcode: &Identifier, variant: &str, arguments: Vec<String>| {
|
let mut construct_simple_function_call = |opcode: &Identifier, variant: &str, arguments: Vec<String>| {
|
||||||
let mut instruction = format!(" {opcode}.{variant} ");
|
let mut instruction = format!(" {opcode}.{variant}");
|
||||||
for argument in arguments {
|
for argument in arguments {
|
||||||
write!(instruction, " {argument}").expect("failed to write to string");
|
write!(instruction, " {argument}").expect("failed to write to string");
|
||||||
}
|
}
|
||||||
@ -298,27 +298,30 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
}
|
}
|
||||||
Type::Identifier(Identifier { name: sym::Mapping, .. }) => match input.name.name {
|
Type::Identifier(Identifier { name: sym::Mapping, .. }) => match input.name.name {
|
||||||
sym::get => {
|
sym::get => {
|
||||||
let mut instruction = " get ".to_string();
|
let mut instruction = " get".to_string();
|
||||||
// Write the mapping name and the key.
|
|
||||||
write!(instruction, " {}[{}]", arguments[0], arguments[1]).expect("failed to write to string");
|
|
||||||
let destination_register = get_destination_register();
|
let destination_register = get_destination_register();
|
||||||
write!(instruction, " into {destination_register};").expect("failed to write to string");
|
// Write the mapping name and the key.
|
||||||
|
writeln!(instruction, " {}[{}] into {destination_register};", arguments[0], arguments[1])
|
||||||
|
.expect("failed to write to string");
|
||||||
(destination_register, instruction)
|
(destination_register, instruction)
|
||||||
}
|
}
|
||||||
sym::get_or => {
|
sym::get_or => {
|
||||||
let mut instruction = " get_or ".to_string();
|
let mut instruction = " get_or".to_string();
|
||||||
// Write the mapping name, the key, and the default value.
|
|
||||||
write!(instruction, " {}[{}] {}", arguments[0], arguments[1], arguments[2])
|
|
||||||
.expect("failed to write to string");
|
|
||||||
let destination_register = get_destination_register();
|
let destination_register = get_destination_register();
|
||||||
write!(instruction, " into {destination_register};").expect("failed to write to string");
|
// Write the mapping name, the key, and the default value.
|
||||||
|
writeln!(
|
||||||
|
instruction,
|
||||||
|
" {}[{}] {} into {destination_register};",
|
||||||
|
arguments[0], arguments[1], arguments[2]
|
||||||
|
)
|
||||||
|
.expect("failed to write to string");
|
||||||
(destination_register, instruction)
|
(destination_register, instruction)
|
||||||
}
|
}
|
||||||
sym::set => {
|
sym::set => {
|
||||||
// TODO: Fix when `put` is renamed to `set` in snarkVM
|
// TODO: Fix when `put` is renamed to `set` in snarkVM
|
||||||
let mut instruction = " put ".to_string();
|
let mut instruction = " put".to_string();
|
||||||
// Write the value, mapping name, and the key.
|
// Write the value, mapping name, and the key.
|
||||||
write!(instruction, " {} into {}[{}];", arguments[2], arguments[0], arguments[1])
|
writeln!(instruction, " {} into {}[{}];", arguments[2], arguments[0], arguments[1])
|
||||||
.expect("failed to write to string");
|
.expect("failed to write to string");
|
||||||
(String::new(), instruction)
|
(String::new(), instruction)
|
||||||
}
|
}
|
||||||
|
@ -166,8 +166,8 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
// if it is a standard function generate an Aleo `closure`,
|
// if it is a standard function generate an Aleo `closure`,
|
||||||
// otherwise, it is an inline function, in which case a function should not be generated.
|
// otherwise, it is an inline function, in which case a function should not be generated.
|
||||||
let mut function_string = match function.variant {
|
let mut function_string = match function.variant {
|
||||||
Variant::Transition => format!("function {}:\n", function.identifier),
|
Variant::Transition => format!("\nfunction {}:\n", function.identifier),
|
||||||
Variant::Standard => format!("closure {}:\n", function.identifier),
|
Variant::Standard => format!("\nclosure {}:\n", function.identifier),
|
||||||
Variant::Inline => return String::from("\n"),
|
Variant::Inline => return String::from("\n"),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
|
|
||||||
fn visit_mapping(&mut self, mapping: &'a Mapping) -> String {
|
fn visit_mapping(&mut self, mapping: &'a Mapping) -> String {
|
||||||
// Create the prefix of the mapping string, e.g. `mapping foo:`.
|
// Create the prefix of the mapping string, e.g. `mapping foo:`.
|
||||||
let mut mapping_string = format!("mapping {}:\n", mapping.identifier);
|
let mut mapping_string = format!("\nmapping {}:\n", mapping.identifier);
|
||||||
|
|
||||||
// Helper to construct the string associated with the type.
|
// Helper to construct the string associated with the type.
|
||||||
let create_type = |type_: &Type| {
|
let create_type = |type_: &Type| {
|
||||||
|
Loading…
Reference in New Issue
Block a user