From 1ba2ba35e215797b5a17e6267dd3c103799e0b16 Mon Sep 17 00:00:00 2001 From: Alexey Stepanov Date: Thu, 11 Aug 2016 18:56:13 +0300 Subject: [PATCH] translator: add custom type size dependenton on architecture --- kotstd/include/BooleanArray.kt | 7 ++++--- kotstd/include/ByteArray.kt | 3 ++- kotstd/include/IntArray.kt | 3 ++- kotstd/include/ShortArray.kt | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/kotstd/include/BooleanArray.kt b/kotstd/include/BooleanArray.kt index 3b2200059f1..656b2771ea1 100644 --- a/kotstd/include/BooleanArray.kt +++ b/kotstd/include/BooleanArray.kt @@ -1,3 +1,5 @@ +external fun kotlinclib_boolean_size(): Int + class BooleanArray(var size: Int) { val data: Int @@ -5,7 +7,7 @@ class BooleanArray(var size: Int) { //size: Int init { - this.data = malloc_array(this.size) + this.data = malloc_array(kotlinclib_boolean_size() * this.size) } /** Returns the array element at the given [index]. This method can be called using the index operator. */ @@ -19,8 +21,7 @@ class BooleanArray(var size: Int) { operator fun set(index: Int, value: Boolean) { if (value == true) { kotlinclib_set_byte(this.data, index, 1.toByte()) - } - else{ + } else { kotlinclib_set_byte(this.data, index, 0.toByte()) } } diff --git a/kotstd/include/ByteArray.kt b/kotstd/include/ByteArray.kt index 904ecd1f6f1..fbcac272ca6 100644 --- a/kotstd/include/ByteArray.kt +++ b/kotstd/include/ByteArray.kt @@ -1,6 +1,7 @@ external fun malloc_array(size: Int): Int external fun kotlinclib_get_byte(src: Int, index: Int): Byte external fun kotlinclib_set_byte(src: Int, index: Int, value: Byte) +external fun kotlinclib_byte_size(): Int class ByteArray(var size: Int) { @@ -10,7 +11,7 @@ class ByteArray(var size: Int) { //size: Int init { - this.data = malloc_array(this.size) + this.data = malloc_array(kotlinclib_byte_size() * this.size) } /** Returns the array element at the given [index]. This method can be called using the index operator. */ diff --git a/kotstd/include/IntArray.kt b/kotstd/include/IntArray.kt index d731c28b8cf..e2b9d616b44 100644 --- a/kotstd/include/IntArray.kt +++ b/kotstd/include/IntArray.kt @@ -1,5 +1,6 @@ external fun kotlinclib_get_int(src: Int, index: Int): Int external fun kotlinclib_set_int(src: Int, index: Int, value: Int) +external fun kotlinclib_int_size(): Int class IntArray(var size: Int) { @@ -9,7 +10,7 @@ class IntArray(var size: Int) { //size: Int init { - this.data = malloc_array(4 * this.size) + this.data = malloc_array(kotlinclib_int_size() * this.size) } /** Returns the array element at the given [index]. This method can be called using the index operator. */ diff --git a/kotstd/include/ShortArray.kt b/kotstd/include/ShortArray.kt index b9c6bf07070..a9c5ec0672f 100644 --- a/kotstd/include/ShortArray.kt +++ b/kotstd/include/ShortArray.kt @@ -1,5 +1,6 @@ external fun kotlinclib_get_short(src: Int, index: Int): Short external fun kotlinclib_set_short(src: Int, index: Int, value: Short) +external fun kotlinclib_short_size(): Int class ShortArray(var size: Int) { @@ -9,7 +10,7 @@ class ShortArray(var size: Int) { //size: Int init { - this.data = malloc_array(this.size) + this.data = malloc_array(kotlinclib_short_size() * this.size) } /** Returns the array element at the given [index]. This method can be called using the index operator. */