skopy/lib/include/sym.h

56 lines
1.1 KiB
C
Raw Normal View History

2024-04-02 15:33:31 +00:00
#ifndef SK_SYM_H
#define SK_SYM_H
#include "commons.h"
2024-04-05 16:31:11 +00:00
#define SK_NO_CLOSURE (-1)
2024-04-02 15:33:31 +00:00
struct symbol
{
int id;
2024-04-05 16:31:11 +00:00
int closure_id;
2024-04-02 15:33:31 +00:00
char* name;
bool is_const;
struct env* env;
};
struct env
{
struct vec symbols;
struct env* parent;
};
struct sym
{
int id_counter;
2024-04-05 16:31:11 +00:00
int closure_counter;
2024-04-02 15:33:31 +00:00
struct env* env;
};
void env_init(struct env* self);
2024-04-05 16:31:11 +00:00
struct env* env_new_clone(struct env* self);
2024-04-02 15:33:31 +00:00
void env_free(struct env* self);
2024-04-05 16:31:11 +00:00
2024-04-02 15:33:31 +00:00
struct symbol* env_try_get(struct env* self, char const* name);
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);
2024-04-05 16:31:11 +00:00
struct sym* sym_new_clone(struct sym* self);
2024-04-02 15:33:31 +00:00
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);
2024-04-05 16:31:11 +00:00
int sym_decl_closure(struct sym* self, int id, char const* name);
2024-04-02 15:33:31 +00:00
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);
#endif