From 170824be613b359935d0d901aeb4f64590aad5e9 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sat, 24 Apr 2021 13:16:48 +0200 Subject: [PATCH] Added some return values for `getBuiltInType` --- .../tlang/compiler/symbols/typing/builtins.d | 27 +++++++++++++++ source/tlang/compiler/symbols/typing/core.d | 33 ++++++++++++++----- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/source/tlang/compiler/symbols/typing/builtins.d b/source/tlang/compiler/symbols/typing/builtins.d index b76a64d..7d144ec 100644 --- a/source/tlang/compiler/symbols/typing/builtins.d +++ b/source/tlang/compiler/symbols/typing/builtins.d @@ -1,2 +1,29 @@ module compiler.symbols.typing.builtins; +import compiler.symbols.typing.core; +import std.string : cmp; + +/** +* TODO: We should write spec here like I want int and stuff of proper size so imma hard code em +* no machine is good if int is not 4, as in imagine short being max addressable unit +* like no, fuck that (and then short=int=long, no , that is shit AND is NOT WHAT TLANG aims for) +*/ +public Type getBuiltInType(string typeString) +{ + /* `int`, signed (2-complement) */ + if(cmp(typeString, "int") == 0) + { + return new Integer("int", 4, true); + } + /* `uint` unsigned */ + else if(cmp(typeString, "uint") == 0) + { + return new Integer("uint", 4, false); + } + /* TODO: Add all remaining types */ + /* If unknown, return null */ + else + { + return null; + } +} \ No newline at end of file diff --git a/source/tlang/compiler/symbols/typing/core.d b/source/tlang/compiler/symbols/typing/core.d index 2cff120..27c8bbc 100644 --- a/source/tlang/compiler/symbols/typing/core.d +++ b/source/tlang/compiler/symbols/typing/core.d @@ -3,18 +3,20 @@ module compiler.symbols.typing.core; import compiler.symbols.data; import std.string : cmp; +public import compiler.symbols.typing.builtins; + public bool isBuiltInType(string name) { return cmp(name, "int") == 0 || cmp(name, "uint") == 0 || cmp(name, "long") == 0 || cmp(name, "ulong") == 0; - - } public class Type : Entity { + /* TODO: Add width here */ + /** * TODO: See what we need in here, Entity name could be our Type name * But to make it look nice we could just have `getType` @@ -27,22 +29,32 @@ public class Type : Entity } } +/* TODO: Move width to Type class */ public class Number : Type { /* Number of bytes (1,2,4,8) */ private ubyte width; - this(string name) + + + /* TODO: Aligbment details etc. */ + + this(string name, ubyte width) { super(name); + this.width = width; } } public class Integer : Number { - this(string name) + /* Whether or not signed (if so, then 2's complement) */ + private bool signed; + + this(string name, ubyte width, bool signed = false) { - super(name); + super(name, width); + this.signed = signed; } } @@ -50,7 +62,8 @@ public class Float : Number { this(string name) { - super(name); + /* TODO: Change */ + super(name, 69); } } @@ -58,18 +71,20 @@ public class Double : Number { this(string name) { - super(name); + /* TODO: Change */ + super(name, 69); } } -public class Pointer : Type +public class Pointer : Integer { /* Data type being pointed to */ private Type dataType; this(string name, Type dataType) { - super(name); + /* TODO: Change below, per architetcure */ + super(name, 8); this.dataType = dataType; } } \ No newline at end of file