diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 7f458d07..e831fcfc 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -175,9 +175,7 @@ pub fn compile_from_compileform( p0: CompileForm, symbol_table: &mut HashMap, ) -> Result { - let mut wrapper = CompileContextWrapper::new( - allocator, runner, symbol_table - ); + let mut wrapper = CompileContextWrapper::new(allocator, runner, symbol_table); let p1 = if opts.frontend_opt() { // Front end optimization fe_opt(&mut wrapper.context, opts.clone(), p0)? @@ -217,13 +215,7 @@ pub fn compile_pre_forms( // Resolve includes, convert program source to lexemes let p0 = frontend(opts.clone(), pre_forms)?; - compile_from_compileform( - allocator, - runner, - opts, - p0, - symbol_table - ) + compile_from_compileform(allocator, runner, opts, p0, symbol_table) } pub fn compile_file( diff --git a/src/compiler/frontend.rs b/src/compiler/frontend.rs index bcd91247..16ba840b 100644 --- a/src/compiler/frontend.rs +++ b/src/compiler/frontend.rs @@ -255,10 +255,7 @@ fn make_let_bindings( opts: Rc, body: Rc, ) -> Result>, CompileErr> { - let err = Err(CompileErr( - body.loc(), - format!("Bad binding tail {body:?}") - )); + let err = Err(CompileErr(body.loc(), format!("Bad binding tail {body:?}"))); let do_atomize = if opts.dialect().strict { |a: &SExp| -> SExp { a.atomize() } } else { diff --git a/src/compiler/preprocessor/macros.rs b/src/compiler/preprocessor/macros.rs index 859d8c79..e485181d 100644 --- a/src/compiler/preprocessor/macros.rs +++ b/src/compiler/preprocessor/macros.rs @@ -19,7 +19,7 @@ fn match_quoted_string(body: Rc) -> Result)>, Comp let is_string = match body.borrow() { SExp::QuotedString(_, b'x', _) => None, SExp::QuotedString(al, _, an) => Some((al.clone(), an.clone())), - _ => None + _ => None, }; if let Some((loc, s)) = is_string { @@ -60,7 +60,7 @@ fn match_number(body: Rc) -> Result, CompileErr> { SExp::Nil(il) => { return Ok(Some(MatchedNumber::MatchedInt(il.clone(), bi_zero()))); } - _ => { } + _ => {} } Err(CompileErr(body.loc(), "number required".to_string())) @@ -94,11 +94,7 @@ pub trait ExtensionFunction { } fn required_args(&self) -> Option; #[allow(clippy::too_many_arguments)] - fn try_eval( - &self, - loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr>; + fn try_eval(&self, loc: &Srcloc, args: &[Rc]) -> Result, CompileErr>; } struct StringQ {} @@ -114,11 +110,7 @@ impl ExtensionFunction for StringQ { Some(1) } - fn try_eval( - &self, - loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { let res = match match_quoted_string(args[0].clone()) { Ok(Some(_)) => SExp::Integer(loc.clone(), bi_one()), _ => SExp::Nil(loc.clone()), @@ -141,11 +133,7 @@ impl ExtensionFunction for NumberQ { Some(1) } - fn try_eval( - &self, - loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { let res = match match_number(args[0].clone()) { Ok(Some(_)) => SExp::Integer(loc.clone(), bi_one()), _ => SExp::Nil(loc.clone()), @@ -168,11 +156,7 @@ impl ExtensionFunction for SymbolQ { Some(1) } - fn try_eval( - &self, - loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { let res = match match_atom(args[0].clone()) { Ok(Some(_)) => SExp::Integer(loc.clone(), bi_one()), _ => SExp::Nil(loc.clone()), @@ -195,15 +179,9 @@ impl ExtensionFunction for SymbolToString { Some(1) } - fn try_eval( - &self, - _loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, _loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { if let Some((loc, value)) = match_atom(args[0].clone())? { - Ok(Rc::new(SExp::QuotedString( - loc, b'\"', value, - ))) + Ok(Rc::new(SExp::QuotedString(loc, b'\"', value))) } else { Err(CompileErr(args[0].loc(), "Not a symbol".to_string())) } @@ -223,11 +201,7 @@ impl ExtensionFunction for StringToSymbol { Some(1) } - fn try_eval( - &self, - _loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, _loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { if let Some((loc, value)) = match_quoted_string(args[0].clone())? { Ok(Rc::new(SExp::Atom(loc, value))) } else { @@ -249,11 +223,7 @@ impl ExtensionFunction for StringAppend { None } - fn try_eval( - &self, - loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { let mut out_vec = Vec::new(); let mut out_loc = None; for a in args.iter() { @@ -287,11 +257,7 @@ impl ExtensionFunction for NumberToString { Some(1) } - fn try_eval( - &self, - _loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, _loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { let match_res = match_number(args[0].clone())?; let (use_loc, int_val) = match &match_res { Some(MatchedNumber::MatchedInt(l, i)) => (l.clone(), i.clone()), @@ -321,11 +287,7 @@ impl ExtensionFunction for StringToNumber { Some(1) } - fn try_eval( - &self, - loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { if let Some((loc, value)) = match_quoted_string(args[0].clone())? { if let Ok(cvt_bi) = decode_string(&value).parse::() { Ok(Rc::new(SExp::Integer(loc, cvt_bi))) @@ -354,18 +316,17 @@ impl ExtensionFunction for StringLength { Some(1) } - fn try_eval( - &self, - _loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, _loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { if let Some((loc, value)) = match_quoted_string(args[0].clone())? { if let Some(len_bi) = value.len().to_bigint() { return Ok(Rc::new(SExp::Integer(loc, len_bi))); } } - Err(CompileErr(args[0].loc(), "Error getting string length".to_string())) + Err(CompileErr( + args[0].loc(), + "Error getting string length".to_string(), + )) } } @@ -382,11 +343,7 @@ impl ExtensionFunction for Substring { Some(3) } - fn try_eval( - &self, - _loc: &Srcloc, - args: &[Rc], - ) -> Result, CompileErr> { + fn try_eval(&self, _loc: &Srcloc, args: &[Rc]) -> Result, CompileErr> { let start_element = usize_value(args[1].clone())?; let end_element = usize_value(args[2].clone())?; @@ -404,11 +361,7 @@ impl ExtensionFunction for Substring { .skip(start_element) .copied() .collect(); - Ok(Rc::new(SExp::QuotedString( - l.clone(), - *ch, - result_value, - ))) + Ok(Rc::new(SExp::QuotedString(l.clone(), *ch, result_value))) } _ => Err(CompileErr(args[0].loc(), "Not a string".to_string())), } @@ -468,15 +421,15 @@ impl PrimOverride for PreprocessorExtension { ) -> Result>, RunFailure> { eprintln!("running {head} {tail}"); if let SExp::Atom(hl, head_atom) = head.borrow() { - let have_args: Vec> = - if let Some(args_list) = tail.proper_list() { - args_list.into_iter().map(Rc::new).collect() - } else { - return Ok(None); - }; + let have_args: Vec> = if let Some(args_list) = tail.proper_list() { + args_list.into_iter().map(Rc::new).collect() + } else { + return Ok(None); + }; if let Some(extension) = self.extfuns.get(head_atom) { - let res = extension.try_eval(&hl, &have_args) + let res = extension + .try_eval(&hl, &have_args) .map_err(compile_to_run_err)?; eprintln!("res = {res}"); diff --git a/src/compiler/preprocessor/mod.rs b/src/compiler/preprocessor/mod.rs index bc94064a..2474f549 100644 --- a/src/compiler/preprocessor/mod.rs +++ b/src/compiler/preprocessor/mod.rs @@ -72,7 +72,7 @@ fn make_defmac_name(name: &[u8]) -> Vec { } fn nilize(v: Rc) -> Rc { - if let SExp::Cons(l,a,b) = v.borrow() { + if let SExp::Cons(l, a, b) = v.borrow() { let a_conv = nilize(a.clone()); let b_conv = nilize(b.clone()); if Rc::as_ptr(&a_conv) == Rc::as_ptr(&a) && Rc::as_ptr(&b_conv) == Rc::as_ptr(&b) { @@ -321,7 +321,9 @@ impl Preprocessor { args.clone(), Some(extension), None, - ).map(nilize).map_err(|e| CompileErr::from(e))?; + ) + .map(nilize) + .map_err(|e| CompileErr::from(e))?; eprintln!("macro {} {args} => {res}", decode_string(&name)); return Ok(Some(res));