diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-11-30 23:43:02 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-11-30 23:43:58 -0500 |
commit | 0f26f41c326f4dab86cdd1791e08d03d624eeb99 (patch) | |
tree | a99eeb864d1b17f41abdc213504d0aea0cc9518b | |
parent | d984e1585b749f184d2014ffff498ce5f36bcf5a (diff) |
trying to make this compilable with a c++ compiler
maybe it works on some but gccs not happy with my gotos...
-rw-r--r-- | copy.c | 7 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | tokenizer.c | 4 | ||||
-rw-r--r-- | types.c | 6 |
5 files changed, 19 insertions, 6 deletions
@@ -10,6 +10,13 @@ static void copy_decl(Copier *c, Declaration *out, Declaration *in); static void copy_block(Copier *c, Block *out, Block *in); static void copy_type(Copier *c, Type *out, Type *in); +static Copier copier_create(Allocator *a, Block *b) { + Copier c; + c.allocr = a; + c.block = b; + return c; +} + static void copy_val(Allocator *a, Value *out, Value *in, Type *t) { assert(t->flags & TYPE_IS_RESOLVED); switch (t->kind) { @@ -732,7 +732,7 @@ static void *eval_ptr_to_struct_field(Evaluator *ev, Expression *dot_expr) { Value struc; if (!eval_expr(ev, dot_expr->binary.lhs, &struc)) - return false; + return NULL; void *struc_data; if (is_ptr) { struc_data = *(void **)struc.ptr; @@ -3,6 +3,7 @@ TODO: fix VBS with structs test ArrInt @= Arr(int); +there are probably places where we enter a function and never exit (in typing?) if there's an error packages X @= newtype(int); or something don't allow while {3; 5} (once break is added) @@ -11,6 +12,11 @@ make sure futurely/currently-declared types are only used by pointer/slice allow omission of trailing ; in foo @= fn() {}? */ +#ifdef __cplusplus +#define new new_ +#define this this_ +#endif + #include "toc.c" int main(int argc, char **argv) { diff --git a/tokenizer.c b/tokenizer.c index 6481cfb..595927f 100644 --- a/tokenizer.c +++ b/tokenizer.c @@ -18,7 +18,7 @@ static const char *directives[DIRECT_COUNT] = /* Returns KW_COUNT if it's not a keyword */ /* OPTIM: don't use strncmp so much */ static Keyword tokenize_kw(char **s) { - for (Keyword k = 0; k < KW_COUNT; k++) { + for (Keyword k = 0; k < KW_COUNT; k = k + 1) { size_t len = strlen(keywords[k]); if (strncmp(*s, keywords[k], len) == 0) { if (k > KW_LAST_SYMBOL) { @@ -40,7 +40,7 @@ static Keyword tokenize_kw(char **s) { /* Returns DIRECT_COUNT if it's not a directive */ static Directive tokenize_direct(char **s) { - for (Directive d = 0; d < DIRECT_COUNT; d++) { + for (Directive d = 0; d < DIRECT_COUNT; d = d + 1) { size_t len = strlen(directives[d]); if (strncmp(*s, directives[d], len) == 0) { if (isident((*s)[len])) { @@ -198,7 +198,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags) FnExpr fn_copy; if (!(flags & TYPE_OF_FN_NO_COPY_EVEN_IF_CONST) && fn_has_any_const_params(f)) { - Copier cop = {.allocr = tr->allocr, .block = tr->block}; + Copier cop = copier_create(tr->allocr, tr->block); copy_fn_expr(&cop, &fn_copy, f, false); f = &fn_copy; } @@ -1105,7 +1105,7 @@ static bool types_expr(Typer *tr, Expression *e) { /* TODO: evaluate once per decl, not once per ident */ Expression copy; /* make a copy of the default argument, and type and evaluate it. */ - Copier cop = {.block = tr->block, .allocr = tr->allocr}; + Copier cop = copier_create(tr->allocr, tr->block); copy_expr(&cop, ©, ¶m->expr); if (!types_expr(tr, ©)) return false; @@ -1146,7 +1146,7 @@ static bool types_expr(Typer *tr, Expression *e) { /* fn is the instance, original_fn is not */ FnExpr *original_fn = fn; FnExpr fn_copy; - Copier cop = {.allocr = tr->allocr, .block = tr->block}; + Copier cop = copier_create(tr->allocr, tr->block); /* TODO: somehow don't do all of this if we've already generated this instance */ copy_fn_expr(&cop, &fn_copy, fn, true); fn = &fn_copy; |