Fixing array code generation
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user