Commit 54c9c264 authored by Jeff Smits's avatar Jeff Smits

Moved stack tracing into `SDefT::eval` and

`Context::call_primitive`.
parent 5b1118e1
......@@ -41,13 +41,20 @@ impl<'a> MutContext<'a> {
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
context.stack_tracer.borrow_mut().push(name.clone());
let prim_ref = self.primitives
.iter()
.flat_map(|prims| prims.get(prim_name))
.cloned() // very cheap, so whatever
.next()
.ok_or_else(|| Error::UndefinedPrimitive(prim_name.to_owned()))?;
eval_prim_ref(prim_ref, self, sargs, targs, current)
let result = eval_prim_ref(prim_ref, self, sargs, targs, current);
if result.is_ok() {
context.stack_tracer.borrow_mut().pop_on_success();
} else {
context.stack_tracer.borrow_mut().pop_on_failure();
}
result
}
// Should really return a &SDefT, but I can't figure out lifetimes that borrowck will accept :(
......
......@@ -115,7 +115,6 @@ impl<'a> Eval<'a> for preprocess::Strategy {
result
}
CallT(ref name, ref sargs, ref targs) => {
context.stack_tracer.borrow_mut().push(name.clone());
let sdeft = context
.get_strategy(name)
.map_err(|e| {
......@@ -135,13 +134,7 @@ impl<'a> Eval<'a> for preprocess::Strategy {
context.stack_tracer.borrow_mut().pop_on_failure();
e
})?;
let result = sdeft.eval(context, sargs, targs, current);
if result.is_ok() {
context.stack_tracer.borrow_mut().pop_on_success();
} else {
context.stack_tracer.borrow_mut().pop_on_failure();
}
result
sdeft.eval(context, sargs, targs, current)
}
// TODO
CallDynamic(ref term, ref sargs, ref targs) => unimplemented!(),
......@@ -170,7 +163,6 @@ impl<'a> Eval<'a> for preprocess::Strategy {
}
}
PrimT(ref name, ref sargs, ref targs) => {
context.stack_tracer.borrow_mut().push(name.clone());
let sargs = sargs
.into_iter()
.cloned()
......@@ -184,13 +176,7 @@ impl<'a> Eval<'a> for preprocess::Strategy {
context.stack_tracer.borrow_mut().pop_on_failure();
e
})?;
let result = context.call_primitive(name, sargs, targs, current);
if result.is_ok() {
context.stack_tracer.borrow_mut().pop_on_success();
} else {
context.stack_tracer.borrow_mut().pop_on_failure();
}
result
context.call_primitive(name, sargs, targs, current)
}
Some(ref strat) => eval_some(strat, context, current),
One(ref strat) => eval_one(strat, context, current),
......
......@@ -62,6 +62,7 @@ impl SDefT {
if sargs.len() != self.sargs.len() || targs.len() != self.targs.len() {
Err(Error::UndefinedStrategy(self.name.clone()))
} else {
context.stack_tracer.borrow_mut().push(self.name.clone());
context
.scopes
.borrow_mut()
......@@ -73,7 +74,13 @@ impl SDefT {
.collect(),
strategy: self.sargs.iter().cloned().zip(sargs).collect(),
});
self.body.eval(context, current)
let result = self.body.eval(context, current);
if result.is_ok() {
context.stack_tracer.borrow_mut().pop_on_success();
} else {
context.stack_tracer.borrow_mut().pop_on_failure();
}
result
}
}
......
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