Commit 0f2b0224 authored by Jeff Smits's avatar Jeff Smits

Actually finished the code that make the overlays work, doh

parent 519dd1ac
......@@ -59,7 +59,7 @@ impl<'a> MutContext<'a> {
result
}
// Should really return a &SDefT, but I can't figure out lifetimes that borrowck will accept :(
// Should really return a &SDef, but I can't figure out lifetimes that borrowck will accept :(
pub fn get_strategy(&self, strat_name: &str) -> Result<StrategyDef> {
self.scopes
.borrow()
......@@ -124,15 +124,26 @@ impl<'a> MutContext<'a> {
self.scopes.borrow_mut().push(scope);
}
pub fn apply_overlay(&self) {
let mut scopes = self.scopes.borrow_mut();
let overlay = scopes
pub fn apply_overlay(&self) -> Result<()> {
let overlay = self.scopes.borrow_mut()
.pop()
.expect("apply_overlay: scopes stack unexpectedly empty");
if !overlay.overlay {
unreachable!("apply_overlay: Interpreter bug, scopes stack did not contain an overlay \
at the top")
}
if !overlay.strategy.is_empty() {
unreachable!("apply_overlay: Interpreter bug, overlay is leaking a strategy definition")
}
for (name, value) in overlay.term {
if let Some(value) = value {
self.match_term(&name, &value)?;
} else {
unreachable!("apply_overlay: Interpreter bug, who put an uninitialised variable in \
my overlay? >:(")
}
}
Ok(())
}
pub fn pop_scope(&self) {
......
......@@ -209,7 +209,7 @@ impl<'a> Eval<'a> for preprocess::Strategy {
context.push_scope(context::Scope::overlay());
match s_if.eval(context, current.clone()) {
Ok(current) => {
context.apply_overlay();
context.apply_overlay()?;
s_then.eval(context, current)
}
Err(Error::StrategyFailed) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment