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

More work on dogfood repl.

This commit is contained in:
Calvin Rose 2017-05-09 20:06:53 -04:00
parent fd72219a2a
commit b7083f6f18
6 changed files with 15 additions and 17 deletions

View File

@ -145,8 +145,8 @@ void gst_mark(Gst *vm, GstValueUnion x, GstType type) {
gc_header(thread->data)->color = vm->black; gc_header(thread->data)->color = vm->black;
while (frame <= end) while (frame <= end)
frame = gst_mark_stackframe(vm, frame); frame = gst_mark_stackframe(vm, frame);
if (x.thread->parent) if (thread->parent)
gst_mark_value(vm, gst_wrap_thread(x.thread->parent)); gst_mark_value(vm, gst_wrap_thread(thread->parent));
} }
break; break;

View File

@ -62,7 +62,7 @@ static GstParseState *parser_peek(GstParser *p) {
if (!p->count) { if (!p->count) {
return NULL; return NULL;
} }
return p->data + p->count - 1; return p->data + (p->count - 1);
} }
/* Remove the top state from the ParseStack */ /* 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) { static void parser_push(GstParser *p, ParseType type, uint8_t character) {
GstParseState *top; GstParseState *top;
if (p->count >= p->cap) { if (p->count >= p->cap) {
uint32_t newCap = 2 * p->count; uint32_t newCap = 2 * p->count + 2;
GstParseState *data = gst_alloc(p->vm, newCap); GstParseState *data = gst_alloc(p->vm, newCap * sizeof(GstParseState));
gst_memcpy(data, p->data, p->cap * sizeof(GstParseState));
p->data = data; p->data = data;
p->cap = newCap; p->cap = newCap;
} }

View File

@ -32,7 +32,6 @@ GstThread *gst_thread(Gst *vm, GstValue callee, uint32_t capacity) {
thread->count = GST_FRAME_SIZE; thread->count = GST_FRAME_SIZE;
thread->data = data; thread->data = data;
thread->status = GST_THREAD_PENDING; thread->status = GST_THREAD_PENDING;
thread->retindex = 0;
stack = data + GST_FRAME_SIZE; stack = data + GST_FRAME_SIZE;
gst_frame_size(stack) = 0; gst_frame_size(stack) = 0;
gst_frame_prevsize(stack) = 0; gst_frame_prevsize(stack) = 0;

View File

@ -398,6 +398,7 @@ int gst_continue(Gst *vm) {
} }
} }
stack = vm->thread->data + vm->thread->count; stack = vm->thread->data + vm->thread->count;
stack[gst_frame_ret(stack)] = vm->ret;
pc = gst_frame_pc(stack); pc = gst_frame_pc(stack);
continue; continue;

View File

@ -204,7 +204,6 @@ struct GstValue {
struct GstThread { struct GstThread {
uint32_t count; uint32_t count;
uint32_t capacity; uint32_t capacity;
uint32_t retindex;
GstValue *data; GstValue *data;
GstThread *parent; GstThread *parent;
enum { enum {

View File

@ -1,8 +1,5 @@
(namespace-set! "gst.repl") (namespace-set! "gst.repl")
"Hold all compile time evaluators"
(export! "evaluators" {})
"Read a line" "Read a line"
(export! "readline" (fn [] (export! "readline" (fn []
(: b (buffer)) (: b (buffer))
@ -16,14 +13,15 @@
"Create a parser" "Create a parser"
(export! "p" (parser)) (export! "p" (parser))
"Run a simple repl. Does not handle errors and other "Run a simple repl."
such details."
(while 1 (while 1
(: t (thread (fn []
(write stdout ">> ") (write stdout ">> ")
(: line (readline)) (: t (thread (fn [line]
(: ret 1)
(while line (while line
(: line (parse-charseq p line)) (: line (parse-charseq p line))
(if (parse-hasvalue p) (if (parse-hasvalue p)
((compile (parse-consume p)))))))) (: ret ((compile (parse-consume p))))))
(transfer t)) ret)))
(: res (tran t (readline)))
(if (= (status t) "dead") (print res) (print "Error: " res)))