Files
fz-lang/src/compiler/generator/op.c
T
samsonium 26decf2626 wip: working on extern
- Feat: add new generator scope to replace walker
- Feat: add generators' context functions
- Feat: add generators' ops array functions
- Feat: add generators' utility functions
2026-11-04 17:03:48 +03:00

49 lines
813 B
C

#include <compiler/fzl_gen.h>
#include <compiler/internals/gen.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
// Check ops length and resize if needed
bool ops_check_size(fzl_gen_t *gen)
{
if (!gen)
return false;
if (gen->ops_count >= gen->ops_remainder)
{
gen->ops_remainder *= 2;
size_t *newops = realloc(gen->ops, gen->ops_remainder * sizeof(size_t));
if (!newops)
return false;
gen->ops = newops;
}
return true;
}
// Push opcode
void gen_op(fzl_gen_t *gen, fzl_opcode_t opcode)
{
if (!gen)
return;
if (!ops_check_size(gen))
return;
gen->ops[gen->ops_count++] = opcode;
}
// Push word
void gen_word(fzl_gen_t *gen, size_t word)
{
if (!gen)
return;
if (!ops_check_size(gen))
return;
gen->ops[gen->ops_count++] = word;
}