summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arr.c4
-rw-r--r--blockarr.c2
-rw-r--r--cgen.c26
-rw-r--r--decls_cgen.c6
-rw-r--r--eval.c12
-rw-r--r--identifiers.c8
-rw-r--r--instance_table.c14
-rw-r--r--parse.c222
-rw-r--r--str.c2
-rw-r--r--test.toc1
-rw-r--r--tokenizer.c26
-rw-r--r--typedefs_cgen.c2
-rw-r--r--types.c22
13 files changed, 174 insertions, 173 deletions
diff --git a/arr.c b/arr.c
index d25dbf1..fc6149e 100644
--- a/arr.c
+++ b/arr.c
@@ -116,7 +116,7 @@ static void *arr_last_(void *arr, size_t item_sz) {
static void arr_remove_last_(void **arr, size_t item_sz) {
assert(arr_hdr(*arr)->len);
- arr_hdr(*arr)->len--; (void)item_sz;
+ --arr_hdr(*arr)->len; (void)item_sz;
}
static void arr_copya_(void **out, void *in, size_t item_sz, Allocator *a) {
@@ -157,7 +157,7 @@ You shouldn't rely on this, though, e.g. by doing
#define arr_clear(arr) arr_clear_((void **)(arr)), (void)sizeof **arr /* second part makes sure most of the time that you don't accidentally call it without taking the address */
#define arr_last(arr) arr_last_((void *)(arr), sizeof *(arr))
/* OPTIM: maybe replace with less standard-compliant version */
-#define arr_foreach(arr, type, var) for (type *var = arr_len(arr) ? arr : NULL, *var##_foreach_end = arr_last(arr); var; var == var##_foreach_end ? var = NULL : var++)
+#define arr_foreach(arr, type, var) for (type *var = arr_len(arr) ? arr : NULL, *var##_foreach_end = arr_last(arr); var; var == var##_foreach_end ? var = NULL : ++var)
#define arr_remove_last(arr) arr_remove_last_((void **)(arr), sizeof **(arr))
#define arr_copya(out, in, a) do { assert(sizeof *(in) == sizeof **(out)); arr_copya_((void **)(out), (in), sizeof **(out), (a)); } while(0)
diff --git a/blockarr.c b/blockarr.c
index 5a689fe..1d8590d 100644
--- a/blockarr.c
+++ b/blockarr.c
@@ -34,7 +34,7 @@ static void *block_arr_add(BlockArr *arr) {
return block->data;
} else {
last_block->last = (char*)last_block->last + arr->item_sz;
- last_block->n++;
+ ++last_block->n;
return last_block->last;
}
}
diff --git a/cgen.c b/cgen.c
index 2689662..f2f8fd4 100644
--- a/cgen.c
+++ b/cgen.c
@@ -139,14 +139,14 @@ static bool cgen_defs_decl(CGenerator *g, Declaration *d);
for (U64 i = 0; i < fn->instances.cap; ++i) { \
if (fn->instances.occupied[i]) { \
cgen_recurse_subexprs_fn_simple((&(*data)->fn), decl_f, block_f); \
- } \
- data++; \
- } \
- } else { \
- cgen_recurse_subexprs_fn_simple(fn, decl_f, block_f); \
+ } \
+ ++data; \
+ } \
+ } else { \
+ cgen_recurse_subexprs_fn_simple(fn, decl_f, block_f); \
} \
} break; \
- case EXPR_NEW: \
+ case EXPR_NEW: \
if (e->new.n && !f(g, e->new.n)) \
return false; \
break; \
@@ -160,7 +160,7 @@ static bool cgen_block_enter(CGenerator *g, Block *b) {
} else {
stmts = b->stmts;
}
- if (b) g->indent_lvl++;
+ if (b) ++g->indent_lvl;
return block_enter(b, stmts, 0);
}
@@ -173,7 +173,7 @@ static void cgen_block_exit(CGenerator *g, Block *into) {
stmts = b->stmts;
}
block_exit(b, stmts);
- if (b) g->indent_lvl--;
+ if (b) --g->indent_lvl;
g->block = into;
}
@@ -1149,7 +1149,7 @@ static bool cgen_expr(CGenerator *g, Expression *e) {
case EXPR_LITERAL_STR: {
size_t c;
cgen_write(g, "mkslice_(\"");
- for (c = 0; c < e->strl.len; c++) {
+ for (c = 0; c < e->strl.len; ++c) {
cgen_write(g, "\\x%x", e->strl.str[c]);
}
cgen_write(g, "\", %lu)", (unsigned long)e->strl.len);
@@ -1527,7 +1527,7 @@ static bool cgen_fn(CGenerator *g, FnExpr *f, Location where, U64 instance, Valu
cgen_nl(g);
if (compile_time_args) {
int carg_idx = 0;
- compile_time_args++; /* move past which_are_const */
+ ++compile_time_args; /* move past which_are_const */
int semi_const_idx = 0;
arr_foreach(f->params, Declaration, param) {
if ((param->flags & DECL_IS_CONST)
@@ -1553,7 +1553,7 @@ static bool cgen_fn(CGenerator *g, FnExpr *f, Location where, U64 instance, Valu
cgen_write(g, ";");
cgen_nl(g);
}
- carg_idx++;
+ ++carg_idx;
}
}
}
@@ -1731,7 +1731,7 @@ static bool cgen_decl(CGenerator *g, Declaration *d) {
bool is_tuple = d->type.kind == TYPE_TUPLE;
if ((d->flags & DECL_IS_CONST) || (g->block == NULL && g->fn == NULL)) {
/* declarations where we use a value */
- for (size_t idx = 0; idx < arr_len(d->idents); idx++) {
+ for (size_t idx = 0; idx < arr_len(d->idents); ++idx) {
Identifier i = d->idents[idx];
Type *type = is_tuple ? &d->type.tuple[idx] : &d->type;
Value *val = is_tuple ? &d->val.tuple[idx] : &d->val;
@@ -1770,7 +1770,7 @@ static bool cgen_decl(CGenerator *g, Declaration *d) {
}
} else {
/* declarations where we use an expression */
- for (size_t idx = 0; idx < arr_len(d->idents); idx++) {
+ for (size_t idx = 0; idx < arr_len(d->idents); ++idx) {
Identifier i = d->idents[idx];
Type *type = d->type.kind == TYPE_TUPLE ? &d->type.tuple[idx] : &d->type;
if (!cgen_type_pre(g, type, d->where)) return false;
diff --git a/decls_cgen.c b/decls_cgen.c
index f1489d8..7288e70 100644
--- a/decls_cgen.c
+++ b/decls_cgen.c
@@ -24,7 +24,7 @@ static bool cgen_decls_fn_instances(CGenerator *g, Expression *e) {
cgen_nl(g);
}
}
- data++;
+ ++data;
}
return true;
}
@@ -65,7 +65,7 @@ static bool cgen_decls_expr(CGenerator *g, Expression *e) {
cgen_ident_id(g, sdef->c.id);
cgen_write(g, "{");
cgen_nl(g);
- g->indent_lvl++;
+ ++g->indent_lvl;
arr_foreach(sdef->fields, Field, f) {
if (!cgen_type_pre(g, f->type, e->where)) return false;
cgen_write(g, " ");
@@ -74,7 +74,7 @@ static bool cgen_decls_expr(CGenerator *g, Expression *e) {
cgen_write(g, ";");
cgen_nl(g);
}
- g->indent_lvl--;
+ --g->indent_lvl;
cgen_write(g, "};");
cgen_nl(g);
sdef->flags |= STRUCT_DEF_CGENERATED;
diff --git a/eval.c b/eval.c
index 446b83f..2f4a8bc 100644
--- a/eval.c
+++ b/eval.c
@@ -1232,7 +1232,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
if (!eval_block(ev, &ea->body, &e->type, v)) return false;
if (index_val) {
- index_val->i64++;
+ ++index_val->i64;
}
eval_numerical_bin_op(x, &ea->type, BINARY_ADD, stepval, ea->range.stepval ? &ea->type : &i64t, &x, &ea->type);
}
@@ -1292,7 +1292,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
eval_deref(value_val, ptr, &ea->type);
if (!eval_block(ev, &ea->body, &e->type, v))
return false;
- index_val->i64++;
+ ++index_val->i64;
}
}
each_exit(e);
@@ -1421,7 +1421,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
IdentDecl *id = ident_decl(*i);
copy_val(NULL, &id->val, &args[arg], type);
id->flags |= IDECL_HAS_VAL;
- arg++;
+ ++arg;
}
}
arr_foreach(fn->ret_decls, Declaration, d) {
@@ -1441,7 +1441,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
id->flags |= IDECL_HAS_VAL;
id->val = val_zero(type);
}
- idx++;
+ ++idx;
}
}
arr_clear(&args);
@@ -1467,7 +1467,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
void *to_free = val_ptr_to_free(element, type);
if (to_free)
*(void **)arr_add(&ev->to_free) = to_free;
- i++;
+ ++i;
}
}
if (arr_len(tuple) == 1) {
@@ -1569,7 +1569,7 @@ static bool eval_decl(Evaluator *ev, Declaration *d) {
id->val = val_zero(type);
}
}
- index++;
+ ++index;
id->flags |= IDECL_HAS_VAL;
}
}
diff --git a/identifiers.c b/identifiers.c
index f1bd380..c8c5047 100644
--- a/identifiers.c
+++ b/identifiers.c
@@ -132,7 +132,7 @@ static Identifier ident_get(Identifiers *ids, const char *s) {
if (!tree) return NULL;
tree = tree->children[c_high];
if (!tree) return NULL;
- s++;
+ ++s;
}
return tree;
}
@@ -143,7 +143,7 @@ static char *ident_to_str(Identifier i) {
str += i_len;
*str = 0;
while (i->parent) {
- str--;
+ --str;
unsigned char c_high = i->index_in_parent;
unsigned char c_low = i->parent->index_in_parent;
char c = (char)ident_uchar_to_char((int)c_low + ((int)c_high << 4));
@@ -194,7 +194,7 @@ static int ident_index_in_decl(Identifier i, Declaration *d) {
arr_foreach(d->idents, Identifier, j) {
if (i == *j)
return index;
- index++;
+ ++index;
}
return -1;
}
@@ -210,7 +210,7 @@ static bool ident_eq_str(Identifier i, const char *s) {
int c = ident_uchar_to_char(c_low + (c_high << 4));
if (c != *t) return false;
i = i->parent->parent;
- if (t > s) t--;
+ if (t > s) --t;
else break;
}
if (i->parent) return false; /* not at root */
diff --git a/instance_table.c b/instance_table.c
index 5e7f917..7f6c7e7 100644
--- a/instance_table.c
+++ b/instance_table.c
@@ -31,8 +31,8 @@ static U64 f32_hash(F32 f) {
}
F32 last = f;
int exponent = 0;
- while (f > 1) {
- exponent++;
+ while (f > 1.0f) {
+ ++exponent;
f /= 10;
if (f == last) {
/* +/- infinity probably */
@@ -57,8 +57,8 @@ static U64 f64_hash(F64 f) {
}
F64 last = f;
int exponent = 0;
- while (f > 1) {
- exponent++;
+ while (f > 1.0) {
+ ++exponent;
f /= 10;
if (f == last) {
/* +/- infinity probably */
@@ -299,7 +299,7 @@ static Instance *instance_table_adda(Allocator *a, HashTable *h, Value v, Type *
if (old_occupied[i]) {
U64 index = val_hash(old_data[i]->val, t) % new_cap;
while (new_occupied[index]) {
- index++;
+ ++index;
if (index >= new_cap)
index -= new_cap;
}
@@ -322,7 +322,7 @@ static Instance *instance_table_adda(Allocator *a, HashTable *h, Value v, Type *
return data[index];
}
} else break;
- index++;
+ ++index;
if (index >= h->cap)
index -= h->cap;
}
@@ -332,7 +332,7 @@ static Instance *instance_table_adda(Allocator *a, HashTable *h, Value v, Type *
data[index] = allocr_malloc(a, sizeof *data[index]);
data[index]->val = v;
h->occupied[index] = true;
- h->n++;
+ ++h->n;
return data[index];
}
return NULL;
diff --git a/parse.c b/parse.c
index d9f73f5..769f2eb 100644
--- a/parse.c
+++ b/parse.c
@@ -321,29 +321,29 @@ static Token *expr_find_end(Parser *p, ExprEndFlags flags) {
return token;
break;
case KW_LPAREN:
- paren_level++;
+ ++paren_level;
break;
case KW_RPAREN:
- paren_level--;
+ --paren_level;
if (paren_level < 0)
return token;
break;
case KW_LSQUARE:
- square_level++;
+ ++square_level;
break;
case KW_RSQUARE:
- square_level--;
+ --square_level;
if (square_level < 0)
return token;
break;
case KW_LBRACE:
if ((flags & EXPR_CAN_END_WITH_LBRACE) && square_level == 0 && paren_level == 0)
return token;
- brace_level++;
+ ++brace_level;
could_be_vbs = true;
break;
case KW_RBRACE:
- brace_level--;
+ --brace_level;
if (paren_level == 0 && brace_level == 0 && square_level == 0
&& could_be_vbs && !token_is_kw(token + 1, KW_RPAREN)) {
/* if there's an else/elif, the expr must continue */
@@ -390,7 +390,7 @@ static Token *expr_find_end(Parser *p, ExprEndFlags flags) {
t->token = token; /* don't try to continue */
return NULL;
}
- token++;
+ ++token;
}
}
@@ -400,7 +400,7 @@ static bool parse_args(Parser *p, Argument **args) {
Token *start = t->token;
assert(token_is_kw(start, KW_LPAREN));
*args = NULL;
- t->token++; /* move past ( */
+ ++t->token; /* move past ( */
if (!token_is_kw(t->token, KW_RPAREN)) {
/* non-empty arg list */
while (1) {
@@ -424,10 +424,10 @@ static bool parse_args(Parser *p, Argument **args) {
if (token_is_kw(t->token, KW_RPAREN))
break;
assert(token_is_kw(t->token, KW_COMMA));
- t->token++; /* move past , */
+ ++t->token; /* move past , */
}
}
- t->token++; /* move past ) */
+ ++t->token; /* move past ) */
return true;
}
@@ -442,14 +442,14 @@ static bool parse_type(Parser *p, Type *type) {
int b = kw_to_builtin_type(t->token->kw);
if (b != -1) {
type->builtin = (BuiltinType)b;
- t->token++;
+ ++t->token;
break;
}
}
/* Not a builtin */
if (t->token->kw == KW_TYPE) {
type->kind = TYPE_TYPE;
- t->token++;
+ ++t->token;
break;
}
switch (t->token->kw) {
@@ -458,13 +458,13 @@ static bool parse_type(Parser *p, Type *type) {
type->kind = TYPE_FN;
type->fn.types = NULL;
type->fn.constness = NULL;
- t->token++;
+ ++t->token;
if (!token_is_kw(t->token, KW_LPAREN)) {
tokr_err(t, "Expected ( to follow fn.");
return false;
}
parser_arr_add(p, &type->fn.types); /* add return type */
- t->token++;
+ ++t->token;
if (!token_is_kw(t->token, KW_RPAREN)) {
while (1) {
Type *param_type = parser_arr_add(p, &type->fn.types);
@@ -479,10 +479,10 @@ static bool parse_type(Parser *p, Type *type) {
tokr_err(t, "Expected , to continue function type parameter list.");
return false;
}
- t->token++; /* move past , */
+ ++t->token; /* move past , */
}
}
- t->token++; /* move past ) */
+ ++t->token; /* move past ) */
Type *ret_type = type->fn.types;
/* if there's a symbol that isn't [, (, or &, that can't be the start of a type */
if ((t->token->kind == TOKEN_KW
@@ -503,12 +503,12 @@ static bool parse_type(Parser *p, Type *type) {
/* array/slice */
type->where = t->token->where;
type->kind = TYPE_ARR;
- t->token++; /* move past [ */
+ ++t->token; /* move past [ */
if (token_is_kw(t->token, KW_RSQUARE)) {
/* slice */
type->kind = TYPE_SLICE;
type->slice = parser_malloc(p, sizeof *type->slice);
- t->token++; /* move past ] */
+ ++t->token; /* move past ] */
if (!parse_type(p, type->slice)) return false;
if (type->slice->kind == TYPE_TUPLE) {
err_print(type->where, "You cannot have a slice of tuples.");
@@ -531,7 +531,7 @@ static bool parse_type(Parser *p, Type *type) {
/* tuple! */
type->kind = TYPE_TUPLE;
type->tuple = NULL;
- t->token++; /* move past ( */
+ ++t->token; /* move past ( */
while (1) {
Type *child = parser_arr_add(p, &type->tuple);
if (!parse_type(p, child)) return false;
@@ -540,11 +540,11 @@ static bool parse_type(Parser *p, Type *type) {
return false;
}
if (token_is_kw(t->token, KW_RPAREN)) { /* we're done with the tuple */
- t->token++; /* move past ) */
+ ++t->token; /* move past ) */
break;
}
if (token_is_kw(t->token, KW_COMMA)) {
- t->token++; /* move past , */
+ ++t->token; /* move past , */
continue;
} else {
tokr_err(t, "Expected , to list next tuple type or ) to end tuple type.");
@@ -556,7 +556,7 @@ static bool parse_type(Parser *p, Type *type) {
/* pointer */
type->kind = TYPE_PTR;
type->ptr = parser_malloc(p, sizeof *type->ptr);
- t->token++; /* move past & */
+ ++t->token; /* move past & */
if (!parse_type(p, type->ptr)) return false;
if (type->ptr->kind == TYPE_TUPLE) {
err_print(type->ptr->where, "You cannot have a pointer to a tuple.");
@@ -572,12 +572,12 @@ static bool parse_type(Parser *p, Type *type) {
type->struc->c.name = NULL;
type->struc->c.id = 0;
type->struc->fields = NULL;
- t->token++;
+ ++t->token;
if (!token_is_kw(t->token, KW_LBRACE)) {
err_print(t->token->where, "Expected { or ( to follow struct.");
return false;
}
- t->token++;
+ ++t->token;
{
while (!token_is_kw(t->token, KW_RBRACE)) {
Declaration field_decl;
@@ -600,10 +600,10 @@ static bool parse_type(Parser *p, Type *type) {
f->name = *fident;
f->type = parser_malloc(p, sizeof *f->type);
*f->type = *ftype;
- idx++;
+ ++idx;
}
}
- t->token++;
+ ++t->token;
}
break;
default:
@@ -647,15 +647,15 @@ static bool parser_is_definitely_type(Parser *p, Token **end) {
while (t->token->kind != TOKEN_EOF) {
if (t->token->kind == TOKEN_KW) switch (t->token->kw) {
case KW_LBRACE:
- level++;
+ ++level;
break;
case KW_RBRACE:
- level--;
+ --level;
if (level == 0) goto end;
break;
default: break;
}
- t->token++;
+ ++t->token;
}
}
break;
@@ -663,17 +663,17 @@ static bool parser_is_definitely_type(Parser *p, Token **end) {
ret = true;
if (end) {
int level = 1;
- t->token++;
+ ++t->token;
while (t->token->kind != TOKEN_EOF) {
if (t->token->kind == TOKEN_KW) switch (t->token->kw) {
case KW_LSQUARE:
- level++;
+ ++level;
break;
case KW_RSQUARE:
- level--;
+ --level;
if (level == 0) {
if (end) {
- t->token++;
+ ++t->token;
parser_is_definitely_type(p, &t->token); /* move to end of type */
}
goto end;
@@ -681,24 +681,24 @@ static bool parser_is_definitely_type(Parser *p, Token **end) {
break;
default: break;
}
- t->token++;
+ ++t->token;
}
}
break;
case KW_LPAREN: {
Token *child_end;
- t->token++;
+ ++t->token;
ret = false;
while (parser_is_definitely_type(p, &child_end)) {
t->token = child_end;
if (t->token->kind == TOKEN_KW) {
if (t->token->kw == KW_COMMA) {
- t->token++;
+ ++t->token;
continue;
} else if (t->token->kw == KW_RPAREN) {
/* it *is* a tuple! */
ret = true;
- t->token++;
+ ++t->token;
goto end;
}
} else break;
@@ -706,21 +706,21 @@ static bool parser_is_definitely_type(Parser *p, Token **end) {
} break;
case KW_FN: {
ret = false;
- t->token++;
+ ++t->token;
if (!token_is_kw(t->token, KW_LPAREN)) {
break;
}
- t->token++;
+ ++t->token;
int paren_level = 1;
while (t->token->kind != TOKEN_EOF) {
if (t->token->kind == TOKEN_KW) switch (t->token->kw) {
case KW_LPAREN:
- paren_level++;
+ ++paren_level;
break;
case KW_RPAREN:
- paren_level--;
+ --paren_level;
if (paren_level == 0) {
- t->token++;
+ ++t->token;
if (token_is_kw(t->token, KW_LBRACE)) goto end; /* void fn expr */
if (is_decl(t)) /* has return declaration */
goto end;
@@ -746,16 +746,16 @@ static bool parser_is_definitely_type(Parser *p, Token **end) {
break;
default: break;
}
- t->token++;
+ ++t->token;
}
} break;
case KW_AMPERSAND:
- t->token++; /* continue; see if next thing is definitely a type */
+ ++t->token; /* continue; see if next thing is definitely a type */
goto continu;
default: {
int x = kw_to_builtin_type(t->token->kw);
if ((ret = x != -1)) {
- t->token++;
+ ++t->token;
}
break;
}
@@ -786,7 +786,7 @@ static bool parse_block(Parser *p, Block *b) {
return false;
}
b->start = t->token->where;
- t->token++; /* move past { */
+ ++t->token; /* move past { */
b->stmts = NULL;
bool ret = true;
b->ret_expr = NULL; /* default to no return unless overwritten later */
@@ -809,7 +809,7 @@ static bool parse_block(Parser *p, Block *b) {
}
}
b->end = t->token->where;
- t->token++; /* move past } */
+ ++t->token; /* move past } */
p->block = prev_block;
return ret;
}
@@ -830,7 +830,7 @@ static bool parse_decl_list(Parser *p, Declaration **decls, DeclEndKind decl_end
ret = false;
/* skip to end of list */
while (t->token->kind != TOKEN_EOF && !ends_decl(t->token, decl_end))
- t->token++;
+ ++t->token;
break;
}
}
@@ -848,16 +848,16 @@ static bool parse_fn_expr(Parser *p, FnExpr *f) {
}
/* only called when token is fn */
assert(token_is_kw(t->token, KW_FN));
- t->token++;
+ ++t->token;
if (!token_is_kw(t->token, KW_LPAREN)) {
tokr_err(t, "Expected '(' after 'fn'.");
return false;
}
- t->token++;
+ ++t->token;
f->params = NULL;
bool ret = true;
if (token_is_kw(t->token, KW_RPAREN)) {
- t->token++;
+ ++t->token;
} else {
if (!parse_decl_list(p, &f->params, DECL_END_RPAREN_COMMA))
return false;
@@ -883,7 +883,7 @@ static bool parse_fn_expr(Parser *p, FnExpr *f) {
return false;
}
}
- t->token--; /* move back to { */
+ --t->token; /* move back to { */
/* just set return type to void. the actual return type will be set by types.c:type_of_fn */
f->ret_type.kind = TYPE_VOID;
f->ret_type.flags = 0;
@@ -1025,7 +1025,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
case KW_IF: {
IfExpr *i = &e->if_;
e->kind = EXPR_IF;
- t->token++;
+ ++t->token;
Token *cond_end = expr_find_end(p, EXPR_CAN_END_WITH_LBRACE);
if (!cond_end) return false;
if (!token_is_kw(cond_end, KW_LBRACE)) {
@@ -1055,12 +1055,12 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
curr->next_elif = next;
IfExpr *nexti = &next->if_;
if (is_else) {
- t->token++;
+ ++t->token;
nexti->cond = NULL;
if (!parse_block(p, &nexti->body)) return false;
} else {
/* elif */
- t->token++;
+ ++t->token;
cond_end = expr_find_end(p, EXPR_CAN_END_WITH_LBRACE);
if (!cond_end) return false;
if (!token_is_kw(cond_end, KW_LBRACE)) {
@@ -1081,7 +1081,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
case KW_WHILE: {
e->kind = EXPR_WHILE;
WhileExpr *w = &e->while_;
- t->token++;
+ ++t->token;
if (token_is_kw(t->token, KW_LBRACE)) {
/* infinite loop */
w->cond = NULL;
@@ -1108,7 +1108,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
ea->flags = 0;
ea->value = NULL;
ea->index = NULL;
- t->token++;
+ ++t->token;
if (token_is_kw(t->token, KW_COLON)
|| (t->token->kind == TOKEN_IDENT
&& (token_is_kw(t->token + 1, KW_COLON)
@@ -1119,14 +1119,14 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
ea->value = t->token->ident;
if (ident_eq_str(ea->value, "_")) /* ignore value */
ea->value = NULL;
- t->token++;
+ ++t->token;
if (token_is_kw(t->token, KW_COMMA)) {
- t->token++;
+ ++t->token;
if (t->token->kind == TOKEN_IDENT) {
ea->index = t->token->ident;
if (ident_eq_str(ea->index, "_")) /* ignore index */
ea->index = NULL;
- t->token++;
+ ++t->token;
} else {
tokr_err(t, "Expected identifier after , in each statement.");
return false;
@@ -1141,7 +1141,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
tokr_err(t, "Expected : following identifiers in for statement.");
return false;
}
- t->token++;
+ ++t->token;
if (!token_is_kw(t->token, KW_EQ)) {
ea->flags |= EACH_ANNOTATED_TYPE;
if (!parse_type(p, &ea->type))
@@ -1151,7 +1151,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
return false;
}
}
- t->token++;
+ ++t->token;
}
Token *first_end = expr_find_end(p, EXPR_CAN_END_WITH_COMMA|EXPR_CAN_END_WITH_DOTDOT|EXPR_CAN_END_WITH_LBRACE);
Expression *first = parser_new_expr(p);
@@ -1164,7 +1164,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
ea->range.from = first;
if (token_is_kw(first_end, KW_COMMA)) {
/* step */
- t->token++;
+ ++t->token;
ea->range.step = parser_new_expr(p);
Token *step_end = expr_find_end(p, EXPR_CAN_END_WITH_LBRACE|EXPR_CAN_END_WITH_DOTDOT);
if (!parse_expr(p, ea->range.step, step_end))
@@ -1176,7 +1176,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
} else {
ea->range.step = NULL;
}
- t->token++; /* move past .. */
+ ++t->token; /* move past .. */
if (token_is_kw(t->token, KW_LBRACE)) {
ea->range.to = NULL; /* infinite loop! */
} else {
@@ -1213,14 +1213,14 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
/* e.g. (5+3) */
bool entirely_within_parentheses = token_is_kw(t->token, KW_LPAREN);
Token *lowest_precedence_op = NULL;
- for (Token *token = t->token; token < end; token++) {
+ for (Token *token = t->token; token < end; ++token) {
if (token->kind == TOKEN_KW) {
switch (token->kw) {
case KW_LPAREN:
- paren_level++;
+ ++paren_level;
break;
case KW_RPAREN:
- paren_level--;
+ --paren_level;
if (paren_level == 0 && token != end - 1)
entirely_within_parentheses = false;
if (paren_level < 0) {
@@ -1231,10 +1231,10 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
}
break;
case KW_LBRACE:
- brace_level++;
+ ++brace_level;
break;
case KW_RBRACE:
- brace_level--;
+ --brace_level;
if (brace_level < 0) {
t->token = token;
tokr_err(t, "Excessive closing }.");
@@ -1242,10 +1242,10 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
}
break;
case KW_LSQUARE:
- square_level++;
+ ++square_level;
break;
case KW_RSQUARE:
- square_level--;
+ --square_level;
if (square_level < 0) {
tokr_err(t, "Excessive closing ].");
return false;
@@ -1291,17 +1291,17 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
}
if (entirely_within_parentheses) {
- t->token++; /* move past opening ( */
+ ++t->token; /* move past opening ( */
if (token_is_kw(t->token, KW_RPAREN)) {
/* ()foo */
- t->token--;
+ --t->token;
tokr_err(t, "Stray () (maybe try wrapping the stuff before this in parentheses)");
return false;
}
Token *new_end = end - 1; /* parse to ending ) */
if (!parse_expr(p, e, new_end))
return false;
- t->token++; /* move past closing ) */
+ ++t->token; /* move past closing ) */
return true;
}
@@ -1311,7 +1311,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
while (lowest_precedence_op != t->token
&& lowest_precedence_op[-1].kind == TOKEN_KW
&& op_precedence(lowest_precedence_op[-1].kw) != NOT_AN_OP) {
- lowest_precedence_op--;
+ --lowest_precedence_op;
}
if (lowest_precedence_op == t->token) {
@@ -1321,7 +1321,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
switch (t->token->kw) {
case KW_PLUS:
/* unary + is ignored entirely */
- t->token++;
+ ++t->token;
/* re-parse this expression without + */
return parse_expr(p, e, end);
case KW_MINUS:
@@ -1338,15 +1338,15 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
break;
case KW_NEW:
e->kind = EXPR_NEW;
- t->token++;
+ ++t->token;
if (!token_is_kw(t->token, KW_LPAREN)) {
err_print(t->token->where, "Expected ( to follow new.");
}
- t->token++;
+ ++t->token;
if (!parse_type(p, &e->new.type)) return false;
if (token_is_kw(t->token, KW_COMMA)) {
/* new(int, 5) */
- t->token++;
+ ++t->token;
Token *n_end = expr_find_end(p, 0);
e->new.n = parser_new_expr(p);
if (!parse_expr(p, e->new.n, n_end))
@@ -1356,7 +1356,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
err_print(t->token->where, "Expected ).");
return false;
}
- t->token++;
+ ++t->token;
if (e->new.type.kind == TYPE_TUPLE) {
err_print(e->where, "You cannot new a tuple.");
return false;
@@ -1384,7 +1384,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
}
e->unary.op = op;
e->kind = EXPR_UNARY_OP;
- t->token++;
+ ++t->token;
Expression *of = parser_new_expr(p);
e->unary.of = of;
return parse_expr(p, of, end);
@@ -1511,13 +1511,13 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
being called with fn() {} as an argument
*/
if (token_is_kw(t->token, KW_LPAREN)) {
- paren_level++;
- token++;
+ ++paren_level;
+ ++token;
}
/* which opening bracket starts the call/array access */
Token *opening_bracket = NULL;
Token *closing_bracket = NULL;
- for (; token < end; token++) {
+ for (; token < end; ++token) {
if (token->kind == TOKEN_KW) {
switch (token->kw) {
case KW_LPAREN:
@@ -1526,28 +1526,28 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
&& token[-1].kind != TOKEN_DIRECT /* don't include directives */
&& !token_is_kw(&token[-1], KW_DOT)) /* or some_struct.("property") */
opening_bracket = token; /* maybe this left parenthesis opens the function call */
- paren_level++;
+ ++paren_level;
break;
case KW_LSQUARE:
if (square_level == 0 && paren_level == 0 && brace_level == 0)
opening_bracket = token; /* (array access) */
- square_level++;
+ ++square_level;
break;
case KW_RPAREN:
- paren_level--;
+ --paren_level;
if (opening_bracket && token_is_kw(opening_bracket, KW_LPAREN) && square_level == 0 && paren_level == 0 && brace_level == 0)
closing_bracket = token;
break;
case KW_RSQUARE:
- square_level--;
+ --square_level;
if (opening_bracket && token_is_kw(opening_bracket, KW_LSQUARE) && square_level == 0 && paren_level == 0 && brace_level == 0)
closing_bracket = token;
break;
case KW_LBRACE:
- brace_level++;
+ ++brace_level;
break;
case KW_RBRACE:
- brace_level--;
+ --brace_level;
break;
default: break;
}
@@ -1618,7 +1618,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
s->from = NULL;
}
assert(token_is_kw(t->token, KW_COLON));
- t->token++;
+ ++t->token;
if (token_is_kw(t->token, KW_RSQUARE)) {
/* e.g. x[5:] */
s->to = NULL;
@@ -1637,7 +1637,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
err_print(iend->where, "Expected ] or : after index.");
return false;
}
- t->token++; /* move past ] */
+ ++t->token; /* move past ] */
return true;
}
default:
@@ -1666,12 +1666,12 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
case DIRECT_COUNT: assert(0); break;
}
if (single_arg) {
- t->token++;
+ ++t->token;
if (!token_is_kw(t->token, KW_LPAREN)) {
err_print(t->token->where, "Expected ( to follow #%s.", directives[t->token->direct]);
return false;
}
- t->token++;
+ ++t->token;
Token *arg_end = expr_find_end(p, 0);
if (!token_is_kw(arg_end, KW_RPAREN)) {
err_print(end->where, "Expected ) at end of #%s directive.", directives[t->token->direct]);
@@ -1679,7 +1679,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
}
if (!parse_expr(p, single_arg, arg_end))
return false;
- t->token++;
+ ++t->token;
return true;
}
}
@@ -1739,19 +1739,19 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 fla
goto ret_false;
}
*ident = t->token->ident;
- t->token++;
+ ++t->token;
if (token_is_kw(t->token, KW_COMMA)) {
- t->token++;
+ ++t->token;
continue;
}
if (token_is_kw(t->token, KW_COLON)) {
- t->token++;
+ ++t->token;
break;
}
if (token_is_kw(t->token, KW_COLONCOLON)) {
- t->token++;
+ ++t->token;
if (token_is_kw(t->token, KW_COLON) && (flags & PARSE_DECL_ALLOW_SEMI_CONST)) {
- t->token++;
+ ++t->token;
d->flags |= DECL_SEMI_CONST;
} else {
d->flags |= DECL_IS_CONST;
@@ -1789,7 +1789,7 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 fla
}
if (token_is_kw(t->token, KW_EQ)) {
- t->token++;
+ ++t->token;
d->flags |= DECL_HAS_EXPR;
uint16_t expr_flags = 0;
if (ends_with == DECL_END_RPAREN_COMMA)
@@ -1807,20 +1807,20 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 fla
goto ret_false;
}
if (ends_decl(t->token, ends_with)) {
- t->token++;
+ ++t->token;
} else {
tokr_err(t, "Expected %s at end of declaration.", end_str);
goto ret_false;
}
} else if (ends_decl(t->token, ends_with)) {
- t->token++;
+ ++t->token;
} else {
tokr_err(t, "Expected %s or '=' at end of delaration.", end_str);
goto ret_false;
}
if ((d->flags & DECL_IS_CONST) && !(d->flags & DECL_HAS_EXPR) && !(flags & PARSE_DECL_ALLOW_CONST_WITH_NO_EXPR)) {
- t->token--;
+ --t->token;
/* disallowed constant without an expression, e.g. x :: int; */
tokr_err(t, "You must have an expression at the end of this constant declaration.");
goto ret_false;
@@ -1838,12 +1838,12 @@ static bool is_decl(Tokenizer *t) {
Token *token = t->token;
while (1) {
if (token->kind != TOKEN_IDENT) return false;
- token++;
+ ++token;
if (token->kind != TOKEN_KW) return false;
if (token->kw == KW_COLON || token->kw == KW_COLONCOLON)
return true;
if (token->kw != KW_COMMA) return false;
- token++;
+ ++token;
}
}
@@ -1857,17 +1857,17 @@ static bool parse_stmt(Parser *p, Statement *s) {
s->flags = 0;
if (token_is_kw(t->token, KW_RETURN)) {
s->kind = STMT_RET;
- t->token++;
+ ++t->token;
s->ret.flags = 0;
if (token_is_kw(t->token, KW_SEMICOLON)) {
/* return with no expr */
- t->token++;
+ ++t->token;
return true;
}
s->ret.flags |= RET_HAS_EXPR;
Token *end = expr_find_end(p, 0);
if (!end) {
- while (t->token->kind != TOKEN_EOF) t->token++; /* move to end of file */
+ while (t->token->kind != TOKEN_EOF) ++t->token; /* move to end of file */
return false;
}
if (!token_is_kw(end, KW_SEMICOLON)) {
@@ -1891,7 +1891,7 @@ static bool parse_stmt(Parser *p, Statement *s) {
Token *end = expr_find_end(p, 0);
if (!end) {
tokr_err(t, "No semicolon found at end of statement.");
- while (t->token->kind != TOKEN_EOF) t->token++; /* move to end of file */
+ while (t->token->kind != TOKEN_EOF) ++t->token; /* move to end of file */
return false;
}
@@ -2222,7 +2222,7 @@ static int decl_ident_index(Declaration *d, Identifier i) {
arr_foreach(d->idents, Identifier, j) {
if (i == *j)
return idx;
- idx++;
+ ++idx;
}
return -1;
}
diff --git a/str.c b/str.c
index b5e326d..e659dc2 100644
--- a/str.c
+++ b/str.c
@@ -21,7 +21,7 @@ size_t str_copy(char *dest, size_t destsz, const char *src) {
*dest = 0;
return i;
}
- src++; dest++;
+ ++src; ++dest;
}
dest[destsz-1] = 0;
return destsz-1;
diff --git a/test.toc b/test.toc
index 9dd03c5..a24df5a 100644
--- a/test.toc
+++ b/test.toc
@@ -5,3 +5,4 @@ f ::= fn(y:f64=19.2, x :f64=3.4) f64 {
main ::= fn() {
f(y = 13, 23);
};
+// \ No newline at end of file
diff --git a/tokenizer.c b/tokenizer.c
index 6a3c136..2841961 100644
--- a/tokenizer.c
+++ b/tokenizer.c
@@ -150,11 +150,11 @@ static void tokenization_err(Tokenizer *t, const char *fmt, ...) {
char *end_of_line = strchr(t->s, '\n');
if (end_of_line) {
t->s = end_of_line;
- t->s++; /* move past newline */
+ ++t->s; /* move past newline */
} else {
t->s = strchr(t->s, '\0');
}
- t->line++;
+ ++t->line;
}
/* to be used after tokenization */
@@ -229,7 +229,7 @@ static bool tokenize_string(Tokenizer *t, char *str) {
switch (t->s[1]) {
case '/': /* single line comment */
tokr_nextchar(t);
- for (t->s++; *t->s && *t->s != '\n'; t->s++);
+ while (*t->s && *t->s != '\n') ++t->s;
if (*t->s) tokr_nextchar(t); /* skip newline */
break;
case '*': { /* multi line comment */
@@ -238,13 +238,13 @@ static bool tokenize_string(Tokenizer *t, char *str) {
while (*t->s) {
if (t->s[0] == '*' && t->s[1] == '/') {
t->s += 2;
- comment_level--;
+ --comment_level;
if (comment_level == 0) {
break;
}
} else if (t->s[0] == '/' && t->s[1] == '*') {
t->s += 2;
- comment_level++;
+ ++comment_level;
} else {
tokr_nextchar(t);
}
@@ -264,7 +264,7 @@ static bool tokenize_string(Tokenizer *t, char *str) {
if (*t->s == '#') {
/* it's a directive */
char *start_s = t->s;
- t->s++; /* move past # */
+ ++t->s; /* move past # */
Directive direct = tokenize_direct(&t->s);
if (direct != DIRECT_COUNT) {
/* it's a directive */
@@ -275,7 +275,7 @@ static bool tokenize_string(Tokenizer *t, char *str) {
token->direct = direct;
continue;
}
- t->s--; /* go back to # */
+ --t->s; /* go back to # */
tokenization_err(t, "Unrecognized directive.");
goto err;
}
@@ -456,7 +456,7 @@ static bool tokenize_string(Tokenizer *t, char *str) {
size_t backslashes = 0;
while (*t->s != '"' || backslashes % 2 == 1) {
if (*t->s == '\\') {
- backslashes++;
+ ++backslashes;
} else if (*t->s == 0) {
/* return t to opening " so that we go to the next line */
tokr_get_location(t, token);
@@ -465,7 +465,7 @@ static bool tokenize_string(Tokenizer *t, char *str) {
} else {
backslashes = 0;
}
- len++;
+ ++len;
tokr_nextchar(t);
}
char *strlit = tokr_malloc(t, len + 1);
@@ -522,17 +522,17 @@ static void tokr_skip_semicolon(Tokenizer *t) {
int brace_level = 0;
while (t->token->kind != TOKEN_EOF) {
if (t->token->kind == TOKEN_KW) switch (t->token->kw) {
- case KW_LBRACE: brace_level++; break;
- case KW_RBRACE: brace_level--; break;
+ case KW_LBRACE: ++brace_level; break;
+ case KW_RBRACE: --brace_level; break;
case KW_SEMICOLON:
if (brace_level == 0) {
- t->token++;
+ ++t->token;
return;
}
break;
default: break;
}
- t->token++;
+ ++t->token;
}
}
diff --git a/typedefs_cgen.c b/typedefs_cgen.c
index 7d0be28..3896686 100644
--- a/typedefs_cgen.c
+++ b/typedefs_cgen.c
@@ -46,7 +46,7 @@ static bool typedefs_decl(CGenerator *g, Declaration *d) {
if (cgen_fn_is_direct(g, d)) {
d->expr.fn.c.name = d->idents[0];
}
- for (int idx = 0; idx < (int)arr_len(d->idents); idx++) {
+ for (int idx = 0; idx < (int)arr_len(d->idents); ++idx) {
Identifier i = d->idents[idx];
Type *type = decl_type_at_index(d, idx);
Value *val = decl_val_at_index(d, idx);
diff --git a/types.c b/types.c
index 1ca20e0..27fd838 100644
--- a/types.c
+++ b/types.c
@@ -226,7 +226,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags)
tr->fn = f;
size_t nparams = arr_len(f->params);
entered_fn = true;
- for (param_idx = 0; param_idx < nparams; param_idx++) {
+ for (param_idx = 0; param_idx < nparams; ++param_idx) {
Declaration *param = &f->params[param_idx];
if (!generic) {
if (!types_decl(tr, param)) {
@@ -287,7 +287,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags)
}
*(Constness *)typer_arr_add(tr, &t->fn.constness) = constn;
}
- idx++;
+ ++idx;
}
if (param->flags & DECL_IS_CONST) {
@@ -365,7 +365,7 @@ static bool type_of_ident(Typer *tr, Location where, Identifier i, Type *t) {
bool captured = false;
if (decl->scope != NULL) {
/* go back through scopes */
- for (Block **block = arr_last(tr->blocks); *block && *block != decl->scope; block--) {
+ for (Block **block = arr_last(tr->blocks); *block && *block != decl->scope; --block) {
if ((*block)->flags & BLOCK_IS_FN) {
captured = true;
break;
@@ -1173,8 +1173,8 @@ static bool types_expr(Typer *tr, Expression *e) {
}
}
}
- ident_idx++;
- index++;
+ ++ident_idx;
+ ++index;
}
}
}
@@ -1258,12 +1258,12 @@ static bool types_expr(Typer *tr, Expression *e) {
*which_are_const |= ((U64)1) << semi_const_index;
}
if (fn_type->constness[i] == CONSTNESS_SEMI) {
- semi_const_index++;
+ ++semi_const_index;
}
- ident_idx++;
+ ++ident_idx;
if (ident_idx >= arr_len(param_decl->idents)) {
ident_idx = 0;
- param_decl++;
+ ++param_decl;
}
}
/* type param declarations, etc */
@@ -1285,7 +1285,7 @@ static bool types_expr(Typer *tr, Expression *e) {
copy_val(tr->allocr, arg_val, &param->expr.val, &param->expr.type);
table_index_type.tuple[i+1] = param->expr.type;
}
- i++;
+ ++i;
}
}
@@ -1294,7 +1294,7 @@ static bool types_expr(Typer *tr, Expression *e) {
}
/* check types of arguments */
- for (size_t p = 0; p < nparams; p++) {
+ for (size_t p = 0; p < nparams; ++p) {
Expression *arg = &arg_exprs[p];
Type *expected = &param_types[p];
Type *got = &arg->type;
@@ -1866,7 +1866,7 @@ static bool types_decl(Typer *tr, Declaration *d) {
}
}
} else if (!(d->flags & DECL_IS_CONST) && t->kind == TYPE_FN && t->fn.constness) {
- for (size_t p = 0; p < arr_len(t->fn.types)-1; p++) {
+ for (size_t p = 0; p < arr_len(t->fn.types)-1; ++p) {
if (t->fn.constness[p] == CONSTNESS_YES) {
err_print(d->where, "You can't have a pointer to a function with constant parameters.");
success = false;