mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
Properly detect import cycles at runtime.
This commit is contained in:
parent
31d76ec733
commit
ad97dfca57
@ -177,7 +177,12 @@ impl Builtins {
|
||||
if let &Value::P(Str(ref path)) = val.as_ref() {
|
||||
// TODO(jwall): A bit hacky we should probably change import stacks to be pathbufs.
|
||||
let normalized = decorate_error!(path_pos => self.normalize_path(base_path, false, path))?;
|
||||
// first we chack the cache
|
||||
let path = normalized.to_string_lossy().to_string();
|
||||
if let Some(val) = env.borrow().get_cached_path_val(&path) {
|
||||
stack.push((val, path_pos));
|
||||
return Ok(());
|
||||
}
|
||||
if import_stack
|
||||
.iter()
|
||||
.find(|p| *p == &path)
|
||||
@ -197,13 +202,15 @@ impl Builtins {
|
||||
let op_pointer =
|
||||
decorate_error!(path_pos => env.borrow_mut().get_ops_for_path(&normalized))?;
|
||||
// TODO(jwall): What if we don't have a base path?
|
||||
let mut vm = VM::with_pointer(op_pointer, env.clone(), normalized.parent().unwrap());
|
||||
let mut vm = VM::with_pointer(op_pointer, env.clone(), normalized.parent().unwrap())
|
||||
.with_import_stack(import_stack.clone());
|
||||
vm.run()?;
|
||||
let result = Rc::new(vm.symbols_to_tuple(true));
|
||||
env.borrow_mut().update_path_val(&path, result.clone());
|
||||
stack.push((result, pos));
|
||||
}
|
||||
}
|
||||
import_stack.push(path.clone());
|
||||
return Ok(());
|
||||
}
|
||||
return Err(Error::new(format!("Invalid Path {:?}", val), pos));
|
||||
|
@ -842,7 +842,7 @@ where
|
||||
}
|
||||
&C(List(ref elems, _)) => {
|
||||
for e in elems {
|
||||
if dbg!(e) == dbg!(&right) {
|
||||
if dbg!(e) == &right {
|
||||
self.push(Rc::new(P(Bool(true))), pos)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -108,11 +108,6 @@ impl BuildError {
|
||||
|
||||
fn render(&self, w: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(ref pos) = self.pos {
|
||||
// FIXME(jwall): we should still be printing the file here.
|
||||
let file = match pos.file {
|
||||
Some(ref pb) => pb.to_string_lossy().to_string(),
|
||||
None => "<eval>".to_string(),
|
||||
};
|
||||
write!(w, "{}: {} at {}", self.err_type, self.msg, pos,)?;
|
||||
} else {
|
||||
write!(w, "{}: {}", self.err_type, self.msg)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user