From d0f3464df3d9e737d7445d28921b8ccc1e2c0e3f Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 10 Jun 2018 21:59:30 -0400 Subject: [PATCH] added float types --- source/codegen.c | 18 ++++++++---------- source/sclpl.h | 3 ++- source/types.c | 6 ++++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source/codegen.c b/source/codegen.c index b16fdfa..563e2a2 100644 --- a/source/codegen.c +++ b/source/codegen.c @@ -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)); } diff --git a/source/sclpl.h b/source/sclpl.h index f04531c..74ce147 100644 --- a/source/sclpl.h +++ b/source/sclpl.h @@ -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); diff --git a/source/types.c b/source/types.c index 3aca206..f02090f 100644 --- a/source/types.c +++ b/source/types.c @@ -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; -- 2.52.0