From 978e5e472ff34d15c90b76dbab6ac55b007483f9 Mon Sep 17 00:00:00 2001 From: ada Date: Tue, 5 Jan 2021 23:51:40 +0100 Subject: [PATCH] make allocations as hashmap lisp type --- lisp/lisp.rs | 19 ++++++++++--------- lisp/types.rs | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lisp/lisp.rs b/lisp/lisp.rs index 4d08dd174..a6caf3f0f 100644 --- a/lisp/lisp.rs +++ b/lisp/lisp.rs @@ -34,7 +34,7 @@ extern crate regex; #[macro_use] mod types; use crate::types::MalErr::{ErrMalVal, ErrString}; -use crate::types::MalVal::{Bool, Func, Hash, List, MalFunc, Nil, Str, Sym, Vector, Allocations}; +use crate::types::MalVal::{Bool, Func, Hash, List, MalFunc, Nil, Str, Sym, Vector}; use crate::types::{error, format_error, MalArgs, MalErr, MalRet, MalVal, Allocation}; mod env; mod printer; @@ -315,14 +315,7 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet { let value = eval(l[2].clone(), env.clone())?; let result = eval(value.clone(), env.clone())?; let symbol = MalVal::Sym(a1.pr_str(false)); - let alloc_symbol = Sym("Allocations".to_string()); - if let MalVal::Allocations(mut valalloc) = env_get(&env.clone(), &alloc_symbol)? { - if let MalVal::ZKScalar(val) = result { - valalloc.push(Allocation { symbol : symbol.pr_str(false), value: val }); - env_set(&env, alloc_symbol, MalVal::Allocations(valalloc)); - }; - }; - + let allocs = get_allocations(&env); Ok(Nil) } //Sym(ref a0sym) if a0sym == "verify" => { @@ -374,6 +367,14 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet { ret } +pub fn get_allocations(env: &Env) -> MalRet { + let alloc_symbol = Sym("Allocations".to_string()); + let mut alloc_hm: FnvHashMap = FnvHashMap::default(); + //alloc_hm.insert(k.to_string(), eval(v.clone(), env.clone())?); + //// TODO check if there is the alloc on the env already + env_set(&env, alloc_symbol, Hash(Rc::new(alloc_hm), Rc::new(Nil))) +} + pub fn setup(ast: MalVal, mut env: Env) -> Result, MalErr> { let start = Instant::now(); // Create parameters for our circuit. In a production deployment these would diff --git a/lisp/types.rs b/lisp/types.rs index 30f116531..1415602f5 100644 --- a/lisp/types.rs +++ b/lisp/types.rs @@ -69,7 +69,6 @@ pub enum MalVal { }, Atom(Rc>), Zk(Rc), // TODO remote it - Allocations(Vec), Enforce(Rc>), ZKScalar(bls12_381::Scalar) }