We are generating basic polymorphic types!
This commit is contained in:
@@ -1042,6 +1042,7 @@ compile_to_c_code() {
|
||||
genln("Type_Info *type_infos = (Type_Info[]){");
|
||||
global_indent++;
|
||||
For_Named(pctx->all_types, t) {
|
||||
if (t->kind == TYPE_POLYMORPH) continue;
|
||||
genln("{/*%Q*/.kind = %d, .size = %d, .align = %d, .is_unsigned = %s, .type = %d, ", typestring(t),
|
||||
(S32)t->kind, (S32)t->size, (S32)t->align, t->is_unsigned ? "true" : "false", t->type_id);
|
||||
switch (t->kind) {
|
||||
|
||||
@@ -41,8 +41,13 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope, Array<Ast_Decl *> *replace, Arr
|
||||
|
||||
if ((dst->flags & AST_TYPESPEC)) {
|
||||
For(*replace) {
|
||||
assert(it->type == pctx->type_type);
|
||||
if (it->name == dst->intern_val) {
|
||||
Breakpoint;
|
||||
int it_index = replace->get_index(&it);
|
||||
Ast_Call_Item *replacement = with[0][it_index];
|
||||
Ast_Atom *replacement_v = (Ast_Atom *)replacement->item;
|
||||
assert(replacement_v->resolved_type == pctx->type_type);
|
||||
dst = ast_create_copy(parent_scope, Ast_Atom, replacement_v);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,6 +294,9 @@ Ast_Decl *get_or_instantiate_polymorph_type(Token *pos, Ast_Decl *poly, Array<As
|
||||
|
||||
if (!result) {
|
||||
result = (Ast_Decl *)ast_copy(poly, poly->parent_scope, &poly->polymorph_parameters, ¶ms);
|
||||
unset_flag(result->flags, AST_POLYMORPH);
|
||||
result->type_val = type_incomplete(result);
|
||||
result->polymorph_hash = hash;
|
||||
poly->polymorphs.add(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -1577,8 +1577,9 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
|
||||
|
||||
// node->exprs = params
|
||||
Ast_Decl *instance = get_or_instantiate_polymorph_type(node->pos, poly, node->exprs, field_access_scope);
|
||||
// type_complete(decl);
|
||||
return {}; // operand_type(resolved_type);
|
||||
resolve_decl(instance);
|
||||
type_complete(instance->type_val);
|
||||
return operand_type(instance->type_val);
|
||||
}
|
||||
|
||||
/* @todo:
|
||||
@@ -1843,6 +1844,9 @@ resolve_decl(Ast_Decl *ast) {
|
||||
}
|
||||
ast->state = DECL_RESOLVED;
|
||||
|
||||
if (is_flag_set(ast->flags, AST_GLOBAL))
|
||||
bool is_polymorph = is_flag_set(ast->flags, AST_POLYMORPH);
|
||||
bool is_global = is_flag_set(ast->flags, AST_GLOBAL);
|
||||
if (is_global && !is_polymorph) {
|
||||
add(pctx->perm, &pctx->ordered_decls, ast);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,5 +26,7 @@ Array :: struct($T: Type)
|
||||
|
||||
main :: (argc: int, argv: **char): int
|
||||
array: Array(int)
|
||||
second_array: Array(int)
|
||||
third_array: Array(int)
|
||||
|
||||
return 0
|
||||
Reference in New Issue
Block a user