diff --git a/Cargo.toml b/Cargo.toml index 40c553f..74b1401 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,6 @@ insta = "1.9.0" [[bench]] name = "parser" harness = false + +[profile.release] +debug = true \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d18e69f..37c2983 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,7 @@ type HashSet = rustc_hash::FxHashSet; pub struct Config<'io> { pub debug: bool, pub step: bool, + pub parse_only: bool, pub stdout: &'io mut dyn Write, } @@ -53,7 +54,12 @@ pub fn run_program(program: &str, cfg: &mut Config) { let ast = parse::parse(lexer, &ast_alloc); match ast { - Ok(ast) => process_ast(program, &ast, runtime, cfg), + Ok(ast) => { + if cfg.parse_only { + return; + } + process_ast(program, &ast, runtime, cfg) + } Err(err) => errors::display_error(program, err), } } diff --git a/src/main.rs b/src/main.rs index c782988..ffbd4e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ fn main() { let mut cfg = Config { debug: false, step: false, + parse_only: false, stdout: &mut stdout, }; @@ -18,6 +19,7 @@ fn main() { match &*arg { "--debug" => cfg.debug = true, "--step" => cfg.step = true, + "--parse-only" => cfg.parse_only = true, _ => {} } } diff --git a/src/runtime/gc.rs b/src/runtime/gc.rs index 66f6f02..4bf7936 100644 --- a/src/runtime/gc.rs +++ b/src/runtime/gc.rs @@ -89,28 +89,28 @@ enum HeapObjectKind { #[derive(Debug)] pub struct RtAlloc { - symbols: HashSet, + symbols: HashSet, objects: LinkedList, } #[derive(Debug)] -struct NonNullStrWrapper(NonNull); +struct NonNullStrStructuralEq(NonNull); -impl Hash for NonNullStrWrapper { +impl Hash for NonNullStrStructuralEq { fn hash(&self, state: &mut H) { // SAFETY: Assume the ptr is valid, same rules as `Gc` unsafe { self.0.as_ref().hash(state) } } } -impl PartialEq for NonNullStrWrapper { +impl PartialEq for NonNullStrStructuralEq { fn eq(&self, other: &Self) -> bool { // SAFETY: Assume the ptr is valid, same rules as `Gc` unsafe { self.0.as_ref().eq(other.0.as_ref()) } } } -impl Eq for NonNullStrWrapper {} +impl Eq for NonNullStrStructuralEq {} impl RtAlloc { /// # Safety @@ -153,11 +153,11 @@ impl RtAlloc { pub fn intern_string(&mut self, str: &str) -> Symbol { let original_nonnull = NonNull::from(str); - if let Some(interned) = self.symbols.get(&NonNullStrWrapper(original_nonnull)) { + if let Some(interned) = self.symbols.get(&NonNullStrStructuralEq(original_nonnull)) { Symbol::new(Gc { ptr: interned.0 }) } else { let allocated = self.alloc_str(str); - self.symbols.insert(NonNullStrWrapper(allocated.ptr)); + self.symbols.insert(NonNullStrStructuralEq(allocated.ptr)); Symbol::new(allocated) } }