From: Michael D. Lowis Date: Thu, 31 May 2018 01:58:17 +0000 (-0400) Subject: stubbed out basic symtable api X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=942153dd4c78020097a34ef58a93e5236874b949;p=proto%2Fsclpl.git stubbed out basic symtable api --- diff --git a/Makefile b/Makefile index 77e0a2d..cf7d517 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,8 @@ OBJS = source/main.o \ source/parser.o \ source/lexer.o \ source/ast.o \ - source/types.o + source/types.o \ + source/syms.o .PHONY: all tests specs all: sclpl tests specs diff --git a/source/main.c b/source/main.c index 4bc946b..8f9ed76 100644 --- a/source/main.c +++ b/source/main.c @@ -6,22 +6,20 @@ char* Artifact = "ast"; /* Builtin Types *****************************************************************************/ static void builtins(Parser* p) { -#if 0 - sym_add(&(p->syms), "void", VoidType()); - sym_add(&(p->syms), "bool", UIntType(1u)); - sym_add(&(p->syms), "byte", UIntType(8u)); - sym_add(&(p->syms), "uint", UIntType(64u)); - sym_add(&(p->syms), "u8", UIntType(8u)); - sym_add(&(p->syms), "u16", UIntType(16u)); - sym_add(&(p->syms), "u32", UIntType(32u)); - sym_add(&(p->syms), "u64", UIntType(64u)); - sym_add(&(p->syms), "int", IntType(64u)); - sym_add(&(p->syms), "i8", IntType(8u)); - sym_add(&(p->syms), "i16", IntType(16u)); - sym_add(&(p->syms), "i32", IntType(32u)); - sym_add(&(p->syms), "i64", IntType(64u)); - sym_add(&(p->syms), "string", ArrayType(sym_get(&(p->syms), "byte"))); -#endif + sym_addtype(&(p->syms), "void", VoidType()); + sym_addtype(&(p->syms), "bool", UIntType(1u)); + sym_addtype(&(p->syms), "byte", UIntType(8u)); + sym_addtype(&(p->syms), "uint", UIntType(64u)); + sym_addtype(&(p->syms), "u8", UIntType(8u)); + sym_addtype(&(p->syms), "u16", UIntType(16u)); + sym_addtype(&(p->syms), "u32", UIntType(32u)); + sym_addtype(&(p->syms), "u64", UIntType(64u)); + sym_addtype(&(p->syms), "int", IntType(64u)); + sym_addtype(&(p->syms), "i8", IntType(8u)); + sym_addtype(&(p->syms), "i16", IntType(16u)); + sym_addtype(&(p->syms), "i32", IntType(32u)); + sym_addtype(&(p->syms), "i64", IntType(64u)); + sym_addtype(&(p->syms), "string", ArrayOf(sym_get(&(p->syms), "byte"), -1)); } /* Driver Modes diff --git a/source/sclpl.h b/source/sclpl.h index 398e246..8bb748c 100644 --- a/source/sclpl.h +++ b/source/sclpl.h @@ -85,6 +85,23 @@ Type* ArrayOf(Type* type, size_t count); Type* RefTo(Type* type); Type* PtrTo(Type* type); +/* Symbol Table + *****************************************************************************/ +typedef struct Sym { + struct Sym* next; + bool is_typedef; + char* name; + Type* type; +} Sym; + +typedef struct { + Sym* syms; +} SymTable; + +void sym_adddef(SymTable* syms, char* name, Type* type); +void sym_addtype(SymTable* syms, char* name, Type* type); +Type* sym_get(SymTable* syms, char* name); + /* AST Types *****************************************************************************/ typedef enum { @@ -160,6 +177,7 @@ void pprint_tree(FILE* file, AST* tree, int depth); typedef struct { FILE* input; Tok tok; + SymTable syms; } Parser; void gettoken(Parser* ctx, Tok* tok); diff --git a/source/syms.c b/source/syms.c new file mode 100644 index 0000000..f356b0a --- /dev/null +++ b/source/syms.c @@ -0,0 +1,13 @@ +#include + +void sym_adddef(SymTable* syms, char* name, Type* type) { + +} + +void sym_addtype(SymTable* syms, char* name, Type* type) { + +} + +Type* sym_get(SymTable* syms, char* name) { + return NULL; +}