From a9a8cf8d337470bb9b4466aea9593df7f5fac776 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 6 Oct 2019 20:17:27 +0200 Subject: Implicit cast to larger size, number suffix for number bitsize --- include/ast.h | 15 +++++---------- include/compiler.h | 2 +- include/number.h | 21 +++++++++++++++++++++ include/tokenizer.h | 5 ++--- 4 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 include/number.h (limited to 'include') diff --git a/include/ast.h b/include/ast.h index c45d4aa..f62d31f 100644 --- a/include/ast.h +++ b/include/ast.h @@ -9,6 +9,7 @@ #include "std/misc.h" #include "std/arena_allocator.h" #include "std/hash_map.h" +#include "number.h" #include "binop_type.h" #include "ssa/ssa.h" @@ -209,6 +210,7 @@ struct StructDecl { u32 fields_num_pointers; /* The total size of all fields which are of a type that have the same size on all platforms (i.e u8, i32, etc), recursive */ u32 fields_fixed_size_bytes; + bool is_signed; /* Only default arithmetic types can be signed, everything else is unsigned */ }; struct StructField { @@ -260,11 +262,7 @@ struct String { }; struct Number { - union { - i64 integer; - f64 floating; - } value; - bool is_integer; + AmalNumber value; BufferView code_ref; }; @@ -307,10 +305,7 @@ typedef struct { jmp_buf env; amal_compiler *compiler; /* Borrowed */ Parser *parser; /* Borrowed. This is the parser that belongs to the thread */ - /* - Borrowed. This is the current scope. Note that this scope can belong to another parser (and thread), - as such, @parser and scope_get_parser(@scope) parser may not be the same. - */ + /* Borrowed. This is the current scope. Note that this scope can belong to another parser (and thread) */ Scope *scope; } AstCompilerContext; @@ -336,7 +331,7 @@ void lhsexpr_init(LhsExpr *self, DeclFlag decl_flag, BufferView var_name); void assignmentexpr_init(AssignmentExpr *self, Ast *lhs_expr, Ast *rhs_expr); void import_init(Import *self, BufferView path); CHECK_RESULT int string_init(String *self, BufferView str); -void number_init(Number *self, i64 value, bool is_integer, BufferView code_ref); +void number_init(Number *self, AmalNumber *value, BufferView code_ref); void variable_init(Variable *self, BufferView name); void binop_init(Binop *self); CHECK_RESULT int if_statement_init(IfStatement *self, Scope *parent, ArenaAllocator *allocator); diff --git a/include/compiler.h b/include/compiler.h index 164cf4e..481a107 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -19,7 +19,6 @@ typedef struct { LhsExpr lhs_expr; - bool is_signed; } amal_default_type; typedef struct { @@ -50,6 +49,7 @@ typedef struct { } amal_default_types; bool is_arithmetic_type(LhsExpr *expr, amal_compiler *compiler); +bool amal_default_type_is_signed(amal_default_type *self); struct amal_compiler { amal_default_types default_types; diff --git a/include/number.h b/include/number.h new file mode 100644 index 0000000..a87d5fa --- /dev/null +++ b/include/number.h @@ -0,0 +1,21 @@ +#ifndef AMAL_NUMBER_H +#define AMAL_NUMBER_H + +#include "std/types.h" + +typedef enum { + AMAL_NUMBER_SIGNED_INTEGER, + AMAL_NUMBER_UNSIGNED_INTEGER, + AMAL_NUMBER_FLOAT +} AmalNumberType; + +typedef struct { + union { + i64 integer; + f64 floating; + } value; + int bits; + AmalNumberType type; +} AmalNumber; + +#endif diff --git a/include/tokenizer.h b/include/tokenizer.h index f716ab2..ceb7acf 100644 --- a/include/tokenizer.h +++ b/include/tokenizer.h @@ -5,6 +5,7 @@ #include "std/misc.h" #include "std/defs.h" #include "defs.h" +#include "number.h" #include "binop_type.h" #include "compiler_options.h" #include @@ -62,11 +63,9 @@ struct Tokenizer { union { BufferView identifier; BufferView string; - i64 integer; - f64 floating; BinopType binop_type; } value; - bool number_is_integer; + AmalNumber number; ArenaAllocator *allocator; /* borrowed */ const amal_compiler_options *compiler_options; /* borrowed */ }; -- cgit v1.2.3