Commit c152479b authored by Jeff Smits's avatar Jeff Smits

Partially (see todo) fixed adding sargs to scope when going into strategy definitions

parent bee22238
......@@ -153,6 +153,26 @@ struct Scope<'s> {
}
impl<'s> Scope<'s> {
fn from_args<I1, I2>(no_of_scopes: usize, sargs: I1, targs: I2) -> Self
where
I1: IntoIterator<Item = &'s str>,
I2: IntoIterator<Item = &'s str>,
{
Scope {
term: targs
.into_iter()
.map(|targ| (targ, Value::UnBound))
.collect(),
strategy: sargs.into_iter()
.map(|sarg| {
(sarg, (Ok(FnvHashSet::default()), no_of_scopes))
})
.collect(),
is_overlay: false,
is_unbound_overlay: false,
}
}
fn from_let_defs<'a, I>(no_of_scopes: usize, defs: I) -> Self
where
I: IntoIterator<Item = &'a preprocess::Def<'s>>,
......@@ -350,11 +370,11 @@ impl<'s> CTreeOptimize for preprocess_ext::Def<'s> {
match self {
SDefT(name, sargs, targs, strat) => {
let mut context = (None, Scopes(vec![Scope::from_fresh_variables(targs.iter().map(|vd| vd.0))]));
let mut context = (None, Scopes(vec![Scope::from_args(0, sargs.iter().map(|vd| vd.0), targs.iter().map(|vd| vd.0))]));
SDefT(name, sargs, targs, strat.optimize(&mut context))
}
ExtSDefInl(name, sargs, targs, strat) => {
let mut context = (None, Scopes(vec![Scope::from_fresh_variables(targs.iter().map(|vd| vd.0))]));
let mut context = (None, Scopes(vec![Scope::from_args(0, sargs.iter().map(|vd| vd.0), targs.iter().map(|vd| vd.0))]));
ExtSDefInl(name, sargs, targs, strat.optimize(&mut context))
}
ExtSDef(name, sargs, targs) => ExtSDef(name, sargs, targs),
......@@ -369,7 +389,13 @@ impl<'s> CTreeOptimize for preprocess::Def<'s> {
fn optimize(mut self, c: &mut Self::Context) -> Self {
// eprintln!("CTreeOptimize::optimize(\"LetDef\", _)");
c.1.push_scope(Scope::from_fresh_variables(self.targs.iter().map(|&s| s)));
let no_of_scopes = (c.1).0.len();
// TODO: reevaluate this from_args call.
// It give an empty set of influenced variable to the sargs, which probably not correct at
// this point. The closure given as sarg to this strategy could be made before this one,
// which would make it able to change variables that this Def would be able to observe.
c.1.push_scope(Scope::from_args(no_of_scopes, self.sargs.iter().map(|&s| s), self.targs.iter().map(|&s| s)));
self.body = self.body.optimize(c);
c.1.pop_scope();
......
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