Skip to content

Commit

Permalink
fix: Continue in for loops now runs increment (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
ookami125 authored Dec 29, 2024
1 parent ee98915 commit aea3547
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 125 deletions.
9 changes: 9 additions & 0 deletions examples/inp_break.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ int main()
continue;
}

for (int i=0; i<3; ++i)
{
if(i == 1)
{
continue;
}
printf("i is %d\n", i);
}

for (int i = 0; i >= 0; i = i + 1)
{
if (i == 0)
Expand Down
6 changes: 5 additions & 1 deletion parser/for.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ apply_result *for_apply(parser_node *node, context *ctx)

char *start_for = new_loop_start_label(ctx);
char *end_for = new_loop_end_label(ctx);
char *cond_for = new_label(ctx);

add_text(ctx, "jmp %s", cond_for);
add_text(ctx, "%s:", start_for);
forn->act->apply(forn->act, ctx);

add_text(ctx, "%s:", cond_for);
apply_result *condv = forn->cond->apply(forn->cond, ctx);
char *rega = reg_a(condv->type, ctx);
add_text(ctx, "mov %s, %s", rega, condv->code);
add_text(ctx, "cmp %s, 0", rega);
add_text(ctx, "je %s", end_for);
forn->body->apply(forn->body, ctx);
forn->act->apply(forn->act, ctx);
add_text(ctx, "jmp %s", start_for);
add_text(ctx, "%s:", end_for);
while (ctx->symbol_table->count > num_syms)
Expand Down
Loading

0 comments on commit aea3547

Please sign in to comment.