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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user