diff --git a/compiler/passes/src/code_generation/generator.rs b/compiler/passes/src/code_generation/generator.rs index 2d8addd29a..2980b70149 100644 --- a/compiler/passes/src/code_generation/generator.rs +++ b/compiler/passes/src/code_generation/generator.rs @@ -18,7 +18,7 @@ use leo_ast::Function; use leo_errors::emitter::Handler; use leo_span::Symbol; -use std::collections::HashMap; +use indexmap::IndexMap; pub struct CodeGenerator<'a> { _handler: &'a Handler, @@ -27,9 +27,9 @@ pub struct CodeGenerator<'a> { /// Reference to the current function. pub(crate) current_function: Option<&'a Function>, /// Mapping of variables to registers. - pub(crate) variable_mapping: HashMap<&'a Symbol, String>, + pub(crate) variable_mapping: IndexMap<&'a Symbol, String>, /// Mapping of composite names to type (`circuit` or `register`). - pub(crate) composite_mapping: HashMap<&'a Symbol, String>, + pub(crate) composite_mapping: IndexMap<&'a Symbol, String>, } impl<'a> CodeGenerator<'a> { @@ -39,8 +39,8 @@ impl<'a> CodeGenerator<'a> { _handler: handler, next_register: 0, current_function: None, - variable_mapping: HashMap::new(), - composite_mapping: HashMap::new(), + variable_mapping: IndexMap::new(), + composite_mapping: IndexMap::new(), } } } diff --git a/compiler/passes/src/code_generation/visit_program.rs b/compiler/passes/src/code_generation/visit_program.rs index 493570eca0..85d0244aa7 100644 --- a/compiler/passes/src/code_generation/visit_program.rs +++ b/compiler/passes/src/code_generation/visit_program.rs @@ -18,8 +18,9 @@ use crate::CodeGenerator; use leo_ast::{Circuit, CircuitMember, Function, Program}; +use indexmap::IndexMap; use itertools::Itertools; -use std::{collections::HashMap, fmt::Write as _}; +use std::fmt::Write as _; impl<'a> CodeGenerator<'a> { pub(crate) fn visit_program(&mut self, input: &'a Program) -> String { @@ -103,7 +104,7 @@ impl<'a> CodeGenerator<'a> { fn visit_function(&mut self, function: &'a Function) -> String { // Initialize the state of `self` with the appropriate values before visiting `function`. self.next_register = 0; - self.variable_mapping = HashMap::new(); + self.variable_mapping = IndexMap::new(); self.current_function = Some(function); // Construct the header of the function. diff --git a/examples/helloworld/src/main.leo b/examples/helloworld/src/main.leo index 2b19c5000a..09ba46e0ac 100644 --- a/examples/helloworld/src/main.leo +++ b/examples/helloworld/src/main.leo @@ -1,7 +1,4 @@ // The 'helloworld' main function. -function compute(a: u32, b: u32) -> u32 { - return a + b; -} function main(public a: u32, b: u32) -> u32 { return a + b; } \ No newline at end of file diff --git a/examples/message/inputs/message.in b/examples/message/inputs/message.in index de962c0fc4..83df037171 100644 --- a/examples/message/inputs/message.in +++ b/examples/message/inputs/message.in @@ -1,3 +1,3 @@ // The program input for message/src/main.leo [main] -a: Message = Message { first: 2field, second: 3field}; +a: Message = Message { first: 2field, second: 3field };