Rewrote callable reference lowering

For each callable reference a class inherited from KFunctionImpl is built.
This commit is contained in:
Igor Chevdar
2017-05-12 18:41:26 +03:00
parent dc80ba3492
commit a41552b3c8
12 changed files with 528 additions and 326 deletions
@@ -1,39 +0,0 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package konan.internal
/**
* Represents the reference to callable without any bound arguments.
* It is supposed to be represented at runtime as native pointer to code.
*
* TODO: it seems to be very closely related to native interop types.
*/
abstract class UnboundCallableReference internal constructor()
/**
* Values of function types are represented at runtime as instances of this class (and its subclasses).
*
* [FunctionImpl] is a reference to callable with itself as single bound argument,
* i.e. when calling this function with arguments `args`, [unboundRef] is called with arguments `(this, *args)`.
* So the instance is supposed to contain all implicit (bound) arguments of target function, e.g. captured values.
*/
open class FunctionImpl(val unboundRef: UnboundCallableReference)
/**
* Simple [FunctionImpl] implementation: all bound arguments of target callable to be placed into [boundArgs].
*/
class SimpleFunctionImpl(unboundRef: UnboundCallableReference, vararg val boundArgs: Any?) : FunctionImpl(unboundRef)
@@ -0,0 +1,35 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package konan.internal
import kotlin.reflect.KFunction
@FixmeReflection
open class KFunctionImpl<out R>(override val name: String, val fqName: String, val bound: Boolean, val receiver: Any?): KFunction<R> {
override fun equals(other: Any?): Boolean {
if (other !is KFunctionImpl<*>) return false
return fqName == other.fqName && bound == other.bound && receiver == other.receiver
}
override fun hashCode(): Int {
return (fqName.hashCode() * 31 + if (bound) 1 else 0) * 31 + receiver.hashCode()
}
override fun toString(): String {
return fqName
}
}
@@ -65,11 +65,11 @@ public interface KProperty<out R> : KCallable<R> {
//
@FixmeReflection
public interface KProperty0<out R> : kotlin.reflect.KProperty<R>/* TODO , (T) -> R*/ {
public interface KProperty0<out R> : kotlin.reflect.KProperty<R>, () -> R {
// public abstract val getter: kotlin.reflect.KProperty1.Getter<T, R>
public abstract fun get(): R
public abstract operator fun invoke(): R
public override abstract operator fun invoke(): R
// @kotlin.SinceKotlin public abstract fun getDelegate(receiver: T): kotlin.Any?
//
@@ -78,11 +78,11 @@ public interface KProperty0<out R> : kotlin.reflect.KProperty<R>/* TODO , (T) ->
}
@FixmeReflection
public interface KProperty1<T, out R> : kotlin.reflect.KProperty<R>/* TODO , (T) -> R*/ {
public interface KProperty1<T, out R> : kotlin.reflect.KProperty<R>, (T) -> R {
// public abstract val getter: kotlin.reflect.KProperty1.Getter<T, R>
public abstract fun get(receiver: T): R
public abstract operator fun invoke(receiver: T): R
public override abstract operator fun invoke(receiver: T): R
// @kotlin.SinceKotlin public abstract fun getDelegate(receiver: T): kotlin.Any?
//
@@ -91,11 +91,11 @@ public interface KProperty1<T, out R> : kotlin.reflect.KProperty<R>/* TODO , (T)
}
@FixmeReflection
public interface KProperty2<T1, T2, out R> : kotlin.reflect.KProperty<R>/* TODO , (T) -> R*/ {
public interface KProperty2<T1, T2, out R> : kotlin.reflect.KProperty<R>, (T1, T2) -> R {
// public abstract val getter: kotlin.reflect.KProperty1.Getter<T, R>
public abstract fun get(receiver1: T1, receiver2: T2): R
public abstract operator fun invoke(receiver1: T1, receiver2: T2): R
public override abstract operator fun invoke(receiver1: T1, receiver2: T2): R
// @kotlin.SinceKotlin public abstract fun getDelegate(receiver: T): kotlin.Any?
//