mirror of
https://github.com/janet-lang/janet
synced 2025-07-05 19:42:55 +00:00
Making some changes.
This commit is contained in:
parent
8c20b7229a
commit
57886db410
6
Makefile
6
Makefile
@ -15,6 +15,10 @@ GST_CORELIB=core/libgst.a
|
|||||||
GST_INTERNAL_HEADERS=$(addprefix core/, cache.h)
|
GST_INTERNAL_HEADERS=$(addprefix core/, cache.h)
|
||||||
GST_HEADERS=$(addprefix include/gst/, gst.h)
|
GST_HEADERS=$(addprefix include/gst/, gst.h)
|
||||||
|
|
||||||
|
# Use gdb. On mac use lldb
|
||||||
|
DEBUGGER=lldb
|
||||||
|
CC=clang
|
||||||
|
|
||||||
all: $(GST_TARGET)
|
all: $(GST_TARGET)
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
@ -42,7 +46,7 @@ run: $(GST_TARGET)
|
|||||||
@ ./$(GST_TARGET)
|
@ ./$(GST_TARGET)
|
||||||
|
|
||||||
debug: $(GST_TARGET)
|
debug: $(GST_TARGET)
|
||||||
@ gdb ./$(GST_TARGET)
|
@ $(DEBUGGER) ./$(GST_TARGET)
|
||||||
|
|
||||||
valgrind: $(GST_TARGET)
|
valgrind: $(GST_TARGET)
|
||||||
@ valgrind --leak-check=full -v ./$(GST_TARGET)
|
@ valgrind --leak-check=full -v ./$(GST_TARGET)
|
||||||
|
10
core/ds.c
10
core/ds.c
@ -278,6 +278,16 @@ void gst_table_put(Gst *vm, GstTable *t, GstValue key, GstValue value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clear a table */
|
||||||
|
void gst_table_clear(GstTable *t) {
|
||||||
|
uint32_t capacity = t->capacity;
|
||||||
|
uint32_t i;
|
||||||
|
GstValue *data = t->data;
|
||||||
|
for (i = 0; i < capacity; i += 2)
|
||||||
|
data[i].type = GST_NIL;
|
||||||
|
t->count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Find next key in an object. Returns nil if no next key. */
|
/* Find next key in an object. Returns nil if no next key. */
|
||||||
GstValue gst_table_next(GstTable *t, GstValue key) {
|
GstValue gst_table_next(GstTable *t, GstValue key) {
|
||||||
const GstValue *bucket, *end;
|
const GstValue *bucket, *end;
|
||||||
|
21
core/stl.c
21
core/stl.c
@ -168,6 +168,25 @@ int gst_stl_not(Gst *vm) {
|
|||||||
/* Core */
|
/* Core */
|
||||||
/****/
|
/****/
|
||||||
|
|
||||||
|
/* Empty a mutable datastructure */
|
||||||
|
int gst_stl_clear(Gst *vm) {
|
||||||
|
GstValue x = gst_arg(vm, 0);
|
||||||
|
switch (x.type) {
|
||||||
|
default:
|
||||||
|
gst_c_throwc(vm, "cannot get length");
|
||||||
|
case GST_ARRAY:
|
||||||
|
x.data.array->count = 0;
|
||||||
|
break;
|
||||||
|
case GST_BYTEBUFFER:
|
||||||
|
x.data.buffer->count = 0;
|
||||||
|
break;
|
||||||
|
case GST_TABLE:
|
||||||
|
gst_table_clear(x.data.table);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
gst_c_return(vm, x);
|
||||||
|
}
|
||||||
|
|
||||||
/* Get length of object */
|
/* Get length of object */
|
||||||
int gst_stl_length(Gst *vm) {
|
int gst_stl_length(Gst *vm) {
|
||||||
uint32_t count = gst_count_args(vm);
|
uint32_t count = gst_count_args(vm);
|
||||||
@ -1037,12 +1056,12 @@ static const GstModuleItem std_module[] = {
|
|||||||
{"parse-hasvalue", gst_stl_parser_hasvalue},
|
{"parse-hasvalue", gst_stl_parser_hasvalue},
|
||||||
{"parse-charseq", gst_stl_parser_charseq},
|
{"parse-charseq", gst_stl_parser_charseq},
|
||||||
{"parse-status", gst_stl_parser_status},
|
{"parse-status", gst_stl_parser_status},
|
||||||
{"parse-status", gst_stl_parser_status},
|
|
||||||
{"parse", gst_stl_parse},
|
{"parse", gst_stl_parse},
|
||||||
/* Compile */
|
/* Compile */
|
||||||
{"compile", gst_stl_compile},
|
{"compile", gst_stl_compile},
|
||||||
/* Other */
|
/* Other */
|
||||||
{"not", gst_stl_not},
|
{"not", gst_stl_not},
|
||||||
|
{"clear", gst_stl_clear},
|
||||||
{"length", gst_stl_length},
|
{"length", gst_stl_length},
|
||||||
{"hash", gst_stl_hash},
|
{"hash", gst_stl_hash},
|
||||||
{"integer", gst_stl_to_int},
|
{"integer", gst_stl_to_int},
|
||||||
|
@ -138,15 +138,14 @@ void gst_thread_endframe(Gst *vm, GstThread *thread) {
|
|||||||
GstValue callee = gst_frame_callee(stack);
|
GstValue callee = gst_frame_callee(stack);
|
||||||
if (callee.type == GST_FUNCTION) {
|
if (callee.type == GST_FUNCTION) {
|
||||||
GstFunction *fn = callee.data.function;
|
GstFunction *fn = callee.data.function;
|
||||||
|
uint32_t locals = fn->def->locals;
|
||||||
gst_frame_pc(stack) = fn->def->byteCode;
|
gst_frame_pc(stack) = fn->def->byteCode;
|
||||||
if (fn->def->flags & GST_FUNCDEF_FLAG_VARARG) {
|
if (fn->def->flags & GST_FUNCDEF_FLAG_VARARG) {
|
||||||
uint32_t arity = fn->def->arity;
|
uint32_t arity = fn->def->arity;
|
||||||
gst_thread_tuplepack(vm, thread, arity);
|
gst_thread_tuplepack(vm, thread, arity);
|
||||||
} else {
|
}
|
||||||
uint32_t locals = fn->def->locals;
|
if (gst_frame_size(stack) < locals) {
|
||||||
if (gst_frame_size(stack) < locals) {
|
gst_thread_pushnil(vm, thread, locals - gst_frame_size(stack));
|
||||||
gst_thread_pushnil(vm, thread, locals - gst_frame_size(stack));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -472,6 +472,7 @@ GstTable *gst_table(Gst *vm, uint32_t capacity);
|
|||||||
GstValue gst_table_get(GstTable *t, GstValue key);
|
GstValue gst_table_get(GstTable *t, GstValue key);
|
||||||
GstValue gst_table_remove(GstTable *t, GstValue key);
|
GstValue gst_table_remove(GstTable *t, GstValue key);
|
||||||
void gst_table_put(Gst *vm, GstTable *t, GstValue key, GstValue value);
|
void gst_table_put(Gst *vm, GstTable *t, GstValue key, GstValue value);
|
||||||
|
void gst_table_clear(GstTable *t);
|
||||||
GstValue gst_table_next(GstTable *o, GstValue key);
|
GstValue gst_table_next(GstTable *o, GstValue key);
|
||||||
|
|
||||||
/****/
|
/****/
|
||||||
|
26
libs/repl.gst
Normal file
26
libs/repl.gst
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
(var *sourcefile* stdin)
|
||||||
|
|
||||||
|
(var *compile* (fn [x]
|
||||||
|
(def ret (compile x))
|
||||||
|
(if (= :function (type ret))
|
||||||
|
ret
|
||||||
|
(error (string "compile error: " ret)))))
|
||||||
|
|
||||||
|
(var *read* (fn []
|
||||||
|
(def b (buffer))
|
||||||
|
(def p (parser))
|
||||||
|
(while (not (parse-hasvalue p))
|
||||||
|
(read *sourcefile* 1 b)
|
||||||
|
(if (= (length b) 0)
|
||||||
|
(error "unexpected end of source"))
|
||||||
|
(parse-charseq p b)
|
||||||
|
(clear b))
|
||||||
|
(parse-consume p)))
|
||||||
|
|
||||||
|
(def eval (fn [x]
|
||||||
|
(apply (*compile* x) 123)))
|
||||||
|
|
||||||
|
(def t (thread (fn []
|
||||||
|
(while true
|
||||||
|
(eval (*read*))))))
|
||||||
|
(print (tran t))
|
Loading…
x
Reference in New Issue
Block a user