diff options
| author | 2022-08-06 14:10:19 +0200 | |
|---|---|---|
| committer | 2022-08-06 14:10:29 +0200 | |
| commit | b8d9ad1f6636f46a832b0f949ce7525ae08f53bd (patch) | |
| tree | 037c7e0a86835b2e284df786e3ba2680b7677cc4 /bootstrap/types.c | |
| parent | 1dd19e56fb81d1334bb21e4aa097f9593576feb7 (diff) | |
basic method calls & many bugfix
Diffstat (limited to 'bootstrap/types.c')
| -rw-r--r-- | bootstrap/types.c | 67 |
1 files changed, 45 insertions, 22 deletions
diff --git a/bootstrap/types.c b/bootstrap/types.c index 7b223f6..f826f9d 100644 --- a/bootstrap/types.c +++ b/bootstrap/types.c @@ -28,36 +28,42 @@ inittypes() { static u32 hashtype(const struct type *ty) { - u32 h = 0; - h = jkhashv(h, ty->t); - h = jkhashv(h, ty->size); - h = jkhashv(h, ty->align); - h = jkhashv(h, ty->konst); + u32 h = FNV1A_INI; + + h = fnv1ai(h, ty->t); + h = fnv1ai(h, ty->konst); + if (ty->t == TYfn) + epri(""); + switch (ty->t) { - case TYvoid: case TYbool: case TYfloat: + case TYvoid: case TYbool: break; - case TYint: - h = jkhashv(h, ty->int_signed); + case TYint: case TYfloat: + h = fnv1az(h, ty->size); + h = fnv1az(h, ty->align); + h = fnv1ai(h, ty->int_signed); break; case TYptr: case TYslice: - h = jkhashv(h, ty->child->_id); + assert(ty->child->size || ty->align == 1); + h = fnv1ai(h, ty->child->_id); break; case TYarr: - h = jkhashv(h, ty->child->_id); - h = jkhashv(h, ty->length); + assert(ty->child->size || ty->align == 1); + h = fnv1ai(h, ty->child->_id); + h = fnv1aI(h, ty->length); break; case TYfn: - h = jkhashv(h, ty->fn.retty->_id); - h = jkhashv(h, ty->fn.params.n); + h = fnv1ai(h, ty->fn.retty->_id); + h = fnv1ai(h, ty->fn.params.n); for (int i = 0; i < ty->fn.params.n; ++i) - h = jkhashv(h, ty->fn.params.d[i]->_id); + h = fnv1ai(h, ty->fn.params.d[i]->_id); break; case TYenum: - h = jkhashv(h, ty->enu.id); + h = fnv1ai(h, ty->enu.id); break; case TYstruct: case TYunion: case TYeunion: - h = jkhashv(h, ty->agg.id); + h = fnv1ai(h, ty->agg.id); break; } return h; @@ -67,15 +73,15 @@ bool typeeql(const struct type *lhs, const struct type *rhs) { if (lhs == rhs) return 1; - if (lhs->t != rhs->t || lhs->size != rhs->size - || lhs->align != rhs->align - || lhs->konst != rhs->konst) + if (lhs->t != rhs->t || lhs->konst != rhs->konst) return 0; switch (lhs->t) { - case TYvoid: case TYbool: case TYfloat: + case TYvoid: case TYbool: return 1; + case TYfloat: + return lhs->size == rhs->size; case TYint: - return lhs->int_signed == rhs->int_signed; + return lhs->size == rhs->size && lhs->int_signed == rhs->int_signed; case TYptr: case TYslice: return typeeql(lhs->child, rhs->child); @@ -139,6 +145,7 @@ typesput(const struct type *key) { nodes->next = types.buckets[idx]; types.buckets[idx] = nodes; } + idx = hash & (types.nbuckets - 1); } n->next = types.buckets[idx]; @@ -151,11 +158,14 @@ interntype(struct type ty) { static int id; if (!ty.align) ty.align = ty.size; + if ((ty.t == TYptr || ty.t == TYarr) && !ty.child->size) + ty.align = 1; const struct type *ty2 = typesfind(&ty); if (ty2) return ty2; ty._id = id++; ty2 = typesput(&ty); + // epri("new %t, h = %d. %d\n", ty2, hashtype(ty2), ty2->agg.id); assert(ty2); return ty2; } @@ -164,13 +174,15 @@ 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) { + types.size--; + 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; } + free(n); break; } prev = n; @@ -384,3 +396,14 @@ typeof2(const struct type *a, const struct type *b) { } return NULL; } + + +void +prialltypes(void) { + for (int i = 0; i < types.nbuckets; ++i) { + epri("bkt %d:\n", i); + for (struct typesnode *n = types.buckets[i]; n; n = n->next) { + epri(" %t : %d\n", &n->ty, hashtype(&n->ty)); + } + } +} |