]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
added float types
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 11 Jun 2018 01:59:30 +0000 (21:59 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 11 Jun 2018 01:59:30 +0000 (21:59 -0400)
source/codegen.c
source/sclpl.h
source/types.c

index b16fdfaecc9d9ca703cfc42d9a41c2bc71935a89..563e2a226a6e918b2a57c5a8fedeecaae60140a6 100644 (file)
@@ -4,16 +4,14 @@ void codegen_init(Parser* p) {
     sym_add(&(p->syms), SF_TYPEDEF, "void",   VoidType());
     sym_add(&(p->syms), SF_TYPEDEF, "bool",   UIntType(1u));
     sym_add(&(p->syms), SF_TYPEDEF, "byte",   UIntType(8u));
-    sym_add(&(p->syms), SF_TYPEDEF, "uint",   UIntType(64u));
-    sym_add(&(p->syms), SF_TYPEDEF, "u8",     UIntType(8u));
-    sym_add(&(p->syms), SF_TYPEDEF, "u16",    UIntType(16u));
-    sym_add(&(p->syms), SF_TYPEDEF, "u32",    UIntType(32u));
-    sym_add(&(p->syms), SF_TYPEDEF, "u64",    UIntType(64u));
-    sym_add(&(p->syms), SF_TYPEDEF, "int",    IntType(64u));
-    sym_add(&(p->syms), SF_TYPEDEF, "i8",     IntType(8u));
-    sym_add(&(p->syms), SF_TYPEDEF, "i16",    IntType(16u));
-    sym_add(&(p->syms), SF_TYPEDEF, "i32",    IntType(32u));
-    sym_add(&(p->syms), SF_TYPEDEF, "i64",    IntType(64u));
+    sym_add(&(p->syms), SF_TYPEDEF, "ushort", UIntType(16u));
+    sym_add(&(p->syms), SF_TYPEDEF, "short",  IntType(16u));
+    sym_add(&(p->syms), SF_TYPEDEF, "uint",   UIntType(32u));
+    sym_add(&(p->syms), SF_TYPEDEF, "int",    IntType(32u));
+    sym_add(&(p->syms), SF_TYPEDEF, "ulong",  UIntType(64u));
+    sym_add(&(p->syms), SF_TYPEDEF, "long",   IntType(64u));
+    sym_add(&(p->syms), SF_TYPEDEF, "float",  FloatType(32u));
+    sym_add(&(p->syms), SF_TYPEDEF, "double", FloatType(64u));
     sym_add(&(p->syms), SF_TYPEDEF, "string",
         ArrayOf(sym_get(&(p->syms), "byte")->type, -1));
 }
index f04531c1047cc02c212064833837418a60e5630a..74ce1470c7bb5f3c5f1d1aae7efca04fe9980d58 100644 (file)
@@ -63,7 +63,7 @@ typedef struct {
 /* Datatype Types
  *****************************************************************************/
 typedef enum {
-    VOID, INT, UINT, ARRAY, REF, PTR, FUNC
+    VOID, INT, UINT, FLOAT, ARRAY, REF, PTR, FUNC
 } Kind;
 
 typedef struct Type {
@@ -81,6 +81,7 @@ typedef struct Type {
 Type* VoidType(void);
 Type* IntType(size_t nbits);
 Type* UIntType(size_t nbits);
+Type* FloatType(size_t nbits);
 Type* ArrayOf(Type* type, size_t count);
 Type* RefTo(Type* type);
 Type* PtrTo(Type* type);
index 3aca20664f0264cdd1fa8b27560d11b9870aa73b..f02090fcc76d0ded33cccce10ceeaade28bbe2de 100644 (file)
@@ -23,6 +23,12 @@ Type* UIntType(size_t nbits) {
     return type;
 }
 
+Type* FloatType(size_t nbits) {
+    Type* type = mktype(FLOAT);
+    type->value.bits = nbits;
+    return type;
+}
+
 Type* ArrayOf(Type* elemtype, size_t count) {
     Type* type = mktype(ARRAY);
     type->value.array.type = elemtype;