summaryrefslogtreecommitdiff
path: root/cgen.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-11-09 16:16:25 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2019-11-09 16:16:25 -0500
commit421a2e5b9d794050d7bfd34bf0d20440cd7450ee (patch)
treeeb0c29f3b30f8e9bdf8429a93650058fc92dc4f0 /cgen.c
parent3c31cd066fb761f7fc1f7f98918ae96a55dedc4d (diff)
got rid of _FLAG_ everywhere
Diffstat (limited to 'cgen.c')
-rw-r--r--cgen.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/cgen.c b/cgen.c
index 9bae62d..60346fd 100644
--- a/cgen.c
+++ b/cgen.c
@@ -187,7 +187,7 @@ static void cgen_ident_id(CGenerator *g, IdentID id) {
/* should declaration be a direct function declaration C (as opposed to using a function pointer or not being a function) */
static bool cgen_fn_is_direct(CGenerator *g, Declaration *d) {
- return g->block == NULL && (d->flags & DECL_FLAG_HAS_EXPR) && d->expr.kind == EXPR_FN && arr_len(d->idents) == 1;
+ return g->block == NULL && (d->flags & DECL_HAS_EXPR) && d->expr.kind == EXPR_FN && arr_len(d->idents) == 1;
}
static bool cgen_uses_ptr(Type *t) {
@@ -239,7 +239,7 @@ static inline Identifier cgen_ident_id_to_ident(CGenerator *g, IdentID id) {
}
static bool cgen_type_pre(CGenerator *g, Type *t, Location where) {
- assert(t->flags & TYPE_FLAG_RESOLVED);
+ assert(t->flags & TYPE_IS_RESOLVED);
switch (t->kind) {
case TYPE_BUILTIN:
switch (t->builtin) {
@@ -334,7 +334,7 @@ static bool cgen_type_post(CGenerator *g, Type *t, Location where) {
return false;
break;
case TYPE_ARR:
- assert(t->flags & TYPE_FLAG_RESOLVED);
+ assert(t->flags & TYPE_IS_RESOLVED);
cgen_write(g, "[%lu])", (unsigned long)t->arr.n);
if (!cgen_type_post(g, t->arr.of, where))
return false;
@@ -655,7 +655,7 @@ static bool cgen_set_tuple(CGenerator *g, Expression *exprs, Identifier *idents,
/* generates the C code for new'ing a slice of array type t (e.g. [5]int) and putting it in the given ident id. */
static bool cgen_new_slice(CGenerator *g, Type *t, IdentID id, Location where) {
Expression *n_expr = t->arr.n_expr;
- assert(!(t->flags & TYPE_FLAG_RESOLVED)); /* we don't want this to be resolved, because the size might only be known at runtime. */
+ assert(!(t->flags & TYPE_IS_RESOLVED)); /* we don't want this to be resolved, because the size might only be known at runtime. */
if (!cgen_expr_pre(g, n_expr)) return false;
cgen_write(g, "size_t s");
cgen_ident_id(g, id);
@@ -805,7 +805,7 @@ static bool cgen_expr_pre(CGenerator *g, Expression *e) {
if (!cgen_type_post(g, &ea->type, e->where)) return false;
cgen_write(g, "; ");
Expression val_expr;
- val_expr.flags = EXPR_FLAG_FOUND_TYPE;
+ val_expr.flags = EXPR_FOUND_TYPE;
val_expr.kind = EXPR_IDENT;
val_expr.ident = ea->value;
val_expr.type = ea->type;
@@ -944,7 +944,7 @@ static bool cgen_expr_pre(CGenerator *g, Expression *e) {
set_expr.kind = EXPR_IDENT;
set_expr.ident = ea->value;
set_expr.type = ea->type;
- set_expr.flags = EXPR_FLAG_FOUND_TYPE;
+ set_expr.flags = EXPR_FOUND_TYPE;
if (!cgen_set(g, &set_expr, NULL, NULL, "(*p_)"))
return false;
@@ -1581,11 +1581,11 @@ static bool cgen_val(CGenerator *g, Value *v, Type *t, Location where) {
static bool cgen_decl(CGenerator *g, Declaration *d) {
- int has_expr = d->flags & DECL_FLAG_HAS_EXPR;
+ int has_expr = d->flags & DECL_HAS_EXPR;
bool is_tuple = d->type.kind == TYPE_TUPLE;
if (cgen_fn_is_direct(g, d)) {
/* definition already generated by cgen_defs_decl */
- } else if ((d->flags & DECL_FLAG_CONST) || g->block == NULL) {
+ } else if ((d->flags & DECL_IS_CONST) || g->block == NULL) {
/* declarations where we use a value */
for (size_t idx = 0; idx < arr_len(d->idents); idx++) {
Identifier i = d->idents[idx];
@@ -1743,7 +1743,7 @@ static bool cgen_defs_decl(CGenerator *g, Declaration *d) {
if (!cgen_defs_block(g, &d->expr.fn.body))
return false;
} else {
- if (d->flags & DECL_FLAG_HAS_EXPR) {
+ if (d->flags & DECL_HAS_EXPR) {
if (!cgen_defs_expr(g, &d->expr))
return false;
}
@@ -1782,6 +1782,10 @@ static bool cgen_defs_block(CGenerator *g, Block *b) {
static bool cgen_file(CGenerator *g, ParsedFile *f) {
g->block = NULL;
g->file = f;
+ /*
+ TODO: to improve compile times, don't include stdlib.h
+ (you can even get away with not including stdio.h with posix file descriptors)
+ */
cgen_write(g, "#include <stdint.h>\n"
"#include <stdlib.h>\n"
"#include <stdio.h>\n"
@@ -1797,10 +1801,10 @@ static bool cgen_file(CGenerator *g, ParsedFile *f) {
"typedef double f64;\n"
"typedef u8 bool;\n"
"typedef struct { void *data; i64 n; } slice_;\n"
- "static slice_ mkslice_(void *data, i64 n) { slice_ ret; ret.data = data; ret.n = n; return ret; }\n"
- "static void *e__calloc(size_t n, size_t sz) { void *ret = calloc(n, sz); if (!ret) { fprintf(stderr, \"Out of memory.\\n\"); abort(); } return ret; }\n"
"#define false ((bool)0)\n"
- "#define true ((bool)1)\n\n\n");
+ "#define true ((bool)1)\n"
+ "static inline slice_ mkslice_(void *data, i64 n) { slice_ ret; ret.data = data; ret.n = n; return ret; }\n"
+ "static void *e__calloc(size_t n, size_t sz) { void *ret = calloc(n, sz); if (!ret) { fprintf(stderr, \"Out of memory.\\n\"); abort(); } return ret; }\n\n\n");
if (!typedefs_file(g, f))
return false;
if (!cgen_decls_file(g, f))