Build as C++

This commit is contained in:
Ginger Bill
2017-06-08 12:03:40 +01:00
parent 333924cce1
commit 9b61adb97d
27 changed files with 216 additions and 243 deletions
+6 -9
View File
@@ -4,8 +4,8 @@
set exe_name=odin.exe set exe_name=odin.exe
:: Debug = 0, Release = 1 :: Debug = 0, Release = 1
set release_mode=1 set release_mode=0
set compiler_flags= -nologo -Oi -TC -fp:fast -fp:except- -Gm- -MP -FC -GS- -EHsc- -GR- set compiler_flags= -nologo -Oi -TP -fp:fast -fp:except- -Gm- -MP -FC -GS- -EHsc- -GR-
if %release_mode% EQU 0 ( rem Debug if %release_mode% EQU 0 ( rem Debug
set compiler_flags=%compiler_flags% -Od -MDd -Z7 set compiler_flags=%compiler_flags% -Od -MDd -Z7
@@ -42,13 +42,10 @@ set linker_settings=%libs% %linker_flags%
del *.pdb > NUL 2> NUL del *.pdb > NUL 2> NUL
del *.ilk > NUL 2> NUL del *.ilk > NUL 2> NUL
odin run code/demo.odin rem odin run code/demo.odin
rem cl %compiler_settings% "src\main.c" ^ cl %compiler_settings% "src\main.cpp" ^
rem /link %linker_settings% -OUT:%exe_name% ^ /link %linker_settings% -OUT:%exe_name% ^
rem && odin run code/demo.odin && odin run code/demo.odin
rem && odin build code/metagen.odin ^
rem && call "code\metagen.exe" "src\ast_nodes.metagen"
rem && odin run code/Jaze/src/main.odin
del *.obj > NUL 2> NUL del *.obj > NUL 2> NUL
View File
+4 -4
View File
@@ -67,7 +67,7 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNodeArra
// NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be // NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be
// an extra allocation // an extra allocation
ArrayOperand operands = {0}; ArrayOperand operands = {};
array_init_reserve(&operands, c->tmp_allocator, 2*lhs_count); array_init_reserve(&operands, c->tmp_allocator, 2*lhs_count);
check_unpack_arguments(c, lhs_count, &operands, inits, true); check_unpack_arguments(c, lhs_count, &operands, inits, true);
@@ -174,7 +174,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init,
e->type = t; e->type = t;
} }
Operand operand = {0}; Operand operand = {};
if (init != NULL) { if (init != NULL) {
check_expr_or_type(c, &operand, init); check_expr_or_type(c, &operand, init);
} }
@@ -420,7 +420,7 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
if (entities == NULL || entity_count == 1) { if (entities == NULL || entity_count == 1) {
GB_ASSERT(entities == NULL || entities[0] == e); GB_ASSERT(entities == NULL || entities[0] == e);
Operand operand = {0}; Operand operand = {};
check_expr(c, &operand, init_expr); check_expr(c, &operand, init_expr);
check_init_variable(c, e, &operand, str_lit("variable declaration")); check_init_variable(c, e, &operand, str_lit("variable declaration"));
} }
@@ -484,7 +484,7 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) {
void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body) { void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body) {
GB_ASSERT(body->kind == AstNode_BlockStmt); GB_ASSERT(body->kind == AstNode_BlockStmt);
String proc_name = {0}; String proc_name = {};
if (token.kind == Token_Ident) { if (token.kind == Token_Ident) {
proc_name = token.string; proc_name = token.string;
} else { } else {
+53 -53
View File
@@ -390,7 +390,7 @@ isize check_fields(Checker *c, AstNode *node, AstNodeArray decls,
String context) { String context) {
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
MapEntity entity_map = {0}; MapEntity entity_map = {};
map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*field_count); map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*field_count);
Entity *using_index_expr = NULL; Entity *using_index_expr = NULL;
@@ -496,7 +496,7 @@ isize check_fields(Checker *c, AstNode *node, AstNodeArray decls,
// TODO(bill): Cleanup struct field reordering // TODO(bill): Cleanup struct field reordering
// TODO(bill): Inline sorting procedure? // TODO(bill): Inline sorting procedure?
gb_global gbAllocator __checker_allocator = {0}; gb_global gbAllocator __checker_allocator = {};
GB_COMPARE_PROC(cmp_reorder_struct_fields) { GB_COMPARE_PROC(cmp_reorder_struct_fields) {
// Rule: // Rule:
@@ -600,7 +600,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
return; return;
} }
Operand o = {0}; Operand o = {};
check_expr(c, &o, st->align); check_expr(c, &o, st->align);
if (o.mode != Addressing_Constant) { if (o.mode != Addressing_Constant) {
if (o.mode != Addressing_Invalid) { if (o.mode != Addressing_Invalid) {
@@ -650,7 +650,7 @@ void check_union_type(Checker *c, Type *union_type, AstNode *node) {
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
MapEntity entity_map = {0}; // Key: String MapEntity entity_map = {}; // Key: String
map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*variant_count); map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*variant_count);
Entity *using_index_expr = NULL; Entity *using_index_expr = NULL;
@@ -692,7 +692,7 @@ void check_union_type(Checker *c, Type *union_type, AstNode *node) {
ast_node(fl, FieldList, f->list); ast_node(fl, FieldList, f->list);
// NOTE(bill): Copy the contents for the common fields for now // NOTE(bill): Copy the contents for the common fields for now
AstNodeArray list = {0}; AstNodeArray list = {};
array_init_count(&list, c->allocator, ut->fields.count+fl->list.count); array_init_count(&list, c->allocator, ut->fields.count+fl->list.count);
gb_memmove_array(list.e, ut->fields.e, ut->fields.count); gb_memmove_array(list.e, ut->fields.e, ut->fields.count);
gb_memmove_array(list.e+ut->fields.count, fl->list.e, fl->list.count); gb_memmove_array(list.e+ut->fields.count, fl->list.e, fl->list.count);
@@ -801,7 +801,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
// NOTE(bill): Must be up here for the `check_init_constant` system // NOTE(bill): Must be up here for the `check_init_constant` system
enum_type->Record.enum_base_type = base_type; enum_type->Record.enum_base_type = base_type;
MapEntity entity_map = {0}; // Key: String MapEntity entity_map = {}; // Key: String
map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*(et->fields.count)); map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*(et->fields.count));
Entity **fields = gb_alloc_array(c->allocator, Entity *, et->fields.count); Entity **fields = gb_alloc_array(c->allocator, Entity *, et->fields.count);
@@ -837,7 +837,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
String name = ident->Ident.string; String name = ident->Ident.string;
if (init != NULL) { if (init != NULL) {
Operand o = {0}; Operand o = {};
check_expr(c, &o, init); check_expr(c, &o, init);
if (o.mode != Addressing_Constant) { if (o.mode != Addressing_Constant) {
error_node(init, "Enumeration value must be a constant"); error_node(init, "Enumeration value must be a constant");
@@ -922,7 +922,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
MapEntity entity_map = {0}; // Key: String MapEntity entity_map = {}; // Key: String
map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*(bft->fields.count)); map_entity_init_with_reserve(&entity_map, c->tmp_allocator, 2*(bft->fields.count));
isize field_count = 0; isize field_count = 0;
@@ -943,7 +943,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
} }
String name = ident->Ident.string; String name = ident->Ident.string;
Operand o = {0}; Operand o = {};
check_expr(c, &o, value); check_expr(c, &o, value);
if (o.mode != Addressing_Constant) { if (o.mode != Addressing_Constant) {
error_node(value, "Bit field bit size must be a constant"); error_node(value, "Bit field bit size must be a constant");
@@ -992,7 +992,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
if (bft->align != NULL) { if (bft->align != NULL) {
Operand o = {0}; Operand o = {};
check_expr(c, &o, bft->align); check_expr(c, &o, bft->align);
if (o.mode != Addressing_Constant) { if (o.mode != Addressing_Constant) {
if (o.mode != Addressing_Invalid) { if (o.mode != Addressing_Invalid) {
@@ -1079,7 +1079,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
AstNode *name = p->names.e[j]; AstNode *name = p->names.e[j];
if (ast_node_expect(name, AstNode_Ident)) { if (ast_node_expect(name, AstNode_Ident)) {
Entity *param = make_entity_param(c->allocator, scope, name->Ident, type, Entity *param = make_entity_param(c->allocator, scope, name->Ident, type,
p->flags&FieldFlag_using, p->flags&FieldFlag_immutable); (p->flags&FieldFlag_using) != 0, (p->flags&FieldFlag_immutable) != 0);
if (p->flags&FieldFlag_no_alias) { if (p->flags&FieldFlag_no_alias) {
param->flags |= EntityFlag_NoAlias; param->flags |= EntityFlag_NoAlias;
} }
@@ -1438,7 +1438,7 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type *
if (t == t_invalid) { if (t == t_invalid) {
continue; continue;
} }
Operand x = {0}; Operand x = {};
x.mode = Addressing_Value; x.mode = Addressing_Value;
x.type = t; x.type = t;
if (check_is_assignable_to(c, &x, type_hint)) { if (check_is_assignable_to(c, &x, type_hint)) {
@@ -1512,7 +1512,7 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type *
break; break;
case Entity_Builtin: case Entity_Builtin:
o->builtin_id = e->Builtin.id; o->builtin_id = cast(BuiltinProcId)e->Builtin.id;
o->mode = Addressing_Builtin; o->mode = Addressing_Builtin;
break; break;
@@ -1546,7 +1546,7 @@ i64 check_array_or_map_count(Checker *c, AstNode *e, bool is_map) {
if (e == NULL) { if (e == NULL) {
return 0; return 0;
} }
Operand o = {0}; Operand o = {};
if (e->kind == AstNode_UnaryExpr && if (e->kind == AstNode_UnaryExpr &&
e->UnaryExpr.op.kind == Token_Ellipsis) { e->UnaryExpr.op.kind == Token_Ellipsis) {
return -1; return -1;
@@ -1711,7 +1711,7 @@ bool check_type_extra_internal(Checker *c, AstNode *e, Type **type, Type *named_
switch (e->kind) { switch (e->kind) {
case_ast_node(i, Ident, e); case_ast_node(i, Ident, e);
Operand o = {0}; Operand o = {};
check_ident(c, &o, e, named_type, NULL, false); check_ident(c, &o, e, named_type, NULL, false);
switch (o.mode) { switch (o.mode) {
@@ -1735,7 +1735,7 @@ bool check_type_extra_internal(Checker *c, AstNode *e, Type **type, Type *named_
case_end; case_end;
case_ast_node(se, SelectorExpr, e); case_ast_node(se, SelectorExpr, e);
Operand o = {0}; Operand o = {};
check_selector(c, &o, e, NULL); check_selector(c, &o, e, NULL);
switch (o.mode) { switch (o.mode) {
@@ -1919,7 +1919,7 @@ bool check_type_extra_internal(Checker *c, AstNode *e, Type **type, Type *named_
case_end; case_end;
case_ast_node(ce, CallExpr, e); case_ast_node(ce, CallExpr, e);
Operand o = {0}; Operand o = {};
check_expr_or_type(c, &o, e); check_expr_or_type(c, &o, e);
if (o.mode == Addressing_Type) { if (o.mode == Addressing_Type) {
*type = o.type; *type = o.type;
@@ -1959,7 +1959,7 @@ Type *check_type_extra(Checker *c, AstNode *e, Type *named_type) {
} }
if (is_type_typed(type)) { if (is_type_typed(type)) {
add_type_and_value(&c->info, e, Addressing_Type, type, (ExactValue){0}); add_type_and_value(&c->info, e, Addressing_Type, type, ExactValue{});
} else { } else {
gbString name = type_to_string(type); gbString name = type_to_string(type);
error_node(e, "Invalid type definition of %s", name); error_node(e, "Invalid type definition of %s", name);
@@ -2213,8 +2213,8 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
if (!is_type_integer(o->type) && is_type_integer(type)) { if (!is_type_integer(o->type) && is_type_integer(type)) {
error_node(o->expr, "`%s` truncated to `%s`", a, b); error_node(o->expr, "`%s` truncated to `%s`", a, b);
} else { } else {
char buf[127] = {0}; char buf[127] = {};
String str = {0}; String str = {};
i128 i = o->value.value_integer; i128 i = o->value.value_integer;
if (is_type_unsigned(o->type)) { if (is_type_unsigned(o->type)) {
str = u128_to_string(*cast(u128 *)&i, buf, gb_size_of(buf)); str = u128_to_string(*cast(u128 *)&i, buf, gb_size_of(buf));
@@ -2421,7 +2421,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) {
GB_ASSERT(node->kind == AstNode_BinaryExpr); GB_ASSERT(node->kind == AstNode_BinaryExpr);
ast_node(be, BinaryExpr, node); ast_node(be, BinaryExpr, node);
ExactValue x_val = {0}; ExactValue x_val = {};
if (x->mode == Addressing_Constant) { if (x->mode == Addressing_Constant) {
x_val = exact_value_to_integer(x->value); x_val = exact_value_to_integer(x->value);
} }
@@ -2517,7 +2517,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) {
String check_down_cast_name(Type *dst_, Type *src_) { String check_down_cast_name(Type *dst_, Type *src_) {
String result = {0}; String result = {};
Type *dst = type_deref(dst_); Type *dst = type_deref(dst_);
Type *src = type_deref(src_); Type *src = type_deref(src_);
Type *dst_s = base_type(dst); Type *dst_s = base_type(dst);
@@ -2552,7 +2552,7 @@ Operand check_ptr_addition(Checker *c, TokenKind op, Operand *ptr, Operand *offs
GB_ASSERT(is_type_integer(offset->type)); GB_ASSERT(is_type_integer(offset->type));
GB_ASSERT(op == Token_Add || op == Token_Sub); GB_ASSERT(op == Token_Add || op == Token_Sub);
Operand operand = {0}; Operand operand = {};
operand.mode = Addressing_Value; operand.mode = Addressing_Value;
operand.type = ptr->type; operand.type = ptr->type;
operand.expr = node; operand.expr = node;
@@ -2764,7 +2764,7 @@ bool check_binary_vector_expr(Checker *c, Token op, Operand *x, Operand *y) {
void check_binary_expr(Checker *c, Operand *x, AstNode *node) { void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
GB_ASSERT(node->kind == AstNode_BinaryExpr); GB_ASSERT(node->kind == AstNode_BinaryExpr);
Operand y_ = {0}, *y = &y_; Operand y_ = {}, *y = &y_;
ast_node(be, BinaryExpr, node); ast_node(be, BinaryExpr, node);
@@ -3238,7 +3238,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
bool check_op_expr = true; bool check_op_expr = true;
Entity *expr_entity = NULL; Entity *expr_entity = NULL;
Entity *entity = NULL; Entity *entity = NULL;
Selection sel = {0}; // NOTE(bill): Not used if it's an import name Selection sel = {}; // NOTE(bill): Not used if it's an import name
operand->expr = node; operand->expr = node;
@@ -3336,7 +3336,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
continue; continue;
} }
Operand x = {0}; Operand x = {};
x.mode = Addressing_Value; x.mode = Addressing_Value;
x.type = t; x.type = t;
if (type_hint != NULL) { if (type_hint != NULL) {
@@ -3390,7 +3390,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
if (entity == NULL && selector->kind == AstNode_BasicLit) { if (entity == NULL && selector->kind == AstNode_BasicLit) {
if (is_type_struct(operand->type) || is_type_tuple(operand->type)) { if (is_type_struct(operand->type) || is_type_tuple(operand->type)) {
Type *type = base_type(operand->type); Type *type = base_type(operand->type);
Operand o = {0}; Operand o = {};
check_expr(c, &o, selector); check_expr(c, &o, selector);
if (o.mode != Addressing_Constant || if (o.mode != Addressing_Constant ||
!is_type_integer(o.type)) { !is_type_integer(o.type)) {
@@ -3496,7 +3496,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
break; break;
case Entity_Builtin: case Entity_Builtin:
operand->mode = Addressing_Builtin; operand->mode = Addressing_Builtin;
operand->builtin_id = entity->Builtin.id; operand->builtin_id = cast(BuiltinProcId)entity->Builtin.id;
break; break;
// NOTE(bill): These cases should never be hit but are here for sanity reasons // NOTE(bill): These cases should never be hit but are here for sanity reasons
@@ -3566,7 +3566,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
Type *op_type = type_deref(operand->type); Type *op_type = type_deref(operand->type);
Type *type = t_int; Type *type = t_int;
AddressingMode mode = Addressing_Invalid; AddressingMode mode = Addressing_Invalid;
ExactValue value = {0}; ExactValue value = {};
if (is_type_string(op_type) && id == BuiltinProc_len) { if (is_type_string(op_type) && id == BuiltinProc_len) {
if (operand->mode == Addressing_Constant) { if (operand->mode == Addressing_Constant) {
mode = Addressing_Constant; mode = Addressing_Constant;
@@ -3608,7 +3608,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
case BuiltinProc_new: { case BuiltinProc_new: {
// new :: proc(Type) -> ^Type // new :: proc(Type) -> ^Type
Operand op = {0}; Operand op = {};
check_expr_or_type(c, &op, ce->args.e[0]); check_expr_or_type(c, &op, ce->args.e[0]);
Type *type = op.type; Type *type = op.type;
if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) { if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) {
@@ -3622,7 +3622,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
case BuiltinProc_new_slice: { case BuiltinProc_new_slice: {
// new_slice :: proc(Type, len: int) -> []Type // new_slice :: proc(Type, len: int) -> []Type
// new_slice :: proc(Type, len, cap: int) -> []Type // new_slice :: proc(Type, len, cap: int) -> []Type
Operand op = {0}; Operand op = {};
check_expr_or_type(c, &op, ce->args.e[0]); check_expr_or_type(c, &op, ce->args.e[0]);
Type *type = op.type; Type *type = op.type;
if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) { if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) {
@@ -3636,7 +3636,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
// NOTE(bill): Return the correct type to reduce errors // NOTE(bill): Return the correct type to reduce errors
} else { } else {
// If any are constant // If any are constant
i64 sizes[2] = {0}; i64 sizes[2] = {};
isize size_count = 0; isize size_count = 0;
for (isize i = 1; i < arg_count; i++) { for (isize i = 1; i < arg_count; i++) {
i64 val = 0; i64 val = 0;
@@ -3660,7 +3660,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
case BuiltinProc_make: { case BuiltinProc_make: {
// make :: proc(Type, len: int) -> Type // make :: proc(Type, len: int) -> Type
// make :: proc(Type, len, cap: int) -> Type // make :: proc(Type, len, cap: int) -> Type
Operand op = {0}; Operand op = {};
check_expr_or_type(c, &op, ce->args.e[0]); check_expr_or_type(c, &op, ce->args.e[0]);
Type *type = op.type; Type *type = op.type;
if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) { if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) {
@@ -3693,7 +3693,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} }
// If any are constant // If any are constant
i64 sizes[4] = {0}; i64 sizes[4] = {};
isize size_count = 0; isize size_count = 0;
for (isize i = 1; i < arg_count; i++) { for (isize i = 1; i < arg_count; i++) {
i64 val = 0; i64 val = 0;
@@ -3756,7 +3756,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} }
AstNode *capacity = ce->args.e[1]; AstNode *capacity = ce->args.e[1];
Operand op = {0}; Operand op = {};
check_expr(c, &op, capacity); check_expr(c, &op, capacity);
if (op.mode == Addressing_Invalid) { if (op.mode == Addressing_Invalid) {
return false; return false;
@@ -3847,7 +3847,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
Type *key = base_type(type)->Map.key; Type *key = base_type(type)->Map.key;
Operand x = {Addressing_Invalid}; Operand x = {Addressing_Invalid};
AstNode *key_node = ce->args.e[1]; AstNode *key_node = ce->args.e[1];
Operand op = {0}; Operand op = {};
check_expr(c, &op, key_node); check_expr(c, &op, key_node);
if (op.mode == Addressing_Invalid) { if (op.mode == Addressing_Invalid) {
return false; return false;
@@ -3918,7 +3918,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
case BuiltinProc_offset_of: { case BuiltinProc_offset_of: {
// offset_of :: proc(Type, field) -> untyped int // offset_of :: proc(Type, field) -> untyped int
Operand op = {0}; Operand op = {};
Type *bt = check_type(c, ce->args.e[0]); Type *bt = check_type(c, ce->args.e[0]);
Type *type = base_type(bt); Type *type = base_type(bt);
if (type == NULL || type == t_invalid) { if (type == NULL || type == t_invalid) {
@@ -4116,7 +4116,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
if (d->kind == Type_Slice) { if (d->kind == Type_Slice) {
dest_type = d->Slice.elem; dest_type = d->Slice.elem;
} }
Operand op = {0}; Operand op = {};
check_expr(c, &op, ce->args.e[1]); check_expr(c, &op, ce->args.e[1]);
if (op.mode == Addressing_Invalid) { if (op.mode == Addressing_Invalid) {
return false; return false;
@@ -4170,7 +4170,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
continue; continue;
} }
AstNode *arg = ce->args.e[i]; AstNode *arg = ce->args.e[i];
Operand op = {0}; Operand op = {};
check_expr(c, &op, arg); check_expr(c, &op, arg);
if (op.mode == Addressing_Invalid) { if (op.mode == Addressing_Invalid) {
return false; return false;
@@ -4207,7 +4207,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
case BuiltinProc_complex: { case BuiltinProc_complex: {
// complex :: proc(real, imag: float_type) -> complex_type // complex :: proc(real, imag: float_type) -> complex_type
Operand x = *operand; Operand x = *operand;
Operand y = {0}; Operand y = {};
// NOTE(bill): Invalid will be the default till fixed // NOTE(bill): Invalid will be the default till fixed
operand->type = t_invalid; operand->type = t_invalid;
@@ -4352,7 +4352,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
// NOTE(bill): Return the correct type to reduce errors // NOTE(bill): Return the correct type to reduce errors
} else { } else {
// If any are constant // If any are constant
i64 sizes[2] = {0}; i64 sizes[2] = {};
isize size_count = 0; isize size_count = 0;
for (isize i = 1; i < arg_count; i++) { for (isize i = 1; i < arg_count; i++) {
i64 val = 0; i64 val = 0;
@@ -4398,7 +4398,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
AstNode *other_arg = ce->args.e[1]; AstNode *other_arg = ce->args.e[1];
Operand a = *operand; Operand a = *operand;
Operand b = {0}; Operand b = {};
check_expr(c, &b, other_arg); check_expr(c, &b, other_arg);
if (b.mode == Addressing_Invalid) { if (b.mode == Addressing_Invalid) {
return false; return false;
@@ -4466,7 +4466,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
AstNode *other_arg = ce->args.e[1]; AstNode *other_arg = ce->args.e[1];
Operand a = *operand; Operand a = *operand;
Operand b = {0}; Operand b = {};
check_expr(c, &b, other_arg); check_expr(c, &b, other_arg);
if (b.mode == Addressing_Invalid) { if (b.mode == Addressing_Invalid) {
return false; return false;
@@ -4569,8 +4569,8 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
AstNode *min_arg = ce->args.e[1]; AstNode *min_arg = ce->args.e[1];
AstNode *max_arg = ce->args.e[2]; AstNode *max_arg = ce->args.e[2];
Operand x = *operand; Operand x = *operand;
Operand y = {0}; Operand y = {};
Operand z = {0}; Operand z = {};
check_expr(c, &y, min_arg); check_expr(c, &y, min_arg);
if (y.mode == Addressing_Invalid) { if (y.mode == Addressing_Invalid) {
@@ -4645,7 +4645,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} break; } break;
case BuiltinProc_transmute: { case BuiltinProc_transmute: {
Operand op = {0}; Operand op = {};
check_expr_or_type(c, &op, ce->args.e[0]); check_expr_or_type(c, &op, ce->args.e[0]);
Type *t = op.type; Type *t = op.type;
if ((op.mode != Addressing_Type && t == NULL) || t == t_invalid) { if ((op.mode != Addressing_Type && t == NULL) || t == t_invalid) {
@@ -4768,7 +4768,7 @@ CallArgumentError check_call_arguments_internal(Checker *c, AstNode *call, Type
return err; return err;
} }
bool err = CallArgumentError_None; CallArgumentError err = CallArgumentError_None;
GB_ASSERT(proc_type->Proc.params != NULL); GB_ASSERT(proc_type->Proc.params != NULL);
Entity **sig_params = proc_type->Proc.params->Tuple.variables; Entity **sig_params = proc_type->Proc.params->Tuple.variables;
@@ -4839,7 +4839,7 @@ typedef Array(Operand) ArrayOperand;
bool check_unpack_arguments(Checker *c, isize lhs_count, ArrayOperand *operands, AstNodeArray rhs, bool allow_ok) { bool check_unpack_arguments(Checker *c, isize lhs_count, ArrayOperand *operands, AstNodeArray rhs, bool allow_ok) {
bool optional_ok = false; bool optional_ok = false;
for_array(i, rhs) { for_array(i, rhs) {
Operand o = {0}; Operand o = {};
check_multi_expr(c, &o, rhs.e[i]); check_multi_expr(c, &o, rhs.e[i]);
if (o.type == NULL || o.type->kind != Type_Tuple) { if (o.type == NULL || o.type->kind != Type_Tuple) {
@@ -5502,7 +5502,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
case Type_DynamicArray: case Type_DynamicArray:
{ {
Type *elem_type = NULL; Type *elem_type = NULL;
String context_name = {0}; String context_name = {};
i64 max_type_count = -1; i64 max_type_count = -1;
if (t->kind == Type_Slice) { if (t->kind == Type_Slice) {
elem_type = t->Slice.elem; elem_type = t->Slice.elem;
@@ -5549,7 +5549,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
error_node(e, "Index %lld is out of bounds (>= %lld) for %.*s", index, max_type_count, LIT(context_name)); error_node(e, "Index %lld is out of bounds (>= %lld) for %.*s", index, max_type_count, LIT(context_name));
} }
Operand operand = {0}; Operand operand = {};
check_expr_with_type_hint(c, &operand, e, elem_type); check_expr_with_type_hint(c, &operand, e, elem_type);
check_assignment(c, &operand, elem_type, context_name); check_assignment(c, &operand, elem_type, context_name);
@@ -5586,7 +5586,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
Type *field_types[2] = {t_rawptr, t_type_info_ptr}; Type *field_types[2] = {t_rawptr, t_type_info_ptr};
isize field_count = 2; isize field_count = 2;
if (cl->elems.e[0]->kind == AstNode_FieldValue) { if (cl->elems.e[0]->kind == AstNode_FieldValue) {
bool fields_visited[2] = {0}; bool fields_visited[2] = {};
for_array(i, cl->elems) { for_array(i, cl->elems) {
AstNode *elem = cl->elems.e[i]; AstNode *elem = cl->elems.e[i];
@@ -5839,7 +5839,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
bool is_const = o->mode == Addressing_Constant; bool is_const = o->mode == Addressing_Constant;
if (is_type_map(t)) { if (is_type_map(t)) {
Operand key = {0}; Operand key = {};
check_expr(c, &key, ie->index); check_expr(c, &key, ie->index);
check_assignment(c, &key, t->Map.key, str_lit("map index")); check_assignment(c, &key, t->Map.key, str_lit("map index"));
if (key.mode == Addressing_Invalid) { if (key.mode == Addressing_Invalid) {
@@ -5983,7 +5983,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
TokenKind interval_kind = se->interval0.kind; TokenKind interval_kind = se->interval0.kind;
i64 indices[2] = {0}; i64 indices[2] = {};
AstNode *nodes[3] = {se->low, se->high, se->max}; AstNode *nodes[3] = {se->low, se->high, se->max};
for (isize i = 0; i < gb_count_of(nodes); i++) { for (isize i = 0; i < gb_count_of(nodes); i++) {
i64 index = max_count; i64 index = max_count;
+23 -23
View File
@@ -218,7 +218,7 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) {
if (t == t_invalid) { if (t == t_invalid) {
continue; continue;
} }
Operand x = {0}; Operand x = {};
x.mode = Addressing_Value; x.mode = Addressing_Value;
x.type = t; x.type = t;
if (check_is_assignable_to(c, &x, lhs.type)) { if (check_is_assignable_to(c, &x, lhs.type)) {
@@ -392,7 +392,7 @@ typedef struct TypeAndToken {
#define MAP_TYPE TypeAndToken #define MAP_TYPE TypeAndToken
#define MAP_PROC map_type_and_token_ #define MAP_PROC map_type_and_token_
#define MAP_NAME MapTypeAndToken #define MAP_NAME MapTypeAndToken
#include "map.c" #include "map.cpp"
void check_when_stmt(Checker *c, AstNodeWhenStmt *ws, u32 flags) { void check_when_stmt(Checker *c, AstNodeWhenStmt *ws, u32 flags) {
flags &= ~Stmt_CheckScopeDecls; flags &= ~Stmt_CheckScopeDecls;
@@ -645,7 +645,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
return; return;
} }
Operand x = {0}; Operand x = {};
check_expr(c, &x, s->expr); check_expr(c, &x, s->expr);
if (x.mode == Addressing_Invalid) { if (x.mode == Addressing_Invalid) {
return; return;
@@ -693,7 +693,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
// NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be // NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be
// an extra allocation // an extra allocation
ArrayOperand operands = {0}; ArrayOperand operands = {};
array_init_reserve(&operands, c->tmp_allocator, 2 * lhs_count); array_init_reserve(&operands, c->tmp_allocator, 2 * lhs_count);
check_unpack_arguments(c, lhs_count, &operands, as->rhs, true); check_unpack_arguments(c, lhs_count, &operands, as->rhs, true);
@@ -863,7 +863,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
Type *val = NULL; Type *val = NULL;
Type *idx = NULL; Type *idx = NULL;
Entity *entities[2] = {0}; Entity *entities[2] = {};
isize entity_count = 0; isize entity_count = 0;
AstNode *expr = unparen_expr(rs->expr); AstNode *expr = unparen_expr(rs->expr);
@@ -943,10 +943,10 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
} }
if (x.mode != Addressing_Constant) { if (x.mode != Addressing_Constant) {
x.value = (ExactValue){0}; x.value = ExactValue{};
} }
if (y.mode != Addressing_Constant) { if (y.mode != Addressing_Constant) {
y.value = (ExactValue){0}; y.value = ExactValue{};
} }
@@ -1072,7 +1072,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
case_end; case_end;
case_ast_node(ms, MatchStmt, node); case_ast_node(ms, MatchStmt, node);
Operand x = {0}; Operand x = {};
mod_flags |= Stmt_BreakAllowed; mod_flags |= Stmt_BreakAllowed;
check_open_scope(c, node); check_open_scope(c, node);
@@ -1089,7 +1089,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
x.type = t_bool; x.type = t_bool;
x.value = exact_value_bool(true); x.value = exact_value_bool(true);
Token token = {0}; Token token = {};
token.pos = ast_node_token(ms->body).pos; token.pos = ast_node_token(ms->body).pos;
token.string = str_lit("true"); token.string = str_lit("true");
x.expr = ast_ident(c->curr_ast_file, token); x.expr = ast_ident(c->curr_ast_file, token);
@@ -1130,7 +1130,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
} }
} }
MapTypeAndToken seen = {0}; // NOTE(bill): Multimap MapTypeAndToken seen = {}; // NOTE(bill): Multimap
map_type_and_token_init(&seen, heap_allocator()); map_type_and_token_init(&seen, heap_allocator());
for_array(i, bs->stmts) { for_array(i, bs->stmts) {
@@ -1146,8 +1146,8 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
if (is_ast_node_a_range(expr)) { if (is_ast_node_a_range(expr)) {
ast_node(ie, BinaryExpr, expr); ast_node(ie, BinaryExpr, expr);
Operand lhs = {0}; Operand lhs = {};
Operand rhs = {0}; Operand rhs = {};
check_expr(c, &lhs, ie->left); check_expr(c, &lhs, ie->left);
if (x.mode == Addressing_Invalid) { if (x.mode == Addressing_Invalid) {
continue; continue;
@@ -1168,7 +1168,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
} }
TokenKind op = {0}; TokenKind op = {};
Operand a = lhs; Operand a = lhs;
Operand b = rhs; Operand b = rhs;
@@ -1197,7 +1197,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
Operand b1 = rhs; Operand b1 = rhs;
check_comparison(c, &a1, &b1, op); check_comparison(c, &a1, &b1, op);
} else { } else {
Operand y = {0}; Operand y = {};
check_expr(c, &y, expr); check_expr(c, &y, expr);
if (x.mode == Addressing_Invalid || if (x.mode == Addressing_Invalid ||
y.mode == Addressing_Invalid) { y.mode == Addressing_Invalid) {
@@ -1274,7 +1274,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
case_end; case_end;
case_ast_node(ms, TypeMatchStmt, node); case_ast_node(ms, TypeMatchStmt, node);
Operand x = {0}; Operand x = {};
mod_flags |= Stmt_BreakAllowed; mod_flags |= Stmt_BreakAllowed;
check_open_scope(c, node); check_open_scope(c, node);
@@ -1346,7 +1346,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
} }
MapBool seen = {0}; // Multimap MapBool seen = {}; // Multimap
map_bool_init(&seen, heap_allocator()); map_bool_init(&seen, heap_allocator());
for_array(i, bs->stmts) { for_array(i, bs->stmts) {
@@ -1364,7 +1364,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
for_array(type_index, cc->list) { for_array(type_index, cc->list) {
AstNode *type_expr = cc->list.e[type_index]; AstNode *type_expr = cc->list.e[type_index];
if (type_expr != NULL) { // Otherwise it's a default expression if (type_expr != NULL) { // Otherwise it's a default expression
Operand y = {0}; Operand y = {};
check_expr_or_type(c, &y, type_expr); check_expr_or_type(c, &y, type_expr);
if (match_type_kind == MatchType_Union) { if (match_type_kind == MatchType_Union) {
@@ -1481,7 +1481,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
} }
AstNode *ident = bs->label; AstNode *ident = bs->label;
String name = ident->Ident.string; String name = ident->Ident.string;
Operand o = {0}; Operand o = {};
Entity *e = check_ident(c, &o, ident, NULL, NULL, false); Entity *e = check_ident(c, &o, ident, NULL, NULL, false);
if (e == NULL) { if (e == NULL) {
error_node(ident, "Undeclared label name: %.*s", LIT(name)); error_node(ident, "Undeclared label name: %.*s", LIT(name));
@@ -1507,10 +1507,10 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
bool is_selector = false; bool is_selector = false;
if (expr->kind == AstNode_Ident) { if (expr->kind == AstNode_Ident) {
Operand o = {0}; Operand o = {};
e = check_ident(c, &o, expr, NULL, NULL, true); e = check_ident(c, &o, expr, NULL, NULL, true);
} else if (expr->kind == AstNode_SelectorExpr) { } else if (expr->kind == AstNode_SelectorExpr) {
Operand o = {0}; Operand o = {};
e = check_selector(c, &o, expr, NULL); e = check_selector(c, &o, expr, NULL);
is_selector = true; is_selector = true;
} else if (expr->kind == AstNode_Implicit) { } else if (expr->kind == AstNode_Implicit) {
@@ -1526,7 +1526,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
case_ast_node(pa, PushAllocator, node); case_ast_node(pa, PushAllocator, node);
Operand op = {0}; Operand op = {};
check_expr(c, &op, pa->expr); check_expr(c, &op, pa->expr);
check_assignment(c, &op, t_allocator, str_lit("argument to push_allocator")); check_assignment(c, &op, t_allocator, str_lit("argument to push_allocator"));
check_stmt(c, pa->body, mod_flags); check_stmt(c, pa->body, mod_flags);
@@ -1534,7 +1534,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
case_ast_node(pa, PushContext, node); case_ast_node(pa, PushContext, node);
Operand op = {0}; Operand op = {};
check_expr(c, &op, pa->expr); check_expr(c, &op, pa->expr);
check_assignment(c, &op, t_context, str_lit("argument to push_context")); check_assignment(c, &op, t_context, str_lit("argument to push_context"));
check_stmt(c, pa->body, mod_flags); check_stmt(c, pa->body, mod_flags);
@@ -1568,7 +1568,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
found = current_scope_lookup_entity(c->context.scope, str); found = current_scope_lookup_entity(c->context.scope, str);
} }
if (found == NULL) { if (found == NULL) {
entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, vd->flags&VarDeclFlag_immutable); entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, (vd->flags&VarDeclFlag_immutable) != 0);
entity->identifier = name; entity->identifier = name;
} else { } else {
TokenPos pos = found->token.pos; TokenPos pos = found->token.pos;
+23 -23
View File
@@ -1,5 +1,5 @@
#include "exact_value.c" #include "exact_value.cpp"
#include "entity.c" #include "entity.cpp"
typedef enum ExprKind { typedef enum ExprKind {
Expr_Expr, Expr_Expr,
@@ -123,7 +123,7 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = {
}; };
#include "types.c" #include "types.cpp"
typedef enum AddressingMode { typedef enum AddressingMode {
Addressing_Invalid, // invalid addressing mode Addressing_Invalid, // invalid addressing mode
@@ -230,7 +230,7 @@ ExprInfo make_expr_info(bool is_lhs, AddressingMode mode, Type *type, ExactValue
#define MAP_TYPE Entity * #define MAP_TYPE Entity *
#define MAP_PROC map_entity_ #define MAP_PROC map_entity_
#define MAP_NAME MapEntity #define MAP_NAME MapEntity
#include "map.c" #include "map.cpp"
typedef struct Scope { typedef struct Scope {
Scope * parent; Scope * parent;
@@ -258,27 +258,27 @@ gb_global Scope *universal_scope = NULL;
#define MAP_TYPE TypeAndValue #define MAP_TYPE TypeAndValue
#define MAP_PROC map_tav_ #define MAP_PROC map_tav_
#define MAP_NAME MapTypeAndValue #define MAP_NAME MapTypeAndValue
#include "map.c" #include "map.cpp"
#define MAP_TYPE Scope * #define MAP_TYPE Scope *
#define MAP_PROC map_scope_ #define MAP_PROC map_scope_
#define MAP_NAME MapScope #define MAP_NAME MapScope
#include "map.c" #include "map.cpp"
#define MAP_TYPE DeclInfo * #define MAP_TYPE DeclInfo *
#define MAP_PROC map_decl_info_ #define MAP_PROC map_decl_info_
#define MAP_NAME MapDeclInfo #define MAP_NAME MapDeclInfo
#include "map.c" #include "map.cpp"
#define MAP_TYPE AstFile * #define MAP_TYPE AstFile *
#define MAP_PROC map_ast_file_ #define MAP_PROC map_ast_file_
#define MAP_NAME MapAstFile #define MAP_NAME MapAstFile
#include "map.c" #include "map.cpp"
#define MAP_TYPE ExprInfo #define MAP_TYPE ExprInfo
#define MAP_PROC map_expr_info_ #define MAP_PROC map_expr_info_
#define MAP_NAME MapExprInfo #define MAP_NAME MapExprInfo
#include "map.c" #include "map.cpp"
typedef struct DelayedDecl { typedef struct DelayedDecl {
Scope * parent; Scope * parent;
@@ -754,7 +754,7 @@ void init_checker(Checker *c, Parser *parser, BuildContext *bc) {
for_array(i, parser->files) { for_array(i, parser->files) {
AstFile *file = &parser->files.e[i]; AstFile *file = &parser->files.e[i];
CheckerFileNode node = {0}; CheckerFileNode node = {};
node.id = file->id; node.id = file->id;
array_init(&node.whats, a); array_init(&node.whats, a);
array_init(&node.wheres, a); array_init(&node.wheres, a);
@@ -810,7 +810,7 @@ Entity *entity_of_ident(CheckerInfo *i, AstNode *identifier) {
TypeAndValue type_and_value_of_expr(CheckerInfo *i, AstNode *expression) { TypeAndValue type_and_value_of_expr(CheckerInfo *i, AstNode *expression) {
TypeAndValue result = {0}; TypeAndValue result = {};
TypeAndValue *found = map_tav_get(&i->types, hash_pointer(expression)); TypeAndValue *found = map_tav_get(&i->types, hash_pointer(expression));
if (found) result = *found; if (found) result = *found;
return result; return result;
@@ -857,7 +857,7 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
} }
} }
TypeAndValue tv = {0}; TypeAndValue tv = {};
tv.type = type; tv.type = type;
tv.value = value; tv.value = value;
tv.mode = mode; tv.mode = mode;
@@ -1086,7 +1086,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) { void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *decl, Type *type, AstNode *body, u32 tags) {
ProcedureInfo info = {0}; ProcedureInfo info = {};
info.file = file; info.file = file;
info.token = token; info.token = token;
info.decl = decl; info.decl = decl;
@@ -1114,7 +1114,7 @@ Type *const curr_procedure_type(Checker *c) {
void add_curr_ast_file(Checker *c, AstFile *file) { void add_curr_ast_file(Checker *c, AstFile *file) {
if (file != NULL) { if (file != NULL) {
TokenPos zero_pos = {0}; TokenPos zero_pos = {};
global_error_collector.prev = zero_pos; global_error_collector.prev = zero_pos;
c->curr_ast_file = file; c->curr_ast_file = file;
c->context.decl = file->decl_info; c->context.decl = file->decl_info;
@@ -1149,7 +1149,7 @@ void add_dependency_to_map(MapEntity *map, CheckerInfo *info, Entity *node) {
} }
MapEntity generate_minimum_dependency_map(CheckerInfo *info, Entity *start) { MapEntity generate_minimum_dependency_map(CheckerInfo *info, Entity *start) {
MapEntity map = {0}; // Key: Entity * MapEntity map = {}; // Key: Entity *
map_entity_init(&map, heap_allocator()); map_entity_init(&map, heap_allocator());
for_array(i, info->definitions.entries) { for_array(i, info->definitions.entries) {
@@ -1388,9 +1388,9 @@ void check_procedure_overloading(Checker *c, Entity *e) {
} }
#include "check_expr.c" #include "check_expr.cpp"
#include "check_decl.c" #include "check_decl.cpp"
#include "check_stmt.c" #include "check_stmt.cpp"
@@ -1517,7 +1517,7 @@ void check_collect_entities(Checker *c, AstNodeArray nodes, bool is_file_scope)
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind])); error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
continue; continue;
} }
Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident, NULL, vd->flags & VarDeclFlag_immutable); Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident, NULL, (vd->flags&VarDeclFlag_immutable) != 0);
e->Variable.is_thread_local = (vd->flags & VarDeclFlag_thread_local) != 0; e->Variable.is_thread_local = (vd->flags & VarDeclFlag_thread_local) != 0;
e->identifier = name; e->identifier = name;
@@ -1580,7 +1580,7 @@ void check_collect_entities(Checker *c, AstNodeArray nodes, bool is_file_scope)
d->proc_lit = up_init; d->proc_lit = up_init;
d->type_expr = vd->type; d->type_expr = vd->type;
} else { } else {
e = make_entity_constant(c->allocator, d->scope, name->Ident, NULL, (ExactValue){0}); e = make_entity_constant(c->allocator, d->scope, name->Ident, NULL, ExactValue{});
d->type_expr = vd->type; d->type_expr = vd->type;
d->init_expr = init; d->init_expr = init;
} }
@@ -1660,7 +1660,7 @@ void check_collect_entities(Checker *c, AstNodeArray nodes, bool is_file_scope)
void check_all_global_entities(Checker *c) { void check_all_global_entities(Checker *c) {
Scope *prev_file = {0}; Scope *prev_file = {};
for_array(i, c->info.entities.entries) { for_array(i, c->info.entities.entries) {
MapDeclInfoEntry *entry = &c->info.entities.entries.e[i]; MapDeclInfoEntry *entry = &c->info.entities.entries.e[i];
@@ -1776,7 +1776,7 @@ void check_import_entities(Checker *c, MapScope *file_scopes) {
#if 0 #if 0
// TODO(bill): Dependency ordering for imports // TODO(bill): Dependency ordering for imports
{ {
Array_i32 shared_global_file_ids = {0}; Array_i32 shared_global_file_ids = {};
array_init_reserve(&shared_global_file_ids, heap_allocator(), c->file_nodes.count); array_init_reserve(&shared_global_file_ids, heap_allocator(), c->file_nodes.count);
for_array(i, c->file_nodes) { for_array(i, c->file_nodes) {
CheckerFileNode *node = &c->file_nodes.e[i]; CheckerFileNode *node = &c->file_nodes.e[i];
@@ -2152,7 +2152,7 @@ void check_parsed_files(Checker *c) {
if (s->is_init) { if (s->is_init) {
Entity *e = current_scope_lookup_entity(s, str_lit("main")); Entity *e = current_scope_lookup_entity(s, str_lit("main"));
if (e == NULL) { if (e == NULL) {
Token token = {0}; Token token = {};
if (s->file->tokens.count > 0) { if (s->file->tokens.count > 0) {
token = s->file->tokens.e[0]; token = s->file->tokens.e[0];
} else { } else {
+8 -8
View File
@@ -13,11 +13,11 @@ gbAllocator heap_allocator(void) {
return gb_heap_allocator(); return gb_heap_allocator();
} }
#include "unicode.c" #include "unicode.cpp"
#include "string.c" #include "string.cpp"
#include "array.c" #include "array.cpp"
#include "integer128.c" #include "integer128.cpp"
#include "murmurhash3.c" #include "murmurhash3.cpp"
u128 fnv128a(void const *data, isize len) { u128 fnv128a(void const *data, isize len) {
u128 o = u128_lo_hi(0x13bull, 0x1000000ull); u128 o = u128_lo_hi(0x13bull, 0x1000000ull);
@@ -249,14 +249,14 @@ typedef Array(isize) Array_isize;
#define MAP_TYPE String #define MAP_TYPE String
#define MAP_PROC map_string_ #define MAP_PROC map_string_
#define MAP_NAME MapString #define MAP_NAME MapString
#include "map.c" #include "map.cpp"
#define MAP_TYPE bool #define MAP_TYPE bool
#define MAP_PROC map_bool_ #define MAP_PROC map_bool_
#define MAP_NAME MapBool #define MAP_NAME MapBool
#include "map.c" #include "map.cpp"
#define MAP_TYPE isize #define MAP_TYPE isize
#define MAP_PROC map_isize_ #define MAP_PROC map_isize_
#define MAP_NAME MapIsize #define MAP_NAME MapIsize
#include "map.c" #include "map.cpp"
View File
+2 -2
View File
@@ -364,7 +364,7 @@ ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision)
failure: failure:
GB_PANIC("Invalid unary operation, %.*s", LIT(token_strings[op])); GB_PANIC("Invalid unary operation, %.*s", LIT(token_strings[op]));
ExactValue error_value = {0}; ExactValue error_value = {};
return error_value; return error_value;
} }
@@ -523,7 +523,7 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y)
error: error:
; // MSVC accepts this??? apparently you cannot declare variables immediately after labels... ; // MSVC accepts this??? apparently you cannot declare variables immediately after labels...
ExactValue error_value = {0}; ExactValue error_value = {};
// gb_printf_err("Invalid binary operation: %s\n", token_kind_to_string(op)); // gb_printf_err("Invalid binary operation: %s\n", token_kind_to_string(op));
return error_value; return error_value;
} }
+5 -5
View File
@@ -1,16 +1,16 @@
typedef struct u128 {u64 lo; u64 hi;} u128; typedef struct u128 {u64 lo; u64 hi;} u128;
typedef struct i128 {u64 lo; i64 hi;} i128; typedef struct i128 {u64 lo; i64 hi;} i128;
#define BIT128_U64_HIGHBIT 0x8000000000000000ul #define BIT128_U64_HIGHBIT 0x8000000000000000ull
#define BIT128_U64_BITS62 0x7ffffffffffffffful #define BIT128_U64_BITS62 0x7fffffffffffffffull
#define BIT128_U64_ALLBITS 0xfffffffffffffffful #define BIT128_U64_ALLBITS 0xffffffffffffffffull
static u128 const U128_ZERO = {0, 0}; static u128 const U128_ZERO = {0, 0};
static u128 const U128_ONE = {1, 0}; static u128 const U128_ONE = {1, 0};
static i128 const I128_ZERO = {0, 0}; static i128 const I128_ZERO = {0, 0};
static i128 const I128_ONE = {1, 0}; static i128 const I128_ONE = {1, 0};
static u128 const U128_NEG_ONE = {BIT128_U64_ALLBITS, BIT128_U64_ALLBITS}; static u128 const U128_NEG_ONE = {BIT128_U64_ALLBITS, BIT128_U64_ALLBITS};
static i128 const I128_NEG_ONE = {BIT128_U64_ALLBITS, BIT128_U64_ALLBITS}; static i128 const I128_NEG_ONE = {BIT128_U64_ALLBITS, cast(i64)BIT128_U64_ALLBITS};
u128 u128_lo_hi (u64 lo, u64 hi); u128 u128_lo_hi (u64 lo, u64 hi);
u128 u128_from_u32 (u32 u); u128 u128_from_u32 (u32 u);
@@ -99,7 +99,7 @@ u64 bit128__digit_value(Rune r) {
return 16; // NOTE(bill): Larger than highest possible return 16; // NOTE(bill): Larger than highest possible
} }
u128 u128_lo_hi(u64 lo, u64 hi) { return (u128){lo, hi}; } u128 u128_lo_hi(u64 lo, u64 hi) { return u128{lo, hi}; }
u128 u128_from_u32(u32 u) { return u128_lo_hi(cast(u64)u, 0); } u128 u128_from_u32(u32 u) { return u128_lo_hi(cast(u64)u, 0); }
u128 u128_from_u64(u64 u) { return u128_lo_hi(cast(u64)u, 0); } u128 u128_from_u64(u64 u) { return u128_lo_hi(cast(u64)u, 0); }
u128 u128_from_i64(i64 u) { return u128_lo_hi(cast(u64)u, u < 0 ? -1 : 0); } u128 u128_from_i64(i64 u) { return u128_lo_hi(cast(u64)u, u < 0 ? -1 : 0); }
+19 -39
View File
@@ -8,12 +8,12 @@ typedef Array(irValue *) irValueArray;
#define MAP_TYPE irValue * #define MAP_TYPE irValue *
#define MAP_PROC map_ir_value_ #define MAP_PROC map_ir_value_
#define MAP_NAME MapIrValue #define MAP_NAME MapIrValue
#include "map.c" #include "map.cpp"
#define MAP_TYPE irDebugInfo * #define MAP_TYPE irDebugInfo *
#define MAP_PROC map_ir_debug_info_ #define MAP_PROC map_ir_debug_info_
#define MAP_NAME MapIrDebugInfo #define MAP_NAME MapIrDebugInfo
#include "map.c" #include "map.cpp"
typedef struct irModule { typedef struct irModule {
@@ -3387,7 +3387,7 @@ irValue *ir_emit_logical_binary_expr(irProcedure *proc, AstNode *expr) {
return ir_build_expr(proc, be->right); return ir_build_expr(proc, be->right);
} }
irValueArray edges = {0}; irValueArray edges = {};
array_init_reserve(&edges, proc->module->allocator, done->preds.count+1); array_init_reserve(&edges, proc->module->allocator, done->preds.count+1);
for_array(i, done->preds) { for_array(i, done->preds) {
array_add(&edges, short_circuit); array_add(&edges, short_circuit);
@@ -3521,7 +3521,7 @@ irBranchBlocks ir_lookup_branch_blocks(irProcedure *proc, AstNode *ident) {
} }
GB_PANIC("Unreachable"); GB_PANIC("Unreachable");
return (irBranchBlocks){0}; return irBranchBlocks{};
} }
@@ -3712,7 +3712,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
case_ast_node(te, TernaryExpr, expr); case_ast_node(te, TernaryExpr, expr);
ir_emit_comment(proc, str_lit("TernaryExpr")); ir_emit_comment(proc, str_lit("TernaryExpr"));
irValueArray edges = {0}; irValueArray edges = {};
array_init_reserve(&edges, proc->module->allocator, 2); array_init_reserve(&edges, proc->module->allocator, 2);
GB_ASSERT(te->y != NULL); GB_ASSERT(te->y != NULL);
@@ -3752,7 +3752,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
ir_build_stmt(proc, ie->init); ir_build_stmt(proc, ie->init);
} }
irValueArray edges = {0}; irValueArray edges = {};
array_init_reserve(&edges, proc->module->allocator, 2); array_init_reserve(&edges, proc->module->allocator, 2);
GB_ASSERT(ie->else_expr != NULL); GB_ASSERT(ie->else_expr != NULL);
@@ -4375,7 +4375,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
TokenPos pos = token.pos; TokenPos pos = token.pos;
gbString expr = expr_to_string(ce->args.e[0]); gbString expr = expr_to_string(ce->args.e[0]);
isize expr_len = gb_string_length(expr); isize expr_len = gb_string_length(expr);
String expr_str = {0}; String expr_str = {};
expr_str.text = cast(u8 *)gb_alloc_copy_align(proc->module->allocator, expr, expr_len, 1); expr_str.text = cast(u8 *)gb_alloc_copy_align(proc->module->allocator, expr, expr_len, 1);
expr_str.len = expr_len; expr_str.len = expr_len;
gb_string_free(expr); gb_string_free(expr);
@@ -4778,7 +4778,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
case_ast_node(i, Ident, expr); case_ast_node(i, Ident, expr);
if (ir_is_blank_ident(expr)) { if (ir_is_blank_ident(expr)) {
irAddr val = {0}; irAddr val = {};
return val; return val;
} }
Entity *e = entity_of_ident(proc->module->info, expr); Entity *e = entity_of_ident(proc->module->info, expr);
@@ -4902,27 +4902,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
case_end; case_end;
case_ast_node(be, BinaryExpr, expr); case_ast_node(be, BinaryExpr, expr);
switch (be->op.kind) { GB_PANIC("Invalid binary expression for ir_build_addr: %.*s\n", LIT(be->op.string));
// case Token_as: {
// ir_emit_comment(proc, str_lit("Cast - as"));
// // NOTE(bill): Needed for dereference of pointer conversion
// Type *type = type_of_expr(proc->module->info, expr);
// irValue *v = ir_add_local_generated(proc, type);
// ir_emit_store(proc, v, ir_emit_conv(proc, ir_build_expr(proc, be->left), type));
// return ir_addr(v);
// }
// case Token_transmute: {
// ir_emit_comment(proc, str_lit("Cast - transmute"));
// // NOTE(bill): Needed for dereference of pointer conversion
// Type *type = type_of_expr(proc->module->info, expr);
// irValue *v = ir_add_local_generated(proc, type);
// ir_emit_store(proc, v, ir_emit_transmute(proc, ir_build_expr(proc, be->left), type));
// return ir_addr(v);
// }
default:
GB_PANIC("Invalid binary expression for ir_build_addr: %.*s\n", LIT(be->op.string));
break;
}
case_end; case_end;
case_ast_node(ie, IndexExpr, expr); case_ast_node(ie, IndexExpr, expr);
@@ -5806,8 +5786,8 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
} }
} }
} else { // Tuple(s) } else { // Tuple(s)
Array(irAddr) lvals = {0}; Array(irAddr) lvals = {};
irValueArray inits = {0}; irValueArray inits = {};
array_init_reserve(&lvals, m->tmp_allocator, vd->names.count); array_init_reserve(&lvals, m->tmp_allocator, vd->names.count);
array_init_reserve(&inits, m->tmp_allocator, vd->names.count); array_init_reserve(&inits, m->tmp_allocator, vd->names.count);
@@ -5950,7 +5930,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
for_array(i, as->lhs) { for_array(i, as->lhs) {
AstNode *lhs = as->lhs.e[i]; AstNode *lhs = as->lhs.e[i];
irAddr lval = {0}; irAddr lval = {};
if (!ir_is_blank_ident(lhs)) { if (!ir_is_blank_ident(lhs)) {
lval = ir_build_addr(proc, lhs); lval = ir_build_addr(proc, lhs);
} }
@@ -6319,8 +6299,8 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
} }
} }
irAddr val_addr = {0}; irAddr val_addr = {};
irAddr idx_addr = {0}; irAddr idx_addr = {};
if (val_type != NULL) { if (val_type != NULL) {
val_addr = ir_build_addr(proc, rs->value); val_addr = ir_build_addr(proc, rs->value);
} }
@@ -6358,7 +6338,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
ast_node(body, BlockStmt, ms->body); ast_node(body, BlockStmt, ms->body);
AstNodeArray default_stmts = {0}; AstNodeArray default_stmts = {};
irBlock *default_fall = NULL; irBlock *default_fall = NULL;
irBlock *default_block = NULL; irBlock *default_block = NULL;
@@ -6404,7 +6384,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
irValue *cond = v_false; irValue *cond = v_false;
if (is_ast_node_a_range(expr)) { if (is_ast_node_a_range(expr)) {
ast_node(ie, BinaryExpr, expr); ast_node(ie, BinaryExpr, expr);
TokenKind op = {0}; TokenKind op = {};
switch (ie->op.kind) { switch (ie->op.kind) {
case Token_Ellipsis: op = Token_LtEq; break; case Token_Ellipsis: op = Token_LtEq; break;
case Token_HalfClosed: op = Token_Lt; break; case Token_HalfClosed: op = Token_Lt; break;
@@ -7184,7 +7164,7 @@ void ir_gen_tree(irGen *s) {
g->Global.name = name; g->Global.name = name;
g->Global.is_thread_local = e->Variable.is_thread_local; g->Global.is_thread_local = e->Variable.is_thread_local;
irGlobalVariable var = {0}; irGlobalVariable var = {};
var.var = g; var.var = g;
var.decl = decl; var.decl = decl;
@@ -7670,7 +7650,7 @@ void ir_gen_tree(irGen *s) {
{ {
irValue *packed = ir_const_bool(a, t->Record.is_packed); irValue *packed = ir_const_bool(a, t->Record.is_packed);
irValue *ordered = ir_const_bool(a, t->Record.is_ordered); irValue *ordered = ir_const_bool(a, t->Record.is_ordered);
irValue *custom_align = ir_const_bool(a, t->Record.custom_align); irValue *custom_align = ir_const_bool(a, t->Record.custom_align != 0);
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), packed); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 4), packed);
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 5), ordered); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 5), ordered);
ir_emit_store(proc, ir_emit_struct_ep(proc, record, 6), custom_align); ir_emit_store(proc, ir_emit_struct_ep(proc, record, 6), custom_align);
@@ -7700,7 +7680,7 @@ void ir_gen_tree(irGen *s) {
ir_emit_store(proc, name, ir_const_string(a, f->token.string)); ir_emit_store(proc, name, ir_const_string(a, f->token.string));
} }
ir_emit_store(proc, offset, ir_const_int(a, foffset)); ir_emit_store(proc, offset, ir_const_int(a, foffset));
ir_emit_store(proc, is_using, ir_const_bool(a, f->flags&EntityFlag_Using)); ir_emit_store(proc, is_using, ir_const_bool(a, (f->flags&EntityFlag_Using) != 0));
} }
irValue *count = ir_const_int(a, t->Record.field_count); irValue *count = ir_const_int(a, t->Record.field_count);
View File
+4 -4
View File
@@ -39,7 +39,7 @@ void ir_file_buffer_write(irFileBuffer *f, void *data, isize len) {
void ir_fprintf(irFileBuffer *f, char *fmt, ...) { void ir_fprintf(irFileBuffer *f, char *fmt, ...) {
va_list va; va_list va;
va_start(va, fmt); va_start(va, fmt);
char buf[4096] = {0}; char buf[4096] = {};
isize len = gb_snprintf_va(buf, gb_size_of(buf), fmt, va); isize len = gb_snprintf_va(buf, gb_size_of(buf), fmt, va);
ir_file_buffer_write(f, buf, len-1); ir_file_buffer_write(f, buf, len-1);
va_end(va); va_end(va);
@@ -48,7 +48,7 @@ void ir_fprint_string(irFileBuffer *f, String s) {
ir_file_buffer_write(f, s.text, s.len); ir_file_buffer_write(f, s.text, s.len);
} }
void ir_fprint_i128(irFileBuffer *f, i128 i) { void ir_fprint_i128(irFileBuffer *f, i128 i) {
char buf[200] = {0}; char buf[200] = {};
String str = i128_to_string(i, buf, gb_size_of(buf)-1); String str = i128_to_string(i, buf, gb_size_of(buf)-1);
ir_fprint_string(f, str); ir_fprint_string(f, str);
} }
@@ -581,7 +581,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
for (isize i = 0; i < value_count; i++) { for (isize i = 0; i < value_count; i++) {
Entity *f = type->Record.fields_in_src_order[i]; Entity *f = type->Record.fields_in_src_order[i];
TypeAndValue tav = type_and_value_of_expr(m->info, cl->elems.e[i]); TypeAndValue tav = type_and_value_of_expr(m->info, cl->elems.e[i]);
ExactValue val = {0}; ExactValue val = {};
if (tav.mode != Addressing_Invalid) { if (tav.mode != Addressing_Invalid) {
val = tav.value; val = tav.value;
} }
@@ -1573,7 +1573,7 @@ void ir_print_type_name(irFileBuffer *f, irModule *m, irValue *v) {
void print_llvm_ir(irGen *ir) { void print_llvm_ir(irGen *ir) {
irModule *m = &ir->module; irModule *m = &ir->module;
irFileBuffer buf = {0}, *f = &buf; irFileBuffer buf = {}, *f = &buf;
ir_file_buffer_init(f, &ir->output_file); ir_file_buffer_init(f, &ir->output_file);
ir_print_encoded_local(f, str_lit("..string")); ir_print_encoded_local(f, str_lit("..string"));
+10 -11
View File
@@ -4,17 +4,16 @@ extern "C" {
#define USE_CUSTOM_BACKEND false #define USE_CUSTOM_BACKEND false
#include "common.c" #include "common.cpp"
#include "timings.c" #include "timings.cpp"
#include "build_settings.c" #include "build_settings.cpp"
#include "tokenizer.c" #include "tokenizer.cpp"
#include "parser.c" #include "parser.cpp"
#include "checker.c" #include "checker.cpp"
#include "ssa.c" #include "ssa.cpp"
#include "ir.c" #include "ir.cpp"
#include "ir_opt.c" #include "ir_opt.cpp"
#include "ir_print.c" #include "ir_print.cpp"
// #include "vm.c"
#if defined(GB_SYSTEM_WINDOWS) #if defined(GB_SYSTEM_WINDOWS)
// NOTE(bill): `name` is used in debugging and profiling modes // NOTE(bill): `name` is used in debugging and profiling modes
+3 -3
View File
@@ -4,7 +4,7 @@
#define MAP_TYPE String #define MAP_TYPE String
#define MAP_PROC map_string_ #define MAP_PROC map_string_
#define MAP_NAME MapString #define MAP_NAME MapString
#include "map.c" #include "map.cpp"
*/ */
// A `Map` is an unordered hash table which can allow for a key to point to multiple values // A `Map` is an unordered hash table which can allow for a key to point to multiple values
// with the use of the `multi_*` procedures. // with the use of the `multi_*` procedures.
@@ -134,7 +134,7 @@ gb_inline void _J2(MAP_PROC,destroy)(MAP_NAME *h) {
} }
gb_internal isize _J2(MAP_PROC,_add_entry)(MAP_NAME *h, HashKey key) { gb_internal isize _J2(MAP_PROC,_add_entry)(MAP_NAME *h, HashKey key) {
MAP_ENTRY e = {0}; MAP_ENTRY e = {};
e.key = key; e.key = key;
e.next = -1; e.next = -1;
array_add(&h->entries, e); array_add(&h->entries, e);
@@ -185,7 +185,7 @@ gb_inline void _J2(MAP_PROC,grow)(MAP_NAME *h) {
void _J2(MAP_PROC,rehash)(MAP_NAME *h, isize new_count) { void _J2(MAP_PROC,rehash)(MAP_NAME *h, isize new_count) {
isize i, j; isize i, j;
MAP_NAME nh = {0}; MAP_NAME nh = {};
_J2(MAP_PROC,init)(&nh, h->hashes.allocator); _J2(MAP_PROC,init)(&nh, h->hashes.allocator);
array_resize(&nh.hashes, new_count); array_resize(&nh.hashes, new_count);
array_reserve(&nh.entries, h->entries.count); array_reserve(&nh.entries, h->entries.count);
+29 -29
View File
@@ -561,7 +561,7 @@ Token ast_node_token(AstNode *node) {
AstNode *clone_ast_node(gbAllocator a, AstNode *node); AstNode *clone_ast_node(gbAllocator a, AstNode *node);
AstNodeArray clone_ast_node_array(gbAllocator a, AstNodeArray array) { AstNodeArray clone_ast_node_array(gbAllocator a, AstNodeArray array) {
AstNodeArray result = {0}; AstNodeArray result = {};
if (array.count > 0) { if (array.count > 0) {
array_init_count(&result, a, array.count); array_init_count(&result, a, array.count);
for_array(i, array) { for_array(i, array) {
@@ -1754,7 +1754,7 @@ AstNodeArray parse_element_list(AstFile *f) {
} }
AstNode *parse_literal_value(AstFile *f, AstNode *type) { AstNode *parse_literal_value(AstFile *f, AstNode *type) {
AstNodeArray elems = {0}; AstNodeArray elems = {};
Token open = expect_token(f, Token_OpenBrace); Token open = expect_token(f, Token_OpenBrace);
f->expr_level++; f->expr_level++;
if (f->curr_token.kind != Token_CloseBrace) { if (f->curr_token.kind != Token_CloseBrace) {
@@ -2048,8 +2048,8 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
case Token_proc: { case Token_proc: {
Token token = f->curr_token; Token token = f->curr_token;
AstNode *foreign_library = NULL; AstNode *foreign_library = NULL;
String foreign_name = {0}; String foreign_name = {};
String link_name = {0}; String link_name = {};
AstNode *type = parse_proc_type(f, &foreign_library, &foreign_name, &link_name); AstNode *type = parse_proc_type(f, &foreign_library, &foreign_name, &link_name);
u64 tags = type->ProcType.tags; u64 tags = type->ProcType.tags;
@@ -2111,7 +2111,7 @@ bool is_literal_type(AstNode *node) {
AstNode *parse_call_expr(AstFile *f, AstNode *operand) { AstNode *parse_call_expr(AstFile *f, AstNode *operand) {
AstNodeArray args = make_ast_node_array(f); AstNodeArray args = make_ast_node_array(f);
Token open_paren, close_paren; Token open_paren, close_paren;
Token ellipsis = {0}; Token ellipsis = {};
f->expr_level++; f->expr_level++;
open_paren = expect_token(f, Token_OpenParen); open_paren = expect_token(f, Token_OpenParen);
@@ -2224,10 +2224,10 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) {
bool prev_allow_range = f->allow_range; bool prev_allow_range = f->allow_range;
f->allow_range = false; f->allow_range = false;
Token open = {0}, close = {0}, interval = {0}; Token open = {}, close = {}, interval = {};
AstNode *indices[3] = {0}; AstNode *indices[3] = {};
isize ellipsis_count = 0; isize ellipsis_count = 0;
Token ellipses[2] = {0}; Token ellipses[2] = {};
f->expr_level++; f->expr_level++;
open = expect_token(f, Token_OpenBracket); open = expect_token(f, Token_OpenBracket);
@@ -2472,7 +2472,7 @@ AstNode *parse_type(AstFile *f) {
AstNode *parse_value_decl(AstFile *f, AstNodeArray lhs) { AstNode *parse_value_decl(AstFile *f, AstNodeArray lhs) {
AstNode *type = NULL; AstNode *type = NULL;
AstNodeArray values = {0}; AstNodeArray values = {};
bool is_mutable = true; bool is_mutable = true;
if (allow_token(f, Token_Colon)) { if (allow_token(f, Token_Colon)) {
@@ -2516,7 +2516,7 @@ AstNode *parse_value_decl(AstFile *f, AstNodeArray lhs) {
values = make_ast_node_array(f); values = make_ast_node_array(f);
} }
AstNodeArray specs = {0}; AstNodeArray specs = {};
array_init_reserve(&specs, heap_allocator(), 1); array_init_reserve(&specs, heap_allocator(), 1);
return ast_value_decl(f, is_mutable, lhs, type, values); return ast_value_decl(f, is_mutable, lhs, type, values);
} }
@@ -2564,7 +2564,7 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) {
AstNode *expr = parse_expr(f, false); AstNode *expr = parse_expr(f, false);
f->allow_range = prev_allow_range; f->allow_range = prev_allow_range;
AstNodeArray rhs = {0}; AstNodeArray rhs = {};
array_init_count(&rhs, heap_allocator(), 1); array_init_count(&rhs, heap_allocator(), 1);
rhs.e[0] = expr; rhs.e[0] = expr;
@@ -2638,7 +2638,7 @@ AstNode *parse_results(AstFile *f) {
if (f->curr_token.kind != Token_OpenParen) { if (f->curr_token.kind != Token_OpenParen) {
Token begin_token = f->curr_token; Token begin_token = f->curr_token;
AstNodeArray empty_names = {0}; AstNodeArray empty_names = {};
AstNodeArray list = make_ast_node_array(f); AstNodeArray list = make_ast_node_array(f);
AstNode *type = parse_type(f); AstNode *type = parse_type(f);
array_add(&list, ast_field(f, empty_names, type, 0)); array_add(&list, ast_field(f, empty_names, type, 0));
@@ -2653,8 +2653,8 @@ AstNode *parse_results(AstFile *f) {
} }
AstNode *parse_proc_type(AstFile *f, AstNode **foreign_library_, String *foreign_name_, String *link_name_) { AstNode *parse_proc_type(AstFile *f, AstNode **foreign_library_, String *foreign_name_, String *link_name_) {
AstNode *params = {0}; AstNode *params = {};
AstNode *results = {0}; AstNode *results = {};
Token proc_token = expect_token(f, Token_proc); Token proc_token = expect_token(f, Token_proc);
expect_token(f, Token_OpenParen); expect_token(f, Token_OpenParen);
@@ -2663,8 +2663,8 @@ AstNode *parse_proc_type(AstFile *f, AstNode **foreign_library_, String *foreign
results = parse_results(f); results = parse_results(f);
u64 tags = 0; u64 tags = 0;
String foreign_name = {0}; String foreign_name = {};
String link_name = {0}; String link_name = {};
AstNode *foreign_library = NULL; AstNode *foreign_library = NULL;
ProcCallingConvention cc = ProcCC_Odin; ProcCallingConvention cc = ProcCC_Odin;
@@ -2789,7 +2789,7 @@ typedef struct AstNodeAndFlags {
typedef Array(AstNodeAndFlags) AstNodeAndFlagsArray; typedef Array(AstNodeAndFlags) AstNodeAndFlagsArray;
AstNodeArray convert_to_ident_list(AstFile *f, AstNodeAndFlagsArray list, bool ignore_flags) { AstNodeArray convert_to_ident_list(AstFile *f, AstNodeAndFlagsArray list, bool ignore_flags) {
AstNodeArray idents = {0}; AstNodeArray idents = {};
array_init_reserve(&idents, heap_allocator(), list.count); array_init_reserve(&idents, heap_allocator(), list.count);
// Convert to ident list // Convert to ident list
for_array(i, list) { for_array(i, list) {
@@ -2834,7 +2834,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok
Token start_token = f->curr_token; Token start_token = f->curr_token;
AstNodeArray params = make_ast_node_array(f); AstNodeArray params = make_ast_node_array(f);
AstNodeAndFlagsArray list = {0}; array_init(&list, heap_allocator()); // LEAK(bill): AstNodeAndFlagsArray list = {}; array_init(&list, heap_allocator()); // LEAK(bill):
isize total_name_count = 0; isize total_name_count = 0;
bool allow_ellipsis = allowed_flags&FieldFlag_ellipsis; bool allow_ellipsis = allowed_flags&FieldFlag_ellipsis;
@@ -2896,7 +2896,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok
} }
for_array(i, list) { for_array(i, list) {
AstNodeArray names = {0}; AstNodeArray names = {};
AstNode *type = list.e[i].node; AstNode *type = list.e[i].node;
Token token = blank_token; Token token = blank_token;
@@ -3054,7 +3054,7 @@ AstNode *parse_type_or_ident(AstFile *f) {
AstNode *fields = parse_record_fields(f, &decl_count, FieldFlag_using, str_lit("struct")); AstNode *fields = parse_record_fields(f, &decl_count, FieldFlag_using, str_lit("struct"));
Token close = expect_token(f, Token_CloseBrace); Token close = expect_token(f, Token_CloseBrace);
AstNodeArray decls = {0}; AstNodeArray decls = {};
if (fields != NULL) { if (fields != NULL) {
GB_ASSERT(fields->kind == AstNode_FieldList); GB_ASSERT(fields->kind == AstNode_FieldList);
decls = fields->FieldList.list; decls = fields->FieldList.list;
@@ -3123,7 +3123,7 @@ AstNode *parse_type_or_ident(AstFile *f) {
AstNode *fields = parse_record_fields(f, &decl_count, FieldFlag_using, str_lit("raw_union")); AstNode *fields = parse_record_fields(f, &decl_count, FieldFlag_using, str_lit("raw_union"));
Token close = expect_token(f, Token_CloseBrace); Token close = expect_token(f, Token_CloseBrace);
AstNodeArray decls = {0}; AstNodeArray decls = {};
if (fields != NULL) { if (fields != NULL) {
GB_ASSERT(fields->kind == AstNode_FieldList); GB_ASSERT(fields->kind == AstNode_FieldList);
decls = fields->FieldList.list; decls = fields->FieldList.list;
@@ -3214,7 +3214,7 @@ AstNode *parse_type_or_ident(AstFile *f) {
AstNode *parse_body(AstFile *f) { AstNode *parse_body(AstFile *f) {
AstNodeArray stmts = {0}; AstNodeArray stmts = {};
Token open, close; Token open, close;
isize prev_expr_level = f->expr_level; isize prev_expr_level = f->expr_level;
@@ -3689,7 +3689,7 @@ AstNode *parse_stmt(AstFile *f) {
if (str_eq(tag, str_lit("import"))) { if (str_eq(tag, str_lit("import"))) {
AstNode *cond = NULL; AstNode *cond = NULL;
Token import_name = {0}; Token import_name = {};
switch (f->curr_token.kind) { switch (f->curr_token.kind) {
case Token_Period: case Token_Period:
@@ -3755,7 +3755,7 @@ AstNode *parse_stmt(AstFile *f) {
return s; return s;
} else if (str_eq(tag, str_lit("foreign_system_library"))) { } else if (str_eq(tag, str_lit("foreign_system_library"))) {
AstNode *cond = NULL; AstNode *cond = NULL;
Token lib_name = {0}; Token lib_name = {};
switch (f->curr_token.kind) { switch (f->curr_token.kind) {
case Token_Ident: case Token_Ident:
@@ -3786,7 +3786,7 @@ AstNode *parse_stmt(AstFile *f) {
return s; return s;
} else if (str_eq(tag, str_lit("foreign_library"))) { } else if (str_eq(tag, str_lit("foreign_library"))) {
AstNode *cond = NULL; AstNode *cond = NULL;
Token lib_name = {0}; Token lib_name = {};
switch (f->curr_token.kind) { switch (f->curr_token.kind) {
case Token_Ident: case Token_Ident:
@@ -4050,11 +4050,11 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, AstNodeArray
syntax_error_node(node, "Only declarations are allowed at file scope %.*s", LIT(ast_node_strings[node->kind])); syntax_error_node(node, "Only declarations are allowed at file scope %.*s", LIT(ast_node_strings[node->kind]));
} else if (node->kind == AstNode_ImportDecl) { } else if (node->kind == AstNode_ImportDecl) {
ast_node(id, ImportDecl, node); ast_node(id, ImportDecl, node);
String collection_name = {0}; String collection_name = {};
String oirignal_string = id->relpath.string; String oirignal_string = id->relpath.string;
String file_str = id->relpath.string; String file_str = id->relpath.string;
gbAllocator allocator = heap_allocator(); // TODO(bill): Change this allocator gbAllocator allocator = heap_allocator(); // TODO(bill): Change this allocator
String import_file = {0}; String import_file = {};
#if 0 #if 0
isize colon_pos = -1; isize colon_pos = -1;
@@ -4173,7 +4173,7 @@ void parse_file(Parser *p, AstFile *f) {
ParseFileError parse_files(Parser *p, char *init_filename) { ParseFileError parse_files(Parser *p, char *init_filename) {
char *fullpath_str = gb_path_get_full_name(heap_allocator(), init_filename); char *fullpath_str = gb_path_get_full_name(heap_allocator(), init_filename);
String init_fullpath = make_string_c(fullpath_str); String init_fullpath = make_string_c(fullpath_str);
TokenPos init_pos = {0}; TokenPos init_pos = {};
ImportedFile init_imported_file = {init_fullpath, init_fullpath, init_pos}; ImportedFile init_imported_file = {init_fullpath, init_fullpath, init_pos};
@@ -4196,7 +4196,7 @@ ParseFileError parse_files(Parser *p, char *init_filename) {
String import_path = imported_file.path; String import_path = imported_file.path;
String import_rel_path = imported_file.rel_path; String import_rel_path = imported_file.rel_path;
TokenPos pos = imported_file.pos; TokenPos pos = imported_file.pos;
AstFile file = {0}; AstFile file = {};
ParseFileError err = init_ast_file(&file, import_path); ParseFileError err = init_ast_file(&file, import_path);
View File
+6 -6
View File
@@ -17,11 +17,11 @@ String ssa_mangle_name(ssaModule *m, String path, Entity *e);
#define MAP_TYPE ssaValue * #define MAP_TYPE ssaValue *
#define MAP_PROC map_ssa_value_ #define MAP_PROC map_ssa_value_
#define MAP_NAME MapSsaValue #define MAP_NAME MapSsaValue
#include "map.c" #include "map.cpp"
typedef Array(ssaValue *) ssaValueArray; typedef Array(ssaValue *) ssaValueArray;
#include "ssa_op.c" #include "ssa_op.cpp"
#define SSA_DEFAULT_VALUE_ARG_CAPACITY 8 #define SSA_DEFAULT_VALUE_ARG_CAPACITY 8
struct ssaValueArgs { struct ssaValueArgs {
@@ -287,7 +287,7 @@ void ssa_add_arg(ssaValueArgs *va, ssaValue *arg) {
} else { } else {
isize old_cap_size = va->capacity * gb_size_of(ssaValue *); isize old_cap_size = va->capacity * gb_size_of(ssaValue *);
isize new_cap_size = capacity * gb_size_of(ssaValue *); isize new_cap_size = capacity * gb_size_of(ssaValue *);
va->e = gb_resize(va->allocator, va->e, old_cap_size, new_cap_size); *(cast(void **)&va->e) = gb_resize(va->allocator, va->e, old_cap_size, new_cap_size);
} }
va->capacity = capacity; va->capacity = capacity;
} }
@@ -378,9 +378,9 @@ ssaValue *ssa_const_i64 (ssaProc *p, Type *t, i64 c) { return ssa
ssaValue *ssa_const_f32 (ssaProc *p, Type *t, f32 c) { return ssa_const_val(p, ssaOp_Const32F, t, exact_value_float(c)); } ssaValue *ssa_const_f32 (ssaProc *p, Type *t, f32 c) { return ssa_const_val(p, ssaOp_Const32F, t, exact_value_float(c)); }
ssaValue *ssa_const_f64 (ssaProc *p, Type *t, f64 c) { return ssa_const_val(p, ssaOp_Const64F, t, exact_value_float(c)); } ssaValue *ssa_const_f64 (ssaProc *p, Type *t, f64 c) { return ssa_const_val(p, ssaOp_Const64F, t, exact_value_float(c)); }
ssaValue *ssa_const_string (ssaProc *p, Type *t, String c) { return ssa_const_val(p, ssaOp_ConstString, t, exact_value_string(c)); } ssaValue *ssa_const_string (ssaProc *p, Type *t, String c) { return ssa_const_val(p, ssaOp_ConstString, t, exact_value_string(c)); }
ssaValue *ssa_const_empty_string(ssaProc *p, Type *t) { return ssa_const_val(p, ssaOp_ConstString, t, (ExactValue){0}); } ssaValue *ssa_const_empty_string(ssaProc *p, Type *t) { return ssa_const_val(p, ssaOp_ConstString, t, ExactValue{}); }
ssaValue *ssa_const_slice (ssaProc *p, Type *t, ExactValue v) { return ssa_const_val(p, ssaOp_ConstSlice, t, v); } ssaValue *ssa_const_slice (ssaProc *p, Type *t, ExactValue v) { return ssa_const_val(p, ssaOp_ConstSlice, t, v); }
ssaValue *ssa_const_nil (ssaProc *p, Type *t) { return ssa_const_val(p, ssaOp_ConstNil, t, (ExactValue){0}); } ssaValue *ssa_const_nil (ssaProc *p, Type *t) { return ssa_const_val(p, ssaOp_ConstNil, t, ExactValue{}); }
ssaValue *ssa_const_int(ssaProc *p, Type *t, i64 c) { ssaValue *ssa_const_int(ssaProc *p, Type *t, i64 c) {
switch (8*type_size_of(p->allocator, t)) { switch (8*type_size_of(p->allocator, t)) {
@@ -413,7 +413,7 @@ void ssa_reset_value_args(ssaValue *v) {
void ssa_reset(ssaValue *v, ssaOp op) { void ssa_reset(ssaValue *v, ssaOp op) {
v->op = op; v->op = op;
v->exact_value = (ExactValue){0}; v->exact_value = ExactValue{};
ssa_reset_value_args(v); ssa_reset_value_args(v);
} }
View File
+5 -5
View File
@@ -1,5 +1,5 @@
gb_global gbArena string_buffer_arena = {0}; gb_global gbArena string_buffer_arena = {};
gb_global gbAllocator string_buffer_allocator = {0}; gb_global gbAllocator string_buffer_allocator = {};
void init_string_buffer_memory(void) { void init_string_buffer_memory(void) {
// NOTE(bill): This should be enough memory for file systems // NOTE(bill): This should be enough memory for file systems
@@ -16,7 +16,7 @@ typedef struct String {
// NOTE(bill): used for printf style arguments // NOTE(bill): used for printf style arguments
#define LIT(x) ((int)(x).len), (x).text #define LIT(x) ((int)(x).len), (x).text
#define STR_LIT(c_str) {cast(u8 *)c_str, gb_size_of(c_str)-1} #define STR_LIT(c_str) {cast(u8 *)c_str, gb_size_of(c_str)-1}
#define str_lit(c_str) (String){cast(u8 *)c_str, gb_size_of(c_str)-1} #define str_lit(c_str) String{cast(u8 *)c_str, gb_size_of(c_str)-1}
// NOTE(bill): String16 is only used for Windows due to its file directories // NOTE(bill): String16 is only used for Windows due to its file directories
@@ -471,12 +471,12 @@ i32 unquote_string(gbAllocator a, String *s_) {
{ {
u8 rune_temp[4] = {0}; u8 rune_temp[4] = {};
isize buf_len = 3*s.len / 2; isize buf_len = 3*s.len / 2;
u8 *buf = gb_alloc_array(a, u8, buf_len); u8 *buf = gb_alloc_array(a, u8, buf_len);
isize offset = 0; isize offset = 0;
while (s.len > 0) { while (s.len > 0) {
String tail_string = {0}; String tail_string = {};
Rune r = 0; Rune r = 0;
bool multiple_bytes = false; bool multiple_bytes = false;
bool success = unquote_char(s, quote, &r, &multiple_bytes, &tail_string); bool success = unquote_char(s, quote, &r, &multiple_bytes, &tail_string);
View File
+5 -5
View File
@@ -343,7 +343,7 @@ typedef struct Tokenizer {
TokenizerState save_tokenizer_state(Tokenizer *t) { TokenizerState save_tokenizer_state(Tokenizer *t) {
TokenizerState state = {0}; TokenizerState state = {};
state.curr_rune = t->curr_rune; state.curr_rune = t->curr_rune;
state.curr = t->curr; state.curr = t->curr;
state.read_curr = t->read_curr; state.read_curr = t->read_curr;
@@ -435,7 +435,7 @@ TokenizerInitError init_tokenizer(Tokenizer *t, String fullpath) {
array_init(&t->allocated_strings, heap_allocator()); array_init(&t->allocated_strings, heap_allocator());
} else { } else {
gbFile f = {0}; gbFile f = {};
gbFileError file_err = gb_file_open(&f, c_str); gbFileError file_err = gb_file_open(&f, c_str);
switch (file_err) { switch (file_err) {
@@ -492,7 +492,7 @@ gb_inline void scan_mantissa(Tokenizer *t, i32 base) {
} }
Token scan_number_to_token(Tokenizer *t, bool seen_decimal_point) { Token scan_number_to_token(Tokenizer *t, bool seen_decimal_point) {
Token token = {0}; Token token = {};
token.kind = Token_Integer; token.kind = Token_Integer;
token.string = make_string(t->curr, 1); token.string = make_string(t->curr, 1);
token.pos.file = t->fullpath; token.pos.file = t->fullpath;
@@ -742,7 +742,7 @@ bool tokenizer_find_line_end(Tokenizer *t) {
Token tokenizer_get_token(Tokenizer *t) { Token tokenizer_get_token(Tokenizer *t) {
tokenizer_skip_whitespace(t); tokenizer_skip_whitespace(t);
Token token = {0}; Token token = {};
token.string = make_string(t->curr, 1); token.string = make_string(t->curr, 1);
token.pos.file = t->fullpath; token.pos.file = t->fullpath;
token.pos.line = t->line_count; token.pos.line = t->line_count;
@@ -963,7 +963,7 @@ Token tokenizer_get_token(Tokenizer *t) {
default: default:
if (curr_rune != GB_RUNE_BOM) { if (curr_rune != GB_RUNE_BOM) {
u8 str[4] = {0}; u8 str[4] = {};
int len = cast(int)gb_utf8_encode_rune(str, curr_rune); int len = cast(int)gb_utf8_encode_rune(str, curr_rune);
tokenizer_err(t, "Illegal character: %.*s (%d) ", len, str, curr_rune); tokenizer_err(t, "Illegal character: %.*s (%d) ", len, str, curr_rune);
} }
+1 -1
View File
@@ -1617,7 +1617,7 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
switch (t->kind) { switch (t->kind) {
case Type_Basic: { case Type_Basic: {
GB_ASSERT(is_type_typed(t)); GB_ASSERT(is_type_typed(t));
switch (t->kind) { switch (t->Basic.kind) {
case Basic_string: return build_context.word_size; case Basic_string: return build_context.word_size;
case Basic_any: return build_context.word_size; case Basic_any: return build_context.word_size;
+2 -1
View File
@@ -1,9 +1,10 @@
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4245) #pragma warning(disable: 4245)
extern "C" {
// #include "utf8proc/utf8proc.h" // #include "utf8proc/utf8proc.h"
#include "utf8proc/utf8proc.c" #include "utf8proc/utf8proc.c"
}
#pragma warning(pop) #pragma warning(pop)
+8 -12
View File
@@ -383,7 +383,7 @@ UTF8PROC_DLLEXPORT int utf8proc_charwidth(utf8proc_int32_t c) {
} }
UTF8PROC_DLLEXPORT utf8proc_category_t utf8proc_category(utf8proc_int32_t c) { UTF8PROC_DLLEXPORT utf8proc_category_t utf8proc_category(utf8proc_int32_t c) {
return utf8proc_get_property(c)->category; return cast(utf8proc_category_t)utf8proc_get_property(c)->category;
} }
UTF8PROC_DLLEXPORT const char *utf8proc_category_string(utf8proc_int32_t c) { UTF8PROC_DLLEXPORT const char *utf8proc_category_string(utf8proc_int32_t c) {
@@ -393,15 +393,15 @@ UTF8PROC_DLLEXPORT const char *utf8proc_category_string(utf8proc_int32_t c) {
#define utf8proc_decompose_lump(replacement_uc) \ #define utf8proc_decompose_lump(replacement_uc) \
return utf8proc_decompose_char((replacement_uc), dst, bufsize, \ return utf8proc_decompose_char((replacement_uc), dst, bufsize, \
options & ~UTF8PROC_LUMP, last_boundclass) (utf8proc_option_t)(options & ~UTF8PROC_LUMP), last_boundclass)
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_char(utf8proc_int32_t uc, utf8proc_int32_t *dst, utf8proc_ssize_t bufsize, utf8proc_option_t options, int *last_boundclass) { UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_char(utf8proc_int32_t uc, utf8proc_int32_t *dst, utf8proc_ssize_t bufsize, utf8proc_option_t options, int *last_boundclass) {
const utf8proc_property_t *property; const utf8proc_property_t *property;
utf8proc_propval_t category; utf8proc_category_t category;
utf8proc_int32_t hangul_sindex; utf8proc_int32_t hangul_sindex;
if (uc < 0 || uc >= 0x110000) return UTF8PROC_ERROR_NOTASSIGNED; if (uc < 0 || uc >= 0x110000) return UTF8PROC_ERROR_NOTASSIGNED;
property = unsafe_get_property(uc); property = unsafe_get_property(uc);
category = property->category; category = cast(utf8proc_category_t)property->category;
hangul_sindex = uc - UTF8PROC_HANGUL_SBASE; hangul_sindex = uc - UTF8PROC_HANGUL_SBASE;
if (options & (UTF8PROC_COMPOSE|UTF8PROC_DECOMPOSE)) { if (options & (UTF8PROC_COMPOSE|UTF8PROC_DECOMPOSE)) {
if (hangul_sindex >= 0 && hangul_sindex < UTF8PROC_HANGUL_SCOUNT) { if (hangul_sindex >= 0 && hangul_sindex < UTF8PROC_HANGUL_SCOUNT) {
@@ -728,28 +728,24 @@ UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map_custom(
UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFD(const utf8proc_uint8_t *str) { UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFD(const utf8proc_uint8_t *str) {
utf8proc_uint8_t *retval; utf8proc_uint8_t *retval;
utf8proc_map(str, 0, &retval, UTF8PROC_NULLTERM | UTF8PROC_STABLE | utf8proc_map(str, 0, &retval, cast(utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_DECOMPOSE));
UTF8PROC_DECOMPOSE);
return retval; return retval;
} }
UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFC(const utf8proc_uint8_t *str) { UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFC(const utf8proc_uint8_t *str) {
utf8proc_uint8_t *retval; utf8proc_uint8_t *retval;
utf8proc_map(str, 0, &retval, UTF8PROC_NULLTERM | UTF8PROC_STABLE | utf8proc_map(str, 0, &retval, cast(utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_COMPOSE));
UTF8PROC_COMPOSE);
return retval; return retval;
} }
UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKD(const utf8proc_uint8_t *str) { UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKD(const utf8proc_uint8_t *str) {
utf8proc_uint8_t *retval; utf8proc_uint8_t *retval;
utf8proc_map(str, 0, &retval, UTF8PROC_NULLTERM | UTF8PROC_STABLE | utf8proc_map(str, 0, &retval, cast(utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_DECOMPOSE|UTF8PROC_COMPAT));
UTF8PROC_DECOMPOSE | UTF8PROC_COMPAT);
return retval; return retval;
} }
UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKC(const utf8proc_uint8_t *str) { UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKC(const utf8proc_uint8_t *str) {
utf8proc_uint8_t *retval; utf8proc_uint8_t *retval;
utf8proc_map(str, 0, &retval, UTF8PROC_NULLTERM | UTF8PROC_STABLE | utf8proc_map(str, 0, &retval, cast(utf8proc_option_t)(UTF8PROC_NULLTERM|UTF8PROC_STABLE|UTF8PROC_COMPOSE|UTF8PROC_COMPAT));
UTF8PROC_COMPOSE | UTF8PROC_COMPAT);
return retval; return retval;
} }