Skip to content

Commit

Permalink
pass in allocator to post-eval callback
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Apr 27, 2024
1 parent d6db84d commit ef3795c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/run_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub type PreEval =
Box<dyn Fn(&mut Allocator, NodePtr, NodePtr) -> Result<Option<Box<PostEval>>, EvalErr>>;

#[cfg(feature = "pre-eval")]
pub type PostEval = dyn Fn(Option<NodePtr>);
pub type PostEval = dyn Fn(&mut Allocator, Option<NodePtr>);

#[repr(u8)]
enum Operation {
Expand Down Expand Up @@ -495,7 +495,7 @@ impl<'a, D: Dialect> RunProgramContext<'a, D> {
Operation::PostEval => {
let f = self.posteval_stack.pop().unwrap();
let peek: Option<NodePtr> = self.val_stack.last().copied();
f(peek);
f(&mut self.allocator, peek);
0
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/test_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ fn test_pre_eval_and_post_eval() {
&mut Allocator,
NodePtr,
NodePtr,
) -> Result<Option<Box<(dyn Fn(Option<NodePtr>))>>, EvalErr>,
) -> Result<Option<Box<(dyn Fn(&mut Allocator, Option<NodePtr>))>>, EvalErr>,
> = Box::new(move |_allocator, prog, args| {
let tracking_key = pre_eval_tracking.borrow().len();
// Ensure lifetime of mutable borrow is contained.
Expand All @@ -430,7 +430,7 @@ fn test_pre_eval_and_post_eval() {
);
}
let post_eval_tracking = pre_eval_tracking.clone();
let post_eval_f: Box<dyn Fn(Option<NodePtr>)> = Box::new(move |outcome| {
let post_eval_f: Box<dyn Fn(&mut Allocator, Option<NodePtr>)> = Box::new(move |_a, outcome| {
let mut tracking_mutable = post_eval_tracking.borrow_mut();
tracking_mutable.insert(
tracking_key,
Expand Down

0 comments on commit ef3795c

Please sign in to comment.