feat: implement AST walker
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#ifndef FZL_CONST_SET_H
|
||||
#define FZL_CONST_SET_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Constant types
|
||||
typedef enum
|
||||
{
|
||||
FZL_CONSTTYPE_STRING
|
||||
} fzl_consttype_t;
|
||||
|
||||
// Constant descriptor
|
||||
typedef struct
|
||||
{
|
||||
fzl_consttype_t type;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
const char *chars;
|
||||
size_t length;
|
||||
} string;
|
||||
} as;
|
||||
} fzl_const_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t pool_index;
|
||||
} fzl_const_hash_slot_t;
|
||||
|
||||
// Constant pool descriptor
|
||||
typedef struct
|
||||
{
|
||||
fzl_const_t *array;
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
|
||||
fzl_const_hash_slot_t *slots;
|
||||
size_t slots_count;
|
||||
size_t slots_capacity;
|
||||
} fzl_const_hash_pool_t;
|
||||
|
||||
// Compare two constants for equality
|
||||
bool fzl_consts_equal(fzl_const_t a, fzl_const_t b);
|
||||
|
||||
// Get hash of specified constant
|
||||
static uint32_t fzl_hash_const(fzl_const_t c);
|
||||
|
||||
// Allocate constants hash pool
|
||||
fzl_const_hash_pool_t *fzl_mkconstpool();
|
||||
|
||||
// Resize the hash table
|
||||
static void fzl_consts_pool_resize_hash(fzl_const_hash_pool_t *pool);
|
||||
|
||||
// Push constant. Returns unique index
|
||||
size_t fzl_consts_pool_add(fzl_const_hash_pool_t *pool, fzl_const_t c);
|
||||
|
||||
// Free constants hash pool
|
||||
void fzl_consts_pool_free(fzl_const_hash_pool_t *pool);
|
||||
|
||||
#endif // FZL_CONST_SET_H
|
||||
Reference in New Issue
Block a user