mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-14 17:35:03 +01:00
more things
This commit is contained in:
parent
912fa48b1d
commit
ee0ccfcb3b
4 changed files with 13 additions and 9 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -16,12 +16,13 @@ use std::rc::Rc;
|
|||
|
||||
type CResult<T = ()> = Result<T, CompilerError>;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum OuterEnvKind {
|
||||
Block,
|
||||
Closure,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug)]
|
||||
struct Env {
|
||||
locals: HashMap<Symbol, usize>,
|
||||
outer: Option<Rc<RefCell<Env>>>,
|
||||
|
|
@ -32,7 +33,7 @@ impl Env {
|
|||
fn lookup_local(&self, name: &Ident) -> CResult<usize> {
|
||||
fn lookup_inner(env: &Env, name: &Ident) -> Option<usize> {
|
||||
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(),
|
||||
|
|
|
|||
|
|
@ -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<K, V> = std::collections::HashMap<K, V>;
|
||||
|
||||
#[cfg(feature = "fxhash")]
|
||||
type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;
|
||||
|
||||
#[cfg(not(feature = "fxhash"))]
|
||||
#[allow(clippy::disallowed_types)]
|
||||
#[allow(clippy::disallowed_type)]
|
||||
type HashSet<T> = std::collections::HashSet<T>;
|
||||
|
||||
#[cfg(feature = "fxhash")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue