diff --git a/core/gc.c b/core/gc.c index 3d71d430..890bbf2c 100644 --- a/core/gc.c +++ b/core/gc.c @@ -145,8 +145,8 @@ void gst_mark(Gst *vm, GstValueUnion x, GstType type) { gc_header(thread->data)->color = vm->black; while (frame <= end) frame = gst_mark_stackframe(vm, frame); - if (x.thread->parent) - gst_mark_value(vm, gst_wrap_thread(x.thread->parent)); + if (thread->parent) + gst_mark_value(vm, gst_wrap_thread(thread->parent)); } break; diff --git a/core/parse.c b/core/parse.c index 6ed40d03..ef4c5990 100644 --- a/core/parse.c +++ b/core/parse.c @@ -62,7 +62,7 @@ static GstParseState *parser_peek(GstParser *p) { if (!p->count) { return NULL; } - return p->data + p->count - 1; + return p->data + (p->count - 1); } /* Remove the top state from the ParseStack */ @@ -88,8 +88,9 @@ static GstValue quote(GstParser *p, GstValue x) { static void parser_push(GstParser *p, ParseType type, uint8_t character) { GstParseState *top; if (p->count >= p->cap) { - uint32_t newCap = 2 * p->count; - GstParseState *data = gst_alloc(p->vm, newCap); + uint32_t newCap = 2 * p->count + 2; + GstParseState *data = gst_alloc(p->vm, newCap * sizeof(GstParseState)); + gst_memcpy(data, p->data, p->cap * sizeof(GstParseState)); p->data = data; p->cap = newCap; } diff --git a/core/thread.c b/core/thread.c index ada5f96d..ee572c0b 100644 --- a/core/thread.c +++ b/core/thread.c @@ -32,7 +32,6 @@ GstThread *gst_thread(Gst *vm, GstValue callee, uint32_t capacity) { thread->count = GST_FRAME_SIZE; thread->data = data; thread->status = GST_THREAD_PENDING; - thread->retindex = 0; stack = data + GST_FRAME_SIZE; gst_frame_size(stack) = 0; gst_frame_prevsize(stack) = 0; diff --git a/core/vm.c b/core/vm.c index eba8c37b..81ffd4f3 100644 --- a/core/vm.c +++ b/core/vm.c @@ -398,6 +398,7 @@ int gst_continue(Gst *vm) { } } stack = vm->thread->data + vm->thread->count; + stack[gst_frame_ret(stack)] = vm->ret; pc = gst_frame_pc(stack); continue; diff --git a/include/gst/gst.h b/include/gst/gst.h index 9fbdea14..93c77df8 100644 --- a/include/gst/gst.h +++ b/include/gst/gst.h @@ -204,7 +204,6 @@ struct GstValue { struct GstThread { uint32_t count; uint32_t capacity; - uint32_t retindex; GstValue *data; GstThread *parent; enum { diff --git a/libs/repl.gst b/libs/repl.gst index 16a1748a..229107ac 100644 --- a/libs/repl.gst +++ b/libs/repl.gst @@ -1,8 +1,5 @@ (namespace-set! "gst.repl") -"Hold all compile time evaluators" -(export! "evaluators" {}) - "Read a line" (export! "readline" (fn [] (: b (buffer)) @@ -16,14 +13,15 @@ "Create a parser" (export! "p" (parser)) -"Run a simple repl. Does not handle errors and other -such details." +"Run a simple repl." (while 1 - (: t (thread (fn [] - (write stdout ">> ") - (: line (readline)) + (write stdout ">> ") + (: t (thread (fn [line] + (: ret 1) (while line (: line (parse-charseq p line)) (if (parse-hasvalue p) - ((compile (parse-consume p)))))))) - (transfer t)) + (: ret ((compile (parse-consume p)))))) + ret))) + (: res (tran t (readline))) + (if (= (status t) "dead") (print res) (print "Error: " res)))