1 #include "system/stacktrace.h"
5 #include "interpreter.h"
7 #include "repl_runtime.h"
11 #define REPL_BUFFER_MAX 1024
13 static void eval_line(Gc *gc, Scope *scope, const char *line)
15 /* TODO(#465): eval_line could be implemented with read_all_exprs_from_string */
17 gc_collect(gc, scope->expr);
19 struct ParseResult parse_result = read_expr_from_string(gc, line);
20 if (parse_result.is_error) {
21 print_parse_error(stderr, line, parse_result);
25 struct EvalResult eval_result = eval(gc, scope, parse_result.expr);
26 if (eval_result.is_error) {
27 fprintf(stderr, "Error:\t");
28 print_expr_as_sexpr(stderr, eval_result.expr);
29 fprintf(stderr, "\n");
33 print_expr_as_sexpr(stderr, eval_result.expr);
34 fprintf(stdout, "\n");
36 line = next_token(parse_result.end).begin;
40 int main(int argc, char *argv[])
45 char buffer[REPL_BUFFER_MAX + 1];
48 struct Scope scope = create_scope(gc);
50 load_std_library(gc, &scope);
51 load_repl_runtime(gc, &scope);
56 if (fgets(buffer, REPL_BUFFER_MAX, stdin) == NULL) {
60 eval_line(gc, &scope, buffer);