diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/FunctionCodegen.kt b/translator/src/main/kotlin/org/kotlinnative/translator/FunctionCodegen.kt index dadd3d26ff4..198599a310e 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/FunctionCodegen.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/FunctionCodegen.kt @@ -4,6 +4,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.context.GlobalContext import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments @@ -160,7 +161,7 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction private fun evaluateCallableReferenceExpression(expr: KtCallableReferenceExpression): LLVMSingleValue? { val kotlinType = state.bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, expr)!!.type!! - return LLVMMapStandardType(expr.text.substring(2), kotlinType) + return LLVMMapStandardType(expr.text.substring(2), kotlinType, LLVMGlobalScope()) } private fun evaluateDotExpression(expr: KtDotQualifiedExpression): LLVMSingleValue? { diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/generators.kt b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/generators.kt index 47d1c1d69cf..ff29d9a1025 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/generators.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/generators.kt @@ -1,6 +1,7 @@ package org.kotlinnative.translator.llvm import org.jetbrains.kotlin.builtins.isFunctionType +import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.isUnit import org.kotlinnative.translator.llvm.types.* @@ -12,11 +13,10 @@ fun LLVMFunctionDescriptor(name: String, argTypes: List?, returnTy "${s.getType()} ${if (s.type is LLVMReferenceType && !(s.type as LLVMReferenceType).isReturn) "byval" else ""} %${s.label}" }?.joinToString()}) ${if (arm) "#0" else ""}" -fun LLVMMapStandardType(name: String, type: KotlinType): LLVMVariable = when { - type.isFunctionType -> LLVMVariable(name, LLVMFunctionType(type), type.toString(), pointer = true) - type.toString() == "Int" -> LLVMVariable(name, LLVMIntType(), type.toString()) - type.toString() == "Double" -> LLVMVariable(name, LLVMDoubleType(), type.toString()) - type.toString() == "Char" -> LLVMVariable(name, LLVMCharType(), type.toString()) - type.isUnit() -> LLVMVariable("", LLVMVoidType()) - else -> LLVMVariable(name, LLVMReferenceType("$type"), name, pointer = true) +fun LLVMMapStandardType(name: String, type: KotlinType, scope: LLVMScope = LLVMLocalScope()): LLVMVariable = when { + type.isFunctionTypeOrSubtype -> LLVMVariable(name, LLVMFunctionType(type), type.toString(), scope, pointer = true) + type.toString() == "Int" -> LLVMVariable(name, LLVMIntType(), type.toString(), scope) + type.toString() == "Double" -> LLVMVariable(name, LLVMDoubleType(), type.toString(), scope) + type.isUnit() -> LLVMVariable("", LLVMVoidType(), "", scope) + else -> LLVMVariable(name, LLVMReferenceType("$type"), name, scope, pointer = true) } \ No newline at end of file diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMFunctionType.kt b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMFunctionType.kt index de36ddf3dec..06021dba7cc 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMFunctionType.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMFunctionType.kt @@ -6,7 +6,7 @@ import org.kotlinnative.translator.llvm.LLVMVariable class LLVMFunctionType(type: KotlinType) : LLVMType() { - override val defaultValue = throw UnsupportedOperationException() + override val defaultValue = "" override val align: Int = 4 override val size: Byte = 4