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
This commit is contained in:
samsonium
2026-11-04 17:03:48 +03:00
parent 358ede4c8c
commit 26decf2626
6 changed files with 478 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
#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;
}