Debug GC crashes, add (gc-stats), add support for libedit to lisp
diff --git a/src/lisp/lib/std.c b/src/lisp/lib/std.c
index 224c086..1afe993 100644
--- a/src/lisp/lib/std.c
+++ b/src/lisp/lib/std.c
@@ -1,4 +1,5 @@
#include "std.h"
+#include "../gc.h"
#include "../plat/plat.h"
#include <stdlib.h>
#include <string.h>
@@ -98,7 +99,6 @@
value_t l_read_stdin()
{
-#ifndef NO_READLINE
char *string = read_input_line("lisp> ");
if (!string)
return nil;
@@ -122,9 +122,6 @@
free(string);
return val;
-#else
- return nil;
-#endif
}
value_t l_num_eq(value_t a, value_t b)
@@ -194,6 +191,15 @@
return first;
}
+value_t l_gc_stats()
+{
+ struct gc_stats stats = gc_get_stats();
+
+ return cons(intval(stats.total_allocs),
+ cons(intval(stats.gc_runs),
+ nil));
+}
+
#define LISP_PREDICATE(name) value_t l_##name(value_t v) { return name(v) ? t : nil; }
LISP_PREDICATE(listp)
@@ -235,6 +241,8 @@
add_c_function(env, "elt", l_elt, 2);
+ add_c_function(env, "gc-stats", l_gc_stats, 0);
+
if (!load_library(env, "std"))
{
fprintf(stderr, "Not found std\n");