Add very basic output, small refactoring. (#14)
Add very basic output, small refactoring.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "Assert.h"
|
||||
#include "Exceptions.h"
|
||||
@@ -8,6 +9,7 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
// Arrays.kt
|
||||
// TODO: those must be compiler intrinsics afterwards.
|
||||
KByte Kotlin_ByteArray_get(const ArrayHeader* obj, KInt index) {
|
||||
if (static_cast<uint32_t>(index) >= obj->count_) {
|
||||
@@ -93,6 +95,14 @@ KInt Kotlin_IntArray_getArrayLength(const ArrayHeader* array) {
|
||||
return array->count_;
|
||||
}
|
||||
|
||||
// io/Console.kt
|
||||
void Kotlin_io_Console_print(const ArrayHeader* array) {
|
||||
RuntimeAssert(array->type_info_ == theStringTypeInfo, "Must use a string");
|
||||
// TODO: system stdout must be aware about UTF-8.
|
||||
write(STDOUT_FILENO, ByteArrayAddressOfElementAt(array, 0), array->count_);
|
||||
}
|
||||
|
||||
// String.kt
|
||||
KInt Kotlin_String_compareTo(const ArrayHeader* obj, const ArrayHeader* other) {
|
||||
return memcmp(ByteArrayAddressOfElementAt(obj, 0),
|
||||
ByteArrayAddressOfElementAt(other, 0),
|
||||
|
||||
@@ -41,6 +41,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// TODO: those must be compiler intrinsics afterwards.
|
||||
// Arrays.kt
|
||||
ArrayHeader* Kotlin_ByteArray_clone(const ArrayHeader* obj);
|
||||
KByte Kotlin_ByteArray_get(const ArrayHeader* obj, KInt index);
|
||||
void Kotlin_ByteArray_set(ArrayHeader* obj, KInt index, KByte value);
|
||||
@@ -56,6 +57,10 @@ KInt Kotlin_IntArray_get(const ArrayHeader* obj, KInt index);
|
||||
void Kotlin_IntArray_set(ArrayHeader* obj, KInt index, KInt value);
|
||||
KInt Kotlin_IntArray_getArrayLength(const ArrayHeader* obj);
|
||||
|
||||
// io/Console.kt
|
||||
void Kotlin_io_Console_print(const ArrayHeader* obj);
|
||||
|
||||
// String.kt
|
||||
KInt Kotlin_String_compareTo(const ArrayHeader* obj, const ArrayHeader* other);
|
||||
KChar Kotlin_String_get(const ArrayHeader* obj, KInt index);
|
||||
ArrayHeader* Kotlin_String_fromUtf8Array(const ArrayHeader* array);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package kotlin_native
|
||||
|
||||
class ByteArray : Cloneable {
|
||||
// Constructors are handled with compiler magic.
|
||||
private constructor() {}
|
||||
|
||||
public val size: Int
|
||||
get() = getArrayLength()
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_get")
|
||||
external public operator fun get(index: Int): Byte
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_set")
|
||||
external public operator fun set(index: Int, value: Byte): Unit
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_clone")
|
||||
external public override fun clone(): Any
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getArrayLength")
|
||||
external private fun getArrayLength(): Int
|
||||
}
|
||||
|
||||
class CharArray : Cloneable {
|
||||
// Constructors are handled with the compiler magic.
|
||||
private constructor() {}
|
||||
|
||||
public val size: Int
|
||||
get() = getArrayLength()
|
||||
|
||||
@SymbolName("Kotlin_CharArray_get")
|
||||
external public operator fun get(index: Int): Char
|
||||
|
||||
@SymbolName("Kotlin_CharArray_set")
|
||||
external public operator fun set(index: Int, value: Char): Unit
|
||||
|
||||
@SymbolName("Kotlin_CharArray_clone")
|
||||
external public override fun clone(): Any
|
||||
|
||||
@SymbolName("Kotlin_CharArray_getArrayLength")
|
||||
external private fun getArrayLength(): Int
|
||||
}
|
||||
|
||||
class IntArray : Cloneable {
|
||||
// Constructors are handled with the compiler magic.
|
||||
private constructor() {}
|
||||
|
||||
public val size: Int
|
||||
get() = getArrayLength()
|
||||
|
||||
@SymbolName("Kotlin_IntArray_get")
|
||||
external public operator fun get(index: Int): Char
|
||||
|
||||
@SymbolName("Kotlin_IntArray_set")
|
||||
external public operator fun set(index: Int, value: Char): Unit
|
||||
|
||||
@SymbolName("Kotlin_IntArray_clone")
|
||||
external public override fun clone(): Any
|
||||
|
||||
@SymbolName("Kotlin_IntArray_getArrayLength")
|
||||
external private fun getArrayLength(): Int
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package kotlin_native
|
||||
|
||||
public interface Cloneable {
|
||||
public fun clone(): Any
|
||||
}
|
||||
@@ -1,60 +1,5 @@
|
||||
package kotlin_native
|
||||
|
||||
public interface Cloneable {
|
||||
public fun clone(): Any
|
||||
}
|
||||
|
||||
class ByteArray(size: Int) : Cloneable {
|
||||
public val size: Int
|
||||
get() = getArrayLength()
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_get")
|
||||
external public operator fun get(index: Int): Byte
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_set")
|
||||
external public operator fun set(index: Int, value: Byte): Unit
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_clone")
|
||||
external public override fun clone(): Any
|
||||
|
||||
@SymbolName("Kotlin_ByteArray_getArrayLength")
|
||||
external private fun getArrayLength(): Int
|
||||
}
|
||||
|
||||
class CharArray(size: Int) : Cloneable {
|
||||
public val size: Int
|
||||
get() = getArrayLength()
|
||||
|
||||
@SymbolName("Kotlin_CharArray_get")
|
||||
external public operator fun get(index: Int): Char
|
||||
|
||||
@SymbolName("Kotlin_CharArray_set")
|
||||
external public operator fun set(index: Int, value: Char): Unit
|
||||
|
||||
@SymbolName("Kotlin_CharArray_clone")
|
||||
external public override fun clone(): Any
|
||||
|
||||
@SymbolName("Kotlin_CharArray_getArrayLength")
|
||||
external private fun getArrayLength(): Int
|
||||
}
|
||||
|
||||
class IntArray(size: Int) : Cloneable {
|
||||
public val size: Int
|
||||
get() = getArrayLength()
|
||||
|
||||
@SymbolName("Kotlin_IntArray_get")
|
||||
external public operator fun get(index: Int): Char
|
||||
|
||||
@SymbolName("Kotlin_IntArray_set")
|
||||
external public operator fun set(index: Int, value: Char): Unit
|
||||
|
||||
@SymbolName("Kotlin_IntArray_clone")
|
||||
external public override fun clone(): Any
|
||||
|
||||
@SymbolName("Kotlin_IntArray_getArrayLength")
|
||||
external private fun getArrayLength(): Int
|
||||
}
|
||||
|
||||
@SymbolName("Kotlin_String_fromUtf8Array")
|
||||
external fun fromUtf8Array(array: ByteArray) : String
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package kotlin_native.io
|
||||
|
||||
@kotlin_native.SymbolName("Kotlin_io_Console_print")
|
||||
external public fun print(message: kotlin_native.String)
|
||||
Reference in New Issue
Block a user