diff --git a/base/runtime/core.odin b/base/runtime/core.odin index 1dadbbf6f39..3308f3ad7da 100644 --- a/base/runtime/core.odin +++ b/base/runtime/core.odin @@ -63,38 +63,44 @@ Type_Info_Struct_Soa_Kind :: enum u8 { // Variant Types Type_Info_Named :: struct { + using info: Type_Info, name: string, base: ^Type_Info, pkg: string, loc: ^Source_Code_Location, } -Type_Info_Integer :: struct {signed: bool, endianness: Platform_Endianness} -Type_Info_Rune :: struct {} -Type_Info_Float :: struct {endianness: Platform_Endianness} -Type_Info_Complex :: struct {} -Type_Info_Quaternion :: struct {} -Type_Info_String :: struct {is_cstring: bool} -Type_Info_Boolean :: struct {} -Type_Info_Any :: struct {} -Type_Info_Type_Id :: struct {} +Type_Info_Integer :: struct {using info: Type_Info, signed: bool, endianness: Platform_Endianness} +Type_Info_Rune :: struct {using info: Type_Info} +Type_Info_Float :: struct {using info: Type_Info, endianness: Platform_Endianness} +Type_Info_Complex :: struct {using info: Type_Info} +Type_Info_Quaternion :: struct {using info: Type_Info} +Type_Info_String :: struct {using info: Type_Info, is_cstring: bool} +Type_Info_Boolean :: struct {using info: Type_Info} +Type_Info_Any :: struct {using info: Type_Info} +Type_Info_Type_Id :: struct {using info: Type_Info} Type_Info_Pointer :: struct { + using info: Type_Info, elem: ^Type_Info, // nil -> rawptr } Type_Info_Multi_Pointer :: struct { + using info: Type_Info, elem: ^Type_Info, } Type_Info_Procedure :: struct { + using info: Type_Info, params: ^Type_Info, // Type_Info_Parameters results: ^Type_Info, // Type_Info_Parameters variadic: bool, convention: Calling_Convention, } Type_Info_Array :: struct { + using info: Type_Info, elem: ^Type_Info, elem_size: int, count: int, } Type_Info_Enumerated_Array :: struct { + using info: Type_Info, elem: ^Type_Info, index: ^Type_Info, elem_size: int, @@ -103,12 +109,21 @@ Type_Info_Enumerated_Array :: struct { max_value: Type_Info_Enum_Value, is_sparse: bool, } -Type_Info_Dynamic_Array :: struct {elem: ^Type_Info, elem_size: int} -Type_Info_Slice :: struct {elem: ^Type_Info, elem_size: int} +Type_Info_Dynamic_Array :: struct { + using info: Type_Info, + elem: ^Type_Info, + elem_size: int, +} +Type_Info_Slice :: struct { + using info: Type_Info, + elem: ^Type_Info, + elem_size: int, +} Type_Info_Parameters :: struct { // Only used for procedures parameters and results - types: []^Type_Info, - names: []string, + using info: Type_Info, + types: []^Type_Info, + names: []string, } Type_Info_Struct_Flags :: distinct bit_set[Type_Info_Struct_Flag; u8] @@ -120,6 +135,8 @@ Type_Info_Struct_Flag :: enum u8 { } Type_Info_Struct :: struct { + using info: Type_Info, + // Slice these with `field_count` types: [^]^Type_Info `fmt:"v,field_count"`, names: [^]string `fmt:"v,field_count"`, @@ -129,16 +146,20 @@ Type_Info_Struct :: struct { field_count: i32, - flags: Type_Info_Struct_Flags, + struct_flags: Type_Info_Struct_Flags, // These are only set iff this structure is an SOA structure soa_kind: Type_Info_Struct_Soa_Kind, + _: [2]u8, soa_len: i32, + _: [4]u8, soa_base_type: ^Type_Info, equal: Equal_Proc, // set only when the struct has .Comparable set but does not have .Simple_Compare set } Type_Info_Union :: struct { + using info: Type_Info, + variants: []^Type_Info, tag_offset: uintptr, tag_type: ^Type_Info, @@ -150,27 +171,32 @@ Type_Info_Union :: struct { shared_nil: bool, } Type_Info_Enum :: struct { + using info: Type_Info, base: ^Type_Info, names: []string, values: []Type_Info_Enum_Value, } Type_Info_Map :: struct { + using info: Type_Info, key: ^Type_Info, value: ^Type_Info, map_info: ^Map_Info, } Type_Info_Bit_Set :: struct { + using info: Type_Info, elem: ^Type_Info, underlying: ^Type_Info, // Possibly nil lower: i64, upper: i64, } Type_Info_Simd_Vector :: struct { + using info: Type_Info, elem: ^Type_Info, elem_size: int, count: int, } Type_Info_Matrix :: struct { + using info: Type_Info, elem: ^Type_Info, elem_size: int, elem_stride: int, // elem_stride >= row_count @@ -183,9 +209,11 @@ Type_Info_Matrix :: struct { }, } Type_Info_Soa_Pointer :: struct { + using info: Type_Info, elem: ^Type_Info, } Type_Info_Bit_Field :: struct { + using info: Type_Info, backing_type: ^Type_Info, names: [^]string `fmt:"v,field_count"`, types: [^]^Type_Info `fmt:"v,field_count"`, @@ -199,7 +227,7 @@ Type_Info_Flag :: enum u8 { Comparable = 0, Simple_Compare = 1, } -Type_Info_Flags :: distinct bit_set[Type_Info_Flag; u32] +Type_Info_Flags :: distinct bit_set[Type_Info_Flag; u64] Type_Info :: struct { size: int, @@ -208,33 +236,33 @@ Type_Info :: struct { id: typeid, variant: union { - Type_Info_Named, - Type_Info_Integer, - Type_Info_Rune, - Type_Info_Float, - Type_Info_Complex, - Type_Info_Quaternion, - Type_Info_String, - Type_Info_Boolean, - Type_Info_Any, - Type_Info_Type_Id, - Type_Info_Pointer, - Type_Info_Multi_Pointer, - Type_Info_Procedure, - Type_Info_Array, - Type_Info_Enumerated_Array, - Type_Info_Dynamic_Array, - Type_Info_Slice, - Type_Info_Parameters, - Type_Info_Struct, - Type_Info_Union, - Type_Info_Enum, - Type_Info_Map, - Type_Info_Bit_Set, - Type_Info_Simd_Vector, - Type_Info_Matrix, - Type_Info_Soa_Pointer, - Type_Info_Bit_Field, + ^Type_Info_Named, + ^Type_Info_Integer, + ^Type_Info_Rune, + ^Type_Info_Float, + ^Type_Info_Complex, + ^Type_Info_Quaternion, + ^Type_Info_String, + ^Type_Info_Boolean, + ^Type_Info_Any, + ^Type_Info_Type_Id, + ^Type_Info_Pointer, + ^Type_Info_Multi_Pointer, + ^Type_Info_Procedure, + ^Type_Info_Array, + ^Type_Info_Enumerated_Array, + ^Type_Info_Dynamic_Array, + ^Type_Info_Slice, + ^Type_Info_Parameters, + ^Type_Info_Struct, + ^Type_Info_Union, + ^Type_Info_Enum, + ^Type_Info_Map, + ^Type_Info_Bit_Set, + ^Type_Info_Simd_Vector, + ^Type_Info_Matrix, + ^Type_Info_Soa_Pointer, + ^Type_Info_Bit_Field, }, } @@ -625,7 +653,7 @@ type_info_base :: proc "contextless" (info: ^Type_Info) -> ^Type_Info { base := info loop: for { #partial switch i in base.variant { - case Type_Info_Named: base = i.base + case ^Type_Info_Named: base = i.base case: break loop } } @@ -641,9 +669,9 @@ type_info_core :: proc "contextless" (info: ^Type_Info) -> ^Type_Info { base := info loop: for { #partial switch i in base.variant { - case Type_Info_Named: base = i.base - case Type_Info_Enum: base = i.base - case Type_Info_Bit_Field: base = i.backing_type + case ^Type_Info_Named: base = i.base + case ^Type_Info_Enum: base = i.base + case ^Type_Info_Bit_Field: base = i.backing_type case: break loop } } diff --git a/base/runtime/core_builtin_soa.odin b/base/runtime/core_builtin_soa.odin index ff27a4559f0..714f87f5888 100644 --- a/base/runtime/core_builtin_soa.odin +++ b/base/runtime/core_builtin_soa.odin @@ -91,13 +91,13 @@ make_soa_aligned :: proc($T: typeid/#soa[]$E, #any_int length, alignment: int, a ti := type_info_of(typeid_of(T)) ti = type_info_base(ti) - si := &ti.variant.(Type_Info_Struct) + si := ti.variant.(^Type_Info_Struct) field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E)) total_size := 0 for i in 0.. 0 && cap(array)-len(array) > 0 { ti := type_info_of(T) ti = type_info_base(ti) - si := &ti.variant.(Type_Info_Struct) + si := ti.variant.(^Type_Info_Struct) field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E)) data := (^rawptr)(array)^ @@ -325,7 +324,7 @@ _append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, zero_memory: bool, #no_broa max_align :: align_of(E) for i in 0.. 0 && arg_len > 0 { ti := type_info_of(typeid_of(T)) ti = type_info_base(ti) - si := &ti.variant.(Type_Info_Struct) + si := ti.variant.(^Type_Info_Struct) field_count := uintptr(len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E)) data := (^rawptr)(array)^ @@ -386,7 +385,7 @@ _append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, zero_memory: bool, #no_bro max_align :: align_of(E) for i in 0.. 0 { print_string(", ") } @@ -336,7 +336,7 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { print_string(" -> ") print_type(info.results) } - case Type_Info_Parameters: + case ^Type_Info_Parameters: count := len(info.names) if count != 1 { print_byte('(') } for name, i in info.names { @@ -352,13 +352,13 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { } if count != 1 { print_string(")") } - case Type_Info_Array: + case ^Type_Info_Array: print_byte('[') print_u64(u64(info.count)) print_byte(']') print_type(info.elem) - case Type_Info_Enumerated_Array: + case ^Type_Info_Enumerated_Array: if info.is_sparse { print_string("#sparse") } @@ -368,20 +368,20 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { print_type(info.elem) - case Type_Info_Dynamic_Array: + case ^Type_Info_Dynamic_Array: print_string("[dynamic]") print_type(info.elem) - case Type_Info_Slice: + case ^Type_Info_Slice: print_string("[]") print_type(info.elem) - case Type_Info_Map: + case ^Type_Info_Map: print_string("map[") print_type(info.key) print_byte(']') print_type(info.value) - case Type_Info_Struct: + case ^Type_Info_Struct: switch info.soa_kind { case .None: // Ignore case .Fixed: @@ -401,10 +401,10 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { } print_string("struct ") - if .packed in info.flags { print_string("#packed ") } - if .raw_union in info.flags { print_string("#raw_union ") } - if .no_copy in info.flags { print_string("#no_copy ") } - if .align in info.flags { + if .packed in info.struct_flags { print_string("#packed ") } + if .raw_union in info.struct_flags { print_string("#raw_union ") } + if .no_copy in info.struct_flags { print_string("#no_copy ") } + if .align in info.struct_flags { print_string("#align(") print_u64(u64(ti.align)) print_string(") ") @@ -418,7 +418,7 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { } print_byte('}') - case Type_Info_Union: + case ^Type_Info_Union: print_string("union ") if info.custom_align { print_string("#align(") @@ -435,7 +435,7 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { } print_string("}") - case Type_Info_Enum: + case ^Type_Info_Enum: print_string("enum ") print_type(info.base) print_string(" {") @@ -445,13 +445,13 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { } print_string("}") - case Type_Info_Bit_Set: + case ^Type_Info_Bit_Set: print_string("bit_set[") #partial switch elem in type_info_base(info.elem).variant { - case Type_Info_Enum: + case ^Type_Info_Enum: print_type(info.elem) - case Type_Info_Rune: + case ^Type_Info_Rune: print_encoded_rune(rune(info.lower)) print_string("..") print_encoded_rune(rune(info.upper)) @@ -466,7 +466,7 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { } print_byte(']') - case Type_Info_Bit_Field: + case ^Type_Info_Bit_Field: print_string("bit_field ") print_type(info.backing_type) print_string(" {") @@ -481,13 +481,13 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) { print_byte('}') - case Type_Info_Simd_Vector: + case ^Type_Info_Simd_Vector: print_string("#simd[") print_u64(u64(info.count)) print_byte(']') print_type(info.elem) - case Type_Info_Matrix: + case ^Type_Info_Matrix: print_string("matrix[") print_u64(u64(info.row_count)) print_string(", ") diff --git a/core/encoding/cbor/marshal.odin b/core/encoding/cbor/marshal.odin index b23087c90bb..abf1fd9e1a8 100644 --- a/core/encoding/cbor/marshal.odin +++ b/core/encoding/cbor/marshal.odin @@ -104,16 +104,16 @@ marshal_into_encoder :: proc(e: Encoder, v: any) -> (err: Marshal_Error) { _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (err: Marshal_Error) { a := any{v.data, ti.id} #partial switch info in ti.variant { - case runtime.Type_Info_Named, runtime.Type_Info_Enum, runtime.Type_Info_Bit_Field: + case ^runtime.Type_Info_Named, ^runtime.Type_Info_Enum, ^runtime.Type_Info_Bit_Field: unreachable() - case runtime.Type_Info_Pointer: + case ^runtime.Type_Info_Pointer: switch vv in v { case Undefined: return _encode_undefined(e.writer) case Nil: return _encode_nil(e.writer) } - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: switch vv in v { case Simple: return err_conv(_encode_simple(e.writer, vv)) case Negative_U8: return _encode_u8(e.writer, u8(vv), .Negative) @@ -159,11 +159,11 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er case u128be: return err_conv(_encode_uint(e, _u128_to_u64(u128(i)) or_return)) } - case runtime.Type_Info_Rune: + case ^runtime.Type_Info_Rune: buf, w := utf8.encode_rune(a.(rune)) return err_conv(_encode_text(e, string(buf[:w]))) - case runtime.Type_Info_Float: + case ^runtime.Type_Info_Float: switch f in a { case f16: return _encode_f16(e.writer, f) case f32: return _encode_f32(e, f) @@ -178,7 +178,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er case f64be: return _encode_f64(e, f64(f)) } - case runtime.Type_Info_Complex: + case ^runtime.Type_Info_Complex: switch z in a { case complex32: arr: [2]Value = {real(z), imag(z)} @@ -191,7 +191,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er return err_conv(_encode_array(e, arr[:])) } - case runtime.Type_Info_Quaternion: + case ^runtime.Type_Info_Quaternion: switch q in a { case quaternion64: arr: [4]Value = {imag(q), jmag(q), kmag(q), real(q)} @@ -204,13 +204,13 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er return err_conv(_encode_array(e, arr[:])) } - case runtime.Type_Info_String: + case ^runtime.Type_Info_String: switch s in a { case string: return err_conv(_encode_text(e, s)) case cstring: return err_conv(_encode_text(e, string(s))) } - case runtime.Type_Info_Boolean: + case ^runtime.Type_Info_Boolean: switch b in a { case bool: return _encode_bool(e.writer, b) case b8: return _encode_bool(e.writer, bool(b)) @@ -219,7 +219,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er case b64: return _encode_bool(e.writer, bool(b)) } - case runtime.Type_Info_Array: + case ^runtime.Type_Info_Array: if info.elem.id == byte { raw := ([^]byte)(v.data) return err_conv(_encode_bytes(e, raw[:info.count])) @@ -242,8 +242,8 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er } return - case runtime.Type_Info_Enumerated_Array: - // index := runtime.type_info_base(info.index).variant.(runtime.Type_Info_Enum) + case ^runtime.Type_Info_Enumerated_Array: + // index := runtime.type_info_base(info.index).variant.(^runtime.Type_Info_Enum) err_conv(_encode_u64(e, u64(info.count), .Array)) or_return if impl, ok := _tag_implementations_type[info.elem.id]; ok { @@ -261,7 +261,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er } return - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: if info.elem.id == byte { raw := (^[dynamic]byte)(v.data) return err_conv(_encode_bytes(e, raw[:])) @@ -285,7 +285,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er } return - case runtime.Type_Info_Slice: + case ^runtime.Type_Info_Slice: if info.elem.id == byte { raw := (^[]byte)(v.data) return err_conv(_encode_bytes(e, raw^)) @@ -309,7 +309,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er } return - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: m := (^mem.Raw_Map)(v.data) err_conv(_encode_u64(e, u64(runtime.map_len(m^)), .Map)) or_return if m != nil { @@ -468,12 +468,12 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er } } - case runtime.Type_Info_Struct: + case ^runtime.Type_Info_Struct: switch vv in v { case Tag: return err_conv(_encode_tag(e, vv)) } - field_name :: #force_inline proc(info: runtime.Type_Info_Struct, i: int) -> string { + field_name :: #force_inline proc(info: ^runtime.Type_Info_Struct, i: int) -> string { if cbor_name := string(reflect.struct_tag_get(reflect.Struct_Tag(info.tags[i]), "cbor")); cbor_name != "" { return cbor_name } else { @@ -481,7 +481,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er } } - marshal_entry :: #force_inline proc(e: Encoder, info: runtime.Type_Info_Struct, v: any, i: int) -> Marshal_Error { + marshal_entry :: #force_inline proc(e: Encoder, info: ^runtime.Type_Info_Struct, v: any, i: int) -> Marshal_Error { id := info.types[i].id data := rawptr(uintptr(v.data) + info.offsets[i]) field_any := any{data, id} @@ -554,7 +554,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er } return - case runtime.Type_Info_Union: + case ^runtime.Type_Info_Union: switch vv in v { case Value: return err_conv(encode(e, vv)) } @@ -577,7 +577,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er vti := reflect.union_variant_type_info(v) #partial switch vt in vti.variant { - case reflect.Type_Info_Named: + case ^reflect.Type_Info_Named: err_conv(_encode_text(e, vt.name)) or_return case: builder := strings.builder_make(e.temp_allocator) or_return @@ -588,7 +588,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er return marshal_into(e, any{v.data, vti.id}) - case runtime.Type_Info_Bit_Set: + case ^runtime.Type_Info_Bit_Set: // Store bit_set as big endian just like the protocol. do_byte_swap := !reflect.bit_set_is_big_endian(v) switch ti.size * 8 { @@ -612,7 +612,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er case: panic("unknown bit_size size") } - case runtime.Type_Info_Matrix: + case ^runtime.Type_Info_Matrix: count := info.column_count * info.elem_stride err_conv(_encode_u64(e, u64(count), .Array)) or_return @@ -631,7 +631,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er } return - case runtime.Type_Info_Simd_Vector: + case ^runtime.Type_Info_Simd_Vector: err_conv(_encode_u64(e, u64(info.count), .Array)) or_return if impl, ok := _tag_implementations_type[info.elem.id]; ok { diff --git a/core/encoding/cbor/tags.odin b/core/encoding/cbor/tags.odin index 17420af4691..2c38762b9fe 100644 --- a/core/encoding/cbor/tags.odin +++ b/core/encoding/cbor/tags.odin @@ -264,17 +264,17 @@ tag_cbor_marshal :: proc(_: ^Tag_Implementation, e: Encoder, v: any) -> Marshal_ _encode_u8(e.writer, TAG_CBOR_NR, .Tag) or_return ti := runtime.type_info_base(type_info_of(v.id)) #partial switch t in ti.variant { - case runtime.Type_Info_String: + case ^runtime.Type_Info_String: return marshal_into(e, v) - case runtime.Type_Info_Array: + case ^runtime.Type_Info_Array: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return .Bad_Tag_Value } return marshal_into(e, v) - case runtime.Type_Info_Slice: + case ^runtime.Type_Info_Slice: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return .Bad_Tag_Value } return marshal_into(e, v) - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return .Bad_Tag_Value } return marshal_into(e, v) @@ -297,7 +297,7 @@ tag_base64_unmarshal :: proc(_: ^Tag_Implementation, d: Decoder, _: Tag_Number, defer delete(bytes, context.temp_allocator) #partial switch t in ti.variant { - case reflect.Type_Info_String: + case ^reflect.Type_Info_String: if t.is_cstring { length := base64.decoded_len(bytes) @@ -313,7 +313,7 @@ tag_base64_unmarshal :: proc(_: ^Tag_Implementation, d: Decoder, _: Tag_Number, return - case reflect.Type_Info_Slice: + case ^reflect.Type_Info_Slice: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return _unsupported(v, hdr) } @@ -322,7 +322,7 @@ tag_base64_unmarshal :: proc(_: ^Tag_Implementation, d: Decoder, _: Tag_Number, raw^ = base64.decode(bytes) or_return return - case reflect.Type_Info_Dynamic_Array: + case ^reflect.Type_Info_Dynamic_Array: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return _unsupported(v, hdr) } @@ -336,7 +336,7 @@ tag_base64_unmarshal :: proc(_: ^Tag_Implementation, d: Decoder, _: Tag_Number, raw.allocator = context.allocator return - case reflect.Type_Info_Array: + case ^reflect.Type_Info_Array: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return _unsupported(v, hdr) } @@ -366,7 +366,7 @@ tag_base64_marshal :: proc(_: ^Tag_Implementation, e: Encoder, v: any) -> Marsha case [dynamic]byte: bytes = val[:] case: #partial switch t in ti.variant { - case runtime.Type_Info_Array: + case ^runtime.Type_Info_Array: if t.elem.id != byte { return .Bad_Tag_Value } bytes = ([^]byte)(v.data)[:t.count] case: diff --git a/core/encoding/cbor/unmarshal.odin b/core/encoding/cbor/unmarshal.odin index 365ac5d6f0a..3736707a9eb 100644 --- a/core/encoding/cbor/unmarshal.odin +++ b/core/encoding/cbor/unmarshal.odin @@ -83,7 +83,7 @@ _unmarshal_any_ptr :: proc(d: Decoder, v: any, hdr: Maybe(Header) = nil, allocat return .Non_Pointer_Parameter } - data := any{(^rawptr)(v.data)^, ti.variant.(reflect.Type_Info_Pointer).elem.id} + data := any{(^rawptr)(v.data)^, ti.variant.(^reflect.Type_Info_Pointer).elem.id} return _unmarshal_value(d, data, hdr.? or_else (_decode_header(d.reader) or_return), allocator, temp_allocator, loc) } @@ -93,7 +93,7 @@ _unmarshal_value :: proc(d: Decoder, v: any, hdr: Header, allocator := context.a r := d.reader // If it's a union with only one variant, then treat it as that variant - if u, ok := ti.variant.(reflect.Type_Info_Union); ok && len(u.variants) == 1 { + if u, ok := ti.variant.(^reflect.Type_Info_Union); ok && len(u.variants) == 1 { #partial switch hdr { case .Nil, .Undefined, nil: // no-op. case: @@ -334,7 +334,7 @@ _unmarshal_value :: proc(d: Decoder, v: any, hdr: Header, allocator := context.a _unmarshal_bytes :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header, add: Add, allocator := context.allocator, loc := #caller_location) -> (err: Unmarshal_Error) { #partial switch t in ti.variant { - case reflect.Type_Info_String: + case ^reflect.Type_Info_String: bytes := err_conv(_decode_bytes(d, add, allocator=allocator, loc=loc)) or_return if t.is_cstring { @@ -349,7 +349,7 @@ _unmarshal_bytes :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header return - case reflect.Type_Info_Slice: + case ^reflect.Type_Info_Slice: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return _unsupported(v, hdr) } @@ -359,7 +359,7 @@ _unmarshal_bytes :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header raw^ = transmute(mem.Raw_Slice)bytes return - case reflect.Type_Info_Dynamic_Array: + case ^reflect.Type_Info_Dynamic_Array: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return _unsupported(v, hdr) } @@ -372,7 +372,7 @@ _unmarshal_bytes :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header raw.allocator = allocator return - case reflect.Type_Info_Array: + case ^reflect.Type_Info_Array: elem_base := reflect.type_info_base(t.elem) if elem_base.id != byte { return _unsupported(v, hdr) } @@ -394,7 +394,7 @@ _unmarshal_bytes :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header _unmarshal_string :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header, add: Add, allocator := context.allocator, temp_allocator := context.temp_allocator, loc := #caller_location) -> (err: Unmarshal_Error) { #partial switch t in ti.variant { - case reflect.Type_Info_String: + case ^reflect.Type_Info_String: text := err_conv(_decode_text(d, add, allocator, loc)) or_return if t.is_cstring { @@ -409,7 +409,7 @@ _unmarshal_string :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Heade return // Enum by its variant name. - case reflect.Type_Info_Enum: + case ^reflect.Type_Info_Enum: text := err_conv(_decode_text(d, add, allocator=temp_allocator, loc=loc)) or_return defer delete(text, temp_allocator, loc) @@ -420,7 +420,7 @@ _unmarshal_string :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Heade } } - case reflect.Type_Info_Rune: + case ^reflect.Type_Info_Rune: text := err_conv(_decode_text(d, add, allocator=temp_allocator, loc=loc)) or_return defer delete(text, temp_allocator, loc) @@ -487,7 +487,7 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header } #partial switch t in ti.variant { - case reflect.Type_Info_Slice: + case ^reflect.Type_Info_Slice: length, scap := err_conv(_decode_len_container(d, add)) or_return data := mem.alloc_bytes_non_zeroed(t.elem.size * scap, t.elem.align, allocator=allocator, loc=loc) or_return @@ -507,7 +507,7 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header raw.len = da.len return - case reflect.Type_Info_Dynamic_Array: + case ^reflect.Type_Info_Dynamic_Array: length, scap := err_conv(_decode_len_container(d, add)) or_return data := mem.alloc_bytes_non_zeroed(t.elem.size * scap, t.elem.align, loc=loc) or_return @@ -527,7 +527,7 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header } return - case reflect.Type_Info_Array: + case ^reflect.Type_Info_Array: length, _ := err_conv(_decode_len_container(d, add)) or_return if length > t.count { return _unsupported(v, hdr) @@ -539,7 +539,7 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header if out_of_space { return _unsupported(v, hdr) } return - case reflect.Type_Info_Enumerated_Array: + case ^reflect.Type_Info_Enumerated_Array: length, _ := err_conv(_decode_len_container(d, add)) or_return if length > t.count { return _unsupported(v, hdr) @@ -551,7 +551,7 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header if out_of_space { return _unsupported(v, hdr) } return - case reflect.Type_Info_Complex: + case ^reflect.Type_Info_Complex: length, _ := err_conv(_decode_len_container(d, add)) or_return if length > 2 { return _unsupported(v, hdr) @@ -571,7 +571,7 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header if out_of_space { return _unsupported(v, hdr) } return - case reflect.Type_Info_Quaternion: + case ^reflect.Type_Info_Quaternion: length, _ := err_conv(_decode_len_container(d, add)) or_return if length > 4 { return _unsupported(v, hdr) @@ -591,7 +591,7 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header if out_of_space { return _unsupported(v, hdr) } return - case reflect.Type_Info_Matrix: + case ^reflect.Type_Info_Matrix: count := t.column_count * t.elem_stride length, _ := err_conv(_decode_len_container(d, add)) or_return if length > count { @@ -604,7 +604,7 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header if out_of_space { return _unsupported(v, hdr) } return - case reflect.Type_Info_Simd_Vector: + case ^reflect.Type_Info_Simd_Vector: length, _ := err_conv(_decode_len_container(d, add)) or_return if length > t.count { return _unsupported(v, hdr) @@ -650,8 +650,8 @@ _unmarshal_map :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header, } #partial switch t in ti.variant { - case reflect.Type_Info_Struct: - if .raw_union in t.flags { + case ^reflect.Type_Info_Struct: + if .raw_union in t.struct_flags { return _unsupported(v, hdr) } @@ -720,7 +720,7 @@ _unmarshal_map :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header, return - case reflect.Type_Info_Map: + case ^reflect.Type_Info_Map: raw_map := (^mem.Raw_Map)(v.data) if raw_map.allocator.procedure == nil { raw_map.allocator = context.allocator @@ -782,7 +782,7 @@ _unmarshal_map :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header, _unmarshal_union :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header, loc := #caller_location) -> (err: Unmarshal_Error) { r := d.reader #partial switch t in ti.variant { - case reflect.Type_Info_Union: + case ^reflect.Type_Info_Union: idhdr: Header target_name: string { @@ -814,7 +814,7 @@ _unmarshal_union :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header } #partial switch vti in variant.variant { - case reflect.Type_Info_Named: + case ^reflect.Type_Info_Named: if vti.name == target_name { reflect.set_union_variant_raw_tag(v, tag) return _unmarshal_value(d, any{v.data, variant.id}, _decode_header(r) or_return, loc=loc) @@ -881,7 +881,7 @@ _assign_int :: proc(val: any, i: $T) -> bool { case uintptr: dst = uintptr(i) case: ti := type_info_of(v.id) - if _, ok := ti.variant.(runtime.Type_Info_Bit_Set); ok { + if _, ok := ti.variant.(^runtime.Type_Info_Bit_Set); ok { do_byte_swap := !reflect.bit_set_is_big_endian(v) switch ti.size * 8 { case 0: // no-op. diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index ebb9a639ce6..9d6d6a8d24e 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -95,10 +95,10 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: a := any{v.data, ti.id} switch info in ti.variant { - case runtime.Type_Info_Named: + case ^runtime.Type_Info_Named: unreachable() - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: buf: [40]byte u := cast_any_int_to_u128(a) @@ -120,13 +120,13 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: io.write_string(w, s) or_return - case runtime.Type_Info_Rune: + case ^runtime.Type_Info_Rune: r := a.(rune) io.write_byte(w, '"') or_return io.write_escaped_rune(w, r, '"', true) or_return io.write_byte(w, '"') or_return - case runtime.Type_Info_Float: + case ^runtime.Type_Info_Float: switch f in a { case f16: io.write_f16(w, f) or_return case f32: io.write_f32(w, f) or_return @@ -134,7 +134,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: case: return .Unsupported_Type } - case runtime.Type_Info_Complex: + case ^runtime.Type_Info_Complex: r, i: f64 switch z in a { case complex32: r, i = f64(real(z)), f64(imag(z)) @@ -149,16 +149,16 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: io.write_f64(w, i) or_return io.write_byte(w, ']') or_return - case runtime.Type_Info_Quaternion: + case ^runtime.Type_Info_Quaternion: return .Unsupported_Type - case runtime.Type_Info_String: + case ^runtime.Type_Info_String: switch s in a { case string: io.write_quoted_string(w, s, '"', nil, true) or_return case cstring: io.write_quoted_string(w, string(s), '"', nil, true) or_return } - case runtime.Type_Info_Boolean: + case ^runtime.Type_Info_Boolean: val: bool switch b in a { case bool: val = bool(b) @@ -169,37 +169,37 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: } io.write_string(w, val ? "true" : "false") or_return - case runtime.Type_Info_Any: + case ^runtime.Type_Info_Any: return .Unsupported_Type - case runtime.Type_Info_Type_Id: + case ^runtime.Type_Info_Type_Id: return .Unsupported_Type - case runtime.Type_Info_Pointer: + case ^runtime.Type_Info_Pointer: return .Unsupported_Type - case runtime.Type_Info_Multi_Pointer: + case ^runtime.Type_Info_Multi_Pointer: return .Unsupported_Type - case runtime.Type_Info_Soa_Pointer: + case ^runtime.Type_Info_Soa_Pointer: return .Unsupported_Type - case runtime.Type_Info_Procedure: + case ^runtime.Type_Info_Procedure: return .Unsupported_Type - case runtime.Type_Info_Parameters: + case ^runtime.Type_Info_Parameters: return .Unsupported_Type - case runtime.Type_Info_Simd_Vector: + case ^runtime.Type_Info_Simd_Vector: return .Unsupported_Type - case runtime.Type_Info_Matrix: + case ^runtime.Type_Info_Matrix: return .Unsupported_Type - case runtime.Type_Info_Bit_Field: + case ^runtime.Type_Info_Bit_Field: return .Unsupported_Type - case runtime.Type_Info_Array: + case ^runtime.Type_Info_Array: opt_write_start(w, opt, '[') or_return for i in 0.. (err: } opt_write_end(w, opt, ']') or_return - case runtime.Type_Info_Enumerated_Array: + case ^runtime.Type_Info_Enumerated_Array: index_type := reflect.type_info_base(info.index) - enum_type := index_type.variant.(reflect.Type_Info_Enum) + enum_type := index_type.variant.(^reflect.Type_Info_Enum) opt_write_start(w, opt, '{') or_return for i in 0.. (err: } opt_write_end(w, opt, '}') or_return - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: opt_write_start(w, opt, '[') or_return array := cast(^mem.Raw_Dynamic_Array)v.data for i in 0.. (err: } opt_write_end(w, opt, ']') or_return - case runtime.Type_Info_Slice: + case ^runtime.Type_Info_Slice: opt_write_start(w, opt, '[') or_return slice := cast(^mem.Raw_Slice)v.data for i in 0.. (err: } opt_write_end(w, opt, ']') or_return - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: m := (^mem.Raw_Map)(v.data) opt_write_start(w, opt, '{') or_return @@ -277,13 +277,13 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: name: string #partial switch info in kti.variant { - case runtime.Type_Info_String: + case ^runtime.Type_Info_String: switch s in ka { case string: name = s case cstring: name = string(s) } opt_write_key(w, opt, name) or_return - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: buf: [40]byte u := cast_any_int_to_u128(ka) name = strconv.write_bits_128(buf[:], u, 10, info.signed, 8*kti.size, "0123456789", nil) @@ -318,7 +318,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: ka := any{kv.data, kti.id} #partial switch info in kti.variant { - case runtime.Type_Info_String: + case ^runtime.Type_Info_String: switch s in ka { case string: name = s case cstring: name = string(s) @@ -343,7 +343,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: opt_write_end(w, opt, '}') or_return - case runtime.Type_Info_Struct: + case ^runtime.Type_Info_Struct: is_omitempty :: proc(v: any) -> bool { v := v if v == nil { @@ -351,30 +351,30 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: } ti := runtime.type_info_core(type_info_of(v.id)) #partial switch info in ti.variant { - case runtime.Type_Info_String: + case ^runtime.Type_Info_String: switch x in v { case string: return x == "" case cstring: return x == nil || x == "" } - case runtime.Type_Info_Any: + case ^runtime.Type_Info_Any: return v.(any) == nil - case runtime.Type_Info_Type_Id: + case ^runtime.Type_Info_Type_Id: return v.(typeid) == nil - case runtime.Type_Info_Pointer, - runtime.Type_Info_Multi_Pointer, - runtime.Type_Info_Procedure: + case ^runtime.Type_Info_Pointer, + ^runtime.Type_Info_Multi_Pointer, + ^runtime.Type_Info_Procedure: return (^rawptr)(v.data)^ == nil - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: return (^runtime.Raw_Dynamic_Array)(v.data).len == 0 - case runtime.Type_Info_Slice: + case ^runtime.Type_Info_Slice: return (^runtime.Raw_Slice)(v.data).len == 0 - case runtime.Type_Info_Union, - runtime.Type_Info_Bit_Set, - runtime.Type_Info_Soa_Pointer: + case ^runtime.Type_Info_Union, + ^runtime.Type_Info_Bit_Set, + ^runtime.Type_Info_Soa_Pointer: return reflect.is_nil(v) - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: return (^runtime.Raw_Map)(v.data).len == 0 } return false @@ -382,7 +382,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: marshal_struct_fields :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: Marshal_Error) { ti := runtime.type_info_base(type_info_of(v.id)) - info := ti.variant.(runtime.Type_Info_Struct) + info := ti.variant.(^runtime.Type_Info_Struct) first_iteration := true for name, i in info.names[:info.field_count] { omitempty := false @@ -432,7 +432,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: marshal_struct_fields(w, v, opt) or_return opt_write_end(w, opt, '}') or_return - case runtime.Type_Info_Union: + case ^runtime.Type_Info_Union: if len(info.variants) == 0 || v.data == nil { io.write_string(w, "null") or_return return nil @@ -464,7 +464,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: id := info.variants[tag].id return marshal_to_writer(w, any{v.data, id}, opt) - case runtime.Type_Info_Enum: + case ^runtime.Type_Info_Enum: if !opt.use_enum_names || len(info.names) == 0 { return marshal_to_writer(w, any{v.data, info.base.id}, opt) } else { @@ -476,14 +476,14 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: } } - case runtime.Type_Info_Bit_Set: + case ^runtime.Type_Info_Bit_Set: is_bit_set_different_endian_to_platform :: proc(ti: ^runtime.Type_Info) -> bool { if ti == nil { return false } t := runtime.type_info_base(ti) #partial switch info in t.variant { - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: switch info.endianness { case .Platform: return false case .Little: return ODIN_ENDIAN != .Little diff --git a/core/encoding/json/unmarshal.odin b/core/encoding/json/unmarshal.odin index b9ed1476f2c..6968e548fef 100644 --- a/core/encoding/json/unmarshal.odin +++ b/core/encoding/json/unmarshal.odin @@ -43,7 +43,7 @@ unmarshal_any :: proc(data: []byte, v: any, spec := DEFAULT_SPECIFICATION, alloc } p := make_parser(data, spec, PARSE_INTEGERS, allocator) - data := any{(^rawptr)(v.data)^, ti.variant.(reflect.Type_Info_Pointer).elem.id} + data := any{(^rawptr)(v.data)^, ti.variant.(^reflect.Type_Info_Pointer).elem.id} if v.data == nil { return .Invalid_Parameter } @@ -123,7 +123,7 @@ assign_int :: proc(val: any, i: $T) -> bool { } t := runtime.type_info_base(ti) #partial switch info in t.variant { - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: switch info.endianness { case .Platform: return false case .Little: return ODIN_ENDIAN != .Little @@ -134,7 +134,7 @@ assign_int :: proc(val: any, i: $T) -> bool { } ti := type_info_of(v.id) - if info, ok := ti.variant.(runtime.Type_Info_Bit_Set); ok { + if info, ok := ti.variant.(^runtime.Type_Info_Bit_Set); ok { do_byte_swap := is_bit_set_different_endian_to_platform(info.underlying) switch ti.size * 8 { case 0: // no-op. @@ -218,7 +218,7 @@ unmarshal_string_token :: proc(p: ^Parser, val: any, str: string, ti: ^reflect.T } #partial switch variant in ti.variant { - case reflect.Type_Info_Enum: + case ^reflect.Type_Info_Enum: for name, i in variant.names { if name == str { assign_int(val, variant.values[i]) @@ -228,7 +228,7 @@ unmarshal_string_token :: proc(p: ^Parser, val: any, str: string, ti: ^reflect.T // TODO(bill): should this be an error or not? return true, nil - case reflect.Type_Info_Integer: + case ^reflect.Type_Info_Integer: i, pok := strconv.parse_i128(str) if !pok { return false, nil @@ -239,7 +239,7 @@ unmarshal_string_token :: proc(p: ^Parser, val: any, str: string, ti: ^reflect.T if assign_float(val, i) { return true, nil } - case reflect.Type_Info_Float: + case ^reflect.Type_Info_Float: f, pok := strconv.parse_f64(str) if !pok { return false, nil @@ -263,7 +263,7 @@ unmarshal_value :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) { v := v ti := reflect.type_info_base(type_info_of(v.id)) - if u, ok := ti.variant.(reflect.Type_Info_Union); ok && token.kind != .Null { + if u, ok := ti.variant.(^reflect.Type_Info_Union); ok && token.kind != .Null { // NOTE: If it's a union with only one variant, then treat it as that variant if len(u.variants) == 1 { variant := u.variants[0] @@ -432,8 +432,8 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm ti := reflect.type_info_base(type_info_of(v.id)) #partial switch t in ti.variant { - case reflect.Type_Info_Struct: - if .raw_union in t.flags { + case ^reflect.Type_Info_Struct: + if .raw_union in t.struct_flags { return UNSUPPORTED_TYPE } @@ -542,7 +542,7 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm } } - case reflect.Type_Info_Map: + case ^reflect.Type_Info_Map: if !reflect.is_string(t.key) && !reflect.is_integer(t.key) { return UNSUPPORTED_TYPE } @@ -570,14 +570,14 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm key_ptr: rawptr #partial switch tk in t.key.variant { - case runtime.Type_Info_String: + case ^runtime.Type_Info_String: key_ptr = rawptr(&key) key_cstr: cstring if reflect.is_cstring(t.key) { key_cstr = cstring(raw_data(key)) key_ptr = &key_cstr } - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: i, ok := strconv.parse_i128(key) if !ok { return UNSUPPORTED_TYPE } key_ptr = rawptr(&i) @@ -599,9 +599,9 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm } } - case reflect.Type_Info_Enumerated_Array: + case ^reflect.Type_Info_Enumerated_Array: index_type := reflect.type_info_base(t.index) - enum_type := index_type.variant.(reflect.Type_Info_Enum) + enum_type := index_type.variant.(^reflect.Type_Info_Enum) enumerated_array_loop: for p.curr_token.kind != end_token { key, _ := parse_object_key(p, p.allocator) @@ -688,7 +688,7 @@ unmarshal_array :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) { length := unmarshal_count_array(p) #partial switch t in ti.variant { - case reflect.Type_Info_Slice: + case ^reflect.Type_Info_Slice: raw := (^mem.Raw_Slice)(v.data) data := bytes_make(t.elem.size * int(length), t.elem.align, p.allocator) or_return raw.data = raw_data(data) @@ -696,7 +696,7 @@ unmarshal_array :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) { return assign_array(p, raw.data, t.elem, length) - case reflect.Type_Info_Dynamic_Array: + case ^reflect.Type_Info_Dynamic_Array: raw := (^mem.Raw_Dynamic_Array)(v.data) data := bytes_make(t.elem.size * int(length), t.elem.align, p.allocator) or_return raw.data = raw_data(data) @@ -706,7 +706,7 @@ unmarshal_array :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) { return assign_array(p, raw.data, t.elem, length) - case reflect.Type_Info_Array: + case ^reflect.Type_Info_Array: // NOTE(bill): Allow lengths which are less than the dst array if int(length) > t.count { return UNSUPPORTED_TYPE @@ -714,7 +714,7 @@ unmarshal_array :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) { return assign_array(p, v.data, t.elem, length) - case reflect.Type_Info_Enumerated_Array: + case ^reflect.Type_Info_Enumerated_Array: // NOTE(bill): Allow lengths which are less than the dst array if int(length) > t.count { return UNSUPPORTED_TYPE @@ -722,7 +722,7 @@ unmarshal_array :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) { return assign_array(p, v.data, t.elem, length) - case reflect.Type_Info_Complex: + case ^reflect.Type_Info_Complex: // NOTE(bill): Allow lengths which are less than the dst array if int(length) > 2 { return UNSUPPORTED_TYPE diff --git a/core/flags/internal_assignment.odin b/core/flags/internal_assignment.odin index 5999dbf2d03..878039ca622 100644 --- a/core/flags/internal_assignment.odin +++ b/core/flags/internal_assignment.odin @@ -85,7 +85,7 @@ set_odin_flag :: proc(model: ^$T, parser: ^Parser, name: string) -> (error: Erro field, index := get_field_by_name(model, name) or_return #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Boolean: + case ^runtime.Type_Info_Boolean: ptr := cast(^bool)(cast(uintptr)model + field.offset) ptr^ = true case: @@ -111,10 +111,10 @@ set_unix_flag :: proc(model: ^$T, parser: ^Parser, name: string) -> (future_args field, index := get_field_by_name(model, name) or_return #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Boolean: + case ^runtime.Type_Info_Boolean: ptr := cast(^bool)(cast(uintptr)model + field.offset) ptr^ = true - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: future_args = 1 if tag, ok := reflect.struct_tag_lookup(field.tag, TAG_ARGS); ok { if length, is_manifold := get_struct_subtag(tag, SUBTAG_MANIFOLD); is_manifold { @@ -150,7 +150,7 @@ set_option :: proc(model: ^$T, parser: ^Parser, name, option: string) -> (error: // Guard against incorrect syntax. #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: return Parse_Error { .No_Value, fmt.tprintf("Unable to set `%s` of type %v to `%s`. Are you missing an `=`? The correct format is `map:key=value`.", name, field.type, option), @@ -181,7 +181,7 @@ set_key_value :: proc(model: ^$T, parser: ^Parser, name, key, value: string) -> field, index := get_field_by_name(model, name) or_return #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: key := key key_ptr := cast(rawptr)&key key_cstr: cstring diff --git a/core/flags/internal_rtti.odin b/core/flags/internal_rtti.odin index 1c559ca5598..9047a0977e7 100644 --- a/core/flags/internal_rtti.odin +++ b/core/flags/internal_rtti.odin @@ -41,7 +41,7 @@ parse_and_set_pointer_by_base_type :: proc(ptr: rawptr, str: string, type_info: // This seems to be the smallest way for now. #partial switch specific_type_info in type_info.variant { - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: if specific_type_info.signed { value := strconv.parse_i128(str) or_return switch type_info.id { @@ -87,14 +87,14 @@ parse_and_set_pointer_by_base_type :: proc(ptr: rawptr, str: string, type_info: } } - case runtime.Type_Info_Rune: + case ^runtime.Type_Info_Rune: if utf8.rune_count_in_string(str) != 1 { return false } (^rune)(ptr)^ = utf8.rune_at_pos(str, 0) - case runtime.Type_Info_Float: + case ^runtime.Type_Info_Float: value := strconv.parse_f64(str) or_return switch type_info.id { case f16: (^f16) (ptr)^ = cast(f16) value @@ -110,7 +110,7 @@ parse_and_set_pointer_by_base_type :: proc(ptr: rawptr, str: string, type_info: case f64be: (^f64be)(ptr)^ = cast(f64be) value } - case runtime.Type_Info_Complex: + case ^runtime.Type_Info_Complex: value := strconv.parse_complex128(str) or_return switch type_info.id { case complex32: (^complex32) (ptr)^ = (complex32)(value) @@ -118,7 +118,7 @@ parse_and_set_pointer_by_base_type :: proc(ptr: rawptr, str: string, type_info: case complex128: (^complex128)(ptr)^ = value } - case runtime.Type_Info_Quaternion: + case ^runtime.Type_Info_Quaternion: value := strconv.parse_quaternion256(str) or_return switch type_info.id { case quaternion64: (^quaternion64) (ptr)^ = (quaternion64)(value) @@ -126,7 +126,7 @@ parse_and_set_pointer_by_base_type :: proc(ptr: rawptr, str: string, type_info: case quaternion256: (^quaternion256)(ptr)^ = value } - case runtime.Type_Info_String: + case ^runtime.Type_Info_String: if specific_type_info.is_cstring { cstr_ptr := (^cstring)(ptr) if cstr_ptr != nil { @@ -138,7 +138,7 @@ parse_and_set_pointer_by_base_type :: proc(ptr: rawptr, str: string, type_info: (^string)(ptr)^ = str } - case runtime.Type_Info_Boolean: + case ^runtime.Type_Info_Boolean: value := strconv.parse_bool(str) or_return switch type_info.id { case bool: (^bool)(ptr)^ = value @@ -148,7 +148,7 @@ parse_and_set_pointer_by_base_type :: proc(ptr: rawptr, str: string, type_info: case b64: (^b64) (ptr)^ = b64(value) } - case runtime.Type_Info_Bit_Set: + case ^runtime.Type_Info_Bit_Set: // Parse a string of 1's and 0's, from left to right, // least significant bit to most significant bit. value: u128 @@ -370,7 +370,7 @@ set_unbounded_integer_by_type :: proc(ptr: rawptr, value: $T, data_type: typeid) @(optimization_mode="favor_size") parse_and_set_pointer_by_type :: proc(ptr: rawptr, str: string, type_info: ^runtime.Type_Info, arg_tag: string) -> (error: Error) { #partial switch specific_type_info in type_info.variant { - case runtime.Type_Info_Named: + case ^runtime.Type_Info_Named: if global_custom_type_setter != nil { // The program gets to go first. error_message, handled, alloc_error := global_custom_type_setter(ptr, type_info.id, str, arg_tag) @@ -399,7 +399,7 @@ parse_and_set_pointer_by_type :: proc(ptr: rawptr, str: string, type_info: ^runt } // Might be a named enum. Need to check here first, since we handle all enums. - if enum_type_info, is_enum := specific_type_info.base.variant.(runtime.Type_Info_Enum); is_enum { + if enum_type_info, is_enum := specific_type_info.base.variant.(^runtime.Type_Info_Enum); is_enum { if value, ok := reflect.enum_from_name_any(type_info.id, str); ok { set_unbounded_integer_by_type(ptr, value, enum_type_info.base.id) } else { @@ -420,7 +420,7 @@ parse_and_set_pointer_by_type :: proc(ptr: rawptr, str: string, type_info: ^runt } } - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: ptr := cast(^runtime.Raw_Dynamic_Array)ptr // Try to convert the value first. @@ -448,7 +448,7 @@ parse_and_set_pointer_by_type :: proc(ptr: rawptr, str: string, type_info: ^runt uintptr((ptr.len - 1) * specific_type_info.elem.size)) mem.copy(subptr, raw_data(elem_backing), len(elem_backing)) - case runtime.Type_Info_Enum: + case ^runtime.Type_Info_Enum: // This is a nameless enum. // The code here is virtually the same as above for named enums. if value, ok := reflect.enum_from_name_any(type_info.id, str); ok { diff --git a/core/flags/internal_validation.odin b/core/flags/internal_validation.odin index cd903c3e5cb..58ea0e47d37 100644 --- a/core/flags/internal_validation.odin +++ b/core/flags/internal_validation.odin @@ -19,7 +19,7 @@ validate_structure :: proc(model_type: $T, style: Parsing_Style, loc := #caller_ check_fields: for field in reflect.struct_fields_zipped(T) { if style == .Unix { #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: fmt.panicf("%T.%s is a map type, and these are not supported in UNIX-style parsing mode.", model_type, field.name, loc = loc) } @@ -62,7 +62,7 @@ validate_structure :: proc(model_type: $T, style: Parsing_Style, loc := #caller_ pos_str, has_pos := get_struct_subtag(args_tag, SUBTAG_POS) if has_pos { #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: fmt.panicf("%T.%s has `%s` defined, and this does not make sense on a map type.", model_type, field.name, SUBTAG_POS, loc = loc) } @@ -86,7 +86,7 @@ validate_structure :: proc(model_type: $T, style: Parsing_Style, loc := #caller_ if len(requirement) > 0 { if required_min, required_max, ok = parse_requirements(requirement); ok { #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: fmt.assertf(required_min != required_max, "%T.%s has `%s` defined as %q, but the minimum and maximum are the same. Increase the maximum by 1 for an exact number of arguments: (%i<%i)", model_type, field.name, @@ -125,7 +125,7 @@ validate_structure :: proc(model_type: $T, style: Parsing_Style, loc := #caller_ } #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: fmt.assertf(style != .Odin, "%T.%s has `%s` defined, but this only makes sense in UNIX-style parsing mode.", model_type, field.name, SUBTAG_MANIFOLD, loc = loc) @@ -137,9 +137,9 @@ validate_structure :: proc(model_type: $T, style: Parsing_Style, loc := #caller_ allowed_to_define_file_perms: bool = --- #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: allowed_to_define_file_perms = specific_type_info.value.id == os.Handle - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: allowed_to_define_file_perms = specific_type_info.elem.id == os.Handle case: allowed_to_define_file_perms = field.type.id == os.Handle @@ -156,7 +156,7 @@ validate_structure :: proc(model_type: $T, style: Parsing_Style, loc := #caller_ } #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: fmt.assertf(reflect.is_string(specific_type_info.key), "%T.%s is defined as a map[%T]. Only string types are currently supported as map keys.", model_type, field.name, @@ -187,7 +187,7 @@ validate_arguments :: proc(model: ^$T, parser: ^Parser) -> Error { is_required = false } - if _, is_array := field.type.variant.(runtime.Type_Info_Dynamic_Array); is_array && has_requirements { + if _, is_array := field.type.variant.(^runtime.Type_Info_Dynamic_Array); is_array && has_requirements { // If it's an array, make sure it meets the required number of arguments. ptr := cast(^runtime.Raw_Dynamic_Array)(cast(uintptr)model + field.offset) if required_min == required_max - 1 && ptr.len != required_min { diff --git a/core/flags/usage.odin b/core/flags/usage.odin index a44baec816b..5da973eda42 100644 --- a/core/flags/usage.odin +++ b/core/flags/usage.odin @@ -138,13 +138,13 @@ write_usage :: proc(out: io.Writer, data_type: typeid, program: string = "", sty } #partial switch specific_type_info in field.type.variant { - case runtime.Type_Info_Map: + case ^runtime.Type_Info_Map: flag.type_description = fmt.tprintf("<%v>=<%v>%s", specific_type_info.key.id, specific_type_info.value.id, ", required" if flag.is_required else "") - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: requirement_spec := describe_array_requirements(flag) if flag.is_manifold || flag.name == INTERNAL_OVERFLOW_FLAG { diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 0f6470ccae3..d700adf722d 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -1613,7 +1613,7 @@ enum_value_to_string :: proc(val: any) -> (string, bool) { // string_to_enum_value :: proc($T: typeid, s: string) -> (T, bool) { ti := runtime.type_info_base(type_info_of(T)) - if e, ok := ti.variant.(runtime.Type_Info_Enum); ok { + if e, ok := ti.variant.(^runtime.Type_Info_Enum); ok { for str, idx in e.names { if s == str { // NOTE(bill): Unsafe cast @@ -1640,7 +1640,7 @@ fmt_enum :: proc(fi: ^Info, v: any, verb: rune) { type_info := type_info_of(v.id) #partial switch e in type_info.variant { case: fmt_bad_verb(fi, verb) - case runtime.Type_Info_Enum: + case ^runtime.Type_Info_Enum: switch verb { case: fmt_bad_verb(fi, verb) case 'i', 'd', 'f': @@ -1680,7 +1680,7 @@ stored_enum_value_to_string :: proc(enum_type: ^runtime.Type_Info, ev: runtime.T ev += runtime.Type_Info_Enum_Value(offset) #partial switch e in et.variant { case: return "", false - case runtime.Type_Info_Enum: + case ^runtime.Type_Info_Enum: if reflect.is_string(e.base) { for val, idx in e.values { if val == ev { @@ -1716,7 +1716,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') { } t := runtime.type_info_base(ti) #partial switch info in t.variant { - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: switch info.endianness { case .Platform: return false case .Little: return ODIN_ENDIAN != .Little @@ -1730,12 +1730,12 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') { type_info := type_info_of(v.id) #partial switch info in type_info.variant { - case runtime.Type_Info_Named: + case ^runtime.Type_Info_Named: val := v val.id = info.base.id fmt_bit_set(fi, val, info.name, verb) - case runtime.Type_Info_Bit_Set: + case ^runtime.Type_Info_Bit_Set: bits: u128 bit_size := u128(8*type_info.size) @@ -1803,7 +1803,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') { io.write_byte(fi.writer, '{', &fi.n) defer io.write_byte(fi.writer, '}', &fi.n) - e, is_enum := et.variant.(runtime.Type_Info_Enum) + e, is_enum := et.variant.(^runtime.Type_Info_Enum) commas := 0 loop: for i in transmute(bit_set[0..<128])bits { i := i64(i) + info.lower @@ -1813,7 +1813,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') { if is_enum { enum_name: string - if ti_named, is_named := info.elem.variant.(runtime.Type_Info_Named); is_named { + if ti_named, is_named := info.elem.variant.(^runtime.Type_Info_Named); is_named { enum_name = ti_named.name } for ev, evi in e.values { @@ -1903,8 +1903,8 @@ fmt_write_array :: proc(fi: ^Info, array_data: rawptr, count: int, elem_size: in // Returns: A boolean value indicating whether to continue processing the tag // @(private) -handle_tag :: proc(state: ^Info_State, data: rawptr, info: reflect.Type_Info_Struct, idx: int, verb: ^rune, optional_len: ^int, use_nul_termination: ^bool) -> (do_continue: bool) { - handle_optional_len :: proc(data: rawptr, info: reflect.Type_Info_Struct, field_name: string, optional_len: ^int) { +handle_tag :: proc(state: ^Info_State, data: rawptr, info: ^reflect.Type_Info_Struct, idx: int, verb: ^rune, optional_len: ^int, use_nul_termination: ^bool) -> (do_continue: bool) { + handle_optional_len :: proc(data: rawptr, info: ^reflect.Type_Info_Struct, field_name: string, optional_len: ^int) { if optional_len == nil { return } @@ -2007,12 +2007,12 @@ handle_tag :: proc(state: ^Info_State, data: rawptr, info: reflect.Type_Info_Str // - info: Type information about the struct // - type_name: The name of the type being formatted // -fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_Struct, type_name: string) { +fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: ^runtime.Type_Info_Struct, type_name: string) { if the_verb != 'v' && the_verb != 'w' { fmt_bad_verb(fi, the_verb) return } - if .raw_union in info.flags { + if .raw_union in info.struct_flags { if type_name == "" { io.write_string(fi.writer, "(raw union)", &fi.n) } else { @@ -2053,7 +2053,7 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St defer fi.indent -= 1 base_type_name: string - if v, ok := info.soa_base_type.variant.(runtime.Type_Info_Named); ok { + if v, ok := info.soa_base_type.variant.(^runtime.Type_Info_Named); ok { base_type_name = v.name } @@ -2117,7 +2117,7 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St io.write_string(fi.writer, " = ", &fi.n) if info.soa_kind == .Fixed { - t := info.types[i].variant.(runtime.Type_Info_Array).elem + t := info.types[i].variant.(^runtime.Type_Info_Array).elem t_size := uintptr(t.size) if reflect.is_any(t) { io.write_string(fi.writer, "any{}", &fi.n) @@ -2126,7 +2126,7 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St fmt_arg(fi, any{data, t.id}, verb) } } else { - t := info.types[i].variant.(runtime.Type_Info_Multi_Pointer).elem + t := info.types[i].variant.(^runtime.Type_Info_Multi_Pointer).elem t_size := uintptr(t.size) if reflect.is_any(t) { io.write_string(fi.writer, "any{}", &fi.n) @@ -2299,7 +2299,7 @@ fmt_array :: proc(fi: ^Info, data: rawptr, n: int, elem_size: int, elem: ^reflec // // NOTE: This procedure supports built-in custom formatters for core library types such as runtime.Source_Code_Location, time.Duration, and time.Time. // -fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named) { +fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: ^runtime.Type_Info_Named) { write_padded_number :: proc(fi: ^Info, i: i64, width: int) { n := width-1 for x := i; x >= 10; x /= 10 { @@ -2456,26 +2456,26 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named) } #partial switch b in info.base.variant { - case runtime.Type_Info_Struct: + case ^runtime.Type_Info_Struct: fmt_struct(fi, v, verb, b, info.name) - case runtime.Type_Info_Bit_Field: + case ^runtime.Type_Info_Bit_Field: fmt_bit_field(fi, v, verb, b, info.name) - case runtime.Type_Info_Bit_Set: + case ^runtime.Type_Info_Bit_Set: fmt_bit_set(fi, v, verb = verb) case: if verb == 'w' { #partial switch _ in info.base.variant { - case runtime.Type_Info_Array, - runtime.Type_Info_Enumerated_Array, - runtime.Type_Info_Dynamic_Array, - runtime.Type_Info_Slice, - runtime.Type_Info_Struct, - runtime.Type_Info_Enum, - runtime.Type_Info_Map, - runtime.Type_Info_Bit_Set, - runtime.Type_Info_Simd_Vector, - runtime.Type_Info_Matrix, - runtime.Type_Info_Bit_Field: + case ^runtime.Type_Info_Array, + ^runtime.Type_Info_Enumerated_Array, + ^runtime.Type_Info_Dynamic_Array, + ^runtime.Type_Info_Slice, + ^runtime.Type_Info_Struct, + ^runtime.Type_Info_Enum, + ^runtime.Type_Info_Map, + ^runtime.Type_Info_Bit_Set, + ^runtime.Type_Info_Simd_Vector, + ^runtime.Type_Info_Matrix, + ^runtime.Type_Info_Bit_Field: io.write_string(fi.writer, info.name, &fi.n) } } @@ -2491,7 +2491,7 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named) // - info: The union type information. // - type_size: The size of the union type. // -fmt_union :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Union, type_size: int) { +fmt_union :: proc(fi: ^Info, v: any, verb: rune, info: ^runtime.Type_Info_Union, type_size: int) { if type_size == 0 { io.write_string(fi.writer, "nil", &fi.n) return @@ -2544,7 +2544,7 @@ fmt_union :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Union, // - verb: The formatting verb rune. // - info: A runtime.Type_Info_Matrix struct containing matrix type information. // -fmt_matrix :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Matrix) { +fmt_matrix :: proc(fi: ^Info, v: any, verb: rune, info: ^runtime.Type_Info_Matrix) { if verb == 'w' { io.write_byte(fi.writer, '{', &fi.n) } else { @@ -2601,7 +2601,7 @@ fmt_matrix :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Matrix } } -fmt_bit_field :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Bit_Field, type_name: string) { +fmt_bit_field :: proc(fi: ^Info, v: any, verb: rune, info: ^runtime.Type_Info_Bit_Field, type_name: string) { read_bits :: proc(ptr: [^]byte, offset, size: uintptr) -> (res: u64) { for i in 0.. (do_continue: bool) { + handle_bit_field_tag :: proc(data: rawptr, info: ^runtime.Type_Info_Bit_Field, idx: int, verb: ^rune) -> (do_continue: bool) { tag := info.tags[idx] if vt, ok := reflect.struct_tag_lookup(reflect.Struct_Tag(tag), "fmt"); ok { value := strings.trim_space(string(vt)) @@ -2722,21 +2722,21 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { type_info := type_info_of(v.id) switch info in type_info.variant { - case runtime.Type_Info_Any: // Ignore - case runtime.Type_Info_Parameters: // Ignore + case ^runtime.Type_Info_Any: // Ignore + case ^runtime.Type_Info_Parameters: // Ignore - case runtime.Type_Info_Named: + case ^runtime.Type_Info_Named: fmt_named(fi, v, verb, info) - case runtime.Type_Info_Boolean: fmt_arg(fi, v, verb) - case runtime.Type_Info_Integer: fmt_arg(fi, v, verb) - case runtime.Type_Info_Rune: fmt_arg(fi, v, verb) - case runtime.Type_Info_Float: fmt_arg(fi, v, verb) - case runtime.Type_Info_Complex: fmt_arg(fi, v, verb) - case runtime.Type_Info_Quaternion: fmt_arg(fi, v, verb) - case runtime.Type_Info_String: fmt_arg(fi, v, verb) + case ^runtime.Type_Info_Boolean: fmt_arg(fi, v, verb) + case ^runtime.Type_Info_Integer: fmt_arg(fi, v, verb) + case ^runtime.Type_Info_Rune: fmt_arg(fi, v, verb) + case ^runtime.Type_Info_Float: fmt_arg(fi, v, verb) + case ^runtime.Type_Info_Complex: fmt_arg(fi, v, verb) + case ^runtime.Type_Info_Quaternion: fmt_arg(fi, v, verb) + case ^runtime.Type_Info_String: fmt_arg(fi, v, verb) - case runtime.Type_Info_Pointer: + case ^runtime.Type_Info_Pointer: if v.id == typeid_of(^runtime.Type_Info) { reflect.write_type(fi.writer, (^^runtime.Type_Info)(v.data)^, &fi.n) } else { @@ -2747,10 +2747,10 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { elem := runtime.type_info_base(info.elem) if elem != nil { #partial switch e in elem.variant { - case runtime.Type_Info_Array, - runtime.Type_Info_Slice, - runtime.Type_Info_Dynamic_Array, - runtime.Type_Info_Map: + case ^runtime.Type_Info_Array, + ^runtime.Type_Info_Slice, + ^runtime.Type_Info_Dynamic_Array, + ^runtime.Type_Info_Map: if ptr == nil { io.write_string(fi.writer, "", &fi.n) return @@ -2763,9 +2763,9 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { return } - case runtime.Type_Info_Struct, - runtime.Type_Info_Union, - runtime.Type_Info_Bit_Field: + case ^runtime.Type_Info_Struct, + ^runtime.Type_Info_Union, + ^runtime.Type_Info_Bit_Field: if ptr == nil { io.write_string(fi.writer, "", &fi.n) return @@ -2783,11 +2783,11 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { fmt_pointer(fi, ptr, verb) } - case runtime.Type_Info_Soa_Pointer: + case ^runtime.Type_Info_Soa_Pointer: ptr := (^runtime.Raw_Soa_Pointer)(v.data)^ fmt_soa_pointer(fi, ptr, verb) - case runtime.Type_Info_Multi_Pointer: + case ^runtime.Type_Info_Multi_Pointer: ptr := (^rawptr)(v.data)^ if ptr == nil { io.write_string(fi.writer, "", &fi.n) @@ -2809,7 +2809,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } #partial switch e in elem.variant { - case runtime.Type_Info_Integer: + case ^runtime.Type_Info_Integer: switch verb { case 's', 'q': switch elem.id { @@ -2823,10 +2823,10 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } } - case runtime.Type_Info_Array, - runtime.Type_Info_Slice, - runtime.Type_Info_Dynamic_Array, - runtime.Type_Info_Map: + case ^runtime.Type_Info_Array, + ^runtime.Type_Info_Slice, + ^runtime.Type_Info_Dynamic_Array, + ^runtime.Type_Info_Map: if fi.indirection_level < 1 { fi.indirection_level += 1 defer fi.indirection_level -= 1 @@ -2835,8 +2835,8 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { return } - case runtime.Type_Info_Struct, - runtime.Type_Info_Union: + case ^runtime.Type_Info_Struct, + ^runtime.Type_Info_Union: if fi.indirection_level < 1 { fi.indirection_level += 1 defer fi.indirection_level -= 1 @@ -2849,7 +2849,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } fmt_pointer(fi, ptr, verb) - case runtime.Type_Info_Enumerated_Array: + case ^runtime.Type_Info_Enumerated_Array: fi.record_level += 1 defer fi.record_level -= 1 @@ -2901,7 +2901,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } } - case runtime.Type_Info_Array: + case ^runtime.Type_Info_Array: n := info.count ptr := v.data if ol, ok := fi.optional_len.?; ok { @@ -2914,7 +2914,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } fmt_array(fi, ptr, n, info.elem_size, info.elem, verb) - case runtime.Type_Info_Slice: + case ^runtime.Type_Info_Slice: slice := cast(^mem.Raw_Slice)v.data n := slice.len ptr := slice.data @@ -2928,7 +2928,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } fmt_array(fi, ptr, n, info.elem_size, info.elem, verb) - case runtime.Type_Info_Dynamic_Array: + case ^runtime.Type_Info_Dynamic_Array: array := cast(^mem.Raw_Dynamic_Array)v.data n := array.len ptr := array.data @@ -2942,7 +2942,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } fmt_array(fi, ptr, n, info.elem_size, info.elem, verb) - case runtime.Type_Info_Simd_Vector: + case ^runtime.Type_Info_Simd_Vector: io.write_byte(fi.writer, '<', &fi.n) defer io.write_byte(fi.writer, '>', &fi.n) for i in 0.. T where intr return T(i) } } else { - values := runtime.type_info_base(type_info_of(T)).variant.(runtime.Type_Info_Enum).values + values := runtime.type_info_base(type_info_of(T)).variant.(^runtime.Type_Info_Enum).values return T(choice(values)) } } diff --git a/core/odin/ast/clone.odin b/core/odin/ast/clone.odin index b7501e6ca03..6547c5f4fb4 100644 --- a/core/odin/ast/clone.odin +++ b/core/odin/ast/clone.odin @@ -81,7 +81,7 @@ clone_node :: proc(node: ^Node) -> ^Node { align := align_of(Node) ti := reflect.union_variant_type_info(node.derived) if ti != nil { - elem := ti.variant.(reflect.Type_Info_Pointer).elem + elem := ti.variant.(^reflect.Type_Info_Pointer).elem size = elem.size align = elem.align } diff --git a/core/os/errors.odin b/core/os/errors.odin index 691397f4b42..b72b5824efb 100644 --- a/core/os/errors.odin +++ b/core/os/errors.odin @@ -164,7 +164,7 @@ _error_string :: proc "contextless" (e: Platform_Error) -> string where intrinsi err := runtime.Type_Info_Enum_Value(e) - ti := &runtime.type_info_base(type_info_of(Platform_Error)).variant.(runtime.Type_Info_Enum) + ti := runtime.type_info_base(type_info_of(Platform_Error)).variant.(^runtime.Type_Info_Enum) if idx, ok := binary_search(ti.values, err); ok { return ti.names[idx] } diff --git a/core/os/os2/errors_wasi.odin b/core/os/os2/errors_wasi.odin index b88e5b81e4a..3fdcb892aeb 100644 --- a/core/os/os2/errors_wasi.odin +++ b/core/os/os2/errors_wasi.odin @@ -16,7 +16,7 @@ _error_string :: proc(errno: i32) -> string { err := runtime.Type_Info_Enum_Value(e) - ti := &runtime.type_info_base(type_info_of(wasi.errno_t)).variant.(runtime.Type_Info_Enum) + ti := &runtime.type_info_base(type_info_of(wasi.errno_t)).variant.(^runtime.Type_Info_Enum) if idx, ok := slice.binary_search(ti.values, err); ok { return ti.names[idx] } diff --git a/core/os/os2/errors_windows.odin b/core/os/os2/errors_windows.odin index 404560f987b..a7d951b1d34 100644 --- a/core/os/os2/errors_windows.odin +++ b/core/os/os2/errors_windows.odin @@ -15,7 +15,7 @@ _error_string :: proc(errno: i32) -> string { err := runtime.Type_Info_Enum_Value(e) - ti := &runtime.type_info_base(type_info_of(win32.System_Error)).variant.(runtime.Type_Info_Enum) + ti := runtime.type_info_base(type_info_of(win32.System_Error)).variant.(^runtime.Type_Info_Enum) if idx, ok := slice.binary_search(ti.values, err); ok { return ti.names[idx] } diff --git a/core/reflect/iterator.odin b/core/reflect/iterator.odin index 090fe04cc8d..b4019d907bd 100644 --- a/core/reflect/iterator.odin +++ b/core/reflect/iterator.odin @@ -10,11 +10,11 @@ iterate_array :: proc(val: any, it: ^int) -> (elem: any, index: int, ok: bool) { ti := type_info_base(type_info_of(val.id)) #partial switch info in ti.variant { - case Type_Info_Pointer: + case ^Type_Info_Pointer: if ptr := (^rawptr)(val.data)^; ptr != nil { return iterate_array(any{ptr, info.elem.id}, it) } - case Type_Info_Array: + case ^Type_Info_Array: if it^ < info.count { elem.data = rawptr(uintptr(val.data) + uintptr(it^ * info.elem_size)) elem.id = info.elem.id @@ -22,7 +22,7 @@ iterate_array :: proc(val: any, it: ^int) -> (elem: any, index: int, ok: bool) { index = it^ it^ += 1 } - case Type_Info_Slice: + case ^Type_Info_Slice: array := (^runtime.Raw_Slice)(val.data) if it^ < array.len { elem.data = rawptr(uintptr(array.data) + uintptr(it^ * info.elem_size)) @@ -31,7 +31,7 @@ iterate_array :: proc(val: any, it: ^int) -> (elem: any, index: int, ok: bool) { index = it^ it^ += 1 } - case Type_Info_Dynamic_Array: + case ^Type_Info_Dynamic_Array: array := (^runtime.Raw_Dynamic_Array)(val.data) if it^ < array.len { elem.data = rawptr(uintptr(array.data) + uintptr(it^ * info.elem_size)) @@ -52,11 +52,11 @@ iterate_map :: proc(val: any, it: ^int) -> (key, value: any, ok: bool) { } ti := type_info_base(type_info_of(val.id)) #partial switch info in ti.variant { - case Type_Info_Pointer: + case ^Type_Info_Pointer: if ptr := (^rawptr)(val.data)^; ptr != nil { return iterate_map(any{ptr, info.elem.id}, it) } - case Type_Info_Map: + case ^Type_Info_Map: if info.map_info == nil { break } diff --git a/core/reflect/reflect.odin b/core/reflect/reflect.odin index b3315a0c355..3e669ca3358 100644 --- a/core/reflect/reflect.odin +++ b/core/reflect/reflect.odin @@ -75,33 +75,33 @@ type_kind :: proc(T: typeid) -> Type_Kind { ti := type_info_of(T) if ti != nil { switch _ in ti.variant { - case Type_Info_Named: return .Named - case Type_Info_Integer: return .Integer - case Type_Info_Rune: return .Rune - case Type_Info_Float: return .Float - case Type_Info_Complex: return .Complex - case Type_Info_Quaternion: return .Quaternion - case Type_Info_String: return .String - case Type_Info_Boolean: return .Boolean - case Type_Info_Any: return .Any - case Type_Info_Type_Id: return .Type_Id - case Type_Info_Pointer: return .Pointer - case Type_Info_Multi_Pointer: return .Multi_Pointer - case Type_Info_Procedure: return .Procedure - case Type_Info_Array: return .Array - case Type_Info_Enumerated_Array: return .Enumerated_Array - case Type_Info_Dynamic_Array: return .Dynamic_Array - case Type_Info_Slice: return .Slice - case Type_Info_Parameters: return .Parameters - case Type_Info_Struct: return .Struct - case Type_Info_Union: return .Union - case Type_Info_Enum: return .Enum - case Type_Info_Map: return .Map - case Type_Info_Bit_Set: return .Bit_Set - case Type_Info_Simd_Vector: return .Simd_Vector - case Type_Info_Matrix: return .Matrix - case Type_Info_Soa_Pointer: return .Soa_Pointer - case Type_Info_Bit_Field: return .Bit_Field + case ^Type_Info_Named: return .Named + case ^Type_Info_Integer: return .Integer + case ^Type_Info_Rune: return .Rune + case ^Type_Info_Float: return .Float + case ^Type_Info_Complex: return .Complex + case ^Type_Info_Quaternion: return .Quaternion + case ^Type_Info_String: return .String + case ^Type_Info_Boolean: return .Boolean + case ^Type_Info_Any: return .Any + case ^Type_Info_Type_Id: return .Type_Id + case ^Type_Info_Pointer: return .Pointer + case ^Type_Info_Multi_Pointer: return .Multi_Pointer + case ^Type_Info_Procedure: return .Procedure + case ^Type_Info_Array: return .Array + case ^Type_Info_Enumerated_Array: return .Enumerated_Array + case ^Type_Info_Dynamic_Array: return .Dynamic_Array + case ^Type_Info_Slice: return .Slice + case ^Type_Info_Parameters: return .Parameters + case ^Type_Info_Struct: return .Struct + case ^Type_Info_Union: return .Union + case ^Type_Info_Enum: return .Enum + case ^Type_Info_Map: return .Map + case ^Type_Info_Bit_Set: return .Bit_Set + case ^Type_Info_Simd_Vector: return .Simd_Vector + case ^Type_Info_Matrix: return .Matrix + case ^Type_Info_Soa_Pointer: return .Soa_Pointer + case ^Type_Info_Bit_Field: return .Bit_Field } } @@ -158,24 +158,24 @@ typeid_elem :: proc(id: typeid) -> typeid { bits := 8*ti.size #partial switch v in ti.variant { - case Type_Info_Complex: + case ^Type_Info_Complex: switch bits { case 64: return f32 case 128: return f64 } - case Type_Info_Quaternion: + case ^Type_Info_Quaternion: switch bits { case 128: return f32 case 256: return f64 } - case Type_Info_Pointer: return v.elem.id - case Type_Info_Multi_Pointer: return v.elem.id - case Type_Info_Soa_Pointer: return v.elem.id - case Type_Info_Array: return v.elem.id - case Type_Info_Enumerated_Array: return v.elem.id - case Type_Info_Slice: return v.elem.id - case Type_Info_Dynamic_Array: return v.elem.id - case Type_Info_Simd_Vector: return v.elem.id + case ^Type_Info_Pointer: return v.elem.id + case ^Type_Info_Multi_Pointer: return v.elem.id + case ^Type_Info_Soa_Pointer: return v.elem.id + case ^Type_Info_Array: return v.elem.id + case ^Type_Info_Enumerated_Array: return v.elem.id + case ^Type_Info_Slice: return v.elem.id + case ^Type_Info_Dynamic_Array: return v.elem.id + case ^Type_Info_Simd_Vector: return v.elem.id } return id } @@ -233,35 +233,35 @@ length :: proc(val: any) -> int { if val == nil { return 0 } #partial switch a in type_info_of(val.id).variant { - case Type_Info_Named: + case ^Type_Info_Named: return length({val.data, a.base.id}) - case Type_Info_Pointer: + case ^Type_Info_Pointer: return length({val.data, a.elem.id}) - case Type_Info_Array: + case ^Type_Info_Array: return a.count - case Type_Info_Enumerated_Array: + case ^Type_Info_Enumerated_Array: return a.count - case Type_Info_Slice: + case ^Type_Info_Slice: return (^runtime.Raw_Slice)(val.data).len - case Type_Info_Dynamic_Array: + case ^Type_Info_Dynamic_Array: return (^runtime.Raw_Dynamic_Array)(val.data).len - case Type_Info_Map: + case ^Type_Info_Map: return runtime.map_len((^runtime.Raw_Map)(val.data)^) - case Type_Info_String: + case ^Type_Info_String: if a.is_cstring { return len((^cstring)(val.data)^) } else { return (^runtime.Raw_String)(val.data).len } - case Type_Info_Simd_Vector: + case ^Type_Info_Simd_Vector: return a.count } @@ -273,25 +273,25 @@ capacity :: proc(val: any) -> int { if val == nil { return 0 } #partial switch a in type_info_of(val.id).variant { - case Type_Info_Named: + case ^Type_Info_Named: return capacity({val.data, a.base.id}) - case Type_Info_Pointer: + case ^Type_Info_Pointer: return capacity({val.data, a.elem.id}) - case Type_Info_Array: + case ^Type_Info_Array: return a.count - case Type_Info_Enumerated_Array: + case ^Type_Info_Enumerated_Array: return a.count - case Type_Info_Dynamic_Array: + case ^Type_Info_Dynamic_Array: return (^runtime.Raw_Dynamic_Array)(val.data).cap - case Type_Info_Map: + case ^Type_Info_Map: return runtime.map_cap((^runtime.Raw_Map)(val.data)^) - case Type_Info_Simd_Vector: + case ^Type_Info_Simd_Vector: return a.count } @@ -304,50 +304,50 @@ index :: proc(val: any, i: int, loc := #caller_location) -> any { if val == nil { return nil } #partial switch a in type_info_of(val.id).variant { - case Type_Info_Named: + case ^Type_Info_Named: return index({val.data, a.base.id}, i, loc) - case Type_Info_Pointer: + case ^Type_Info_Pointer: ptr := (^rawptr)(val.data)^ if ptr == nil { return nil } return index({ptr, a.elem.id}, i, loc) - case Type_Info_Multi_Pointer: + case ^Type_Info_Multi_Pointer: ptr := (^rawptr)(val.data)^ if ptr == nil { return nil } return index({ptr, a.elem.id}, i, loc) - case Type_Info_Array: + case ^Type_Info_Array: runtime.bounds_check_error_loc(loc, i, a.count) offset := uintptr(a.elem.size * i) data := rawptr(uintptr(val.data) + offset) return any{data, a.elem.id} - case Type_Info_Enumerated_Array: + case ^Type_Info_Enumerated_Array: runtime.bounds_check_error_loc(loc, i, a.count) offset := uintptr(a.elem.size * i) data := rawptr(uintptr(val.data) + offset) return any{data, a.elem.id} - case Type_Info_Slice: + case ^Type_Info_Slice: raw := (^runtime.Raw_Slice)(val.data) runtime.bounds_check_error_loc(loc, i, raw.len) offset := uintptr(a.elem.size * i) data := rawptr(uintptr(raw.data) + offset) return any{data, a.elem.id} - case Type_Info_Dynamic_Array: + case ^Type_Info_Dynamic_Array: raw := (^runtime.Raw_Dynamic_Array)(val.data) runtime.bounds_check_error_loc(loc, i, raw.len) offset := uintptr(a.elem.size * i) data := rawptr(uintptr(raw.data) + offset) return any{data, a.elem.id} - case Type_Info_String: + case ^Type_Info_String: if a.is_cstring { return nil } raw := (^runtime.Raw_String)(val.data) @@ -363,7 +363,7 @@ index :: proc(val: any, i: int, loc := #caller_location) -> any { deref :: proc(val: any) -> any { if val != nil { ti := type_info_base(type_info_of(val.id)) - if info, ok := ti.variant.(Type_Info_Pointer); ok { + if info, ok := ti.variant.(^Type_Info_Pointer); ok { return any{ (^rawptr)(val.data)^, info.elem.id, @@ -392,7 +392,7 @@ Struct_Field :: struct { @(require_results) struct_field_at :: proc(T: typeid, i: int) -> (field: Struct_Field) { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { if 0 <= i && i < int(s.field_count) { field.name = s.names[i] field.type = s.types[i] @@ -407,7 +407,7 @@ struct_field_at :: proc(T: typeid, i: int) -> (field: Struct_Field) { @(require_results) struct_field_by_name :: proc(T: typeid, name: string) -> (field: Struct_Field) { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { for fname, i in s.names[:s.field_count] { if fname == name { field.name = s.names[i] @@ -428,7 +428,7 @@ struct_field_value_by_name :: proc(a: any, field: string, allow_using := false) ti := runtime.type_info_base(type_info_of(a.id)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { for name, i in s.names[:s.field_count] { if name == field { return any{ @@ -464,7 +464,7 @@ struct_field_value :: proc(a: any, field: Struct_Field) -> any { @(require_results) struct_field_names :: proc(T: typeid) -> []string { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { return s.names[:s.field_count] } return nil @@ -473,7 +473,7 @@ struct_field_names :: proc(T: typeid) -> []string { @(require_results) struct_field_types :: proc(T: typeid) -> []^Type_Info { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { return s.types[:s.field_count] } return nil @@ -483,7 +483,7 @@ struct_field_types :: proc(T: typeid) -> []^Type_Info { @(require_results) struct_field_tags :: proc(T: typeid) -> []Struct_Tag { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { return transmute([]Struct_Tag)s.tags[:s.field_count] } return nil @@ -492,7 +492,7 @@ struct_field_tags :: proc(T: typeid) -> []Struct_Tag { @(require_results) struct_field_offsets :: proc(T: typeid) -> []uintptr { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { return s.offsets[:s.field_count] } return nil @@ -531,7 +531,7 @@ Example: @(require_results) struct_field_count :: proc(T: typeid, method := Struct_Field_Count_Method.Top_Level) -> (count: int) { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { switch method { case .Top_Level: return int(s.field_count) @@ -559,7 +559,7 @@ struct_field_count :: proc(T: typeid, method := Struct_Field_Count_Method.Top_Le @(require_results) struct_fields_zipped :: proc(T: typeid) -> (fields: #soa[]Struct_Field) { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Struct); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Struct); ok { return soa_zip( name = s.names[:s.field_count], type = s.types[:s.field_count], @@ -642,7 +642,7 @@ struct_tag_lookup :: proc(tag: Struct_Tag, key: string) -> (value: string, ok: b enum_string :: proc(a: any) -> string { if a == nil { return "" } ti := runtime.type_info_base(type_info_of(a.id)) - if e, ok := ti.variant.(runtime.Type_Info_Enum); ok { + if e, ok := ti.variant.(^runtime.Type_Info_Enum); ok { v, _ := as_i64(a) for value, i in e.values { if value == Type_Info_Enum_Value(v) { @@ -660,7 +660,7 @@ enum_string :: proc(a: any) -> string { @(require_results) enum_from_name :: proc($Enum_Type: typeid, name: string) -> (value: Enum_Type, ok: bool) { ti := type_info_base(type_info_of(Enum_Type)) - if eti, eti_ok := ti.variant.(runtime.Type_Info_Enum); eti_ok { + if eti, eti_ok := ti.variant.(^runtime.Type_Info_Enum); eti_ok { for value_name, i in eti.names { if value_name != name { continue @@ -677,7 +677,7 @@ enum_from_name :: proc($Enum_Type: typeid, name: string) -> (value: Enum_Type, o @(require_results) enum_from_name_any :: proc(Enum_Type: typeid, name: string) -> (value: Type_Info_Enum_Value, ok: bool) { ti := runtime.type_info_base(type_info_of(Enum_Type)) - if eti, eti_ok := ti.variant.(runtime.Type_Info_Enum); eti_ok { + if eti, eti_ok := ti.variant.(^runtime.Type_Info_Enum); eti_ok { for value_name, i in eti.names { if value_name != name { continue @@ -693,7 +693,7 @@ enum_from_name_any :: proc(Enum_Type: typeid, name: string) -> (value: Type_Info @(require_results) enum_name_from_value :: proc(value: $Enum_Type) -> (name: string, ok: bool) where intrinsics.type_is_enum(Enum_Type) { ti := type_info_base(type_info_of(Enum_Type)) - e := ti.variant.(runtime.Type_Info_Enum) or_return + e := ti.variant.(^runtime.Type_Info_Enum) or_return if len(e.values) == 0 { return } @@ -712,7 +712,7 @@ enum_name_from_value_any :: proc(value: any) -> (name: string, ok: bool) { return } ti := type_info_base(type_info_of(value.id)) - e := ti.variant.(runtime.Type_Info_Enum) or_return + e := ti.variant.(^runtime.Type_Info_Enum) or_return if len(e.values) == 0 { return } @@ -752,7 +752,7 @@ enum_value_has_name :: proc(value: $T) -> bool where intrinsics.type_is_enum(T) @(require_results) enum_field_names :: proc(Enum_Type: typeid) -> []string { ti := runtime.type_info_base(type_info_of(Enum_Type)) - if eti, eti_ok := ti.variant.(runtime.Type_Info_Enum); eti_ok { + if eti, eti_ok := ti.variant.(^runtime.Type_Info_Enum); eti_ok { return eti.names } return nil @@ -760,7 +760,7 @@ enum_field_names :: proc(Enum_Type: typeid) -> []string { @(require_results) enum_field_values :: proc(Enum_Type: typeid) -> []Type_Info_Enum_Value { ti := runtime.type_info_base(type_info_of(Enum_Type)) - if eti, eti_ok := ti.variant.(runtime.Type_Info_Enum); eti_ok { + if eti, eti_ok := ti.variant.(^runtime.Type_Info_Enum); eti_ok { return eti.values } return nil @@ -774,7 +774,7 @@ Enum_Field :: struct { @(require_results) enum_fields_zipped :: proc(Enum_Type: typeid) -> (fields: #soa[]Enum_Field) { ti := runtime.type_info_base(type_info_of(Enum_Type)) - if eti, eti_ok := ti.variant.(runtime.Type_Info_Enum); eti_ok { + if eti, eti_ok := ti.variant.(^runtime.Type_Info_Enum); eti_ok { return soa_zip(name=eti.names, value=eti.values) } return nil @@ -789,7 +789,7 @@ union_variant_type_info :: proc(a: any) -> ^Type_Info { } @(require_results) -type_info_union_is_pure_maybe :: proc(info: runtime.Type_Info_Union) -> bool { +type_info_union_is_pure_maybe :: proc(info: ^runtime.Type_Info_Union) -> bool { return len(info.variants) == 1 && is_pointer_internally(info.variants[0]) } @@ -798,7 +798,7 @@ union_variant_typeid :: proc(a: any) -> typeid { if a == nil { return nil } ti := runtime.type_info_base(type_info_of(a.id)) - if info, ok := ti.variant.(runtime.Type_Info_Union); ok { + if info, ok := ti.variant.(^runtime.Type_Info_Union); ok { if type_info_union_is_pure_maybe(info) { if a.data != nil { return info.variants[0].id @@ -838,7 +838,7 @@ get_union_variant_raw_tag :: proc(a: any) -> i64 { if a == nil { return -1 } ti := runtime.type_info_base(type_info_of(a.id)) - if info, ok := ti.variant.(runtime.Type_Info_Union); ok { + if info, ok := ti.variant.(^runtime.Type_Info_Union); ok { if type_info_union_is_pure_maybe(info) { return 1 if a.data != nil else 0 } @@ -891,7 +891,7 @@ set_union_variant_raw_tag :: proc(a: any, tag: i64) { if a == nil { return } ti := runtime.type_info_base(type_info_of(a.id)) - if info, ok := ti.variant.(runtime.Type_Info_Union); ok { + if info, ok := ti.variant.(^runtime.Type_Info_Union); ok { if type_info_union_is_pure_maybe(info) { // Cannot do anything return @@ -921,7 +921,7 @@ set_union_variant_typeid :: proc(a: any, id: typeid) { if a == nil { return } ti := runtime.type_info_base(type_info_of(a.id)) - if info, ok := ti.variant.(runtime.Type_Info_Union); ok { + if info, ok := ti.variant.(^runtime.Type_Info_Union); ok { if type_info_union_is_pure_maybe(info) { // Cannot do anything return @@ -951,7 +951,7 @@ set_union_variant_type_info :: proc(a: any, tag_ti: ^Type_Info) { if a == nil { return } ti := runtime.type_info_base(type_info_of(a.id)) - if info, ok := ti.variant.(runtime.Type_Info_Union); ok { + if info, ok := ti.variant.(^runtime.Type_Info_Union); ok { if type_info_union_is_pure_maybe(info) { // Cannot do anything return @@ -981,7 +981,7 @@ set_union_value :: proc(dst: any, value: any) -> bool { if dst == nil { return false } ti := runtime.type_info_base(type_info_of(dst.id)) - if info, ok := ti.variant.(runtime.Type_Info_Union); ok { + if info, ok := ti.variant.(^runtime.Type_Info_Union); ok { if value.id == nil { intrinsics.mem_zero(dst.data, ti.size) return true @@ -1020,11 +1020,11 @@ bit_set_is_big_endian :: proc(value: any, loc := #caller_location) -> bool { if value == nil { return ODIN_ENDIAN == .Big } ti := runtime.type_info_base(type_info_of(value.id)) - if info, ok := ti.variant.(runtime.Type_Info_Bit_Set); ok { + if info, ok := ti.variant.(^runtime.Type_Info_Bit_Set); ok { if info.underlying == nil { return ODIN_ENDIAN == .Big } underlying_ti := runtime.type_info_base(info.underlying) - if underlying_info, uok := underlying_ti.variant.(runtime.Type_Info_Integer); uok { + if underlying_info, uok := underlying_ti.variant.(^runtime.Type_Info_Integer); uok { switch underlying_info.endianness { case .Platform: return ODIN_ENDIAN == .Big case .Little: return false @@ -1049,7 +1049,7 @@ Bit_Field :: struct { @(require_results) bit_fields_zipped :: proc(T: typeid) -> (fields: #soa[]Bit_Field) { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Bit_Field); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Bit_Field); ok { return soa_zip( name = s.names[:s.field_count], type = s.types[:s.field_count], @@ -1064,7 +1064,7 @@ bit_fields_zipped :: proc(T: typeid) -> (fields: #soa[]Bit_Field) { @(require_results) bit_field_names :: proc(T: typeid) -> []string { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Bit_Field); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Bit_Field); ok { return s.names[:s.field_count] } return nil @@ -1073,7 +1073,7 @@ bit_field_names :: proc(T: typeid) -> []string { @(require_results) bit_field_types :: proc(T: typeid) -> []^Type_Info { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Bit_Field); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Bit_Field); ok { return s.types[:s.field_count] } return nil @@ -1082,7 +1082,7 @@ bit_field_types :: proc(T: typeid) -> []^Type_Info { @(require_results) bit_field_sizes :: proc(T: typeid) -> []uintptr { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Bit_Field); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Bit_Field); ok { return s.bit_sizes[:s.field_count] } return nil @@ -1091,7 +1091,7 @@ bit_field_sizes :: proc(T: typeid) -> []uintptr { @(require_results) bit_field_offsets :: proc(T: typeid) -> []uintptr { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Bit_Field); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Bit_Field); ok { return s.bit_offsets[:s.field_count] } return nil @@ -1100,7 +1100,7 @@ bit_field_offsets :: proc(T: typeid) -> []uintptr { @(require_results) bit_field_tags :: proc(T: typeid) -> []Struct_Tag { ti := runtime.type_info_base(type_info_of(T)) - if s, ok := ti.variant.(runtime.Type_Info_Bit_Field); ok { + if s, ok := ti.variant.(^runtime.Type_Info_Bit_Field); ok { return transmute([]Struct_Tag)s.tags[:s.field_count] } return nil @@ -1114,7 +1114,7 @@ as_bool :: proc(a: any) -> (value: bool, valid: bool) { a.id = ti.id #partial switch info in ti.variant { - case Type_Info_Boolean: + case ^Type_Info_Boolean: valid = true switch v in a { case bool: value = v @@ -1153,7 +1153,7 @@ as_i64 :: proc(a: any) -> (value: i64, valid: bool) { a.id = ti.id #partial switch info in ti.variant { - case Type_Info_Integer: + case ^Type_Info_Integer: valid = true switch v in a { case i8: value = i64(v) @@ -1193,12 +1193,12 @@ as_i64 :: proc(a: any) -> (value: i64, valid: bool) { case: valid = false } - case Type_Info_Rune: + case ^Type_Info_Rune: r := a.(rune) value = i64(r) valid = true - case Type_Info_Float: + case ^Type_Info_Float: valid = true switch v in a { case f32: value = i64(v) @@ -1210,7 +1210,7 @@ as_i64 :: proc(a: any) -> (value: i64, valid: bool) { case: valid = false } - case Type_Info_Boolean: + case ^Type_Info_Boolean: valid = true switch v in a { case bool: value = i64(v) @@ -1221,7 +1221,7 @@ as_i64 :: proc(a: any) -> (value: i64, valid: bool) { case: valid = false } - case Type_Info_Complex: + case ^Type_Info_Complex: switch v in a { case complex64: if imag(v) == 0 { @@ -1235,7 +1235,7 @@ as_i64 :: proc(a: any) -> (value: i64, valid: bool) { } } - case Type_Info_Quaternion: + case ^Type_Info_Quaternion: switch v in a { case quaternion128: if imag(v) == 0 && jmag(v) == 0 && kmag(v) == 0 { @@ -1261,7 +1261,7 @@ as_u64 :: proc(a: any) -> (value: u64, valid: bool) { a.id = ti.id #partial switch info in ti.variant { - case Type_Info_Integer: + case ^Type_Info_Integer: valid = true switch v in a { case i8: value = u64(v) @@ -1301,12 +1301,12 @@ as_u64 :: proc(a: any) -> (value: u64, valid: bool) { case: valid = false } - case Type_Info_Rune: + case ^Type_Info_Rune: r := a.(rune) value = u64(r) valid = true - case Type_Info_Float: + case ^Type_Info_Float: valid = true switch v in a { case f16: value = u64(v) @@ -1319,7 +1319,7 @@ as_u64 :: proc(a: any) -> (value: u64, valid: bool) { case: valid = false } - case Type_Info_Boolean: + case ^Type_Info_Boolean: valid = true switch v in a { case bool: value = u64(v) @@ -1330,7 +1330,7 @@ as_u64 :: proc(a: any) -> (value: u64, valid: bool) { case: valid = false } - case Type_Info_Complex: + case ^Type_Info_Complex: switch v in a { case complex64: if imag(v) == 0 { @@ -1344,7 +1344,7 @@ as_u64 :: proc(a: any) -> (value: u64, valid: bool) { } } - case Type_Info_Quaternion: + case ^Type_Info_Quaternion: switch v in a { case quaternion128: if imag(v) == 0 && jmag(v) == 0 && kmag(v) == 0 { @@ -1371,7 +1371,7 @@ as_f64 :: proc(a: any) -> (value: f64, valid: bool) { a.id = ti.id #partial switch info in ti.variant { - case Type_Info_Integer: + case ^Type_Info_Integer: valid = true switch v in a { case i8: value = f64(v) @@ -1408,12 +1408,12 @@ as_f64 :: proc(a: any) -> (value: f64, valid: bool) { case: valid = false } - case Type_Info_Rune: + case ^Type_Info_Rune: r := a.(rune) value = f64(i32(r)) valid = true - case Type_Info_Float: + case ^Type_Info_Float: valid = true switch v in a { case f16: value = f64(v) @@ -1426,7 +1426,7 @@ as_f64 :: proc(a: any) -> (value: f64, valid: bool) { case: valid = false } - case Type_Info_Boolean: + case ^Type_Info_Boolean: valid = true switch v in a { case bool: value = f64(i32(v)) @@ -1437,7 +1437,7 @@ as_f64 :: proc(a: any) -> (value: f64, valid: bool) { case: valid = false } - case Type_Info_Complex: + case ^Type_Info_Complex: switch v in a { case complex32: if imag(v) == 0 { @@ -1456,7 +1456,7 @@ as_f64 :: proc(a: any) -> (value: f64, valid: bool) { } } - case Type_Info_Quaternion: + case ^Type_Info_Quaternion: switch v in a { case quaternion64: if imag(v) == 0 && jmag(v) == 0 && kmag(v) == 0 { @@ -1488,7 +1488,7 @@ as_string :: proc(a: any) -> (value: string, valid: bool) { a.id = ti.id #partial switch info in ti.variant { - case Type_Info_String: + case ^Type_Info_String: valid = true switch v in a { case string: value = v @@ -1551,11 +1551,11 @@ as_pointer :: proc(a: any) -> (value: rawptr, valid: bool) { a.id = ti.id #partial switch info in ti.variant { - case Type_Info_Pointer: + case ^Type_Info_Pointer: valid = true value = (^rawptr)(a.data)^ - case Type_Info_String: + case ^Type_Info_String: valid = true switch v in a { case cstring: value = rawptr(v) @@ -1575,7 +1575,7 @@ as_raw_data :: proc(a: any) -> (value: rawptr, valid: bool) { a.id = ti.id #partial switch info in ti.variant { - case Type_Info_String: + case ^Type_Info_String: valid = true switch v in a { case string: value = raw_data(v) @@ -1583,15 +1583,15 @@ as_raw_data :: proc(a: any) -> (value: rawptr, valid: bool) { case: valid = false } - case Type_Info_Array: + case ^Type_Info_Array: valid = true value = a.data - case Type_Info_Slice: + case ^Type_Info_Slice: valid = true value = (^runtime.Raw_Slice)(a.data).data - case Type_Info_Dynamic_Array: + case ^Type_Info_Dynamic_Array: valid = true value = (^runtime.Raw_Dynamic_Array)(a.data).data } @@ -1643,24 +1643,24 @@ equal :: proc(a, b: any, including_indirect_array_recursion := false, recursion_ t = runtime.type_info_core(t) switch v in t.variant { - case Type_Info_Named: + case ^Type_Info_Named: unreachable() - case Type_Info_Parameters: + case ^Type_Info_Parameters: unreachable() - case Type_Info_Any: + case ^Type_Info_Any: if !including_indirect_array_recursion { return false } va := (^any)(a.data) vb := (^any)(b.data) return equal(va, vb, including_indirect_array_recursion, recursion_level+1) - case Type_Info_Map: + case ^Type_Info_Map: return false - case Type_Info_Float: + case ^Type_Info_Float: x, _ := as_f64(a) y, _ := as_f64(b) return x == y - case Type_Info_Complex: + case ^Type_Info_Complex: switch x in a { case complex32: #no_type_assert y := b.(complex32) @@ -1673,7 +1673,7 @@ equal :: proc(a, b: any, including_indirect_array_recursion := false, recursion_ return x == y } return false - case Type_Info_Quaternion: + case ^Type_Info_Quaternion: switch x in a { case quaternion64: #no_type_assert y := b.(quaternion64) @@ -1687,21 +1687,21 @@ equal :: proc(a, b: any, including_indirect_array_recursion := false, recursion_ } return false case - Type_Info_Boolean, - Type_Info_Integer, - Type_Info_Rune, - Type_Info_Type_Id, - Type_Info_Pointer, - Type_Info_Multi_Pointer, - Type_Info_Procedure, - Type_Info_Bit_Set, - Type_Info_Enum, - Type_Info_Simd_Vector, - Type_Info_Soa_Pointer, - Type_Info_Matrix: + ^Type_Info_Boolean, + ^Type_Info_Integer, + ^Type_Info_Rune, + ^Type_Info_Type_Id, + ^Type_Info_Pointer, + ^Type_Info_Multi_Pointer, + ^Type_Info_Procedure, + ^Type_Info_Bit_Set, + ^Type_Info_Enum, + ^Type_Info_Simd_Vector, + ^Type_Info_Soa_Pointer, + ^Type_Info_Matrix: return runtime.memory_compare(a.data, b.data, t.size) == 0 - case Type_Info_String: + case ^Type_Info_String: if v.is_cstring { x := string((^cstring)(a.data)^) y := string((^cstring)(b.data)^) @@ -1712,7 +1712,7 @@ equal :: proc(a, b: any, including_indirect_array_recursion := false, recursion_ return x == y } return true - case Type_Info_Array: + case ^Type_Info_Array: for i in 0.. bool { } switch x in a.variant { - case Type_Info_Named: - y := b.variant.(Type_Info_Named) or_return + case ^Type_Info_Named: + y := b.variant.(^Type_Info_Named) or_return return x.base == y.base - case Type_Info_Integer: - y := b.variant.(Type_Info_Integer) or_return + case ^Type_Info_Integer: + y := b.variant.(^Type_Info_Integer) or_return return x.signed == y.signed && x.endianness == y.endianness - case Type_Info_Rune: - _, ok := b.variant.(Type_Info_Rune) + case ^Type_Info_Rune: + _, ok := b.variant.(^Type_Info_Rune) return ok - case Type_Info_Float: - _, ok := b.variant.(Type_Info_Float) + case ^Type_Info_Float: + _, ok := b.variant.(^Type_Info_Float) return ok - case Type_Info_Complex: - _, ok := b.variant.(Type_Info_Complex) + case ^Type_Info_Complex: + _, ok := b.variant.(^Type_Info_Complex) return ok - case Type_Info_Quaternion: - _, ok := b.variant.(Type_Info_Quaternion) + case ^Type_Info_Quaternion: + _, ok := b.variant.(^Type_Info_Quaternion) return ok - case Type_Info_Type_Id: - _, ok := b.variant.(Type_Info_Type_Id) + case ^Type_Info_Type_Id: + _, ok := b.variant.(^Type_Info_Type_Id) return ok - case Type_Info_String: - _, ok := b.variant.(Type_Info_String) + case ^Type_Info_String: + _, ok := b.variant.(^Type_Info_String) return ok - case Type_Info_Boolean: - _, ok := b.variant.(Type_Info_Boolean) + case ^Type_Info_Boolean: + _, ok := b.variant.(^Type_Info_Boolean) return ok - case Type_Info_Any: - _, ok := b.variant.(Type_Info_Any) + case ^Type_Info_Any: + _, ok := b.variant.(^Type_Info_Any) return ok - case Type_Info_Pointer: - y := b.variant.(Type_Info_Pointer) or_return + case ^Type_Info_Pointer: + y := b.variant.(^Type_Info_Pointer) or_return return are_types_identical(x.elem, y.elem) - case Type_Info_Multi_Pointer: - y := b.variant.(Type_Info_Multi_Pointer) or_return + case ^Type_Info_Multi_Pointer: + y := b.variant.(^Type_Info_Multi_Pointer) or_return return are_types_identical(x.elem, y.elem) - case Type_Info_Soa_Pointer: - y := b.variant.(Type_Info_Soa_Pointer) or_return + case ^Type_Info_Soa_Pointer: + y := b.variant.(^Type_Info_Soa_Pointer) or_return return are_types_identical(x.elem, y.elem) - case Type_Info_Procedure: - y := b.variant.(Type_Info_Procedure) or_return + case ^Type_Info_Procedure: + y := b.variant.(^Type_Info_Procedure) or_return switch { case x.variadic != y.variadic, x.convention != y.convention: @@ -82,27 +82,27 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool { return are_types_identical(x.params, y.params) && are_types_identical(x.results, y.results) - case Type_Info_Array: - y := b.variant.(Type_Info_Array) or_return + case ^Type_Info_Array: + y := b.variant.(^Type_Info_Array) or_return if x.count != y.count { return false } return are_types_identical(x.elem, y.elem) - case Type_Info_Enumerated_Array: - y := b.variant.(Type_Info_Enumerated_Array) or_return + case ^Type_Info_Enumerated_Array: + y := b.variant.(^Type_Info_Enumerated_Array) or_return if x.count != y.count { return false } return are_types_identical(x.index, y.index) && are_types_identical(x.elem, y.elem) - case Type_Info_Dynamic_Array: - y := b.variant.(Type_Info_Dynamic_Array) or_return + case ^Type_Info_Dynamic_Array: + y := b.variant.(^Type_Info_Dynamic_Array) or_return return are_types_identical(x.elem, y.elem) - case Type_Info_Slice: - y := b.variant.(Type_Info_Slice) or_return + case ^Type_Info_Slice: + y := b.variant.(^Type_Info_Slice) or_return return are_types_identical(x.elem, y.elem) - case Type_Info_Parameters: - y := b.variant.(Type_Info_Parameters) or_return + case ^Type_Info_Parameters: + y := b.variant.(^Type_Info_Parameters) or_return if len(x.types) != len(y.types) { return false } for _, i in x.types { xt, yt := x.types[i], y.types[i] @@ -112,8 +112,8 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool { } return true - case Type_Info_Struct: - y := b.variant.(Type_Info_Struct) or_return + case ^Type_Info_Struct: + y := b.variant.(^Type_Info_Struct) or_return switch { case x.field_count != y.field_count, x.flags != y.flags, @@ -133,8 +133,8 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool { } return true - case Type_Info_Union: - y := b.variant.(Type_Info_Union) or_return + case ^Type_Info_Union: + y := b.variant.(^Type_Info_Union) or_return if len(x.variants) != len(y.variants) { return false } for _, i in x.variants { @@ -143,31 +143,31 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool { } return true - case Type_Info_Enum: + case ^Type_Info_Enum: // NOTE(bill): Should be handled above return false - case Type_Info_Map: - y := b.variant.(Type_Info_Map) or_return + case ^Type_Info_Map: + y := b.variant.(^Type_Info_Map) or_return return are_types_identical(x.key, y.key) && are_types_identical(x.value, y.value) - case Type_Info_Bit_Set: - y := b.variant.(Type_Info_Bit_Set) or_return + case ^Type_Info_Bit_Set: + y := b.variant.(^Type_Info_Bit_Set) or_return return x.elem == y.elem && x.lower == y.lower && x.upper == y.upper - case Type_Info_Simd_Vector: - y := b.variant.(Type_Info_Simd_Vector) or_return + case ^Type_Info_Simd_Vector: + y := b.variant.(^Type_Info_Simd_Vector) or_return return x.count == y.count && x.elem == y.elem - case Type_Info_Matrix: - y := b.variant.(Type_Info_Matrix) or_return + case ^Type_Info_Matrix: + y := b.variant.(^Type_Info_Matrix) or_return if x.row_count != y.row_count { return false } if x.column_count != y.column_count { return false } if x.layout != y.layout { return false } return are_types_identical(x.elem, y.elem) - case Type_Info_Bit_Field: - y := b.variant.(Type_Info_Bit_Field) or_return + case ^Type_Info_Bit_Field: + y := b.variant.(^Type_Info_Bit_Field) or_return if !are_types_identical(x.backing_type, y.backing_type) { return false } if x.field_count != y.field_count { return false } for _, i in x.names[:x.field_count] { @@ -191,8 +191,8 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool { is_signed :: proc(info: ^Type_Info) -> bool { if info == nil { return false } #partial switch i in type_info_base(info).variant { - case Type_Info_Integer: return i.signed - case Type_Info_Float: return true + case ^Type_Info_Integer: return i.signed + case ^Type_Info_Float: return true } return false } @@ -200,8 +200,8 @@ is_signed :: proc(info: ^Type_Info) -> bool { is_unsigned :: proc(info: ^Type_Info) -> bool { if info == nil { return false } #partial switch i in type_info_base(info).variant { - case Type_Info_Integer: return !i.signed - case Type_Info_Float: return false + case ^Type_Info_Integer: return !i.signed + case ^Type_Info_Float: return false } return false } @@ -210,7 +210,7 @@ is_unsigned :: proc(info: ^Type_Info) -> bool { is_byte :: proc(info: ^Type_Info) -> bool { if info == nil { return false } #partial switch i in type_info_base(info).variant { - case Type_Info_Integer: return info.size == 1 + case ^Type_Info_Integer: return info.size == 1 } return false } @@ -219,83 +219,83 @@ is_byte :: proc(info: ^Type_Info) -> bool { @(require_results) is_integer :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Integer) + _, ok := type_info_base(info).variant.(^Type_Info_Integer) return ok } @(require_results) is_rune :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Rune) + _, ok := type_info_base(info).variant.(^Type_Info_Rune) return ok } @(require_results) is_float :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Float) + _, ok := type_info_base(info).variant.(^Type_Info_Float) return ok } @(require_results) is_complex :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Complex) + _, ok := type_info_base(info).variant.(^Type_Info_Complex) return ok } @(require_results) is_quaternion :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Quaternion) + _, ok := type_info_base(info).variant.(^Type_Info_Quaternion) return ok } @(require_results) is_any :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Any) + _, ok := type_info_base(info).variant.(^Type_Info_Any) return ok } @(require_results) is_string :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_String) + _, ok := type_info_base(info).variant.(^Type_Info_String) return ok } @(require_results) is_cstring :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - v, ok := type_info_base(info).variant.(Type_Info_String) + v, ok := type_info_base(info).variant.(^Type_Info_String) return ok && v.is_cstring } @(require_results) is_boolean :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Boolean) + _, ok := type_info_base(info).variant.(^Type_Info_Boolean) return ok } @(require_results) is_pointer :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Pointer) + _, ok := type_info_base(info).variant.(^Type_Info_Pointer) return ok } @(require_results) is_multi_pointer :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Multi_Pointer) + _, ok := type_info_base(info).variant.(^Type_Info_Multi_Pointer) return ok } @(require_results) is_soa_pointer :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Soa_Pointer) + _, ok := type_info_base(info).variant.(^Type_Info_Soa_Pointer) return ok } @(require_results) 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: + case ^Type_Info_Pointer, ^Type_Info_Multi_Pointer, + ^Type_Info_Procedure: return true - case Type_Info_String: + case ^Type_Info_String: return v.is_cstring } return false @@ -303,79 +303,79 @@ is_pointer_internally :: proc(info: ^Type_Info) -> bool { @(require_results) is_procedure :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Procedure) + _, ok := type_info_base(info).variant.(^Type_Info_Procedure) return ok } @(require_results) is_array :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Array) + _, ok := type_info_base(info).variant.(^Type_Info_Array) return ok } @(require_results) is_enumerated_array :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Enumerated_Array) + _, ok := type_info_base(info).variant.(^Type_Info_Enumerated_Array) return ok } @(require_results) is_dynamic_array :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Dynamic_Array) + _, ok := type_info_base(info).variant.(^Type_Info_Dynamic_Array) return ok } @(require_results) is_dynamic_map :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Map) + _, ok := type_info_base(info).variant.(^Type_Info_Map) return ok } @(require_results) is_bit_set :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Bit_Set) + _, ok := type_info_base(info).variant.(^Type_Info_Bit_Set) return ok } @(require_results) is_slice :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Slice) + _, ok := type_info_base(info).variant.(^Type_Info_Slice) return ok } @(require_results) is_parameters :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Parameters) + _, ok := type_info_base(info).variant.(^Type_Info_Parameters) return ok } @(require_results) is_struct :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - s, ok := type_info_base(info).variant.(Type_Info_Struct) - return ok && .raw_union not_in s.flags + s, ok := type_info_base(info).variant.(^Type_Info_Struct) + return ok && .raw_union not_in s.struct_flags } @(require_results) is_raw_union :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - s, ok := type_info_base(info).variant.(Type_Info_Struct) - return ok && .raw_union in s.flags + s, ok := type_info_base(info).variant.(^Type_Info_Struct) + return ok && .raw_union in s.struct_flags } @(require_results) is_union :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Union) + _, ok := type_info_base(info).variant.(^Type_Info_Union) return ok } @(require_results) is_enum :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Enum) + _, ok := type_info_base(info).variant.(^Type_Info_Enum) return ok } @(require_results) is_simd_vector :: proc(info: ^Type_Info) -> bool { if info == nil { return false } - _, ok := type_info_base(info).variant.(Type_Info_Simd_Vector) + _, ok := type_info_base(info).variant.(^Type_Info_Simd_Vector) return ok } @@ -386,14 +386,14 @@ is_endian_platform :: proc(info: ^Type_Info) -> bool { info := info info = type_info_core(info) #partial switch v in info.variant { - case Type_Info_Integer: + case ^Type_Info_Integer: return v.endianness == .Platform - case Type_Info_Bit_Set: + case ^Type_Info_Bit_Set: if v.underlying != nil { return is_endian_platform(v.underlying) } return true - case Type_Info_Pointer: + case ^Type_Info_Pointer: return true } return false @@ -405,17 +405,17 @@ is_endian_little :: proc(info: ^Type_Info) -> bool { info := info info = type_info_core(info) #partial switch v in info.variant { - case Type_Info_Integer: + case ^Type_Info_Integer: if v.endianness == .Platform { return ODIN_ENDIAN == .Little } return v.endianness == .Little - case Type_Info_Bit_Set: + case ^Type_Info_Bit_Set: if v.underlying != nil { return is_endian_platform(v.underlying) } return ODIN_ENDIAN == .Little - case Type_Info_Pointer: + case ^Type_Info_Pointer: return ODIN_ENDIAN == .Little } return ODIN_ENDIAN == .Little @@ -427,17 +427,17 @@ is_endian_big :: proc(info: ^Type_Info) -> bool { info := info info = type_info_core(info) #partial switch v in info.variant { - case Type_Info_Integer: + case ^Type_Info_Integer: if v.endianness == .Platform { return ODIN_ENDIAN == .Big } return v.endianness == .Big - case Type_Info_Bit_Set: + case ^Type_Info_Bit_Set: if v.underlying != nil { return is_endian_platform(v.underlying) } return ODIN_ENDIAN == .Big - case Type_Info_Pointer: + case ^Type_Info_Pointer: return ODIN_ENDIAN == .Big } return ODIN_ENDIAN == .Big @@ -477,9 +477,9 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt } switch info in ti.variant { - case Type_Info_Named: + case ^Type_Info_Named: io.write_string(w, info.name, &n) or_return - case Type_Info_Integer: + case ^Type_Info_Integer: switch ti.id { case int: io.write_string(w, "int", &n) or_return case uint: io.write_string(w, "uint", &n) or_return @@ -493,9 +493,9 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt case .Big: io.write_string(w, "be", &n) or_return } } - case Type_Info_Rune: + case ^Type_Info_Rune: io.write_string(w, "rune", &n) or_return - case Type_Info_Float: + case ^Type_Info_Float: io.write_byte(w, 'f', &n) or_return io.write_i64(w, i64(8*ti.size), 10, &n) or_return switch info.endianness { @@ -503,50 +503,50 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt case .Little: io.write_string(w, "le", &n) or_return case .Big: io.write_string(w, "be", &n) or_return } - case Type_Info_Complex: + case ^Type_Info_Complex: io.write_string(w, "complex", &n) or_return io.write_i64(w, i64(8*ti.size), 10, &n) or_return - case Type_Info_Quaternion: + case ^Type_Info_Quaternion: io.write_string(w, "quaternion", &n) or_return io.write_i64(w, i64(8*ti.size), 10, &n) or_return - case Type_Info_String: + case ^Type_Info_String: if info.is_cstring { io.write_string(w, "cstring", &n) or_return } else { io.write_string(w, "string", &n) or_return } - case Type_Info_Boolean: + case ^Type_Info_Boolean: switch ti.id { case bool: io.write_string(w, "bool", &n) or_return case: io.write_byte(w, 'b', &n) or_return io.write_i64(w, i64(8*ti.size), 10, &n) or_return } - case Type_Info_Any: + case ^Type_Info_Any: io.write_string(w, "any", &n) or_return - case Type_Info_Type_Id: + case ^Type_Info_Type_Id: io.write_string(w, "typeid", &n) or_return - case Type_Info_Pointer: + case ^Type_Info_Pointer: if info.elem == nil { io.write_string(w, "rawptr", &n) or_return } else { io.write_string(w, "^", &n) or_return write_type(w, info.elem, &n) or_return } - case Type_Info_Multi_Pointer: + case ^Type_Info_Multi_Pointer: io.write_string(w, "[^]", &n) or_return write_type(w, info.elem, &n) or_return - case Type_Info_Soa_Pointer: + case ^Type_Info_Soa_Pointer: io.write_string(w, "#soa ^", &n) or_return write_type(w, info.elem, &n) or_return - case Type_Info_Procedure: + case ^Type_Info_Procedure: io.write_string(w, "proc", &n) or_return if info.params == nil { io.write_string(w, "()", &n) or_return } else { - t := info.params.variant.(Type_Info_Parameters) + t := info.params.variant.(^Type_Info_Parameters) io.write_string(w, "(", &n) or_return for t, i in t.types { if i > 0 { @@ -560,7 +560,7 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt io.write_string(w, " -> ", &n) or_return write_type(w, info.results, &n) or_return } - case Type_Info_Parameters: + case ^Type_Info_Parameters: count := len(info.names) if count != 1 { io.write_string(w, "(", &n) or_return @@ -580,13 +580,13 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt io.write_string(w, ")", &n) or_return } - case Type_Info_Array: + case ^Type_Info_Array: io.write_string(w, "[", &n) or_return io.write_i64(w, i64(info.count), 10, &n) or_return io.write_string(w, "]", &n) or_return write_type(w, info.elem, &n) or_return - case Type_Info_Enumerated_Array: + case ^Type_Info_Enumerated_Array: if info.is_sparse { io.write_string(w, "#sparse", &n) or_return } @@ -595,20 +595,20 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt io.write_string(w, "]", &n) or_return write_type(w, info.elem, &n) or_return - case Type_Info_Dynamic_Array: + case ^Type_Info_Dynamic_Array: io.write_string(w, "[dynamic]", &n) or_return write_type(w, info.elem, &n) or_return - case Type_Info_Slice: + case ^Type_Info_Slice: io.write_string(w, "[]", &n) or_return write_type(w, info.elem, &n) or_return - case Type_Info_Map: + case ^Type_Info_Map: io.write_string(w, "map[", &n) or_return write_type(w, info.key, &n) or_return io.write_byte(w, ']', &n) or_return write_type(w, info.value, &n) or_return - case Type_Info_Struct: + case ^Type_Info_Struct: switch info.soa_kind { case .None: // Ignore case .Fixed: @@ -628,10 +628,10 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt } io.write_string(w, "struct ", &n) or_return - if .packed in info.flags { io.write_string(w, "#packed ", &n) or_return } - if .raw_union in info.flags { io.write_string(w, "#raw_union ", &n) or_return } - if .no_copy in info.flags { io.write_string(w, "#no_copy ", &n) or_return } - if .align in info.flags { + if .packed in info.struct_flags { io.write_string(w, "#packed ", &n) or_return } + if .raw_union in info.struct_flags { io.write_string(w, "#raw_union ", &n) or_return } + if .no_copy in info.struct_flags { io.write_string(w, "#no_copy ", &n) or_return } + if .align in info.struct_flags { io.write_string(w, "#align(", &n) or_return io.write_i64(w, i64(ti.align), 10, &n) or_return io.write_string(w, ") ", &n) or_return @@ -645,7 +645,7 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt } io.write_byte(w, '}', &n) or_return - case Type_Info_Union: + case ^Type_Info_Union: io.write_string(w, "union ", &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 } @@ -661,7 +661,7 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt } io.write_byte(w, '}', &n) or_return - case Type_Info_Enum: + case ^Type_Info_Enum: io.write_string(w, "enum ", &n) or_return write_type(w, info.base, &n) or_return io.write_string(w, " {", &n) or_return @@ -671,7 +671,7 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt } io.write_byte(w, '}', &n) or_return - case Type_Info_Bit_Set: + case ^Type_Info_Bit_Set: io.write_string(w, "bit_set[", &n) or_return switch { case is_enum(info.elem): @@ -691,7 +691,7 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt } io.write_byte(w, ']', &n) or_return - case Type_Info_Bit_Field: + case ^Type_Info_Bit_Field: io.write_string(w, "bit_field ", &n) or_return write_type(w, info.backing_type, &n) or_return io.write_string(w, " {", &n) or_return @@ -705,13 +705,13 @@ write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_writt } io.write_string(w, "}", &n) or_return - case Type_Info_Simd_Vector: + case ^Type_Info_Simd_Vector: io.write_string(w, "#simd[", &n) or_return io.write_i64(w, i64(info.count), 10, &n) or_return io.write_byte(w, ']', &n) or_return write_type(w, info.elem, &n) or_return - case Type_Info_Matrix: + case ^Type_Info_Matrix: if info.layout == .Row_Major { io.write_string(w, "#row_major ", &n) or_return } diff --git a/core/slice/map.odin b/core/slice/map.odin index c68488d2660..3b03f2f54d6 100644 --- a/core/slice/map.odin +++ b/core/slice/map.odin @@ -52,7 +52,7 @@ map_entry_infos :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (ent m := m rm := (^runtime.Raw_Map)(&m) - info := runtime.type_info_base(type_info_of(M)).variant.(runtime.Type_Info_Map) + info := runtime.type_info_base(type_info_of(M)).variant.(^runtime.Type_Info_Map) if info.map_info != nil { entries = make(type_of(entries), len(m), allocator) or_return diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 9308eab8eb6..75f9c908031 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -10501,6 +10501,8 @@ gb_internal ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *no } if (!ok) { + ERROR_BLOCK(); + gbString expr_str = expr_to_string(o->expr); gbString dst_type_str = type_to_string(t); defer (gb_string_free(expr_str)); @@ -10509,6 +10511,18 @@ gb_internal ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *no error(o->expr, "Cannot type assert '%s' to '%s' as this is an empty union", expr_str, dst_type_str); } else { error(o->expr, "Cannot type assert '%s' to '%s' as it is not a variant of that union", expr_str, dst_type_str); + + for (Type *vt : bsrc->Union.variants) { + Type *xt = type_deref(vt); + Type *yt = type_deref(t); + if (are_types_identical(xt, yt)) { + gbString s = type_to_string(vt); + error_line("\tDid you mean: '%s'?", s); + gb_string_free(s); + break; + } + } + } o->mode = Addressing_Invalid; o->expr = node; diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index d92edf41d4b..b950c9a46ce 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1501,9 +1501,23 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ } } if (!tag_type_found) { + ERROR_BLOCK(); + gbString type_str = type_to_string(y.type); error(y.expr, "Unknown variant type, got '%s'", type_str); gb_string_free(type_str); + + for (Type *vt : bt->Union.variants) { + Type *xt = type_deref(vt); + Type *yt = type_deref(y.type); + if (are_types_identical(xt, yt)) { + gbString s = type_to_string(vt); + error_line("\tDid you mean: '%s'?", s); + gb_string_free(s); + break; + } + } + continue; } case_type = y.type; diff --git a/src/llvm_backend_type.cpp b/src/llvm_backend_type.cpp index 4e514c3d14a..eba926abc66 100644 --- a/src/llvm_backend_type.cpp +++ b/src/llvm_backend_type.cpp @@ -40,17 +40,23 @@ gb_internal u64 lb_typeid_kind(lbModule *m, Type *type, u64 id=0) { TypeKind tk = bt->kind; switch (tk) { case Type_Basic: { + switch (bt->Basic.kind) { + case Basic_typeid: return Typeid_Type_Id; + case Basic_any: return Typeid_Any; + case Basic_rune: return Typeid_Rune; + } + u32 flags = bt->Basic.flags; - if (flags & BasicFlag_Boolean) kind = Typeid_Boolean; - if (flags & BasicFlag_Integer) kind = Typeid_Integer; - if (flags & BasicFlag_Unsigned) kind = Typeid_Integer; - if (flags & BasicFlag_Float) kind = Typeid_Float; - if (flags & BasicFlag_Complex) kind = Typeid_Complex; - if (flags & BasicFlag_Pointer) kind = Typeid_Pointer; - if (flags & BasicFlag_String) kind = Typeid_String; - if (flags & BasicFlag_Rune) kind = Typeid_Rune; - - if (bt->Basic.kind == Basic_typeid) kind = Typeid_Type_Id; + if (0) {} + else if (flags & BasicFlag_Boolean) kind = Typeid_Boolean; + else if (flags & BasicFlag_Integer) kind = Typeid_Integer; + else if (flags & BasicFlag_Unsigned) kind = Typeid_Integer; + else if (flags & BasicFlag_Float) kind = Typeid_Float; + else if (flags & BasicFlag_Complex) kind = Typeid_Complex; + else if (flags & BasicFlag_Quaternion) kind = Typeid_Quaternion; + else if (flags & BasicFlag_Pointer) kind = Typeid_Pointer; + else if (flags & BasicFlag_String) kind = Typeid_String; + else GB_PANIC("Unhandled basic type"); } break; case Type_Pointer: kind = Typeid_Pointer; break; case Type_MultiPointer: kind = Typeid_Multi_Pointer; break; @@ -162,60 +168,17 @@ gb_internal lbValue lb_type_info_member_tags_offset(lbModule *m, isize count, i6 } gb_internal LLVMTypeRef *lb_setup_modified_types_for_type_info(lbModule *m, isize max_type_info_count) { - LLVMTypeRef *element_types = gb_alloc_array(heap_allocator(), LLVMTypeRef, max_type_info_count); - defer (gb_free(heap_allocator(), element_types)); - - auto entries_handled = slice_make(heap_allocator(), max_type_info_count); - defer (gb_free(heap_allocator(), entries_handled.data)); - entries_handled[0] = true; - - element_types[0] = lb_type(m, t_type_info); - Type *tibt = base_type(t_type_info); GB_ASSERT(tibt->kind == Type_Struct); Type *ut = base_type(tibt->Struct.fields[tibt->Struct.fields.count-1]->type); GB_ASSERT(ut->kind == Type_Union); - GB_ASSERT(tibt->Struct.fields.count == 5); - LLVMTypeRef stypes[6] = {}; - stypes[0] = lb_type(m, tibt->Struct.fields[0]->type); - stypes[1] = lb_type(m, tibt->Struct.fields[1]->type); - stypes[2] = lb_type(m, tibt->Struct.fields[2]->type); - isize variant_index = 0; - if (build_context.ptr_size == 8) { - stypes[3] = lb_type(m, t_i32); // padding - stypes[4] = lb_type(m, tibt->Struct.fields[3]->type); - variant_index = 5; - } else { - stypes[3] = lb_type(m, tibt->Struct.fields[3]->type); - variant_index = 4; - } - LLVMTypeRef *modified_types = gb_alloc_array(heap_allocator(), LLVMTypeRef, Typeid__COUNT); GB_ASSERT(Typeid__COUNT == ut->Union.variants.count); - modified_types[0] = element_types[0]; - - i64 tag_offset = ut->Union.variant_block_size; - LLVMTypeRef tag = lb_type(m, union_tag_type(ut)); - for_array(i, ut->Union.variants) { - Type *t = ut->Union.variants[i]; - LLVMTypeRef padding = llvm_array_type(lb_type(m, t_u8), tag_offset-type_size_of(t)); - - LLVMTypeRef vtypes[3] = {}; - vtypes[0] = lb_type(m, t); - vtypes[1] = padding; - vtypes[2] = tag; - LLVMTypeRef variant_type = LLVMStructType(vtypes, gb_count_of(vtypes), true); - - stypes[variant_index] = variant_type; - LLVMTypeRef modified_type = LLVMStructType(stypes, cast(unsigned)(variant_index+1), false); - - modified_types[i] = modified_type; - } - - for (isize i = 0; i < Typeid__COUNT; i++) { - GB_ASSERT_MSG(modified_types[i] != nullptr, "%td", ut->Union.variants.count); + Type *pt = ut->Union.variants[i]; + Type *t = type_deref(pt); + modified_types[i] = lb_type(m, t); } return modified_types; @@ -288,7 +251,8 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ } - LLVMValueRef *small_const_values = gb_alloc_array(heap_allocator(), LLVMValueRef, 6); + enum {SMALL_CONST_VALUES_COUNT = 6}; + LLVMValueRef *small_const_values = gb_alloc_array(heap_allocator(), LLVMValueRef, SMALL_CONST_VALUES_COUNT); defer (gb_free(heap_allocator(), small_const_values)); #define type_info_allocate_values(name) \ @@ -337,7 +301,6 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ } entries_handled[entry_index] = true; - LLVMTypeRef stype = nullptr; if (t->kind == Type_Named) { stype = modified_types[0]; @@ -345,39 +308,8 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ stype = modified_types[lb_typeid_kind(m, t)]; } - i64 size = type_size_of(t); - i64 align = type_align_of(t); - u32 flags = type_info_flags_of_type(t); - lbValue id = lb_typeid(m, t); - GB_ASSERT_MSG(align != 0, "%lld %s", align, type_to_string(t)); - - lbValue type_info_flags = lb_const_int(m, t_type_info_flags, flags); - - for (isize i = 0; i < 6; i++) { - small_const_values[i] = nullptr; - } - - small_const_values[0] = LLVMConstInt(lb_type(m, t_int), size, true); - small_const_values[1] = LLVMConstInt(lb_type(m, t_int), align, true); - small_const_values[2] = type_info_flags.value; - - unsigned variant_index = 0; - if (build_context.ptr_size == 8) { - small_const_values[3] = LLVMConstNull(LLVMStructGetTypeAtIndex(stype, 3)); - small_const_values[4] = id.value; - variant_index = 5; - } else { - small_const_values[3] = id.value; - variant_index = 4; - } - - LLVMTypeRef full_variant_type = LLVMStructGetTypeAtIndex(stype, variant_index); - unsigned full_variant_elem_count = LLVMCountStructElementTypes(full_variant_type); - if (full_variant_elem_count != 2) { - GB_ASSERT_MSG(LLVMCountStructElementTypes(full_variant_type) == 3, "%lld %s", entry_index, type_to_string(t)); // blob, padding, tag - } + LLVMValueRef vals[32] = {}; - LLVMValueRef variant_value = nullptr; Type *tag_type = nullptr; switch (t->kind) { @@ -402,14 +334,11 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ lbValue loc = lb_const_source_code_location_as_global_ptr(m, proc_name, pos); - LLVMValueRef vals[4] = { - lb_const_string(m, t->Named.type_name->token.string).value, - get_type_info_ptr(m, t->Named.base), - pkg_name, - loc.value - }; - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = lb_const_string(m, t->Named.type_name->token.string).value; + vals[2] = get_type_info_ptr(m, t->Named.base); + vals[3] = pkg_name; + vals[4] = loc.value; break; } @@ -466,12 +395,8 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ } lbValue endianness = lb_const_int(m, t_u8, endianness_value); - LLVMValueRef vals[2] = { - is_signed.value, - endianness.value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = is_signed.value; + vals[2] = endianness.value; break; } @@ -500,11 +425,7 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ } lbValue endianness = lb_const_int(m, t_u8, endianness_value); - LLVMValueRef vals[1] = { - endianness.value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = endianness.value; } break; @@ -522,21 +443,17 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ case Basic_rawptr: tag_type = t_type_info_pointer; + vals[1] = LLVMConstNull(lb_type(m, t_type_info_ptr)); break; case Basic_string: tag_type = t_type_info_string; + vals[1] = lb_const_bool(m, t_bool, false).value; break; case Basic_cstring: - { - tag_type = t_type_info_string; - LLVMValueRef vals[1] = { - lb_const_bool(m, t_bool, true).value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); - } + tag_type = t_type_info_string; + vals[1] = lb_const_bool(m, t_bool, true).value; break; case Basic_any: @@ -549,90 +466,53 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ } break; - case Type_Pointer: { + case Type_Pointer: tag_type = t_type_info_pointer; - LLVMValueRef vals[1] = { - get_type_info_ptr(m, t->Pointer.elem), - }; - - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = get_type_info_ptr(m, t->Pointer.elem); break; - } - case Type_MultiPointer: { + case Type_MultiPointer: tag_type = t_type_info_multi_pointer; - - LLVMValueRef vals[1] = { - get_type_info_ptr(m, t->MultiPointer.elem), - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = get_type_info_ptr(m, t->MultiPointer.elem); break; - } - case Type_SoaPointer: { + case Type_SoaPointer: tag_type = t_type_info_soa_pointer; - - LLVMValueRef vals[1] = { - get_type_info_ptr(m, t->SoaPointer.elem), - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = get_type_info_ptr(m, t->SoaPointer.elem); break; - } case Type_Array: { tag_type = t_type_info_array; i64 ez = type_size_of(t->Array.elem); - LLVMValueRef vals[3] = { - get_type_info_ptr(m, t->Array.elem), - lb_const_int(m, t_int, ez).value, - lb_const_int(m, t_int, t->Array.count).value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = get_type_info_ptr(m, t->Array.elem); + vals[2] = lb_const_int(m, t_int, ez).value; + vals[3] = lb_const_int(m, t_int, t->Array.count).value; break; } - case Type_EnumeratedArray: { + case Type_EnumeratedArray: tag_type = t_type_info_enumerated_array; - LLVMValueRef vals[7] = { - get_type_info_ptr(m, t->EnumeratedArray.elem), - get_type_info_ptr(m, t->EnumeratedArray.index), - lb_const_int(m, t_int, type_size_of(t->EnumeratedArray.elem)).value, - lb_const_int(m, t_int, t->EnumeratedArray.count).value, + vals[1] = get_type_info_ptr(m, t->EnumeratedArray.elem); + vals[2] = get_type_info_ptr(m, t->EnumeratedArray.index); + vals[3] = lb_const_int(m, t_int, type_size_of(t->EnumeratedArray.elem)).value; + vals[4] = lb_const_int(m, t_int, t->EnumeratedArray.count).value; // Unions - lb_const_value(m, t_type_info_enum_value, *t->EnumeratedArray.min_value).value, - lb_const_value(m, t_type_info_enum_value, *t->EnumeratedArray.max_value).value, + vals[5] = lb_const_value(m, t_type_info_enum_value, *t->EnumeratedArray.min_value).value; + vals[6] = lb_const_value(m, t_type_info_enum_value, *t->EnumeratedArray.max_value).value; - lb_const_bool(m, t_bool, t->EnumeratedArray.is_sparse).value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[7] = lb_const_bool(m, t_bool, t->EnumeratedArray.is_sparse).value; break; - } - case Type_DynamicArray: { + case Type_DynamicArray: tag_type = t_type_info_dynamic_array; - LLVMValueRef vals[2] = { - get_type_info_ptr(m, t->DynamicArray.elem), - lb_const_int(m, t_int, type_size_of(t->DynamicArray.elem)).value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = get_type_info_ptr(m, t->DynamicArray.elem); + vals[2] = lb_const_int(m, t_int, type_size_of(t->DynamicArray.elem)).value; break; - } - case Type_Slice: { + case Type_Slice: tag_type = t_type_info_slice; - LLVMValueRef vals[2] = { - get_type_info_ptr(m, t->Slice.elem), - lb_const_int(m, t_int, type_size_of(t->Slice.elem)).value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = get_type_info_ptr(m, t->Slice.elem); + vals[2] = lb_const_int(m, t_int, type_size_of(t->Slice.elem)).value; break; - } case Type_Proc: { tag_type = t_type_info_procedure; @@ -645,14 +525,10 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ results = get_type_info_ptr(m, t->Proc.results); } - LLVMValueRef vals[4] = { - params, - results, - lb_const_bool(m, t_bool, t->Proc.variadic).value, - lb_const_int(m, t_u8, t->Proc.calling_convention).value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = params; + vals[2] = results; + vals[3] = lb_const_bool(m, t_bool, t->Proc.variadic).value; + vals[4] = lb_const_int(m, t_u8, t->Proc.calling_convention).value; break; } case Type_Tuple: { @@ -680,63 +556,49 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ LLVMValueRef types_slice = llvm_const_slice(m, memory_types, count); LLVMValueRef names_slice = llvm_const_slice(m, memory_names, count); - LLVMValueRef vals[2] = { - types_slice, - names_slice, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = types_slice; + vals[2] = names_slice; break; } case Type_Enum: tag_type = t_type_info_enum; - - { - GB_ASSERT(t->Enum.base_type != nullptr); - // GB_ASSERT_MSG(type_size_of(t_type_info_enum_value) == 16, "%lld == 16", cast(long long)type_size_of(t_type_info_enum_value)); - - - LLVMValueRef vals[3] = {}; - vals[0] = get_type_info_ptr(m, t->Enum.base_type); - if (t->Enum.fields.count > 0) { - auto fields = t->Enum.fields; - lbValue name_array = lb_generate_global_array(m, t_string, fields.count, - str_lit("$enum_names"), cast(i64)entry_index); - lbValue value_array = lb_generate_global_array(m, t_type_info_enum_value, fields.count, - str_lit("$enum_values"), cast(i64)entry_index); + GB_ASSERT(t->Enum.base_type != nullptr); + vals[1] = get_type_info_ptr(m, t->Enum.base_type); + if (t->Enum.fields.count > 0) { + auto fields = t->Enum.fields; + lbValue name_array = lb_generate_global_array(m, t_string, fields.count, + str_lit("$enum_names"), cast(i64)entry_index); + lbValue value_array = lb_generate_global_array(m, t_type_info_enum_value, fields.count, + str_lit("$enum_values"), cast(i64)entry_index); - LLVMValueRef *name_values = gb_alloc_array(temporary_allocator(), LLVMValueRef, fields.count); - LLVMValueRef *value_values = gb_alloc_array(temporary_allocator(), LLVMValueRef, fields.count); + LLVMValueRef *name_values = gb_alloc_array(temporary_allocator(), LLVMValueRef, fields.count); + LLVMValueRef *value_values = gb_alloc_array(temporary_allocator(), LLVMValueRef, fields.count); - GB_ASSERT(is_type_integer(t->Enum.base_type)); + GB_ASSERT(is_type_integer(t->Enum.base_type)); - for_array(i, fields) { - name_values[i] = lb_const_string(m, fields[i]->token.string).value; - value_values[i] = lb_const_value(m, t_i64, fields[i]->Constant.value).value; - } - - LLVMValueRef name_init = llvm_const_array(lb_type(m, t_string), name_values, cast(unsigned)fields.count); - LLVMValueRef value_init = llvm_const_array(lb_type(m, t_type_info_enum_value), value_values, cast(unsigned)fields.count); - LLVMSetInitializer(name_array.value, name_init); - LLVMSetInitializer(value_array.value, value_init); - LLVMSetGlobalConstant(name_array.value, true); - LLVMSetGlobalConstant(value_array.value, true); - lb_set_odin_rtti_section(name_array.value); - lb_set_odin_rtti_section(value_array.value); - - lbValue v_count = lb_const_int(m, t_int, fields.count); - - vals[1] = llvm_const_slice(m, lbValue{name_array.value, alloc_type_pointer(t_string)}, v_count); - vals[2] = llvm_const_slice(m, lbValue{value_array.value, alloc_type_pointer(t_type_info_enum_value)}, v_count); - } else { - vals[1] = LLVMConstNull(lb_type(m, base_type(t_type_info_enum)->Struct.fields[1]->type)); - vals[2] = LLVMConstNull(lb_type(m, base_type(t_type_info_enum)->Struct.fields[2]->type)); + for_array(i, fields) { + name_values[i] = lb_const_string(m, fields[i]->token.string).value; + value_values[i] = lb_const_value(m, t_i64, fields[i]->Constant.value).value; } + LLVMValueRef name_init = llvm_const_array(lb_type(m, t_string), name_values, cast(unsigned)fields.count); + LLVMValueRef value_init = llvm_const_array(lb_type(m, t_type_info_enum_value), value_values, cast(unsigned)fields.count); + LLVMSetInitializer(name_array.value, name_init); + LLVMSetInitializer(value_array.value, value_init); + LLVMSetGlobalConstant(name_array.value, true); + LLVMSetGlobalConstant(value_array.value, true); + lb_set_odin_rtti_section(name_array.value); + lb_set_odin_rtti_section(value_array.value); + + lbValue v_count = lb_const_int(m, t_int, fields.count); - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[2] = llvm_const_slice(m, lbValue{name_array.value, alloc_type_pointer(t_string)}, v_count); + vals[3] = llvm_const_slice(m, lbValue{value_array.value, alloc_type_pointer(t_type_info_enum_value)}, v_count); + } else { + vals[2] = LLVMConstNull(LLVMStructGetTypeAtIndex(stype, 2)); + vals[3] = LLVMConstNull(LLVMStructGetTypeAtIndex(stype, 3)); } break; @@ -744,8 +606,6 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ tag_type = t_type_info_union; { - LLVMValueRef vals[7] = {}; - isize variant_count = gb_max(0, t->Union.variants.count); i64 variant_offset = 0; lbValue memory_types = lb_type_info_member_types_offset(m, variant_count, &variant_offset); @@ -756,33 +616,27 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ } lbValue count = lb_const_int(m, t_int, variant_count); - vals[0] = llvm_const_slice(m, memory_types, count); + vals[1] = llvm_const_slice(m, memory_types, count); i64 tag_size = union_tag_size(t); if (tag_size > 0) { i64 tag_offset = align_formula(t->Union.variant_block_size, tag_size); - vals[1] = lb_const_int(m, t_uintptr, tag_offset).value; - vals[2] = get_type_info_ptr(m, union_tag_type(t)); + vals[2] = lb_const_int(m, t_uintptr, tag_offset).value; + vals[3] = get_type_info_ptr(m, union_tag_type(t)); } else { - vals[1] = lb_const_int(m, t_uintptr, 0).value; - vals[2] = LLVMConstNull(lb_type(m, t_type_info_ptr)); + vals[2] = lb_const_int(m, t_uintptr, 0).value; + vals[3] = LLVMConstNull(lb_type(m, t_type_info_ptr)); } if (is_type_comparable(t) && !is_type_simple_compare(t)) { - vals[3] = lb_equal_proc_for_type(m, t).value; - } - - vals[4] = lb_const_bool(m, t_bool, t->Union.custom_align != 0).value; - vals[5] = lb_const_bool(m, t_bool, t->Union.kind == UnionType_no_nil).value; - vals[6] = lb_const_bool(m, t_bool, t->Union.kind == UnionType_shared_nil).value; - - for (isize i = 0; i < gb_count_of(vals); i++) { - if (vals[i] == nullptr) { - vals[i] = LLVMConstNull(lb_type(m, get_struct_field_type(tag_type, i))); - } + vals[4] = lb_equal_proc_for_type(m, t).value; + } else { + vals[4] = LLVMConstNull(lb_type(m, t_equal_proc)); } - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[5] = lb_const_bool(m, t_bool, t->Union.custom_align != 0).value; + vals[6] = lb_const_bool(m, t_bool, t->Union.kind == UnionType_no_nil).value; + vals[7] = lb_const_bool(m, t_bool, t->Union.kind == UnionType_shared_nil).value; } break; @@ -791,8 +645,6 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ case Type_Struct: { tag_type = t_type_info_struct; - LLVMValueRef vals[11] = {}; - { u8 flags = 0; if (t->Struct.is_packed) flags |= 1<<0; @@ -800,23 +652,31 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ if (t->Struct.is_no_copy) flags |= 1<<2; if (t->Struct.custom_align) flags |= 1<<3; - vals[6] = lb_const_int(m, t_u8, flags).value; + vals[7] = lb_const_int(m, t_u8, flags).value; if (is_type_comparable(t) && !is_type_simple_compare(t)) { - vals[10] = lb_equal_proc_for_type(m, t).value; + vals[13] = lb_equal_proc_for_type(m, t).value; + } else { + vals[13] = LLVMConstNull(lb_type(m, t_equal_proc)); } + Type *soa_kind_type = get_struct_field_type(tag_type, 7); if (t->Struct.soa_kind != StructSoa_None) { - Type *kind_type = get_struct_field_type(tag_type, 7); - lbValue soa_kind = lb_const_value(m, kind_type, exact_value_i64(t->Struct.soa_kind)); + lbValue soa_kind = lb_const_value(m, soa_kind_type, exact_value_i64(t->Struct.soa_kind)); LLVMValueRef soa_type = get_type_info_ptr(m, t->Struct.soa_elem); lbValue soa_len = lb_const_int(m, t_i32, t->Struct.soa_count); - vals[7] = soa_kind.value; - vals[8] = soa_len.value; - vals[9] = soa_type; + vals[8] = soa_kind.value; + vals[10] = soa_len.value; + vals[12] = soa_type; + } else { + vals[8] = LLVMConstNull(lb_type(m, soa_kind_type)); + vals[10] = LLVMConstNull(lb_type(m, t_i32)); + vals[12] = LLVMConstNull(lb_type(m, t_type_info_ptr)); } + vals[9] = LLVMConstNull(lb_type(m, base_type(t_type_info_struct)->Struct.fields[9]->type)); + vals[11] = LLVMConstNull(lb_type(m, base_type(t_type_info_struct)->Struct.fields[11]->type)); } isize count = t->Struct.fields.count; @@ -863,70 +723,53 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ } lbValue cv = lb_const_int(m, t_i32, count); - vals[0] = memory_types.value; - vals[1] = memory_names.value; - vals[2] = memory_offsets.value; - vals[3] = memory_usings.value; - vals[4] = memory_tags.value; - vals[5] = cv.value; - } - for (isize i = 0; i < gb_count_of(vals); i++) { - if (vals[i] == nullptr) { - vals[i] = LLVMConstNull(lb_type(m, get_struct_field_type(tag_type, i))); - } + vals[1] = memory_types.value; + vals[2] = memory_names.value; + vals[3] = memory_offsets.value; + vals[4] = memory_usings.value; + vals[5] = memory_tags.value; + vals[6] = cv.value; + } else { + vals[1] = LLVMConstNull(lb_type(m, base_type(t_type_info_struct)->Struct.fields[1]->type)); + vals[2] = LLVMConstNull(lb_type(m, base_type(t_type_info_struct)->Struct.fields[2]->type)); + vals[3] = LLVMConstNull(lb_type(m, base_type(t_type_info_struct)->Struct.fields[3]->type)); + vals[4] = LLVMConstNull(lb_type(m, base_type(t_type_info_struct)->Struct.fields[4]->type)); + vals[5] = LLVMConstNull(lb_type(m, base_type(t_type_info_struct)->Struct.fields[5]->type)); + vals[6] = LLVMConstNull(lb_type(m, base_type(t_type_info_struct)->Struct.fields[6]->type)); } - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); break; } - case Type_Map: { + case Type_Map: tag_type = t_type_info_map; init_map_internal_debug_types(t); - LLVMValueRef vals[3] = { - get_type_info_ptr(m, t->Map.key), - get_type_info_ptr(m, t->Map.value), - lb_gen_map_info_ptr(m, t).value - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = get_type_info_ptr(m, t->Map.key); + vals[2] = get_type_info_ptr(m, t->Map.value); + vals[3] = lb_gen_map_info_ptr(m, t).value; break; - } case Type_BitSet: - { - tag_type = t_type_info_bit_set; - - GB_ASSERT(is_type_typed(t->BitSet.elem)); + tag_type = t_type_info_bit_set; + GB_ASSERT(is_type_typed(t->BitSet.elem)); - LLVMValueRef vals[4] = { - get_type_info_ptr(m, t->BitSet.elem), - LLVMConstNull(lb_type(m, t_type_info_ptr)), - lb_const_int(m, t_i64, t->BitSet.lower).value, - lb_const_int(m, t_i64, t->BitSet.upper).value, - }; - if (t->BitSet.underlying != nullptr) { - vals[1] = get_type_info_ptr(m, t->BitSet.underlying); - } + vals[1] = get_type_info_ptr(m, t->BitSet.elem); + vals[2] = LLVMConstNull(lb_type(m, t_type_info_ptr)); + vals[3] = lb_const_int(m, t_i64, t->BitSet.lower).value; + vals[4] = lb_const_int(m, t_i64, t->BitSet.upper).value; - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + if (t->BitSet.underlying != nullptr) { + vals[2] = get_type_info_ptr(m, t->BitSet.underlying); } break; case Type_SimdVector: - { - tag_type = t_type_info_simd_vector; - - LLVMValueRef vals[3] = {}; - - vals[0] = get_type_info_ptr(m, t->SimdVector.elem); - vals[1] = lb_const_int(m, t_int, type_size_of(t->SimdVector.elem)).value; - vals[2] = lb_const_int(m, t_int, t->SimdVector.count).value; + tag_type = t_type_info_simd_vector; - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); - } + vals[1] = get_type_info_ptr(m, t->SimdVector.elem); + vals[2] = lb_const_int(m, t_int, type_size_of(t->SimdVector.elem)).value; + vals[3] = lb_const_int(m, t_int, t->SimdVector.count).value; break; case Type_Matrix: @@ -934,16 +777,12 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ tag_type = t_type_info_matrix; i64 ez = type_size_of(t->Matrix.elem); - LLVMValueRef vals[6] = { - get_type_info_ptr(m, t->Matrix.elem), - lb_const_int(m, t_int, ez).value, - lb_const_int(m, t_int, matrix_type_stride_in_elems(t)).value, - lb_const_int(m, t_int, t->Matrix.row_count).value, - lb_const_int(m, t_int, t->Matrix.column_count).value, - lb_const_int(m, t_u8, cast(u8)t->Matrix.is_row_major).value, - }; - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); + vals[1] = get_type_info_ptr(m, t->Matrix.elem); + vals[2] = lb_const_int(m, t_int, ez).value; + vals[3] = lb_const_int(m, t_int, matrix_type_stride_in_elems(t)).value; + vals[4] = lb_const_int(m, t_int, t->Matrix.row_count).value; + vals[5] = lb_const_int(m, t_int, t->Matrix.column_count).value; + vals[6] = lb_const_int(m, t_u8, cast(u8)t->Matrix.is_row_major).value; } break; @@ -951,8 +790,7 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ { tag_type = t_type_info_bit_field; - LLVMValueRef vals[7] = {}; - vals[0] = get_type_info_ptr(m, t->BitField.backing_type); + vals[1] = get_type_info_ptr(m, t->BitField.backing_type); isize count = t->BitField.fields.count; if (count > 0) { i64 names_offset = 0; @@ -992,64 +830,81 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ } lbValue cv = lb_const_int(m, t_int, count); - vals[1] = memory_names.value; - vals[2] = memory_types.value; - vals[3] = memory_bit_sizes.value; - vals[4] = memory_bit_offsets.value; - vals[5] = memory_tags.value; - vals[6] = cv.value; - } - - - for (isize i = 0; i < gb_count_of(vals); i++) { - if (vals[i] == nullptr) { - vals[i] = LLVMConstNull(lb_type(m, get_struct_field_type(tag_type, i))); - } + vals[2] = memory_names.value; + vals[3] = memory_types.value; + vals[4] = memory_bit_sizes.value; + vals[5] = memory_bit_offsets.value; + vals[6] = memory_tags.value; + vals[7] = cv.value; + } else { + vals[2] = LLVMConstNull(lb_type(m, base_type(t_type_info_bit_field)->Struct.fields[2]->type)); + vals[3] = LLVMConstNull(lb_type(m, base_type(t_type_info_bit_field)->Struct.fields[3]->type)); + vals[4] = LLVMConstNull(lb_type(m, base_type(t_type_info_bit_field)->Struct.fields[4]->type)); + vals[5] = LLVMConstNull(lb_type(m, base_type(t_type_info_bit_field)->Struct.fields[5]->type)); + vals[6] = LLVMConstNull(lb_type(m, base_type(t_type_info_bit_field)->Struct.fields[6]->type)); + vals[7] = LLVMConstNull(lb_type(m, base_type(t_type_info_bit_field)->Struct.fields[7]->type)); } - - variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals)); break; } } + i64 size = type_size_of(t); + i64 align = type_align_of(t); + u32 flags = type_info_flags_of_type(t); + lbValue id = lb_typeid(m, t); + GB_ASSERT_MSG(align != 0, "%lld %s", align, type_to_string(t)); + + lbValue type_info_flags = lb_const_int(m, t_type_info_flags, flags); + + for (isize i = 0; i < SMALL_CONST_VALUES_COUNT; i++) { + small_const_values[i] = nullptr; + } + + small_const_values[0] = LLVMConstInt(lb_type(m, t_int), size, true); + small_const_values[1] = LLVMConstInt(lb_type(m, t_int), align, true); + small_const_values[2] = type_info_flags.value; + small_const_values[3] = id.value; + unsigned const VARIANT_INDEX_IN_STRUCT = 4; i64 tag_index = 0; if (tag_type != nullptr) { - tag_index = union_variant_index(ut, tag_type); + tag_index = union_variant_index(ut, alloc_type_pointer(tag_type)); } GB_ASSERT(tag_index <= Typeid__COUNT); - LLVMValueRef full_variant_values[3] = {}; + LLVMValueRef full_variant_values[2] = {}; - if (full_variant_elem_count == 2) { - if (variant_value == nullptr) { - full_variant_values[0] = LLVMConstNull(LLVMStructGetTypeAtIndex(full_variant_type, 0)); - full_variant_values[1] = LLVMConstInt(LLVMStructGetTypeAtIndex(full_variant_type, 1), tag_index, false); - } else { - full_variant_values[0] = variant_value; - full_variant_values[1] = LLVMConstInt(LLVMStructGetTypeAtIndex(full_variant_type, 1), tag_index, false); - } - } else { - if (variant_value == nullptr) { - variant_value = LLVMConstNull(LLVMStructGetTypeAtIndex(full_variant_type, 0)); - } else { - GB_ASSERT_MSG(LLVMStructGetTypeAtIndex(full_variant_type, 0) == LLVMTypeOf(variant_value), - "\n%s -> %s\n%s vs %s\n", - type_to_string(t), LLVMPrintValueToString(variant_value), - LLVMPrintTypeToString(LLVMStructGetTypeAtIndex(full_variant_type, 0)), LLVMPrintTypeToString(LLVMTypeOf(variant_value)) - ); - } + LLVMTypeRef type_info_base_type = LLVMStructGetTypeAtIndex(stype, 0); + LLVMTypeRef variant_type = LLVMStructGetTypeAtIndex(type_info_base_type, LLVMCountStructElementTypes(type_info_base_type)-1); - full_variant_values[0] = variant_value; - full_variant_values[1] = LLVMConstNull(LLVMStructGetTypeAtIndex(full_variant_type, 1)); - full_variant_values[2] = LLVMConstInt(LLVMStructGetTypeAtIndex(full_variant_type, 2), tag_index, false); + if (tag_type == nullptr) { + full_variant_values[0] = LLVMConstNull(LLVMStructGetTypeAtIndex(variant_type, 0)); + full_variant_values[1] = LLVMConstInt(LLVMStructGetTypeAtIndex(variant_type, 1), tag_index, false); + } else { + full_variant_values[0] = LLVMConstPointerCast(giant_const_values[entry_index], LLVMStructGetTypeAtIndex(variant_type, 0)); + full_variant_values[1] = LLVMConstInt(LLVMStructGetTypeAtIndex(variant_type, 1), tag_index, false); } - LLVMValueRef full_variant_value = LLVMConstNamedStruct(full_variant_type, full_variant_values, full_variant_elem_count); + LLVMValueRef full_variant_value = LLVMConstNamedStruct(variant_type, full_variant_values, 2); - small_const_values[variant_index] = full_variant_value; + small_const_values[VARIANT_INDEX_IN_STRUCT] = full_variant_value; - LLVMSetInitializer(giant_const_values[entry_index], LLVMConstNamedStruct(stype, small_const_values, variant_index+1)); + vals[0] = LLVMConstNamedStruct(LLVMStructGetTypeAtIndex(stype, 0), small_const_values, VARIANT_INDEX_IN_STRUCT+1); + + unsigned total_elem_count = LLVMCountStructElementTypes(stype); + for (unsigned i = 0; i < total_elem_count; i++) { + if (vals[i] == nullptr) { + if (i+1 == total_elem_count) { + LLVMTypeRef end_type = LLVMStructGetTypeAtIndex(stype, i); + GB_ASSERT_MSG(LLVMGetTypeKind(end_type) == LLVMArrayTypeKind, "%s %s %u < %u %s", LLVMPrintTypeToString(end_type), type_to_string(tag_type), i, total_elem_count, LLVMPrintTypeToString(stype)); + vals[i] = LLVMConstNull(end_type); + } else { + GB_PANIC("HERE! %s %u < %u %s %d", type_to_string(tag_type), i, total_elem_count, LLVMPrintTypeToString(stype), lb_typeid_kind(m, t)); + } + } + } + + LLVMSetInitializer(giant_const_values[entry_index], LLVMConstNamedStruct(stype, vals, total_elem_count)); } for (isize i = 0; i < global_type_info_data_entity_count; i++) { auto *ptr = &giant_const_values[i]; @@ -1083,9 +938,7 @@ gb_internal void lb_setup_type_info_data(lbModule *m) { // NOTE(bill): Setup typ GB_ASSERT(type->kind == Type_Array); global_type_info_data_entity_count = type->Array.count; - if (true) { - lb_setup_type_info_data_giant_array(m, global_type_info_data_entity_count); - } + lb_setup_type_info_data_giant_array(m, global_type_info_data_entity_count); LLVMValueRef data = lb_global_type_info_data_ptr(m).value; data = LLVMConstPointerCast(data, lb_type(m, alloc_type_pointer(type->Array.elem)));