71 lines
1.2 KiB
C
71 lines
1.2 KiB
C
#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_NUMBER
|
|
} fzl_consttype_t;
|
|
|
|
// Constant descriptor
|
|
typedef struct
|
|
{
|
|
fzl_consttype_t type;
|
|
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
const char *chars;
|
|
size_t length;
|
|
} string;
|
|
|
|
struct
|
|
{
|
|
uint64_t value;
|
|
} num;
|
|
} 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
|