Various small fixes. (#208)
This commit is contained in:
-2
@@ -17,8 +17,6 @@ import java.lang.System.out
|
||||
|
||||
internal final class Context(val config: KonanConfig) : KonanBackendContext() {
|
||||
|
||||
val debug = true
|
||||
|
||||
var moduleDescriptor: ModuleDescriptor? = null
|
||||
|
||||
// TODO: make lateinit?
|
||||
|
||||
+2
-2
@@ -32,8 +32,8 @@ internal class CodeGenerator(override val context: Context) : ContextUtils {
|
||||
prologue(llvmFunction,
|
||||
LLVMGetReturnType(getLlvmFunctionType(descriptor))!!)
|
||||
|
||||
if (!descriptor.isExported() && !context.debug) {
|
||||
LLVMSetLinkage(llvmFunction, LLVMLinkage.LLVMPrivateLinkage)
|
||||
if (!descriptor.isExported()) {
|
||||
LLVMSetLinkage(llvmFunction, LLVMLinkage.LLVMInternalLinkage)
|
||||
// (Cannot do this before the function body is created).
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -614,7 +614,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
context.llvm.fileInitializers.add(expression)
|
||||
}
|
||||
|
||||
LLVMSetLinkage(globalProperty, LLVMLinkage.LLVMPrivateLinkage)
|
||||
LLVMSetLinkage(globalProperty, LLVMLinkage.LLVMInternalLinkage)
|
||||
// (Cannot do this before the global is initialized).
|
||||
|
||||
return
|
||||
|
||||
+1
-1
@@ -239,7 +239,7 @@ private class DeclarationsGeneratorVisitor(override val context: Context) :
|
||||
typeInfoSymbolName)!!
|
||||
|
||||
if (!descriptor.isExported()) {
|
||||
LLVMSetLinkage(llvmTypeInfoPtr, LLVMLinkage.LLVMPrivateLinkage)
|
||||
LLVMSetLinkage(llvmTypeInfoPtr, LLVMLinkage.LLVMInternalLinkage)
|
||||
}
|
||||
|
||||
typeInfoPtr = constPointer(llvmTypeInfoPtr)
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ internal class StaticData(override val context: Context): ContextUtils {
|
||||
val llvmGlobal = LLVMAddGlobal(module, type, name)!!
|
||||
|
||||
if (!isExported) {
|
||||
LLVMSetLinkage(llvmGlobal, LLVMLinkage.LLVMPrivateLinkage)
|
||||
LLVMSetLinkage(llvmGlobal, LLVMLinkage.LLVMInternalLinkage)
|
||||
}
|
||||
|
||||
return llvmGlobal
|
||||
|
||||
@@ -559,8 +559,7 @@ OBJ_GETTER(InitInstance,
|
||||
RETURN_OBJ(value);
|
||||
}
|
||||
|
||||
AllocInstance(type_info, OBJ_RESULT);
|
||||
ObjHeader* object = *OBJ_RESULT;
|
||||
ObjHeader* object = AllocInstance(type_info, OBJ_RESULT);
|
||||
UpdateGlobalRef(location, object);
|
||||
try {
|
||||
ctor(object);
|
||||
@@ -574,7 +573,7 @@ OBJ_GETTER(InitInstance,
|
||||
} catch (...) {
|
||||
UpdateLocalRef(OBJ_RESULT, nullptr);
|
||||
UpdateGlobalRef(location, nullptr);
|
||||
RETURN_OBJ(nullptr);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ OBJ_GETTER(AllocInstance, const TypeInfo* type_info) RUNTIME_NOTHROW;
|
||||
OBJ_GETTER(AllocArrayInstance, const TypeInfo* type_info, uint32_t elements) RUNTIME_NOTHROW;
|
||||
OBJ_GETTER(AllocStringInstance, const char* data, uint32_t length) RUNTIME_NOTHROW;
|
||||
OBJ_GETTER(InitInstance,
|
||||
ObjHeader** location, const TypeInfo* type_info, void (*ctor)(ObjHeader*)) RUNTIME_NOTHROW;
|
||||
ObjHeader** location, const TypeInfo* type_info, void (*ctor)(ObjHeader*));
|
||||
|
||||
//
|
||||
// Object reference management.
|
||||
|
||||
@@ -46,7 +46,6 @@ private class IteratorImpl<T>(val collection: Array<T>) : Iterator<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> arrayOf(vararg elements: T) : Array<out T> = elements
|
||||
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun <T> Array<T>.plus(elements: Array<T>): Array<T> {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package kotlin
|
||||
|
||||
import kotlin.collections.*
|
||||
import kotlin.internal.PureReifiable
|
||||
|
||||
// TODO: make all iterator() methods inline.
|
||||
|
||||
@@ -883,3 +884,122 @@ public fun BooleanArray.toHashSet(): HashSet<Boolean> {
|
||||
public fun CharArray.toHashSet(): HashSet<Char> {
|
||||
return toCollection(HashSet<Char>(mapCapacity(size)))
|
||||
}
|
||||
|
||||
// From Library.kt.
|
||||
/**
|
||||
* Returns an array of objects of the given type with the given [size], initialized with null values.
|
||||
*/
|
||||
public inline fun <reified @PureReifiable T> arrayOfNulls(size: Int): Array<T?> =
|
||||
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
|
||||
arrayOfUninitializedElements<T?>(size)
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified elements.
|
||||
*/
|
||||
public inline fun <reified @PureReifiable T> arrayOf(vararg elements: T): Array<T> = elements as Array<T>
|
||||
|
||||
// TODO: optimize those operations.
|
||||
/**
|
||||
* Returns an array containing the specified [Double] numbers.
|
||||
*/
|
||||
|
||||
public fun doubleArrayOf(vararg elements: Double): DoubleArray {
|
||||
val result = DoubleArray(elements.size)
|
||||
var index = 0
|
||||
while (index < elements.size) {
|
||||
result[index] = elements[index]
|
||||
index++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Float] numbers.
|
||||
*/
|
||||
public fun floatArrayOf(vararg elements: Float): FloatArray {
|
||||
val result = FloatArray(elements.size)
|
||||
var index = 0
|
||||
while (index < elements.size) {
|
||||
result[index] = elements[index]
|
||||
index++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Long] numbers.
|
||||
*/
|
||||
public fun longArrayOf(vararg elements: Long): LongArray {
|
||||
val result = LongArray(elements.size)
|
||||
var index = 0
|
||||
while (index < elements.size) {
|
||||
result[index] = elements[index]
|
||||
index++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Int] numbers.
|
||||
*/
|
||||
public fun intArrayOf(vararg elements: Int): IntArray {
|
||||
val result = IntArray(elements.size)
|
||||
var index = 0
|
||||
while (index < elements.size) {
|
||||
result[index] = elements[index]
|
||||
index++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified characters.
|
||||
*/
|
||||
public fun charArrayOf(vararg elements: Char): CharArray {
|
||||
val result = CharArray(elements.size)
|
||||
var index = 0
|
||||
while (index < elements.size) {
|
||||
result[index] = elements[index]
|
||||
index++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Short] numbers.
|
||||
*/
|
||||
public fun shortArrayOf(vararg elements: Short): ShortArray {
|
||||
val result = ShortArray(elements.size)
|
||||
var index = 0
|
||||
while (index < elements.size) {
|
||||
result[index] = elements[index]
|
||||
index++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified [Byte] numbers.
|
||||
*/
|
||||
public fun byteArrayOf(vararg elements: Byte): ByteArray {
|
||||
val result = ByteArray(elements.size)
|
||||
var index = 0
|
||||
while (index < elements.size) {
|
||||
result[index] = elements[index]
|
||||
index++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the specified boolean values.
|
||||
*/
|
||||
public fun booleanArrayOf(vararg elements: Boolean): BooleanArray {
|
||||
val result = BooleanArray(elements.size)
|
||||
var index = 0
|
||||
while (index < elements.size) {
|
||||
result[index] = elements[index]
|
||||
index++
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -43,6 +43,7 @@ public final class String : Comparable<String>, CharSequence {
|
||||
|
||||
// TODO: in big Kotlin this operations are in kotlin.kotlin_builtins.
|
||||
private val kNullString = "<null>"
|
||||
|
||||
public operator fun kotlin.String?.plus(other: kotlin.Any?): kotlin.String =
|
||||
this?.plus(other?.toString() ?: kNullString) ?: other?.toString() ?: kNullString
|
||||
|
||||
|
||||
@@ -37,7 +37,12 @@ class HashMap<K, V> private constructor(
|
||||
override fun containsKey(key: K): Boolean = findKey(key) >= 0
|
||||
override fun containsValue(value: V): Boolean = findValue(value) >= 0
|
||||
|
||||
override fun get(key: K): V? {
|
||||
|
||||
operator fun set(key: K, value: V): Unit {
|
||||
put(key, value)
|
||||
}
|
||||
|
||||
override operator fun get(key: K): V? {
|
||||
val index = findKey(key)
|
||||
if (index < 0) return null
|
||||
return valuesArray!![index]
|
||||
|
||||
@@ -52,3 +52,11 @@ internal annotation class InlineOnly
|
||||
@Target(AnnotationTarget.CLASS, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
internal annotation class InlineExposed
|
||||
|
||||
/**
|
||||
* Specifies that the corresponding type parameter is not used for unsafe operations such as casts or 'is' checks
|
||||
* That means it's completely safe to use generic types as argument for such parameter.
|
||||
*/
|
||||
@Target(AnnotationTarget.TYPE_PARAMETER)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
internal annotation class PureReifiable
|
||||
|
||||
Reference in New Issue
Block a user