This commit is contained in:
gingerBill
2018-05-12 17:39:04 +01:00
parent 56ff5496bc
commit 830f4f540f
8 changed files with 88 additions and 3 deletions
+7
View File
@@ -49,6 +49,7 @@ Type_Info_Complex :: struct {};
Type_Info_String :: struct {is_cstring: bool};
Type_Info_Boolean :: struct {};
Type_Info_Any :: struct {};
Type_Info_Type_Id :: struct {};
Type_Info_Pointer :: struct {
elem: ^Type_Info // nil -> rawptr
};
@@ -114,6 +115,7 @@ Type_Info :: struct {
Type_Info_String,
Type_Info_Boolean,
Type_Info_Any,
Type_Info_Type_Id,
Type_Info_Pointer,
Type_Info_Procedure,
Type_Info_Array,
@@ -237,6 +239,11 @@ type_info_base_without_enum :: proc(info: ^Type_Info) -> ^Type_Info {
return base;
}
type_info_from_typeid :: proc(t: typeid) -> ^Type_Info {
index := transmute(uintptr)t;
return &__type_table[index];
}
@(default_calling_convention = "c")
+14 -1
View File
@@ -150,6 +150,10 @@ fprint_type :: proc(fd: os.Handle, info: ^Type_Info) {
os.write(fd, buf[..]);
}
write_typeid :: proc(buf: ^String_Buffer, id: typeid) {
write_type(buf, type_info_from_typeid(id));
}
write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
if ti == nil {
write_string(buf, "nil");
@@ -194,6 +198,9 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
case Type_Info_Any:
write_string(buf, "any");
case Type_Info_Type_Id:
write_string(buf, "typeid");
case Type_Info_Pointer:
if info.elem == nil {
write_string(buf, "rawptr");
@@ -914,6 +921,10 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_string(fi.buf, " @ ");
fmt_pointer(fi, ptr, 'p');
}
case Type_Info_Type_Id:
id := (^typeid)(v.data)^;
write_typeid(fi.buf, id);
}
}
@@ -983,7 +994,9 @@ fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) {
case string: fmt_string(fi, a, verb);
case cstring: fmt_cstring(fi, a, verb);
case: fmt_value(fi, arg, verb);
case typeid: write_typeid(fi.buf, a);
case: fmt_value(fi, arg, verb);
}
}