Cleanup compile time variables from generated code
This commit is contained in:
@@ -328,5 +328,51 @@ Ast_Decl *get_or_instantiate_polymorph_type(Token *pos, Ast_Decl *poly, Array<As
|
||||
return result;
|
||||
}
|
||||
|
||||
// Ast_Decl *get_or_instantiate_polymorph_lambda(Token *pos, Ast_Decl *poly, Array<Ast_Call_Item *> params, Ast_Scope *field_access_scope) {
|
||||
// }
|
||||
Ast_Decl *get_or_instantiate_polymorph_lambda(Token *pos, Ast_Decl *poly, Array<Ast_Call_Item *> params, Ast_Scope *field_access_scope) {
|
||||
if (params.len != poly->polymorph_parameters.len) compiler_error(pos, "Invalid count of polymorphic arguments");
|
||||
|
||||
int i = 0;
|
||||
uint64_t hash = 91;
|
||||
For(params) {
|
||||
Ast_Decl *poly_decl = poly->polymorph_parameters[i++];
|
||||
resolve_decl(poly_decl);
|
||||
if (poly_decl->type != pctx->type_type) compiler_error(poly_decl->pos, "Invalid type of polymorphic struct argument");
|
||||
|
||||
Operand op = resolve_expr(it->item, AST_CANT_BE_NULL, 0, field_access_scope);
|
||||
if (!op.is_const) compiler_error(it->pos, "Argument is required to be compile time known");
|
||||
if (op.type != pctx->type_type) compiler_error(it->pos, "Struct argument required to be a type");
|
||||
|
||||
hash = hash_mix(hash, hash_ptr(op.type_val));
|
||||
}
|
||||
|
||||
Ast_Decl *result = 0;
|
||||
For(poly->polymorphs) {
|
||||
if (it->polymorph_hash == hash) {
|
||||
result = it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
result = (Ast_Decl *)ast_copy(poly, poly->parent_scope, &poly->polymorph_parameters, ¶ms);
|
||||
For(result->lambda->args) {
|
||||
if (it->flags & AST_IDENT_POLYMORPH) {
|
||||
result->lambda->args.ordered_remove(it);
|
||||
}
|
||||
}
|
||||
|
||||
unset_flag(result->flags, AST_POLYMORPH);
|
||||
unset_flag(result->flags, AST_PARENT_POLYMORPH);
|
||||
result->polymorph_hash = hash;
|
||||
|
||||
assert(result->di != poly->di);
|
||||
result->name = get_unique_name_for_decl(result);
|
||||
result->unique_name = result->name;
|
||||
|
||||
poly->polymorphs.allocator = pctx->heap;
|
||||
poly->polymorphs.add(result);
|
||||
}
|
||||
|
||||
resolve_decl(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user