diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-10-06 20:17:27 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | a9a8cf8d337470bb9b4466aea9593df7f5fac776 (patch) | |
tree | 22c197c8217cd216e58f8a47a6820d96ff279138 /include | |
parent | fa03e7d230f2625c384ca9a7c314b6d05ab44e70 (diff) |
Implicit cast to larger size, number suffix for number bitsize
Diffstat (limited to 'include')
-rw-r--r-- | include/ast.h | 15 | ||||
-rw-r--r-- | include/compiler.h | 2 | ||||
-rw-r--r-- | include/number.h | 21 | ||||
-rw-r--r-- | include/tokenizer.h | 5 |
4 files changed, 29 insertions, 14 deletions
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 <stdarg.h> @@ -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 */ }; |