wip: working on generator
- Feat: add break handler - Feat: add class handler - Feat: add format string handler - Feat: add loop handler
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#include <compiler/fzl_gen.h>
|
||||
#include <compiler/internals/gen.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Break keyword
|
||||
bool gen_break(fzl_gen_t *gen, fzl_node_t *node)
|
||||
{
|
||||
if (!gen || !node)
|
||||
return false;
|
||||
|
||||
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 false;
|
||||
|
||||
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 true;
|
||||
}
|
||||
Reference in New Issue
Block a user