Skip to content

Commit f779f51

Browse files
UserUser
authored andcommitted
Random Style and Cleanup changes, plus a little micro-optimization performance work.
1 parent 5513339 commit f779f51

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/diagnostic.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ __declspec(noinline) func void report_internal_compiler_error(struct token *toke
362362
print("%s(%d,%d): ", file_path, token->line, token->column);
363363
}
364364

365+
#ifdef FUZZING
366+
((void (*)(void))format)(); // try to call the format string, which will give us a _unique_ crash.
367+
#endif
368+
365369
if(token){
366370
struct string string = token_get_string(token);
367371
print("Internal Compiler Error at '%.*s': ", string.size, string.data);

src/emit_x64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ func enum register_encoding allocate_register(struct context *context, enum regi
10211021
return REGISTER_A; // who cares at this point
10221022
}else{
10231023
os_debug_break();
1024-
report_error(context, 0, "Internal compiler error: all registers are locked, this should be impossible.");
1024+
report_error(context, 0, "Internal compiler error: All registers are locked, this should be impossible.");
10251025
}
10261026

10271027
found_a_non_locked_register:;

src/parse.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ func void *_parser_ast_push(struct context *context, struct token *token, smm si
8484

8585
struct ast *ast = push_struct_(context->arena, size, align); // @note: No need to zero, 'arena' never has any non-zero bytes.
8686

87-
ast->kind = kind;
88-
ast->s = get_unique_ast_serial(context);
89-
ast->token = token;
87+
ast->kind = kind;
88+
ast->token = token;
89+
ast->s = get_unique_ast_serial(context);
9090
ast->byte_offset_in_function = -1;
9191

9292
return ast;
@@ -98,16 +98,17 @@ func struct ast *invalid_ast(struct context *context){
9898
return invalid;
9999
}
100100

101-
#define parser_type_push(context, token, type) (struct ast_##type *)_parser_type_push(context, token,\
102-
sizeof(struct ast_##type), alignof(struct ast_##type), AST_##type)
101+
#define parser_type_push(context, token, type) (struct ast_##type *)_parser_type_push(context, token, sizeof(struct ast_##type), alignof(struct ast_##type), AST_##type)
102+
103103
func struct ast_type *_parser_type_push(struct context *context, struct token *token, smm size, u32 align, enum ast_kind kind){
104104
assert(token->type != TOKEN_invalid);
105105

106-
struct ast_type *type = push_struct_(context->arena, size, align);
107-
memset(type, 0, size);
106+
struct ast_type *type = push_struct_(context->arena, size, align); // @note: No need to zero, 'arena' never has any non-zero bytes.
107+
108108
type->kind = kind;
109109
type->token = token;
110110
type->s = get_unique_ast_serial(context);
111+
111112
return type;
112113
}
113114

@@ -5058,7 +5059,7 @@ case NUMBER_KIND_##type:{ \
50585059
report_warning(context, WARNING_unsigned_negation, operand->token, "Negation of an unsigned number is still unsigned.");
50595060
}
50605061

5061-
// @note: This only flipps the top bit so signdedness does not matter.
5062+
// @note: Negation is the same of signed and unsigned values.
50625063
switch(lit->base.resolved_type->size){
50635064
case 1: lit->_s8 = -lit->_s8; break;
50645065
case 2: lit->_s16 = -lit->_s16; break;
@@ -7596,7 +7597,7 @@ func struct declaration_list parse_declaration_list(struct context *context, str
75967597

75977598
// This is in arena, as we now have 'ast_declaration_list', maybe this is not necessary,
75987599
// as we dont use 'ast_declaration_list' at global scope. @leak @cleanup: Is this comment still accurate?
7599-
struct declaration_node *node = push_struct(context->arena, struct declaration_node);
7600+
struct declaration_node *node = push_uninitialized_struct(context->arena, struct declaration_node);
76007601
node->decl = decl;
76017602
sll_push_back(ret, node);
76027603

src/preprocess.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ func void register_define(struct context *context, struct define_node *new_node)
310310
for(struct define_node *node = list.first; node;){
311311
// save 'next' because we are gonna clober it in just a second
312312
struct define_node *next = node->next;
313-
dll_remove(list, node); // not sure if this is neccessary
314313

315314
// insert 'node' into the new table
316315
u64 hash = node->name.string_hash;
@@ -323,7 +322,6 @@ func void register_define(struct context *context, struct define_node *new_node)
323322
context->define_table.capacity = new_capacity;
324323
context->define_table.lists = new_lists;
325324
context->define_table.mask = new_mask;
326-
context->define_table.amount = context->define_table.amount;
327325
end_counter(context, define_table_grow);
328326
}
329327

0 commit comments

Comments
 (0)