Added some return values for `getBuiltInType`
parent
cce89233eb
commit
170824be61
|
@ -1,2 +1,29 @@
|
||||||
module compiler.symbols.typing.builtins;
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,18 +3,20 @@ module compiler.symbols.typing.core;
|
||||||
import compiler.symbols.data;
|
import compiler.symbols.data;
|
||||||
import std.string : cmp;
|
import std.string : cmp;
|
||||||
|
|
||||||
|
public import compiler.symbols.typing.builtins;
|
||||||
|
|
||||||
public bool isBuiltInType(string name)
|
public bool isBuiltInType(string name)
|
||||||
{
|
{
|
||||||
return cmp(name, "int") == 0 || cmp(name, "uint") == 0 ||
|
return cmp(name, "int") == 0 || cmp(name, "uint") == 0 ||
|
||||||
cmp(name, "long") == 0 || cmp(name, "ulong") == 0;
|
cmp(name, "long") == 0 || cmp(name, "ulong") == 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class Type : Entity
|
public class Type : Entity
|
||||||
{
|
{
|
||||||
|
/* TODO: Add width here */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: See what we need in here, Entity name could be our Type name
|
* 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`
|
* 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
|
public class Number : Type
|
||||||
{
|
{
|
||||||
/* Number of bytes (1,2,4,8) */
|
/* Number of bytes (1,2,4,8) */
|
||||||
private ubyte width;
|
private ubyte width;
|
||||||
|
|
||||||
this(string name)
|
|
||||||
|
|
||||||
|
/* TODO: Aligbment details etc. */
|
||||||
|
|
||||||
|
this(string name, ubyte width)
|
||||||
{
|
{
|
||||||
super(name);
|
super(name);
|
||||||
|
this.width = width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Integer : Number
|
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)
|
this(string name)
|
||||||
{
|
{
|
||||||
super(name);
|
/* TODO: Change */
|
||||||
|
super(name, 69);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,18 +71,20 @@ public class Double : Number
|
||||||
{
|
{
|
||||||
this(string name)
|
this(string name)
|
||||||
{
|
{
|
||||||
super(name);
|
/* TODO: Change */
|
||||||
|
super(name, 69);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Pointer : Type
|
public class Pointer : Integer
|
||||||
{
|
{
|
||||||
/* Data type being pointed to */
|
/* Data type being pointed to */
|
||||||
private Type dataType;
|
private Type dataType;
|
||||||
|
|
||||||
this(string name, Type dataType)
|
this(string name, Type dataType)
|
||||||
{
|
{
|
||||||
super(name);
|
/* TODO: Change below, per architetcure */
|
||||||
|
super(name, 8);
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue