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;