diff --git a/build.bat b/build.bat index 873ed2fa0..732b1adab 100644 --- a/build.bat +++ b/build.bat @@ -6,7 +6,7 @@ set exe_name=odin.exe :: Debug = 0, Release = 1 set release_mode=0 -set compiler_flags= -nologo -Oi -TP -W4 -fp:fast -fp:except- -Gm- -MP -FC -GS- -EHsc- -GR- +set compiler_flags= -nologo -Oi -TC -W4 -fp:fast -fp:except- -Gm- -MP -FC -GS- -EHsc- -GR- if %release_mode% EQU 0 ( rem Debug set compiler_flags=%compiler_flags% -Od -MDd -Z7 @@ -17,7 +17,7 @@ if %release_mode% EQU 0 ( rem Debug set compiler_warnings= ^ -we4013 -we4706 -we4002 ^ - -wd4100 -wd4127 -wd4189 ^ + -wd4100 -wd4101 -wd4127 -wd4189 ^ -wd4201 -wd4204 -wd4244 ^ -wd4306 ^ -wd4456 -wd4457 -wd4480 ^ @@ -47,8 +47,8 @@ rem pushd %build_dir% del *.ilk > NUL 2> NUL cl %compiler_settings% "src\main.cpp" ^ - /link %linker_settings% -OUT:%exe_name% - rem && odin run code/demo.odin + /link %linker_settings% -OUT:%exe_name% ^ + && odin run code/demo.odin rem odin run code/demo.odin diff --git a/src/array.cpp b/src/array.cpp index 67e87166c..7e185e872 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -148,7 +148,7 @@ void array_init_count(Array *array, gbAllocator a, isize count) { template Array array_make(T *data, isize count, isize capacity) { - Array a = {}; + Array a = {0}; a.data = data; a.count = count; a.capacity = capacity; diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp index f8953352a..8c42e5363 100644 --- a/src/checker/checker.cpp +++ b/src/checker/checker.cpp @@ -186,7 +186,7 @@ typedef struct ImplicitValueInfo { Type * type; } ImplicitValueInfo; // NOTE(bill): This is initialized later -gb_global ImplicitValueInfo implicit_value_infos[ImplicitValue_Count] = {}; +gb_global ImplicitValueInfo implicit_value_infos[ImplicitValue_Count] = {0}; @@ -667,7 +667,7 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode } } - TypeAndValue tv = {}; + TypeAndValue tv = {0}; tv.type = type; tv.value = value; tv.mode = mode; @@ -852,7 +852,7 @@ void add_type_info_type(Checker *c, Type *t) { void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *decl, Type *type, AstNode *body, u32 tags) { - ProcedureInfo info = {}; + ProcedureInfo info = {0}; info.file = file; info.token = token; info.decl = decl; @@ -879,7 +879,7 @@ Type *const curr_procedure(Checker *c) { } void add_curr_ast_file(Checker *c, AstFile *file) { - TokenPos zero_pos = {}; + TokenPos zero_pos = {0}; global_error_collector.prev = zero_pos; c->curr_ast_file = file; c->context.decl = file->decl_info; @@ -911,7 +911,7 @@ void add_dependency_to_map(MapEntity *map, CheckerInfo *info, Entity *node) { } MapEntity generate_minimum_dependency_map(CheckerInfo *info, Entity *start) { - MapEntity map = {}; // Key: Entity * + MapEntity map = {0}; // Key: Entity * map_entity_init(&map, heap_allocator()); for_array(i, info->entities.entries) { @@ -1027,7 +1027,7 @@ void check_global_entity(Checker *c, EntityKind kind) { Scope *prev_scope = c->context.scope; c->context.scope = d->scope; - check_entity_decl(c, e, d, NULL); + check_entity_decl(c, e, d, NULL, NULL); } } } diff --git a/src/checker/decl.cpp b/src/checker/decl.cpp index 2d83b6654..f5a5daad6 100644 --- a/src/checker/decl.cpp +++ b/src/checker/decl.cpp @@ -69,7 +69,7 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNodeArra for_array(i, inits) { AstNode *rhs = inits.e[i]; - Operand o = {}; + Operand o = {0}; check_multi_expr(c, &o, rhs); if (o.type->kind != Type_Tuple) { array_add(&operands, o); @@ -185,7 +185,7 @@ void check_var_decl_node(Checker *c, AstNode *node) { Type *init_type = NULL; if (vd->type) { - init_type = check_type(c, vd->type, NULL); + init_type = check_type_extra(c, vd->type, NULL, NULL); if (init_type == NULL) init_type = t_invalid; } @@ -280,7 +280,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init_e e->type = t; } - Operand operand = {}; + Operand operand = {0}; if (init_expr) { check_expr(c, &operand, init_expr); } @@ -296,12 +296,12 @@ void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *def, Cycle } e->type = named; - CycleChecker local_cycle_checker = {}; + CycleChecker local_cycle_checker = {0}; if (cycle_checker == NULL) { cycle_checker = &local_cycle_checker; } - Type *bt = check_type(c, type_expr, named, cycle_checker_add(cycle_checker, e)); + Type *bt = check_type_extra(c, type_expr, named, cycle_checker_add(cycle_checker, e)); named->Named.base = bt; named->Named.base = base_type(named->Named.base); if (named->Named.base == t_invalid) { @@ -457,7 +457,7 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count e->flags |= EntityFlag_Visited; if (type_expr != NULL) - e->type = check_type(c, type_expr, NULL); + e->type = check_type_extra(c, type_expr, NULL, NULL); if (init_expr == NULL) { if (type_expr == NULL) @@ -467,7 +467,7 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count if (entities == NULL || entity_count == 1) { GB_ASSERT(entities == NULL || entities[0] == e); - Operand operand = {}; + Operand operand = {0}; check_expr(c, &operand, init_expr); check_init_variable(c, e, &operand, str_lit("variable declaration")); } diff --git a/src/checker/entity.cpp b/src/checker/entity.cpp index 83ea1d782..98083e803 100644 --- a/src/checker/entity.cpp +++ b/src/checker/entity.cpp @@ -37,7 +37,8 @@ typedef enum EntityFlag { EntityFlag_VectorElem = 1<<5, } EntityFlag; -typedef struct Entity { +typedef struct Entity Entity; +struct Entity { EntityKind kind; u32 flags; Token token; @@ -57,8 +58,8 @@ typedef struct Entity { i32 field_index; i32 field_src_index; } Variable; - struct {} TypeName; - struct {} Procedure; + i32 TypeName; + i32 Procedure; struct { BuiltinProcId id; } Builtin; @@ -68,14 +69,14 @@ typedef struct Entity { Scope *scope; bool used; } ImportName; - struct {} Nil; + i32 Nil; struct { // TODO(bill): Should this be a user-level construct rather than compiler-level? ImplicitValueId id; Entity * backing; } ImplicitValue; }; -} Entity; +}; bool is_entity_exported(Entity *e) { if (e->kind == Entity_ImportName) { diff --git a/src/checker/expr.cpp b/src/checker/expr.cpp index bd5fa41d6..13d81894a 100644 --- a/src/checker/expr.cpp +++ b/src/checker/expr.cpp @@ -1,18 +1,23 @@ void check_expr (Checker *c, Operand *operand, AstNode *expression); void check_multi_expr (Checker *c, Operand *operand, AstNode *expression); void check_expr_or_type (Checker *c, Operand *operand, AstNode *expression); -ExprKind check_expr_base (Checker *c, Operand *operand, AstNode *expression, Type *type_hint = NULL); -Type * check_type (Checker *c, AstNode *expression, Type *named_type = NULL, CycleChecker *cycle_checker = NULL); +ExprKind check_expr_base (Checker *c, Operand *operand, AstNode *expression, Type *type_hint); +Type * check_type_extra (Checker *c, AstNode *expression, Type *named_type, CycleChecker *cycle_checker); +Type * check_type (Checker *c, AstNode *expression); void check_type_decl (Checker *c, Entity *e, AstNode *type_expr, Type *def, CycleChecker *cycle_checker); Entity * check_selector (Checker *c, Operand *operand, AstNode *node); void check_not_tuple (Checker *c, Operand *operand); -bool check_value_is_expressible(Checker *c, ExactValue in_value, Type *type, ExactValue *out_value); -void convert_to_typed (Checker *c, Operand *operand, Type *target_type, i32 level = 0); +bool check_value_is_expressible(Checker *c, ExactValue in_value, Type *type, ExactValue *out_value); +void convert_to_typed (Checker *c, Operand *operand, Type *target_type, i32 level); gbString expr_to_string (AstNode *expression); -void check_entity_decl (Checker *c, Entity *e, DeclInfo *decl, Type *named_type, CycleChecker *cycle_checker = NULL); +void check_entity_decl (Checker *c, Entity *e, DeclInfo *decl, Type *named_type, CycleChecker *cycle_checker); void check_proc_body (Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body); void update_expr_type (Checker *c, AstNode *e, Type *type, bool final); +gb_inline Type *check_type(Checker *c, AstNode *expression) { + return check_type_extra(c, expression, NULL, NULL); +} + bool check_is_assignable_to_using_subtype(Type *dst, Type *src) { @@ -46,7 +51,7 @@ bool check_is_assignable_to_using_subtype(Type *dst, Type *src) { } -bool check_is_assignable_to(Checker *c, Operand *operand, Type *type, bool is_argument = false) { +bool check_is_assignable_to(Checker *c, Operand *operand, Type *type) { if (operand->mode == Addressing_Invalid || type == t_invalid) { return true; @@ -138,19 +143,12 @@ bool check_is_assignable_to(Checker *c, Operand *operand, Type *type, bool is_ar return true; } - if (true || is_argument) { - // NOTE(bill): Polymorphism for subtyping - if (check_is_assignable_to_using_subtype(type, src)) { - return true; - } - } - return false; } // NOTE(bill): `content_name` is for debugging and error messages -void check_assignment(Checker *c, Operand *operand, Type *type, String context_name, bool is_argument = false) { +void check_assignment(Checker *c, Operand *operand, Type *type, String context_name) { check_not_tuple(c, operand); if (operand->mode == Addressing_Invalid) { return; @@ -169,14 +167,14 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n add_type_info_type(c, type); target_type = default_type(operand->type); } - convert_to_typed(c, operand, target_type); + convert_to_typed(c, operand, target_type, 0); if (operand->mode == Addressing_Invalid) { return; } } if (type != NULL) { - if (!check_is_assignable_to(c, operand, type, is_argument)) { + if (!check_is_assignable_to(c, operand, type)) { gbString type_str = type_to_string(type); gbString op_type_str = type_to_string(operand->type); gbString expr_str = expr_to_string(operand->expr); @@ -243,7 +241,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls, CycleChecker *cycle_checker, String context) { gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); - MapEntity entity_map = {}; + MapEntity entity_map = {0}; map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*(field_count+other_field_count)); isize other_field_index = 0; @@ -350,7 +348,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls, } ast_node(vd, VarDecl, decl); - Type *base_type = check_type(c, vd->type, NULL, cycle_checker); + Type *base_type = check_type_extra(c, vd->type, NULL, cycle_checker); for_array(name_index, vd->names) { AstNode *name = vd->names.e[name_index]; @@ -386,7 +384,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls, } ast_node(vd, VarDecl, decl); - Type *type = check_type(c, vd->type, NULL, cycle_checker); + Type *type = check_type_extra(c, vd->type, NULL, cycle_checker); if (vd->is_using) { if (vd->names.count > 1) { @@ -459,8 +457,8 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls, // TODO(bill): Cleanup struct field reordering // TODO(bill): Inline sorting procedure? -gb_global BaseTypeSizes __checker_sizes = {}; -gb_global gbAllocator __checker_allocator = {}; +gb_global BaseTypeSizes __checker_sizes = {0}; +gb_global gbAllocator __checker_allocator = {0}; GB_COMPARE_PROC(cmp_struct_entity_size) { // Rule: @@ -677,7 +675,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); - MapEntity entity_map = {}; + MapEntity entity_map = {0}; map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*(et->fields.count)); Entity *blank_entity = make_entity_constant(c->allocator, c->context.scope, blank_token, constant_type, make_exact_value_integer(0));; @@ -702,7 +700,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod continue; } - Operand o = {}; + Operand o = {0}; if (f->value != NULL) { check_expr(c, &o, f->value); if (o.mode != Addressing_Constant) { @@ -892,7 +890,7 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl } add_entity_use(c, n, e); - // CycleChecker local_cycle_checker = {}; + // CycleChecker local_cycle_checker = {0}; // if (cycle_checker == NULL) { // cycle_checker = &local_cycle_checker; // } @@ -990,7 +988,7 @@ i64 check_array_count(Checker *c, AstNode *e) { if (e == NULL) { return 0; } - Operand o = {}; + Operand o = {0}; check_expr(c, &o, e); if (o.mode != Addressing_Constant) { if (o.mode != Addressing_Invalid) { @@ -1013,14 +1011,14 @@ i64 check_array_count(Checker *c, AstNode *e) { return 0; } -Type *check_type(Checker *c, AstNode *e, Type *named_type, CycleChecker *cycle_checker) { +Type *check_type_extra(Checker *c, AstNode *e, Type *named_type, CycleChecker *cycle_checker) { ExactValue null_value = {ExactValue_Invalid}; Type *type = NULL; gbString err_str = NULL; switch (e->kind) { case_ast_node(i, Ident, e); - Operand o = {}; + Operand o = {0}; check_identifier(c, &o, e, named_type, cycle_checker); switch (o.mode) { @@ -1042,7 +1040,7 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type, CycleChecker *cycle_c case_end; case_ast_node(se, SelectorExpr, e); - Operand o = {}; + Operand o = {0}; check_selector(c, &o, e); switch (o.mode) { @@ -1064,7 +1062,7 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type, CycleChecker *cycle_c case_end; case_ast_node(pe, ParenExpr, e); - type = check_type(c, pe->expr, named_type, cycle_checker); + type = check_type_extra(c, pe->expr, named_type, cycle_checker); goto end; case_end; @@ -1092,7 +1090,7 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type, CycleChecker *cycle_c case_ast_node(at, ArrayType, e); if (at->count != NULL) { - Type *elem = check_type(c, at->elem, NULL, cycle_checker); + Type *elem = check_type_extra(c, at->elem, NULL, cycle_checker); type = make_type_array(c->allocator, elem, check_array_count(c, at->count)); } else { Type *elem = check_type(c, at->elem); @@ -1164,7 +1162,7 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type, CycleChecker *cycle_c case_end; case_ast_node(ce, CallExpr, e); - Operand o = {}; + Operand o = {0}; check_expr_or_type(c, &o, e); if (o.mode == Addressing_Type) { type = o.type; @@ -1586,7 +1584,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) { GB_ASSERT(node->kind == AstNode_BinaryExpr); ast_node(be, BinaryExpr, node); - ExactValue x_val = {}; + ExactValue x_val = {0}; if (x->mode == Addressing_Constant) { x_val = exact_value_to_integer(x->value); } @@ -1604,7 +1602,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) { if (is_type_unsigned(y->type)) { } else if (is_type_untyped(y->type)) { - convert_to_typed(c, y, t_untyped_integer); + convert_to_typed(c, y, t_untyped_integer, 0); if (y->mode == Addressing_Invalid) { x->mode = Addressing_Invalid; return; @@ -1741,7 +1739,7 @@ bool check_is_castable_to(Checker *c, Operand *operand, Type *y) { } String check_down_cast_name(Type *dst_, Type *src_) { - String result = {}; + String result = {0}; Type *dst = type_deref(dst_); Type *src = type_deref(src_); Type *dst_s = base_type(dst); @@ -1776,7 +1774,7 @@ Operand check_ptr_addition(Checker *c, TokenKind op, Operand *ptr, Operand *offs GB_ASSERT(is_type_integer(offset->type)); GB_ASSERT(op == Token_Add || op == Token_Sub); - Operand operand = {}; + Operand operand = {0}; operand.mode = Addressing_Value; operand.type = ptr->type; operand.expr = node; @@ -1809,7 +1807,7 @@ Operand check_ptr_addition(Checker *c, TokenKind op, Operand *ptr, Operand *offs void check_binary_expr(Checker *c, Operand *x, AstNode *node) { GB_ASSERT(node->kind == AstNode_BinaryExpr); - Operand y_ = {}, *y = &y_; + Operand y_ = {0}, *y = &y_; ast_node(be, BinaryExpr, node); @@ -2079,11 +2077,11 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { } - convert_to_typed(c, x, y->type); + convert_to_typed(c, x, y->type, 0); if (x->mode == Addressing_Invalid) { return; } - convert_to_typed(c, y, x->type); + convert_to_typed(c, y, x->type, 0); if (y->mode == Addressing_Invalid) { x->mode = Addressing_Invalid; return; @@ -2261,6 +2259,7 @@ void convert_untyped_error(Checker *c, Operand *operand, Type *target_type) { operand->mode = Addressing_Invalid; } +// NOTE(bill): Set initial level to 0 void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level) { GB_ASSERT_NOT_NULL(target_type); if (operand->mode == Addressing_Invalid || @@ -2348,7 +2347,7 @@ bool check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *val return false; } - convert_to_typed(c, &operand, t_int); + convert_to_typed(c, &operand, t_int, 0); if (operand.mode == Addressing_Invalid) { if (value) *value = 0; return false; @@ -2400,7 +2399,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node) { bool check_op_expr = true; Entity *expr_entity = NULL; Entity *entity = NULL; - Selection sel = {}; // NOTE(bill): Not used if it's an import name + Selection sel = {0}; // NOTE(bill): Not used if it's an import name AstNode *op_expr = se->expr; AstNode *selector = unparen_expr(se->selector); @@ -2425,7 +2424,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node) { goto error; } if (entity->type == NULL) { // Not setup yet - check_entity_decl(c, entity, NULL, NULL); + check_entity_decl(c, entity, NULL, NULL, NULL); } GB_ASSERT(entity->type != NULL); bool is_not_exported = !is_entity_exported(entity); @@ -2449,7 +2448,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node) { } } if (check_op_expr) { - check_expr_base(c, operand, op_expr); + check_expr_base(c, operand, op_expr, NULL); if (operand->mode == Addressing_Invalid) { goto error; } @@ -2564,7 +2563,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id switch (id) { case BuiltinProc_new: { // new :: proc(Type) -> ^Type - Operand op = {}; + Operand op = {0}; check_expr_or_type(c, &op, ce->args.e[0]); Type *type = op.type; if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) { @@ -2576,7 +2575,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id } break; case BuiltinProc_new_slice: { // new_slice :: proc(Type, len: int[, cap: int]) -> []Type - Operand op = {}; + Operand op = {0}; check_expr_or_type(c, &op, ce->args.e[0]); Type *type = op.type; if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) { @@ -2679,7 +2678,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id case BuiltinProc_offset_of: { // offset_of :: proc(Type, field) -> untyped int - Operand op = {}; + Operand op = {0}; Type *bt = check_type(c, ce->args.e[0]); Type *type = base_type(bt); if (type == NULL || type == t_invalid) { @@ -2861,7 +2860,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id if (d->kind == Type_Slice) { dest_type = d->Slice.elem; } - Operand op = {}; + Operand op = {0}; check_expr(c, &op, ce->args.e[1]); if (op.mode == Addressing_Invalid) { return false; @@ -2900,7 +2899,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id Type *x_type = NULL, *y_type = NULL; x_type = base_type(operand->type); - Operand op = {}; + Operand op = {0}; check_expr(c, &op, ce->args.e[1]); if (op.mode == Addressing_Invalid) { return false; @@ -2951,7 +2950,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id continue; } AstNode *arg = ce->args.e[i]; - Operand op = {}; + Operand op = {0}; check_expr(c, &op, arg); if (op.mode == Addressing_Invalid) { return false; @@ -3006,7 +3005,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id } AstNode *offset = ce->args.e[1]; - Operand op = {}; + Operand op = {0}; check_expr(c, &op, offset); if (op.mode == Addressing_Invalid) return false; @@ -3047,7 +3046,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id return false; } AstNode *offset = ce->args[1]; - Operand op = {}; + Operand op = {0}; check_expr(c, &op, offset); if (op.mode == Addressing_Invalid) return false; @@ -3115,7 +3114,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id cap = ce->args.e[2]; } - Operand op = {}; + Operand op = {0}; check_expr(c, &op, len); if (op.mode == Addressing_Invalid) return false; @@ -3165,7 +3164,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id AstNode *other_arg = ce->args.e[1]; Operand a = *operand; - Operand b = {}; + Operand b = {0}; check_expr(c, &b, other_arg); if (b.mode == Addressing_Invalid) { return false; @@ -3197,11 +3196,11 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id operand->mode = Addressing_Value; operand->type = type; - convert_to_typed(c, &a, b.type); + convert_to_typed(c, &a, b.type, 0); if (a.mode == Addressing_Invalid) { return false; } - convert_to_typed(c, &b, a.type); + convert_to_typed(c, &b, a.type, 0); if (b.mode == Addressing_Invalid) { return false; } @@ -3234,7 +3233,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id AstNode *other_arg = ce->args.e[1]; Operand a = *operand; - Operand b = {}; + Operand b = {0}; check_expr(c, &b, other_arg); if (b.mode == Addressing_Invalid) { return false; @@ -3266,11 +3265,11 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id operand->mode = Addressing_Value; operand->type = type; - convert_to_typed(c, &a, b.type); + convert_to_typed(c, &a, b.type, 0); if (a.mode == Addressing_Invalid) { return false; } - convert_to_typed(c, &b, a.type); + convert_to_typed(c, &b, a.type, 0); if (b.mode == Addressing_Invalid) { return false; } @@ -3396,7 +3395,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode array_init_reserve(&operands, c->tmp_allocator, 2*param_count); for_array(i, ce->args) { - Operand o = {}; + Operand o = {0}; check_multi_expr(c, &o, ce->args.e[i]); if (o.type->kind != Type_Tuple) { array_add(&operands, o); @@ -3443,7 +3442,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode if (variadic) { o = operands.e[operand_index]; } - check_assignment(c, &o, arg_type, str_lit("argument"), true); + check_assignment(c, &o, arg_type, str_lit("argument")); } if (variadic) { @@ -3463,7 +3462,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode break; } } - check_assignment(c, &o, t, str_lit("argument"), true); + check_assignment(c, &o, t, str_lit("argument")); } } end: @@ -3500,7 +3499,7 @@ ExprKind check_call_expr(Checker *c, Operand *operand, AstNode *call) { if (operand->mode == Addressing_Invalid) { for_array(i, ce->args) { - check_expr_base(c, operand, ce->args.e[i]); + check_expr_base(c, operand, ce->args.e[i], NULL); } operand->mode = Addressing_Invalid; operand->expr = call; @@ -3799,7 +3798,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint case Type_Vector: { Type *elem_type = NULL; - String context_name = {}; + String context_name = {0}; if (t->kind == Type_Slice) { elem_type = t->Slice.elem; context_name = str_lit("slice literal"); @@ -3839,7 +3838,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint error(ast_node_token(e), "Index %lld is out of bounds (>= %lld) for vector literal", index, t->Vector.count); } - Operand operand = {}; + Operand operand = {0}; check_expr_with_type_hint(c, &operand, e, elem_type); check_assignment(c, &operand, elem_type, context_name); @@ -4023,7 +4022,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint o->mode = Addressing_Value; - i64 indices[3] = {}; + i64 indices[3] = {0}; AstNode *nodes[3] = {se->low, se->high, se->max}; for (isize i = 0; i < gb_count_of(nodes); i++) { i64 index = max_count; @@ -4157,7 +4156,7 @@ ExprKind check_expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) void check_multi_expr(Checker *c, Operand *o, AstNode *e) { gbString err_str = NULL; - check_expr_base(c, o, e); + check_expr_base(c, o, e, NULL); switch (o->mode) { default: return; // NOTE(bill): Valid @@ -4195,7 +4194,7 @@ void check_expr(Checker *c, Operand *o, AstNode *e) { void check_expr_or_type(Checker *c, Operand *o, AstNode *e) { - check_expr_base(c, o, e); + check_expr_base(c, o, e, NULL); check_not_tuple(c, o); if (o->mode == Addressing_NoValue) { gbString str = expr_to_string(o->expr); diff --git a/src/checker/stmt.cpp b/src/checker/stmt.cpp index b49d8de23..129f13607 100644 --- a/src/checker/stmt.cpp +++ b/src/checker/stmt.cpp @@ -1,14 +1,14 @@ -bool check_is_terminating(AstNode *node); -bool check_has_break (AstNode *stmt, bool implicit); +bool check_is_terminating(AstNode *node); +bool check_has_break (AstNode *stmt, bool implicit); void check_stmt (Checker *c, AstNode *node, u32 flags); // Statements and Declarations -enum StmtFlag : u32 { +typedef enum StmtFlag { Stmt_BreakAllowed = GB_BIT(0), Stmt_ContinueAllowed = GB_BIT(1), Stmt_FallthroughAllowed = GB_BIT(2), // TODO(bill): fallthrough -}; +} StmtFlag; @@ -74,10 +74,10 @@ void check_stmt_list(Checker *c, AstNodeArray stmts, u32 flags) { } for_array(i, delayed_type) { - check_entity_decl(c, delayed_type.e[i].e, delayed_type.e[i].d, NULL); + check_entity_decl(c, delayed_type.e[i].e, delayed_type.e[i].d, NULL, NULL); } for_array(i, delayed_const) { - check_entity_decl(c, delayed_const.e[i].e, delayed_const.e[i].d, NULL); + check_entity_decl(c, delayed_const.e[i].e, delayed_const.e[i].d, NULL, NULL); } bool ft_ok = (flags & Stmt_FallthroughAllowed) != 0; @@ -352,7 +352,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { case_ast_node(es, ExprStmt, node) Operand operand = {Addressing_Invalid}; - ExprKind kind = check_expr_base(c, &operand, es->expr); + ExprKind kind = check_expr_base(c, &operand, es->expr, NULL); switch (operand.mode) { case Addressing_Type: error(ast_node_token(node), "Is not an expression"); @@ -436,7 +436,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { for_array(i, as->rhs) { AstNode *rhs = as->rhs.e[i]; - Operand o = {}; + Operand o = {0}; check_multi_expr(c, &o, rhs); if (o.type->kind != Type_Tuple) { array_add(&operands, o); @@ -592,7 +592,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { case_end; case_ast_node(ms, MatchStmt, node); - Operand x = {}; + Operand x = {0}; mod_flags |= Stmt_BreakAllowed; check_open_scope(c, node); @@ -608,7 +608,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { x.type = t_bool; x.value = make_exact_value_bool(true); - Token token = {}; + Token token = {0}; token.pos = ast_node_token(ms->body).pos; token.string = str_lit("true"); x.expr = make_ident(c->curr_ast_file, token); @@ -642,7 +642,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { } ; - MapTypeAndToken seen = {}; // NOTE(bill): Multimap + MapTypeAndToken seen = {0}; // NOTE(bill): Multimap map_type_and_token_init(&seen, heap_allocator()); for_array(i, bs->stmts) { @@ -656,8 +656,8 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { for_array(j, cc->list) { AstNode *expr = cc->list.e[j]; - Operand y = {}; - Operand z = {}; + Operand y = {0}; + Operand z = {0}; Token eq = {Token_CmpEq}; check_expr(c, &y, expr); @@ -665,7 +665,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { y.mode == Addressing_Invalid) { continue; } - convert_to_typed(c, &y, x.type); + convert_to_typed(c, &y, x.type, 0); if (y.mode == Addressing_Invalid) { continue; } @@ -732,7 +732,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { case_end; case_ast_node(ms, TypeMatchStmt, node); - Operand x = {}; + Operand x = {0}; mod_flags |= Stmt_BreakAllowed; check_open_scope(c, node); @@ -783,7 +783,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { } - MapBool seen = {}; + MapBool seen = {0}; map_bool_init(&seen, heap_allocator()); for_array(i, bs->stmts) { @@ -801,7 +801,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { AstNode *type_expr = cc->list.count > 0 ? cc->list.e[0] : NULL; Type *case_type = NULL; if (type_expr != NULL) { // Otherwise it's a default expression - Operand y = {}; + Operand y = {0}; check_expr_or_type(c, &y, type_expr); if (is_union_ptr) { @@ -915,7 +915,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { String name = expr->Ident.string; e = scope_lookup_entity(c->context.scope, name); } else if (expr->kind == AstNode_SelectorExpr) { - Operand o = {}; + Operand o = {0}; e = check_selector(c, &o, expr); is_selector = true; } @@ -1083,7 +1083,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { case_ast_node(pa, PushAllocator, node); - Operand op = {}; + Operand op = {0}; check_expr(c, &op, pa->expr); check_assignment(c, &op, t_allocator, str_lit("argument to push_allocator")); check_stmt(c, pa->body, mod_flags); @@ -1091,7 +1091,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { case_ast_node(pa, PushContext, node); - Operand op = {}; + Operand op = {0}; check_expr(c, &op, pa->expr); check_assignment(c, &op, t_context, str_lit("argument to push_context")); check_stmt(c, pa->body, mod_flags); @@ -1124,7 +1124,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { d->proc_decl = node; add_entity_and_decl_info(c, pd->name, e, d); - check_entity_decl(c, e, d, NULL); + check_entity_decl(c, e, d, NULL, NULL); case_end; } } diff --git a/src/checker/types.cpp b/src/checker/types.cpp index 04ed459dc..f51cbb660 100644 --- a/src/checker/types.cpp +++ b/src/checker/types.cpp @@ -295,7 +295,7 @@ gb_global Type *t_context_ptr = NULL; -gbString type_to_string(Type *type, gbAllocator a = heap_allocator()); +gbString type_to_string(Type *type); Type *base_type(Type *t) { for (;;) { @@ -823,7 +823,13 @@ gb_global Entity *entity__string_count = NULL; gb_global Entity *entity__slice_count = NULL; gb_global Entity *entity__slice_capacity = NULL; -Selection lookup_field(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel = empty_selection) { +Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel); + +Selection lookup_field(gbAllocator a, Type *type_, String field_name, bool is_type) { + return lookup_field_with_selection(a, type_, field_name, is_type, empty_selection); +} + +Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel) { GB_ASSERT(type_ != NULL); if (str_eq(field_name, str_lit("_"))) { @@ -1010,7 +1016,7 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, bool is_ty isize prev_count = sel.index.count; selection_add_index(&sel, i); // HACK(bill): Leaky memory - sel = lookup_field(a, f->type, field_name, is_type, sel); + sel = lookup_field_with_selection(a, f->type, field_name, is_type, sel); if (sel.entity != NULL) { if (is_type_pointer(f->type)) { @@ -1473,8 +1479,8 @@ gbString write_type_to_string(gbString str, Type *type) { } -gbString type_to_string(Type *type, gbAllocator a) { - gbString str = gb_string_make(a, ""); +gbString type_to_string(Type *type) { + gbString str = gb_string_make(gb_heap_allocator(), ""); return write_type_to_string(str, type); } diff --git a/src/common.cpp b/src/common.cpp index db946d5f3..d1ca1a8db 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -2,6 +2,8 @@ #define GB_IMPLEMENTATION #include "gb/gb.h" +typedef _Bool bool; + gbAllocator heap_allocator(void) { return gb_heap_allocator(); } diff --git a/src/exact_value.cpp b/src/exact_value.cpp index d06194d2b..313cda694 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -54,7 +54,7 @@ ExactValue make_exact_value_string(String string) { return result; } -ExactValue make_exact_value_integer(String string) { +ExactValue make_exact_value_integer_from_string(String string) { // TODO(bill): Allow for numbers with underscores in them ExactValue result = {ExactValue_Integer}; i32 base = 10; @@ -78,7 +78,7 @@ ExactValue make_exact_value_integer(i64 i) { return result; } -ExactValue make_exact_value_float(String string) { +ExactValue make_exact_value_float_from_string(String string) { // TODO(bill): Allow for numbers with underscores in them ExactValue result = {ExactValue_Float}; result.value_float = gb_str_to_f64(cast(char *)string.text, NULL); @@ -100,8 +100,8 @@ ExactValue make_exact_value_pointer(i64 ptr) { ExactValue make_exact_value_from_basic_literal(Token token) { switch (token.kind) { case Token_String: return make_exact_value_string(token.string); - case Token_Integer: return make_exact_value_integer(token.string); - case Token_Float: return make_exact_value_float(token.string); + case Token_Integer: return make_exact_value_integer_from_string(token.string); + case Token_Float: return make_exact_value_float_from_string(token.string); case Token_Rune: { Rune r = GB_RUNE_INVALID; gb_utf8_decode(token.string.text, token.string.len, &r); @@ -209,7 +209,7 @@ ExactValue exact_unary_operator_value(Token op, ExactValue v, i32 precision) { failure: GB_PANIC("Invalid unary operation, %.*s", LIT(token_strings[op.kind])); - ExactValue error_value = {}; + ExactValue error_value = {0}; return error_value; } @@ -323,7 +323,7 @@ ExactValue exact_binary_operator_value(Token op, ExactValue x, ExactValue y) { } error: - ExactValue error_value = {}; + ExactValue error_value = {0}; // gb_printf_err("Invalid binary operation: %s\n", token_kind_to_string(op.kind)); return error_value; } diff --git a/src/map.c b/src/map.c index 9d6f93c98..3ffd2a230 100644 --- a/src/map.c +++ b/src/map.c @@ -76,7 +76,7 @@ gb_inline void _J2(MAP_FUNC,destroy)(MAP_NAME *h) { } gb_internal isize _J2(MAP_FUNC,_add_entry)(MAP_NAME *h, HashKey key) { - MAP_ENTRY e = {}; + MAP_ENTRY e = {0}; e.key = key; e.next = -1; array_add(&h->entries, e); @@ -99,7 +99,7 @@ gb_internal MapFindResult _J2(MAP_FUNC,_find)(MAP_NAME *h, HashKey key) { return fr; } -gb_internal MapFindResult _J2(MAP_FUNC,_find)(MAP_NAME *h, MAP_ENTRY *e) { +gb_internal MapFindResult _J2(MAP_FUNC,_find_from_entry)(MAP_NAME *h, MAP_ENTRY *e) { MapFindResult fr = {-1, -1, -1}; if (h->hashes.count > 0) { fr.hash_index = e->key.key % h->hashes.count; @@ -244,7 +244,7 @@ MAP_ENTRY *_J2(MAP_FUNC,multi_find_next)(MAP_NAME *h, MAP_ENTRY *e) { isize _J2(MAP_FUNC,multi_count)(MAP_NAME *h, HashKey key) { isize count = 0; - auto *e = _J2(MAP_FUNC,multi_find_first)(h, key); + MAP_ENTRY *e = _J2(MAP_FUNC,multi_find_first)(h, key); while (e != NULL) { count++; e = _J2(MAP_FUNC,multi_find_next)(h, e); @@ -254,7 +254,7 @@ isize _J2(MAP_FUNC,multi_count)(MAP_NAME *h, HashKey key) { void _J2(MAP_FUNC,multi_get_all)(MAP_NAME *h, HashKey key, MAP_TYPE *items) { isize i = 0; - auto *e = _J2(MAP_FUNC,multi_find_first)(h, key); + MAP_ENTRY *e = _J2(MAP_FUNC,multi_find_first)(h, key); while (e != NULL) { items[i++] = e->value; e = _J2(MAP_FUNC,multi_find_next)(h, e); @@ -280,7 +280,7 @@ void _J2(MAP_FUNC,multi_insert)(MAP_NAME *h, HashKey key, MAP_TYPE value) { } void _J2(MAP_FUNC,multi_remove)(MAP_NAME *h, HashKey key, MAP_ENTRY *e) { - MapFindResult fr = _J2(MAP_FUNC,_find)(h, e); + MapFindResult fr = _J2(MAP_FUNC,_find_from_entry)(h, e); if (fr.entry_index >= 0) { _J2(MAP_FUNC,_erase)(h, fr); } diff --git a/src/old_vm.cpp b/src/old_vm.cpp index e1a92151c..071af7ae3 100644 --- a/src/old_vm.cpp +++ b/src/old_vm.cpp @@ -25,7 +25,7 @@ struct vmValue { vmValue vm_make_value_ptr(Type *type, void *ptr) { GB_ASSERT(is_type_pointer(type)); - vmValue v = {}; + vmValue v = {0}; v.type = default_type(type); v.val_ptr = ptr; return v; @@ -34,21 +34,21 @@ vmValue vm_make_value_int(Type *type, i64 i) { GB_ASSERT(is_type_integer(type) || is_type_boolean(type) || is_type_enum(type)); - vmValue v = {}; + vmValue v = {0}; v.type = default_type(type); v.val_int = i; return v; } vmValue vm_make_value_f32(Type *type, f32 f) { GB_ASSERT(is_type_f32(type)); - vmValue v = {}; + vmValue v = {0}; v.type = default_type(type); v.val_f32 = f; return v; } vmValue vm_make_value_f64(Type *type, f64 f) { GB_ASSERT(is_type_f64(type)); - vmValue v = {}; + vmValue v = {0}; v.type = default_type(type); v.val_f64 = f; return v; @@ -65,7 +65,7 @@ vmValue vm_make_value_comp(Type *type, gbAllocator allocator, isize count) { is_type_raw_union(type) || is_type_tuple (type) || is_type_proc (type)); - vmValue v = {}; + vmValue v = {0}; v.type = default_type(type); array_init_count(&v.val_comp, allocator, count); return v; @@ -183,7 +183,7 @@ void vm_set_value(vmFrame *f, ssaValue *v, vmValue val) { vmFrame *vm_push_frame(VirtualMachine *vm, ssaProcedure *proc) { - vmFrame frame = {}; + vmFrame frame = {0}; frame.vm = vm; frame.curr_proc = proc; @@ -227,7 +227,7 @@ vmValue vm_call_proc(VirtualMachine *vm, ssaProcedure *proc, Array valu if (proc->body == NULL) { // GB_PANIC("TODO(bill): external procedure"); gb_printf_err("TODO(bill): external procedure: %.*s\n", LIT(proc->name)); - vmValue result = {}; + vmValue result = {0}; result.type = result_type; return result; } @@ -269,7 +269,7 @@ vmValue vm_call_proc(VirtualMachine *vm, ssaProcedure *proc, Array valu return vm_load(vm, result_mem, result_type); } - vmValue void_result = {}; + vmValue void_result = {0}; return void_result; } @@ -323,7 +323,7 @@ vmValue vm_exact_value(VirtualMachine *vm, ssaValue *ptr, ExactValue value, Type ast_node(cl, CompoundLit, value.value_compound); if (is_type_array(t)) { - vmValue result = {}; + vmValue result = {0}; isize elem_count = cl->elems.count; if (elem_count == 0) { @@ -347,7 +347,7 @@ vmValue vm_exact_value(VirtualMachine *vm, ssaValue *ptr, ExactValue value, Type return result; } else if (is_type_vector(t)) { - vmValue result = {}; + vmValue result = {0}; isize elem_count = cl->elems.count; if (elem_count == 0) { @@ -409,7 +409,7 @@ vmValue vm_exact_value(VirtualMachine *vm, ssaValue *ptr, ExactValue value, Type } } else if (value.kind == ExactValue_Invalid) { - vmValue zero_result = {}; + vmValue zero_result = {0}; zero_result.type = t; return zero_result; } else { @@ -417,14 +417,14 @@ vmValue vm_exact_value(VirtualMachine *vm, ssaValue *ptr, ExactValue value, Type } GB_ASSERT_MSG(t == NULL, "%s - %d", type_to_string(t), value.kind); - vmValue void_result = {}; + vmValue void_result = {0}; return void_result; } vmValue vm_operand_value(VirtualMachine *vm, ssaValue *value) { vmFrame *f = vm_back_frame(vm); - vmValue v = {}; + vmValue v = {0}; switch (value->kind) { case ssaValue_Constant: { v = vm_exact_value(vm, value, value->Constant.value, value->Constant.type); @@ -637,7 +637,7 @@ void vm_store(VirtualMachine *vm, void *dst, vmValue val, Type *type) { vmValue vm_load_integer(VirtualMachine *vm, void *ptr, Type *type) { // TODO(bill): I assume little endian here - vmValue v = {}; + vmValue v = {0}; v.type = type; GB_ASSERT(is_type_integer(type) || is_type_boolean(type)); // NOTE(bill): Only load the needed amount @@ -647,7 +647,7 @@ vmValue vm_load_integer(VirtualMachine *vm, void *ptr, Type *type) { vmValue vm_load_pointer(VirtualMachine *vm, void *ptr, Type *type) { // TODO(bill): I assume little endian here - vmValue v = {}; + vmValue v = {0}; v.type = type; GB_ASSERT(is_type_pointer(type)); // NOTE(bill): Only load the needed amount @@ -783,12 +783,12 @@ vmValue vm_load(VirtualMachine *vm, void *ptr, Type *type) { } GB_ASSERT(type == NULL); - vmValue void_result = {}; + vmValue void_result = {0}; return void_result; } vmValue vm_exec_binary_op(VirtualMachine *vm, Type *type, vmValue lhs, vmValue rhs, TokenKind op) { - vmValue result = {}; + vmValue result = {0}; type = base_type(type); if (is_type_vector(type)) { @@ -834,7 +834,7 @@ vmValue vm_exec_binary_op(VirtualMachine *vm, Type *type, vmValue lhs, vmValue r case Token_GtEq: result.val_f64 = lhs.val_f64 >= rhs.val_f64; break; } } else if (is_type_string(type)) { - Array args = {}; + Array args = {0}; array_init_count(&args, vm->stack_allocator, 2); args[0] = lhs; args[1] = rhs; @@ -912,7 +912,7 @@ void vm_exec_instr(VirtualMachine *vm, ssaValue *value) { switch (instr->kind) { case ssaInstr_StartupRuntime: { #if 1 - Array args = {}; // Empty + Array args = {0}; // Empty vm_call_proc_by_name(vm, make_string(SSA_STARTUP_RUNTIME_PROC_NAME), args); // NOTE(bill): No return value #endif } break; @@ -1025,7 +1025,7 @@ void vm_exec_instr(VirtualMachine *vm, ssaValue *value) { case ssaInstr_Return: { Type *return_type = NULL; - vmValue result = {}; + vmValue result = {0}; if (instr->Return.value != NULL) { return_type = ssa_type(instr->Return.value); @@ -1040,7 +1040,7 @@ void vm_exec_instr(VirtualMachine *vm, ssaValue *value) { case ssaInstr_Conv: { // TODO(bill): Assuming little endian - vmValue dst = {}; + vmValue dst = {0}; vmValue src = vm_operand_value(vm, instr->Conv.value); i64 from_size = vm_type_size_of(vm, instr->Conv.from); i64 to_size = vm_type_size_of(vm, instr->Conv.to); @@ -1129,7 +1129,7 @@ void vm_exec_instr(VirtualMachine *vm, ssaValue *value) { } break; case ssaInstr_Call: { - Array args = {}; + Array args = {0}; array_init(&args, f->stack_allocator, instr->Call.arg_count); for (isize i = 0; i < instr->Call.arg_count; i++) { array_add(&args, vm_operand_value(vm, instr->Call.args[i])); @@ -1145,7 +1145,7 @@ void vm_exec_instr(VirtualMachine *vm, ssaValue *value) { } break; case ssaInstr_Select: { - vmValue v = {}; + vmValue v = {0}; vmValue cond = vm_operand_value(vm, instr->Select.cond); if (cond.val_int != 0) { v = vm_operand_value(vm, instr->Select.true_value); @@ -1184,7 +1184,7 @@ void vm_exec_instr(VirtualMachine *vm, ssaValue *value) { case ssaInstr_BoundsCheck: { ssaInstrBoundsCheck *bc = &instr->BoundsCheck; - Array args = {}; + Array args = {0}; array_init(&args, vm->stack_allocator, 5); array_add(&args, vm_exact_value(vm, NULL, make_exact_value_string(bc->pos.file), t_string)); array_add(&args, vm_exact_value(vm, NULL, make_exact_value_integer(bc->pos.line), t_int)); @@ -1197,7 +1197,7 @@ void vm_exec_instr(VirtualMachine *vm, ssaValue *value) { case ssaInstr_SliceBoundsCheck: { ssaInstrSliceBoundsCheck *bc = &instr->SliceBoundsCheck; - Array args = {}; + Array args = {0}; array_init(&args, vm->stack_allocator, 7); array_add(&args, vm_exact_value(vm, NULL, make_exact_value_string(bc->pos.file), t_string)); diff --git a/src/parser.cpp b/src/parser.cpp index 16235475a..32da1680a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -117,7 +117,7 @@ AstNodeArray make_ast_node_array(AstFile *f) { AstNodeArray elems; \ Token open, close; \ }) \ -AST_NODE_KIND(_ExprBegin, "", struct{}) \ +AST_NODE_KIND(_ExprBegin, "", i32) \ AST_NODE_KIND(BadExpr, "bad expression", struct { Token begin, end; }) \ AST_NODE_KIND(TagExpr, "tag expression", struct { Token token, name; AstNode *expr; }) \ AST_NODE_KIND(RunExpr, "run expression", struct { Token token, name; AstNode *expr; }) \ @@ -142,8 +142,8 @@ AST_NODE_KIND(_ExprBegin, "", struct{}) \ bool triple_indexed; \ }) \ AST_NODE_KIND(FieldValue, "field value", struct { Token eq; AstNode *field, *value; }) \ -AST_NODE_KIND(_ExprEnd, "", struct{}) \ -AST_NODE_KIND(_StmtBegin, "", struct{}) \ +AST_NODE_KIND(_ExprEnd, "", i32) \ +AST_NODE_KIND(_StmtBegin, "", i32) \ AST_NODE_KIND(BadStmt, "bad statement", struct { Token begin, end; }) \ AST_NODE_KIND(EmptyStmt, "empty statement", struct { Token token; }) \ AST_NODE_KIND(ExprStmt, "expression statement", struct { AstNode *expr; } ) \ @@ -157,7 +157,7 @@ AST_NODE_KIND(_StmtBegin, "", struct{}) \ Token op; \ AstNodeArray lhs, rhs; \ }) \ -AST_NODE_KIND(_ComplexStmtBegin, "", struct{}) \ +AST_NODE_KIND(_ComplexStmtBegin, "", i32) \ AST_NODE_KIND(BlockStmt, "block statement", struct { \ AstNodeArray stmts; \ Token open, close; \ @@ -220,9 +220,9 @@ AST_NODE_KIND(_ComplexStmtBegin, "", struct{}) \ AstNode *body; \ }) \ \ -AST_NODE_KIND(_ComplexStmtEnd, "", struct{}) \ -AST_NODE_KIND(_StmtEnd, "", struct{}) \ -AST_NODE_KIND(_DeclBegin, "", struct{}) \ +AST_NODE_KIND(_ComplexStmtEnd, "", i32) \ +AST_NODE_KIND(_StmtEnd, "", i32) \ +AST_NODE_KIND(_DeclBegin, "", i32) \ AST_NODE_KIND(BadDecl, "bad declaration", struct { Token begin, end; }) \ AST_NODE_KIND(VarDecl, "variable declaration", struct { \ u64 tags; \ @@ -264,8 +264,8 @@ AST_NODE_KIND(_DeclBegin, "", struct{}) \ Token token, filepath; \ bool is_system; \ }) \ -AST_NODE_KIND(_DeclEnd, "", struct{}) \ -AST_NODE_KIND(_TypeBegin, "", struct{}) \ +AST_NODE_KIND(_DeclEnd, "", i32) \ +AST_NODE_KIND(_TypeBegin, "", i32) \ AST_NODE_KIND(Parameter, "parameter", struct { \ AstNodeArray names; \ AstNode *type; \ @@ -316,7 +316,7 @@ AST_NODE_KIND(_TypeBegin, "", struct{}) \ AstNode *base_type; \ AstNodeArray fields; \ }) \ -AST_NODE_KIND(_TypeEnd, "", struct{}) +AST_NODE_KIND(_TypeEnd, "", i32) typedef enum AstNodeKind { AstNode_Invalid, @@ -1186,7 +1186,7 @@ AstNodeArray parse_element_list(AstFile *f) { } AstNode *parse_literal_value(AstFile *f, AstNode *type) { - AstNodeArray elems = {}; + AstNodeArray elems = {0}; Token open = expect_token(f, Token_OpenBrace); f->expr_level++; if (f->curr_token.kind != Token_CloseBrace) { @@ -1206,7 +1206,7 @@ AstNode *parse_value(AstFile *f) { return value; } -AstNode *parse_identifier_or_type(AstFile *f, u32 flags = 0); +AstNode *parse_identifier_or_type(AstFile *f, u32 flags); void check_proc_add_tag(AstFile *f, AstNode *tag_expr, u64 *tags, ProcTag tag, String tag_name) { @@ -1418,8 +1418,8 @@ AstNode *parse_operand(AstFile *f, bool lhs) { f->curr_proc = type; u64 tags = 0; - String foreign_name = {}; - String link_name = {}; + String foreign_name = {0}; + String link_name = {0}; parse_proc_tags(f, &tags, &foreign_name, &link_name); if (tags & ProcTag_foreign) { syntax_error(f->curr_token, "#foreign cannot be applied to procedure literals"); @@ -1442,7 +1442,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { } default: { - AstNode *type = parse_identifier_or_type(f); + AstNode *type = parse_identifier_or_type(f, 0); if (type != NULL) { // NOTE(bill): Sanity check as identifiers should be handled already GB_ASSERT_MSG(type->kind != AstNode_Ident, "Type Cannot be identifier"); @@ -1473,7 +1473,7 @@ bool is_literal_type(AstNode *node) { AstNode *parse_call_expr(AstFile *f, AstNode *operand) { AstNodeArray args = make_ast_node_array(f); Token open_paren, close_paren; - Token ellipsis = {}; + Token ellipsis = {0}; f->expr_level++; open_paren = expect_token(f, Token_OpenParen); @@ -1555,7 +1555,7 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) { // TODO(bill): Handle this } Token open, close; - AstNode *indices[3] = {}; + AstNode *indices[3] = {0}; f->expr_level++; open = expect_token(f, Token_OpenBracket); @@ -1563,7 +1563,7 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) { if (f->curr_token.kind != Token_Colon) indices[0] = parse_expr(f, false); isize colon_count = 0; - Token colons[2] = {}; + Token colons[2] = {0}; while (f->curr_token.kind == Token_Colon && colon_count < 2) { colons[colon_count++] = f->curr_token; @@ -1720,7 +1720,7 @@ AstNode *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { expression = call; } else */{ right = parse_binary_expr(f, false, prec+1); - AstNodeArray args = {}; + AstNodeArray args = {0}; array_init_reserve(&args, gb_arena_allocator(&f->arena), 2); array_add(&args, expression); array_add(&args, right); @@ -1880,7 +1880,7 @@ AstNodeArray parse_identfier_list(AstFile *f) { AstNode *parse_type_attempt(AstFile *f) { - AstNode *type = parse_identifier_or_type(f); + AstNode *type = parse_identifier_or_type(f, 0); if (type != NULL) { // TODO(bill): Handle? } @@ -1903,8 +1903,8 @@ Token parse_procedure_signature(AstFile *f, AstNodeArray *params, AstNodeArray *results); AstNode *parse_proc_type(AstFile *f) { - AstNodeArray params = {}; - AstNodeArray results = {}; + AstNodeArray params = {0}; + AstNodeArray results = {0}; Token proc_token = parse_procedure_signature(f, ¶ms, &results); @@ -2237,7 +2237,7 @@ Token parse_procedure_signature(AstFile *f, } AstNode *parse_body(AstFile *f) { - AstNodeArray stmts = {}; + AstNodeArray stmts = {0}; Token open, close; open = expect_token(f, Token_OpenBrace); stmts = parse_stmt_list(f); @@ -2249,16 +2249,16 @@ AstNode *parse_body(AstFile *f) { AstNode *parse_proc_decl(AstFile *f, Token proc_token, AstNode *name) { - AstNodeArray params = {}; - AstNodeArray results = {}; + AstNodeArray params = {0}; + AstNodeArray results = {0}; parse_procedure_signature(f, ¶ms, &results); AstNode *proc_type = make_proc_type(f, proc_token, params, results); AstNode *body = NULL; u64 tags = 0; - String foreign_name = {}; - String link_name = {}; + String foreign_name = {0}; + String link_name = {0}; parse_proc_tags(f, &tags, &foreign_name, &link_name); @@ -2277,7 +2277,7 @@ AstNode *parse_proc_decl(AstFile *f, Token proc_token, AstNode *name) { } AstNode *parse_decl(AstFile *f, AstNodeArray names) { - AstNodeArray values = {}; + AstNodeArray values = {0}; AstNode *type = NULL; for_array(i, names) { @@ -2294,7 +2294,7 @@ AstNode *parse_decl(AstFile *f, AstNodeArray names) { if (allow_token(f, Token_Colon)) { if (!allow_token(f, Token_type)) { - type = parse_identifier_or_type(f); + type = parse_identifier_or_type(f, 0); } } else if (f->curr_token.kind != Token_Eq && f->curr_token.kind != Token_Semicolon) { syntax_error(f->curr_token, "Expected type separator `:` or `=`"); @@ -2756,7 +2756,7 @@ AstNode *parse_stmt(AstFile *f) { return make_bad_decl(f, token, f->curr_token); } else if (str_eq(tag, str_lit("import"))) { // TODO(bill): better error messages - Token import_name = {}; + Token import_name = {0}; Token file_path = expect_token_after(f, Token_String, "#import"); if (allow_token(f, Token_as)) { // NOTE(bill): Custom import name @@ -2970,7 +2970,7 @@ bool try_add_import_path(Parser *p, String path, String rel_path, TokenPos pos) } String get_fullpath_relative(gbAllocator a, String base_dir, String path) { - String res = {}; + String res = {0}; isize str_len = base_dir.len+path.len; u8 *str = gb_alloc_array(heap_allocator(), u8, str_len+1); @@ -2986,7 +2986,7 @@ String get_fullpath_relative(gbAllocator a, String base_dir, String path) { String get_fullpath_core(gbAllocator a, String path) { String module_dir = get_module_dir(); - String res = {}; + String res = {0}; char core[] = "core/"; isize core_len = gb_size_of(core)-1; @@ -3170,7 +3170,7 @@ void parse_file(Parser *p, AstFile *f) { ParseFileError parse_files(Parser *p, char *init_filename) { char *fullpath_str = gb_path_get_full_name(heap_allocator(), init_filename); String init_fullpath = make_string_c(fullpath_str); - TokenPos init_pos = {}; + TokenPos init_pos = {0}; ImportedFile init_imported_file = {init_fullpath, init_fullpath, init_pos}; array_add(&p->imports, init_imported_file); p->init_fullpath = init_fullpath; @@ -3191,7 +3191,7 @@ ParseFileError parse_files(Parser *p, char *init_filename) { String import_path = imported_file.path; String import_rel_path = imported_file.rel_path; TokenPos pos = imported_file.pos; - AstFile file = {}; + AstFile file = {0}; ParseFileError err = init_ast_file(&file, import_path); if (err != ParseFile_None) { diff --git a/src/ssa.cpp b/src/ssa.cpp index 16156e985..c86be9d01 100644 --- a/src/ssa.cpp +++ b/src/ssa.cpp @@ -191,7 +191,7 @@ struct ssaProcedure { ssaValue *false_value; \ }) \ SSA_INSTR_KIND(Phi, struct { ssaValueArray edges; Type *type; }) \ - SSA_INSTR_KIND(Unreachable, struct {}) \ + SSA_INSTR_KIND(Unreachable, i32) \ SSA_INSTR_KIND(BinaryOp, struct { \ Type * type; \ TokenKind op; \ @@ -218,7 +218,7 @@ struct ssaProcedure { i32 index_count; \ Type * type; \ }) \ - SSA_INSTR_KIND(StartupRuntime, struct {}) \ + SSA_INSTR_KIND(StartupRuntime, i32) \ SSA_INSTR_KIND(BoundsCheck, struct { \ TokenPos pos; \ ssaValue *index; \ @@ -1181,9 +1181,9 @@ ssaValue *ssa_add_global_string_array(ssaModule *m, String string) { -ssaValue *ssa_add_local(ssaProcedure *proc, Entity *e, bool zero_initialized = true) { +ssaValue *ssa_add_local(ssaProcedure *proc, Entity *e) { ssaBlock *b = proc->decl_block; // all variables must be in the first block - ssaValue *instr = ssa_make_instr_local(proc, e, zero_initialized); + ssaValue *instr = ssa_make_instr_local(proc, e, true); instr->Instr.parent = b; array_add(&b->instrs, instr); array_add(&b->locals, instr); @@ -1201,7 +1201,7 @@ ssaValue *ssa_add_local_for_identifier(ssaProcedure *proc, AstNode *name, bool z if (found) { Entity *e = *found; ssa_emit_comment(proc, e->token.string); - return ssa_add_local(proc, e, zero_initialized); + return ssa_add_local(proc, e); } return NULL; } @@ -1217,7 +1217,7 @@ ssaValue *ssa_add_local_generated(ssaProcedure *proc, Type *type) { scope, empty_token, type); - return ssa_add_local(proc, e, true); + return ssa_add_local(proc, e); } ssaValue *ssa_add_param(ssaProcedure *proc, Entity *e) { @@ -1543,6 +1543,7 @@ ssaValue *ssa_emit_comp(ssaProcedure *proc, TokenKind op_kind, ssaValue *left, s } ssaValue *ssa_emit_array_ep(ssaProcedure *proc, ssaValue *s, ssaValue *index) { + GB_ASSERT(index != NULL); Type *st = base_type(type_deref(ssa_type(s))); GB_ASSERT(is_type_array(st) || is_type_vector(st)); @@ -1551,7 +1552,7 @@ ssaValue *ssa_emit_array_ep(ssaProcedure *proc, ssaValue *s, ssaValue *index) { return ssa_emit(proc, ssa_make_instr_array_element_ptr(proc, s, index)); } -ssaValue *ssa_emit_array_ep(ssaProcedure *proc, ssaValue *s, i32 index) { +ssaValue *ssa_emit_array_epi(ssaProcedure *proc, ssaValue *s, i32 index) { return ssa_emit_array_ep(proc, s, ssa_make_const_i32(proc->module->allocator, index)); } @@ -1710,9 +1711,9 @@ ssaValue *ssa_emit_deep_field_gep(ssaProcedure *proc, Type *type, ssaValue *e, S } else if (type->kind == Type_Slice) { e = ssa_emit_struct_ep(proc, e, index); } else if (type->kind == Type_Vector) { - e = ssa_emit_array_ep(proc, e, index); + e = ssa_emit_array_epi(proc, e, index); } else if (type->kind == Type_Array) { - e = ssa_emit_array_ep(proc, e, index); + e = ssa_emit_array_epi(proc, e, index); } else { GB_PANIC("un-gep-able type"); } @@ -2404,7 +2405,7 @@ ssaValue *ssa_emit_logical_binary_expr(ssaProcedure *proc, AstNode *expr) { return ssa_build_expr(proc, be->right); } - ssaValueArray edges = {}; + ssaValueArray edges = {0}; array_init_reserve(&edges, proc->module->allocator, done->preds.count+1); for_array(i, done->preds) { array_add(&edges, short_circuit); @@ -2827,7 +2828,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue TokenPos pos = token.pos; gbString expr = expr_to_string(ce->args.e[0]); isize expr_len = gb_string_length(expr); - String expr_str = {}; + String expr_str = {0}; expr_str.text = cast(u8 *)gb_alloc_copy_align(proc->module->allocator, expr, expr_len, 1); expr_str.len = expr_len; gb_string_free(expr); @@ -3171,11 +3172,11 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue ssaValue *base_array = ssa_add_local_generated(proc, make_type_array(allocator, elem_type, slice_len)); for (isize i = type->param_count-1, j = 0; i < arg_count; i++, j++) { - ssaValue *addr = ssa_emit_array_ep(proc, base_array, j); + ssaValue *addr = ssa_emit_array_epi(proc, base_array, j); ssa_emit_store(proc, addr, args[i]); } - ssaValue *base_elem = ssa_emit_array_ep(proc, base_array, 0); + ssaValue *base_elem = ssa_emit_array_epi(proc, base_array, 0); ssaValue *slice_elem = ssa_emit_struct_ep(proc, slice, 0); ssa_emit_store(proc, slice_elem, base_elem); ssaValue *len = ssa_make_const_int(allocator, slice_len); @@ -3268,7 +3269,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) { switch (expr->kind) { case_ast_node(i, Ident, expr); if (ssa_is_blank_ident(expr)) { - ssaAddr val = {}; + ssaAddr val = {0}; return val; } @@ -3677,7 +3678,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) { Type *t = ssa_type(field_expr); GB_ASSERT(t->kind != Type_Tuple); ssaValue *ev = ssa_emit_conv(proc, field_expr, et); - ssaValue *gep = ssa_emit_array_ep(proc, v, i); + ssaValue *gep = ssa_emit_array_epi(proc, v, i); ssa_emit_store(proc, gep, ev); } } @@ -4004,7 +4005,7 @@ void ssa_build_stmt_internal(ssaProcedure *proc, AstNode *node) { for_array(i, as->lhs) { AstNode *lhs = as->lhs.e[i]; - ssaAddr lval = {}; + ssaAddr lval = {0}; if (!ssa_is_blank_ident(lhs)) { lval = ssa_build_addr(proc, lhs); } @@ -4233,7 +4234,7 @@ void ssa_build_stmt_internal(ssaProcedure *proc, AstNode *node) { ast_node(body, BlockStmt, ms->body); - AstNodeArray default_stmts = {}; + AstNodeArray default_stmts = {0}; ssaBlock *default_fall = NULL; ssaBlock *default_block = NULL; @@ -4336,7 +4337,7 @@ void ssa_build_stmt_internal(ssaProcedure *proc, AstNode *node) { String tag_var_name = ms->var->Ident.string; - AstNodeArray default_stmts = {}; + AstNodeArray default_stmts = {0}; ssaBlock *default_block = NULL; @@ -4802,11 +4803,11 @@ String ssa_mangle_name(ssaGen *s, String path, String name) { ssaValue *ssa_get_type_info_ptr(ssaProcedure *proc, ssaValue *type_info_data, Type *type) { i32 index = cast(i32)ssa_type_info_index(proc->module->info, type); // gb_printf_err("%d %s\n", index, type_to_string(type)); - return ssa_emit_array_ep(proc, type_info_data, index); + return ssa_emit_array_epi(proc, type_info_data, index); } ssaValue *ssa_type_info_member_offset(ssaProcedure *proc, ssaValue *data, isize count, i32 *index) { - ssaValue *offset = ssa_emit_array_ep(proc, data, *index); + ssaValue *offset = ssa_emit_array_epi(proc, data, *index); *index += count; return offset; } @@ -4884,7 +4885,7 @@ void ssa_gen_tree(ssaGen *s) { if (decl->var_decl_tags & VarDeclTag_thread_local) { g->Global.is_thread_local = true; } - ssaGlobalVariable var = {}; + ssaGlobalVariable var = {0}; var.var = g; var.decl = decl; @@ -4977,7 +4978,7 @@ void ssa_gen_tree(ssaGen *s) { NULL, 0, false); AstNode *body = gb_alloc_item(a, AstNode); ssaValue *p = ssa_make_value_procedure(a, m, NULL, proc_type, NULL, body, name); - Token token = {}; + Token token = {0}; token.string = name; Entity *e = make_entity_procedure(a, NULL, token, proc_type); @@ -5302,8 +5303,8 @@ void ssa_gen_tree(ssaGen *s) { } for (isize i = 0; i < count; i++) { - ssaValue *value_gep = ssa_emit_array_ep(proc, value_array, i); - ssaValue *name_gep = ssa_emit_array_ep(proc, name_array, i); + ssaValue *value_gep = ssa_emit_array_epi(proc, value_array, i); + ssaValue *name_gep = ssa_emit_array_epi(proc, name_array, i); ssa_emit_store(proc, value_gep, ssa_make_const_i64(a, fields[i]->Constant.value.value_integer)); ssa_emit_store(proc, name_gep, ssa_make_const_string(a, fields[i]->token.string)); @@ -5391,7 +5392,7 @@ void ssa_gen_tree(ssaGen *s) { } if (tag != NULL) { - ssaValue *gep = ssa_emit_array_ep(proc, type_info_data, entry_index); + ssaValue *gep = ssa_emit_array_epi(proc, type_info_data, entry_index); ssaValue *val = ssa_emit_conv(proc, ssa_emit_load(proc, tag), t_type_info); ssa_emit_store(proc, gep, val); } diff --git a/src/ssa_opt.cpp b/src/ssa_opt.cpp index 07223b387..5fccbfcb6 100644 --- a/src/ssa_opt.cpp +++ b/src/ssa_opt.cpp @@ -129,7 +129,7 @@ bool ssa_opt_block_has_phi(ssaBlock *b) { ssaValueArray ssa_get_block_phi_nodes(ssaBlock *b) { - ssaValueArray phis = {}; + ssaValueArray phis = {0}; for_array(i, b->instrs) { ssaInstr *instr = &b->instrs.e[i]->Instr; if (instr->kind != ssaInstr_Phi) { @@ -275,7 +275,7 @@ void ssa_opt_blocks(ssaProcedure *proc) { void ssa_opt_build_referrers(ssaProcedure *proc) { gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&proc->module->tmp_arena); - ssaValueArray ops = {}; // NOTE(bill): Act as a buffer + ssaValueArray ops = {0}; // NOTE(bill): Act as a buffer array_init_reserve(&ops, proc->module->tmp_allocator, 64); // HACK(bill): This _could_ overflow the temp arena for_array(i, proc->blocks) { ssaBlock *b = proc->blocks.e[i]; @@ -375,7 +375,7 @@ void ssa_opt_build_dom_tree(ssaProcedure *proc) { isize n = proc->blocks.count; ssaBlock **buf = gb_alloc_array(proc->module->tmp_allocator, ssaBlock *, 5*n); - ssaLTState lt = {}; + ssaLTState lt = {0}; lt.count = n; lt.sdom = &buf[0*n]; lt.parent = &buf[1*n]; diff --git a/src/ssa_print.cpp b/src/ssa_print.cpp index fcdf136f9..e6e6532d5 100644 --- a/src/ssa_print.cpp +++ b/src/ssa_print.cpp @@ -39,7 +39,7 @@ void ssa_file_buffer_write(ssaFileBuffer *f, void *data, isize len) { void ssa_fprintf(ssaFileBuffer *f, char *fmt, ...) { va_list va; va_start(va, fmt); - char buf[4096] = {}; + char buf[4096] = {0}; isize len = gb_snprintf_va(buf, gb_size_of(buf), fmt, va); ssa_file_buffer_write(f, buf, len-1); va_end(va); @@ -407,7 +407,7 @@ void ssa_print_exact_value(ssaFileBuffer *f, ssaModule *m, ExactValue value, Typ } } break; case ExactValue_Pointer: - if (value.value_pointer == NULL) { + if (value.value_pointer == 0) { ssa_fprintf(f, "null"); } else { ssa_fprintf(f, "inttoptr ("); @@ -1273,7 +1273,7 @@ void ssa_print_type_name(ssaFileBuffer *f, ssaModule *m, ssaValue *v) { void ssa_print_llvm_ir(ssaGen *ssa) { ssaModule *m = &ssa->module; - ssaFileBuffer buf = {}, *f = &buf; + ssaFileBuffer buf = {0}, *f = &buf; ssa_file_buffer_init(f, &ssa->output_file); if (m->layout.len > 0) { diff --git a/src/timings.cpp b/src/timings.cpp index f3bbddb5d..a1eecc01a 100644 --- a/src/timings.cpp +++ b/src/timings.cpp @@ -44,7 +44,7 @@ u64 time_stamp__freq(void) { } TimeStamp make_time_stamp(String label) { - TimeStamp ts = {}; + TimeStamp ts = {0}; ts.start = time_stamp_time_now(); ts.label = label; return ts; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index afa3f9094..edf6e9721 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -373,7 +373,7 @@ TokenizerInitError init_tokenizer(Tokenizer *t, String fullpath) { array_init(&t->allocated_strings, heap_allocator()); } else { - gbFile f = {}; + gbFile f = {0}; gbFileError file_err = gb_file_open(&f, c_str); switch (file_err) { @@ -431,7 +431,7 @@ gb_inline void scan_mantissa(Tokenizer *t, i32 base) { Token scan_number_to_token(Tokenizer *t, bool seen_decimal_point) { - Token token = {}; + Token token = {0}; token.kind = Token_Integer; token.string = make_string(t->curr, 1); token.pos.file = t->fullpath; @@ -609,7 +609,7 @@ gb_inline TokenKind token_kind_dub_eq(Tokenizer *t, Rune sing_rune, TokenKind si } Token tokenizer_get_token(Tokenizer *t) { - Token token = {}; + Token token = {0}; Rune curr_rune; tokenizer_skip_whitespace(t); @@ -802,7 +802,7 @@ Token tokenizer_get_token(Tokenizer *t) { default: if (curr_rune != GB_RUNE_BOM) { - u8 str[4] = {}; + u8 str[4] = {0}; int len = cast(int)gb_utf8_encode_rune(str, curr_rune); tokenizer_err(t, "Illegal character: %.*s (%d) ", len, str, curr_rune); } diff --git a/src/utf8proc/utf8proc.h b/src/utf8proc/utf8proc.h index b27b01179..240fac66f 100644 --- a/src/utf8proc/utf8proc.h +++ b/src/utf8proc/utf8proc.h @@ -94,7 +94,7 @@ typedef unsigned int utf8proc_size_t; # endif # ifndef __cplusplus typedef unsigned char utf8proc_bool; -enum {false, true}; +// enum {false, true}; # else typedef bool utf8proc_bool; # endif