Explorar o código

cleaning the code

ada %!s(int64=5) %!d(string=hai) anos
pai
achega
06856e1941
Modificáronse 3 ficheiros con 6 adicións e 119 borrados
  1. 1 21
      lisp/core.rs
  2. 5 91
      lisp/lisp.rs
  3. 0 7
      lisp/types.rs

+ 1 - 21
lisp/core.rs

@@ -8,7 +8,7 @@ use crate::printer::pr_seq;
 use crate::reader::read_str;
 use crate::types::MalErr::ErrMalVal;
 use crate::types::MalVal::{
-    Add, AddOne, Atom, Bool, Func, Hash, Int, Lc0, List, MalFunc, Nil, Private, Public, Str, Sub,
+    Atom, Bool, Func, Hash, Int, List, MalFunc, Nil, Private, Public, Str,
     Sym, Vector, Params
 };
 use crate::types::{MalArgs, MalRet, MalVal, _assoc, _dissoc, atom, error, func, hash_map};
@@ -252,11 +252,6 @@ fn conj(a: MalArgs) -> MalRet {
     }
 }
 
-fn sub(a: MalArgs) -> MalRet {
-    // get next symbol should be lc0 lc1 lc2
-    Ok(Sub(Rc::new(a[0].clone()), Rc::new(a[1].clone())))
-}
-
 fn sub_scalar(a: MalArgs) -> MalRet {
     match (a[0].clone(), a[1].clone()) {
         (Str(a0), Str(a1)) => {
@@ -330,15 +325,6 @@ fn add_scalar(a: MalArgs) -> MalRet {
     }
 }
 
-fn add_one(a: MalArgs) -> MalRet {
-    Ok(AddOne(Rc::new(a[0].clone())))
-}
-
-fn add(a: MalArgs) -> MalRet {
-    // get next symbol should be lc0 lc1 lc2
-    Ok(Add(Rc::new(a[0].clone()), Rc::new(a[1].clone())))
-}
-
 fn seq(a: MalArgs) -> MalRet {
     match a[0] {
         List(ref v, _) | Vector(ref v, _) if v.len() == 0 => Ok(Nil),
@@ -448,12 +434,6 @@ pub fn ns() -> Vec<(&'static str, MalVal)> {
         ("reset!", func(|a| a[0].reset_bang(&a[1]))),
         ("swap!", func(|a| a[0].swap_bang(&a[1..].to_vec()))),
         ("unpack-bits", func(unpack_bits)),
-        ("add", func(add)),
-        ("add-one", func(add_one)),
-        ("sub", func(sub)),
-        ("lc0", func(|a| Ok(MalVal::Lc0))),
-        ("lc1", func(|a| Ok(MalVal::Lc1))),
-        ("lc2", func(|a| Ok(MalVal::Lc2))),
         ("enforce", func(|a| Ok(MalVal::Enforce))),
         ("public", func(cs_public)),
         ("private", func(cs_private)),

+ 5 - 91
lisp/lisp.rs

@@ -26,8 +26,8 @@ extern crate regex;
 mod types;
 use crate::types::MalErr::{ErrMalVal, ErrString};
 use crate::types::MalVal::{
-    Add, AddOne, Bool, Func, Hash, Lc0, Lc1, Lc2, List, MalFunc, Nil, Params, Private, Public, Str,
-    Sub, Sym, Vector, Zk,
+    Bool, Func, Hash, List, MalFunc, Nil, Params, Private, Public, Str,
+    Sym, Vector, Zk,
 };
 use crate::types::ZKCircuit;
 use crate::types::{error, format_error, MalArgs, MalErr, MalRet, MalVal};
@@ -278,8 +278,9 @@ fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
                         let value = eval_ast(&a2, &env)?;
                         match value {
                             List(ref el, _) => {
-                                let val = zkcons_eval(el.to_vec(), &a1, &env)?;
-                                val.clone();
+                                //let val = zkcons_eval(el.to_vec(), &a1, &env)?;
+                                //val.clone();
+                                println!("{:?}", el.to_vec());
                             }
                             _ => println!("invalid format"),
                         }
@@ -363,93 +364,6 @@ fn zk_circuit_create(a1: &MalVal, env: &Env) -> ZKCircuit {
     zk_circuit
 }
 
-fn zkcons_eval(elements: Vec<MalVal>, a1: &MalVal, env: &Env) -> MalRet {
-    let zkc = match eval(a1.clone(), env.clone()) {
-        Ok(mut zkv) => {
-            match zkv {
-                Zk(mut zk) => {
-                    for b in elements.iter() {
-                        match b {
-                            Add(b1, b2) => {
-                                zk.private
-                                    .push(Scalar::from_string(&b2.pr_str(false).to_string()));
-                                let const_a: ConstraintInstruction = match b1.apply(vec![])? {
-                                    Lc0 => ConstraintInstruction::Lc0Add(zk.private.len()),
-                                    Lc1 => ConstraintInstruction::Lc1Add(zk.private.len()),
-                                    Lc2 => ConstraintInstruction::Lc2Add(zk.private.len()),
-                                    _ => {
-                                        println!("{:?}", b1.apply(vec![]));
-                                        ConstraintInstruction::Lc0Add(0)
-                                    }
-                                };
-                                zk.constraints.push(const_a);
-                                //env_set(&env, a1.clone(), types::MalVal::Zk(zk.clone()));
-                            }
-                            Sub(b1, b2) => {
-                                zk.private
-                                    .push(Scalar::from_string(&b2.pr_str(false).to_string()));
-                                let const_a: ConstraintInstruction = match b1.apply(vec![])? {
-                                    Lc0 => ConstraintInstruction::Lc0Sub(zk.private.len()),
-                                    Lc1 => ConstraintInstruction::Lc1Sub(zk.private.len()),
-                                    Lc2 => ConstraintInstruction::Lc2Sub(zk.private.len()),
-                                    _ => {
-                                        println!("{:?}", b1.apply(vec![]));
-                                        ConstraintInstruction::Lc0Sub(0)
-                                    }
-                                };
-                                zk.constraints.push(const_a);
-                                //env_set(&env, a1.clone(), types::MalVal::Zk(zk.clone()));
-                            }
-                            AddOne(b1) => {
-                                let const_a: ConstraintInstruction = match b1.apply(vec![])? {
-                                    Lc0 => ConstraintInstruction::Lc0AddOne,
-                                    Lc1 => ConstraintInstruction::Lc1AddOne,
-                                    Lc2 => ConstraintInstruction::Lc2AddOne,
-                                    _ => {
-                                        println!("{:?}", b1.apply(vec![]));
-                                        ConstraintInstruction::Lc0AddOne
-                                    }
-                                };
-                                zk.constraints.push(const_a);
-                            }
-                            Private(a) => {
-                                zk.private
-                                    .push(Scalar::from_string(&a.pr_str(false).to_string()));
-                            }
-                            Public(a) => {
-                                zk.public
-                                    .push(Scalar::from_string(&a.pr_str(false).to_string()));
-                            }
-                            Params(a) => {
-                                // todo add multiple matchs
-                                match a.as_ref() {
-                                    Vector(v, _) => {
-                                        for i in v.iter() {
-                                            zk.params.push(Scalar::from_string(
-                                                &i.pr_str(false).to_string(),
-                                            ));
-                                        }
-                                    }
-                                    _ => println!("params called with a non-seq"),
-                                };
-                            }
-                            Enforce => {
-                                zk.constraints.push(ConstraintInstruction::Enforce);
-                            }
-                            _ => println!("not mapped"),
-                        }
-                    }
-                    env_set(&env, a1.clone(), types::MalVal::Zk(zk.clone()));
-                }
-                _ => println!("not parsed"),
-            }
-        }
-        _ => println!("not a circuit"),
-    };
-
-    env_get(&env, &a1.clone())
-}
-
 // print
 fn print(ast: &MalVal) -> String {
     ast.pr_str(true)

+ 0 - 7
lisp/types.rs

@@ -29,7 +29,6 @@ pub enum MalVal {
     Nil,
     Bool(bool),
     Int(i64),
-    //Float(f64),
     Str(String),
     Sym(String),
     List(Rc<Vec<MalVal>>, Rc<MalVal>),
@@ -46,13 +45,7 @@ pub enum MalVal {
     },
     Atom(Rc<RefCell<MalVal>>),
     Zk(ZKCircuit),
-    Lc0,
-    Lc1,
-    Lc2,
     Enforce,
-    Add(Rc<MalVal>, Rc<MalVal>),
-    AddOne(Rc<MalVal>),
-    Sub(Rc<MalVal>, Rc<MalVal>),
     Public(Rc<MalVal>),
     Private(Rc<MalVal>),
     Params(Rc<MalVal>),