mirror of
https://github.com/urbit/ares.git
synced 2024-11-23 09:06:23 +03:00
Merge pull request #141 from urbit/eamsden/stack_frame_wrapper
2stackz: add function to wrap a closure in frame push and pop
This commit is contained in:
commit
b78ccf25e5
@ -656,6 +656,21 @@ impl NockStack {
|
|||||||
self.pc = false;
|
self.pc = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Run a closure inside a frame, popping regardless of the value returned by the closure.
|
||||||
|
* This is useful for writing fallible computations with the `?` operator.
|
||||||
|
*
|
||||||
|
* Note that results allocated on the stack *must* be `preserve()`d by the closure.
|
||||||
|
*/
|
||||||
|
pub unsafe fn with_frame<F, O>(&mut self, num_locals: usize, f: F) -> O
|
||||||
|
where
|
||||||
|
F: FnOnce() -> O,
|
||||||
|
{
|
||||||
|
self.frame_push(num_locals);
|
||||||
|
let ret = f();
|
||||||
|
self.frame_pop();
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
/** Lightweight stack.
|
/** Lightweight stack.
|
||||||
* The lightweight stack is a stack data structure present in each stack
|
* The lightweight stack is a stack data structure present in each stack
|
||||||
* frame, often used for noun traversal. During normal operation (self.pc
|
* frame, often used for noun traversal. During normal operation (self.pc
|
||||||
|
Loading…
Reference in New Issue
Block a user