]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
stubbed out basic symtable api
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 31 May 2018 01:58:17 +0000 (21:58 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 31 May 2018 01:58:17 +0000 (21:58 -0400)
Makefile
source/main.c
source/sclpl.h
source/syms.c [new file with mode: 0644]

index 77e0a2d81329a4cb60b9021d5de5eacb138f5593..cf7d517a65ad3bfe0807c3e2b1f5b17abf5dedfd 100644 (file)
--- 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
index 4bc946bb3f899cc7e016e15a31ff945c0a940852..8f9ed76d2e13291a0bcb3de18da45051c2211eec 100644 (file)
@@ -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
index 398e2468345e1e27a5acda780cae7dc5565db538..8bb748c991e32d62962b5dd31fa52e72042a65d6 100644 (file)
@@ -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 (file)
index 0000000..f356b0a
--- /dev/null
@@ -0,0 +1,13 @@
+#include <sclpl.h>
+
+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;
+}