mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 02:40:05 +00:00
Merge functionality of #maybe with the standard 'union' functionality
This commit is contained in:
@@ -209,7 +209,7 @@ unmarshal_value :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) {
|
||||
variant := u.variants[0]
|
||||
v.id = variant.id
|
||||
ti = reflect.type_info_base(variant)
|
||||
if !(u.maybe && reflect.is_pointer(variant)) {
|
||||
if !reflect.is_pointer_internally(variant) {
|
||||
tag := any{rawptr(uintptr(v.data) + u.tag_offset), u.tag_type.id}
|
||||
assign_int(tag, 1)
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -135,7 +135,6 @@ Type_Info_Union :: struct {
|
||||
|
||||
custom_align: bool,
|
||||
no_nil: bool,
|
||||
maybe: bool,
|
||||
shared_nil: bool,
|
||||
}
|
||||
Type_Info_Enum :: struct {
|
||||
|
||||
@@ -3,7 +3,7 @@ package runtime
|
||||
import "core:intrinsics"
|
||||
|
||||
@builtin
|
||||
Maybe :: union($T: typeid) #maybe {T}
|
||||
Maybe :: union($T: typeid) {T}
|
||||
|
||||
|
||||
@builtin
|
||||
|
||||
Reference in New Issue
Block a user