Commit 3633389f authored by Jeff Smits's avatar Jeff Smits

Fix bug, let needs extra scope not +1 on the scope offset

parent 023e1ab2
......@@ -76,12 +76,13 @@ impl<'d, 'f: 'd> MutContext<'d, 'f> {
(term_clos_offsets, strategy_clos_offsets)
}
pub fn make_let_clos_offsets(&self) -> (Vec<usize>, Vec<usize>) {
pub fn make_let_clos_offsets(&self, let_scope_size: usize) -> (Vec<usize>, Vec<usize>) {
let mut term_clos_offsets = self.term_clos_offsets.borrow().clone();
let mut strategy_clos_offsets = self.strategy_clos_offsets.borrow().clone();
term_clos_offsets.push(self.term.borrow().len());
// note the + 1, because `let`s allow recursive definitions
strategy_clos_offsets.push(self.strategy.borrow().len() + 1);
strategy_clos_offsets.push(self.strategy.borrow().len());
// note the extra scope, because `let`s allow recursive definitions
strategy_clos_offsets.push(self.strategy.borrow().len() + let_scope_size);
(term_clos_offsets, strategy_clos_offsets)
}
......
......@@ -95,15 +95,11 @@ pub fn interpret<'f>(
use ctree::match_;
use std::iter;
let program = match match_(&program).and_then(ir_v1::preprocess) {
Ok(v) => v,
Err(e) => return Err(TracedError(e, String::new())),
};
let defs = match libraries
.libs
.into_iter()
.chain(iter::once(program))
.map(|l| match_(&l).and_then(ir_v1::preprocess))
.chain(iter::once(Ok(program)))
.collect::<Result<Vec<_>>>() {
Ok(v) => v,
Err(e) => return Err(TracedError(e, String::new())),
......@@ -152,7 +148,7 @@ impl<'d, 'f: 'd> Eval<'d, 'f> for ir_v2::Strategy<'f> {
Let(ref defs, ref body) => {
use context::Scope;
let (term_scope_offsets, strat_scope_offsets) = context.make_let_clos_offsets();
let (term_scope_offsets, strat_scope_offsets) = context.make_let_clos_offsets(defs.len());
let scope =
Scope::from_let_defs(term_scope_offsets, strat_scope_offsets, defs.iter());
......
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