Use __type_info_of internally

This commit is contained in:
gingerBill
2018-05-12 20:17:12 +01:00
parent 373a60b9ef
commit 324b7d65e7
4 changed files with 17 additions and 8 deletions
+10 -1
View File
@@ -244,9 +244,18 @@ __typeid_of :: proc "contextless" (ti: ^Type_Info) -> typeid {
start := uintptr(&__type_table[0]);
end := uintptr(ti);
id := (end-start)/size_of(Type_Info);
if uintptr(len(__type_table)) < id {
return nil;
}
return transmute(typeid)id;
}
__type_info_of :: proc "contextless" (id: typeid) -> ^Type_Info {
n := int(transmute(uintptr)id);
if n < 0 || n >= len(__type_table) {
n = 0;
}
return &__type_table[n];
}
typeid_base :: proc "contextless" (id: typeid) -> typeid {
ti := type_info_of(id);
+2 -4
View File
@@ -755,8 +755,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_string(fi.buf, "any{}");
} else {
data := rawptr(uintptr(v.data) + b.offsets[i]);
id := typeid_of(t);
fmt_arg(fi, any{data, id}, 'v');
fmt_arg(fi, any{data, typeid_of(t)}, 'v');
}
if hash do write_string(fi.buf, ",\n");
@@ -884,8 +883,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_string(fi.buf, "any{}");
} else {
data := uintptr(v.data) + info.offsets[i];
id := typeid_of(t);
fmt_arg(fi, any{rawptr(data), id}, 'v');
fmt_arg(fi, any{rawptr(data), typeid_of(t)}, 'v');
}
if hash do write_string(fi.buf, ",\n");
}