5 #include "interpreter.h"
9 #define REPL_BUFFER_MAX 1024
11 static struct EvalResult quit(void *param, Gc *gc, struct Scope *scope, struct Expr args)
19 return eval_success(NIL(gc));
22 static void eval_line(Gc *gc, Scope *scope, const char *line)
24 const char *read_iter = line;
25 while (*read_iter != 0) {
26 printf("Before parse:\t");
29 struct ParseResult parse_result = read_expr_from_string(gc, read_iter);
30 if (parse_result.is_error) {
31 print_parse_error(stderr, line, parse_result);
34 printf("After parse:\t");
37 struct EvalResult eval_result = eval(gc, scope, parse_result.expr);
38 printf("After eval:\t");
41 gc_collect(gc, CONS(gc, scope->expr, eval_result.expr));
42 printf("After collect:\t");
46 print_expr_as_sexpr(scope->expr);
49 if (eval_result.is_error) {
53 print_expr_as_sexpr(eval_result.expr);
56 read_iter = next_token(parse_result.end).begin;
60 int main(int argc, char *argv[])
65 char buffer[REPL_BUFFER_MAX + 1];
68 struct Scope scope = {
69 .expr = CONS(gc, NIL(gc), NIL(gc))
72 set_scope_value(gc, &scope, SYMBOL(gc, "quit"), NATIVE(gc, quit, NULL));
77 if (fgets(buffer, REPL_BUFFER_MAX, stdin) == NULL) {
81 eval_line(gc, &scope, buffer);