1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 17:00:27 +00:00

Allow 1 argument call of debug/stacktrace

Since fibers now track the last value signaled.
This commit is contained in:
Calvin Rose 2021-01-17 13:55:40 -06:00
parent 96262e7d87
commit bd2e335063
2 changed files with 13 additions and 7 deletions

View File

@ -299,9 +299,11 @@ static Janet cfun_debug_stack(int32_t argc, Janet *argv) {
}
static Janet cfun_debug_stacktrace(int32_t argc, Janet *argv) {
janet_fixarity(argc, 2);
janet_arity(argc, 1, 2);
JanetFiber *fiber = janet_getfiber(argv, 0);
janet_stacktrace(fiber, argv[1]);
Janet x = argc == 1 ? janet_wrap_nil() : argv[1];
x = janet_checktype(x, JANET_NIL) ? fiber->last_value : x;
janet_stacktrace(fiber, x);
return argv[0];
}
@ -377,10 +379,10 @@ static const JanetReg debug_cfuns[] = {
},
{
"debug/stacktrace", cfun_debug_stacktrace,
JDOC("(debug/stacktrace fiber err)\n\n"
"Prints a nice looking stacktrace for a fiber. The error message "
"err must be passed to the function as fiber's do not keep track of "
"the last error they have thrown. Returns the fiber.")
JDOC("(debug/stacktrace fiber &opt err)\n\n"
"Prints a nice looking stacktrace for a fiber. Can optionally provide "
"an error value to print the stack trace with. If `err` is nil or not "
"provided, will default to `(fiber/last-value fiber)`. Returns the fiber.")
},
{
"debug/lineage", cfun_debug_lineage,

View File

@ -1065,7 +1065,11 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
janet_status_names[sub_status]);
}
fiber->child = f;
vm_return((int) sub_status, stack[B]);
if (janet_checktype(stack[B], JANET_NIL)) {
vm_return((int) sub_status, f->last_value);
} else {
vm_return((int) sub_status, stack[B]);
}
}
VM_OP(JOP_CANCEL) {