#ifndef UNDAR_COMPILER_H #define UNDAR_COMPILER_H #include "../vm/libc.h" #include "../vm/vm.h" typedef enum { GLOBAL, LOCAL, VAR } ScopeType; typedef enum { VOID, BOOL, I8, I16, I32, U8, U16, U32, F8, F16, F32, STR, PLEX, ARRAY, FUNCTION } SymbolType; typedef struct symbol_s Symbol; typedef struct symbol_tab_s SymbolTable; typedef struct value_type_s ValueType; typedef struct plex_fields_tab_s PlexFieldsTable; typedef struct plex_def_s PlexDef; typedef struct plex_tab_s PlexTable; typedef struct scope_s Scope; typedef struct scope_tab_s ScopeTable; struct value_type_s { SymbolType type; u32 name; u32 size; u32 table_ref; // if it is a heap object }; struct plex_def_s { u32 name; u32 size; u32 field_ref_start; u32 field_count; }; struct plex_fields_tab_s { u32 *plex_refs; ValueType *fields; u32 count; u32 capacity; }; struct plex_tab_s { PlexDef *symbols; u32 count; u32 capacity; }; #define MAX_SYMBOL_NAME_LENGTH 64 struct symbol_s { char name[MAX_SYMBOL_NAME_LENGTH]; u8 name_length; SymbolType type; ScopeType scope; u32 ref; // vm->mp if global, vm->pc local, register if var u32 size; // size of symbol }; struct symbol_tab_s { Symbol symbols[256]; u8 count; i32 parent; }; struct scope_tab_s { SymbolTable *scopes; u32 count; u32 capacity; i32 scope_ref; }; bool compile(ScopeTable *st, char *source); extern bool table_realloc(ScopeTable *table);/* implement this in arch/ not here */ #endif