Unique names for polymorphic types
This commit is contained in:
@@ -41,27 +41,6 @@ gen_last_line() {
|
||||
}
|
||||
}
|
||||
|
||||
CORE_Static String
|
||||
string_scope_name(Ast_Scope *scope) {
|
||||
String string = {};
|
||||
if (scope->parent_scope) string = string_scope_name(scope->parent_scope);
|
||||
assert_message(scope->scope_id != 0, "Scope id is equal to 0 which is invalid, scope didn't initialize id");
|
||||
string = pctx->fmt("%QS%u_", string, scope->scope_id);
|
||||
return string;
|
||||
}
|
||||
|
||||
CORE_Static void
|
||||
gen_scope_name(Ast_Scope *scope) {
|
||||
gen("%Q", string_scope_name(scope));
|
||||
}
|
||||
|
||||
CORE_Static Intern_String
|
||||
get_unique_name(Ast *ast) {
|
||||
String result = string_scope_name(ast->parent_scope);
|
||||
assert(result.len);
|
||||
return pctx->internf("%Q%d", result, ast->pos->line);
|
||||
}
|
||||
|
||||
global String prefixed_string_type;
|
||||
CORE_Static const char *
|
||||
get_ctype_name_for_type(Ast_Type *type) {
|
||||
@@ -565,7 +544,7 @@ gen_ast(Ast *ast) {
|
||||
if (is_tuple(node->resolved_type)) {
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
Intern_String tuple_name = get_unique_name(node);
|
||||
Intern_String tuple_name = get_unique_name();
|
||||
gen_simple_decl(node->resolved_type, tuple_name);
|
||||
gen(";");
|
||||
|
||||
@@ -804,7 +783,7 @@ gen_ast(Ast *ast) {
|
||||
|
||||
Scoped_Arena scratch(pctx->scratch);
|
||||
|
||||
Intern_String var_name = get_unique_name(node);
|
||||
Intern_String var_name = get_unique_name();
|
||||
gen_simple_decl(node->resolved_type, var_name);
|
||||
gen(" = ");
|
||||
gen_expr(node->expr);
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
|
||||
CORE_Static Intern_String
|
||||
get_unique_name() {
|
||||
static uint64_t counter;
|
||||
static char char_counter;
|
||||
if (char_counter == 0 || char_counter > 'Z') char_counter = 'A';
|
||||
return pctx->internf("%c%uUnique", char_counter++, counter++);
|
||||
}
|
||||
|
||||
CORE_Static Intern_String
|
||||
get_unique_name_for_decl(Ast_Decl *decl) {
|
||||
static char char_counter;
|
||||
if (char_counter == 0 || char_counter > 'Z') char_counter = 'A';
|
||||
return pctx->internf("%c%u_%Q", char_counter++, decl->di, decl->name);
|
||||
}
|
||||
|
||||
#define ast_create_copy(parent_scope, T, ast) (T *)ast__create_copy(parent_scope, sizeof(T), ast)
|
||||
Ast *ast__create_copy(Ast_Scope *parent_scope, size_t size, Ast *ast) {
|
||||
@@ -297,6 +311,9 @@ Ast_Decl *get_or_instantiate_polymorph_type(Token *pos, Ast_Decl *poly, Array<As
|
||||
unset_flag(result->flags, AST_POLYMORPH);
|
||||
result->type_val = type_incomplete(result);
|
||||
result->polymorph_hash = hash;
|
||||
|
||||
assert(result->di != poly->di);
|
||||
result->name = get_unique_name_for_decl(result);
|
||||
poly->polymorphs.add(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,21 @@ Array :: struct($T: Type)
|
||||
len: int
|
||||
cap: int
|
||||
|
||||
make_array :: (a: *int, count: int): Array(int)
|
||||
result := Array(int) {
|
||||
data = a,
|
||||
len = count,
|
||||
cap = count
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
main :: (argc: int, argv: **char): int
|
||||
array: Array(int)
|
||||
buff: *int
|
||||
array: Array(int) = {len = 10, cap = 10, data = buff}
|
||||
second_array: Array(int)
|
||||
third_array: Array(int)
|
||||
fourth: Array(F32)
|
||||
fifth: Array(F32)
|
||||
|
||||
return 0
|
||||
Reference in New Issue
Block a user