lisp.rs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. #![allow(non_snake_case)]
  2. use crate::types::LispCircuit;
  3. use bellman::groth16::PreparedVerifyingKey;
  4. use sapvi::{BlsStringConversion, Decodable, Encodable, ZKContract, ZKProof};
  5. use simplelog::*;
  6. use bellman::groth16;
  7. use bls12_381::Bls12;
  8. use fnv::FnvHashMap;
  9. use itertools::Itertools;
  10. use rand::rngs::OsRng;
  11. use std::fs;
  12. use std::fs::File;
  13. use std::rc::Rc;
  14. use std::time::Instant;
  15. use types::EnforceAllocation;
  16. #[macro_use]
  17. extern crate clap;
  18. #[macro_use]
  19. extern crate lazy_static;
  20. extern crate fnv;
  21. extern crate itertools;
  22. extern crate regex;
  23. #[macro_use]
  24. mod types;
  25. use crate::types::MalErr::{ErrMalVal, ErrString};
  26. use crate::types::MalVal::{Bool, Enforce, Func, Hash, List, MalFunc, Nil, Str, Sym, Vector};
  27. use crate::types::VerifyKeyParams;
  28. use crate::types::{error, format_error, MalArgs, MalErr, MalRet, MalVal};
  29. mod env;
  30. mod printer;
  31. mod reader;
  32. use crate::env::{env_bind, env_find, env_get, env_new, env_set, env_sets, Env};
  33. #[macro_use]
  34. mod core;
  35. pub const ZK_CIRCUIT_ENV_KEY: &str = "ZKC";
  36. // read
  37. fn read(str: &str) -> MalRet {
  38. reader::read_str(str.to_string())
  39. }
  40. // eval
  41. fn qq_iter(elts: &MalArgs) -> MalVal {
  42. let mut acc = list![];
  43. for elt in elts.iter().rev() {
  44. if let List(v, _) = elt {
  45. if v.len() == 2 {
  46. if let Sym(ref s) = v[0] {
  47. if s == "splice-unquote" {
  48. acc = list![Sym("concat".to_string()), v[1].clone(), acc];
  49. continue;
  50. }
  51. }
  52. }
  53. }
  54. acc = list![Sym("cons".to_string()), quasiquote(&elt), acc];
  55. }
  56. return acc;
  57. }
  58. fn quasiquote(ast: &MalVal) -> MalVal {
  59. match ast {
  60. List(v, _) => {
  61. if v.len() == 2 {
  62. if let Sym(ref s) = v[0] {
  63. if s == "unquote" {
  64. return v[1].clone();
  65. }
  66. }
  67. }
  68. return qq_iter(&v);
  69. }
  70. Vector(v, _) => return list![Sym("vec".to_string()), qq_iter(&v)],
  71. Hash(_, _) | Sym(_) => return list![Sym("quote".to_string()), ast.clone()],
  72. _ => ast.clone(),
  73. }
  74. }
  75. fn is_macro_call(ast: &MalVal, env: &Env) -> Option<(MalVal, MalArgs)> {
  76. match ast {
  77. List(v, _) => match v[0] {
  78. Sym(ref s) => match env_find(env, s) {
  79. Some(e) => match env_get(&e, &v[0]) {
  80. Ok(f @ MalFunc { is_macro: true, .. }) => Some((f, v[1..].to_vec())),
  81. _ => None,
  82. },
  83. _ => None,
  84. },
  85. _ => None,
  86. },
  87. _ => None,
  88. }
  89. }
  90. fn macroexpand(mut ast: MalVal, env: &Env) -> (bool, MalRet) {
  91. let mut was_expanded = false;
  92. while let Some((mf, args)) = is_macro_call(&ast, env) {
  93. //println!("macroexpand 1: {:?}", ast);
  94. ast = match mf.apply(args) {
  95. Err(e) => return (false, Err(e)),
  96. Ok(a) => a,
  97. };
  98. //println!("macroexpand 2: {:?}", ast);
  99. was_expanded = true;
  100. }
  101. (was_expanded, Ok(ast))
  102. }
  103. fn eval_ast(ast: &MalVal, env: &Env) -> MalRet {
  104. match ast {
  105. Sym(_) => Ok(env_get(&env, &ast)?),
  106. List(v, _) => {
  107. let mut lst: MalArgs = vec![];
  108. for a in v.iter() {
  109. lst.push(eval(a.clone(), env.clone())?)
  110. }
  111. Ok(list!(lst))
  112. }
  113. Vector(v, _) => {
  114. let mut lst: MalArgs = vec![];
  115. for a in v.iter() {
  116. lst.push(eval(a.clone(), env.clone())?)
  117. }
  118. Ok(vector!(lst))
  119. }
  120. Hash(hm, _) => {
  121. let mut new_hm: FnvHashMap<String, MalVal> = FnvHashMap::default();
  122. for (k, v) in hm.iter() {
  123. new_hm.insert(k.to_string(), eval(v.clone(), env.clone())?);
  124. }
  125. Ok(Hash(Rc::new(new_hm), Rc::new(Nil)))
  126. }
  127. _ => Ok(ast.clone()),
  128. }
  129. }
  130. fn eval(mut ast: MalVal, mut env: Env) -> MalRet {
  131. let ret: MalRet;
  132. 'tco: loop {
  133. ret = match ast.clone() {
  134. List(l, _) => {
  135. if l.len() == 0 {
  136. return Ok(ast);
  137. }
  138. match macroexpand(ast.clone(), &env) {
  139. (true, Ok(new_ast)) => {
  140. ast = new_ast;
  141. continue 'tco;
  142. }
  143. (_, Err(e)) => return Err(e),
  144. _ => (),
  145. }
  146. if l.len() == 0 {
  147. return Ok(ast);
  148. }
  149. let a0 = &l[0];
  150. match a0 {
  151. Sym(ref a0sym) if a0sym == "def!" => {
  152. env_set(&env, l[1].clone(), eval(l[2].clone(), env.clone())?)
  153. }
  154. Sym(ref a0sym) if a0sym == "let*" => {
  155. // TODO let should be restored to the first purpose
  156. // and the new let* without an env creation should be availaable
  157. // env = env_new(Some(env.clone()));
  158. let (a1, a2) = (l[1].clone(), l[2].clone());
  159. match a1 {
  160. List(ref binds, _) | Vector(ref binds, _) => {
  161. for (b, e) in binds.iter().tuples() {
  162. match b {
  163. Sym(_) => {
  164. let _ = env_set(
  165. &env,
  166. b.clone(),
  167. eval(e.clone(), env.clone())?,
  168. );
  169. }
  170. _ => {
  171. return error("let* with non-Sym binding");
  172. }
  173. }
  174. }
  175. }
  176. _ => {
  177. return error("let* with non-List bindings");
  178. }
  179. };
  180. ast = a2;
  181. continue 'tco;
  182. }
  183. Sym(ref a0sym) if a0sym == "quote" => Ok(l[1].clone()),
  184. Sym(ref a0sym) if a0sym == "quasiquoteexpand" => Ok(quasiquote(&l[1])),
  185. Sym(ref a0sym) if a0sym == "quasiquote" => {
  186. ast = quasiquote(&l[1]);
  187. continue 'tco;
  188. }
  189. Sym(ref a0sym) if a0sym == "defmacro!" => {
  190. let (a1, a2) = (l[1].clone(), l[2].clone());
  191. let r = eval(a2, env.clone())?;
  192. match r {
  193. MalFunc {
  194. eval,
  195. ast,
  196. env,
  197. params,
  198. ..
  199. } => Ok(env_set(
  200. &env,
  201. a1.clone(),
  202. MalFunc {
  203. eval: eval,
  204. ast: ast.clone(),
  205. env: env.clone(),
  206. params: params.clone(),
  207. is_macro: true,
  208. meta: Rc::new(Nil),
  209. },
  210. )?),
  211. _ => error("set_macro on non-function"),
  212. }
  213. }
  214. Sym(ref a0sym) if a0sym == "macroexpand" => {
  215. match macroexpand(l[1].clone(), &env) {
  216. (_, Ok(new_ast)) => Ok(new_ast),
  217. (_, e) => return e,
  218. }
  219. }
  220. Sym(ref a0sym) if a0sym == "try*" => match eval(l[1].clone(), env.clone()) {
  221. Err(ref e) if l.len() >= 3 => {
  222. let exc = match e {
  223. ErrMalVal(mv) => mv.clone(),
  224. ErrString(s) => Str(s.to_string()),
  225. };
  226. match l[2].clone() {
  227. List(c, _) => {
  228. let catch_env = env_bind(
  229. Some(env.clone()),
  230. list!(vec![c[1].clone()]),
  231. vec![exc],
  232. )?;
  233. eval(c[2].clone(), catch_env)
  234. }
  235. _ => error("invalid catch block"),
  236. }
  237. }
  238. res => res,
  239. },
  240. Sym(ref a0sym) if a0sym == "do" => {
  241. match eval_ast(&list!(l[1..l.len() - 1].to_vec()), &env)? {
  242. List(_, _) => {
  243. ast = l.last().unwrap_or(&Nil).clone();
  244. continue 'tco;
  245. }
  246. _ => error("invalid do form"),
  247. }
  248. }
  249. Sym(ref a0sym) if a0sym == "if" => {
  250. let cond = eval(l[1].clone(), env.clone())?;
  251. match cond {
  252. Bool(false) | Nil if l.len() >= 4 => {
  253. ast = l[3].clone();
  254. continue 'tco;
  255. }
  256. Bool(false) | Nil => Ok(Nil),
  257. _ if l.len() >= 3 => {
  258. ast = l[2].clone();
  259. continue 'tco;
  260. }
  261. _ => Ok(Nil),
  262. }
  263. }
  264. Sym(ref a0sym) if a0sym == "fn*" => {
  265. let (a1, a2) = (l[1].clone(), l[2].clone());
  266. Ok(MalFunc {
  267. eval: eval,
  268. ast: Rc::new(a2),
  269. env: env,
  270. params: Rc::new(a1),
  271. is_macro: false,
  272. meta: Rc::new(Nil),
  273. })
  274. }
  275. Sym(ref a0sym) if a0sym == "eval" => {
  276. ast = eval(l[1].clone(), env.clone())?;
  277. while let Some(ref e) = env.clone().outer {
  278. env = e.clone();
  279. }
  280. continue 'tco;
  281. }
  282. Sym(ref a0sym) if a0sym == "setup" => {
  283. let a1 = l[1].clone();
  284. // todo
  285. ast = eval(a1.clone(), env.clone())?;
  286. // let _pvk = setup(a1.clone(), env.clone())?;
  287. continue 'tco;
  288. }
  289. Sym(ref a0sym) if a0sym == "prove" => {
  290. let a1 = l[1].clone();
  291. ast = eval(a1.clone(), env.clone())?;
  292. prove(a1.clone(), env.clone())
  293. }
  294. Sym(ref a0sym) if a0sym == "alloc-const" => {
  295. let a1 = l[1].clone();
  296. let value = eval(l[2].clone(), env.clone())?;
  297. let result = eval(value.clone(), env.clone())?;
  298. let allocs = get_allocations(&env, "AllocationsConst");
  299. let mut new_hm: FnvHashMap<String, MalVal> = FnvHashMap::default();
  300. for (k, v) in allocs.iter() {
  301. new_hm.insert(k.to_string(), eval(v.clone(), env.clone())?);
  302. }
  303. new_hm.insert(a1.pr_str(false), result.clone());
  304. env_set(
  305. &env,
  306. Sym("AllocationsConst".to_string()),
  307. Hash(Rc::new(new_hm), Rc::new(Nil)),
  308. )?;
  309. Ok(result.clone())
  310. }
  311. Sym(ref a0sym) if a0sym == "alloc-input" => {
  312. let a1 = l[1].clone();
  313. let value = eval(l[2].clone(), env.clone())?;
  314. let result = eval(value.clone(), env.clone())?;
  315. let allocs = get_allocations(&env, "AllocationsInput");
  316. let mut new_hm: FnvHashMap<String, MalVal> = FnvHashMap::default();
  317. for (k, v) in allocs.iter() {
  318. new_hm.insert(k.to_string(), eval(v.clone(), env.clone())?);
  319. }
  320. new_hm.insert(a1.pr_str(false), result.clone());
  321. env_set(
  322. &env,
  323. Sym("AllocationsInput".to_string()),
  324. Hash(Rc::new(new_hm), Rc::new(Nil)),
  325. )?;
  326. Ok(result.clone())
  327. }
  328. Sym(ref a0sym) if a0sym == "alloc" => {
  329. let a1 = l[1].clone();
  330. let value = eval(l[2].clone(), env.clone())?;
  331. let result = eval(value.clone(), env.clone())?;
  332. let allocs = get_allocations(&env, "Allocations");
  333. let mut new_hm: FnvHashMap<String, MalVal> = FnvHashMap::default();
  334. for (k, v) in allocs.iter() {
  335. new_hm.insert(k.to_string(), eval(v.clone(), env.clone())?);
  336. }
  337. new_hm.insert(a1.pr_str(false), result.clone());
  338. env_set(
  339. &env,
  340. Sym("Allocations".to_string()),
  341. Hash(Rc::new(new_hm), Rc::new(Nil)),
  342. )?;
  343. Ok(result.clone())
  344. }
  345. //Sym(ref a0sym) if a0sym == "verify" => {
  346. Sym(ref a0sym) if a0sym == "enforce" => {
  347. // here i'm considering that we always have tuple with only two elements
  348. // also it's important to keep in mind for the sake of brevity of this v0
  349. // we will not allow calculation or any lisp evaluations inside the enforce
  350. // it means that every symbol will be on allocations and we will do the
  351. // find/replace on the bellman circuit, it's nasty v0
  352. let mut left_vec = vec![];
  353. let mut right_vec = vec![];
  354. let mut out_vec = vec![];
  355. // todo extract a macro for this
  356. match l[1].clone() {
  357. List(v, _) | Vector(v, _) => {
  358. if let List(_, _) = &v.to_vec()[0] {
  359. for ele in v.to_vec().iter() {
  360. if let List(ele_vec, _) = ele {
  361. left_vec.push((
  362. ele_vec[0].pr_str(false),
  363. ele_vec[1].pr_str(false),
  364. ));
  365. }
  366. }
  367. } else {
  368. left_vec.push((v[0].pr_str(false), v[1].pr_str(false)));
  369. }
  370. }
  371. _ => {}
  372. };
  373. match l[2].clone() {
  374. List(v, _) | Vector(v, _) => {
  375. if let List(_, _) = &v.to_vec()[0] {
  376. for ele in v.to_vec().iter() {
  377. if let List(ele_vec, _) = ele {
  378. right_vec.push((
  379. ele_vec[0].pr_str(false),
  380. ele_vec[1].pr_str(false),
  381. ));
  382. }
  383. }
  384. } else {
  385. right_vec.push((v[0].pr_str(false), v[1].pr_str(false)));
  386. }
  387. }
  388. _ => {}
  389. };
  390. match l[3].clone() {
  391. List(v, _) | Vector(v, _) => {
  392. if let List(_, _) = &v.to_vec()[0] {
  393. for ele in v.to_vec().iter() {
  394. if let List(ele_vec, _) = ele {
  395. out_vec.push((
  396. ele_vec[0].pr_str(false),
  397. ele_vec[1].pr_str(false),
  398. ));
  399. }
  400. }
  401. } else {
  402. out_vec.push((v[0].pr_str(false), v[1].pr_str(false)));
  403. }
  404. }
  405. _ => {}
  406. };
  407. let enforce_vec = get_enforce_allocs(&env);
  408. let enforce = EnforceAllocation {
  409. idx: enforce_vec.len() + 1,
  410. left: left_vec,
  411. right: right_vec,
  412. output: out_vec,
  413. };
  414. let mut new_vec: Vec<EnforceAllocation> = vec![enforce];
  415. for value in enforce_vec.iter() {
  416. new_vec.push(value.clone());
  417. }
  418. env_set(
  419. &env,
  420. Sym("AllocationsEnforce".to_string()),
  421. vector![vec![Enforce(Rc::new(new_vec))]],
  422. );
  423. /*
  424. println!("\n\nallocations {:?}", get_allocations(&env, "Allocations"));
  425. println!(
  426. "\n\nallocations input {:?}",
  427. get_allocations(&env, "AllocationsInput")
  428. );
  429. println!("\n\nallocations enforce {:?}", get_enforce_allocs(&env));
  430. */
  431. Ok(vector![vec![]])
  432. }
  433. _ => match eval_ast(&ast, &env)? {
  434. List(ref el, _) => {
  435. let ref f = el[0].clone();
  436. let args = el[1..].to_vec();
  437. match f {
  438. Func(_, _) => f.apply(args),
  439. MalFunc {
  440. ast: mast,
  441. env: menv,
  442. params,
  443. ..
  444. } => {
  445. let a = &**mast;
  446. let p = &**params;
  447. env = env_bind(Some(menv.clone()), p.clone(), args)?;
  448. ast = a.clone();
  449. continue 'tco;
  450. }
  451. _ => {
  452. Ok(vector![el.to_vec()])
  453. //error("call non-function")
  454. }
  455. }
  456. }
  457. _ => error("expected a list"),
  458. },
  459. }
  460. }
  461. _ => eval_ast(&ast, &env),
  462. };
  463. break;
  464. } // end 'tco loop
  465. ret
  466. }
  467. pub fn get_enforce_allocs(env: &Env) -> Vec<EnforceAllocation> {
  468. // todo need some cleanup
  469. match env_find(env, "AllocationsEnforce") {
  470. Some(e) => match env_get(&e, &Sym("AllocationsEnforce".to_string())) {
  471. Ok(f) => {
  472. if let Vector(val, _) = f {
  473. if let Enforce(ret) = &val[0] {
  474. ret.to_vec()
  475. } else {
  476. vec![]
  477. }
  478. } else {
  479. vec![]
  480. }
  481. }
  482. _ => vec![],
  483. },
  484. _ => vec![],
  485. }
  486. }
  487. pub fn get_allocations(env: &Env, key: &str) -> Rc<FnvHashMap<String, MalVal>> {
  488. let alloc_hm: Rc<FnvHashMap<String, MalVal>> = Rc::new(FnvHashMap::default());
  489. match env_find(env, key) {
  490. Some(e) => match env_get(&e, &Sym(key.to_string())) {
  491. Ok(f) => {
  492. if let Hash(allocs, _) = f {
  493. allocs
  494. } else {
  495. alloc_hm
  496. }
  497. }
  498. _ => alloc_hm,
  499. },
  500. _ => alloc_hm,
  501. }
  502. }
  503. pub fn setup(_ast: MalVal, env: Env) -> Result<VerifyKeyParams, MalErr> {
  504. let start = Instant::now();
  505. let c = LispCircuit {
  506. params: FnvHashMap::default(),
  507. allocs: FnvHashMap::default(),
  508. alloc_inputs: FnvHashMap::default(),
  509. constraints: Vec::new(),
  510. };
  511. let random_parameters =
  512. groth16::generate_random_parameters::<Bls12, _, _>(c, &mut OsRng).unwrap();
  513. let pvk = groth16::prepare_verifying_key(&random_parameters.vk);
  514. println!("Setup: [{:?}]", start.elapsed());
  515. Ok(VerifyKeyParams {
  516. verifying_key: pvk,
  517. random_params: random_parameters,
  518. })
  519. }
  520. pub fn prove(_ast: MalVal, env: Env) -> MalRet {
  521. let start = Instant::now();
  522. let allocs_input = get_allocations(&env, "AllocationsInput");
  523. let allocs = get_allocations(&env, "Allocations");
  524. let enforce_allocs = get_enforce_allocs(&env);
  525. let allocs_const = get_allocations(&env, "AllocationsConst");
  526. //setup
  527. let params = Some({
  528. let circuit = LispCircuit {
  529. params: allocs_const.as_ref().clone(),
  530. allocs: allocs.as_ref().clone(),
  531. alloc_inputs: allocs_input.as_ref().clone(),
  532. constraints: enforce_allocs.clone(),
  533. };
  534. groth16::generate_random_parameters::<Bls12, _, _>(circuit, &mut OsRng)?
  535. });
  536. let verifying_key = Some(groth16::prepare_verifying_key(&params.as_ref().unwrap().vk));
  537. // prove
  538. let circuit = LispCircuit {
  539. params: allocs_const.as_ref().clone(),
  540. allocs: allocs.as_ref().clone(),
  541. alloc_inputs: allocs_input.as_ref().clone(),
  542. constraints: enforce_allocs.clone(),
  543. };
  544. let proof = groth16::create_random_proof(circuit, params.as_ref().unwrap(), &mut OsRng)?;
  545. let mut vec_input = vec![];
  546. for (k, val) in allocs_input.iter() {
  547. println!("{:?}", val);
  548. match val {
  549. MalVal::Str(v) => {
  550. vec_input.push(bls12_381::Scalar::from_string(&v.to_string()));
  551. }
  552. MalVal::ZKScalar(v) => {
  553. vec_input.push(bls12_381::Scalar::from(*v));
  554. }
  555. _ => {}
  556. };
  557. }
  558. let result = groth16::verify_proof(verifying_key.as_ref().unwrap(), &proof, &vec_input);
  559. println!("{:?}", result);
  560. println!("vec public {:?}", vec_input);
  561. Ok(MalVal::Nil)
  562. }
  563. pub fn verify(_ast: &MalVal) -> MalRet {
  564. let _public_input = vec![bls12_381::Scalar::from(27)];
  565. let start = Instant::now();
  566. println!("Verify: [{:?}]", start.elapsed());
  567. Ok(MalVal::Nil)
  568. }
  569. // print
  570. fn print(ast: &MalVal) -> String {
  571. ast.pr_str(true)
  572. }
  573. fn rep(str: &str, env: &Env) -> Result<String, MalErr> {
  574. let ast = read(str)?;
  575. let exp = eval(ast, env.clone())?;
  576. Ok(print(&exp))
  577. }
  578. fn main() -> Result<(), ()> {
  579. let matches = clap_app!(zklisp =>
  580. (version: "0.1.0")
  581. (author: "mileschet <miles.chet@gmail.com>")
  582. (about: "A Lisp Interpreter for Zero Knowledge Virtual Machine")
  583. (@subcommand load =>
  584. (about: "Load the file into the interpreter")
  585. (@arg FILE: +required "Lisp Contract filename")
  586. )
  587. )
  588. .get_matches();
  589. CombinedLogger::init(vec![TermLogger::new(
  590. LevelFilter::Debug,
  591. Config::default(),
  592. TerminalMode::Mixed,
  593. )
  594. .unwrap()])
  595. .unwrap();
  596. match matches.subcommand() {
  597. Some(("load", matches)) => {
  598. let file: String = matches.value_of("FILE").unwrap().parse().unwrap();
  599. repl_load(file)?;
  600. }
  601. _ => {
  602. eprintln!("error: Invalid subcommand invoked");
  603. std::process::exit(-1);
  604. }
  605. }
  606. Ok(())
  607. }
  608. fn repl_load(file: String) -> Result<(), ()> {
  609. let repl_env = env_new(None);
  610. for (k, v) in core::ns() {
  611. env_sets(&repl_env, k, v);
  612. }
  613. let _ = rep("(def! not (fn* (a) (if a false true)))", &repl_env);
  614. let _ = rep(
  615. "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \"\nnil)\")))))",
  616. &repl_env,
  617. );
  618. //let _ = rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))", &repl_env);
  619. match rep(&format!("(load-file \"{}\")", file), &repl_env) {
  620. Ok(_) => std::process::exit(0),
  621. Err(e) => {
  622. println!("Error: {}", format_error(e));
  623. std::process::exit(1);
  624. }
  625. }
  626. }