aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/main.c')
-rwxr-xr-xsrc/bootstrap/main.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/bootstrap/main.c b/src/bootstrap/main.c
index e6155b4..2aa3038 100755
--- a/src/bootstrap/main.c
+++ b/src/bootstrap/main.c
@@ -12,6 +12,8 @@
12#include "objects.c" 12#include "objects.c"
13#include "parser.c" 13#include "parser.c"
14 14
15#define MAKE_SYM(STR) make_symbol((StringView){(STR), sizeof(STR) - 1})
16
15void 17void
16init(void) { 18init(void) {
17 // Initialize singletons. 19 // Initialize singletons.
@@ -19,6 +21,11 @@ init(void) {
19 obj_true = alloc_object(OBJ_TYPE_BOOL); 21 obj_true = alloc_object(OBJ_TYPE_BOOL);
20 obj_false = alloc_object(OBJ_TYPE_BOOL); 22 obj_false = alloc_object(OBJ_TYPE_BOOL);
21 obj_err = alloc_object(OBJ_TYPE_ERR); 23 obj_err = alloc_object(OBJ_TYPE_ERR);
24
25 // Global environment.
26 global_env = env_create(NULL);
27 env_add_symbol(global_env, MAKE_SYM("quote"), make_procedure(proc_quote));
28 env_add_symbol(global_env, MAKE_SYM("+"), make_procedure(proc_sum));
22} 29}
23 30
24void 31void
@@ -41,8 +48,15 @@ process_source(const StringView *source) {
41 free_objects(root); 48 free_objects(root);
42 break; 49 break;
43 } 50 }
51
52 // FIXME: Not freeing result or intermediate objects, can leak memory.
53 Object *result = eval(global_env, root);
54 printf("AST: ");
44 display(root); 55 display(root);
45 printf("\n"); 56 printf("\n");
57 printf("EVAL: ");
58 display(result);
59 printf("\n");
46 free_objects(root); 60 free_objects(root);
47 } 61 }
48 62
@@ -116,9 +130,9 @@ run_file(char *file_name) {
116 Error err = errors[i]; 130 Error err = errors[i];
117 fprintf(stderr, "%s", file_name); 131 fprintf(stderr, "%s", file_name);
118 if (err.line != 0) { 132 if (err.line != 0) {
119 fprintf(stderr, ":%ld:%ld: ", err.line, err.col); 133 fprintf(stderr, ":%ld:%ld", err.line, err.col);
120 } 134 }
121 fprintf(stderr, "%s\n", error_msgs[err.value]); 135 fprintf(stderr, ": %s\n", error_msgs[err.value]);
122 } 136 }
123 errors_n = 0; 137 errors_n = 0;
124 } 138 }
@@ -158,9 +172,9 @@ run_stdin(void) {
158 Error err = errors[i]; 172 Error err = errors[i];
159 fprintf(stderr, "stdin"); 173 fprintf(stderr, "stdin");
160 if (err.line != 0) { 174 if (err.line != 0) {
161 fprintf(stderr, ":%ld:%ld: ", err.line, err.col); 175 fprintf(stderr, ":%ld:%ld", err.line, err.col);
162 } 176 }
163 fprintf(stderr, "%s\n", error_msgs[err.value]); 177 fprintf(stderr, ": %s\n", error_msgs[err.value]);
164 } 178 }
165 errors_n = 0; 179 errors_n = 0;
166 } 180 }