From cb3b9dd76ff4500a457fbbe0659758cc82a7ae2c Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 31 Jan 2019 10:09:34 -0500 Subject: [PATCH 1/8] Update changelog an fix typos. --- CHANGELOG.md | 8 ++++++++ src/core/core.janet | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d64fd4af..d58720a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Changelog All notable changes to this project will be documented in this file. +## 0.4.0 - ?? +- Add debug/stacktrace for easy, pretty stacktraces +- Remove the status-pp function +- Update API to run-context to be much more sane +- Add :lflags option to cook/make-native +- Disallow NaNs as table or struct keys +- Update module resolution paths and format + ## 0.3.0 - 2019-26-01 - Add amalgamated build to janet for easier embedding. - Add os/date function diff --git a/src/core/core.janet b/src/core/core.janet index 1a10028a..6ae56e12 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -1518,7 +1518,7 @@ value, one key will be ignored." (error (res :error)))) (def module/paths - "The list of paths to look for modules. The followig + "The list of paths to look for modules. The following substitutions are preformed on each path. :sys: becomes module/*syspath*, :name: becomes the last part of the module name after the last /, and :all: is the module name literally. From 7ba925c50a50c1b55d07021ca59142bb4aad8945 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 31 Jan 2019 12:34:22 -0500 Subject: [PATCH 2/8] Make getline more useful. --- src/core/core.janet | 7 +++++-- src/mainclient/line.c | 16 ++++++++-------- src/mainclient/line.h | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/core/core.janet b/src/core/core.janet index 6ae56e12..1efafff2 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -1403,8 +1403,11 @@ value, one key will be ignored." (defn getline "Read a line from stdin into a buffer." - [buf p] - (file/read stdin :line buf)) + [buf p &] + (default buf @"") + (when p (file/write stdout p)) + (file/read stdin :line buf) + buf) (defn run-context "Run a context. This evaluates expressions of janet in an environment, diff --git a/src/mainclient/line.c b/src/mainclient/line.c index 46987223..723966e5 100644 --- a/src/mainclient/line.c +++ b/src/mainclient/line.c @@ -24,11 +24,11 @@ /* Common */ Janet janet_line_getter(int32_t argc, Janet *argv) { - janet_fixarity(argc, 2); - const uint8_t *str = janet_getstring(argv, 0); - JanetBuffer *buf = janet_getbuffer(argv, 1); + janet_arity(argc, 0, 2); + const char *str = (argc >= 1) ? (const char *) janet_getstring(argv, 0) : ""; + JanetBuffer *buf = (argc >= 2) ? janet_getbuffer(argv, 1) : janet_buffer(10); janet_line_get(str, buf); - return argv[0]; + return janet_wrap_buffer(buf); } static void simpleline(JanetBuffer *buffer) { @@ -55,8 +55,8 @@ void janet_line_deinit() { ; } -void janet_line_get(const uint8_t *p, JanetBuffer *buffer) { - fputs((const char *)p, stdout); +void janet_line_get(const char *p, JanetBuffer *buffer) { + fputs(p, stdout); simpleline(buffer); } @@ -444,8 +444,8 @@ static int checktermsupport() { return 1; } -void janet_line_get(const uint8_t *p, JanetBuffer *buffer) { - prompt = (const char *)p; +void janet_line_get(const char *p, JanetBuffer *buffer) { + prompt = p; buffer->count = 0; historyi = 0; if (!isatty(STDIN_FILENO) || !checktermsupport()) { diff --git a/src/mainclient/line.h b/src/mainclient/line.h index 74c9e9a1..51b134bb 100644 --- a/src/mainclient/line.h +++ b/src/mainclient/line.h @@ -28,7 +28,7 @@ void janet_line_init(); void janet_line_deinit(); -void janet_line_get(const uint8_t *p, JanetBuffer *buffer); +void janet_line_get(const char *p, JanetBuffer *buffer); Janet janet_line_getter(int32_t argc, Janet *argv); #endif From 0c950d0846471a205a82470a48057a5e4099b11a Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 31 Jan 2019 13:02:09 -0500 Subject: [PATCH 3/8] Fix emscripten build. --- src/webclient/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webclient/main.c b/src/webclient/main.c index 9510e1ab..651f8808 100644 --- a/src/webclient/main.c +++ b/src/webclient/main.c @@ -44,7 +44,7 @@ static int enter_loop(void) { Janet ret; JanetSignal status = janet_continue(repl_fiber, janet_wrap_nil(), &ret); if (status == JANET_SIGNAL_ERROR) { - janet_stacktrace(repl_fiber, "runtime", ret); + janet_stacktrace(repl_fiber, ret); janet_deinit(); repl_fiber = NULL; return 1; From 4bcf6565cdb9c8de0f956609da8a9998d6e2d140 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 31 Jan 2019 14:48:28 -0500 Subject: [PATCH 4/8] Add parser/insert and bump to 0.4.0 --- CHANGELOG.md | 1 + src/core/core.janet | 6 ++++-- src/core/parse.c | 40 +++++++++++++++++++++++++++++++++++++++ src/include/janet/janet.h | 2 +- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d58720a4..3f879249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## 0.4.0 - ?? +- Add parser/insert to modify parser state programmatically - Add debug/stacktrace for easy, pretty stacktraces - Remove the status-pp function - Update API to run-context to be much more sane diff --git a/src/core/core.janet b/src/core/core.janet index 1efafff2..b4a6bcd0 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -1393,12 +1393,14 @@ value, one key will be ignored." where " around byte " (string (parser/where p)) - (or (parser/error p) "unmatched delimiter"))) + ": " + (or (parser/error p) "unmatched delimiter") + "\n")) (defn bad-compile "Default handler for a compile error." [msg macrof where] - (file/write stderr msg " while compiling " where "\n") + (file/write stderr "compile error: " msg " while compiling " where "\n") (when macrof (debug/stacktrace macrof))) (defn getline diff --git a/src/core/parse.c b/src/core/parse.c index 1dbfab56..00cad587 100644 --- a/src/core/parse.c +++ b/src/core/parse.c @@ -649,6 +649,39 @@ static Janet cfun_parse_consume(int32_t argc, Janet *argv) { return janet_wrap_integer(i); } +static Janet cfun_parse_insert(int32_t argc, Janet *argv) { + janet_fixarity(argc, 2); + JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype); + JanetParseState *s = p->states + p->statecount - 1; + if (s->consumer == tokenchar) { + janet_parser_consume(p, ' '); + p->offset--; + s = p->states + p->statecount - 1; + } + if (s->flags & PFLAG_CONTAINER) { + s->argn++; + if (p->statecount == 1) p->pending++; + push_arg(p, argv[1]); + } else if (s->flags & (PFLAG_STRING | PFLAG_LONGSTRING)) { + const uint8_t *str = janet_to_string(argv[1]); + int32_t slen = janet_string_length(str); + size_t newcount = p->bufcount + slen; + if (p->bufcap > p->bufcount + slen) { + size_t newcap = 2 * newcount; + p->buf = realloc(p->buf, newcap); + if (p->buf == NULL) { + JANET_OUT_OF_MEMORY; + } + p->bufcap = newcap; + } + memcpy(p->buf + p->bufcount, str, slen); + p->bufcount = newcount; + } else { + janet_panic("cannot insert value into parser"); + } + return argv[0]; +} + static Janet cfun_parse_has_more(int32_t argc, Janet *argv) { janet_fixarity(argc, 1); JanetParser *p = janet_getabstract(argv, 0, &janet_parse_parsertype); @@ -807,6 +840,13 @@ static const JanetReg parse_cfuns[] = { "in the byte stream as a tuple (line, column). Lines and columns are counted from " "1, (the first byte is line 1, column 1) and a newline is considered ASCII 0x0A.") }, + { + "parser/insert", cfun_parse_insert, + JDOC("(parser/insert parser value)\n\n" + "Insert a value into the parser. This means that the parser state can be manipulated " + "in between chunks of bytes. This would allow a user to add extra elements to arrays " + "and tuples, for example. Returns the parser.") + }, {NULL, NULL, NULL} }; diff --git a/src/include/janet/janet.h b/src/include/janet/janet.h index de0d5ac5..f7785fcc 100644 --- a/src/include/janet/janet.h +++ b/src/include/janet/janet.h @@ -29,7 +29,7 @@ extern "C" { /***** START SECTION CONFIG *****/ -#define JANET_VERSION "0.3.0" +#define JANET_VERSION "0.4.0" #ifndef JANET_BUILD #define JANET_BUILD "local" From 367c9da8560924244d1b3d8c8689c86883fdc888 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 31 Jan 2019 22:38:59 -0500 Subject: [PATCH 5/8] Fix some typos and update style. Add bars.janet tool for templating arbitrary strings, especially HTML. --- src/core/strtod.c | 2 +- tools/amalg.janet | 4 ++-- tools/bars.janet | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tools/bars.janet diff --git a/src/core/strtod.c b/src/core/strtod.c index cc2c21d6..ee8b4b64 100644 --- a/src/core/strtod.c +++ b/src/core/strtod.c @@ -228,7 +228,7 @@ static double convert( bignat_lshift_n(mant, shamt); exponent2 -= shamt * BIGNAT_NBIT; for (;exponent < -3; exponent += 4) bignat_div(mant, base * base * base * base); - for (;exponent < -2; exponent += 2) bignat_div(mant, base * base); + for (;exponent < -1; exponent += 2) bignat_div(mant, base * base); for (;exponent < 0; exponent += 1) bignat_div(mant, base); } diff --git a/tools/amalg.janet b/tools/amalg.janet index 1a6270f9..7dcf3f5b 100644 --- a/tools/amalg.janet +++ b/tools/amalg.janet @@ -65,8 +65,8 @@ # as the version being generated (print "#define JANET_BUILD \"" janet/build "\"") -(print ```#define JANET_AMALG -#include "janet.h"```) +(print ```#define JANET_AMALG```) +(print ```#include "janet.h"```) (each h headers (dofile h)) (each s sources (dofile s)) diff --git a/tools/bars.janet b/tools/bars.janet new file mode 100644 index 00000000..c14eb40b --- /dev/null +++ b/tools/bars.janet @@ -0,0 +1,55 @@ +# A flexible templater for janet. Compiles +# templates to janet functions that produce buffers. + +(defn template + "Compile a template string into a function" + [source] + + # State for compilation machine + (def p (parser/new)) + (def forms @[]) + + (defn parse-chunk + "Parse a string and push produced values to forms." + [chunk] + (parser/consume p chunk) + (while (parser/has-more p) + (array/push forms (parser/produce p))) + (if (= :error (parser/status p)) + (error (parser/error p)))) + + (defn code-chunk + "Parse all the forms in str and return them + in a tuple prefixed with 'do." + [str] + (parse-chunk str) + true) + + (defn string-chunk + "Insert string chunk into parser" + [str] + (parser/insert p str) + (parse-chunk "") + true) + + # Run peg + (def grammar + ~{:code-chunk (* "{%" (drop (cmt '(any (if-not "%}" 1)) ,code-chunk)) "%}") + :main-chunk (drop (cmt '(any (if-not "{%" 1)) ,string-chunk)) + :main (any (+ :code-chunk :main-chunk (error "")))}) + (def parts (peg/match grammar source)) + + # Check errors in template and parser + (unless parts (error "invalid template syntax")) + (parse-chunk "\n") + (case (parser/status p) + :pending (error (string "unfinished parser state " (parser/state p))) + :error (error (parser/error p))) + + # Make ast from forms + (def ast ~(fn [params &] (default params @{}) (,buffer ;forms))) + + (def ctor (compile ast *env* source)) + (if-not (function? ctor) + (error (string "could not compile template"))) + (ctor)) From 19e59705b93a7de2472bf979b14a2adc13278774 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Thu, 31 Jan 2019 23:39:33 -0500 Subject: [PATCH 6/8] Main rule in peg is always 0 After we changed peg bytecode emission to preallocate space for an instruction before emitting sub rules, the rules are numbered in the order that they are compiled. This means that the main rule is always 0. We can remove the explicitly stored main rule in the peg structure. --- src/core/peg.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/peg.c b/src/core/peg.c index 3f713e19..8f464c72 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -990,7 +990,6 @@ static uint32_t compile1(Builder *b, Janet peg) { typedef struct { uint32_t *bytecode; Janet *constants; - uint32_t main_rule; uint32_t num_constants; } Peg; @@ -1009,7 +1008,7 @@ static JanetAbstractType peg_type = { }; /* Convert Builder to Peg (Janet Abstract Value) */ -static Peg *make_peg(Builder *b, uint32_t main_rule) { +static Peg *make_peg(Builder *b) { size_t bytecode_size = janet_v_count(b->bytecode) * sizeof(uint32_t); size_t constants_size = janet_v_count(b->constants) * sizeof(Janet); size_t total_size = bytecode_size + constants_size + sizeof(Peg); @@ -1018,7 +1017,6 @@ static Peg *make_peg(Builder *b, uint32_t main_rule) { peg->bytecode = (uint32_t *)(mem + sizeof(Peg)); peg->constants = (Janet *)(mem + sizeof(Peg) + bytecode_size); peg->num_constants = janet_v_count(b->constants); - peg->main_rule = main_rule; memcpy(peg->bytecode, b->bytecode, bytecode_size); memcpy(peg->constants, b->constants, constants_size); return peg; @@ -1035,8 +1033,8 @@ static Peg *compile_peg(Janet x) { builder.nexttag = 1; builder.form = x; builder.depth = JANET_RECURSION_GUARD; - uint32_t main_rule = compile1(&builder, x); - Peg *peg = make_peg(&builder, main_rule); + compile1(&builder, x); + Peg *peg = make_peg(&builder); builder_cleanup(&builder); return peg; } @@ -1082,7 +1080,7 @@ static Janet cfun_peg_match(int32_t argc, Janet *argv) { s.constants = peg->constants; s.bytecode = peg->bytecode; - const uint8_t *result = peg_rule(&s, s.bytecode + peg->main_rule, bytes.bytes + start); + const uint8_t *result = peg_rule(&s, s.bytecode, bytes.bytes + start); return result ? janet_wrap_array(s.captures) : janet_wrap_nil(); } From 8a3f5127466993b3368e10d0309641df0484b2b4 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 1 Feb 2019 11:56:25 -0500 Subject: [PATCH 7/8] Experimental changes to janet_call to make it faster. Remove setjmp and fiber creationg from janet_call. This adds the constraint to janet_call can only be called when there is already a current fiber. --- src/core/capi.c | 6 ++-- src/core/fiber.c | 1 + src/core/state.h | 5 +++ src/core/vm.c | 72 ++++++++++++++++++++++++--------------- src/include/janet/janet.h | 4 ++- 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/core/capi.c b/src/core/capi.c index 6c5d09f7..d1cfe78a 100644 --- a/src/core/capi.c +++ b/src/core/capi.c @@ -27,9 +27,9 @@ #endif void janet_panicv(Janet message) { - if (janet_vm_fiber != NULL) { - janet_fiber_push(janet_vm_fiber, message); - longjmp(janet_vm_fiber->buf, 1); + if (janet_vm_return_reg != NULL) { + *janet_vm_return_reg = message; + longjmp(*janet_vm_jmp_buf, 1); } else { fputs((const char *)janet_formatc("janet top level panic - %v\n", message), stdout); exit(1); diff --git a/src/core/fiber.c b/src/core/fiber.c index 7896e567..9be9ce92 100644 --- a/src/core/fiber.c +++ b/src/core/fiber.c @@ -66,6 +66,7 @@ JanetFiber *janet_fiber_reset(JanetFiber *fiber, JanetFunction *callee, int32_t fiber->stacktop = newstacktop; } if (janet_fiber_funcframe(fiber, callee)) return NULL; + janet_fiber_frame(fiber)->flags |= JANET_STACKFRAME_ENTRANCE; return fiber; } diff --git a/src/core/state.h b/src/core/state.h index 73086308..20693691 100644 --- a/src/core/state.h +++ b/src/core/state.h @@ -39,6 +39,11 @@ extern JANET_THREAD_LOCAL int janet_vm_stackn; * Set and unset by janet_run. */ extern JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber; +/* The current pointer to the inner most jmp_buf. The current + * return point for panics. */ +extern JANET_THREAD_LOCAL jmp_buf *janet_vm_jmp_buf; +extern JANET_THREAD_LOCAL Janet *janet_vm_return_reg; + /* The global registry for c functions. Used to store meta-data * along with otherwise bare c function pointers. */ extern JANET_THREAD_LOCAL JanetTable *janet_vm_registry; diff --git a/src/core/vm.c b/src/core/vm.c index 9857caff..42f70816 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -33,6 +33,8 @@ JANET_THREAD_LOCAL JanetTable *janet_vm_registry; JANET_THREAD_LOCAL int janet_vm_stackn = 0; JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber = NULL; +JANET_THREAD_LOCAL Janet *janet_vm_return_reg = NULL; +JANET_THREAD_LOCAL jmp_buf *janet_vm_jmp_buf = NULL; /* Virtual registers * @@ -148,7 +150,7 @@ static void *op_lookup[255] = { } while (0) #define vm_return(sig, val) do { \ vm_commit(); \ - janet_fiber_push(fiber, (val)); \ + janet_vm_return_reg[0] = (val); \ return (sig); \ } while (0) @@ -283,8 +285,9 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status) VM_OP(JOP_RETURN) { Janet retval = stack[D]; + int entrance_frame = janet_stack_frame(stack)->flags & JANET_STACKFRAME_ENTRANCE; janet_fiber_popframe(fiber); - if (fiber->frame == 0) vm_return(JANET_SIGNAL_OK, retval); + if (entrance_frame) vm_return(JANET_SIGNAL_OK, retval); vm_restore(); stack[A] = retval; vm_checkgc_pcnext(); @@ -293,8 +296,9 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status) VM_OP(JOP_RETURN_NIL) { Janet retval = janet_wrap_nil(); + int entrance_frame = janet_stack_frame(stack)->flags & JANET_STACKFRAME_ENTRANCE; janet_fiber_popframe(fiber); - if (fiber->frame == 0) vm_return(JANET_SIGNAL_OK, retval); + if (entrance_frame) vm_return(JANET_SIGNAL_OK, retval); vm_restore(); stack[A] = retval; vm_checkgc_pcnext(); @@ -581,7 +585,7 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status) janet_fiber_cframe(fiber, janet_unwrap_cfunction(callee)); Janet ret = janet_unwrap_cfunction(callee)(argc, fiber->data + fiber->frame); janet_fiber_popframe(fiber); - if (fiber->frame == 0) vm_return(JANET_SIGNAL_OK, ret); + /*if (fiber->frame == 0) vm_return(JANET_SIGNAL_OK, ret);*/ stack = fiber->data + fiber->frame; stack[A] = ret; vm_checkgc_pcnext(); @@ -614,6 +618,7 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status) vm_checkgc_next(); } else { Janet retreg; + int entrance_frame = janet_stack_frame(stack)->flags & JANET_STACKFRAME_ENTRANCE; vm_commit(); if (janet_checktype(callee, JANET_CFUNCTION)) { int32_t argc = fiber->stacktop - fiber->stackstart; @@ -624,7 +629,7 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status) retreg = call_nonfn(fiber, callee); } janet_fiber_popframe(fiber); - if (fiber->frame == 0) + if (entrance_frame) vm_return(JANET_SIGNAL_OK, retreg); vm_restore(); stack[A] = retreg; @@ -755,39 +760,45 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in, JanetFiberStatus status) } Janet janet_call(JanetFunction *fun, int32_t argc, const Janet *argv) { + Janet ret; + Janet *old_return_reg = janet_vm_return_reg; + + /* Check entry conditions */ + if (!janet_vm_fiber) + janet_panic("janet_call failed because there is no current fiber"); if (janet_vm_stackn >= JANET_RECURSION_GUARD) janet_panic("C stack recursed too deeply"); - JanetFiber *fiber = janet_fiber(fun, 64, argc, argv); - if (!fiber) - janet_panic("arity mismatch"); - JanetFiber *old_fiber = janet_vm_fiber; - janet_vm_fiber = fiber; - janet_gcroot(janet_wrap_fiber(fiber)); + + /* Push frame */ + janet_fiber_pushn(janet_vm_fiber, argv, argc); + if (janet_fiber_funcframe(janet_vm_fiber, fun)) { + janet_panicf("arity mismatch in %v", fun); + } + janet_fiber_frame(janet_vm_fiber)->flags |= JANET_STACKFRAME_ENTRANCE; + + /* Set up */ int32_t oldn = janet_vm_stackn++; int handle = janet_gclock(); + janet_vm_return_reg = &ret; - JanetSignal signal; - if (setjmp(fiber->buf)) { - signal = JANET_SIGNAL_ERROR; - } else { - signal = run_vm(fiber, janet_wrap_nil(), JANET_STATUS_NEW); - } + /* Run vm */ + JanetSignal signal = run_vm(janet_vm_fiber, + janet_wrap_nil(), + JANET_STATUS_ALIVE); + /* Teardown */ + janet_vm_return_reg = old_return_reg; janet_vm_stackn = oldn; - janet_vm_fiber = old_fiber; - Janet ret = fiber->data[fiber->stacktop - 1]; - janet_gcunroot(janet_wrap_fiber(fiber)); janet_gcunlock(handle); - if (signal == JANET_SIGNAL_ERROR) { - old_fiber->child = fiber; - janet_fiber_set_status(fiber, signal); - janet_panicv(ret); - } + + if (signal != JANET_SIGNAL_OK) janet_panicv(ret); + return ret; } /* Enter the main vm loop */ JanetSignal janet_continue(JanetFiber *fiber, Janet in, Janet *out) { + jmp_buf buf; /* Check conditions */ JanetFiberStatus old_status = janet_fiber_status(fiber); @@ -820,15 +831,19 @@ JanetSignal janet_continue(JanetFiber *fiber, Janet in, Janet *out) { int32_t oldn = janet_vm_stackn++; int handle = janet_vm_gc_suspend; JanetFiber *old_vm_fiber = janet_vm_fiber; + jmp_buf *old_vm_jmp_buf = janet_vm_jmp_buf; + Janet *old_vm_return_reg = janet_vm_return_reg; /* Setup fiber */ janet_vm_fiber = fiber; janet_gcroot(janet_wrap_fiber(fiber)); janet_fiber_set_status(fiber, JANET_STATUS_ALIVE); + janet_vm_return_reg = out; + janet_vm_jmp_buf = &buf; /* Run loop */ JanetSignal signal; - if (setjmp(fiber->buf)) { + if (setjmp(buf)) { signal = JANET_SIGNAL_ERROR; } else { signal = run_vm(fiber, in, old_status); @@ -839,12 +854,13 @@ JanetSignal janet_continue(JanetFiber *fiber, Janet in, Janet *out) { janet_gcunroot(janet_wrap_fiber(fiber)); /* Restore global state */ - janet_vm_gc_suspend = handle; + janet_vm_gc_suspend = handle; janet_vm_fiber = old_vm_fiber; janet_vm_stackn = oldn; + janet_vm_return_reg = old_vm_return_reg; + janet_vm_jmp_buf = old_vm_jmp_buf; /* Pop error or return value from fiber stack */ - *out = fiber->data[--fiber->stacktop]; return signal; } diff --git a/src/include/janet/janet.h b/src/include/janet/janet.h index f7785fcc..1ce7f323 100644 --- a/src/include/janet/janet.h +++ b/src/include/janet/janet.h @@ -603,12 +603,14 @@ struct JanetFiber { int32_t capacity; int32_t maxstack; /* Arbitrary defined limit for stack overflow */ int32_t flags; /* Various flags */ - jmp_buf buf; /* Handle errors */ }; /* Mark if a stack frame is a tail call for debugging */ #define JANET_STACKFRAME_TAILCALL 1 +/* Mark if a stack frame is an entrance frame */ +#define JANET_STACKFRAME_ENTRANCE 2 + /* A stack frame on the fiber. Is stored along with the stack values. */ struct JanetStackFrame { JanetFunction *func; From 09d9dca5f5ec2e6f36bdd7cbb0f014a3121426da Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 1 Feb 2019 13:43:16 -0500 Subject: [PATCH 8/8] Add Gitter channel to README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da95e482..e2465db1 100644 --- a/README.md +++ b/README.md @@ -175,9 +175,10 @@ Building with emscripten on windows is currently unsupported. See the examples directory for some example janet code. -## IRC +## Discussion -Feel free to ask questions and join discussion on [the #janet channel on Freenode](https://webchat.freenode.net/) +Feel free to ask questions and join discussion on the [Janet Gitter Channel](https://gitter.im/janet-language/community). +Alternatively, check out [the #janet channel on Freenode](https://webchat.freenode.net/) ## Why Janet