return mem;
}
-compress :: proc (arr: [5] $T, f : proc (T, T) -> T) -> T {
+compress :: proc (arr: [$N] $T, f : proc (T, T) -> T) -> T {
val := arr[0];
- for i: 1 .. 5 do val = f(val, arr[i]);
+ for i: 1..N do val = f(val, arr[i]);
return val;
}
Entity :: struct { use pos: Vec2; }
array_literal_optim :: proc () #export {
- // This needs to be optimized
bar : [5] u32;
bar = u32.[ 1, 2, 3, 4, 5 ];
bar[2] = 1234;
}
}
+static void insert_poly_slns_into_scope(Scope* scope, bh_arr(AstPolySolution) slns) {
+ bh_arr_each(AstPolySolution, sln, slns) {
+ AstNode *node = NULL;
+
+ switch (sln->kind) {
+ case PSK_Type:
+ node = onyx_ast_node_new(semstate.node_allocator, sizeof(AstTypeRawAlias), Ast_Kind_Type_Raw_Alias);
+ ((AstTypeRawAlias *) node)->token = sln->poly_sym->token;
+ ((AstTypeRawAlias *) node)->to = sln->type;
+ break;
+
+ case PSK_Value:
+ // CLEANUP: Maybe clone this?
+ node = (AstNode *) sln->value;
+ break;
+ }
+
+ symbol_introduce(scope, sln->poly_sym->token, node);
+ }
+}
+
typedef struct PolySolveResult {
PolySolutionKind kind;
union {
}
Scope* poly_scope = scope_create(semstate.node_allocator, pp->poly_scope, pos);
- bh_arr_each(AstPolySolution, sln, slns) {
- AstNode *node = NULL;
-
- switch (sln->kind) {
- case PSK_Type:
- node = onyx_ast_node_new(semstate.node_allocator, sizeof(AstTypeRawAlias), Ast_Kind_Type_Raw_Alias);
- ((AstTypeRawAlias *) node)->to = sln->type;
- break;
-
- case PSK_Value:
- // CLEANUP: Maybe clone this?
- node = (AstNode *) sln->value;
- break;
- }
-
- symbol_introduce(poly_scope, sln->poly_sym->token, node);
- }
+ insert_poly_slns_into_scope(poly_scope, slns);
AstFunction* func = (AstFunction *) ast_clone(semstate.node_allocator, pp->base_func);
bh_table_put(AstFunction *, pp->concrete_funcs, unique_key, func);
}
scope_clear(ps_type->scope);
-
- bh_arr_each(AstPolySolution, sln, slns) {
- AstNode *node = NULL;
-
- switch (sln->kind) {
- case PSK_Type:
- node = onyx_ast_node_new(semstate.node_allocator, sizeof(AstTypeRawAlias), Ast_Kind_Type_Raw_Alias);
- ((AstTypeRawAlias *) node)->to = sln->type;
- break;
-
- case PSK_Value:
- // CLEANUP: Maybe clone this?
- node = (AstNode *) sln->value;
- break;
- }
-
- symbol_introduce(ps_type->scope, sln->poly_sym->token, node);
- }
+ insert_poly_slns_into_scope(ps_type->scope, slns);
AstStructType* concrete_struct = (AstStructType *) ast_clone(semstate.node_allocator, ps_type->base_struct);
+ bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct);
Entity struct_entity = {
.state = Entity_State_Resolve_Symbols,
return NULL;
}
- bh_table_put(AstStructType *, ps_type->concrete_structs, unique_key, concrete_struct);
-
Type* cs_type = type_build_from_ast(semstate.node_allocator, (AstType *) concrete_struct);
cs_type->Struct.poly_sln = NULL;
bh_arr_new(global_heap_allocator, cs_type->Struct.poly_sln, bh_arr_length(slns));