2024-03-27 10:49:10 +00:00
|
|
|
#ifndef MK_SYMTABLE_H
|
|
|
|
#define MK_SYMTABLE_H
|
|
|
|
|
|
|
|
#include "commons.h"
|
|
|
|
#include "vec.h"
|
|
|
|
|
|
|
|
struct entry
|
|
|
|
{
|
|
|
|
char* name;
|
|
|
|
size_t addr;
|
|
|
|
bool is_local;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct env
|
|
|
|
{
|
|
|
|
struct vec entries;
|
|
|
|
struct env* parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct symtable
|
|
|
|
{
|
|
|
|
struct env* root;
|
|
|
|
};
|
|
|
|
|
|
|
|
void entry_init(struct entry* self,
|
|
|
|
char const* name,
|
|
|
|
size_t addr,
|
|
|
|
bool is_local);
|
|
|
|
void entry_free(struct entry* self);
|
|
|
|
|
|
|
|
void env_init(struct env* self, struct env* parent);
|
|
|
|
void env_free(struct env* self);
|
|
|
|
struct entry* env_try_get(struct env* self, char* name);
|
|
|
|
|
|
|
|
void symtable_init(struct symtable* self);
|
|
|
|
void symtable_free(struct symtable* self);
|
|
|
|
|
|
|
|
void symtable_declare(struct symtable* self,
|
|
|
|
char* name,
|
|
|
|
size_t addr,
|
|
|
|
bool is_local);
|
|
|
|
|
|
|
|
struct entry* symtable_try_get(struct symtable* self, char* name);
|
|
|
|
|
2024-03-30 19:04:07 +00:00
|
|
|
void symtable_open_scope(struct symtable* self);
|
|
|
|
void symtable_close_scope(struct symtable* self);
|
|
|
|
|
2024-03-27 10:49:10 +00:00
|
|
|
#endif
|