diff options
| author | 2022-08-04 22:36:59 +0200 | |
|---|---|---|
| committer | 2022-08-04 22:36:59 +0200 | |
| commit | 0fec7de747d93586eda66ce190f5f3d6715421a4 (patch) | |
| tree | 2c6db93b3e6d3299d530cea20dd6468cf47b43c2 /bootstrap/types.c | |
| parent | 4b2451500b8f085321a041ebc13761a5102f0e6d (diff) | |
struct,unions, compound literals; mostly
Diffstat (limited to 'bootstrap/types.c')
| -rw-r--r-- | bootstrap/types.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/bootstrap/types.c b/bootstrap/types.c index 0353041..7491b4b 100644 --- a/bootstrap/types.c +++ b/bootstrap/types.c @@ -23,7 +23,7 @@ inittypes() { free(types.buckets); types.size = 0; - types.buckets = calloc(types.nbuckets = 16, sizeof(struct typesnode *)); + types.buckets = calloc(types.nbuckets = 64, sizeof(struct typesnode *)); } static u32 @@ -41,20 +41,23 @@ hashtype(const struct type *ty) { break; case TYptr: case TYslice: - h = jkhashv(h, ty->child); + h = jkhashv(h, ty->child->_id); break; case TYarr: - h = jkhashv(h, ty->child); + h = jkhashv(h, ty->child->_id); h = jkhashv(h, ty->length); break; case TYfn: - h = jkhashv(h, ty->fn.retty); + h = jkhashv(h, ty->fn.retty->_id); h = jkhashv(h, ty->fn.params.n); for (int i = 0; i < ty->fn.params.n; ++i) - h = jkhashv(h, ty->fn.params.d[i]); + h = jkhashv(h, ty->fn.params.d[i]->_id); case TYenum: h = jkhashv(h, ty->enu.id); break; + case TYstruct: case TYunion: case TYeunion: + h = jkhashv(h, ty->agg.id); + break; } return h; } @@ -85,7 +88,9 @@ typeeql(const struct type *lhs, const struct type *rhs) { return 0; return 1; case TYenum: - return 0; + return lhs->enu.id == rhs->enu.id; + case TYstruct: case TYunion: case TYeunion: + return lhs->agg.id == rhs->agg.id; } assert(0 && "unreachable"); } @@ -117,16 +122,35 @@ typesput(const struct type *key) { const struct type * interntype(struct type ty) { + static int id; if (!ty.align) ty.align = ty.size; const struct type *ty2 = typesfind(&ty); if (ty2) return ty2; + ty._id = id++; ty2 = typesput(&ty); assert(ty2); return ty2; } +void +uninterntype(const struct type *key) { + u32 hash = hashtype(key); + size_t idx = hash & (types.nbuckets - 1); + for (struct typesnode *n = types.buckets[idx], *prev = NULL; n; n = n->next) { + if (key == &n->ty) { + if (prev) { + prev->next = n->next; + } else { + types.buckets[idx] = n->next; + } + break; + } + prev = n; + } +} + bool completetype(const struct type *ty) { if (ty->t == TYvoid) @@ -135,6 +159,8 @@ completetype(const struct type *ty) { return 0; if (ty->t == TYarr && ty->length < 0) return 0; + if (ty->t == TYstruct || ty->t == TYunion || ty->t == TYeunion) + return !ty->agg.fwd; return 1; } |