indexmap over hashmap

This commit is contained in:
collin 2022-07-12 22:52:56 -07:00
parent 0bd0aed089
commit d151401385
4 changed files with 9 additions and 11 deletions

View File

@ -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(),
}
}
}

View File

@ -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.

View File

@ -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;
}

View File

@ -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 };