From 0eaa5060a21d0afe79064689d1559d0da3519b75 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Wed, 20 May 2020 15:25:10 -0400 Subject: [PATCH] Run cargo fmt Signed-off-by: Alek Ratzloff --- src/compile/block.rs | 21 ++++++++------------- src/compile/ctx.rs | 9 ++------- src/compile/error.rs | 4 +--- src/compile/ir.rs | 5 +---- src/compile/mod.rs | 4 ++-- src/compile/visit.rs | 5 ++--- src/main.rs | 19 ++++++------------- src/mem/basic.rs | 9 +++------ src/mem/gc.rs | 7 +------ src/mem/mod.rs | 5 ++--- src/mem/ptr.rs | 19 ++++++++++++------- src/obj/attrs.rs | 20 +++++++------------- src/obj/error.rs | 5 +---- src/obj/fun.rs | 5 +---- src/obj/mod.rs | 7 +++++-- src/syn/ast.rs | 10 +--------- src/syn/lexer.rs | 25 +++++++++++-------------- src/vm/frame.rs | 8 ++------ src/vm/op.rs | 2 +- 19 files changed, 69 insertions(+), 120 deletions(-) diff --git a/src/compile/block.rs b/src/compile/block.rs index 926b49f..a4eba19 100644 --- a/src/compile/block.rs +++ b/src/compile/block.rs @@ -1,11 +1,6 @@ use crate::{ + compile::{ctx::Ctx, error::*, ir, visit::*}, syn::{ast::*, op::BinOp, span::*}, - compile::{ - ctx::Ctx, - error::*, - ir, - visit::*, - }, }; // basic block @@ -20,10 +15,7 @@ pub struct TranslateAst<'c, 't> { impl<'c, 't> TranslateAst<'c, 't> { pub fn new(ctx: &'c mut Ctx, text: &'t str) -> Self { - TranslateAst { - ctx, - text, - } + TranslateAst { ctx, text } } pub fn translate(&mut self, ast: &Vec) -> Result { @@ -33,13 +25,16 @@ impl<'c, 't> TranslateAst<'c, 't> { fn visit_lhs_expr(&mut self, expr: &Expr) -> Result { match expr { Expr::Bin(b) if b.op == BinOp::Dot => todo!(), - Expr::Base(BaseExpr { kind: BaseExprKind::Ident, .. }) => { + Expr::Base(BaseExpr { + kind: BaseExprKind::Ident, + .. + }) => { let name = expr.text_at(self.text); //let name_id = self.ctx. - todo!() + todo!() //Ok(ir::Lhs::Name( } - _ => todo!() + _ => todo!(), } } } diff --git a/src/compile/ctx.rs b/src/compile/ctx.rs index b4fbf15..bb2bfc6 100644 --- a/src/compile/ctx.rs +++ b/src/compile/ctx.rs @@ -1,7 +1,4 @@ -use crate::{ - compile::name::NameStack, - obj::Sym, -}; +use crate::{compile::name::NameStack, obj::Sym}; use std::collections::HashMap; pub struct Ctx { @@ -35,8 +32,6 @@ impl Ctx { pub fn add_sym(&mut self, name: String) -> Sym { let next_sym = self.syms().len(); - *self.syms_mut() - .entry(name) - .or_insert(next_sym.into()) + *self.syms_mut().entry(name).or_insert(next_sym.into()) } } diff --git a/src/compile/error.rs b/src/compile/error.rs index e534125..978c2eb 100644 --- a/src/compile/error.rs +++ b/src/compile/error.rs @@ -4,9 +4,7 @@ use snafu::Snafu; #[derive(Debug, Snafu)] pub enum Error { #[snafu(display("invalid assignment target"))] - InvalidLhs { - span: Span, - } + InvalidLhs { span: Span }, } pub type Result = std::result::Result; diff --git a/src/compile/ir.rs b/src/compile/ir.rs index d25dfb9..2166878 100644 --- a/src/compile/ir.rs +++ b/src/compile/ir.rs @@ -1,7 +1,4 @@ -use crate::{ - obj::Sym, - syn::span::*, -}; +use crate::{obj::Sym, syn::span::*}; pub type Body = Vec; diff --git a/src/compile/mod.rs b/src/compile/mod.rs index a1e95fc..b3a325d 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -1,4 +1,5 @@ -#[macro_use] pub mod visit; +#[macro_use] +pub mod visit; pub mod block; pub mod ctx; pub mod error; @@ -8,4 +9,3 @@ pub mod name; // * Desugar // * Collect names as symbols // * Create basic blocks - diff --git a/src/compile/visit.rs b/src/compile/visit.rs index 7fbfe04..9ca78e9 100644 --- a/src/compile/visit.rs +++ b/src/compile/visit.rs @@ -11,8 +11,7 @@ pub trait Accept { Self: Sized; } -pub trait DefaultAccept>: Accept + Sized -{ +pub trait DefaultAccept>: Accept + Sized { fn default_accept(&self, visitor: &mut V) -> V::Out; } @@ -35,7 +34,7 @@ macro_rules! empty_visitor { type Out = (); fn visit(&mut self, _: &$default) -> Self::Out {} } - } + }; } macro_rules! impl_accept { diff --git a/src/main.rs b/src/main.rs index 114c534..df37f24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,16 +2,12 @@ #![feature(unsize, coerce_unsized, new_uninit)] mod compile; -mod syn; -mod obj; mod mem; +mod obj; +mod syn; mod vm; -use std::{ - convert::TryFrom, - fs, - path::PathBuf, -}; +use std::{convert::TryFrom, fs, path::PathBuf}; use structopt::StructOpt; type Result = std::result::Result>; @@ -24,7 +20,6 @@ struct Options { /// Supplying - for the path will read from STDIN. #[structopt(name = "FILE", parse(from_os_str))] input: PathBuf, - /* /// Disassemble object that would be passed to VM and exit before running it. #[structopt(short = "d", long)] @@ -33,16 +28,14 @@ struct Options { } fn main() -> Result<()> { - use syn::{ - parser::Parser, - }; + use syn::parser::Parser; let opt = Options::from_args(); let text = fs::read_to_string(&opt.input)?; let mut parser = Parser::try_from(text.as_str())?; let ast = parser.next_body()?; //println!("{:#?}", ast); - + let mut ctx = compile::ctx::Ctx::new(); compile::name::CollectSyms::new(&mut ctx, text.as_str()).collect(&ast); println!("{:#?}", ctx.syms()); @@ -54,6 +47,6 @@ fn main() -> Result<()> { } let names = ctx.name_stack_mut().pop().unwrap(); //println!("{:#?}", names); - + Ok(()) } diff --git a/src/mem/basic.rs b/src/mem/basic.rs index 5df793e..9ccef93 100644 --- a/src/mem/basic.rs +++ b/src/mem/basic.rs @@ -1,11 +1,8 @@ use crate::{ - mem::{ - gc::Gc, - ptr::ObjCell, - }, + mem::{gc::Gc, ptr::ObjCell}, obj::prelude::*, }; -use std::{ptr::NonNull}; +use std::ptr::NonNull; #[derive(Default)] pub struct BasicGc { @@ -55,7 +52,7 @@ impl Gc for BasicGc { #[test] fn test_gc_clone() { use crate::{obj::{attrs::AttrsBuilder, ctx::DefaultGc, Attrs, ObjCtx}}; - + let mut ctx = ObjCtx::new(DefaultGc::default()); let empty_attrs = Attrs::new(&mut ctx, Default::default()); diff --git a/src/mem/gc.rs b/src/mem/gc.rs index d2befda..866e09e 100644 --- a/src/mem/gc.rs +++ b/src/mem/gc.rs @@ -1,9 +1,4 @@ -use crate::{ - obj::prelude::*, - mem::{ - ptr::ObjCell, - } -}; +use crate::{mem::ptr::ObjCell, obj::prelude::*}; pub trait Gc { fn alloc(&mut self, obj: O) -> ObjRef; diff --git a/src/mem/mod.rs b/src/mem/mod.rs index 1306ea7..2630792 100644 --- a/src/mem/mod.rs +++ b/src/mem/mod.rs @@ -3,13 +3,12 @@ pub mod gc; pub mod intern; pub mod ptr; -pub use basic::BasicGc; +pub use basic::BasicGc; pub mod prelude { pub use crate::mem::{ - BasicGc, gc::Gc, ptr::{DynRef, ObjRef}, + BasicGc, }; } - diff --git a/src/mem/ptr.rs b/src/mem/ptr.rs index b1e697e..aa25436 100644 --- a/src/mem/ptr.rs +++ b/src/mem/ptr.rs @@ -11,7 +11,8 @@ use std::{ pub type DynRef = ObjRef; pub struct ObjRef -where O: Obj + ?Sized, +where + O: Obj + ?Sized, { ptr: NonNull>, } @@ -126,14 +127,18 @@ where } impl CoerceUnsized> for ObjRef - where T: Obj + Unsize + ?Sized, - U: Obj + ?Sized -{} +where + T: Obj + Unsize + ?Sized, + U: Obj + ?Sized, +{ +} impl CoerceUnsized> for ObjCell - where T: CoerceUnsized + Obj, - U: Obj -{} +where + T: CoerceUnsized + Obj, + U: Obj, +{ +} // // ObjCell diff --git a/src/obj/attrs.rs b/src/obj/attrs.rs index 2516412..0bb7c0b 100644 --- a/src/obj/attrs.rs +++ b/src/obj/attrs.rs @@ -97,10 +97,7 @@ impl<'i, I: Intern> AttrsBuilder<'i, I> { } pub fn with_base(intern: &'i mut I, attrs: Ss) -> Self { - AttrsBuilder { - attrs, - intern, - } + AttrsBuilder { attrs, intern } } pub fn attr(self, symbol_name: &str, value: DynRef) -> Self { @@ -125,7 +122,7 @@ fn test_attrs_new() { let mut gc = BasicGc::default(); let mut intern = BasicIntern::default(); - + let attrs_ref = Attrs::new(&mut gc, Default::default()); { @@ -133,13 +130,10 @@ fn test_attrs_new() { let sym = intern.intern_sym("symbol"); attrs.insert(sym, attrs_ref.as_dyn()); - assert!( - ptr::eq( - dbg!(attrs.get(sym).unwrap().as_ptr()), - dbg!(attrs_ref.as_dyn().as_ptr()) - // ^ as_dyn() is important here - this will cause the test to fail - // otherwise - ), - ); + assert!(ptr::eq( + dbg!(attrs.get(sym).unwrap().as_ptr()), + dbg!(attrs_ref.as_dyn().as_ptr()) // ^ as_dyn() is important here - this will cause the test to fail + // otherwise + ),); } } diff --git a/src/obj/error.rs b/src/obj/error.rs index f243112..7718c7a 100644 --- a/src/obj/error.rs +++ b/src/obj/error.rs @@ -4,10 +4,7 @@ use snafu::Snafu; #[derive(Debug, Snafu)] pub enum Error { #[snafu(display("illegal attr key"))] - AttrKey { - key: DynRef - } + AttrKey { key: DynRef }, } pub type Result = std::result::Result; - diff --git a/src/obj/fun.rs b/src/obj/fun.rs index b5ba0d3..9ef4543 100644 --- a/src/obj/fun.rs +++ b/src/obj/fun.rs @@ -11,10 +11,7 @@ pub struct NativeFun { impl NativeFun { pub fn new(attrs: AttrsRef, name: StrRef, fn_ptr: NativeFunPtr) -> Self { // TODO : clone attrs, add name - NativeFun { - attrs, - fn_ptr, - } + NativeFun { attrs, fn_ptr } } pub fn call(&self, argv: Vec) { diff --git a/src/obj/mod.rs b/src/obj/mod.rs index bcc4d1c..16ec9af 100644 --- a/src/obj/mod.rs +++ b/src/obj/mod.rs @@ -6,7 +6,10 @@ pub mod fun; pub mod name; //pub mod num; pub mod ns { - use crate::{mem::ptr::DynRef, obj::{NameId, Sym}}; + use crate::{ + mem::ptr::DynRef, + obj::{NameId, Sym}, + }; use std::collections::BTreeMap; /// A namespace, indexed by `NameID`. This is used for scopes and local values. @@ -26,7 +29,7 @@ pub mod prelude { ptr::{DynRef, ObjRef}, }, obj::{ - Attrs, AttrsRef, Dict, DictRef, Fun, NativeFun, NameId, Ns, Obj, ObjCtx, Ss, Str, + Attrs, AttrsRef, Dict, DictRef, Fun, NameId, NativeFun, Ns, Obj, ObjCtx, Ss, Str, StrRef, Sym, }, }; diff --git a/src/syn/ast.rs b/src/syn/ast.rs index 127dfc3..5468f14 100644 --- a/src/syn/ast.rs +++ b/src/syn/ast.rs @@ -3,16 +3,8 @@ use derivative::Derivative; pub mod prelude { pub use super::{ - Stmt, - AssignStmt, - Expr, - BinExpr, + AssignStmt, BaseExpr, BaseExprKind, BinExpr, Expr, FunCallExpr, FunExpr, IndexExpr, Stmt, UnExpr, - FunCallExpr, - IndexExpr, - FunExpr, - BaseExpr, - BaseExprKind }; } diff --git a/src/syn/lexer.rs b/src/syn/lexer.rs index 6cd95ce..ed8385f 100644 --- a/src/syn/lexer.rs +++ b/src/syn/lexer.rs @@ -91,10 +91,7 @@ impl<'t> Lexer<'t> { .ignore_whitespace(true) .build() .unwrap(); - - static ref SKIP_REGEX: Regex = Regex::new( - r"^((#[^\n]*)\n?|[ \t\r]+)+" - ).unwrap(); + static ref SKIP_REGEX: Regex = Regex::new(r"^((#[^\n]*)\n?|[ \t\r]+)+").unwrap(); } const CAPTURES: &[(&str, TokenKind)] = &[ @@ -139,13 +136,12 @@ impl<'t> Lexer<'t> { return Ok(None); }; - let caps = - REGEX - .captures(self.pos_text()) - .ok_or_else(|| Error::Unexpected { - what: "EOF".to_string(), - pos: self.pos, - })?; + let caps = REGEX + .captures(self.pos_text()) + .ok_or_else(|| Error::Unexpected { + what: "EOF".to_string(), + pos: self.pos, + })?; // Get first capture let capture_kind = CAPTURES @@ -165,7 +161,6 @@ impl<'t> Lexer<'t> { }); }; - let start = self.pos; self.pos.adv_str(token_text); let end = self.pos; @@ -211,8 +206,10 @@ mod test { assert!(matches!(lexer.next_token(), Ok(None))); assert!(lexer.is_eof()); - let mut lexer = Lexer::new(r"#comment - #another comment"); + let mut lexer = Lexer::new( + r"#comment + #another comment", + ); assert!(matches!(lexer.next_token(), Ok(None))); assert!(lexer.is_eof()); } diff --git a/src/vm/frame.rs b/src/vm/frame.rs index 8a66581..37c2614 100644 --- a/src/vm/frame.rs +++ b/src/vm/frame.rs @@ -1,7 +1,4 @@ -use crate::{ - obj::prelude::*, - vm::op::Op, -}; +use crate::{obj::prelude::*, vm::op::Op}; use std::{collections::BTreeMap, rc::Rc}; pub struct Frame { @@ -26,7 +23,7 @@ impl Frame { pub fn push(&mut self, obj_ref: DynRef) { self.stack.push(obj_ref) } - + pub fn pop(&mut self) -> Option { self.stack.pop() } @@ -59,4 +56,3 @@ impl Frame { &self.ops } } - diff --git a/src/vm/op.rs b/src/vm/op.rs index 40b4954..92142a8 100644 --- a/src/vm/op.rs +++ b/src/vm/op.rs @@ -10,7 +10,7 @@ use crate::obj::{NameId, Sym}; pub enum Op { /// Push a value from a name ID. Push(NameId), - + /// Pop the top stack value into a local name (if supplied) Pop(Option),