diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index a78362f..b7d399b 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -728,11 +728,11 @@ gen_ast(Ast *ast) { } CASE(ENUM, Decl) { - gen("/*enum %Q{", node->name); + gen("/*enum %Q{", node->unique_name); // @todo add typespec global_indent++; For(node->scope->decls) { - genln("%Q", it->name); + genln("%Q", it->unique_name); gen(" = "); gen_value(it->pos, it->value); gen(","); diff --git a/core_parsing.cpp b/core_parsing.cpp index 6a882cb..aaac50f 100644 --- a/core_parsing.cpp +++ b/core_parsing.cpp @@ -1011,6 +1011,7 @@ parse_decl(B32 is_global) { if (result) { set_flag(result->flags, flags); result->name = tname->intern_val; + result->unique_name = tname->intern_val; } return result; diff --git a/core_polymorph.cpp b/core_polymorph.cpp index 942d0e7..c97d6c7 100644 --- a/core_polymorph.cpp +++ b/core_polymorph.cpp @@ -53,14 +53,14 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope, Array *replace, Arr Ast_Atom *src = (Ast_Atom *)ast; Ast_Atom *dst = ast_create_copy(parent_scope, Ast_Atom, ast); - if (replace && with && (dst->flags & AST_TYPESPEC)) { + if (replace && with) { + // @todo: IF ITS STRUCT we only want to replace TYPESPECS For(*replace) { assert(it->type == pctx->type_type); if (it->name == dst->intern_val) { int it_index = replace->get_index(&it); Ast_Call_Item *replacement = with[0][it_index]; Ast *replacement_v = replacement->item; - // assert(replacement_v->resolved_type == pctx->type_type); dst = (Ast_Atom *)ast_copy(replacement_v, parent_scope, 0, 0); } } @@ -316,8 +316,7 @@ Ast_Decl *get_or_instantiate_polymorph_type(Token *pos, Ast_Decl *poly, Arraypolymorph_hash = hash; assert(result->di != poly->di); - result->name = get_unique_name_for_decl(result); - result->unique_name = result->name; + result->unique_name = get_unique_name_for_decl(result); poly->polymorphs.allocator = pctx->heap; poly->polymorphs.add(result); @@ -366,8 +365,7 @@ Ast_Decl *get_or_instantiate_polymorph_lambda(Token *pos, Ast_Decl *poly, Array< result->polymorph_hash = hash; assert(result->di != poly->di); - result->name = get_unique_name_for_decl(result); - result->unique_name = result->name; + result->unique_name = get_unique_name_for_decl(result); poly->polymorphs.allocator = pctx->heap; poly->polymorphs.add(result); diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 9829a36..78adfb9 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1699,6 +1699,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str For(matches) { if (it.lambda_arg->flags & AST_POLYMORPH) { replacements.add(it.call_arg); + matches.ordered_remove(it); } } @@ -1706,6 +1707,11 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str Ast_Decl *instance = get_or_instantiate_polymorph_lambda(node->pos, poly, replacements, field_access_scope); node->resolved_decl = instance; lambda = instance->lambda; + + // We know need to fix the matches list CAUSE ITS FUCKED + // Thanks polymorphism + For(matches) { + } } // Typecheck the arguments and produce properly ordered list of arguments for codegeneration diff --git a/core_types.cpp b/core_types.cpp index f88869f..0b66ad4 100644 --- a/core_types.cpp +++ b/core_types.cpp @@ -261,7 +261,6 @@ type_struct_complete(Ast_Type *type, Ast_Decl *node) { type->padding = type->size - members_size; type->agg.members = members.tight_copy(pctx->perm); type->kind = TYPE_STRUCT; - node->unique_name = pctx->internf("%Q%Q", pctx->symbol_prefix, node->name); } else { assert(node->kind == AST_UNION); @@ -289,7 +288,6 @@ type_struct_complete(Ast_Type *type, Ast_Decl *node) { type->size = align_up(type->size, type->align); type->agg.members = members.tight_copy(pctx->perm); type->kind = TYPE_UNION; - node->unique_name = pctx->internf("%Q%Q", pctx->symbol_prefix, node->name); } } diff --git a/examples/_polymorphism.core b/examples/_polymorphism.core index bbf023c..40b58ba 100644 --- a/examples/_polymorphism.core +++ b/examples/_polymorphism.core @@ -53,7 +53,6 @@ MultipleArgs :: (): Tuple(int, F32) PolyLambda :: ($T: Type): T return 32 - GetCount :: (a: int): int return a diff --git a/examples/push_struct.core b/examples/push_struct.core index cb4e60e..50c2482 100644 --- a/examples/push_struct.core +++ b/examples/push_struct.core @@ -1,16 +1,10 @@ MA :: #import "Arena.core" -/* -PushStruct :: (a: *MA.Arena, $T: Type): *$T - size := size_of(Type) - result := PushSize(a, size) - return result -*/ - -PushStruct :: (a: *MA.Arena, type: Type): *void - ti := GetTypeInfo(type) - result := MA.PushSize(a, ti.size->U64) - return result +PushStruct :: (a: *MA.Arena, $T: Type): *T + v: T + size := SizeOf(v) + result := MA.PushSize(a, size->U64) + return result->*T main :: (argc: int, argv: **char): int arena: MA.Arena