ref: add type/classname result for each gen_* function
This commit is contained in:
@@ -1,28 +1,30 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_gen.h>
|
||||
#include <compiler/internals/gen.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// While or for loops
|
||||
bool gen_loop(fzl_gen_t *gen, fzl_node_t *node)
|
||||
gen_res_t gen_loop(fzl_gen_t *gen, fzl_node_t *node)
|
||||
{
|
||||
if (!gen || !node)
|
||||
return false;
|
||||
return (gen_res_t){.error = true};
|
||||
|
||||
fzl_gen_ctx_t *ctx = gen_ctx(gen, FZL_GEN_CTX_TYPE_LOOP, node);
|
||||
if (!ctx)
|
||||
return false;
|
||||
return (gen_res_t){.error = true};
|
||||
|
||||
gen_op(gen, FZL_OPCODE_MK_ENVTABLE);
|
||||
|
||||
if (node->loop.init)
|
||||
if (!gen_common(gen, node->loop.init))
|
||||
return false;
|
||||
if (gen_common(gen, node->loop.init).error)
|
||||
return (gen_res_t){.error = true};
|
||||
|
||||
size_t start_ip = gen->ops_count;
|
||||
if (node->loop.cond)
|
||||
{
|
||||
if (!gen_common(gen, node->loop.cond))
|
||||
return false;
|
||||
if (gen_common(gen, node->loop.cond).error)
|
||||
return (gen_res_t){.error = true};
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -34,12 +36,12 @@ bool gen_loop(fzl_gen_t *gen, fzl_node_t *node)
|
||||
ctx->loop.breaks[ctx->loop.breaks_count++] = gen->ops_count;
|
||||
gen_word(gen, 0);
|
||||
|
||||
if (!gen_common(gen, node->loop.body))
|
||||
return false;
|
||||
if (gen_common(gen, node->loop.body).error)
|
||||
return (gen_res_t){.error = true};
|
||||
|
||||
if (node->loop.step)
|
||||
if (!gen_common(gen, node->loop.step))
|
||||
return false;
|
||||
if (gen_common(gen, node->loop.step).error)
|
||||
return (gen_res_t){.error = true};
|
||||
|
||||
gen_op(gen, FZL_OPCODE_JMP);
|
||||
gen_word(gen, start_ip);
|
||||
@@ -55,7 +57,7 @@ bool gen_loop(fzl_gen_t *gen, fzl_node_t *node)
|
||||
|
||||
ctx = gen_fin_ctx(gen);
|
||||
if (!ctx)
|
||||
return false;
|
||||
return (gen_res_t){.error = true};
|
||||
|
||||
return true;
|
||||
return (gen_res_t){.error = false, .type = FZL_TYPE_NULL, .classname = NULL};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user