Browse Source

Added support for Pointer type resolution via `getType()`. Now `char**` -> Pointer("char*"), which before construction of such a Pointer is recursively resolved, so nested Pointer(Pointer(...))

constants
Tristan B. V. Kildaire 7 months ago
parent
commit
ca2fa84057
  1. 36
      source/tlang/compiler/symbols/typing/builtins.d
  2. 23
      source/tlang/compiler/symbols/typing/core.d
  3. 15
      source/tlang/compiler/typecheck/core.d
  4. 4
      source/tlang/testing/typecheck/simple_string.t

36
source/tlang/compiler/symbols/typing/builtins.d

@ -1,14 +1,16 @@
module compiler.symbols.typing.builtins;
import compiler.symbols.typing.core;
import std.string : cmp;
import std.string : cmp, indexOf, lastIndexOf;
import gogga;
import compiler.typecheck.core;
/**
* 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)
public Type getBuiltInType(TypeChecker tc, string typeString)
{
/* `int`, signed (2-complement) */
if(cmp(typeString, "int") == 0)
@ -56,11 +58,39 @@ public Type getBuiltInType(string typeString)
return new Void();
}
/* TODO: char */
else if(cmp(typeString, "char") == 0)
{
return new Integer("ubyte", 1, false);
}
/* Pointer handling `<type>*` */
else if(lastIndexOf(typeString, "*") > -1)
{
/* FIXME: We may need to recurse call, for Pointer generation */
long ptrTypePos = lastIndexOf(typeString, "*");
string ptrType = typeString[0..(ptrTypePos)];
gprintln("Pointer to '"~ptrType~"'");
return new Pointer(tc.getType(tc.getModule(), ptrType));
}
/* TODO: Add all remaining types */
/* TODO: Add all remaining types, BUGS probabloy occur on failed looks ups when hitting this */
/* If unknown, return null */
else
{
/* If it contains a `[]` then its an array type */
if(indexOf(typeString, "[]") > -1)
{
/* FIXME: Implement me */
}
return null;
}
}

23
source/tlang/compiler/symbols/typing/core.d

@ -2,6 +2,7 @@ module compiler.symbols.typing.core;
import compiler.symbols.data;
import std.string : cmp;
import std.conv : to;
public import compiler.symbols.typing.builtins;
@ -114,4 +115,26 @@ public class Pointer : Integer
super(name, 8);
this.dataType = dataType;
}
}
/**
* Array type
*
* TODO: Might need investigation
*/
public class Array : Type
{
private Type elementType;
this(Type elementType)
{
/* The name should be `elementType[]` */
// super(name, )
/* TODO: Differentiate between stack arrays and heap */
super(to!(string)(elementType)~"[]");
this.elementType = elementType;
}
}

15
source/tlang/compiler/typecheck/core.d

@ -273,12 +273,19 @@ public final class TypeChecker
LiteralValue litValInstr = new LiteralValue(i, 4);
addInstr(litValInstr);
}
/* String literal */
else if(cast(StringExpression)statement)
{
/* TODO: For now */
// gprintln("STRING LIT");
// addType(getType(modulle, "int"));
//addType();
gprintln("Typecheck(): String literal processing...");
/**
* Add the char* type as string literals should be
* interned
*/
addType(getType(modulle, "char*")); /* FIXME: Make char* */
gprintln("Typecheck(): String literal processing... [done]");
}
else if(cast(VariableExpression)statement)
{
@ -855,7 +862,7 @@ public final class TypeChecker
Type foundType;
/* Check if the type is built-in */
foundType = getBuiltInType(typeString);
foundType = getBuiltInType(this, typeString);
/* If it isn't then check for a type (resolve it) */
if(!foundType)

4
source/tlang/testing/typecheck/simple_string.t

@ -0,0 +1,4 @@
module simple;
int g = "";
Loading…
Cancel
Save