summaryrefslogtreecommitdiff
path: root/base_cgen.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-09-01 15:21:25 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-09-01 15:21:25 -0400
commitcc7d494226f41d76208bd2a0613a26435247cc87 (patch)
tree77ba93bae293ea2e2299ab54bea5c0f58065bce0 /base_cgen.c
parent8640ec94e95156551ce90a8fe4d96eddc6e66f88 (diff)
improved the way identifiers worked (now they use a single block array)
Diffstat (limited to 'base_cgen.c')
-rw-r--r--base_cgen.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/base_cgen.c b/base_cgen.c
index 1e79aaa..125146b 100644
--- a/base_cgen.c
+++ b/base_cgen.c
@@ -12,6 +12,7 @@ typedef struct {
int indent_level;
bool indent_next; /* should the next thing written be indented? */
CGenWritingTo writing_to;
+ Identifier main_ident;
} CGenerator;
static FILE *cgen_writing_to(CGenerator *g) {
@@ -79,23 +80,6 @@ static void cgen_write_line_comment(CGenerator *g, const char *fmt, ...) {
cgen_write(g, " */\n");
}
-static void cgen_create(CGenerator *g, FILE *c_out, FILE *h_out, const char *h_filename) {
- g->c_out = c_out;
- g->h_out = h_out;
- g->anon_fn_count = 0;
- g->indent_level = 0;
- g->block = NULL;
- g->indent_next = true;
-
- g->writing_to = CGEN_WRITING_TO_H;
- cgen_write(g, "#include <stddef.h>\n"
- "#include <stdint.h>\n");
-
- g->writing_to = CGEN_WRITING_TO_C;
- cgen_write(g, "#include \"%s\"\n", h_filename);
- cgen_writeln(g, ""); /* extra newline between includes and code */
-}
-
/* Pass NULL for where if you don't want to check if it's declared */
static bool cgen_fn_name(CGenerator *g, FnExpr *f, Location *where);
@@ -247,10 +231,11 @@ static void cgen_type_post(CGenerator *g, Type *t) {
static bool cgen_fn_name(CGenerator *g, FnExpr *f, Location *where) {
if (f->name) {
- if (ident_eq_str(f->name, "main"))
+ if (f->name == g->main_ident) {
cgen_write(g, "main__");
- else
+ } else {
return cgen_ident(g, f->name, where);
+ }
} else {
cgen_write(g, "a___");
}