lisp.rs 25 KB

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