64 lines
1.4 KiB
C
64 lines
1.4 KiB
C
#ifndef SK_SYM_H
|
|
#define SK_SYM_H
|
|
|
|
#include "commons.h"
|
|
#define SK_NO_CLOSURE (-1)
|
|
#define SK_NO_NATIVE (-1)
|
|
|
|
struct symbol
|
|
{
|
|
int id;
|
|
int closure_id;
|
|
int native_id;
|
|
char* name;
|
|
bool is_const;
|
|
bool is_global;
|
|
struct env* env;
|
|
};
|
|
|
|
struct env
|
|
{
|
|
struct vec symbols;
|
|
struct env* parent;
|
|
};
|
|
|
|
struct sym
|
|
{
|
|
int id_counter;
|
|
int closure_counter;
|
|
int native_counter;
|
|
int global_counter;
|
|
struct env* env;
|
|
};
|
|
|
|
void env_init(struct env* self);
|
|
struct env* env_new_clone(struct env* self);
|
|
void env_free(struct env* self);
|
|
|
|
struct symbol* env_try_get(struct env* self, char const* name);
|
|
struct symbol* env_try_get_by_id(struct env* self, int id);
|
|
|
|
void symbol_init(struct symbol* self,
|
|
int id,
|
|
char const* name,
|
|
struct env* env);
|
|
|
|
void symbol_free(struct symbol* self);
|
|
|
|
void sym_init(struct sym* self);
|
|
struct sym* sym_new_clone(struct sym* self);
|
|
void sym_free(struct sym* self);
|
|
|
|
int sym_decl_var(struct sym* self, char const* name);
|
|
int sym_decl_const(struct sym* self, char const* name);
|
|
int sym_decl_closure(struct sym* self, int id, char const* name);
|
|
int sym_decl_global(struct sym* self, int id, char const* name);
|
|
|
|
void sym_open_scope(struct sym* self);
|
|
void sym_close_scope(struct sym* self);
|
|
|
|
struct symbol* sym_try_get(struct sym* self, char const* name);
|
|
struct symbol* sym_try_get_by_id(struct sym* self, int id);
|
|
|
|
#endif
|