]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Added type node constructors
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 31 May 2018 01:17:55 +0000 (21:17 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 31 May 2018 01:17:55 +0000 (21:17 -0400)
Makefile
source/main.c
source/sclpl.h
source/types.c [new file with mode: 0644]

index 33845875d82a134fa30b8af98276a1a24081b1e7..77e0a2d81329a4cb60b9021d5de5eacb138f5593 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,8 @@ OBJS = source/main.o    \
        source/pprint.o  \
        source/parser.o  \
        source/lexer.o   \
-       source/ast.o
+       source/ast.o     \
+       source/types.o
 
 .PHONY: all tests specs
 all: sclpl tests specs
index c5f156310b7924ce50309f921b381da8ac93ff71..4bc946bb3f899cc7e016e15a31ff945c0a940852 100644 (file)
@@ -3,6 +3,27 @@
 char* ARGV0;
 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
+}
+
 /* Driver Modes
  *****************************************************************************/
 static int emit_tokens(void) {
index 21784bfac05dc335890e59277837208233bad1a2..398e2468345e1e27a5acda780cae7dc5565db538 100644 (file)
@@ -70,7 +70,7 @@ typedef struct Type {
     Kind kind;
     union {
         struct Type* type;
-        ssize_t bits;
+        size_t bits;
         struct {
             struct Type* type;
             size_t count;
@@ -78,9 +78,10 @@ typedef struct Type {
     } value;
 } Type;
 
-Type* IntType(ssize_t nbits);
-Type* UIntType(ssize_t nbits);
-Type* ArrayOf(Type* type);
+Type* VoidType(void);
+Type* IntType(size_t nbits);
+Type* UIntType(size_t nbits);
+Type* ArrayOf(Type* type, size_t count);
 Type* RefTo(Type* type);
 Type* PtrTo(Type* type);
 
diff --git a/source/types.c b/source/types.c
new file mode 100644 (file)
index 0000000..41db199
--- /dev/null
@@ -0,0 +1,39 @@
+#include <sclpl.h>
+
+static Type* mktype(Kind kind) {
+    Type* type = emalloc(sizeof(Type));
+    memset(type, 0, sizeof(Type));
+    type->kind = kind;
+    return type;
+}
+
+Type* VoidType(void) {
+    return mktype(VOID);
+}
+
+Type* IntType(size_t nbits) {
+    Type* type = mktype(INT);
+    type->value.bits = nbits;
+    return type;
+}
+
+Type* UIntType(size_t nbits) {
+    Type* type = mktype(UINT);
+    type->value.bits = nbits;
+    return type;
+}
+
+Type* ArrayOf(Type* elemtype, size_t count) {
+    Type* type = mktype(ARRAY);
+    type->value.array.type = elemtype;
+    type->value.array.count = count;
+    return type;
+}
+
+Type* RefTo(Type* type) {
+    return NULL;
+}
+
+Type* PtrTo(Type* type) {
+    return NULL;
+}