Remove 'text' member from Compile struct, since we can return file positions instead
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -6,18 +6,17 @@ pub mod thunk;
|
||||
use crate::{syn::ast::Body, obj::prelude::*, vm::consts::*};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
pub struct Compile<'t> {
|
||||
text: &'t str,
|
||||
pub struct Compile {
|
||||
const_data: ConstData,
|
||||
globals: BTreeMap<Sym, Local>,
|
||||
locals: Vec<BTreeMap<Sym, Local>>,
|
||||
next_local: Local,
|
||||
}
|
||||
|
||||
impl<'t> Compile<'t> {
|
||||
pub fn new(text: &'t str) -> Self {
|
||||
impl Compile {
|
||||
/// Creates a new compiler using the given text.
|
||||
pub fn new() -> Self {
|
||||
Compile {
|
||||
text,
|
||||
const_data: Default::default(),
|
||||
globals: Default::default(),
|
||||
locals: Default::default(),
|
||||
@@ -25,14 +24,12 @@ impl<'t> Compile<'t> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn text(&self) -> &'t str {
|
||||
self.text
|
||||
}
|
||||
|
||||
/// Gets the constant data that is interned in this compile session.
|
||||
pub fn const_data(&self) -> &ConstData {
|
||||
&self.const_data
|
||||
}
|
||||
|
||||
/// Mutably gets the constant data that is interned in this compile session.
|
||||
pub fn const_data_mut(&mut self) -> &mut ConstData {
|
||||
&mut self.const_data
|
||||
}
|
||||
@@ -62,7 +59,7 @@ impl<'t> Compile<'t> {
|
||||
}
|
||||
|
||||
/// Creates a new local variable if it does not exist in the current local scope.
|
||||
pub fn create_local(&mut self, sym: Sym) -> Local {
|
||||
pub(crate) fn create_local(&mut self, sym: Sym) -> Local {
|
||||
let locals = self.locals.last_mut().expect("scope");
|
||||
if let Some(local) = locals.get(&sym) {
|
||||
*local
|
||||
@@ -88,17 +85,17 @@ impl<'t> Compile<'t> {
|
||||
}
|
||||
|
||||
/// Pushes an empty scope layer of local variables.
|
||||
pub fn push_scope_layer(&mut self) {
|
||||
pub(crate) fn push_scope_layer(&mut self) {
|
||||
self.locals.push(Default::default());
|
||||
}
|
||||
|
||||
/// Pops a scope layer of local variables, if any are available.
|
||||
pub fn pop_scope_layer(&mut self) -> Option<BTreeMap<Sym, Local>> {
|
||||
pub(crate) 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) {
|
||||
pub(crate) fn collect_locals(&mut self, body: &Body) {
|
||||
locals::CollectLocals::new(self).collect(body);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user