Add tuple type
This commit is contained in:
@@ -152,6 +152,25 @@ type_slice(Ast_Type *base, Ast *ast){
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Ast_Type *
|
||||||
|
type_tuple(Array<Ast_Resolved_Member> 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 *
|
function Ast_Type *
|
||||||
type_array(Ast_Type *base, S64 size){
|
type_array(Ast_Type *base, S64 size){
|
||||||
U64 hash_base = hash_ptr(base);
|
U64 hash_base = hash_ptr(base);
|
||||||
|
|||||||
2
types.h
2
types.h
@@ -32,6 +32,7 @@ enum Ast_Type_Kind{
|
|||||||
TYPE_ENUM,
|
TYPE_ENUM,
|
||||||
TYPE_TYPE,
|
TYPE_TYPE,
|
||||||
TYPE_SLICE,
|
TYPE_SLICE,
|
||||||
|
TYPE_TUPLE,
|
||||||
|
|
||||||
TYPE_UNTYPED_FIRST = TYPE_UNTYPED_BOOL,
|
TYPE_UNTYPED_FIRST = TYPE_UNTYPED_BOOL,
|
||||||
TYPE_UNTYPED_LAST = TYPE_UNTYPED_STRING,
|
TYPE_UNTYPED_LAST = TYPE_UNTYPED_STRING,
|
||||||
@@ -134,6 +135,7 @@ docname(Ast_Type *type){
|
|||||||
case TYPE_ENUM: return "[Enum]";
|
case TYPE_ENUM: return "[Enum]";
|
||||||
case TYPE_TYPE: return "[Type]";
|
case TYPE_TYPE: return "[Type]";
|
||||||
case TYPE_SLICE: return "[Slice]";
|
case TYPE_SLICE: return "[Slice]";
|
||||||
|
case TYPE_TUPLE: return "[Tuple]";
|
||||||
invalid_default_case;
|
invalid_default_case;
|
||||||
}
|
}
|
||||||
return "<Unknown_Type>";
|
return "<Unknown_Type>";
|
||||||
|
|||||||
Reference in New Issue
Block a user