Working on slices, arrays and any types
This commit is contained in:
19
ccodegen.cpp
19
ccodegen.cpp
@@ -288,9 +288,13 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){
|
||||
CASE(INDEX, Index){
|
||||
gen("(");
|
||||
gen_expr(node->expr);
|
||||
if(is_string(node->resolved_type))
|
||||
if(is_string(node->resolved_type)){
|
||||
if(!(type_of_var && type_of_var == type_pointer_to_char))
|
||||
gen(".str");
|
||||
}
|
||||
else if(is_slice(node->resolved_type)){
|
||||
gen(".data");
|
||||
}
|
||||
gen("[");
|
||||
gen_expr(node->index);
|
||||
gen("]");
|
||||
@@ -370,14 +374,26 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){
|
||||
gen(")");
|
||||
gen("{");
|
||||
|
||||
if(is_slice(node->resolved_type)) {
|
||||
gen(".len = %d, ", node->exprs.len);
|
||||
gen(".data = (");
|
||||
gen_simple_decl(node->resolved_type->base);
|
||||
gen("[]");
|
||||
gen(")");
|
||||
gen("{");
|
||||
}
|
||||
|
||||
For(node->exprs){
|
||||
if(is_struct(node->resolved_type))
|
||||
gen(".%Q = ", it->resolved_name);
|
||||
else if(is_array(node->resolved_type))
|
||||
gen("[%d] = ", (int)it->resolved_index);
|
||||
gen_expr(it->item, it->resolved_type);
|
||||
|
||||
if(!node->exprs.is_last(&it)) gen(", ");
|
||||
}
|
||||
|
||||
if(is_slice(node->resolved_type)) gen("}");
|
||||
gen("}");
|
||||
BREAK();
|
||||
}
|
||||
@@ -699,7 +715,6 @@ insert_builtin_types_into_scope(Ast_Scope *p){
|
||||
insert_builtin_into_scope(p, "void"_s , type_void);
|
||||
insert_builtin_into_scope(p, "Bool"_s , type_bool);
|
||||
insert_builtin_into_scope(p, "String"_s, type_string);
|
||||
// insert_builtin_into_scope(p, "Any"_s, type_any);
|
||||
insert_builtin_into_scope(p, "Type"_s, type_type);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user