4 #include "ebisp/interpreter.h"
5 #include "ebisp/parser.h"
6 #include "ebisp/scope.h"
9 #include "system/error.h"
10 #include "system/line_stream.h"
11 #include "system/lt.h"
20 Script *create_script_from_line_stream(LineStream *line_stream)
29 Script *script = PUSH_LT(lt, malloc(sizeof(Script)), free);
31 throw_error(ERROR_TYPE_LIBC);
36 script->gc = PUSH_LT(lt, create_gc(), destroy_gc);
37 if (script->gc == NULL) {
41 script->scope = create_scope(script->gc);
44 sscanf(line_stream_next(line_stream), "%lu", &n);
46 char *source_code = NULL;
47 for (size_t i = 0; i < n; ++i) {
48 /* TODO: maybe source_code should be constantly replaced in the Lt */
49 source_code = string_append(
51 line_stream_next(line_stream));
53 PUSH_LT(lt, source_code, free);
55 printf("Source code: %s", source_code);
57 struct ParseResult parse_result =
58 read_all_exprs_from_string(
61 if (parse_result.is_error) {
62 fprintf(stderr, "Parsing error: %s\n", parse_result.error_message);
66 struct EvalResult eval_result = eval(
70 SYMBOL(script->gc, "begin"),
72 if (eval_result.is_error) {
73 print_expr_as_sexpr(stderr, eval_result.expr);
74 fprintf(stderr, "\n");
78 free(RELEASE_LT(lt, source_code));
80 print_expr_as_sexpr(stdout, script->scope.expr);
85 void destroy_script(Script *script)
88 RETURN_LT0(script->lt);