Skip to content

Commit

Permalink
fix: garbage collector and error position display
Browse files Browse the repository at this point in the history
  • Loading branch information
viddrobnic committed Jun 15, 2024
1 parent c1fcd4c commit 240a24f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion runtime/src/vm/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 240a24f

Please sign in to comment.