X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Febisp%2Frepl.c;h=2be4b1a47feb11f028238a2e3ea9beb5af411b1f;hb=2e0ea7aa0c7bbd55d0f66597b4a363ad67a57e36;hp=c542c155955109d5b974a08191c8b5652891cefe;hpb=da98335867793400878f9d4a88ef5142a1dd6660;p=nothing.git diff --git a/src/ebisp/repl.c b/src/ebisp/repl.c index c542c155..2be4b1a4 100644 --- a/src/ebisp/repl.c +++ b/src/ebisp/repl.c @@ -1,47 +1,15 @@ -#include +#include "system/stacktrace.h" #include -#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("> ");