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;
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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

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

View File

@ -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)))