Print nil for nil procedures in fmt.odin

This commit is contained in:
gingerBill
2017-12-12 21:21:55 +00:00
parent f7e9649be4
commit 78b459590c
4 changed files with 31 additions and 38 deletions

View File

@@ -909,9 +909,14 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
fmt_enum(fi, v, verb);
case Type_Info_Procedure:
write_type(fi.buf, v.type_info);
write_string(fi.buf, " @ ");
fmt_pointer(fi, (^rawptr)(v.data)^, 'p');
ptr := (^rawptr)(v.data)^;
if ptr == nil {
write_string(fi.buf, "nil");
} else {
write_type(fi.buf, v.type_info);
write_string(fi.buf, " @ ");
fmt_pointer(fi, ptr, 'p');
}
}
}

View File

@@ -40,12 +40,12 @@ general_stuff :: proc() {
i := i32(137);
ptr := &i;
fp1 := (^f32)(ptr);
_ = (^f32)(ptr);
// ^f32(ptr) == ^(f32(ptr))
fp2 := cast(^f32)ptr;
_ = cast(^f32)ptr;
f1 := (^f32)(ptr)^;
f2 := (cast(^f32)ptr)^;
_ = (^f32)(ptr)^;
_ = (cast(^f32)ptr)^;
// Questions: Should there be two ways to do it?
}
@@ -540,7 +540,7 @@ threading_example :: proc() {
threads := make([dynamic]^thread.Thread, 0, len(prefix_table));
defer free(threads);
for i in 0..len(prefix_table) {
for in prefix_table {
if t := thread.create(worker_proc); t != nil {
t.init_context = context;
t.use_init_context = true;

View File

@@ -802,6 +802,7 @@ GB_COMPARE_PROC(entity_variable_pos_cmp) {
void check_scope_usage(Checker *c, Scope *scope) {
// TODO(bill): Use this?
#if 0
Array<Entity *> unused = {};
array_init(&unused, heap_allocator());
defer (array_free(&unused));
@@ -827,6 +828,7 @@ void check_scope_usage(Checker *c, Scope *scope) {
check_scope_usage(c, child);
}
}
#endif
}

View File

@@ -605,7 +605,9 @@ struct irGen {
gb_inline bool ir_min_dep_entity(irModule *m, Entity *e) {
return ptr_set_exists(&m->min_dep_set, e);
}
Type *ir_type(irValue *value);
Type *ir_instr_type(irInstr *instr) {
@@ -3804,7 +3806,7 @@ void ir_gen_global_type_name(irModule *m, Entity *e, String name) {
for_array(i, *found) {
Entity *sub = (*found)[i];
// gb_printf_err("--> %.*s\n", LIT(sub->token.string));
if (ptr_set_exists(&m->min_dep_set, sub)) {
if (ir_min_dep_entity(m, sub)) {
ir_mangle_add_sub_type_name(m, sub, name);
}
}
@@ -3812,7 +3814,7 @@ void ir_gen_global_type_name(irModule *m, Entity *e, String name) {
return;
}
if (!ptr_set_exists(&m->min_dep_set, e)) {
if (!ir_min_dep_entity(m, e)) {
return;
}
irValue *t = ir_value_type_name(m->allocator, name, e->type);
@@ -5977,7 +5979,7 @@ irValue *ir_build_cond(irProcedure *proc, AstNode *cond, irBlock *true_block, ir
void ir_build_poly_proc(irProcedure *proc, AstNodeProcLit *pd, Entity *e) {
GB_ASSERT(pd->body != nullptr);
if (ptr_set_exists(&proc->module->min_dep_set, e) == false) {
if (ir_min_dep_entity(proc->module, e) == false) {
// NOTE(bill): Nothing depends upon it so doesn't need to be built
return;
}
@@ -6037,7 +6039,7 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) {
}
}
if (!polymorphic_struct && !ptr_set_exists(&proc->module->min_dep_set, e)) {
if (!polymorphic_struct && !ir_min_dep_entity(proc->module, e)) {
continue;
}
@@ -6065,7 +6067,7 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) {
auto procs = *found;
for_array(i, procs) {
Entity *e = procs[i];
if (!ptr_set_exists(&proc->module->min_dep_set, e)) {
if (!ir_min_dep_entity(proc->module, e)) {
continue;
}
DeclInfo *d = decl_info_of_entity(info, e);
@@ -8194,9 +8196,9 @@ void ir_gen_tree(irGen *s) {
}
}
{ // Add global default context
m->global_default_context = ir_add_global_generated(m, t_context, nullptr);
}
// Add global default context
m->global_default_context = ir_add_global_generated(m, t_context, nullptr);
struct irGlobalVariable {
irValue *var, *init;
DeclInfo *decl;
@@ -8217,7 +8219,7 @@ void ir_gen_tree(irGen *s) {
continue;
}
if (!ptr_set_exists(&m->min_dep_set, e)) {
if (!ir_min_dep_entity(m, e)) {
continue;
}
DeclInfo *decl = decl_info_of_entity(info, e);
@@ -8310,7 +8312,7 @@ void ir_gen_tree(irGen *s) {
}
}
if (!polymorphic_struct && !ptr_set_exists(&m->min_dep_set, e)) {
if (!polymorphic_struct && !ir_min_dep_entity(m, e)) {
// NOTE(bill): Nothing depends upon it so doesn't need to be built
continue;
}
@@ -8438,6 +8440,7 @@ void ir_gen_tree(irGen *s) {
e->Procedure.link_name = name;
ir_begin_procedure_body(proc);
defer (ir_end_procedure_body(proc));
// NOTE(bill): https://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx
// DLL_PROCESS_ATTACH == 1
@@ -8461,9 +8464,6 @@ void ir_gen_tree(irGen *s) {
ir_start_block(proc, done);
ir_emit_return(proc, v_one32);
ir_end_procedure_body(proc);
}
#endif
if (!(build_context.is_dll && !has_dll_main)) {
@@ -8517,6 +8517,7 @@ void ir_gen_tree(irGen *s) {
e->Procedure.link_name = name;
ir_begin_procedure_body(proc);
defer (ir_end_procedure_body(proc));
// NOTE(bill): https://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx
// DLL_PROCESS_ATTACH == 1
@@ -8539,7 +8540,6 @@ void ir_gen_tree(irGen *s) {
}
ir_emit_return(proc, v_zero32);
ir_end_procedure_body(proc);
}
#if 0 && defined(GB_SYSTEM_WINDOWS)
@@ -8607,6 +8607,7 @@ void ir_gen_tree(irGen *s) {
proc->inlining = ProcInlining_no_inline; // TODO(bill): is no_inline a good idea?
ir_begin_procedure_body(proc);
defer (ir_end_procedure_body(proc));
{
irValue **args = gb_alloc_array(a, irValue *, 1);
@@ -8643,23 +8644,8 @@ void ir_gen_tree(irGen *s) {
}
}
ir_end_procedure_body(proc);
}
for_array(type_info_map_index, info->type_info_map.entries) {
auto *entry = &info->type_info_map.entries[type_info_map_index];
Type *t = cast(Type *)entry->key.ptr;
t = default_type(t);
isize entry_index = entry->value;
gbString s = type_to_string(t);
GB_ASSERT(s[0] != 0);
// gb_printf_err("%s\n", s);
}
for_array(i, m->procs_to_generate) {
irValue *p = m->procs_to_generate[i];
ir_build_proc(p, p->Proc.parent);