Add local variable collection to compilation
* Upon entering a new body, the local scope variables are collected. * VM instruction PushLocal now uses a `Local` value instead of a `Sym` value * Compilation of a new AST body will implicitly create a new scope Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@ pub mod error;
|
||||
mod locals;
|
||||
pub mod thunk;
|
||||
|
||||
use crate::{obj::prelude::*, vm::consts::*};
|
||||
use crate::{syn::ast::Body, obj::prelude::*, vm::consts::*};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
pub struct Compile<'t> {
|
||||
@@ -96,6 +96,11 @@ impl<'t> Compile<'t> {
|
||||
pub fn pop_scope_layer(&mut self) -> Option<BTreeMap<Sym, Local>> {
|
||||
self.locals.pop()
|
||||
}
|
||||
|
||||
/// Collects local variables for the given AST body non-recursively.
|
||||
pub fn collect_locals(&mut self, body: &Body) {
|
||||
locals::CollectLocals::new(self).collect(body);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
||||
Reference in New Issue
Block a user