skopy/lib/include/sym.h

74 lines
1.7 KiB
C

#ifndef SK_SYM_H
#define SK_SYM_H
#include "commons.h"
#define SK_NO_CLOSURE (-1)
#define SK_NO_NATIVE (-1)
#include "value.h"
extern int IdCounter;
struct symbol
{
int id;
int closure_id;
int native_id;
char* name;
bool is_const;
bool is_global;
struct env* env;
struct node* node;
struct fun* fun;
};
struct env
{
struct vec symbols;
struct env* parent;
};
struct sym
{
struct sym* parent;
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 node* node,
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,
struct node* node);
int sym_decl_const(struct sym* self, char const* name,
struct node* node);
int sym_decl_closure(struct sym* self, int id, char const* name,
struct node* node, struct fun* fun);
int sym_decl_global(struct sym* self, int id, char const* name,
struct node* node);
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