summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-01-04 17:18:46 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-01-04 17:18:46 -0500
commit8741d955a1ebdbcb60cc5141c6e8eaa0f6415471 (patch)
tree450ef9c80b0bb06ca61597d955c08ca733805caa
parentcd9d0a7c5e4ec6cefdd2a67b263d04f2e24f7708 (diff)
formatting
-rw-r--r--allocator.c2
-rw-r--r--arr.c4
-rw-r--r--binfile.c6
-rw-r--r--cgen.c4
-rw-r--r--copy.c2
-rw-r--r--err.c2
-rw-r--r--eval.c4
-rw-r--r--identifiers.c2
-rw-r--r--infer.c2
-rw-r--r--main.c3
-rw-r--r--package.c2
-rw-r--r--parse.c13
-rw-r--r--scope.c2
-rw-r--r--tokenizer.c6
-rw-r--r--types.c10
-rw-r--r--types.h24
16 files changed, 41 insertions, 47 deletions
diff --git a/allocator.c b/allocator.c
index 2fc607d..adf67c5 100644
--- a/allocator.c
+++ b/allocator.c
@@ -85,7 +85,7 @@ static void *allocr_realloc(Allocator *a, void *data, size_t old_size, size_t ne
return NULL;
}
if (a == NULL) return err_realloc(data, new_size);
- void *ret = allocr_malloc(a, new_size);
+ void *ret = allocr_malloc(a, new_size);
memcpy(ret, data, old_size);
return ret;
}
diff --git a/arr.c b/arr.c
index 400210a..c6591d9 100644
--- a/arr.c
+++ b/arr.c
@@ -83,7 +83,7 @@ static void arr_set_lena_(void **arr, size_t n, size_t item_sz, Allocator *a) {
static void *arr_add_(void **arr, size_t item_sz) {
ArrHeader *hdr;
- if (*arr == NULL) {
+ if (*arr == NULL) {
arr_resv_(arr, 10, item_sz);
hdr = arr_hdr(*arr);
} else {
@@ -97,7 +97,7 @@ static void *arr_add_(void **arr, size_t item_sz) {
}
static void *arr_adda_(void **arr, size_t item_sz, Allocator *a) {
ArrHeader *hdr;
- if (*arr == NULL) {
+ if (*arr == NULL) {
arr_resva_(arr, 10, item_sz, a);
hdr = arr_hdr(*arr);
} else {
diff --git a/binfile.c b/binfile.c
index 33d5757..5ee6aeb 100644
--- a/binfile.c
+++ b/binfile.c
@@ -36,12 +36,12 @@ static inline void write_u16(FILE *fp, U16 u16) {
}
static inline void write_i16(FILE *fp, I16 i16) {
- write_u16(fp, (U16)i16);
+ write_u16(fp, (U16)i16);
}
static inline void write_u32(FILE *fp, U32 u32) {
write_u16(fp, u32 & 0xFFFF);
- write_u16(fp, (U16)(u32 >> 16));
+ write_u16(fp, (U16)(u32 >> 16));
}
static inline void write_i32(FILE *fp, I32 i32) {
@@ -163,5 +163,5 @@ static void write_vlq(FILE *fp, U64 x) {
write_u8(fp, (U8)(x & 0x7f) | 0x80);
x >>= 7;
}
- write_u8(fp, (U8)x);
+ write_u8(fp, (U8)x);
}
diff --git a/cgen.c b/cgen.c
index b5282e1..15b7b24 100644
--- a/cgen.c
+++ b/cgen.c
@@ -712,7 +712,7 @@ static bool cgen_set_tuple(CGenerator *g, Expression *exprs, Identifier *idents,
}
break;
case EXPR_SLICE:
- case EXPR_IDENT:
+ case EXPR_IDENT:
case EXPR_LITERAL_INT:
case EXPR_LITERAL_CHAR:
case EXPR_LITERAL_BOOL:
@@ -1905,7 +1905,7 @@ static bool cgen_defs_expr(CGenerator *g, Expression *e) {
}
static bool cgen_defs_decl(CGenerator *g, Declaration *d) {
- if (d->flags & DECL_HAS_EXPR) {
+ if (d->flags & DECL_HAS_EXPR) {
if (!cgen_defs_expr(g, &d->expr))
return false;
}
diff --git a/copy.c b/copy.c
index a33ee16..343b74f 100644
--- a/copy.c
+++ b/copy.c
@@ -309,7 +309,7 @@ static void copy_block(Copier *c, Block *out, Block *in) {
*out = *in;
size_t nstmts = arr_len(in->stmts);
out->stmts = NULL;
- Block *prev = c->block;
+ Block *prev = c->block;
c->block = out;
if (in->ret_expr)
copy_expr(c, out->ret_expr = allocr_malloc(c->allocr, sizeof *out->ret_expr), in->ret_expr);
diff --git a/err.c b/err.c
index 2927ba0..0a519c1 100644
--- a/err.c
+++ b/err.c
@@ -138,7 +138,7 @@ static void err_print_(
int line, const char *file,
#endif
Location where, const char *fmt, ...) {
- va_list args;
+ va_list args;
if (where.ctx && !where.ctx->enabled) return;
#if ERR_SHOW_SOURCE_LOCATION
if (file)
diff --git a/eval.c b/eval.c
index e1d199e..66995ce 100644
--- a/eval.c
+++ b/eval.c
@@ -748,7 +748,7 @@ static void *eval_ptr_to_struct_field(Evaluator *ev, Expression *dot_expr) {
} else {
struc_data = struc.struc;
}
- return (char *)struc_data + dot_expr->binary.field->offset;
+ return (char *)struc_data + dot_expr->binary.field->offset;
}
static bool eval_address_of(Evaluator *ev, Expression *e, void **ptr) {
@@ -992,7 +992,7 @@ static Value val_zero(Type *t) {
case TYPE_ARR:
val.arr = err_calloc(t->arr.n, compiler_sizeof(t->arr.of));
break;
- default:
+ default:
break;
}
return val;
diff --git a/identifiers.c b/identifiers.c
index ad3fdff..c40d360 100644
--- a/identifiers.c
+++ b/identifiers.c
@@ -181,7 +181,7 @@ static IdentDecl *ident_add_decl(Identifier i, struct Declaration *d, struct Blo
}
static IdentDecl *ident_decl(Identifier i) {
- return (IdentDecl *)arr_last(i->decls);
+ return (IdentDecl *)arr_last(i->decls);
}
static void ident_tree_free(IdentTree *id) {
diff --git a/infer.c b/infer.c
index 1e99fec..d43c31f 100644
--- a/infer.c
+++ b/infer.c
@@ -77,7 +77,7 @@ static bool infer_from_expr(Typer *tr, Expression *match, Expression *to, Expres
/* if match is not the same kind of type as to, returns true */
static bool infer_from_type(Typer *tr, Type *match, Type *to, Identifier *idents, Value *vals, Type *types) {
- assert(to->flags & TYPE_IS_RESOLVED);
+ assert(to->flags & TYPE_IS_RESOLVED);
switch (match->kind) {
case TYPE_VOID:
diff --git a/main.c b/main.c
index 7b91cea..cf9f627 100644
--- a/main.c
+++ b/main.c
@@ -6,7 +6,6 @@
/*
NOTE:
-
Structure of the toc compiler:
tokenizer => parser => typing (types.c) => typdefs_cgen, decls_cgen, cgen
(lexing)
@@ -105,7 +104,7 @@ int main(int argc, char **argv) {
Parser p;
parser_create(&p, &t, &main_allocr);
- ParsedFile f;
+ ParsedFile f;
if (!parse_file(&p, &f)) {
err_fprint(TEXT_IMPORTANT("Errors occured while parsing.\n"));
diff --git a/package.c b/package.c
index 64adc2f..a425ecb 100644
--- a/package.c
+++ b/package.c
@@ -147,7 +147,7 @@ static bool export_fn_ptr(Exporter *ex, FnExpr *f, Location where) {
static bool export_val(Exporter *ex, Value val, Type *type, Location where);
static bool export_val_ptr(Exporter *ex, void *val, Type *type, Location where) {
switch (type->kind) {
- case TYPE_VOID: break;
+ case TYPE_VOID: break;
case TYPE_BUILTIN:
switch (type->builtin) {
case BUILTIN_I8: export_i8(ex, *(I8 *)val); break;
diff --git a/parse.c b/parse.c
index a1bb794..6776d95 100644
--- a/parse.c
+++ b/parse.c
@@ -293,9 +293,7 @@ static inline void *parser_malloc(Parser *p, size_t bytes) {
return allocr_malloc(p->allocr, bytes);
}
-/*
- allocate a new expression.
-*/
+/* allocate a new expression. */
static inline Expression *parser_new_expr(Parser *p) {
return parser_malloc(p, sizeof(Expression));
}
@@ -641,7 +639,7 @@ static bool parser_is_definitely_type(Parser *p, Token **end) {
Tokenizer *t = p->tokr;
Token *start = t->token;
bool ret = false;
- do {
+ do {
continu:
switch (t->token->kind) {
case TOKEN_KW:
@@ -964,7 +962,6 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
/* there's more stuff after. maybe it's, e.g. int, float */
}
t->token = before;
-
if (end - t->token == 1) {
/* 1-token expression */
switch (t->token->kind) {
@@ -1735,7 +1732,7 @@ static inline bool ends_decl(Token *t, DeclEndKind ends_with) {
switch (ends_with) {
case DECL_END_SEMICOLON:
return t->kw == KW_SEMICOLON;
- case DECL_END_RPAREN_COMMA:
+ case DECL_END_RPAREN_COMMA:
return t->kw == KW_RPAREN || t->kw == KW_COMMA;
case DECL_END_LBRACE_COMMA:
return t->kw == KW_LBRACE || t->kw == KW_COMMA;
@@ -1746,7 +1743,7 @@ static inline bool ends_decl(Token *t, DeclEndKind ends_with) {
static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, U16 flags) {
Tokenizer *t = p->tokr;
d->where = t->token->where;
- d->idents = NULL;
+ d->idents = NULL;
d->flags = 0;
if ((flags & PARSE_DECL_ALLOW_EXPORT) && token_is_direct(t->token, DIRECT_EXPORT)) {
@@ -1965,7 +1962,7 @@ static void parser_create(Parser *p, Tokenizer *t, Allocator *allocr) {
static bool parse_file(Parser *p, ParsedFile *f) {
Tokenizer *t = p->tokr;
- f->stmts = NULL;
+ f->stmts = NULL;
bool ret = true;
while (t->token->kind != TOKEN_EOF) {
Statement *stmt = parser_arr_add(p, &f->stmts);
diff --git a/scope.c b/scope.c
index 016d4bb..a180c3b 100644
--- a/scope.c
+++ b/scope.c
@@ -99,7 +99,7 @@ static void fn_exit(FnExpr *f) {
static bool each_enter(Expression *e) {
assert(e->kind == EXPR_EACH);
EachExpr *ea = e->each;
- if (ea->index && ea->index == ea->value) {
+ if (ea->index && ea->index == ea->value) {
err_print(e->where, "The identifier for the index of an each loop must be different from the identifier for the value.");
return false;
}
diff --git a/tokenizer.c b/tokenizer.c
index f841d90..7abf56b 100644
--- a/tokenizer.c
+++ b/tokenizer.c
@@ -523,9 +523,7 @@ static bool tokenize_string(Tokenizer *t, char *str) {
return !has_err;
}
-/*
- skip to one token past the next semicolon not in braces (or the end of the file).
-*/
+/* skip to one token past the next semicolon not in braces (or the end of the file). */
static void tokr_skip_semicolon(Tokenizer *t) {
int brace_level = 0;
while (t->token->kind != TOKEN_EOF) {
@@ -546,5 +544,5 @@ static void tokr_skip_semicolon(Tokenizer *t) {
/* only frees tokens, not string literals (because those are on the allocator). */
static void tokr_free(Tokenizer *t) {
- arr_clear(&t->tokens);
+ arr_clear(&t->tokens);
}
diff --git a/types.c b/types.c
index 891e525..d823d15 100644
--- a/types.c
+++ b/types.c
@@ -211,7 +211,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Type *t, U16 flags) {
/* f has compile time params, but it's not an instance! */
bool generic = !(flags & TYPE_OF_FN_IS_INSTANCE) && fn_has_any_const_params(f);
- if (generic) {
+ if (generic) {
Copier cop = copier_create(tr->allocr, tr->block);
copy_fn_expr(&cop, &fn_copy, f, false);
f = &fn_copy;
@@ -344,7 +344,7 @@ static bool type_of_fn(Typer *tr, FnExpr *f, Type *t, U16 flags) {
fn_exit(f);
tr->fn = prev_fn;
}
- return success;
+ return success;
}
static bool type_of_ident(Typer *tr, Location where, Identifier i, Type *t) {
@@ -643,7 +643,7 @@ static Status type_cast_status(Type *from, Type *to) {
break;
}
assert(0);
- return STATUS_ERR;
+ return STATUS_ERR;
}
static bool arg_is_const(Expression *arg, Constness constness) {
@@ -1059,7 +1059,7 @@ static bool types_expr(Typer *tr, Expression *e) {
IfExpr *nexti = &curr->next_elif->if_;
Type *next_type = &curr->next_elif->type;
curr->next_elif->flags |= EXPR_FOUND_TYPE;
- if (!types_block(tr, &nexti->body)) {
+ if (!types_block(tr, &nexti->body)) {
return false;
}
if (nexti->body.ret_expr) {
@@ -1494,7 +1494,7 @@ static bool types_expr(Typer *tr, Expression *e) {
t->kind = TYPE_UNKNOWN;
} break;
case EXPR_DSIZEOF:
- case EXPR_DALIGNOF: {
+ case EXPR_DALIGNOF: {
Expression *of = e->kind == EXPR_DSIZEOF ? e->dsizeof.of : e->dalignof.of;
if (!types_expr(tr, of))
return false;
diff --git a/types.h b/types.h
index d515ab5..26efd86 100644
--- a/types.h
+++ b/types.h
@@ -83,7 +83,7 @@ typedef U32 IdentID; /* identifier ID for cgen (anonymous variables). not to be
typedef struct Location {
U32 line;
- U32 pos; /* position in ctx->str */
+ U32 pos; /* position in ctx->str */
struct ErrCtx *ctx;
} Location;
@@ -98,7 +98,7 @@ typedef struct ErrCtx {
typedef struct Page {
struct Page *next;
size_t used; /* number MaxAligns used, not bytes */
- MaxAlign data[];
+ MaxAlign data[];
} Page;
typedef struct Allocator {
@@ -109,7 +109,7 @@ typedef struct Allocator {
typedef struct ArrBlock {
void *data;
size_t n; /* number of things in this block so far */
- void *last; /* last one of them */
+ void *last; /* last one of them */
} ArrBlock;
typedef struct BlockArr {
@@ -126,7 +126,7 @@ typedef struct HashTable {
} HashTable;
typedef struct Slice {
- I64 n;
+ I64 n;
void *data;
} Slice;
@@ -170,7 +170,7 @@ typedef struct IdentDecl {
Value val;
SOURCE_LOCATION
IdentDeclKind kind;
- U16 flags;
+ U16 flags;
} IdentDecl;
/*
@@ -188,7 +188,7 @@ typedef struct IdentTree {
U64 id; /* 0 if there's no actual identifier here, otherwise unique positive integer associated with this identifier */
struct IdentTree *parent;
struct IdentTree *children[TREE_NCHILDREN];
- IdentDecl *decls; /* array of declarations of this identifier */
+ IdentDecl *decls; /* array of declarations of this identifier */
} IdentTree;
typedef IdentTree *Identifier;
@@ -428,7 +428,7 @@ typedef struct Block {
Location start;
Location end;
struct Statement *stmts;
- struct Expression *ret_expr; /* the return expression of this block, e.g. {foo(); 3} => 3 NULL for no expression. */
+ struct Expression *ret_expr; /* the return expression of this block, e.g. {foo(); 3} => 3 NULL for no expression. */
} Block;
typedef enum {
@@ -493,7 +493,7 @@ typedef enum {
typedef struct CallExpr {
struct Expression *fn;
- union {
+ union {
struct Argument *args;
struct Expression *arg_exprs;
};
@@ -551,8 +551,8 @@ typedef struct EachExpr {
typedef struct FnExpr {
- struct Declaration *params; /* declarations of the parameters to this function */
- struct Declaration *ret_decls; /* array of decls, if this has named return values. otherwise, NULL */
+ struct Declaration *params; /* declarations of the parameters to this function */
+ struct Declaration *ret_decls; /* array of decls, if this has named return values. otherwise, NULL */
Type ret_type;
Block body;
HashTable instances; /* for fns with constant parameters. the key is a tuple where
@@ -684,7 +684,7 @@ typedef struct Declaration {
Location where;
Identifier *idents;
Type type;
- DeclFlags flags;
+ DeclFlags flags;
Expression expr;
Value val; /* only for constant decls. */
} Declaration;
@@ -757,7 +757,7 @@ typedef struct Typer {
typedef struct Exporter {
FILE *out; /* .top (toc package) to output to */
bool export_locations;
- FnExpr **exported_fns;
+ FnExpr **exported_fns;
StructDef **exported_structs;
} Exporter;