Merge functionality of #maybe with the standard 'union' functionality

This commit is contained in:
gingerBill
2022-05-23 12:04:19 +01:00
parent d9f293b281
commit 3ec70c5517
11 changed files with 27 additions and 25 deletions
+1 -1
View File
@@ -654,7 +654,7 @@ union_variant_type_info :: proc(a: any) -> ^Type_Info {
}
type_info_union_is_pure_maybe :: proc(info: runtime.Type_Info_Union) -> bool {
return info.maybe && len(info.variants) == 1 && is_pointer(info.variants[0])
return len(info.variants) == 1 && is_pointer(info.variants[0])
}
union_variant_typeid :: proc(a: any) -> typeid {
+13 -3
View File
@@ -256,6 +256,17 @@ is_multi_pointer :: proc(info: ^Type_Info) -> bool {
_, ok := type_info_base(info).variant.(Type_Info_Multi_Pointer)
return ok
}
is_pointer_internally :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
#partial switch v in info.variant {
case Type_Info_Pointer, Type_Info_Multi_Pointer,
Type_Info_Procedure:
return true
case Type_Info_String:
return v.is_cstring
}
return false
}
is_procedure :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Procedure)
@@ -531,9 +542,8 @@ write_type_writer :: proc(w: io.Writer, ti: ^Type_Info, n_written: ^int = nil) -
case Type_Info_Union:
io.write_string(w, "union ", &n) or_return
if info.maybe {
io.write_string(w, "#maybe ", &n) or_return
}
if info.no_nil { io.write_string(w, "#no_nil ", &n) or_return }
if info.shared_nil { io.write_string(w, "#shared_nil ", &n) or_return }
if info.custom_align {
io.write_string(w, "#align ", &n) or_return
io.write_i64(w, i64(ti.align), 10, &n) or_return