diff options
-rwxr-xr-x | src/bootstrap/main.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/bootstrap/main.c b/src/bootstrap/main.c index 7323629..e6155b4 100755 --- a/src/bootstrap/main.c +++ b/src/bootstrap/main.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "errors.c" | 10 | #include "errors.c" |
11 | #include "lexer.c" | 11 | #include "lexer.c" |
12 | #include "objects.c" | 12 | #include "objects.c" |
13 | #include "parser.c" | ||
13 | 14 | ||
14 | void | 15 | void |
15 | init(void) { | 16 | init(void) { |
@@ -17,6 +18,7 @@ init(void) { | |||
17 | obj_nil = alloc_object(OBJ_TYPE_NIL); | 18 | obj_nil = alloc_object(OBJ_TYPE_NIL); |
18 | obj_true = alloc_object(OBJ_TYPE_BOOL); | 19 | obj_true = alloc_object(OBJ_TYPE_BOOL); |
19 | obj_false = alloc_object(OBJ_TYPE_BOOL); | 20 | obj_false = alloc_object(OBJ_TYPE_BOOL); |
21 | obj_err = alloc_object(OBJ_TYPE_ERR); | ||
20 | } | 22 | } |
21 | 23 | ||
22 | void | 24 | void |
@@ -29,10 +31,19 @@ process_source(const StringView *source) { | |||
29 | return; | 31 | return; |
30 | } | 32 | } |
31 | 33 | ||
32 | // Print tokens. | 34 | Visitor visitor = (Visitor){ |
33 | for (size_t i = 0; i < tokens.size; i++) { | 35 | .tokens = tokens, |
34 | Token tok = tokens.buf[i]; | 36 | .current = 0, |
35 | print_token(tok); | 37 | }; |
38 | while (has_next_token(&visitor) && peek_token(&visitor).type != TOKEN_EOF) { | ||
39 | Object *root = parse_tree(&visitor); | ||
40 | if (root == obj_err || errors_n != 0) { | ||
41 | free_objects(root); | ||
42 | break; | ||
43 | } | ||
44 | display(root); | ||
45 | printf("\n"); | ||
46 | free_objects(root); | ||
36 | } | 47 | } |
37 | 48 | ||
38 | if (tokens.buf != NULL) { | 49 | if (tokens.buf != NULL) { |
@@ -69,7 +80,6 @@ run_repl(void) { | |||
69 | errors_n = 0; | 80 | errors_n = 0; |
70 | continue; | 81 | continue; |
71 | } | 82 | } |
72 | |||
73 | if (sv.n != 0) { | 83 | if (sv.n != 0) { |
74 | printf("\n"); | 84 | printf("\n"); |
75 | } | 85 | } |
@@ -104,11 +114,11 @@ run_file(char *file_name) { | |||
104 | if (errors_n != 0) { | 114 | if (errors_n != 0) { |
105 | for (size_t i = 0; i < errors_n; i++) { | 115 | for (size_t i = 0; i < errors_n; i++) { |
106 | Error err = errors[i]; | 116 | Error err = errors[i]; |
107 | printf("%s", file_name); | 117 | fprintf(stderr, "%s", file_name); |
108 | if (err.line != 0) { | 118 | if (err.line != 0) { |
109 | printf(":%ld:%ld", err.line, err.col); | 119 | fprintf(stderr, ":%ld:%ld: ", err.line, err.col); |
110 | } | 120 | } |
111 | printf("%s\n", error_msgs[err.value]); | 121 | fprintf(stderr, "%s\n", error_msgs[err.value]); |
112 | } | 122 | } |
113 | errors_n = 0; | 123 | errors_n = 0; |
114 | } | 124 | } |
@@ -146,11 +156,11 @@ run_stdin(void) { | |||
146 | if (errors_n != 0) { | 156 | if (errors_n != 0) { |
147 | for (size_t i = 0; i < errors_n; i++) { | 157 | for (size_t i = 0; i < errors_n; i++) { |
148 | Error err = errors[i]; | 158 | Error err = errors[i]; |
149 | printf("stdin"); | 159 | fprintf(stderr, "stdin"); |
150 | if (err.line != 0) { | 160 | if (err.line != 0) { |
151 | printf(":%ld:%ld: ", err.line, err.col); | 161 | fprintf(stderr, ":%ld:%ld: ", err.line, err.col); |
152 | } | 162 | } |
153 | printf("%s\n", error_msgs[err.value]); | 163 | fprintf(stderr, "%s\n", error_msgs[err.value]); |
154 | } | 164 | } |
155 | errors_n = 0; | 165 | errors_n = 0; |
156 | } | 166 | } |