diff --git a/src/build/opcode/runtime.rs b/src/build/opcode/runtime.rs index 4253802..c4a4449 100644 --- a/src/build/opcode/runtime.rs +++ b/src/build/opcode/runtime.rs @@ -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)); diff --git a/src/build/opcode/vm.rs b/src/build/opcode/vm.rs index 7aa838e..4115cc0 100644 --- a/src/build/opcode/vm.rs +++ b/src/build/opcode/vm.rs @@ -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(()); } diff --git a/src/error.rs b/src/error.rs index 4aea57c..78bda6a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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 => "".to_string(), - }; write!(w, "{}: {} at {}", self.err_type, self.msg, pos,)?; } else { write!(w, "{}: {}", self.err_type, self.msg)?;