فهرست منبع

zkas: Use IndexMap instead of HashMap to keep order.

parazyd 4 سال پیش
والد
کامیت
b05a32d0e1
4فایلهای تغییر یافته به همراه11 افزوده شده و 8 حذف شده
  1. 1 0
      zkas/Cargo.lock
  2. 1 0
      zkas/Cargo.toml
  3. 3 3
      zkas/src/ast.rs
  4. 6 5
      zkas/src/parser.rs

+ 1 - 0
zkas/Cargo.lock

@@ -302,6 +302,7 @@ version = "0.0.1"
 dependencies = [
  "anyhow",
  "clap",
+ "indexmap",
  "itertools",
  "termion",
 ]

+ 1 - 0
zkas/Cargo.toml

@@ -10,5 +10,6 @@ edition = "2021"
 [dependencies]
 anyhow = "1.0.52"
 clap = {version = "3.0.0", features = ["derive"]}
+indexmap = "1.7.0"
 itertools = "0.10.3"
 termion = "1.5.6"

+ 3 - 3
zkas/src/ast.rs

@@ -1,4 +1,4 @@
-use std::collections::HashMap;
+use indexmap::IndexMap;
 
 use crate::{lexer::Token, opcode::Opcode, types::Type};
 
@@ -44,8 +44,8 @@ impl Default for Statement {
     }
 }
 
-pub type UnparsedConstants = HashMap<String, (Token, Token)>;
-pub type UnparsedWitnesses = HashMap<String, (Token, Token)>;
+pub type UnparsedConstants = IndexMap<String, (Token, Token)>;
+pub type UnparsedWitnesses = IndexMap<String, (Token, Token)>;
 
 pub type Constants = Vec<Constant>;
 pub type Witnesses = Vec<Witness>;

+ 6 - 5
zkas/src/parser.rs

@@ -1,5 +1,6 @@
-use std::{collections::HashMap, io, io::Write, iter::Peekable, process, str::Chars};
+use std::{io, io::Write, iter::Peekable, process, str::Chars};
 
+use indexmap::IndexMap;
 use itertools::Itertools;
 use termion::{color, style};
 
@@ -41,9 +42,9 @@ impl Parser {
         // All the circuit statements
         let mut circuit_statements = vec![];
 
-        let mut ast = HashMap::new();
+        let mut ast = IndexMap::new();
         let mut namespace = String::new();
-        let mut ast_inner = HashMap::new();
+        let mut ast_inner = IndexMap::new();
         let mut namespace_found = false; // Nasty
 
         let mut iter = self.tokens.iter();
@@ -127,7 +128,7 @@ impl Parser {
                 }
 
                 let constants_cloned = constant_tokens.clone();
-                let mut constants_map = HashMap::new();
+                let mut constants_map = IndexMap::new();
                 // This is everything between the braces: { .. }
                 let mut constants_inner = constants_cloned[2..constant_tokens.len() - 1].iter();
 
@@ -177,7 +178,7 @@ impl Parser {
                 }
 
                 let contract_cloned = contract_tokens.clone();
-                let mut contract_map = HashMap::new();
+                let mut contract_map = IndexMap::new();
                 // This is everything between the braces: { .. }
                 let mut contract_inner = contract_cloned[2..contract_tokens.len() - 1].iter();