[fine] Oh no a runtime and module loading and stuff

Lots of test work to use the new mechanism. I'm not sure I like it.
This commit is contained in:
John Doty 2024-02-12 22:49:34 -08:00
parent 2093502031
commit 994268abb6
6 changed files with 224 additions and 90 deletions

View file

@ -3,7 +3,12 @@ use crate::{
tokens::{Lines, Token, TokenKind},
vm::StackValue,
};
use std::{cell::RefCell, collections::HashMap, fmt, rc::Rc};
use std::{
cell::{OnceCell, RefCell},
collections::HashMap,
fmt,
rc::{Rc, Weak},
};
// TODO: Unused variables?
// TODO: Underscore for discard?
@ -610,6 +615,8 @@ pub struct Semantics {
syntax_tree: Rc<SyntaxTree>,
lines: Rc<Lines>,
import_map: OnceCell<HashMap<String, Weak<Semantics>>>,
// Instead of physical parents, this is the set of *logical* parents.
// This is what is used for binding.
logical_parents: Vec<Option<TreeRef>>,
@ -635,6 +642,7 @@ impl Semantics {
source,
syntax_tree: tree.clone(),
lines,
import_map: OnceCell::new(),
logical_parents,
errors: RefCell::new(vec![]),
types: RefCell::new(vec![Incremental::None; tree.len()]),
@ -653,6 +661,10 @@ impl Semantics {
semantics
}
pub fn set_imports(&self, imports: HashMap<String, Weak<Semantics>>) {
self.import_map.set(imports).expect("imports already set");
}
pub fn source(&self) -> Rc<str> {
self.source.clone()
}
@ -665,6 +677,10 @@ impl Semantics {
self.lines.clone()
}
pub fn imports(&self) -> Vec<String> {
vec![]
}
pub fn snapshot_errors(&self) -> Vec<Error> {
let mut result = (*self.errors.borrow()).clone();
result.sort_by(|a, b| match a.start.0.cmp(&b.start.0) {