translator: fixes for method calls, class return, this arg
This commit is contained in:
@@ -36,6 +36,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
|||||||
is KtBinaryExpression -> evaluateBinaryExpression(expr, scopeDepth)
|
is KtBinaryExpression -> evaluateBinaryExpression(expr, scopeDepth)
|
||||||
is KtCallExpression -> evaluateCallExpression(expr, scopeDepth)
|
is KtCallExpression -> evaluateCallExpression(expr, scopeDepth)
|
||||||
is KtDoWhileExpression -> evaluateDoWhileExpression(expr.firstChild, scopeDepth + 1)
|
is KtDoWhileExpression -> evaluateDoWhileExpression(expr.firstChild, scopeDepth + 1)
|
||||||
|
is KtDotQualifiedExpression -> evaluateDotExpression(expr, scopeDepth)
|
||||||
is PsiElement -> evaluateExpression(expr.firstChild, scopeDepth + 1)
|
is PsiElement -> evaluateExpression(expr.firstChild, scopeDepth + 1)
|
||||||
null -> {
|
null -> {
|
||||||
variableManager.pullUpwardsLevel(scopeDepth)
|
variableManager.pullUpwardsLevel(scopeDepth)
|
||||||
@@ -60,9 +61,9 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
|||||||
is KtConstantExpression -> evaluateConstantExpression(expr)
|
is KtConstantExpression -> evaluateConstantExpression(expr)
|
||||||
is KtCallExpression -> evaluateCallExpression(expr, scopeDepth)
|
is KtCallExpression -> evaluateCallExpression(expr, scopeDepth)
|
||||||
is KtCallableReferenceExpression -> evaluateCallableReferenceExpression(expr)
|
is KtCallableReferenceExpression -> evaluateCallableReferenceExpression(expr)
|
||||||
|
is KtDotQualifiedExpression -> evaluateDotExpression(expr, scopeDepth)
|
||||||
is KtReferenceExpression -> evaluateReferenceExpression(expr, scopeDepth)
|
is KtReferenceExpression -> evaluateReferenceExpression(expr, scopeDepth)
|
||||||
is KtIfExpression -> evaluateIfOperator(expr.firstChild as LeafPsiElement, scopeDepth + 1, true)
|
is KtIfExpression -> evaluateIfOperator(expr.firstChild as LeafPsiElement, scopeDepth + 1, true)
|
||||||
is KtDotQualifiedExpression -> evaluateDotExpression(expr, scopeDepth)
|
|
||||||
is KtStringTemplateExpression -> evaluateStringTemplateExpression(expr)
|
is KtStringTemplateExpression -> evaluateStringTemplateExpression(expr)
|
||||||
is PsiWhiteSpace -> null
|
is PsiWhiteSpace -> null
|
||||||
is PsiElement -> evaluatePsiElement(expr, scopeDepth)
|
is PsiElement -> evaluatePsiElement(expr, scopeDepth)
|
||||||
@@ -102,12 +103,14 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
|||||||
val methodName = clazz.structName + '.' + selectorName.substringBefore('(')
|
val methodName = clazz.structName + '.' + selectorName.substringBefore('(')
|
||||||
val method = clazz.methods[methodName]!!
|
val method = clazz.methods[methodName]!!
|
||||||
val returnType = clazz.methods[methodName]!!.returnType!!.type
|
val returnType = clazz.methods[methodName]!!.returnType!!.type
|
||||||
val methodArgs = mutableListOf<LLVMSingleValue>(receiver)
|
|
||||||
|
|
||||||
val names = parseArgList(expr.lastChild as KtCallExpression, scopeDepth)
|
val names = parseArgList(expr.lastChild as KtCallExpression, scopeDepth)
|
||||||
methodArgs.addAll(names)
|
val loadedArgs = loadArgsIfRequired(names, method.args)
|
||||||
|
val callArgs = mutableListOf<LLVMSingleValue>(receiver)
|
||||||
|
callArgs.addAll(loadedArgs)
|
||||||
|
|
||||||
return evaluateFunctionCallExpression(LLVMVariable(methodName, returnType, scope = LLVMVariableScope()), loadArgsIfRequired(methodArgs, method.args))
|
|
||||||
|
return evaluateFunctionCallExpression(LLVMVariable(methodName, returnType, scope = LLVMVariableScope()), callArgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import org.kotlinnative.translator.llvm.types.LLVMVoidType
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
class FunctionCodegen(override val state: TranslationState, override val variableManager: VariableManager, val function: KtNamedFunction, override val codeBuilder: LLVMBuilder) :
|
class FunctionCodegen(override val state: TranslationState, override val variableManager: VariableManager, val function: KtNamedFunction,
|
||||||
|
override val codeBuilder: LLVMBuilder) :
|
||||||
BlockCodegen(state, variableManager, codeBuilder) {
|
BlockCodegen(state, variableManager, codeBuilder) {
|
||||||
|
|
||||||
var name = function.fqName.toString()
|
var name = function.fqName.toString()
|
||||||
@@ -23,6 +24,7 @@ class FunctionCodegen(override val state: TranslationState, override val variabl
|
|||||||
LLVMMapStandardType(it.name.toString(), it.type)
|
LLVMMapStandardType(it.name.toString(), it.type)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
returnType = LLVMMapStandardType("instance", descriptor.returnType!!)
|
returnType = LLVMMapStandardType("instance", descriptor.returnType!!)
|
||||||
val retType = returnType!!.type
|
val retType = returnType!!.type
|
||||||
when (retType) {
|
when (retType) {
|
||||||
@@ -57,9 +59,6 @@ class FunctionCodegen(override val state: TranslationState, override val variabl
|
|||||||
private fun generateDeclaration(this_type: LLVMVariable? = null): Boolean {
|
private fun generateDeclaration(this_type: LLVMVariable? = null): Boolean {
|
||||||
var external = false
|
var external = false
|
||||||
|
|
||||||
if (this_type != null) {
|
|
||||||
args.addFirst(this_type)
|
|
||||||
}
|
|
||||||
args.forEach {
|
args.forEach {
|
||||||
val type = it.type
|
val type = it.type
|
||||||
if (type is LLVMReferenceType && state.classes.containsKey(type.type)) {
|
if (type is LLVMReferenceType && state.classes.containsKey(type.type)) {
|
||||||
@@ -85,6 +84,10 @@ class FunctionCodegen(override val state: TranslationState, override val variabl
|
|||||||
actualArgs.add(returnType!!)
|
actualArgs.add(returnType!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this_type != null) {
|
||||||
|
actualArgs.add(this_type)
|
||||||
|
}
|
||||||
|
|
||||||
actualArgs.addAll(args)
|
actualArgs.addAll(args)
|
||||||
|
|
||||||
codeBuilder.addLLVMCode(LLVMFunctionDescriptor(function.fqName.toString(), actualArgs, actualReturnType, external, state.arm))
|
codeBuilder.addLLVMCode(LLVMFunctionDescriptor(function.fqName.toString(), actualArgs, actualReturnType, external, state.arm))
|
||||||
|
|||||||
Reference in New Issue
Block a user