make allocations as hashmap lisp type

This commit is contained in:
ada
2021-01-05 23:51:40 +01:00
parent 9140d5ef04
commit 978e5e472f
2 changed files with 10 additions and 10 deletions

View File

@@ -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<String, MalVal> = 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<PreparedVerifyingKey<Bls12>, MalErr> {
let start = Instant::now();
// Create parameters for our circuit. In a production deployment these would

View File

@@ -69,7 +69,6 @@ pub enum MalVal {
},
Atom(Rc<RefCell<MalVal>>),
Zk(Rc<LispCircuit>), // TODO remote it
Allocations(Vec<Allocation>),
Enforce(Rc<Vec<MalVal>>),
ZKScalar(bls12_381::Scalar)
}