From 240a24f907fdcde3c51df1f7e9c3fe6fe60f8e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vid=20Drobni=C4=8D?= Date: Sat, 15 Jun 2024 20:41:16 +0200 Subject: [PATCH] fix: garbage collector and error position display --- runtime/src/vm/gc.rs | 6 +++++- runtime/src/vm/mod.rs | 2 +- src/main.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/src/vm/gc.rs b/runtime/src/vm/gc.rs index a9d5210..cfd9824 100644 --- a/runtime/src/vm/gc.rs +++ b/runtime/src/vm/gc.rs @@ -61,13 +61,17 @@ impl GarbageCollector { rc_ref } - pub fn free(&mut self, used_stack: &[Object]) { + pub fn free(&mut self, used_stack: &[Object], globals: &[Object]) { self.mark_all(true); for obj in used_stack { self.traverse(obj); } + for obj in globals { + self.traverse(obj) + } + self.owners.retain(|_, owner| !owner.marked); } diff --git a/runtime/src/vm/mod.rs b/runtime/src/vm/mod.rs index 01221f1..e86c54b 100644 --- a/runtime/src/vm/mod.rs +++ b/runtime/src/vm/mod.rs @@ -118,7 +118,7 @@ impl VirtualMachine { } if self.gc.should_free() { - self.gc.free(&self.stack[0..self.sp]); + self.gc.free(&self.stack[0..self.sp], &self.globals); } } diff --git a/src/main.rs b/src/main.rs index 38b3c13..0001c41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,9 @@ fn run(path: PathBuf) { Err(err) => { println!( "Syntax error on line {}, character {}:\n {}", - err.range.start.line, err.range.start.character, err + err.range.start.line + 1, + err.range.start.character + 1, + err ); exit(1); } @@ -39,7 +41,9 @@ fn run(path: PathBuf) { Err(err) => { println!( "Runtime error on line {}, character {}:\n {}", - err.range.start.line, err.range.start.character, err + err.range.start.line + 1, + err.range.start.character + 1, + err ); exit(1); }