translator: callbacks passing to C

This commit is contained in:
e5l
2016-07-14 16:13:39 +03:00
parent 517ec41df8
commit 30d71cee03
3 changed files with 10 additions and 9 deletions
@@ -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? {
@@ -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<LLVMVariable>?, 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)
}
@@ -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