function calls work!!!

This commit is contained in:
SpookyDervish
2025-10-15 06:59:29 +11:00
parent 170146ee7e
commit 049db7c53a
6 changed files with 119 additions and 15 deletions

55
debug/ast.json Normal file
View File

@@ -0,0 +1,55 @@
{
"type": "Program",
"statements": [
{
"FunctionStatement": {
"type": "FunctionStatement",
"name": {
"type": "IdentifierLiteral",
"value": "test"
},
"return_type": "Int",
"parameters": [],
"body": {
"type": "BlockStatement",
"statements": [
{
"type": "ReturnStatement",
"return_value": {
"type": "IntegerLiteral",
"value": 123
}
}
]
}
}
},
{
"FunctionStatement": {
"type": "FunctionStatement",
"name": {
"type": "IdentifierLiteral",
"value": "main"
},
"return_type": "Int",
"parameters": [],
"body": {
"type": "BlockStatement",
"statements": [
{
"type": "ReturnStatement",
"return_value": {
"type": "CallExpression",
"function": {
"type": "IdentifierLiteral",
"value": "test"
},
"arguments": []
}
}
]
}
}
}
]
}

View File

@@ -4,18 +4,19 @@ target datalayout = ""
@"true" = constant i1 1
@"false" = constant i1 0
define i32 @"test"()
{
test_entry:
%".2" = alloca i32
store i32 3, i32* %".2"
%".4" = load i32, i32* %".2"
%".5" = add i32 %".4", 2
ret i32 %".5"
}
define i32 @"main"()
{
main_entry:
%".2" = alloca float
store float 0x4014000000000000, float* %".2"
%".4" = load float, float* %".2"
%".5" = fcmp oeq float %".4", 0x4014000000000000
br i1 %".5", label %"main_entry.if", label %"main_entry.else"
main_entry.if:
ret i32 1
main_entry.else:
ret i32 0
main_entry.endif:
ret i32 0
%".2" = call i32 @"test"()
ret i32 %".2"
}