| 1 | module main |
| 2 | |
| 3 | enum TypeKindShape { |
| 4 | void_t |
| 5 | int_t |
| 6 | float_t |
| 7 | ptr_t |
| 8 | array_t |
| 9 | struct_t |
| 10 | func_t |
| 11 | label_t |
| 12 | metadata_t |
| 13 | } |
| 14 | |
| 15 | struct TypeShape { |
| 16 | kind TypeKindShape |
| 17 | width int |
| 18 | elem_type int |
| 19 | len int |
| 20 | fields []int |
| 21 | field_names []string |
| 22 | params []int |
| 23 | ret_type int |
| 24 | is_c_struct bool |
| 25 | is_union bool |
| 26 | is_unsigned bool |
| 27 | } |
| 28 | |
| 29 | struct TypeStoreShape { |
| 30 | mut: |
| 31 | types []TypeShape |
| 32 | cache map[string]int |
| 33 | } |
| 34 | |
| 35 | fn (mut ts TypeStoreShape) register(t TypeShape) int { |
| 36 | id := ts.types.len |
| 37 | ts.types << t |
| 38 | return id |
| 39 | } |
| 40 | |
| 41 | fn (mut ts TypeStoreShape) get_array(elem int, length int) int { |
| 42 | return ts.register(TypeShape{ |
| 43 | kind: .array_t |
| 44 | elem_type: elem |
| 45 | len: length |
| 46 | }) |
| 47 | } |
| 48 | |
| 49 | fn main() { |
| 50 | mut ts := TypeStoreShape{} |
| 51 | ts.cache = map[string]int{} |
| 52 | id := ts.get_array(1, 128) |
| 53 | typ := ts.types[id] |
| 54 | println(typ.len) |
| 55 | println(typ.elem_type) |
| 56 | println(int(typ.kind)) |
| 57 | } |
| 58 | |