diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-11-23 09:46:58 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-11-23 09:46:58 +0000 |
| commit | 543a2d1e5a0ee96e782fb184ea5b73b9081c0eff (patch) | |
| tree | 8fa17a5fb07c8103dc88d6b760ef1d73c06876a5 /src | |
| parent | 36ad9dae43cd21d8532994cd0d0e92a89af0ed04 (diff) | |
Swap b32 to bool, et al.
Diffstat (limited to 'src')
| -rw-r--r-- | src/checker/checker.cpp | 34 | ||||
| -rw-r--r-- | src/checker/decl.cpp | 12 | ||||
| -rw-r--r-- | src/checker/entity.cpp | 8 | ||||
| -rw-r--r-- | src/checker/expr.cpp | 86 | ||||
| -rw-r--r-- | src/checker/stmt.cpp | 38 | ||||
| -rw-r--r-- | src/checker/types.cpp | 92 | ||||
| -rw-r--r-- | src/common.cpp | 6 | ||||
| -rw-r--r-- | src/exact_value.cpp | 6 | ||||
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/parser.cpp | 96 | ||||
| -rw-r--r-- | src/ssa.cpp | 62 | ||||
| -rw-r--r-- | src/ssa_opt.cpp | 6 | ||||
| -rw-r--r-- | src/ssa_print.cpp | 10 | ||||
| -rw-r--r-- | src/string.cpp | 16 | ||||
| -rw-r--r-- | src/tokenizer.cpp | 16 | ||||
| -rw-r--r-- | src/unicode.cpp | 10 | ||||
| -rw-r--r-- | src/vm.cpp | 356 |
17 files changed, 250 insertions, 608 deletions
diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp index f8c35bcc3..0ff089168 100644 --- a/src/checker/checker.cpp +++ b/src/checker/checker.cpp @@ -38,17 +38,17 @@ struct DeclInfo { AstNode *proc_decl; // AstNode_ProcDecl u32 var_decl_tags; - Map<b32> deps; // Key: Entity * + Map<bool> deps; // Key: Entity * }; struct ExpressionInfo { - b32 is_lhs; // Debug info + bool is_lhs; // Debug info AddressingMode mode; Type * type; // Type_Basic ExactValue value; }; -ExpressionInfo make_expression_info(b32 is_lhs, AddressingMode mode, Type *type, ExactValue value) { +ExpressionInfo make_expression_info(bool is_lhs, AddressingMode mode, Type *type, ExactValue value) { ExpressionInfo ei = {is_lhs, mode, type, value}; return ei; } @@ -72,10 +72,10 @@ struct Scope { Array<Scope *> shared; Array<Scope *> imported; - b32 is_proc; - b32 is_global; - b32 is_file; - b32 is_init; + bool is_proc; + bool is_global; + bool is_file; + bool is_init; AstFile * file; }; gb_global Scope *universal_scope = NULL; @@ -126,7 +126,7 @@ enum BuiltinProcId { struct BuiltinProc { String name; isize arg_count; - b32 variadic; + bool variadic; ExprKind kind; }; gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = { @@ -221,7 +221,7 @@ struct Checker { CheckerContext context; Array<Type *> proc_stack; - b32 in_defer; // TODO(bill): Actually handle correctly + bool in_defer; // TODO(bill): Actually handle correctly }; struct CycleChecker { @@ -265,7 +265,7 @@ void destroy_declaration_info(DeclInfo *d) { map_destroy(&d->deps); } -b32 decl_info_has_init(DeclInfo *d) { +bool decl_info_has_init(DeclInfo *d) { if (d->init_expr != NULL) { return true; } @@ -347,7 +347,7 @@ void check_close_scope(Checker *c) { } void scope_lookup_parent_entity(Scope *scope, String name, Scope **scope_, Entity **entity_) { - b32 gone_thru_proc = false; + bool gone_thru_proc = false; HashKey key = hash_string(name); for (Scope *s = scope; s != NULL; s = s->parent) { Entity **found = map_get(&s->elements, key); @@ -460,7 +460,7 @@ void check_scope_usage(Checker *c, Scope *scope) { void add_dependency(DeclInfo *d, Entity *e) { - map_set(&d->deps, hash_pointer(e), cast(b32)true); + map_set(&d->deps, hash_pointer(e), true); } void add_declaration_dependency(Checker *c, Entity *e) { @@ -633,7 +633,7 @@ Type *type_of_expr(CheckerInfo *i, AstNode *expression) { } -void add_untyped(CheckerInfo *i, AstNode *expression, b32 lhs, AddressingMode mode, Type *basic_type, ExactValue value) { +void add_untyped(CheckerInfo *i, AstNode *expression, bool lhs, AddressingMode mode, Type *basic_type, ExactValue value) { map_set(&i->untyped, hash_pointer(expression), make_expression_info(lhs, mode, basic_type, value)); } @@ -670,7 +670,7 @@ void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) } } -b32 add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) { +bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) { if (entity->token.string != make_string("_")) { Entity *insert_entity = scope_insert_entity(scope, entity); if (insert_entity) { @@ -1161,7 +1161,7 @@ void check_parsed_files(Checker *c) { continue; } - b32 previously_added = false; + bool previously_added = false; for_array(import_index, file_scope->imported) { Scope *prev = file_scope->imported[import_index]; if (prev == scope) { @@ -1296,8 +1296,8 @@ void check_parsed_files(Checker *c) { ProcedureInfo *pi = &c->procs[i]; add_curr_ast_file(c, pi->file); - b32 bounds_check = (pi->tags & ProcTag_bounds_check) != 0; - b32 no_bounds_check = (pi->tags & ProcTag_no_bounds_check) != 0; + bool bounds_check = (pi->tags & ProcTag_bounds_check) != 0; + bool no_bounds_check = (pi->tags & ProcTag_no_bounds_check) != 0; auto prev_context = c->context; defer (c->context = prev_context); diff --git a/src/checker/decl.cpp b/src/checker/decl.cpp index 63cd6e3ce..c99296ec6 100644 --- a/src/checker/decl.cpp +++ b/src/checker/decl.cpp @@ -1,4 +1,4 @@ -b32 check_is_terminating(AstNode *node); +bool check_is_terminating(AstNode *node); void check_stmt (Checker *c, AstNode *node, u32 flags); void check_stmt_list (Checker *c, AstNodeArray stmts, u32 flags); void check_type_decl (Checker *c, Entity *e, AstNode *type_expr, Type *def, CycleChecker *cycle_checker); @@ -322,7 +322,7 @@ void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *def, Cycle } -b32 are_signatures_similar_enough(Type *a_, Type *b_) { +bool are_signatures_similar_enough(Type *a_, Type *b_) { GB_ASSERT(a_->kind == Type_Proc); GB_ASSERT(b_->kind == Type_Proc); auto *a = &a_->Proc; @@ -372,10 +372,10 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) { defer (check_close_scope(c)); check_procedure_type(c, proc_type, pd->type); - b32 is_foreign = (pd->tags & ProcTag_foreign) != 0; - b32 is_link_name = (pd->tags & ProcTag_link_name) != 0; - b32 is_inline = (pd->tags & ProcTag_inline) != 0; - b32 is_no_inline = (pd->tags & ProcTag_no_inline) != 0; + bool is_foreign = (pd->tags & ProcTag_foreign) != 0; + bool is_link_name = (pd->tags & ProcTag_link_name) != 0; + bool is_inline = (pd->tags & ProcTag_inline) != 0; + bool is_no_inline = (pd->tags & ProcTag_no_inline) != 0; if ((d->scope->is_file || d->scope->is_global) && e->token.string == "main") { diff --git a/src/checker/entity.cpp b/src/checker/entity.cpp index 44c32bece..dec2a7ee8 100644 --- a/src/checker/entity.cpp +++ b/src/checker/entity.cpp @@ -66,7 +66,7 @@ struct Entity { String path; String name; Scope *scope; - b32 used; + bool used; } ImportName; struct {} Nil; struct { @@ -77,7 +77,7 @@ struct Entity { }; }; -b32 is_entity_exported(Entity *e) { +bool is_entity_exported(Entity *e) { if (e->kind == Entity_ImportName) { return false; } @@ -125,7 +125,7 @@ Entity *make_entity_type_name(gbAllocator a, Scope *scope, Token token, Type *ty return entity; } -Entity *make_entity_param(gbAllocator a, Scope *scope, Token token, Type *type, b32 anonymous) { +Entity *make_entity_param(gbAllocator a, Scope *scope, Token token, Type *type, bool anonymous) { Entity *entity = make_entity_variable(a, scope, token, type); entity->flags |= EntityFlag_Used; entity->flags |= EntityFlag_Anonymous*(anonymous != 0); @@ -133,7 +133,7 @@ Entity *make_entity_param(gbAllocator a, Scope *scope, Token token, Type *type, return entity; } -Entity *make_entity_field(gbAllocator a, Scope *scope, Token token, Type *type, b32 anonymous, i32 field_src_index) { +Entity *make_entity_field(gbAllocator a, Scope *scope, Token token, Type *type, bool anonymous, i32 field_src_index) { Entity *entity = make_entity_variable(a, scope, token, type); entity->Variable.field_src_index = field_src_index; entity->Variable.field_index = field_src_index; diff --git a/src/checker/expr.cpp b/src/checker/expr.cpp index 1b2353ac5..5b20899ec 100644 --- a/src/checker/expr.cpp +++ b/src/checker/expr.cpp @@ -6,22 +6,22 @@ Type * check_type (Checker *c, AstNode *expression, Type *named 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); -b32 check_value_is_expressible(Checker *c, ExactValue in_value, Type *type, ExactValue *out_value); +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); 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_proc_body (Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body); -void update_expr_type (Checker *c, AstNode *e, Type *type, b32 final); +void update_expr_type (Checker *c, AstNode *e, Type *type, bool final); -b32 check_is_assignable_to_using_subtype(Type *dst, Type *src) { +bool check_is_assignable_to_using_subtype(Type *dst, Type *src) { Type *prev_src = src; // Type *prev_dst = dst; src = base_type(type_deref(src)); // dst = base_type(type_deref(dst)); - b32 src_is_ptr = src != prev_src; - // b32 dst_is_ptr = dst != prev_dst; + bool src_is_ptr = src != prev_src; + // bool dst_is_ptr = dst != prev_dst; if (is_type_struct(src)) { for (isize i = 0; i < src->Record.field_count; i++) { @@ -35,7 +35,7 @@ b32 check_is_assignable_to_using_subtype(Type *dst, Type *src) { return true; } } - b32 ok = check_is_assignable_to_using_subtype(dst, f->type); + bool ok = check_is_assignable_to_using_subtype(dst, f->type); if (ok) { return true; } @@ -46,7 +46,7 @@ b32 check_is_assignable_to_using_subtype(Type *dst, Type *src) { } -b32 check_is_assignable_to(Checker *c, Operand *operand, Type *type, b32 is_argument = false) { +bool check_is_assignable_to(Checker *c, Operand *operand, Type *type, bool is_argument = false) { PROF_PROC(); if (operand->mode == Addressing_Invalid || @@ -152,7 +152,7 @@ b32 check_is_assignable_to(Checker *c, Operand *operand, Type *type, b32 is_argu // NOTE(bill): `content_name` is for debugging and error messages -void check_assignment(Checker *c, Operand *operand, Type *type, String context_name, b32 is_argument = false) { +void check_assignment(Checker *c, Operand *operand, Type *type, String context_name, bool is_argument = false) { PROF_PROC(); check_not_tuple(c, operand); @@ -432,7 +432,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls, if (!is_type_struct(t) && !is_type_raw_union(t)) { Token name_token = vd->names[0]->Ident; if (is_type_indexable(t)) { - b32 ok = true; + bool ok = true; for_array(emi, entity_map.entries) { Entity *e = entity_map.entries[emi].value; if (e->kind == Entity_Variable && e->flags & EntityFlag_Anonymous) { @@ -773,14 +773,14 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod make_token_ident(make_string("max_value")), constant_type, make_exact_value_integer(max_value)); } -Type *check_get_params(Checker *c, Scope *scope, AstNodeArray params, b32 *is_variadic_) { +Type *check_get_params(Checker *c, Scope *scope, AstNodeArray params, bool *is_variadic_) { PROF_PROC(); if (params.count == 0) { return NULL; } - b32 is_variadic = false; + bool is_variadic = false; Type *tuple = make_type_tuple(c->allocator); @@ -870,7 +870,7 @@ void check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node) { ast_node(pt, ProcType, proc_type_node); - b32 variadic = false; + bool variadic = false; Type *params = check_get_params(c, c->context.scope, pt->params, &variadic); Type *results = check_get_results(c, c->context.scope, pt->results); @@ -1214,7 +1214,7 @@ end: } -b32 check_unary_op(Checker *c, Operand *o, Token op) { +bool check_unary_op(Checker *c, Operand *o, Token op) { // TODO(bill): Handle errors correctly Type *type = base_type(base_vector_type(o->type)); gbString str = NULL; @@ -1249,7 +1249,7 @@ b32 check_unary_op(Checker *c, Operand *o, Token op) { return true; } -b32 check_binary_op(Checker *c, Operand *o, Token op) { +bool check_binary_op(Checker *c, Operand *o, Token op) { // TODO(bill): Handle errors correctly Type *type = base_type(base_vector_type(o->type)); switch (op.kind) { @@ -1323,7 +1323,7 @@ b32 check_binary_op(Checker *c, Operand *o, Token op) { return true; } -b32 check_value_is_expressible(Checker *c, ExactValue in_value, Type *type, ExactValue *out_value) { +bool check_value_is_expressible(Checker *c, ExactValue in_value, Type *type, ExactValue *out_value) { PROF_PROC(); if (in_value.kind == ExactValue_Invalid) { @@ -1431,7 +1431,7 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) { } } -b32 check_is_expr_vector_index(Checker *c, AstNode *expr) { +bool check_is_expr_vector_index(Checker *c, AstNode *expr) { // HACK(bill): Handle this correctly. Maybe with a custom AddressingMode expr = unparen_expr(expr); if (expr->kind == AstNode_IndexExpr) { @@ -1444,7 +1444,7 @@ b32 check_is_expr_vector_index(Checker *c, AstNode *expr) { return false; } -b32 check_is_vector_elem(Checker *c, AstNode *expr) { +bool check_is_vector_elem(Checker *c, AstNode *expr) { // HACK(bill): Handle this correctly. Maybe with a custom AddressingMode expr = unparen_expr(expr); if (expr->kind == AstNode_SelectorExpr) { @@ -1479,7 +1479,7 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) { case Token_Maybe: { // Make maybe Type *t = default_type(o->type); - b32 is_value = + bool is_value = o->mode == Addressing_Variable || o->mode == Addressing_Value || o->mode == Addressing_Constant; @@ -1548,7 +1548,7 @@ void check_comparison(Checker *c, Operand *x, Operand *y, Token op) { if (check_is_assignable_to(c, x, y->type) || check_is_assignable_to(c, y, x->type)) { Type *err_type = x->type; - b32 defined = false; + bool defined = false; switch (op.kind) { case Token_CmpEq: case Token_NotEq: @@ -1620,7 +1620,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) { x_val = exact_value_to_integer(x->value); } - b32 x_is_untyped = is_type_untyped(x->type); + bool x_is_untyped = is_type_untyped(x->type); if (!(is_type_integer(x->type) || (x_is_untyped && x_val.kind == ExactValue_Integer))) { gbString err_str = expr_to_string(x->expr); defer (gb_string_free(err_str)); @@ -1704,7 +1704,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) { x->mode = Addressing_Value; } -b32 check_is_castable_to(Checker *c, Operand *operand, Type *y) { +bool check_is_castable_to(Checker *c, Operand *operand, Type *y) { PROF_PROC(); if (check_is_assignable_to(c, operand, y)) { @@ -1856,8 +1856,8 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { return; } - b32 is_const_expr = x->mode == Addressing_Constant; - b32 can_convert = false; + bool is_const_expr = x->mode == Addressing_Constant; + bool can_convert = false; Type *bt = base_type(type); if (is_const_expr && is_type_constant_type(bt)) { @@ -2021,8 +2021,8 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { return; } - b32 src_is_ptr = is_type_pointer(x->type); - b32 dst_is_ptr = is_type_pointer(type); + bool src_is_ptr = is_type_pointer(x->type); + bool dst_is_ptr = is_type_pointer(type); Type *src = type_deref(x->type); Type *dst = type_deref(type); Type *bsrc = base_type(src); @@ -2044,7 +2044,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { return; } - b32 ok = false; + bool ok = false; for (isize i = 1; i < bsrc->Record.field_count; i++) { Entity *f = bsrc->Record.fields[i]; if (are_types_identical(f->type, dst)) { @@ -2156,7 +2156,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { case Token_ModEq: if ((x->mode == Addressing_Constant || is_type_integer(x->type)) && y->mode == Addressing_Constant) { - b32 fail = false; + bool fail = false; switch (y->value.kind) { case ExactValue_Integer: if (y->value.value_integer == 0) { @@ -2218,7 +2218,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { } -void update_expr_type(Checker *c, AstNode *e, Type *type, b32 final) { +void update_expr_type(Checker *c, AstNode *e, Type *type, bool final) { PROF_PROC(); HashKey key = hash_pointer(e); @@ -2378,7 +2378,7 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level operand->type = target_type; } -b32 check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *value) { +bool check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *value) { PROF_PROC(); Operand operand = {Addressing_Invalid}; @@ -2439,7 +2439,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node) { ast_node(se, SelectorExpr, node); - b32 check_op_expr = true; + bool check_op_expr = true; Entity *expr_entity = NULL; Entity *entity = NULL; Selection sel = {}; // NOTE(bill): Not used if it's an import name @@ -2470,7 +2470,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node) { check_entity_decl(c, entity, NULL, NULL); } GB_ASSERT(entity->type != NULL); - b32 is_not_exported = !is_entity_exported(entity); + bool is_not_exported = !is_entity_exported(entity); // TODO(bill): Fix this for `#import "file.odin" as .` if (is_not_exported) { @@ -2569,7 +2569,7 @@ error: return NULL; } -b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id) { +bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id) { PROF_PROC(); GB_ASSERT(call->kind == AstNode_CallExpr); @@ -3413,8 +3413,8 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode ast_node(ce, CallExpr, call); isize param_count = 0; - b32 variadic = proc_type->Proc.variadic; - b32 vari_expand = (ce->ellipsis.pos.line != 0); + bool variadic = proc_type->Proc.variadic; + bool vari_expand = (ce->ellipsis.pos.line != 0); if (proc_type->Proc.params != NULL) { param_count = proc_type->Proc.params->Tuple.variable_count; @@ -3492,7 +3492,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode } if (variadic) { - b32 variadic_expand = false; + bool variadic_expand = false; Type *slice = sig_params[param_count]->type; GB_ASSERT(is_type_slice(slice)); Type *elem = base_type(slice)->Slice.elem; @@ -3672,8 +3672,8 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint PROF_SCOPED("check__expr_base - CompoundLit"); Type *type = type_hint; - b32 ellipsis_array = false; - b32 is_constant = true; + bool ellipsis_array = false; + bool is_constant = true; if (cl->type != NULL) { type = NULL; @@ -3710,7 +3710,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint { // Checker values isize field_count = t->Record.field_count; if (cl->elems[0]->kind == AstNode_FieldValue) { - b32 *fields_visited = gb_alloc_array(c->allocator, b32, field_count); + bool *fields_visited = gb_alloc_array(c->allocator, bool, field_count); for_array(i, cl->elems) { AstNode *elem = cl->elems[i]; @@ -3938,10 +3938,10 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint } Type *t = base_type(type_deref(o->type)); - b32 is_const = o->mode == Addressing_Constant; + bool is_const = o->mode == Addressing_Constant; - auto set_index_data = [](Operand *o, Type *t, i64 *max_count) -> b32 { + auto set_index_data = [](Operand *o, Type *t, i64 *max_count) -> bool { t = base_type(type_deref(t)); switch (t->kind) { @@ -3985,7 +3985,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint }; i64 max_count = -1; - b32 valid = set_index_data(o, t, &max_count); + bool valid = set_index_data(o, t, &max_count); if (is_const) { valid = false; @@ -4017,7 +4017,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint } i64 index = 0; - b32 ok = check_index_value(c, ie->index, max_count, &index); + bool ok = check_index_value(c, ie->index, max_count, &index); case_end; @@ -4031,7 +4031,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint goto error; } - b32 valid = false; + bool valid = false; i64 max_count = -1; Type *t = base_type(type_deref(o->type)); switch (t->kind) { diff --git a/src/checker/stmt.cpp b/src/checker/stmt.cpp index ecfc48cdd..675b35a51 100644 --- a/src/checker/stmt.cpp +++ b/src/checker/stmt.cpp @@ -1,5 +1,5 @@ -b32 check_is_terminating(AstNode *node); -b32 check_has_break (AstNode *stmt, b32 implicit); +bool check_is_terminating(AstNode *node); +bool check_has_break (AstNode *stmt, bool implicit); void check_stmt (Checker *c, AstNode *node, u32 flags); @@ -81,7 +81,7 @@ void check_stmt_list(Checker *c, AstNodeArray stmts, u32 flags) { check_entity_decl(c, delayed_const[i].e, delayed_const[i].d, NULL); } - b32 ft_ok = (flags & Stmt_FallthroughAllowed) != 0; + bool ft_ok = (flags & Stmt_FallthroughAllowed) != 0; u32 f = flags & (~Stmt_FallthroughAllowed); for_array(i, stmts) { @@ -97,7 +97,7 @@ void check_stmt_list(Checker *c, AstNodeArray stmts, u32 flags) { } } -b32 check_is_terminating_list(AstNodeArray stmts) { +bool check_is_terminating_list(AstNodeArray stmts) { // Iterate backwards for (isize n = stmts.count-1; n >= 0; n--) { @@ -110,7 +110,7 @@ b32 check_is_terminating_list(AstNodeArray stmts) { return false; } -b32 check_has_break_list(AstNodeArray stmts, b32 implicit) { +bool check_has_break_list(AstNodeArray stmts, bool implicit) { for_array(i, stmts) { AstNode *stmt = stmts[i]; if (check_has_break(stmt, implicit)) { @@ -121,7 +121,7 @@ b32 check_has_break_list(AstNodeArray stmts, b32 implicit) { } -b32 check_has_break(AstNode *stmt, b32 implicit) { +bool check_has_break(AstNode *stmt, bool implicit) { PROF_PROC(); switch (stmt->kind) { @@ -152,7 +152,7 @@ b32 check_has_break(AstNode *stmt, b32 implicit) { // NOTE(bill): The last expression has to be a `return` statement // TODO(bill): This is a mild hack and should be probably handled properly // TODO(bill): Warn/err against code after `return` that it won't be executed -b32 check_is_terminating(AstNode *node) { +bool check_is_terminating(AstNode *node) { PROF_PROC(); switch (node->kind) { @@ -184,7 +184,7 @@ b32 check_is_terminating(AstNode *node) { case_end; case_ast_node(ms, MatchStmt, node); - b32 has_default = false; + bool has_default = false; for_array(i, ms->body->BlockStmt.stmts) { AstNode *clause = ms->body->BlockStmt.stmts[i]; ast_node(cc, CaseClause, clause); @@ -200,7 +200,7 @@ b32 check_is_terminating(AstNode *node) { case_end; case_ast_node(ms, TypeMatchStmt, node); - b32 has_default = false; + bool has_default = false; for_array(i, ms->body->BlockStmt.stmts) { AstNode *clause = ms->body->BlockStmt.stmts[i]; ast_node(cc, CaseClause, clause); @@ -247,7 +247,7 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) { } Entity *e = NULL; - b32 used = false; + bool used = false; if (node->kind == AstNode_Ident) { ast_node(i, Ident, node); e = scope_lookup_entity(c->context.scope, i->string); @@ -302,7 +302,7 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) { return op_a->type; } -b32 check_valid_type_match_type(Type *type, b32 *is_union_ptr, b32 *is_any) { +bool check_valid_type_match_type(Type *type, bool *is_union_ptr, bool *is_any) { if (is_type_pointer(type)) { *is_union_ptr = is_type_union(type_deref(type)); return *is_union_ptr; @@ -695,7 +695,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { TypeAndToken *taps = gb_alloc_array(c->tmp_allocator, TypeAndToken, count); multi_map_get_all(&seen, key, taps); - b32 continue_outer = false; + bool continue_outer = false; for (isize i = 0; i < count; i++) { TypeAndToken tap = taps[i]; @@ -741,8 +741,8 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { check_open_scope(c, node); defer (check_close_scope(c)); - b32 is_union_ptr = false; - b32 is_any = false; + bool is_union_ptr = false; + bool is_any = false; check_expr(c, &x, ms->tag); check_assignment(c, &x, NULL, make_string("type match expression")); @@ -787,7 +787,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { } - Map<b32> seen = {}; + Map<bool> seen = {}; map_init(&seen, heap_allocator()); defer (map_destroy(&seen)); @@ -812,7 +812,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { if (is_union_ptr) { GB_ASSERT(is_type_union(bt)); - b32 tag_type_found = false; + bool tag_type_found = false; for (isize i = 0; i < bt->Record.field_count; i++) { Entity *f = bt->Record.fields[i]; if (are_types_identical(f->type, y.type)) { @@ -847,7 +847,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { gb_string_free(expr_str); break; } - map_set(&seen, key, cast(b32)true); + map_set(&seen, key, true); } check_open_scope(c, stmt); @@ -875,7 +875,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { if (is_ast_node_decl(ds->stmt)) { error(ds->token, "You cannot defer a declaration"); } else { - b32 out_in_defer = c->in_defer; + bool out_in_defer = c->in_defer; c->in_defer = true; check_stmt(c, ds->stmt, 0); c->in_defer = out_in_defer; @@ -914,7 +914,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { // TODO(bill): Allow for just a LHS expression list rather than this silly code Entity *e = NULL; - b32 is_selector = false; + bool is_selector = false; AstNode *expr = unparen_expr(es->expr); if (expr->kind == AstNode_Ident) { String name = expr->Ident.string; diff --git a/src/checker/types.cpp b/src/checker/types.cpp index 965798be9..c0d582336 100644 --- a/src/checker/types.cpp +++ b/src/checker/types.cpp @@ -136,9 +136,9 @@ struct Type { }; struct { // struct only i64 * struct_offsets; - b32 struct_are_offsets_set; - b32 struct_is_packed; - b32 struct_is_ordered; + bool struct_are_offsets_set; + bool struct_is_packed; + bool struct_is_ordered; Entity **fields_in_src_order; // Entity_Variable }; }; @@ -155,7 +155,7 @@ struct Type { struct { Entity **variables; // Entity_Variable i32 variable_count; - b32 are_offsets_set; + bool are_offsets_set; i64 * offsets; } Tuple; struct { @@ -164,7 +164,7 @@ struct Type { Type * results; // Type_Tuple i32 param_count; i32 result_count; - b32 variadic; + bool variadic; } Proc; }; }; @@ -378,7 +378,7 @@ Type *make_type_tuple(gbAllocator a) { return t; } -Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_count, Type *results, isize result_count, b32 variadic) { +Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_count, Type *results, isize result_count, bool variadic) { Type *t = alloc_type(a, Type_Proc); if (variadic) { @@ -423,34 +423,34 @@ Type *get_enum_base_type(Type *t) { return t; } -b32 is_type_named(Type *t) { +bool is_type_named(Type *t) { if (t->kind == Type_Basic) { return true; } return t->kind == Type_Named; } -b32 is_type_boolean(Type *t) { +bool is_type_boolean(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Boolean) != 0; } return false; } -b32 is_type_integer(Type *t) { +bool is_type_integer(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Integer) != 0; } return false; } -b32 is_type_unsigned(Type *t) { +bool is_type_unsigned(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Unsigned) != 0; } return false; } -b32 is_type_numeric(Type *t) { +bool is_type_numeric(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Numeric) != 0; @@ -460,28 +460,28 @@ b32 is_type_numeric(Type *t) { } return false; } -b32 is_type_string(Type *t) { +bool is_type_string(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_String) != 0; } return false; } -b32 is_type_typed(Type *t) { +bool is_type_typed(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Untyped) == 0; } return true; } -b32 is_type_untyped(Type *t) { +bool is_type_untyped(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Untyped) != 0; } return false; } -b32 is_type_ordered(Type *t) { +bool is_type_ordered(Type *t) { t = base_type(get_enum_base_type(t)); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Ordered) != 0; @@ -491,7 +491,7 @@ b32 is_type_ordered(Type *t) { } return false; } -b32 is_type_constant_type(Type *t) { +bool is_type_constant_type(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_ConstantType) != 0; @@ -501,82 +501,82 @@ b32 is_type_constant_type(Type *t) { } return false; } -b32 is_type_float(Type *t) { +bool is_type_float(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Float) != 0; } return false; } -b32 is_type_f32(Type *t) { +bool is_type_f32(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return t->Basic.kind == Basic_f32; } return false; } -b32 is_type_f64(Type *t) { +bool is_type_f64(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return t->Basic.kind == Basic_f64; } return false; } -b32 is_type_pointer(Type *t) { +bool is_type_pointer(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Pointer) != 0; } return t->kind == Type_Pointer; } -b32 is_type_maybe(Type *t) { +bool is_type_maybe(Type *t) { t = base_type(t); return t->kind == Type_Maybe; } -b32 is_type_tuple(Type *t) { +bool is_type_tuple(Type *t) { t = base_type(t); return t->kind == Type_Tuple; } -b32 is_type_int_or_uint(Type *t) { +bool is_type_int_or_uint(Type *t) { if (t->kind == Type_Basic) { return (t->Basic.kind == Basic_int) || (t->Basic.kind == Basic_uint); } return false; } -b32 is_type_rawptr(Type *t) { +bool is_type_rawptr(Type *t) { if (t->kind == Type_Basic) { return t->Basic.kind == Basic_rawptr; } return false; } -b32 is_type_u8(Type *t) { +bool is_type_u8(Type *t) { if (t->kind == Type_Basic) { return t->Basic.kind == Basic_u8; } return false; } -b32 is_type_array(Type *t) { +bool is_type_array(Type *t) { t = base_type(t); return t->kind == Type_Array; } -b32 is_type_slice(Type *t) { +bool is_type_slice(Type *t) { t = base_type(t); return t->kind == Type_Slice; } -b32 is_type_u8_slice(Type *t) { +bool is_type_u8_slice(Type *t) { t = base_type(t); if (t->kind == Type_Slice) { return is_type_u8(t->Slice.elem); } return false; } -b32 is_type_vector(Type *t) { +bool is_type_vector(Type *t) { t = base_type(t); return t->kind == Type_Vector; } -b32 is_type_proc(Type *t) { +bool is_type_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc; } @@ -589,40 +589,40 @@ Type *base_vector_type(Type *t) { } -b32 is_type_enum(Type *t) { +bool is_type_enum(Type *t) { t = base_type(t); return (t->kind == Type_Record && t->Record.kind == TypeRecord_Enum); } -b32 is_type_struct(Type *t) { +bool is_type_struct(Type *t) { t = base_type(t); return (t->kind == Type_Record && t->Record.kind == TypeRecord_Struct); } -b32 is_type_union(Type *t) { +bool is_type_union(Type *t) { t = base_type(t); return (t->kind == Type_Record && t->Record.kind == TypeRecord_Union); } -b32 is_type_raw_union(Type *t) { +bool is_type_raw_union(Type *t) { t = base_type(t); return (t->kind == Type_Record && t->Record.kind == TypeRecord_RawUnion); } -b32 is_type_any(Type *t) { +bool is_type_any(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_any); } -b32 is_type_untyped_nil(Type *t) { +bool is_type_untyped_nil(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_UntypedNil); } -b32 is_type_indexable(Type *t) { +bool is_type_indexable(Type *t) { return is_type_array(t) || is_type_slice(t) || is_type_vector(t) || is_type_string(t); } -b32 type_has_nil(Type *t) { +bool type_has_nil(Type *t) { t = base_type(t); switch (t->kind) { case Type_Basic: @@ -642,7 +642,7 @@ b32 type_has_nil(Type *t) { } -b32 is_type_comparable(Type *t) { +bool is_type_comparable(Type *t) { t = base_type(get_enum_base_type(t)); switch (t->kind) { case Type_Basic: @@ -671,7 +671,7 @@ b32 is_type_comparable(Type *t) { return false; } -b32 are_types_identical(Type *x, Type *y) { +bool are_types_identical(Type *x, Type *y) { if (x == y) return true; @@ -808,11 +808,11 @@ struct BaseTypeSizes { struct Selection { Entity *entity; Array<isize> index; - b32 indirect; // Set if there was a pointer deref anywhere down the line + bool indirect; // Set if there was a pointer deref anywhere down the line }; Selection empty_selection = {}; -Selection make_selection(Entity *entity, Array<isize> index, b32 indirect) { +Selection make_selection(Entity *entity, Array<isize> index, bool indirect) { Selection s = {entity, index, indirect}; return s; } @@ -833,7 +833,7 @@ 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, b32 is_type, Selection sel = empty_selection) { +Selection lookup_field(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel = empty_selection) { GB_ASSERT(type_ != NULL); if (field_name == "_") { @@ -841,7 +841,7 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, b32 is_typ } Type *type = type_deref(type_); - b32 is_ptr = type != type_; + bool is_ptr = type != type_; sel.indirect = sel.indirect || is_ptr; type = base_type(type); @@ -1129,7 +1129,7 @@ i64 type_align_of(BaseTypeSizes s, gbAllocator allocator, Type *t) { return gb_clamp(next_pow2(type_size_of(s, allocator, t)), 1, s.word_size); } -i64 *type_set_offsets_of(BaseTypeSizes s, gbAllocator allocator, Entity **fields, isize field_count, b32 is_packed) { +i64 *type_set_offsets_of(BaseTypeSizes s, gbAllocator allocator, Entity **fields, isize field_count, bool is_packed) { i64 *offsets = gb_alloc_array(allocator, i64, field_count); i64 curr_offset = 0; if (is_packed) { @@ -1149,7 +1149,7 @@ i64 *type_set_offsets_of(BaseTypeSizes s, gbAllocator allocator, Entity **fields return offsets; } -b32 type_set_offsets(BaseTypeSizes s, gbAllocator allocator, Type *t) { +bool type_set_offsets(BaseTypeSizes s, gbAllocator allocator, Type *t) { t = base_type(t); if (is_type_struct(t)) { if (!t->Record.struct_are_offsets_set) { diff --git a/src/common.cpp b/src/common.cpp index e07ea362a..7969b5943 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -9,7 +9,7 @@ gbAllocator heap_allocator(void) { #include "array.cpp" gb_global String global_module_path = {}; -gb_global b32 global_module_path_set = false; +gb_global bool global_module_path_set = false; String get_module_dir() { @@ -125,7 +125,7 @@ gb_inline HashKey hash_pointer(void *ptr) { return h; } -b32 hash_key_equal(HashKey a, HashKey b) { +bool hash_key_equal(HashKey a, HashKey b) { if (a.key == b.key) { // NOTE(bill): If two string's hashes collide, compare the strings themselves if (a.kind == HashKey_String) { @@ -351,7 +351,7 @@ gb_internal MapFindResult map__find(Map<T> *h, MapEntry<T> *e) { template <typename T> -gb_internal b32 map__full(Map<T> *h) { +gb_internal bool map__full(Map<T> *h) { return 0.75f * h->hashes.count <= h->entries.count; } diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 15d03ba2b..890a0f33e 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -21,7 +21,7 @@ enum ExactValueKind { struct ExactValue { ExactValueKind kind; union { - b32 value_bool; + bool value_bool; String value_string; i64 value_integer; // NOTE(bill): This must be an integer and not a pointer f64 value_float; @@ -41,7 +41,7 @@ ExactValue make_exact_value_compound(AstNode *node) { return result; } -ExactValue make_exact_value_bool(b32 b) { +ExactValue make_exact_value_bool(bool b) { ExactValue result = {ExactValue_Bool}; result.value_bool = (b != 0); return result; @@ -339,7 +339,7 @@ i32 cmp_f64(f64 a, f64 b) { return (a > b) - (a < b); } -b32 compare_exact_values(Token op, ExactValue x, ExactValue y) { +bool compare_exact_values(Token op, ExactValue x, ExactValue y) { match_exact_values(&x, &y); switch (x.kind) { diff --git a/src/main.cpp b/src/main.cpp index 6fea6d583..0d1a64326 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -123,7 +123,7 @@ int main(int argc, char **argv) { init_universal_scope(); char *init_filename = NULL; - b32 run_output = false; + bool run_output = false; String arg1 = make_string(argv[1]); if (arg1 == "run") { run_output = true; @@ -243,7 +243,7 @@ int main(int argc, char **argv) { exit_code = win32_exec_command_line_app("msvc-link", "link %.*s.obj -OUT:%.*s.exe %s " "/defaultlib:libcmt " - "/nologo /incremental:no /opt:ref /subsystem:console /debug " + "/nologo /incremental:no /opt:ref /subsystem:console " " %.*s " "", LIT(output), LIT(output), diff --git a/src/parser.cpp b/src/parser.cpp index d263fa1dd..76b2333d4 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -32,7 +32,7 @@ struct AstFile { isize expr_level; AstNodeArray decls; - b32 is_global_scope; + bool is_global_scope; AstNode * curr_proc; isize scope_level; @@ -140,7 +140,7 @@ AST_NODE_KIND(_ExprBegin, "", struct{}) \ AstNode *expr; \ Token open, close; \ AstNode *low, *high, *max; \ - b32 triple_indexed; \ + bool triple_indexed; \ }) \ AST_NODE_KIND(FieldValue, "field value", struct { Token eq; AstNode *field, *value; }) \ AST_NODE_KIND(_ExprEnd, "", struct{}) \ @@ -202,7 +202,7 @@ AST_NODE_KIND(_ComplexStmtBegin, "", struct{}) \ }) \ AST_NODE_KIND(AsmStmt, "assembly statement", struct { \ Token token; \ - b32 is_volatile; \ + bool is_volatile; \ Token open, close; \ Token code_string; \ AstNode *output_list; \ @@ -227,7 +227,7 @@ AST_NODE_KIND(_DeclBegin, "", struct{}) \ AST_NODE_KIND(BadDecl, "bad declaration", struct { Token begin, end; }) \ AST_NODE_KIND(VarDecl, "variable declaration", struct { \ u64 tags; \ - b32 is_using; \ + bool is_using; \ AstNodeArray names; \ AstNode * type; \ AstNodeArray values; \ @@ -258,19 +258,19 @@ AST_NODE_KIND(_DeclBegin, "", struct{}) \ Token token, relpath; \ String fullpath; \ Token import_name; \ - b32 is_load; \ + bool is_load; \ AstNode *note; \ }) \ AST_NODE_KIND(ForeignLibrary, "foreign library", struct { \ Token token, filepath; \ - b32 is_system; \ + bool is_system; \ }) \ AST_NODE_KIND(_DeclEnd, "", struct{}) \ AST_NODE_KIND(_TypeBegin, "", struct{}) \ AST_NODE_KIND(Parameter, "parameter", struct { \ AstNodeArray names; \ AstNode *type; \ - b32 is_using; \ + bool is_using; \ }) \ AST_NODE_KIND(ProcType, "procedure type", struct { \ Token token; \ @@ -299,8 +299,8 @@ AST_NODE_KIND(_TypeBegin, "", struct{}) \ Token token; \ AstNodeArray decls; \ isize decl_count; \ - b32 is_packed; \ - b32 is_ordered; \ + bool is_packed; \ + bool is_ordered; \ }) \ AST_NODE_KIND(UnionType, "union type", struct { \ Token token; \ @@ -355,19 +355,19 @@ struct AstNode { -gb_inline b32 is_ast_node_expr(AstNode *node) { +gb_inline bool is_ast_node_expr(AstNode *node) { return gb_is_between(node->kind, AstNode__ExprBegin+1, AstNode__ExprEnd-1); } -gb_inline b32 is_ast_node_stmt(AstNode *node) { +gb_inline bool is_ast_node_stmt(AstNode *node) { return gb_is_between(node->kind, AstNode__StmtBegin+1, AstNode__StmtEnd-1); } -gb_inline b32 is_ast_node_complex_stmt(AstNode *node) { +gb_inline bool is_ast_node_complex_stmt(AstNode *node) { return gb_is_between(node->kind, AstNode__ComplexStmtBegin+1, AstNode__ComplexStmtEnd-1); } -gb_inline b32 is_ast_node_decl(AstNode *node) { +gb_inline bool is_ast_node_decl(AstNode *node) { return gb_is_between(node->kind, AstNode__DeclBegin+1, AstNode__DeclEnd-1); } -gb_inline b32 is_ast_node_type(AstNode *node) { +gb_inline bool is_ast_node_type(AstNode *node) { return gb_is_between(node->kind, AstNode__TypeBegin+1, AstNode__TypeEnd-1); } @@ -598,7 +598,7 @@ AstNode *make_index_expr(AstFile *f, AstNode *expr, AstNode *index, Token open, } -AstNode *make_slice_expr(AstFile *f, AstNode *expr, Token open, Token close, AstNode *low, AstNode *high, AstNode *max, b32 triple_indexed) { +AstNode *make_slice_expr(AstFile *f, AstNode *expr, Token open, Token close, AstNode *low, AstNode *high, AstNode *max, bool triple_indexed) { AstNode *result = make_node(f, AstNode_SliceExpr); result->SliceExpr.expr = expr; result->SliceExpr.open = open; @@ -796,7 +796,7 @@ AstNode *make_asm_operand(AstFile *f, Token string, AstNode *operand) { } -AstNode *make_asm_stmt(AstFile *f, Token token, b32 is_volatile, Token open, Token close, Token code_string, +AstNode *make_asm_stmt(AstFile *f, Token token, bool is_volatile, Token open, Token close, Token code_string, AstNode *output_list, AstNode *input_list, AstNode *clobber_list, isize output_count, isize input_count, isize clobber_count) { AstNode *result = make_node(f, AstNode_AsmStmt); @@ -856,7 +856,7 @@ AstNode *make_const_decl(AstFile *f, AstNodeArray names, AstNode *type, AstNodeA return result; } -AstNode *make_parameter(AstFile *f, AstNodeArray names, AstNode *type, b32 is_using) { +AstNode *make_parameter(AstFile *f, AstNodeArray names, AstNode *type, bool is_using) { AstNode *result = make_node(f, AstNode_Parameter); result->Parameter.names = names; result->Parameter.type = type; @@ -913,7 +913,7 @@ AstNode *make_vector_type(AstFile *f, Token token, AstNode *count, AstNode *elem return result; } -AstNode *make_struct_type(AstFile *f, Token token, AstNodeArray decls, isize decl_count, b32 is_packed, b32 is_ordered) { +AstNode *make_struct_type(AstFile *f, Token token, AstNodeArray decls, isize decl_count, bool is_packed, bool is_ordered) { AstNode *result = make_node(f, AstNode_StructType); result->StructType.token = token; result->StructType.decls = decls; @@ -957,7 +957,7 @@ AstNode *make_type_decl(AstFile *f, Token token, AstNode *name, AstNode *type) { return result; } -AstNode *make_import_decl(AstFile *f, Token token, Token relpath, Token import_name, b32 is_load) { +AstNode *make_import_decl(AstFile *f, Token token, Token relpath, Token import_name, bool is_load) { AstNode *result = make_node(f, AstNode_ImportDecl); result->ImportDecl.token = token; result->ImportDecl.relpath = relpath; @@ -966,7 +966,7 @@ AstNode *make_import_decl(AstFile *f, Token token, Token relpath, Token import_n return result; } -AstNode *make_foreign_library(AstFile *f, Token token, Token filepath, b32 is_system) { +AstNode *make_foreign_library(AstFile *f, Token token, Token filepath, bool is_system) { AstNode *result = make_node(f, AstNode_ForeignLibrary); result->ForeignLibrary.token = token; result->ForeignLibrary.filepath = filepath; @@ -974,7 +974,7 @@ AstNode *make_foreign_library(AstFile *f, Token token, Token filepath, b32 is_sy return result; } -b32 next_token(AstFile *f) { +bool next_token(AstFile *f) { if (f->curr_token_index+1 < f->tokens.count) { if (f->curr_token.kind != Token_Comment) { f->prev_token = f->curr_token; @@ -1035,7 +1035,7 @@ Token expect_keyword(AstFile *f) { return prev; } -b32 allow_token(AstFile *f, TokenKind kind) { +bool allow_token(AstFile *f, TokenKind kind) { Token prev = f->curr_token; if (prev.kind == kind) { next_token(f); @@ -1045,7 +1045,7 @@ b32 allow_token(AstFile *f, TokenKind kind) { } -b32 is_blank_ident(String str) { +bool is_blank_ident(String str) { if (str.len == 1) { return str.text[0] == '_'; } @@ -1099,7 +1099,7 @@ void fix_advance_to_next_stmt(AstFile *f) { #endif } -b32 expect_semicolon_after_stmt(AstFile *f, AstNode *s) { +bool expect_semicolon_after_stmt(AstFile *f, AstNode *s) { if (allow_token(f, Token_Semicolon)) { return true; } @@ -1122,7 +1122,7 @@ b32 expect_semicolon_after_stmt(AstFile *f, AstNode *s) { } -AstNode * parse_expr(AstFile *f, b32 lhs); +AstNode * parse_expr(AstFile *f, bool lhs); AstNode * parse_proc_type(AstFile *f); AstNodeArray parse_stmt_list(AstFile *f); AstNode * parse_stmt(AstFile *f); @@ -1215,7 +1215,7 @@ void check_proc_add_tag(AstFile *f, AstNode *tag_expr, u64 *tags, ProcTag tag, S *tags |= tag; } -b32 is_foreign_name_valid(String name) { +bool is_foreign_name_valid(String name) { // TODO(bill): is_foreign_name_valid if (name.len == 0) return false; @@ -1340,7 +1340,7 @@ void parse_proc_tags(AstFile *f, u64 *tags, String *foreign_name, String *link_n } } -AstNode *parse_operand(AstFile *f, b32 lhs) { +AstNode *parse_operand(AstFile *f, bool lhs) { AstNode *operand = NULL; // Operand switch (f->curr_token.kind) { case Token_Identifier: @@ -1457,7 +1457,7 @@ AstNode *parse_operand(AstFile *f, b32 lhs) { return make_bad_expr(f, begin, f->curr_token); } -b32 is_literal_type(AstNode *node) { +bool is_literal_type(AstNode *node) { switch (node->kind) { case AstNode_BadExpr: case AstNode_Ident: @@ -1506,10 +1506,10 @@ AstNode *parse_call_expr(AstFile *f, AstNode *operand) { return make_call_expr(f, operand, args, open_paren, close_paren, ellipsis); } -AstNode *parse_atom_expr(AstFile *f, b32 lhs) { +AstNode *parse_atom_expr(AstFile *f, bool lhs) { AstNode *operand = parse_operand(f, lhs); - b32 loop = true; + bool loop = true; while (loop) { switch (f->curr_token.kind) { @@ -1581,7 +1581,7 @@ AstNode *parse_atom_expr(AstFile *f, b32 lhs) { if (colon_count == 0) { operand = make_index_expr(f, operand, indices[0], open, close); } else { - b32 triple_indexed = false; + bool triple_indexed = false; if (colon_count == 2) { triple_indexed = true; if (indices[1] == NULL) { @@ -1633,7 +1633,7 @@ AstNode *parse_atom_expr(AstFile *f, b32 lhs) { AstNode *parse_type(AstFile *f); -AstNode *parse_unary_expr(AstFile *f, b32 lhs) { +AstNode *parse_unary_expr(AstFile *f, bool lhs) { switch (f->curr_token.kind) { case Token_Pointer: case Token_Maybe: @@ -1691,7 +1691,7 @@ i32 token_precedence(Token t) { return 0; } -AstNode *parse_binary_expr(AstFile *f, b32 lhs, i32 prec_in) { +AstNode *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { AstNode *expression = parse_unary_expr(f, lhs); for (i32 prec = token_precedence(f->curr_token); prec >= prec_in; prec--) { for (;;) { @@ -1749,12 +1749,12 @@ AstNode *parse_binary_expr(AstFile *f, b32 lhs, i32 prec_in) { return expression; } -AstNode *parse_expr(AstFile *f, b32 lhs) { +AstNode *parse_expr(AstFile *f, bool lhs) { return parse_binary_expr(f, lhs, 0+1); } -AstNodeArray parse_expr_list(AstFile *f, b32 lhs) { +AstNodeArray parse_expr_list(AstFile *f, bool lhs) { AstNodeArray list = make_ast_node_array(f); do { AstNode *e = parse_expr(f, lhs); @@ -1917,7 +1917,7 @@ AstNodeArray parse_parameter_list(AstFile *f) { while (f->curr_token.kind == Token_Identifier || f->curr_token.kind == Token_using) { - b32 is_using = false; + bool is_using = false; if (allow_token(f, Token_using)) { is_using = true; } @@ -1969,13 +1969,13 @@ AstNodeArray parse_parameter_list(AstFile *f) { } -AstNodeArray parse_struct_params(AstFile *f, isize *decl_count_, b32 using_allowed) { +AstNodeArray parse_struct_params(AstFile *f, isize *decl_count_, bool using_allowed) { AstNodeArray decls = make_ast_node_array(f); isize decl_count = 0; while (f->curr_token.kind == Token_Identifier || f->curr_token.kind == Token_using) { - b32 is_using = false; + bool is_using = false; if (allow_token(f, Token_using)) { is_using = true; } @@ -2083,8 +2083,8 @@ AstNode *parse_identifier_or_type(AstFile *f, u32 flags) { case Token_struct: { Token token = expect_token(f, Token_struct); - b32 is_packed = false; - b32 is_ordered = false; + bool is_packed = false; + bool is_ordered = false; while (allow_token(f, Token_Hash)) { Token tag = expect_token_after(f, Token_Identifier, "`#`"); if (tag.string == "packed") { @@ -2300,7 +2300,7 @@ AstNode *parse_decl(AstFile *f, AstNodeArray names) { syntax_error(f->curr_token, "Expected type separator `:` or `=`"); } - b32 is_mutable = true; + bool is_mutable = true; if (f->curr_token.kind == Token_Eq || f->curr_token.kind == Token_Colon) { @@ -2622,7 +2622,7 @@ AstNode *parse_defer_stmt(AstFile *f) { AstNode *parse_asm_stmt(AstFile *f) { Token token = expect_token(f, Token_asm); - b32 is_volatile = false; + bool is_volatile = false; if (allow_token(f, Token_volatile)) { is_volatile = true; } @@ -2696,7 +2696,7 @@ AstNode *parse_stmt(AstFile *f) { next_token(f); node = parse_stmt(f); - b32 valid = false; + bool valid = false; switch (node->kind) { case AstNode_ExprStmt: { @@ -2924,7 +2924,7 @@ void destroy_ast_file(AstFile *f) { destroy_tokenizer(&f->tokenizer); } -b32 init_parser(Parser *p) { +bool init_parser(Parser *p) { array_init(&p->files, heap_allocator()); array_init(&p->imports, heap_allocator()); array_init(&p->foreign_libraries, heap_allocator()); @@ -2949,7 +2949,7 @@ void destroy_parser(Parser *p) { } // NOTE(bill): Returns true if it's added -b32 try_add_import_path(Parser *p, String path, String rel_path, TokenPos pos) { +bool try_add_import_path(Parser *p, String path, String rel_path, TokenPos pos) { gb_mutex_lock(&p->mutex); defer (gb_mutex_unlock(&p->mutex)); @@ -3000,7 +3000,7 @@ String get_fullpath_core(gbAllocator a, String path) { } // NOTE(bill): Returns true if it's added -b32 try_add_foreign_library_path(Parser *p, String import_file) { +bool try_add_foreign_library_path(Parser *p, String import_file) { gb_mutex_lock(&p->mutex); defer (gb_mutex_unlock(&p->mutex)); @@ -3023,7 +3023,7 @@ gb_global Rune illegal_import_runes[] = { '|', ',', '<', '>', '?', }; -b32 is_import_path_valid(String path) { +bool is_import_path_valid(String path) { if (path.len > 0) { u8 *start = path.text; u8 *end = path.text + path.len; @@ -3055,7 +3055,7 @@ b32 is_import_path_valid(String path) { String get_filepath_extension(String path) { isize dot = 0; - b32 seen_slash = false; + bool seen_slash = false; for (isize i = path.len-1; i >= 0; i--) { u8 c = path.text[i]; if (c == '/' || c == '\\') { diff --git a/src/ssa.cpp b/src/ssa.cpp index 0563f0022..2f35932c7 100644 --- a/src/ssa.cpp +++ b/src/ssa.cpp @@ -10,7 +10,7 @@ struct ssaModule { gbArena tmp_arena; gbAllocator allocator; gbAllocator tmp_allocator; - b32 generate_debug_info; + bool generate_debug_info; u32 stmt_state_flags; @@ -197,7 +197,7 @@ struct ssaInstr { struct { Entity * entity; Type * type; - b32 zero_initialized; + bool zero_initialized; Array<ssaValue *> referrers; } Local; struct { @@ -312,7 +312,7 @@ struct ssaInstr { ssaValue *low; ssaValue *high; ssaValue *max; - b32 is_substring; + bool is_substring; } SliceBoundsCheck; }; }; @@ -360,10 +360,10 @@ struct ssaValue { Type * type; ssaValue * value; Array<ssaValue *> referrers; - b8 is_constant; - b8 is_private; - b8 is_thread_local; - b8 is_unnamed_addr; + bool is_constant; + bool is_private; + bool is_thread_local; + bool is_unnamed_addr; } Global; struct { ssaProcedure * parent; @@ -538,7 +538,7 @@ struct ssaDebugInfo { struct ssaGen { ssaModule module; gbFile output_file; - b32 opt_called; + bool opt_called; }; ssaValue *ssa_lookup_member(ssaModule *m, String name) { @@ -636,7 +636,7 @@ Type *ssa_addr_type(ssaAddr lval) { -b32 ssa_is_blank_ident(AstNode *node) { +bool ssa_is_blank_ident(AstNode *node) { if (node->kind == AstNode_Ident) { ast_node(i, Ident, node); return is_blank_ident(i->string); @@ -658,7 +658,7 @@ ssaInstr *ssa_get_last_instr(ssaBlock *block) { } -b32 ssa_is_instr_terminating(ssaInstr *i) { +bool ssa_is_instr_terminating(ssaInstr *i) { if (i != NULL) { switch (i->kind) { case ssaInstr_Return: @@ -784,7 +784,7 @@ ssaValue *ssa_make_value_nil(gbAllocator a, Type *type) { -ssaValue *ssa_make_instr_local(ssaProcedure *p, Entity *e, b32 zero_initialized) { +ssaValue *ssa_make_instr_local(ssaProcedure *p, Entity *e, bool zero_initialized) { ssaValue *v = ssa_alloc_instr(p, ssaInstr_Local); ssaInstr *i = &v->Instr; i->Local.entity = e; @@ -1012,7 +1012,7 @@ ssaValue *ssa_make_instr_bounds_check(ssaProcedure *p, TokenPos pos, ssaValue *i v->Instr.BoundsCheck.len = len; return v; } -ssaValue *ssa_make_instr_slice_bounds_check(ssaProcedure *p, TokenPos pos, ssaValue *low, ssaValue *high, ssaValue *max, b32 is_substring) { +ssaValue *ssa_make_instr_slice_bounds_check(ssaProcedure *p, TokenPos pos, ssaValue *low, ssaValue *high, ssaValue *max, bool is_substring) { ssaValue *v = ssa_alloc_instr(p, ssaInstr_SliceBoundsCheck); v->Instr.SliceBoundsCheck.pos = pos; v->Instr.SliceBoundsCheck.low = low; @@ -1049,7 +1049,7 @@ ssaValue *ssa_make_const_i32(gbAllocator a, i64 i) { ssaValue *ssa_make_const_i64(gbAllocator a, i64 i) { return ssa_make_value_constant(a, t_i64, make_exact_value_integer(i)); } -ssaValue *ssa_make_const_bool(gbAllocator a, b32 b) { +ssaValue *ssa_make_const_bool(gbAllocator a, bool b) { return ssa_make_value_constant(a, t_bool, make_exact_value_bool(b != 0)); } ssaValue *ssa_make_const_string(gbAllocator a, String s) { @@ -1194,7 +1194,7 @@ ssaValue *ssa_add_global_string_array(ssaModule *m, String string) { -ssaValue *ssa_add_local(ssaProcedure *proc, Entity *e, b32 zero_initialized = true) { +ssaValue *ssa_add_local(ssaProcedure *proc, Entity *e, bool zero_initialized = true) { ssaBlock *b = proc->decl_block; // all variables must be in the first block ssaValue *instr = ssa_make_instr_local(proc, e, zero_initialized); instr->Instr.parent = b; @@ -1209,7 +1209,7 @@ ssaValue *ssa_add_local(ssaProcedure *proc, Entity *e, b32 zero_initialized = tr return instr; } -ssaValue *ssa_add_local_for_identifier(ssaProcedure *proc, AstNode *name, b32 zero_initialized) { +ssaValue *ssa_add_local_for_identifier(ssaProcedure *proc, AstNode *name, bool zero_initialized) { Entity **found = map_get(&proc->module->info->definitions, hash_pointer(name)); if (found) { Entity *e = *found; @@ -1873,8 +1873,8 @@ String lookup_polymorphic_field(CheckerInfo *info, Type *dst, Type *src) { // Type *prev_dst = dst; src = base_type(type_deref(src)); // dst = base_type(type_deref(dst)); - b32 src_is_ptr = src != prev_src; - // b32 dst_is_ptr = dst != prev_dst; + bool src_is_ptr = src != prev_src; + // bool dst_is_ptr = dst != prev_dst; GB_ASSERT(is_type_struct(src)); for (isize i = 0; i < src->Record.field_count; i++) { @@ -2039,7 +2039,7 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t) { // subtype polymorphism casting { Type *sb = base_type(type_deref(src)); - b32 src_is_ptr = src != sb; + bool src_is_ptr = src != sb; if (is_type_struct(sb)) { String field_name = lookup_polymorphic_field(proc->module->info, t, src); // gb_printf("field_name: %.*s\n", LIT(field_name)); @@ -2162,7 +2162,7 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t) { return NULL; } -b32 ssa_is_type_aggregate(Type *t) { +bool ssa_is_type_aggregate(Type *t) { t = base_type(get_enum_base_type(t)); switch (t->kind) { case Type_Basic: @@ -2230,7 +2230,6 @@ ssaValue *ssa_emit_down_cast(ssaProcedure *proc, ssaValue *value, Type *t) { String field_name = check_down_cast_name(t, type_deref(ssa_type(value))); GB_ASSERT(field_name.len > 0); Selection sel = lookup_field(proc->module->allocator, t, field_name, false); - Type *t_u8_ptr = make_type_pointer(allocator, t_u8); ssaValue *bytes = ssa_emit_conv(proc, value, t_u8_ptr); i64 offset_ = type_offset_of_from_selection(proc->module->sizes, allocator, type_deref(t), sel); @@ -2244,7 +2243,7 @@ ssaValue *ssa_emit_union_cast(ssaProcedure *proc, ssaValue *value, Type *tuple) gbAllocator a = proc->module->allocator; Type *src_type = ssa_type(value); - b32 is_ptr = is_type_pointer(src_type); + bool is_ptr = is_type_pointer(src_type); ssaValue *v = ssa_add_local_generated(proc, tuple); @@ -2455,7 +2454,7 @@ void ssa_emit_bounds_check(ssaProcedure *proc, Token token, ssaValue *index, ssa // ssa_emit_global_call(proc, "__bounds_check_error", args, 5); } -void ssa_emit_slice_bounds_check(ssaProcedure *proc, Token token, ssaValue *low, ssaValue *high, ssaValue *max, b32 is_substring) { +void ssa_emit_slice_bounds_check(ssaProcedure *proc, Token token, ssaValue *low, ssaValue *high, ssaValue *max, bool is_substring) { if ((proc->module->stmt_state_flags & StmtStateFlag_no_bounds_check) != 0) { return; } @@ -3134,8 +3133,8 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue } } ssaValue **args = gb_alloc_array(proc->module->allocator, ssaValue *, arg_count); - b32 variadic = proc_type_->Proc.variadic; - b32 vari_expand = ce->ellipsis.pos.line != 0; + bool variadic = proc_type_->Proc.variadic; + bool vari_expand = ce->ellipsis.pos.line != 0; for_array(i, ce->args) { ssaValue *a = ssa_build_expr(proc, ce->args[i]); @@ -3362,7 +3361,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) { gbAllocator a = proc->module->allocator; - b32 deref = is_type_pointer(t); + bool deref = is_type_pointer(t); t = type_deref(t); ssaValue *using_addr = NULL; @@ -3596,7 +3595,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) { case Type_Slice: et = bt->Slice.elem; break; } - auto is_elem_const = [](ssaModule *m, AstNode *elem, Type *elem_type) -> b32 { + auto is_elem_const = [](ssaModule *m, AstNode *elem, Type *elem_type) -> bool { if (base_type(elem_type) == t_any) { return false; } @@ -3700,7 +3699,6 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) { Type *elem_type = bt->Slice.elem; Type *elem_ptr_type = make_type_pointer(proc->module->allocator, elem_type); Type *elem_ptr_ptr_type = make_type_pointer(proc->module->allocator, elem_ptr_type); - Type *t_int_ptr = make_type_pointer(proc->module->allocator, t_int); ssaValue *slice = ssa_add_module_constant(proc->module, type, make_exact_value_compound(expr)); GB_ASSERT(slice->kind == ssaValue_ConstantSlice); @@ -4244,7 +4242,7 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) { ssaBlock *default_block = NULL; ssaBlock *fall = NULL; - b32 append_fall = false; + bool append_fall = false; isize case_count = body->stmts.count; for_array(i, body->stmts) { @@ -4320,8 +4318,8 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) { gbAllocator allocator = proc->module->allocator; ssaValue *parent = ssa_build_expr(proc, ms->tag); - b32 is_union_ptr = false; - b32 is_any = false; + bool is_union_ptr = false; + bool is_any = false; GB_ASSERT(check_valid_type_match_type(ssa_type(parent), &is_union_ptr, &is_any)); ssaValue *tag_index = NULL; @@ -4742,7 +4740,7 @@ void ssa_destroy_module(ssaModule *m) { //////////////////////////////////////////////////////////////// -b32 ssa_gen_init(ssaGen *s, Checker *c) { +bool ssa_gen_init(ssaGen *s, Checker *c) { if (global_error_collector.count != 0) { return false; } @@ -5084,7 +5082,7 @@ void ssa_gen_tree(ssaGen *s) { case Basic_int: case Basic_uint: { tag = ssa_add_local_generated(proc, t_type_info_integer); - b32 is_unsigned = (t->Basic.flags & BasicFlag_Unsigned) != 0; + bool is_unsigned = (t->Basic.flags & BasicFlag_Unsigned) != 0; ssaValue *bits = ssa_make_const_int(a, type_size_of(m->sizes, a, t)); ssaValue *is_signed = ssa_make_const_bool(a, !is_unsigned); ssa_emit_store(proc, ssa_emit_struct_ep(proc, tag, 0), bits); diff --git a/src/ssa_opt.cpp b/src/ssa_opt.cpp index 0fb4bd873..7f1d39f17 100644 --- a/src/ssa_opt.cpp +++ b/src/ssa_opt.cpp @@ -115,7 +115,7 @@ void ssa_opt_block_replace_succ(ssaBlock *b, ssaBlock *from, ssaBlock *to) { } } -b32 ssa_opt_block_has_phi(ssaBlock *b) { +bool ssa_opt_block_has_phi(ssaBlock *b) { return b->instrs[0]->Instr.kind == ssaInstr_Phi; } @@ -215,7 +215,7 @@ void ssa_remove_unreachable_blocks(ssaProcedure *proc) { ssa_remove_dead_blocks(proc); } -b32 ssa_opt_block_fusion(ssaProcedure *proc, ssaBlock *a) { +bool ssa_opt_block_fusion(ssaProcedure *proc, ssaBlock *a) { if (a->succs.count != 1) { return false; } @@ -252,7 +252,7 @@ void ssa_opt_blocks(ssaProcedure *proc) { ssa_remove_unreachable_blocks(proc); #if 1 - b32 changed = true; + bool changed = true; while (changed) { changed = false; for_array(i, proc->blocks) { diff --git a/src/ssa_print.cpp b/src/ssa_print.cpp index 2f074008d..dd96b679a 100644 --- a/src/ssa_print.cpp +++ b/src/ssa_print.cpp @@ -51,7 +51,7 @@ void ssa_file_write(ssaFileBuffer *f, void *data, isize len) { } -b32 ssa_valid_char(u8 c) { +bool ssa_valid_char(u8 c) { if (c >= 0x80) { return false; } @@ -71,7 +71,7 @@ b32 ssa_valid_char(u8 c) { return false; } -void ssa_print_escape_string(ssaFileBuffer *f, String name, b32 print_quotes) { +void ssa_print_escape_string(ssaFileBuffer *f, String name, bool print_quotes) { isize extra = 0; for (isize i = 0; i < name.len; i++) { u8 c = name.text[i]; @@ -126,7 +126,7 @@ void ssa_print_encoded_local(ssaFileBuffer *f, String name) { ssa_print_escape_string(f, name, true); } -void ssa_print_encoded_global(ssaFileBuffer *f, String name, b32 global_scope) { +void ssa_print_encoded_global(ssaFileBuffer *f, String name, bool global_scope) { ssa_fprintf(f, "@"); if (!global_scope && name != make_string("main")) { ssa_fprintf(f, "."); @@ -611,7 +611,7 @@ void ssa_print_value(ssaFileBuffer *f, ssaModule *m, ssaValue *value, Type *type break; case ssaValue_Global: { Scope *scope = value->Global.entity->scope; - b32 in_global_scope = false; + bool in_global_scope = false; if (scope != NULL) { in_global_scope = scope->is_global || scope->is_init; } @@ -1337,7 +1337,7 @@ void ssa_print_llvm_ir(ssaGen *ssa) { } auto *g = &v->Global; Scope *scope = g->entity->scope; - b32 in_global_scope = false; + bool in_global_scope = false; if (scope != NULL) { in_global_scope = scope->is_global || scope->is_init; } diff --git a/src/string.cpp b/src/string.cpp index d62a0e900..26b0f5c84 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -51,14 +51,14 @@ gb_inline String make_string(char const (&text)[N]) { return make_string(cast(u8 *)cast(void *)text, N-1); } -gb_inline b32 are_strings_equal(String a, String b) { +gb_inline bool are_strings_equal(String a, String b) { if (a.len == b.len) { return gb_memcompare(a.text, b.text, a.len) == 0; } return false; } -gb_inline b32 are_strings_equal_ignore_case(String a, String b) { +gb_inline bool are_strings_equal_ignore_case(String a, String b) { if (a.len == b.len) { for (isize i = 0; i < a.len; i++) { char x = cast(char)a.text[i]; @@ -133,7 +133,7 @@ template <size_t N> gb_inline bool operator !=(char const (&a)[N], String b) { r gb_inline isize string_extension_position(String str) { isize dot_pos = -1; isize i = str.len; - b32 seen_dot = false; + bool seen_dot = false; while (i --> 0) { if (str.text[i] == GB_PATH_SEPARATOR) break; @@ -146,7 +146,7 @@ gb_inline isize string_extension_position(String str) { return dot_pos; } -gb_inline b32 string_has_extension(String str, String ext) { +gb_inline bool string_has_extension(String str, String ext) { if (str.len > ext.len+1) { u8 *s = str.text+str.len - ext.len-1; if (s[0] == '.') { @@ -158,7 +158,7 @@ gb_inline b32 string_has_extension(String str, String ext) { return false; } -b32 string_contains_char(String s, u8 c) { +bool string_contains_char(String s, u8 c) { for (isize i = 0; i < s.len; i++) { if (s.text[i] == c) return true; @@ -234,7 +234,7 @@ String string16_to_string(gbAllocator a, String16 s) { -b32 unquote_char(String s, u8 quote, Rune *rune, b32 *multiple_bytes, String *tail_string) { +bool unquote_char(String s, u8 quote, Rune *rune, bool *multiple_bytes, String *tail_string) { if (s.text[0] == quote && (quote == '$' || quote == '"')) { return false; @@ -392,8 +392,8 @@ i32 unquote_string(gbAllocator a, String *s_) { while (s.len > 0) { String tail_string = {}; Rune r = 0; - b32 multiple_bytes = false; - b32 success = unquote_char(s, quote, &r, &multiple_bytes, &tail_string); + bool multiple_bytes = false; + bool success = unquote_char(s, quote, &r, &multiple_bytes, &tail_string); if (!success) { gb_free(a, buf); return 0; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index d0f14990a..5ad346ca1 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -144,7 +144,7 @@ i32 token_pos_cmp(TokenPos a, TokenPos b) { return (a.line < b.line) ? -1 : +1; } -b32 token_pos_are_equal(TokenPos a, TokenPos b) { +bool token_pos_are_equal(TokenPos a, TokenPos b) { return token_pos_cmp(a, b) == 0; } @@ -250,19 +250,19 @@ void compiler_error(char *fmt, ...) { -gb_inline b32 token_is_literal(Token t) { +gb_inline bool token_is_literal(Token t) { return gb_is_between(t.kind, Token__LiteralBegin+1, Token__LiteralEnd-1); } -gb_inline b32 token_is_operator(Token t) { +gb_inline bool token_is_operator(Token t) { return gb_is_between(t.kind, Token__OperatorBegin+1, Token__OperatorEnd-1); } -gb_inline b32 token_is_keyword(Token t) { +gb_inline bool token_is_keyword(Token t) { return gb_is_between(t.kind, Token__KeywordBegin+1, Token__KeywordEnd-1); } -gb_inline b32 token_is_comparison(Token t) { +gb_inline bool token_is_comparison(Token t) { return gb_is_between(t.kind, Token__ComparisonBegin+1, Token__ComparisonEnd-1); } -gb_inline b32 token_is_shift(Token t) { +gb_inline bool token_is_shift(Token t) { return t.kind == Token_Shl || t.kind == Token_Shr; } @@ -435,7 +435,7 @@ gb_inline void scan_mantissa(Tokenizer *t, i32 base) { } -Token scan_number_to_token(Tokenizer *t, b32 seen_decimal_point) { +Token scan_number_to_token(Tokenizer *t, bool seen_decimal_point) { Token token = {}; token.kind = Token_Integer; token.string = make_string(t->curr, 1); @@ -510,7 +510,7 @@ exponent: } // Quote == " for string -b32 scan_escape(Tokenizer *t, Rune quote) { +bool scan_escape(Tokenizer *t, Rune quote) { isize len = 0; u32 base = 0, max = 0, x = 0; diff --git a/src/unicode.cpp b/src/unicode.cpp index 872881414..5c9f91f46 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -6,7 +6,7 @@ #pragma warning(pop) -b32 rune_is_letter(Rune r) { +bool rune_is_letter(Rune r) { if ((r < 0x80 && gb_char_is_alpha(cast(char)r)) || r == '_') { return true; @@ -22,14 +22,14 @@ b32 rune_is_letter(Rune r) { return false; } -b32 rune_is_digit(Rune r) { +bool rune_is_digit(Rune r) { if (r < 0x80 && gb_is_between(r, '0', '9')) { return true; } return utf8proc_category(r) == UTF8PROC_CATEGORY_ND; } -b32 rune_is_whitespace(Rune r) { +bool rune_is_whitespace(Rune r) { switch (r) { case ' ': case '\t': @@ -41,13 +41,13 @@ b32 rune_is_whitespace(Rune r) { } -b32 is_string_an_identifier(String s) { +bool is_string_an_identifier(String s) { if (s.len < 1) { return false; } isize offset = 0; while (offset < s.len) { - b32 ok = false; + bool ok = false; Rune r = -1; isize size = gb_utf8_decode(s.text+offset, s.len-offset, &r); if (offset == 0) { diff --git a/src/vm.cpp b/src/vm.cpp deleted file mode 100644 index db9941553..000000000 --- a/src/vm.cpp +++ /dev/null @@ -1,356 +0,0 @@ -#if 0 -// TODO(bill): COMPLETELY REWORK THIS ENTIRE INTERPRETER -#include "dyncall/include/dyncall.h" - -struct vmInterpreter; - -/* -Types: -boolean -integer -float -pointer -string -any -array -vector -slice -maybe -struct -union -raw_union -enum -tuple -proc -*/ - -struct vmProcedure { - Type * type; - String name; - b32 is_external; -}; - -struct vmValue { - void *data; - i32 id; - Type *type; - union { - i64 v_int; - f32 v_f32; - f64 v_f64; - vmProcedure * v_proc; - }; -}; - -Array<vmValue> vm_empty_args = {}; - -struct vmFrame { - vmInterpreter *i; - vmFrame * caller; - ssaProcedure * proc; - ssaBlock * block; - ssaBlock * prev_block; - isize instr_index; // For the current block - - Array<void *> env; // Index == instr id - vmValue result; -}; - -struct vmInterpreter { - ssaModule * module; - BaseTypeSizes sizes; - gbArena stack_arena; - gbAllocator stack_allocator; - gbAllocator heap_allocator; - - Array<vmFrame> frame_stack; - Map<vmValue> globals; -}; - -enum vmContinuation { - vmContinuation_Next, - vmContinuation_Return, - vmContinuation_Branch, -}; - - - - -i64 vm_size_of(vmInterpreter *i, Type *type) { - return type_size_of(i->sizes, i->heap_allocator, type); -} -i64 vm_align_of(vmInterpreter *i, Type *type) { - return type_align_of(i->sizes, i->heap_allocator, type); -} -i64 vm_offset_of(vmInterpreter *i, Type *type, i64 index) { - return type_offset_of(i->sizes, i->heap_allocator, type, index); -} - - - - - - -Array<vmValue> vm_prepare_call(vmFrame *f, ssaInstr *instr, vmValue *proc) { - GB_ASSERT(instr->kind == ssaInstr_Call); - - *proc = vm_get_value(f, instr->Call.value); - - Array<vmValue> args = {}; - array_init_count(&args, f->i->stack_allocator, instr->Call.arg_count); - - for (isize i = 0; i < instr->Call.arg_count; i++) { - args[i] = vm_get_value(f, instr->Call.args[i]); - } - - return args; -} - - -vmContinuation vm_visit_instr(vmFrame *f, ssaValue *value) { - ssaInstr *instr = &value->Instr; -#if 1 - if (instr->kind != ssaInstr_Comment) { - gb_printf("instr: %.*s\n", LIT(ssa_instr_strings[instr->kind])); - } -#endif - switch (instr->kind) { - case ssaInstr_StartupRuntime: { - - } break; - - case ssaInstr_Comment: break; - - case ssaInstr_Local: { - Type *type = ssa_type(value); - GB_ASSERT(is_type_pointer(type)); - i64 size = gb_max(1, vm_size_of(f->i, type)); - i64 align = gb_max(1, vm_align_of(f->i, type)); - void *mem = gb_alloc_align(f->i->stack_allocator, size, align); - - array_add(&f->locals, mem); - } break; - - case ssaInstr_ZeroInit: { - Type *pt = ssa_type(instr->ZeroInit.address); - GB_ASSERT(is_type_pointer(pt)); - vmValue addr = vm_get_value(f, instr->ZeroInit.address); - GB_ASSERT(are_types_identical(addr.type, ptr)); - i64 size = vm_size_of(vm, type_deref(pt)); - gb_zero(addr.v_ptr, size); - } break; - - case ssaInstr_Store: { - ssaValue *addr = instr->Store.Address; - ssaValue *value = instr->Store.Value; - } break; - - case ssaInstr_Load: { - ssaValue *addr = instr->Load.Address; - } break; - - case ssaInstr_ArrayElementPtr: { - - } break; - - case ssaInstr_StructElementPtr: { - - } break; - - case ssaInstr_PtrOffset: { - - } break; - - case ssaInstr_Phi: - for_array(i, f->block->preds) { - ssaBlock *pred = f->block->preds[i]; - if (f->prev_block == pred) { - vmValue edge = vm_get_value(f, instr->Phi.edges[i]); - // vm_set_value(f, value, edge); - break; - } - } - break; - - case ssaInstr_ArrayExtractValue: { - - } break; - - case ssaInstr_StructExtractValue: { - - } break; - - case ssaInstr_Jump: - f->prev_block = f->block; - f->block = instr->Jump.block; - return vmContinuation_Branch; - - case ssaInstr_If: - f->prev_block = f->block; - if (vm_get_value(f, instr->If.cond).v_int != 0) { - f->block = instr->If.true_block; - } else { - f->block = instr->If.false_block; - } - return vmContinuation_Branch; - - case ssaInstr_Return: - if (instr->Return.value != NULL) { - Type *type = base_type(ssa_type(instr->Return.value)); - GB_ASSERT(is_type_tuple(type)); - f->result = vm_get_value(f, instr->Return.value); - if (type->Tuple.variable_count == 1) { - f->result.type = type->Tuple.variables[0]->type; - } - } - f->block = NULL; - return vmContinuation_Return; - - case ssaInstr_Conv: { - - } break; - - case ssaInstr_Unreachable: { - GB_PANIC("Unreachable"); - } break; - - case ssaInstr_BinaryOp: { - - } break; - - case ssaInstr_Call: { - - } break; - - case ssaInstr_Select: { - - } break; - - case ssaInstr_VectorExtractElement: { - - } break; - - case ssaInstr_VectorInsertElement: { - - } break; - - case ssaInstr_VectorShuffle: { - - } break; - - case ssaInstr_BoundsCheck: { - - } break; - - case ssaInstr_SliceBoundsCheck: { - - } break; - - default: { - GB_PANIC("<unknown instr> %d\n", instr->kind); - } break; - } - - return vmContinuation_Next; -} - - -void vm_run_frame(vmFrame *f) { - for (;;) { - for_array(i, f->block->instrs) { - ssaValue *v = f->block->instrs[i]; - GB_ASSERT(v->kind == ssaValue_Instr); - switch (vm_visit_instr(f, v)) { - case vmContinuation_Return: - return; - case vmContinuation_Next: - // Do nothing - break; - case vmContinuation_Branch: - goto end; - } - } - end: - ; - } -} - -ssaProcedure *vm_lookup_proc(vmInterpreter *i, String name) { - ssaValue **found = map_get(&i->module->members, hash_string(name)); - if (found == NULL) { - return NULL; - } - ssaValue *v = *found; - if (v->kind != ssaValue_Proc) { - return NULL; - } - - return &v->Proc; -} - -vmValue vm_ext(vmFrame *caller, Array<vmValue> args) { - GB_PANIC("TODO(bill): vm_ext"); - vmValue v = {}; - return v; -} - -vmValue vm_call(vmInterpreter *i, vmFrame *caller, ssaProcedure *proc, Array<vmValue> args) { - if (proc == NULL) { - GB_PANIC("Call to NULL procedure"); - } - - gb_printf("Call: %.*s", LIT(proc->name)); - - vmFrame f = {}; - f.i = i; - f.caller = caller; - f.proc = proc; - if (proc->body == NULL) { - return vm_ext(&f, args); - } - f.block = proc->blocks[0]; - - map_init_with_reserve(&f.env, i->heap_allocator, 1.5*proc->instr_count); - defer (map_destroy(&f.env)); - - array_init_count(&f.locals, i->heap_allocator, proc->local_count); - defer (array_free(&f.locals)); - - for_array(i, proc->params) { - map_set(&f.env, hash_pointer(proc->params[i]), args[i]); - } - - while (f.block != NULL) { - vm_run_frame(&f); - } - - return f.result; -} - -i32 vm_interpret(ssaModule *m) { - i32 exit_code = 2; - - vmInterpreter i = {}; - - i.module = m; - i.sizes = m->sizes; - - gb_arena_init_from_allocator(&i.stack_arena, heap_allocator(), gb_megabytes(64)); - defer (gb_arena_free(&i.stack_arena)); - - i.stack_allocator = gb_arena_allocator(&i.stack_arena); - i.heap_allocator = heap_allocator(); - - ssaProcedure *main_proc = vm_lookup_proc(&i, make_string("main")); - if (main_proc != NULL) { - vm_call(&i, NULL, main_proc, vm_empty_args); - exit_code = 0; - } else { - gb_printf_err("No main procedure."); - exit_code = 1; - } - - return exit_code; -} - -#endif |