diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-07 21:43:34 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-07 21:43:34 -0500 |
commit | 5f3c455003272bfca6769afcaaade1ca365038d9 (patch) | |
tree | 292a149deef3761f769aa47b2d704403544bee7a | |
parent | 0bd0b45ae59e559d88bdc908b8bab8401eb41a30 (diff) |
formatting (emacs doesnt like my tabs)
-rw-r--r-- | blockarr.c | 2 | ||||
-rw-r--r-- | cgen.c | 24 | ||||
-rw-r--r-- | eval.c | 8 | ||||
-rw-r--r-- | infer.c | 10 | ||||
-rw-r--r-- | instance_table.c | 8 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | package.c | 6 | ||||
-rw-r--r-- | parse.c | 34 | ||||
-rw-r--r-- | tokenizer.c | 12 | ||||
-rw-r--r-- | types.c | 22 | ||||
-rw-r--r-- | types.h | 14 |
11 files changed, 71 insertions, 71 deletions
@@ -72,7 +72,7 @@ static void block_arr_test(void) { ps[i] = p; } for (int i = 0; i < 100; ++i) { - assert(*ps[i] == i); + assert(*ps[i] == i); } block_arr_free(&a); } @@ -348,7 +348,7 @@ static bool cgen_type_post(CGenerator *g, Type *t, Location where) { break; case TYPE_ARR: assert(t->flags & TYPE_IS_RESOLVED); - cgen_write(g, "[%lu])", (unsigned long)t->arr.n); + cgen_write(g, "[%lu])", (unsigned long)t->arr.n); if (!cgen_type_post(g, t->arr.of, where)) return false; break; @@ -622,7 +622,7 @@ static bool cgen_set(CGenerator *g, Expression *set_expr, const char *set_str, E case TYPE_TUPLE: assert(set_expr); assert(to_expr); - assert(set_expr->kind == EXPR_TUPLE); + assert(set_expr->kind == EXPR_TUPLE); if (!cgen_set_tuple(g, set_expr->tuple, NULL, NULL, to_expr)) return false; break; @@ -699,7 +699,7 @@ static bool cgen_set_tuple(CGenerator *g, Expression *exprs, Identifier *idents, cgen_writeln(g, "); "); } break; case EXPR_IF: - prefix_id = to->if_.c.id; + prefix_id = to->if_.c.id; goto prefixed; case EXPR_BLOCK: prefix_id = to->block_ret_id; @@ -726,7 +726,7 @@ static bool cgen_set_tuple(CGenerator *g, Expression *exprs, Identifier *idents, cgen_write(g, "%lu_", i); cgen_write(g, "; "); } - break; + break; /* things which can never be tuples */ case EXPR_SLICE: @@ -830,7 +830,7 @@ static bool cgen_expr_pre(CGenerator *g, Expression *e) { } else { if (!cgen_expr_pre(g, ea->of)) return false; } - + ea->c.id = id; if (!each_enter(e)) return false; cgen_write(g, "{"); @@ -1017,7 +1017,7 @@ static bool cgen_expr_pre(CGenerator *g, Expression *e) { case EXPR_CALL: { if (!cgen_expr_pre(g, e->call.fn)) return false; int i = 0; - Constness *constness = e->call.fn->type.fn.constness; + Constness *constness = e->call.fn->type.fn.constness; arr_foreach(e->call.arg_exprs, Expression, arg) { if (!constness || !arg_is_const(arg, constness[i])) { if (!cgen_expr_pre(g, arg)) return false; @@ -1070,7 +1070,7 @@ static bool cgen_expr_pre(CGenerator *g, Expression *e) { break; case EXPR_SLICE: { SliceExpr *s = &e->slice; - IdentID s_id = e->slice.c.id = ++g->ident_counter; + IdentID s_id = e->slice.c.id = ++g->ident_counter; IdentID from_id = ++g->ident_counter; if (!cgen_expr_pre(g, s->of)) return false; @@ -1407,7 +1407,7 @@ static bool cgen_expr(CGenerator *g, Expression *e) { } cgen_write(g, "("); bool first_arg = true; - int i = 0; + int i = 0; arr_foreach(e->call.arg_exprs, Expression, arg) { if (!fn_type->constness || !arg_is_const(arg, fn_type->constness[i])) { if (!first_arg) @@ -1599,7 +1599,7 @@ static bool cgen_fn(CGenerator *g, FnExpr *f, Location where, U64 instance, Valu /* long-winded code to generate a return expression using the ret_decls. */ Expression ret_expr; ret_expr.flags = EXPR_FOUND_TYPE; - ret_expr.type = f->ret_type; + ret_expr.type = f->ret_type; if (arr_len(f->ret_decls) == 1 && arr_len(f->ret_decls[0].idents) == 1) { ret_expr.kind = EXPR_IDENT; @@ -1677,7 +1677,7 @@ static bool cgen_val_ptr_pre(CGenerator *g, void *v, Type *t, Location where) { case TYPE_EXPR: case TYPE_PKG: assert(0); - return false; + return false; } return true; } @@ -1759,7 +1759,7 @@ static bool cgen_decl(CGenerator *g, Declaration *d) { if (d->flags & DECL_FOUND_VAL) { /* declarations where we use a value */ for (int idx = 0, nidents = (int)arr_len(d->idents); idx < nidents; ++idx) { - Identifier i = d->idents[idx]; + Identifier i = d->idents[idx]; Type *type = decl_type_at_index(d, idx); Value *val = decl_val_at_index(d, idx); if (type_contains_compileonly_type(type)) { @@ -1799,7 +1799,7 @@ static bool cgen_decl(CGenerator *g, Declaration *d) { if (!cgen_type_post(g, type, d->where)) return false; if (!has_expr) { cgen_write(g, " = "); - cgen_zero_value(g, type); + cgen_zero_value(g, type); } cgen_write(g, "; "); @@ -1187,7 +1187,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { if (ea->range.stepval) stepval = *ea->range.stepval; Value x = from; - Value *index_val; + Value *index_val; Value *value_val; if (!each_enter(e)) return false; if (ea->index) { @@ -1261,13 +1261,13 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { case TYPE_ARR: len = (I64)of_type->arr.n; if (uses_ptr) { - of.arr = of.ptr; + of.arr = of.ptr; } break; case TYPE_SLICE: if (uses_ptr) { - of.slice = *(Slice *)of.ptr; + of.slice = *(Slice *)of.ptr; } len = of.slice.n; break; @@ -1466,7 +1466,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { } break; case EXPR_SLICE: { SliceExpr *s = &e->slice; - Value ofv; + Value ofv; Type *of_type = &s->of->type; if (!eval_expr(ev, s->of, &ofv)) return false; @@ -24,7 +24,7 @@ static bool infer_from_expr(Typer *tr, Expression *match, Expression *to, Expres break; case EXPR_CALL: { while (to->kind == EXPR_IDENT) { - IdentDecl *idecl = ident_decl(to->ident); + IdentDecl *idecl = ident_decl(to->ident); if (idecl->kind == IDECL_DECL) { Declaration *decl = idecl->decl; int index = ident_index_in_decl(to->ident, decl); @@ -46,7 +46,7 @@ static bool infer_from_expr(Typer *tr, Expression *match, Expression *to, Expres U16 *order = NULL; Expression *f = match->call.fn; - IdentDecl *idecl = ident_decl(f->ident); + IdentDecl *idecl = ident_decl(f->ident); bool is_direct_fn = idecl && idecl->kind == IDECL_DECL && (idecl->decl->flags & DECL_HAS_EXPR) && idecl->decl->expr.kind == EXPR_FN; if (is_direct_fn) { if (!types_expr(tr, f)) @@ -89,7 +89,7 @@ static bool infer_from_type(Typer *tr, Type *match, Type *to, Identifier *idents case TYPE_TUPLE: { if (to->kind != TYPE_TUPLE) return true; if (arr_len(match->tuple) != arr_len(to->tuple)) return true; - Type *b = to->tuple; + Type *b = to->tuple; arr_foreach(match->tuple, Type, a) { if (!infer_from_type(tr, a, b, idents, vals, types)) return false; @@ -102,7 +102,7 @@ static bool infer_from_type(Typer *tr, Type *match, Type *to, Identifier *idents } if (to->kind != TYPE_FN) return true; if (arr_len(match->fn.types) != arr_len(to->fn.types)) return true; - size_t i, len = arr_len(match->fn.types); + size_t i, len = arr_len(match->fn.types); for (i = 0; i < len; ++i) { if (!infer_from_type(tr, &match->fn.types[i], &to->fn.types[i], idents, vals, types)) return false; @@ -112,7 +112,7 @@ static bool infer_from_type(Typer *tr, Type *match, Type *to, Identifier *idents if (to->kind != TYPE_PTR) return true; if (!infer_from_type(tr, match->ptr, to->ptr, idents, vals, types)) return false; - break; + break; case TYPE_SLICE: if (to->kind != TYPE_SLICE) return true; if (!infer_from_type(tr, match->slice, to->slice, idents, vals, types)) diff --git a/instance_table.c b/instance_table.c index aeb72d3..b2a4c01 100644 --- a/instance_table.c +++ b/instance_table.c @@ -239,11 +239,11 @@ static bool val_ptr_eq(void *u, void *v, Type *t) { case TYPE_TUPLE: { Value *us = *(Value **)u; Value *vs = *(Value **)v; - for (size_t i = 0, len = arr_len(t->tuple); i < len; ++i) { + for (size_t i = 0, len = arr_len(t->tuple); i < len; ++i) { if (!val_eq(us[i], vs[i], &t->tuple[i])) return false; } - return true; + return true; } case TYPE_ARR: { U64 size = (U64)compiler_sizeof(t->arr.of); @@ -275,7 +275,7 @@ static bool val_ptr_eq(void *u, void *v, Type *t) { if (!val_ptr_eq((char *)u + f->offset, (char *)v + f->offset, f->type)) return false; } - return true; + return true; case TYPE_PKG: return *(Package **)u == *(Package **)v; case TYPE_EXPR: break; @@ -311,7 +311,7 @@ static Instance *instance_table_adda(Allocator *a, HashTable *h, Value v, Type * index -= new_cap; } new_data[index] = old_data[i]; - new_occupied[index] = true; + new_occupied[index] = true; } } h->data = new_data; @@ -126,7 +126,7 @@ int main(int argc, char **argv) { if (!types_file(&tr, &f, contents)) { /* TODO(eventually): fix this if the error occured while exporting something */ - err_fprint(TEXT_IMPORTANT("Errors occured while determining types.\n")); + err_fprint(TEXT_IMPORTANT("Errors occured while determining types.\n")); return EXIT_FAILURE; } #ifdef TOC_DEBUG @@ -160,7 +160,7 @@ static bool export_type(Exporter *ex, Type *type, Location where) { case TYPE_STRUCT: { StructDef *struc = type->struc; if (struc->export.id == 0) { - StructDef **ptr = arr_add(&ex->exported_structs); + StructDef **ptr = arr_add(&ex->exported_structs); *ptr = struc; size_t nexported_structs = arr_len(ex->exported_structs); if (nexported_structs > U32_MAX) { @@ -268,7 +268,7 @@ static bool export_val_ptr(Exporter *ex, void *val, Type *type, Location where) case TYPE_UNKNOWN: case TYPE_EXPR: assert(0); - return false; + return false; } return true; } @@ -325,7 +325,7 @@ static bool export_expr(Exporter *ex, Expression *e) { assert(e->c.code->kind == EXPR_VAL); if (!export_val(ex, e->c.code->val, &e->c.code->type, e->where)) return false; - break; + break; case EXPR_IDENT: export_ident(ex, e->ident); break; @@ -337,7 +337,7 @@ static Token *expr_find_end(Parser *p, ExprEndFlags flags) { ++square_level; break; case KW_RSQUARE: - --square_level; + --square_level; if (square_level < 0) return token; break; @@ -418,7 +418,7 @@ static bool parse_args(Parser *p, Argument **args) { arg->where = t->token->where; /* named arguments */ if (t->token->kind == TOKEN_IDENT && token_is_kw(t->token + 1, KW_EQ)) { - arg->name = t->token->ident; + arg->name = t->token->ident; t->token += 2; } else { arg->name = NULL; @@ -443,7 +443,7 @@ static bool parse_type(Parser *p, Type *type) { switch (t->token->kind) { case TOKEN_KW: type->kind = TYPE_BUILTIN; - { + { int b = kw_to_builtin_type(t->token->kw); if (b != -1) { type->builtin = (BuiltinType)b; @@ -534,7 +534,7 @@ static bool parse_type(Parser *p, Type *type) { case KW_LT: /* tuple! */ type->kind = TYPE_TUPLE; - type->tuple = NULL; + type->tuple = NULL; ++t->token; /* move past < */ while (1) { Type *child = parser_arr_add(p, &type->tuple); @@ -665,7 +665,7 @@ static bool parser_is_definitely_type(Parser *p, Token **end) { ++t->token; } } - break; + break; case KW_LSQUARE: ret = true; if (end) { @@ -720,14 +720,14 @@ static bool parser_is_definitely_type(Parser *p, Token **end) { /* TODO: think of a better way of determining if it's a void fn type. (maybe followed by ;/,/)?)*/ bool *enabled = &t->token->where.ctx->enabled; bool prev_enabled = *enabled; - *enabled = false; + *enabled = false; if (!parse_type(p, &return_type)) { /* couldn't parse a return type. void fn type */ *enabled = prev_enabled; ret = true; goto end; } - *enabled = prev_enabled; + *enabled = prev_enabled; if (token_is_kw(t->token, KW_LBRACE)) { /* non-void fn expr */ goto end; @@ -747,7 +747,7 @@ static bool parser_is_definitely_type(Parser *p, Token **end) { goto continu; default: { int x = kw_to_builtin_type(t->token->kw); - if ((ret = x != -1)) { + if ((ret = x != -1)) { ++t->token; } break; @@ -860,7 +860,7 @@ static bool parse_fn_expr(Parser *p, FnExpr *f) { ++t->token; } else { if (!parse_decl_list(p, &f->params, DECL_END_RPAREN_COMMA)) - return false; + return false; arr_foreach(f->params, Declaration, param) param->flags |= DECL_IS_PARAM; } @@ -978,7 +978,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) { case TOKEN_LITERAL_STR: e->kind = EXPR_LITERAL_STR; e->strl = t->token->str; - break; + break; case TOKEN_LITERAL_CHAR: e->kind = EXPR_LITERAL_CHAR; e->charl = t->token->chr; @@ -1109,7 +1109,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) { return false; } if (!parse_block(p, &w->body)) return false; - return true; + return true; } case KW_EACH: { e->kind = EXPR_EACH; @@ -1174,7 +1174,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) { if (token_is_kw(first_end, KW_COMMA)) { /* step */ ++t->token; - ea->range.step = parser_new_expr(p); + 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)) return false; @@ -1648,7 +1648,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) { return false; } ++t->token; /* move past ] */ - return true; + return true; } default: assert(0); @@ -1675,7 +1675,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) { break; case DIRECT_EXPORT: err_print(t->token->where, "Unrecognized expression."); - return false; + return false; case DIRECT_COUNT: assert(0); break; } if (single_arg) { @@ -1863,7 +1863,7 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 fla --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; + goto ret_false; } return true; @@ -1973,7 +1973,7 @@ static bool parse_stmt(Parser *p, Statement *s, bool *was_a_statement) { return false; } - bool success = parse_expr(p, &s->expr, end); + bool success = parse_expr(p, &s->expr, end); /* go past end of expr regardless of whether successful or not */ if (token_is_kw(end, KW_SEMICOLON)) { @@ -2144,7 +2144,7 @@ static void fprint_expr(FILE *out, Expression *e) { fprint_expr(out, e->if_.next_elif); break; case EXPR_WHILE: - fprintf(out, "while "); + fprintf(out, "while "); if (e->while_.cond) fprint_expr(out, e->while_.cond); fprint_block(out, &e->while_.body); break; diff --git a/tokenizer.c b/tokenizer.c index 97c856f..fd1d2d7 100644 --- a/tokenizer.c +++ b/tokenizer.c @@ -229,7 +229,7 @@ static bool tokenize_string(Tokenizer *t, char *str) { if (*t->s == 0) break; if (isspace(*t->s)) { tokr_nextchar(t); - continue; + continue; } if (*t->s == '/') { @@ -244,7 +244,7 @@ static bool tokenize_string(Tokenizer *t, char *str) { case '*': { /* multi line comment */ tokr_nextchar(t); int comment_level = 1; /* allow nested multi-line comments */ - while (1) { + while (1) { if (t->s[0] == '*' && t->s[1] == '/') { t->s += 2; --comment_level; @@ -275,7 +275,7 @@ static bool tokenize_string(Tokenizer *t, char *str) { /* it's a directive */ char *start_s = t->s; ++t->s; /* move past # */ - Directive direct = tokenize_direct(&t->s); + Directive direct = tokenize_direct(&t->s); if (direct != DIRECT_COUNT) { /* it's a directive */ Token *token = tokr_add(t); @@ -351,7 +351,7 @@ static bool tokenize_string(Tokenizer *t, char *str) { tokenization_err(t, "Decimal point in non base 10 number."); goto err; } - n->kind = NUM_LITERAL_FLOAT; + n->kind = NUM_LITERAL_FLOAT; decimal_pow10 = 0.1; n->floatval = (Floating)n->intval; tokr_nextchar(t); @@ -424,7 +424,7 @@ static bool tokenize_string(Tokenizer *t, char *str) { } tokr_nextchar(t); } - + token->kind = TOKEN_LITERAL_NUM; continue; } @@ -479,7 +479,7 @@ static bool tokenize_string(Tokenizer *t, char *str) { tokr_nextchar(t); } char *strlit = tokr_malloc(t, len + 1); - char *strptr = strlit; + char *strptr = strlit; tokr_get_location(t, token); tokr_nextchar(t); /* past opening " */ while (*t->s != '"') { @@ -157,7 +157,7 @@ static bool expr_must_lval(Expression *e) { default: break; } err_print(e->where, "Cannot use operator %s as l-value.", binary_op_to_str(e->binary.op)); - return false; + return false; case EXPR_TUPLE: /* x, y is an lval, but 3, "hello" is not. */ arr_foreach(e->tuple, Expression, x) { @@ -302,7 +302,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Type *t, U16 flags) { arr_foreach(f->ret_decls, Declaration, d) { if (!types_decl(tr, d)) { - success = false; + success = false; goto ret; } } @@ -478,7 +478,7 @@ static bool type_resolve(Typer *tr, Type *t, Location where) { U64 size; if (type_builtin_is_signed(n_expr->type.builtin)) { - I64 ssize = val_to_i64(&val, n_expr->type.builtin); + I64 ssize = val_to_i64(&val, n_expr->type.builtin); if (ssize < 0) { err_print(t->arr.n_expr->where, "Negative array length (" I64_FMT ")", ssize); return false; @@ -640,7 +640,7 @@ static Status type_cast_status(Type *from, Type *to) { case TYPE_SLICE: if (to->kind == TYPE_PTR && type_eq(from->slice, to->ptr)) return STATUS_NONE; - return STATUS_ERR; + return STATUS_ERR; case TYPE_EXPR: break; } @@ -829,7 +829,7 @@ static bool types_expr(Typer *tr, Expression *e) { } } break; case EXPR_LITERAL_INT: - t->kind = TYPE_BUILTIN; + t->kind = TYPE_BUILTIN; t->builtin = BUILTIN_I64; t->flags |= TYPE_IS_FLEXIBLE; break; @@ -933,7 +933,7 @@ static bool types_expr(Typer *tr, Expression *e) { } if (!(ea->flags & EACH_ANNOTATED_TYPE)) { - ea->type = ea->range.from->type; + ea->type = ea->range.from->type; } if (!type_eq(&ea->type, &ea->range.from->type)) { @@ -1200,7 +1200,7 @@ static bool types_expr(Typer *tr, Expression *e) { if (params_set[idx]) { Declaration *param = fn_decl->params; Identifier *ident; - for (Declaration *end = arr_end(fn_decl->params); param < end; ++param) { + for (Declaration *end = arr_end(fn_decl->params); param < end; ++param) { ident = param->idents; for (Identifier *iend = arr_end(param->idents); ident != iend; ++ident) { if (idx == 0) @@ -1283,7 +1283,7 @@ static bool types_expr(Typer *tr, Expression *e) { FnExpr *fn = fn_val.fn; /* fn is the instance, original_fn is not */ - original_fn = fn; + original_fn = fn; copy_fn_expr(&cop, &fn_copy, fn, false); fn = &fn_copy; @@ -1380,7 +1380,7 @@ static bool types_expr(Typer *tr, Expression *e) { u64t->builtin = BUILTIN_U64; table_index.tuple = NULL; /* we need to keep table_index's memory around because instance_table_add makes a copy of it to compare against. */ - Value *which_are_const_val = typer_arr_add(tr, &table_index.tuple); + Value *which_are_const_val = typer_arr_add(tr, &table_index.tuple); U64 *which_are_const = &which_are_const_val->u64; *which_are_const = 0; int semi_const_index = 0; @@ -1670,7 +1670,7 @@ static bool types_expr(Typer *tr, Expression *e) { bool valid = false; assert(lhs_type->flags & TYPE_IS_RESOLVED); assert(rhs_type->flags & TYPE_IS_RESOLVED); - + if (o == BINARY_SET) { valid = type_eq(lhs_type, rhs_type); @@ -2185,7 +2185,7 @@ static bool types_file(Typer *tr, ParsedFile *f, char *code) { err_print(f->pkg_name->where, "Package name has a negative length (" I64_FMT ")!", pkg_name_slice.n); return false; } - size_t pkg_name_len = (size_t)pkg_name_slice.n; + size_t pkg_name_len = (size_t)pkg_name_slice.n; char *pkg_name_cstr = typer_malloc(tr, pkg_name_len+1); memcpy(pkg_name_cstr, pkg_name_str, pkg_name_len); @@ -408,17 +408,17 @@ typedef struct Type { TypeFlags flags; struct Expression *was_expr; /* if non-NULL, indicates that this type used to be an expression (TYPE_EXPR) */ union { - BuiltinType builtin; + BuiltinType builtin; FnType fn; struct Type *tuple; struct { struct Type *of; union { - U64 n; /* after resolving */ + U64 n; /* after resolving */ struct Expression *n_expr; /* before resolving */ }; } arr; - struct Type *ptr; + struct Type *ptr; struct Type *slice; StructDef *struc; /* it's a pointer so that multiple Types can reference the same struct definition */ struct Expression *expr; @@ -501,7 +501,7 @@ typedef enum { typedef struct CallExpr { struct Expression *fn; union { - struct Argument *args; + struct Argument *args; struct Expression *arg_exprs; }; struct Instance *instance; /* NULL = ordinary function, no compile time args */ @@ -574,7 +574,7 @@ typedef struct FnExpr { struct { /* if name = NULL, this is an anonymous function, and id will be the ID of the fn. */ Identifier name; - IdentID id; + IdentID id; } c; } FnExpr; /* an expression such as fn(x: int) int { 2 * x } */ @@ -582,7 +582,7 @@ typedef struct Instance { Value val; /* key into hash table */ FnExpr fn; /* the typed function */ struct { - U64 id; + U64 id; } c; } Instance; @@ -652,7 +652,7 @@ typedef struct Expression { } pkg; IfExpr if_; WhileExpr while_; - EachExpr *each; + EachExpr *each; FnExpr *fn; CastExpr cast; SliceExpr slice; |