From 185fd8975cba194d39c4ec0d915fa8ac51238f64 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 15 Jun 2022 14:48:05 +0200 Subject: [PATCH] Add tuple type --- typechecking.h | 19 +++++++++++++++++++ types.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/typechecking.h b/typechecking.h index 3b86f50..4b3c57a 100644 --- a/typechecking.h +++ b/typechecking.h @@ -152,6 +152,25 @@ type_slice(Ast_Type *base, Ast *ast){ return result; } +function Ast_Type * +type_tuple(Array types, Ast *ast){ + U64 hash = 1234; + For(types) hash = hash_mix(hash, hash_ptr(it.type)); + Ast_Type *result = (Ast_Type *)map_get(&pctx->type_map, hash); + if(result){ + assert(result->kind == TYPE_TUPLE); + assert(result->agg.members.len == types.len); + return result; + } + // @todo alignment, offsets + + result = type_new(pctx->perm, TYPE_TUPLE, 0, pointer_align); + For(types) result->size += it.type->size; + result->agg.members = types.tight_copy(pctx->perm); + map_insert(&pctx->type_map, hash, result); + return result; +} + function Ast_Type * type_array(Ast_Type *base, S64 size){ U64 hash_base = hash_ptr(base); diff --git a/types.h b/types.h index c65cd6e..e501738 100644 --- a/types.h +++ b/types.h @@ -32,6 +32,7 @@ enum Ast_Type_Kind{ TYPE_ENUM, TYPE_TYPE, TYPE_SLICE, + TYPE_TUPLE, TYPE_UNTYPED_FIRST = TYPE_UNTYPED_BOOL, TYPE_UNTYPED_LAST = TYPE_UNTYPED_STRING, @@ -134,6 +135,7 @@ docname(Ast_Type *type){ case TYPE_ENUM: return "[Enum]"; case TYPE_TYPE: return "[Type]"; case TYPE_SLICE: return "[Slice]"; + case TYPE_TUPLE: return "[Tuple]"; invalid_default_case; } return "";