More resolved data in compound exprs, Fix invalid generation of compound exprs,

This commit is contained in:
Krzosa Karol
2022-06-14 21:41:41 +02:00
parent 58e919ef69
commit 7f5471de08
4 changed files with 22 additions and 6 deletions

View File

@@ -86,6 +86,9 @@ struct Ast_Call_Item: Ast_Expr{
Ast_Atom *name; // for calls only name, for compounds name | index Ast_Atom *name; // for calls only name, for compounds name | index
Ast_Expr *item; Ast_Expr *item;
Ast_Expr *index; Ast_Expr *index;
Intern_String resolved_name;
S64 resolved_index;
}; };
struct Ast_Call: Ast_Expr{ struct Ast_Call: Ast_Expr{

View File

@@ -341,7 +341,12 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){
gen_simple_decl(node->resolved_type); gen_simple_decl(node->resolved_type);
gen(")"); gen(")");
gen("{"); gen("{");
For(node->exprs){ For(node->exprs){
if(is_struct(node->resolved_type))
gen("[%s] = ", it->resolved_name.str);
else if(is_array(node->resolved_type))
gen("[%d] = ", (int)it->resolved_index);
gen_expr(it->item); gen_expr(it->item);
if(!node->exprs.is_last(&it)) gen(", "); if(!node->exprs.is_last(&it)) gen(", ");
} }

View File

@@ -46,8 +46,7 @@ want to export all the symbols, we can namespace them optionally.
[ ] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order [ ] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order
[ ] - Switch [ ] - Switch
[ ] - Some way to take slice of data [ ] - Some way to take slice of data
[ ] - elif [ ] - Optional function renaming in codegen
[ ] - Optional function renaming
[ ] - #assert that handles constants at compile time and vars at runtime [ ] - #assert that handles constants at compile time and vars at runtime
[ ] - Comma notation when declaring variables thing1, thing2: S32 [ ] - Comma notation when declaring variables thing1, thing2: S32
@@ -78,6 +77,7 @@ want to export all the symbols, we can namespace them optionally.
[x] - Scope [x] - Scope
[x] - Hex 0x42 [x] - Hex 0x42
[x] - Rewrite where # happen, [x] - Rewrite where # happen,
[x] - elif
[x] - cast -> [x] - cast ->
[x] - Remodel compound from call to {} [x] - Remodel compound from call to {}
[x] - Fix codegen renames [x] - Fix codegen renames

View File

@@ -605,7 +605,8 @@ resolve_compound_struct(Ast_Call *node, Ast_Type *type){
if(it->name){ if(it->name){
For_Named(type->agg.members, m){ For_Named(type->agg.members, m){
if(it->name->intern_val == m.name){ if(it->name->intern_val == m.name){
it->resolved_name = m.name;
it->resolved_index = type->agg.members.get_index(&m);
// @copy_paste // @copy_paste
if(m.type == type_type) if(m.type == type_type)
item_type = m.type_val; item_type = m.type_val;
@@ -626,10 +627,15 @@ resolve_compound_struct(Ast_Call *node, Ast_Type *type){
if(default_counter >= type->agg.members.len) if(default_counter >= type->agg.members.len)
compiler_error(it->pos, "Too many struct initializers"); compiler_error(it->pos, "Too many struct initializers");
Ast_Resolved_Member *m = &type->agg.members[default_counter];
it->resolved_name = m->name;
it->resolved_index = default_counter;
m->visited = true;
// @copy_paste // @copy_paste
item_type = type->agg.members[default_counter].type; if(m->type == type_type)
if(item_type == type_type) item_type = m->type_val;
item_type = type->agg.members[default_counter].type_val; else item_type = m->type;
default_counter+=1; default_counter+=1;
} }
@@ -637,6 +643,8 @@ resolve_compound_struct(Ast_Call *node, Ast_Type *type){
assert(item_type); assert(item_type);
Operand item = resolve_expr(it->item, AST_CANT_BE_NULL); Operand item = resolve_expr(it->item, AST_CANT_BE_NULL);
make_sure_value_is_compatible_with_type(it->pos, &item, item_type, TYPE_AND_EXPR_REQUIRED); make_sure_value_is_compatible_with_type(it->pos, &item, item_type, TYPE_AND_EXPR_REQUIRED);
it->resolved_type = item_type;
} }
For(type->agg.members) it.visited = false; For(type->agg.members) it.visited = false;