From e3f4142d2ae825ff4706ebe4970c389c8f087b77 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 12 Oct 2023 05:26:23 -0500 Subject: [PATCH] Update result value from janet_do* functions. --- .gitignore | 5 ++++- src/core/run.c | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 123cf5fb..b95e115b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,8 +34,11 @@ local # Common test files I use. temp.janet -temp*.janet +temp.c +temp*janet +temp*.c scratch.janet +scratch.c # Emscripten *.bc diff --git a/src/core/run.c b/src/core/run.c index 9532e683..c0698231 100644 --- a/src/core/run.c +++ b/src/core/run.c @@ -32,6 +32,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char int errflags = 0, done = 0; int32_t index = 0; Janet ret = janet_wrap_nil(); + JanetFiber *fiber = NULL; const uint8_t *where = sourcePath ? janet_cstring(sourcePath) : NULL; if (where) janet_gcroot(janet_wrap_string(where)); @@ -47,7 +48,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char JanetCompileResult cres = janet_compile(form, env, where); if (cres.status == JANET_COMPILE_OK) { JanetFunction *f = janet_thunk(cres.funcdef); - JanetFiber *fiber = janet_fiber(f, 64, 0, NULL); + fiber = janet_fiber(f, 64, 0, NULL); fiber->env = env; JanetSignal status = janet_continue(fiber, janet_wrap_nil(), &ret); if (status != JANET_SIGNAL_OK && status != JANET_SIGNAL_EVENT) { @@ -112,9 +113,14 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char #ifdef JANET_EV /* Enter the event loop if we are not already in it */ if (janet_vm.stackn == 0) { - janet_gcroot(ret); + if (fiber) { + janet_gcroot(janet_wrap_fiber(fiber)); + } janet_loop(); - janet_gcunroot(ret); + if (fiber) { + janet_gcunroot(janet_wrap_fiber(fiber)); + ret = fiber->last_value; + } } #endif if (out) *out = ret;