diff --git a/compiler/passes/src/code_generation/visit_expressions.rs b/compiler/passes/src/code_generation/visit_expressions.rs index e1c28280d7..564669dc15 100644 --- a/compiler/passes/src/code_generation/visit_expressions.rs +++ b/compiler/passes/src/code_generation/visit_expressions.rs @@ -258,7 +258,7 @@ impl<'a> CodeGenerator<'a> { // Helper function to construct the instruction associated with a simple function call. // This assumes that the function call has one output. let mut construct_simple_function_call = |opcode: &Identifier, variant: &str, arguments: Vec| { - let mut instruction = format!(" {opcode}.{variant} "); + let mut instruction = format!(" {opcode}.{variant}"); for argument in arguments { 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 { sym::get => { - 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 mut instruction = " get".to_string(); 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) } sym::get_or => { - 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 mut instruction = " get_or".to_string(); 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) } sym::set => { // 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!(instruction, " {} into {}[{}];", arguments[2], arguments[0], arguments[1]) + writeln!(instruction, " {} into {}[{}];", arguments[2], arguments[0], arguments[1]) .expect("failed to write to string"); (String::new(), instruction) } diff --git a/compiler/passes/src/code_generation/visit_program.rs b/compiler/passes/src/code_generation/visit_program.rs index 902ba53735..9830357fdb 100644 --- a/compiler/passes/src/code_generation/visit_program.rs +++ b/compiler/passes/src/code_generation/visit_program.rs @@ -166,8 +166,8 @@ impl<'a> CodeGenerator<'a> { // 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. let mut function_string = match function.variant { - Variant::Transition => format!("function {}:\n", function.identifier), - Variant::Standard => format!("closure {}:\n", function.identifier), + Variant::Transition => format!("\nfunction {}:\n", function.identifier), + Variant::Standard => format!("\nclosure {}:\n", function.identifier), Variant::Inline => return String::from("\n"), }; @@ -249,7 +249,7 @@ impl<'a> CodeGenerator<'a> { fn visit_mapping(&mut self, mapping: &'a Mapping) -> String { // 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. let create_type = |type_: &Type| {