codegen fixes

ast_refactor
cosmonaut 2021-05-16 00:23:52 -07:00
parent 459a1dd3b7
commit 876e8deb6e
2 changed files with 7 additions and 5 deletions

View File

@ -54,6 +54,8 @@ struct Program
myStruct.myInt = 4; myStruct.myInt = 4;
} }
return myStruct.myInt; Console.PrintLine("%i", myStruct.myInt);
return 0;
} }
} }

View File

@ -509,7 +509,7 @@ static LLVMValueRef CompileFunctionCallExpression(
if (functionCallExpression->functionCallExpression.identifier->syntaxKind == AccessExpression) if (functionCallExpression->functionCallExpression.identifier->syntaxKind == AccessExpression)
{ {
LLVMTypeRef typeReference = FindStructType( LLVMTypeRef typeReference = FindStructType(
functionCallExpression->functionCallExpression.identifier->identifier.name functionCallExpression->functionCallExpression.identifier->accessExpression.accessee->identifier.name
); );
if (typeReference != NULL) if (typeReference != NULL)
@ -708,7 +708,7 @@ static LLVMBasicBlockRef CompileIfElseStatement(LLVMBuilderRef builder, LLVMValu
for (i = 0; i < ifElseStatement->ifElseStatement.ifStatement->ifStatement.statementSequence->statementSequence.count; i += 1) for (i = 0; i < ifElseStatement->ifElseStatement.ifStatement->ifStatement.statementSequence->statementSequence.count; i += 1)
{ {
CompileStatement(builder, function, ifElseStatement->ifStatement.statementSequence->statementSequence.sequence[i]); CompileStatement(builder, function, ifElseStatement->ifElseStatement.ifStatement->ifStatement.statementSequence->statementSequence.sequence[i]);
} }
LLVMBuildBr(builder, afterCond); LLVMBuildBr(builder, afterCond);
@ -900,13 +900,13 @@ static void CompileFunction(
for (i = 0; i < functionSignature->functionSignature.arguments->functionSignatureArguments.count; i += 1) for (i = 0; i < functionSignature->functionSignature.arguments->functionSignatureArguments.count; i += 1)
{ {
char *ptrName = strdup(functionSignature->functionSignature.arguments->functionSignatureArguments.sequence[i]->identifier.name); char *ptrName = strdup(functionSignature->functionSignature.arguments->functionSignatureArguments.sequence[i]->declaration.identifier->identifier.name);
strcat(ptrName, "_ptr"); strcat(ptrName, "_ptr");
LLVMValueRef argument = LLVMGetParam(function, i + !isStatic); LLVMValueRef argument = LLVMGetParam(function, i + !isStatic);
LLVMValueRef argumentCopy = LLVMBuildAlloca(builder, LLVMTypeOf(argument), ptrName); LLVMValueRef argumentCopy = LLVMBuildAlloca(builder, LLVMTypeOf(argument), ptrName);
LLVMBuildStore(builder, argument, argumentCopy); LLVMBuildStore(builder, argument, argumentCopy);
free(ptrName); free(ptrName);
AddLocalVariable(scope, argumentCopy, NULL, functionSignature->functionSignature.arguments->functionSignatureArguments.sequence[i]->identifier.name); AddLocalVariable(scope, argumentCopy, NULL, functionSignature->functionSignature.arguments->functionSignatureArguments.sequence[i]->declaration.identifier->identifier.name);
} }
for (i = 0; i < functionBody->statementSequence.count; i += 1) for (i = 0; i < functionBody->statementSequence.count; i += 1)