Repository navigation
Expand file tree
/
Copy pathtypes.odin
More file actions
796 lines (722 loc) · 25.1 KB
/
Copy pathtypes.odin
File metadata and controls
796 lines (722 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
package reflect
import "core:io"
import "core:strings"
// Returns true when the `^Type_Info`s are semantically equivalent types
// Note: The pointers being identical should be enough to check but this is done to make sure in certain cases where it is non-trivial
// and each value wants to be checked directly.
@(require_results)
are_types_identical :: proc(a, b: ^Type_Info) -> bool {
if a == b {
return true
}
if a == nil || b == nil {
return false
}
switch {
case a.size != b.size, a.align != b.align:
return false
}
switch x in a.variant {
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
return x.signed == y.signed && x.endianness == y.endianness
case Type_Info_Rune:
_, ok := b.variant.(Type_Info_Rune)
return ok
case Type_Info_Float:
_, ok := b.variant.(Type_Info_Float)
return ok
case Type_Info_Complex:
_, ok := b.variant.(Type_Info_Complex)
return ok
case Type_Info_Quaternion:
_, ok := b.variant.(Type_Info_Quaternion)
return ok
case Type_Info_Type_Id:
_, ok := b.variant.(Type_Info_Type_Id)
return ok
case Type_Info_String:
_, ok := b.variant.(Type_Info_String)
return ok
case Type_Info_Boolean:
_, ok := b.variant.(Type_Info_Boolean)
return ok
case Type_Info_Any:
_, ok := b.variant.(Type_Info_Any)
return ok
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
return are_types_identical(x.elem, y.elem)
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
switch {
case x.variadic != y.variadic,
x.convention != y.convention:
return false
}
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
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
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
return are_types_identical(x.elem, y.elem)
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
if len(x.types) != len(y.types) { return false }
for _, i in x.types {
xt, yt := x.types[i], y.types[i]
if !are_types_identical(xt, yt) {
return false
}
}
return true
case Type_Info_Struct:
y := b.variant.(Type_Info_Struct) or_return
switch {
case x.field_count != y.field_count,
x.flags != y.flags,
x.soa_kind != y.soa_kind,
x.soa_base_type != y.soa_base_type,
x.soa_len != y.soa_len:
return false
}
for i in 0..<x.field_count {
xn, yn := x.names[i], y.names[i]
xt, yt := x.types[i], y.types[i]
xl, yl := x.tags[i], y.tags[i]
if xn != yn { return false }
if !are_types_identical(xt, yt) { return false }
if xl != yl { return false }
}
return true
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 {
xv, yv := x.variants[i], y.variants[i]
if !are_types_identical(xv, yv) { return false }
}
return true
case Type_Info_Enum:
// NOTE(bill): Should be handled above
return false
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
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
return x.count == y.count && x.elem == y.elem
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
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] {
if x.names[i] != y.names[i] {
return false
}
if !are_types_identical(x.types[i], y.types[i]) {
return false
}
if x.bit_sizes[i] != y.bit_sizes[i] {
return false
}
}
return true
}
return false
}
// Returns true if the base-type is a signed integer or just a float, false otherwise.
@(require_results)
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
}
return false
}
// Returns true if the base-type is an usigned integer, false otherwise.
@(require_results)
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
}
return false
}
// Returns true when it is a 1-byte wide integer type, false otherwise.
@(require_results)
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
}
return false
}
// Returns true the base-type is an integer of any kind, false otherwise.
@(require_results)
is_integer :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Integer)
return ok
}
// Returns true the base-type is a rune, false otherwise.
@(require_results)
is_rune :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Rune)
return ok
}
// Returns true the base-type is a float of any kind, false otherwise.
@(require_results)
is_float :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Float)
return ok
}
// Returns true the base-type is a complex-type of any kind, false otherwise.
@(require_results)
is_complex :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
10BC8
div>
_, ok := type_info_base(info).variant.(Type_Info_Complex)
return ok
}
// Returns true the base-type is a quaternions any kind, false otherwise.
@(require_results)
is_quaternion :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Quaternion)
return ok
}
// Returns true the base-type is an `any`, false otherwise.
@(require_results)
is_any :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Any)
return ok
}
// Returns true the base-type is a string of any kind (string, cstring, string16, cstring16), false otherwise.
@(require_results)
is_string :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_String)
return ok
}
// Returns true the base-type is a cstring of any kind (cstring, cstring16), false otherwise.
@(require_results)
is_cstring :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
v, ok := type_info_base(info).variant.(Type_Info_String)
return ok && v.is_cstring
}
// Returns true the base-type is a string of any kind (string16, cstring16), false otherwise.
@(require_results)
is_string16 :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
v, ok := type_info_base(info).variant.(Type_Info_String)
return ok && v.encoding == .UTF_16
}
// Returns true the base-type is a cstring of any kind (cstring16), false otherwise.
@(require_results)
is_cstring16 :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
v, ok := type_info_base(info).variant.(Type_Info_String)
return ok && v.is_cstring && v.encoding == .UTF_16
}
// Returns true the base-type is a boolean of any kind, false otherwise.
@(require_results)
is_boolean :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Boolean)
return ok
}
// Returns true the base-type is a pointer-type of any kind (^T or rawptr), false otherwise.
@(require_results)
is_pointer :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Pointer)
return ok
}
// Returns true the base-type is a pointer-type of any kind ([^]T), false otherwise.
@(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)
return ok
}
// Returns true the base-type is a pointer-type of any kind (#soa^T), false otherwise.
@(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)
return ok
}
// Returns true when the type is a pointer-like type, false otherwise.
@(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:
return true
case Type_Info_String:
return v.is_cstring
}
return false
}
// Returns true when the type is a procedure type, false otherwise.
@(require_results)
is_procedure :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Procedure)
return ok
}
// Returns true when the type is a fixed-array type ([N]T), false otherwise.
@(require_results)
is_array :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Array)
return ok
}
// Returns true when the type is an enumerated-array type ([Enum]T), false otherwise.
@(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)
return ok
}
// Returns true when the type is a dynamic-array type ([dynamic]T), false otherwise.
@(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)
return ok
}
// Returns true when the type is a map type (map[K]V), false otherwise.
@(require_results)
is_dynamic_map :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Map)
return ok
}
// Returns true when the type is a bit_set type, false otherwise.
@(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)
return ok
}
// Returns true when the type is a slice type ([]T), false otherwise.
@(require_results)
is_slice :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Slice)
return ok
}
// Returns true when the type represents a set of parameters for a procedure (inputs or outputs), false otherwise.
@(require_results)
is_parameters :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Parameters)
return ok
}
// Returns true when the type is a struct type, `#raw_union` will be false. All other types will be false otherwise.
@(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
}
// Returns true when the type is a struct type with `#raw_union` applied, when `#raw_union` is not applied, the value will be false. All other types will be false otherwise.
@(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
}
// Returns true when the type is a union type (not `#raw_union`), false otherwise.
@(require_results)
is_union :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Union)
return ok
}
// Returns true when the type is an enum type, false otherwise.
@(require_results)
is_enum :: proc(info: ^Type_Info) -> bool {
if info == nil { return false }
_, ok := type_info_base(info).variant.(Type_Info_Enum)
return ok
}
// Returns true when the type is a #simd-array type (#simd[N]T), false otherwise.
@(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)
return ok
}
// Returns true when the core-type is represented with a platform-native endian type, and returns false otherwise.
// This will also return false when the type is not an integer, pointer, or bit_set.
// If the type is the same as the platform-native endian type (e.g. `u32le` on a little-endian system), this will return false.
@(require_results)
is_endian_platform :: proc(info: ^Type_Info) -> bool {
if info == nil { return false}
info := info
info = type_info_core(info)
#partial switch v in info.variant {
case Type_Info_Integer:
return v.endianness == .Platform
case Type_Info_Bit_Set:
if v.underlying != nil {
return is_endian_platform(v.underlying)
}
return true
case Type_Info_Pointer:
return true
}
return false
}
// Returns true when the core-type is represented with a platform-native endian type or the same endianness as the system.
// This will also return false when the type is not an integer, pointer, or bit_set.
// If the type is the same as the platform-native endian type (e.g. `u32le` on a little-endian system), this will return true.
@(require_results)
is_endian_little :: proc(info: ^Type_Info) -> bool {
if info == nil { return false}
info := info
info = type_info_core(info)
#partial switch v in info.variant {
case Type_Info_Integer:
if v.endianness == .Platform {
return ODIN_ENDIAN == .Little
}
return v.endianness == .Little
case Type_Info_Bit_Set:
if v.underlying != nil {
return is_endian_platform(v.underlying)
}
return ODIN_ENDIAN == .Little
case Type_Info_Pointer:
return ODIN_ENDIAN == .Little
}
return ODIN_ENDIAN == .Little
}
// Returns true when the core-type is represented with a platform-native endian type or the same endianness as the system.
// This will also return false when the type is not an integer, pointer, or bit_set.
// If the type is the same as the platform-native endian type (e.g. `u32be` on a big-endian system), this will return true.
@(require_results)
is_endian_big :: proc(info: ^Type_Info) -> bool {
if info == nil { return false}
info := info
info = type_info_core(info)
#partial switch v in info.variant {
case Type_Info_Integer:
if v.endianness == .Platform {
return ODIN_ENDIAN == .Big
}
return v.endianness == .Big
case Type_Info_Bit_Set:
if v.underlying != nil {
return is_endian_platform(v.underlying)
}
return ODIN_ENDIAN == .Big
case Type_Info_Pointer:
return ODIN_ENDIAN == .Big
}
return ODIN_ENDIAN == .Big
}
// Writes a typeid in standard (non-canonical) form to a `strings.Builder`
write_typeid_builder :: proc(buf: ^strings.Builder, id: typeid, n_written: ^int = nil) -> (n: int, err: io.Error) {
return write_type_writer(strings.to_writer(buf), type_info_of(id))
}
// Writes a typeid in standard (non-canonical) form to an `io.Writer`
write_typeid_writer :: proc(writer: io.Writer, id: typeid, n_written: ^int = nil) -> (n: int, err: io.Error) {
return write_type_writer(writer, type_info_of(id), n_written)
}
// Writes a typeid in standard (non-canonical) form
write_typeid :: proc{
write_typeid_builder,
write_typeid_writer,
}
// Writes a `^Type_Info` in standard (non-canonical) form
write_type :: proc{
write_type_builder,
write_type_writer,
}
// Writes a `^Type_Info` in standard (non-canonical) form to a `strings.Builder`
write_type_builder :: proc(buf: ^strings.Builder, ti: ^Type_Info) -> int {
n, _ := write_type_writer(strings.to_writer(buf), ti)
return n
}
// Writes a `^Type_Info` in standard (non-canonical) form to an `io.Writer`
write_type_writer :: #force_no_inline proc(w: io.Writer, ti: ^Type_Info, n_written: ^int = nil) -> (n: int, err: io.Error) {
defer if n_written != nil {
n_written^ += n
}
if ti == nil {
io.write_string(w, "nil", &n) or_return
return
}
switch info in ti.variant {
case Type_Info_Named:
io.write_string(w, info.name, &n) or_return
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
case uintptr: io.write_string(w, "uintptr", &n) or_return
case:
io.write_byte(w, 'i' if info.signed else 'u', &n) or_return
io.write_i64(w, i64(8*ti.size), 10, &n) or_return
switch info.endianness {
case .Platform: // Okay
case .Little: io.write_string(w, "le", &n) or_return
case .Big: io.write_string(w, "be", &n) or_return
}
}
case Type_Info_Rune:
io.write_string(w, "rune", &n) or_return
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 {
case .Platform: // Okay
case .Little: io.write_string(w, "le", &n) or_return
case .Big: io.write_string(w, "be", &n) or_return
}
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:
io.write_string(w, "quaternion", &n) or_return
io.write_i64(w, i64(8*ti.size), 10, &n) or_return
case Type_Info_String:
if info.is_cstring {
io.write_byte(w, 'c', &n) or_return
}
io.write_string(w, "string", &n) or_return
switch info.encoding {
case .UTF_8: /**/
case .UTF_16: io.write_string(w, "16", &n) or_return
}
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:
io.write_string(w, "any", &n) or_return
case Type_Info_Type_Id:
io.write_string(w, "typeid", &n) or_return
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:
io.write_string(w, "[^]", &n) or_return
write_type(w, info.elem, &n) or_return
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:
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)
io.write_string(w, "(", &n) or_return
for t, i in t.types {
if i > 0 {
io.write_string(w, ", ", &n) or_return
}
write_type(w, t, &n) or_return
}
io.write_string(w, ")", &n) or_return
}
if info.results != nil {
io.write_string(w, " -> ", &n) or_return
write_type(w, info.results, &n) or_return
}
case Type_Info_Parameters:
count := len(info.names)
if count != 1 {
io.write_string(w, "(", &n) or_return
}
for name, i in info.names {
if i > 0 { io.write_string(w, ", ", &n) or_return }
t := info.types[i]
if len(name) > 0 {
io.write_string(w, name, &n) or_return
io.write_string(w, ": ", &n) or_return
}
write_type(w, t, &n) or_return
}
if count != 1 {
io.write_string(w, ")", &n) or_return
}
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:
if info.is_sparse {
io.write_string(w, "#sparse", &n) or_return
}
io.write_string(w, "[", &n) or_return
write_type(w, info.index, &n) or_return
io.write_string(w, "]", &n) or_return
write_type(w, info.elem, &n) or_return
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:
io.write_string(w, "[]", &n) or_return
write_type(w, info.elem, &n) or_return
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:
switch info.soa_kind {
case .None: // Ignore
case .Fixed:
io.write_string(w, "#soa[", &n) or_return
io.write_i64(w, i64(info.soa_len), 10) or_return
io.write_byte(w, ']', &n) or_return
write_type(w, info.soa_base_type, &n) or_return
return
case .Slice:
io.write_string(w, "#soa[]", &n) or_return
write_type(w, info.soa_base_type, &n) or_return
return
case .Dynamic:
io.write_string(w, "#soa[dynamic]", &n) or_return
write_type(w, info.soa_base_type, &n) or_return
return
}
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 {
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
}
io.write_byte(w, '{', &n) or_return
for name, i in info.names[:info.field_count] {
if i > 0 { io.write_string(w, ", ", &n) or_return }
io.write_string(w, name, &n) or_return
io.write_string(w, ": ", &n) or_return
write_type(w, info.types[i], &n) or_return
}
io.write_byte(w, '}', &n) or_return
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 }
if info.custom_align {
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
}
io.write_byte(w, '{', &n) or_return
for variant, i in info.variants {
if i > 0 { io.write_string(w, ", ", &n) or_return }
write_type(w, variant, &n) or_return
}
io.write_byte(w, '}', &n) or_return
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
for name, i in info.names {
if i > 0 { io.write_string(w, ", ", &n) or_return }
io.write_string(w, name, &n) or_return
}
io.write_byte(w, '}', &n) or_return
case Type_Info_Bit_Set:
io.write_string(w, "bit_set[", &n) or_return
switch {
case is_enum(info.elem):
write_type(w, info.elem, &n) or_return
case is_rune(info.elem):
io.write_encoded_rune(w, rune(info.lower), true, &n) or_return
io.write_string(w, "..=", &n) or_return
io.write_encoded_rune(w, rune(info.upper), true, &n) or_return
case:
io.write_i64(w, info.lower, 10, &n) or_return
io.write_string(w, "..=", &n) or_return
io.write_i64(w, info.upper, 10, &n) or_return
}
if info.underlying != nil {
io.write_string(w, "; ", &n) or_return
write_type(w, info.underlying, &n) or_return
}
io.write_byte(w, ']', &n) or_return
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
for name, i in info.names[:info.field_count] {
if i > 0 { io.write_string(w, ", ", &n) or_return }
io.write_string(w, name, &n) or_return
io.write_string(w, ": ", &n) or_return
write_type(w, info.types[i], &n) or_return
io.write_string(w, " | ", &n) or_return
io.write_u64(w, u64(info.bit_sizes[i]), 10, &n) or_return
}
io.write_string(w, "}", &n) or_return
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:
if info.layout == .Row_Major {
io.write_string(w, "#row_major ", &n) or_return
}
io.write_string(w, "matrix[", &n) or_return
io.write_i64(w, i64(info.row_count), 10, &n) or_return
io.write_string(w, ", ", &n) or_return
io.write_i64(w, i64(info.column_count), 10, &n) or_return
io.write_string(w, "]", &n) or_return
write_type(w, info.elem, &n) or_return
}
return
}