]> git.lizzy.rs Git - nothing.git/blob - src/ebisp/repl_runtime.c
Add TODO(#928)
[nothing.git] / src / ebisp / repl_runtime.c
1 #include "system/stacktrace.h"
2
3 #include "scope.h"
4 #include "interpreter.h"
5 #include "gc.h"
6 #include "expr.h"
7 #include "repl_runtime.h"
8
9 static struct EvalResult gc_inspect_adapter(void *param, Gc *gc, struct Scope *scope, struct Expr args)
10 {
11     trace_assert(gc);
12     trace_assert(scope);
13     (void) param;
14     (void) args;
15
16     gc_inspect(gc);
17
18     return eval_success(NIL(gc));
19 }
20
21 static struct EvalResult quit(void *param, Gc *gc, struct Scope *scope, struct Expr args)
22 {
23     trace_assert(gc);
24     trace_assert(scope);
25     (void) args;
26     (void) param;
27
28     exit(0);
29
30     return eval_success(NIL(gc));
31 }
32
33 static struct EvalResult get_scope(void *param, Gc *gc, struct Scope *scope, struct Expr args)
34 {
35     trace_assert(gc);
36     trace_assert(scope);
37     (void) param;
38     (void) args;
39
40     return eval_success(scope->expr);
41 }
42
43 static struct EvalResult print(void *param, Gc *gc, struct Scope *scope, struct Expr args)
44 {
45     trace_assert(gc);
46     trace_assert(scope);
47     (void) param;
48
49     const char *s = NULL;
50     struct EvalResult result = match_list(gc, "s", args, &s);
51     if (result.is_error) {
52         return result;
53     }
54
55     printf("%s\n", s);
56
57     return eval_success(NIL(gc));
58 }
59
60 void load_repl_runtime(Gc *gc, struct Scope *scope)
61 {
62     set_scope_value(gc, scope, SYMBOL(gc, "quit"), NATIVE(gc, quit, NULL));
63     set_scope_value(gc, scope, SYMBOL(gc, "gc-inspect"), NATIVE(gc, gc_inspect_adapter, NULL));
64     set_scope_value(gc, scope, SYMBOL(gc, "scope"), NATIVE(gc, get_scope, NULL));
65     set_scope_value(gc, scope, SYMBOL(gc, "print"), NATIVE(gc, print, NULL));
66 }