diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-05-11 15:14:34 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-05-11 15:14:34 -0400 |
commit | e64ad4e05257063863040c087181959577535834 (patch) | |
tree | 2239fc1aaf0bb26e5a014ed03c76295afb4206f0 | |
parent | fcf0174ce10900f7f5ed6547382e0912d6a291b3 (diff) |
improved function naming; started init
-rw-r--r-- | abbrevs.txt | 5 | ||||
-rw-r--r-- | cgen.c | 23 | ||||
-rw-r--r-- | types.h | 13 |
3 files changed, 26 insertions, 15 deletions
diff --git a/abbrevs.txt b/abbrevs.txt index 8c5ad76..d486c78 100644 --- a/abbrevs.txt +++ b/abbrevs.txt @@ -1,3 +1,7 @@ +Abbreviations used in this code +Some of them are very common +Others aren't + allocr - allocator arg - argument cap - capacity @@ -15,6 +19,7 @@ expr - expression fn - function ident - identifier inc - include +init - initialization kw - keyword lbl - label len - length @@ -467,16 +467,19 @@ static void cgen_ctype(CGenerator *g, CType *c) { } + +static inline void cgen_fn_instance_number(CGenerator *g, U64 instance) { + cgen_write(g, U64_FMT "_", instance); +} static inline void cgen_fn_name(CGenerator *g, FnExpr *f) { if (f->c.name) { cgen_ident(g, f->c.name); } else { cgen_ident_id(g, f->c.id); } -} - -static inline void cgen_fn_instance_number(CGenerator *g, U64 instance) { - cgen_write(g, U64_FMT "_", instance); + if (f->instance_id) { + cgen_fn_instance_number(g, f->instance_id); + } } /* should we generate this function? (or is it just meant for compile time) */ @@ -493,13 +496,6 @@ static bool cgen_should_gen_fn(FnExpr *f) { } } -static void cgen_full_fn_name(CGenerator *g, FnExpr *f) { - cgen_fn_name(g, f); - if (f->instance_id) { - cgen_fn_instance_number(g, f->instance_id); - } -} - static void cgen_val_ptr_pre(CGenerator *g, void *v, Type *t) { assert(t->flags & TYPE_IS_RESOLVED); switch (t->kind) { @@ -729,7 +725,7 @@ static void cgen_fn_header(CGenerator *g, FnExpr *f, U64 which_are_const) { cgen_type_pre(g, &f->ret_type); cgen_write(g, " "); } - cgen_full_fn_name(g, f); + cgen_fn_name(g, f); cgen_fn_params(g, f, which_are_const); if (!out_param) { cgen_type_post(g, &f->ret_type); @@ -863,10 +859,7 @@ static void cgen_set_tuple(CGenerator *g, Expression *exprs, Identifier *idents, Type *ret_type = &fn_type->types[0]; Constness *constness = fn_type->constness; int i = 0; - IdentID *underscore_ids = NULL; - - int nout_params = (int)(exprs ? arr_len(exprs) : arr_len(idents)); if (idents) { @@ -1003,9 +1003,22 @@ typedef struct Statement { } Statement; typedef Statement *StatementPtr; +/* + Statements to be run before any code in main is called. + This is mainly for the standard library, so you don't have to do something weird + like io.init(); + Each initialization has a "priority", with lower priorities being executed first. + Priorities <0 are reserved for the standard library (you can use them if you want, + but standard library functions might not work) +*/ +typedef struct { + Statement s; + I64 priority; +} Initialization; typedef struct ParsedFile { Statement *stmts; + Initialization *inits; } ParsedFile; typedef struct Parser { |