diff options
| author | gingerBill <bill@gingerbill.org> | 2023-08-07 15:04:03 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-08-07 15:04:03 +0100 |
| commit | 55c9fb7c5c416ff0b94d0a9a531c41662a4eeb54 (patch) | |
| tree | 3147103c25b86ac4c6bb1f4dccfe1a595ad669f3 /src/tilde_builtin.cpp | |
| parent | 8201a9ce6ea1d2a89d51f891305d27f5196dc6c9 (diff) | |
Tilde: Begin work on #soa
Diffstat (limited to 'src/tilde_builtin.cpp')
| -rw-r--r-- | src/tilde_builtin.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tilde_builtin.cpp b/src/tilde_builtin.cpp index d84506e09..012e2c1b9 100644 --- a/src/tilde_builtin.cpp +++ b/src/tilde_builtin.cpp @@ -43,6 +43,26 @@ gb_internal cgValue cg_builtin_len(cgProcedure *p, cgValue value) { } case Type_Struct: GB_ASSERT(is_type_soa_struct(t)); + { + if (t->Struct.soa_kind == StructSoa_Fixed) { + return cg_const_int(p, t_int, t->Struct.soa_count); + } + + GB_ASSERT(t->Struct.soa_kind == StructSoa_Slice || + t->Struct.soa_kind == StructSoa_Dynamic); + + isize n = 0; + Type *elem = base_type(t->Struct.soa_elem); + if (elem->kind == Type_Struct) { + n = cast(isize)elem->Struct.fields.count; + } else if (elem->kind == Type_Array) { + n = cast(isize)elem->Array.count; + } else { + GB_PANIC("Unreachable"); + } + + return cg_emit_struct_ev(p, value, n); + } break; } |