return eval_success(NIL(gc));
}
-char buffer[REPL_BUFFER_MAX + 1];
-
-int main(int argc, char *argv[])
+static void eval_line(Gc *gc, Scope *scope, const char *line)
{
- (void) argc;
- (void) argv;
-
- Gc *gc = create_gc();
- struct Scope scope = {
- .expr = CONS(gc, NIL(gc), NIL(gc))
- };
-
- set_scope_value(gc, &scope, SYMBOL(gc, "quit"), NATIVE(gc, quit, NULL));
-
- while (true) {
- printf("> ");
-
- if (fgets(buffer, REPL_BUFFER_MAX, stdin) == NULL) {
- return -1;
- }
-
+ const char *read_iter = line;
+ while (read_iter != NULL) {
printf("Before parse:\t");
gc_inspect(gc);
- struct ParseResult parse_result = read_expr_from_string(gc, buffer);
+ struct ParseResult parse_result = read_expr_from_string(gc, read_iter);
if (parse_result.is_error) {
- print_parse_error(stderr, buffer, parse_result);
- continue;
+ print_parse_error(stderr, line, parse_result);
+ return;
}
printf("After parse:\t");
gc_inspect(gc);
- struct EvalResult eval_result = eval(gc, &scope, parse_result.expr);
+ struct EvalResult eval_result = eval(gc, scope, parse_result.expr);
printf("After eval:\t");
gc_inspect(gc);
- gc_collect(gc, CONS(gc, scope.expr, eval_result.expr));
+ gc_collect(gc, CONS(gc, scope->expr, eval_result.expr));
printf("After collect:\t");
gc_inspect(gc);
printf("Scope:\t");
- print_expr_as_sexpr(scope.expr);
+ print_expr_as_sexpr(scope->expr);
printf("\n");
if (eval_result.is_error) {
print_expr_as_sexpr(eval_result.expr);
printf("\n");
+
+ if (*next_token(parse_result.end).begin == 0) {
+ return;
+ }
+ read_iter = parse_result.end;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ (void) argc;
+ (void) argv;
+
+ char buffer[REPL_BUFFER_MAX + 1];
+
+ Gc *gc = create_gc();
+ struct Scope scope = {
+ .expr = CONS(gc, NIL(gc), NIL(gc))
+ };
+
+ set_scope_value(gc, &scope, SYMBOL(gc, "quit"), NATIVE(gc, quit, NULL));
+
+ while (true) {
+ printf("> ");
+
+ if (fgets(buffer, REPL_BUFFER_MAX, stdin) == NULL) {
+ return -1;
+ }
+
+ eval_line(gc, &scope, buffer);
}
destroy_gc(gc);