more things

This commit is contained in:
nora 2022-01-17 08:39:19 +01:00
parent 912fa48b1d
commit ee0ccfcb3b
4 changed files with 13 additions and 9 deletions

View file

@ -17,7 +17,7 @@ fxhash = ["rustc-hash"]
_debug = ["debug2"] _debug = ["debug2"]
# todo: we don't actually want this as a default feature # todo: we don't actually want this as a default feature
default = ["_debug"] default = ["_debug", "fxhash"]
[dev-dependencies] [dev-dependencies]
insta = "1.9.0" insta = "1.9.0"

View file

@ -61,7 +61,6 @@
use crate::errors::Span; use crate::errors::Span;
use crate::vm::Value; use crate::vm::Value;
use bumpalo::collections::Vec; use bumpalo::collections::Vec;
use debug2::Formatter;
/// This struct contains all data for a function. /// This struct contains all data for a function.
#[derive(Debug)] #[derive(Debug)]
@ -80,7 +79,7 @@ pub struct FnBlock<'bc> {
#[cfg(feature = "_debug")] #[cfg(feature = "_debug")]
impl debug2::Debug for FnBlock<'_> { 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") f.debug_struct("FnBlock")
.field("code", &self.code.as_slice()) .field("code", &self.code.as_slice())
.field("stack_sizes", &self.stack_sizes.as_slice()) .field("stack_sizes", &self.stack_sizes.as_slice())

View file

@ -16,12 +16,13 @@ use std::rc::Rc;
type CResult<T = ()> = Result<T, CompilerError>; type CResult<T = ()> = Result<T, CompilerError>;
#[derive(Debug, PartialEq, Eq)]
enum OuterEnvKind { enum OuterEnvKind {
Block, Block,
Closure, Closure,
} }
#[derive(Debug, Default)] #[derive(Debug)]
struct Env { struct Env {
locals: HashMap<Symbol, usize>, locals: HashMap<Symbol, usize>,
outer: Option<Rc<RefCell<Env>>>, outer: Option<Rc<RefCell<Env>>>,
@ -32,7 +33,7 @@ impl Env {
fn lookup_local(&self, name: &Ident) -> CResult<usize> { fn lookup_local(&self, name: &Ident) -> CResult<usize> {
fn lookup_inner(env: &Env, name: &Ident) -> Option<usize> { fn lookup_inner(env: &Env, name: &Ident) -> Option<usize> {
env.locals.get(&name.sym).copied().or_else(|| { env.locals.get(&name.sym).copied().or_else(|| {
// TODO: closure handling 👀 // TODO: closure handling lol 👀
if env.outer_kind == OuterEnvKind::Closure { if env.outer_kind == OuterEnvKind::Closure {
return None; return None;
} }
@ -84,7 +85,11 @@ pub fn compile<'ast, 'bc, 'gc>(
blocks: Vec::new_in(bytecode_bump), blocks: Vec::new_in(bytecode_bump),
current_block_idx: 0, current_block_idx: 0,
bump: bytecode_bump, 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, rt,
loop_nesting: 0, loop_nesting: 0,
breaks: HashMap::default(), breaks: HashMap::default(),

View file

@ -1,4 +1,4 @@
#![deny(clippy::disallowed_types)] #![deny(clippy::disallowed_type)]
mod ast; mod ast;
mod bytecode; mod bytecode;
@ -18,14 +18,14 @@ pub use lex::*;
pub use parse::*; pub use parse::*;
#[cfg(not(feature = "fxhash"))] #[cfg(not(feature = "fxhash"))]
#[allow(clippy::disallowed_types)] #[allow(clippy::disallowed_type)]
type HashMap<K, V> = std::collections::HashMap<K, V>; type HashMap<K, V> = std::collections::HashMap<K, V>;
#[cfg(feature = "fxhash")] #[cfg(feature = "fxhash")]
type HashMap<K, V> = rustc_hash::FxHashMap<K, V>; type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;
#[cfg(not(feature = "fxhash"))] #[cfg(not(feature = "fxhash"))]
#[allow(clippy::disallowed_types)] #[allow(clippy::disallowed_type)]
type HashSet<T> = std::collections::HashSet<T>; type HashSet<T> = std::collections::HashSet<T>;
#[cfg(feature = "fxhash")] #[cfg(feature = "fxhash")]