add MemoryAddress primtiive type

main
cosmonaut 2021-06-02 12:44:36 -07:00
parent 506ee9ecad
commit 61344f5b60
6 changed files with 20 additions and 2 deletions

View File

@ -12,6 +12,7 @@
"double" return DOUBLE;
"string" return STRING;
"bool" return BOOL;
"MemoryAddress" return MEMORYADDRESS;
"struct" return STRUCT;
"return" return RETURN;
"static" return STATIC;

View File

@ -25,6 +25,7 @@ extern FILE *yyin;
%token DOUBLE
%token STRING
%token BOOL
%token MEMORYADDRESS
%token STRUCT
%token RETURN
%token STATIC
@ -108,6 +109,10 @@ BaseType : VOID
{
$$ = MakePrimitiveTypeNode(Bool);
}
| MEMORYADDRESS
{
$$ = MakePrimitiveTypeNode(MemoryAddress);
}
| Identifier
{
$$ = MakeCustomTypeNode(yytext);

View File

@ -13,7 +13,7 @@ struct Program {
static Main(): int {
x: int = 4;
y: int = Foo.Func(x);
addr: uint = @malloc(y);
addr: MemoryAddress = @malloc(y);
@free(addr);
return x;
}

View File

@ -499,6 +499,8 @@ static const char *PrimitiveTypeToString(PrimitiveType type)
return "UInt";
case Bool:
return "Bool";
case MemoryAddress:
return "MemoryAddress";
case Void:
return "Void";
}
@ -728,6 +730,12 @@ void PrintNode(Node *node, uint32_t tabCount)
PrintNode(node->structDeclaration.declarationSequence, tabCount + 1);
return;
case SystemCall:
printf("\n");
PrintNode(node->systemCall.identifier, tabCount + 1);
PrintNode(node->systemCall.argumentSequence, tabCount + 1);
return;
case Type:
printf("\n");
PrintNode(node->type.typeNode, tabCount + 1);

View File

@ -74,7 +74,8 @@ typedef enum
UInt,
Float,
Double,
String
String,
MemoryAddress
} PrimitiveType;
typedef union

View File

@ -204,6 +204,9 @@ static LLVMTypeRef WraithTypeToLLVMType(PrimitiveType type)
case Bool:
return LLVMInt1Type();
case MemoryAddress:
return LLVMInt64Type();
case Void:
return LLVMVoidType();
}