From ee0ccfcb3b1dee135007bd6f507684b4586ba4c2 Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 17 Jan 2022 08:39:19 +0100 Subject: [PATCH] more things --- Cargo.toml | 2 +- src/bytecode.rs | 3 +-- src/compile.rs | 11 ++++++++--- src/lib.rs | 6 +++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9dc799e..109993f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ fxhash = ["rustc-hash"] _debug = ["debug2"] # todo: we don't actually want this as a default feature -default = ["_debug"] +default = ["_debug", "fxhash"] [dev-dependencies] insta = "1.9.0" diff --git a/src/bytecode.rs b/src/bytecode.rs index ccb8c88..70b037c 100644 --- a/src/bytecode.rs +++ b/src/bytecode.rs @@ -61,7 +61,6 @@ use crate::errors::Span; use crate::vm::Value; use bumpalo::collections::Vec; -use debug2::Formatter; /// This struct contains all data for a function. #[derive(Debug)] @@ -80,7 +79,7 @@ pub struct FnBlock<'bc> { #[cfg(feature = "_debug")] impl debug2::Debug for FnBlock<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut debug2::Formatter<'_>) -> std::fmt::Result { f.debug_struct("FnBlock") .field("code", &self.code.as_slice()) .field("stack_sizes", &self.stack_sizes.as_slice()) diff --git a/src/compile.rs b/src/compile.rs index 8ec5bdc..622dde2 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -16,12 +16,13 @@ use std::rc::Rc; type CResult = Result; +#[derive(Debug, PartialEq, Eq)] enum OuterEnvKind { Block, Closure, } -#[derive(Debug, Default)] +#[derive(Debug)] struct Env { locals: HashMap, outer: Option>>, @@ -32,7 +33,7 @@ impl Env { fn lookup_local(&self, name: &Ident) -> CResult { fn lookup_inner(env: &Env, name: &Ident) -> Option { env.locals.get(&name.sym).copied().or_else(|| { - // TODO: closure handling 👀 + // TODO: closure handling lol 👀 if env.outer_kind == OuterEnvKind::Closure { return None; } @@ -84,7 +85,11 @@ pub fn compile<'ast, 'bc, 'gc>( blocks: Vec::new_in(bytecode_bump), current_block_idx: 0, bump: bytecode_bump, - env: Rc::new(RefCell::new(Env::default())), + env: Rc::new(RefCell::new(Env { + locals: HashMap::default(), + outer: None, + outer_kind: OuterEnvKind::Block, + })), rt, loop_nesting: 0, breaks: HashMap::default(), diff --git a/src/lib.rs b/src/lib.rs index 37bfc78..30db747 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![deny(clippy::disallowed_types)] +#![deny(clippy::disallowed_type)] mod ast; mod bytecode; @@ -18,14 +18,14 @@ pub use lex::*; pub use parse::*; #[cfg(not(feature = "fxhash"))] -#[allow(clippy::disallowed_types)] +#[allow(clippy::disallowed_type)] type HashMap = std::collections::HashMap; #[cfg(feature = "fxhash")] type HashMap = rustc_hash::FxHashMap; #[cfg(not(feature = "fxhash"))] -#[allow(clippy::disallowed_types)] +#[allow(clippy::disallowed_type)] type HashSet = std::collections::HashSet; #[cfg(feature = "fxhash")]