-#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: eval_line could've been implemented with read_all_exprs_from_string */
+ /* TODO(#465): eval_line could be implemented with read_all_exprs_from_string */
while (*line != 0) {
gc_collect(gc, scope->expr);
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("> ");