Files
fz-lang/include/compiler/fzl_gen.h
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

78 lines
1.4 KiB
C

#ifndef FZL_GENERATOR_H
#define FZL_GENERATOR_H
#include <common/fzl_extern.h>
#include <compiler/fzl_parser.h>
#include <compiler/utils/fzl_const_pool.h>
#include <compiler/utils/fzl_ctable.h>
#include <compiler/utils/fzl_symtable.h>
#include <stdbool.h>
#include <stddef.h>
// Generator context type
typedef enum
{
FZL_GEN_CTX_TYPE_UNECCESSARY,
FZL_GEN_CTX_TYPE_FUNCTION,
FZL_GEN_CTX_TYPE_CLASS,
FZL_GEN_CTX_TYPE_LOOP
} fzl_gen_ctx_type_t;
// Generator context descriptor
typedef struct fzl_gen_ctx
{
fzl_gen_ctx_type_t type;
struct fzl_gen_ctx *parent;
size_t level;
union
{
fzl_node_t *function;
struct
{
size_t breaks[256];
size_t breaks_count;
} loop;
};
} fzl_gen_ctx_t;
// Generator descriptor
typedef struct
{
fzl_node_t *root;
fzl_const_hash_pool_t *consts;
fzl_gen_ctx_t *ctx;
size_t *ops;
size_t ops_count;
size_t ops_remainder;
fzl_symtable_t *syms[256];
size_t syms_top;
fzl_ctable_t *classes[64];
size_t classes_count;
fzl_extern_lib_t extern_libs[64];
size_t extern_libs_count;
fzl_extern_type_t extern_types[256];
size_t extern_types_count;
fzl_extern_fn_t extern_fns[256];
size_t extern_fns_count;
} fzl_gen_t;
// Allocate new generator
fzl_gen_t *fzl_mkgen(fzl_node_t *root);
// Run program generation
bool fzl_gen_run(fzl_gen_t *gen);
// Free generator
void fzl_freegen(fzl_gen_t *gen);
#endif // FZL_GENERATOR_H