mirror of
https://github.com/janet-lang/janet
synced 2025-11-21 17:54:49 +00:00
Add propagate function and opcode
This allows better stacktraces when manually intercepting signals to clean up resources. Also allows functionality from Common Lisp's unwind-protect, such as calling cleanup code while unwindinding the stack, restarting on certain signals, and just in general having more control over signal and signal propagation. Also fix a bug encountered while implementing with-resource in the compiler. Desturcturing arguments that were not the last argument would often result in bad code generation, as slots used to destructure the earlier arguments would invalidate the later parameters. This is fixed by allocating all named parameters before doing any destructuring.
This commit is contained in:
@@ -245,6 +245,7 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status)
|
||||
&&label_JOP_TAILCALL,
|
||||
&&label_JOP_RESUME,
|
||||
&&label_JOP_SIGNAL,
|
||||
&&label_JOP_PROPAGATE,
|
||||
&&label_JOP_GET,
|
||||
&&label_JOP_PUT,
|
||||
&&label_JOP_GET_INDEX,
|
||||
@@ -277,7 +278,9 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status)
|
||||
* DO NOT use input when resuming a fiber that has been interrupted at a
|
||||
* breakpoint. */
|
||||
if (status != JANET_STATUS_NEW &&
|
||||
((*pc & 0xFF) == JOP_SIGNAL || (*pc & 0xFF) == JOP_RESUME)) {
|
||||
((*pc & 0xFF) == JOP_SIGNAL ||
|
||||
(*pc & 0xFF) == JOP_PROPAGATE ||
|
||||
(*pc & 0xFF) == JOP_RESUME)) {
|
||||
stack[A] = in;
|
||||
pc++;
|
||||
}
|
||||
@@ -673,6 +676,18 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status)
|
||||
vm_return(s, stack[B]);
|
||||
}
|
||||
|
||||
VM_OP(JOP_PROPAGATE) {
|
||||
Janet fv = stack[C];
|
||||
vm_assert_type(fv, JANET_FIBER);
|
||||
JanetFiber *f = janet_unwrap_fiber(fv);
|
||||
JanetFiberStatus status = janet_fiber_status(f);
|
||||
if (status > JANET_STATUS_USER9) {
|
||||
vm_throw("cannot propagate from new or alive fiber");
|
||||
}
|
||||
janet_vm_fiber->child = f;
|
||||
vm_return((int) status, stack[B]);
|
||||
}
|
||||
|
||||
VM_OP(JOP_PUT)
|
||||
vm_commit();
|
||||
janet_put(stack[A], stack[B], stack[C]);
|
||||
|
||||
Reference in New Issue
Block a user