backend: instantiate string literals statically

also improve other code for static instantiation
This commit is contained in:
Svyatoslav Scherbina
2016-11-07 01:03:53 +07:00
committed by SvyatoslavScherbina
parent fddaea5624
commit 674713f429
12 changed files with 333 additions and 103 deletions
@@ -10,7 +10,7 @@ fun free(ptr: NativePtr?) {
fun free(ref: NativeRef?) = free(ref.getNativePtr())
fun <T : NativeRef> Placement.allocNativeArrayOf(elemType: NativeRef.Type<T>, vararg elements: T?): NativeArray<RefBox<T>> {
fun <T : NativeRef> Placement.allocNativeArrayOf(elemType: NativeRef.Type<T>, elements: List<T?>): NativeArray<RefBox<T>> {
val res = this.alloc(array[elements.size](elemType.ref))
elements.forEachIndexed { i, element ->
res[i].value = element
@@ -18,6 +18,9 @@ fun <T : NativeRef> Placement.allocNativeArrayOf(elemType: NativeRef.Type<T>, va
return res
}
fun <T : NativeRef> Placement.allocNativeArrayOf(elemType: NativeRef.Type<T>, vararg elements: T?) =
allocNativeArrayOf(elemType, elements.toList())
fun <T : NativeRef> mallocNativeArrayOf(elemType: NativeRef.Type<T>, vararg elements: T?) = heap.allocNativeArrayOf(elemType, *elements)
fun Placement.allocNativeArrayOf(elements: ByteArray): NativeArray<Int8Box> {