Fixing array code generation

This commit is contained in:
Krzosa Karol
2022-07-28 13:29:25 +02:00
parent 78a0f54319
commit b806bafb51
2 changed files with 36 additions and 8 deletions

View File

@@ -520,8 +520,18 @@ gen_ast(Ast *ast){
// Array iter
if(node->is_array_traversal){
gen("for(S64 _i%d = 0; _i%d < ", node->pos->line, node->pos->line);
gen_expr(node->cond);
gen(".len; _i%d+=1)", node->pos->line);
if(is_array(node->cond->resolved_type)){
gen("_buff_cap(");
gen_expr(node->cond);
gen(")");
} else{
assert(is_slice(node->cond->resolved_type));
gen_expr(node->cond);
gen(".len");
}
gen("; _i%d+=1)", node->pos->line);
gen("{");
global_indent++;
genln("");
@@ -719,6 +729,7 @@ typedef S64 Type;
#define false 0
#define assert(x) do{if(!(x))__debugbreak();}while(0)
#define assert_msg(x,...) assert(x)
#define _buff_cap(x) (sizeof(x)/sizeof((x)[0]))
typedef struct String{
U8 *str;
S64 len;