5 #include "interpreter.h"
8 #include "repl_runtime.h"
10 #define REPL_BUFFER_MAX 1024
12 static void eval_line(Gc *gc, Scope *scope, const char *line)
14 /* TODO(#465): eval_line could be implemented with read_all_exprs_from_string */
16 gc_collect(gc, scope->expr);
18 struct ParseResult parse_result = read_expr_from_string(gc, line);
19 if (parse_result.is_error) {
20 print_parse_error(stderr, line, parse_result);
24 struct EvalResult eval_result = eval(gc, scope, parse_result.expr);
25 if (eval_result.is_error) {
26 fprintf(stderr, "Error:\t");
27 print_expr_as_sexpr(stderr, eval_result.expr);
28 fprintf(stderr, "\n");
32 print_expr_as_sexpr(stderr, eval_result.expr);
33 fprintf(stdout, "\n");
35 line = next_token(parse_result.end).begin;
39 int main(int argc, char *argv[])
44 char buffer[REPL_BUFFER_MAX + 1];
47 struct Scope scope = {
48 .expr = CONS(gc, NIL(gc), NIL(gc))
51 load_repl_runtime(gc, &scope);
56 if (fgets(buffer, REPL_BUFFER_MAX, stdin) == NULL) {
60 eval_line(gc, &scope, buffer);