]> git.lizzy.rs Git - nothing.git/blobdiff - src/ebisp/repl.c
ebisp/std: Validate arglist to defun in the same way as for lambda
[nothing.git] / src / ebisp / repl.c
index c542c155955109d5b974a08191c8b5652891cefe..2be4b1a47feb11f028238a2e3ea9beb5af411b1f 100644 (file)
@@ -1,47 +1,15 @@
-#include <assert.h>
+#include "system/stacktrace.h"
 #include <stdbool.h>
 
-#include "parser.h"
+#include "gc.h"
 #include "interpreter.h"
+#include "parser.h"
+#include "repl_runtime.h"
 #include "scope.h"
-#include "gc.h"
+#include "std.h"
 
 #define REPL_BUFFER_MAX 1024
 
-static struct EvalResult gc_inspect_adapter(void *param, Gc *gc, struct Scope *scope, struct Expr args)
-{
-    assert(gc);
-    assert(scope);
-    (void) param;
-    (void) args;
-
-    gc_inspect(gc);
-
-    return eval_success(NIL(gc));
-}
-
-static struct EvalResult quit(void *param, Gc *gc, struct Scope *scope, struct Expr args)
-{
-    assert(gc);
-    assert(scope);
-    (void) args;
-    (void) param;
-
-    exit(0);
-
-    return eval_success(NIL(gc));
-}
-
-static struct EvalResult get_scope(void *param, Gc *gc, struct Scope *scope, struct Expr args)
-{
-    assert(gc);
-    assert(scope);
-    (void) param;
-    (void) args;
-
-    return eval_success(scope->expr);
-}
-
 static void eval_line(Gc *gc, Scope *scope, const char *line)
 {
     /* TODO(#465): eval_line could be implemented with read_all_exprs_from_string */
@@ -77,13 +45,10 @@ int main(int argc, char *argv[])
     char buffer[REPL_BUFFER_MAX + 1];
 
     Gc *gc = create_gc();
-    struct Scope scope = {
-        .expr = CONS(gc, NIL(gc), NIL(gc))
-    };
+    struct Scope scope = create_scope(gc);
 
-    set_scope_value(gc, &scope, SYMBOL(gc, "quit"), NATIVE(gc, quit, NULL));
-    set_scope_value(gc, &scope, SYMBOL(gc, "gc-inspect"), NATIVE(gc, gc_inspect_adapter, NULL));
-    set_scope_value(gc, &scope, SYMBOL(gc, "scope"), NATIVE(gc, get_scope, NULL));
+    load_std_library(gc, &scope);
+    load_repl_runtime(gc, &scope);
 
     while (true) {
         printf("> ");