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; "double" return DOUBLE;
"string" return STRING; "string" return STRING;
"bool" return BOOL; "bool" return BOOL;
"MemoryAddress" return MEMORYADDRESS;
"struct" return STRUCT; "struct" return STRUCT;
"return" return RETURN; "return" return RETURN;
"static" return STATIC; "static" return STATIC;

View File

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

View File

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

View File

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

View File

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

View File

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