Files
fz-lang/src/compiler/generator/gen_break.c
T

34 lines
814 B
C

#include <common/fzl_types.h>
#include <compiler/fzl_gen.h>
#include <compiler/internals/gen.h>
#include <stdbool.h>
#include <stdio.h>
// Break keyword
gen_res_t gen_break(fzl_gen_t *gen, fzl_node_t *node)
{
if (!gen || !node)
return (gen_res_t){.error = true};
fzl_gen_ctx_t *ctx = gen->ctx;
while (ctx != NULL)
{
if (ctx && ctx->type == FZL_GEN_CTX_TYPE_LOOP)
break;
ctx = ctx->parent;
}
if (!ctx || ctx->type != FZL_GEN_CTX_TYPE_LOOP)
return (gen_res_t){.error = true};
for (size_t i = gen->syms_top - 1; i > ctx->level + 1; i--)
gen_op(gen, FZL_OPCODE_RM_ENVTABLE);
gen_op(gen, FZL_OPCODE_JMP);
ctx->loop.breaks[ctx->loop.breaks_count++] = gen->ops_count;
gen_word(gen, 0);
return (gen_res_t){.error = false, .type = FZL_TYPE_NULL, .classname = NULL};
}