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(#466): 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 struct ParseResult parse_result =
56 read_all_exprs_from_string(
59 if (parse_result.is_error) {
60 fprintf(stderr, "Parsing error: %s\n", parse_result.error_message);
64 struct EvalResult eval_result = eval(
68 SYMBOL(script->gc, "begin"),
70 if (eval_result.is_error) {
71 print_expr_as_sexpr(stderr, eval_result.expr);
72 fprintf(stderr, "\n");
76 gc_collect(script->gc, script->scope.expr);
78 free(RELEASE_LT(lt, source_code));
83 void destroy_script(Script *script)
86 RETURN_LT0(script->lt);
89 int script_eval(Script *script, const char *source_code)
93 /* TODO: script_eval is not implemented */