Commit 77392d2d authored by Jeff Smits's avatar Jeff Smits

WIP Set up offset prefetching in term match

parent 45bb8b56
......@@ -72,12 +72,8 @@ impl<'d, 'f : 'd> MutContext<'d, 'f> {
.ok_or_else(|| Error::UndefinedStrategy(strat_name.to_owned()))
}
fn get_term_option(&self, term_name: &str) -> Result<Option<ATermRef>> {
Scopes::get_term_option(&self.scopes.borrow(), term_name)
}
pub fn get_term(&self, term_name: &str) -> Result<ATermRef> {
self.get_term_option(term_name).and_then(|o| {
Scopes::get_term_option(&self.scopes.borrow(), term_name).and_then(|(_, o)| {
o.ok_or(Error::StrategyFailed)
})
}
......@@ -269,15 +265,20 @@ pub mod Scopes {
use super::*;
pub fn get_term_option(
vec: &Vec<Scope<ATermRef>>,
scopes: &Vec<Scope<ATermRef>>,
term_name: &str,
) -> Result<Option<ATermRef>> {
vec.iter()
.rev()
.flat_map(|scope| scope.term.get(term_name))
.cloned()
.next()
.ok_or_else(|| Error::UndefinedVariable(term_name.to_owned()))
) -> Result<(usize, Option<ATermRef>)> {
let mut offset = None;
for (n,scope) in scopes.iter().enumerate().rev() {
if offset == None && scope.is_overlay {
offset = Some(n);
}
if let Some(binding) = scope.term.get(term_name) {
let n = offset.unwrap_or(n);
return Ok((n, binding.clone()))
}
}
Err(Error::UndefinedVariable(term_name.to_owned()))
}
pub fn match_term<'a>(
......@@ -287,21 +288,15 @@ pub mod Scopes {
) -> Result<()> {
let term = get_term_option(scopes, term_name)?;
match term {
Some(term) => {
(_, Some(term)) => {
if Borrow::<ATerm>::borrow(&term) == current.borrow() {
return Ok(());
} else {
return Err(Error::StrategyFailed);
}
}
None => {
for mut scope in scopes.iter_mut().rev() {
if scope.is_overlay || scope.term.contains_key(term_name) {
if let Some(Some(t)) = scope.term.insert(
term_name,
Some(current.clone()),
)
{
(n, None) => {
if let Some(Some(t)) = scopes[n].term.insert(term_name, Some(current.clone())) {
unreachable!(format!(
"match_term: No scope had {}, but we just \
replaced {} when we added it?!",
......@@ -313,8 +308,6 @@ pub mod Scopes {
}
}
}
}
}
unreachable!(format!(
"match_term: First we could find {} unbound, then we couldn't \
anymore?!",
......
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