Simplified launcher to utilize some ready made functionality.

This commit is contained in:
Alexander Gorshenev
2016-12-01 15:58:27 +03:00
committed by alexander-gorshenev
parent 62be62e5d6
commit 2c89fee837
8 changed files with 46 additions and 35 deletions
+3 -1
View File
@@ -23,7 +23,9 @@ abstract class KonanTest extends DefaultTask {
public KonanTest(){
dependsOn([project.project(":runtime").tasks['build'],
project.parent.tasks['build'],
project.project(":backend.native").tasks['stdlib']])
project.project(":backend.native").tasks['stdlib'],
project.project(":backend.native").tasks['start']
])
}
+2 -9
View File
@@ -3,20 +3,13 @@
#include "Natives.h"
#include "Types.h"
extern "C" ArrayHeader* konanArrayInit(ArrayHeader*, int)
asm("_kfun:kotlin.Array.<init>(Int)");
extern "C" const TypeInfo konanArrayType
asm("_ktype:kotlin.Array");
ArrayHeader* setupArgs(int argc, char** argv) {
// The count is one less, because we skip argv[0] which is the binary name.
ArrayHeader* array = AllocArrayInstance(&konanArrayType, SCOPE_GLOBAL, argc-1);
ArrayHeader* args = konanArrayInit(array, argc-1);
ArrayHeader* args = AllocArrayInstance(theArrayTypeInfo, SCOPE_GLOBAL, argc-1);
for (int i = 0; i < argc-1; i++) {
Kotlin_Array_set(args, i, (ArrayHeader*) makeString( argv[i+1] ));
Kotlin_Array_set(args, i, AllocStringInstance( argv[i+1] ));
}
return args;
+11
View File
@@ -1,8 +1,10 @@
#include <string.h>
#include <stdlib.h>
#include "Assert.h"
#include "Exceptions.h"
#include "Memory.h"
#include "Natives.h"
void FreeObject(ContainerHeader* header) {
header->ref_count_ = CONTAINER_TAG_INVALID;
@@ -87,6 +89,15 @@ ArrayHeader* AllocArrayInstance(
return ArrayContainer(type_info, elements).GetPlace();
}
ArrayHeader* AllocStringInstance(const char* cstring) {
uint32_t length = strlen(cstring);
ArrayHeader* result = ArrayContainer(theStringTypeInfo, length).GetPlace();
memcpy(
ByteArrayAddressOfElementAt(result, 0),
cstring,
length);
return result;
}
#ifdef __cplusplus
}
#endif
+2 -12
View File
@@ -79,18 +79,6 @@ struct ArenaContainerHeader : public ContainerHeader {
uint8_t* end_;
};
inline void* AddressOfElementAt(ArrayHeader* obj, int32_t index) {
// Instance size is negative.
return reinterpret_cast<uint8_t*>(obj + 1) -
obj->type_info()->instanceSize_ * index;
}
inline const void* AddressOfElementAt(const ArrayHeader* obj, int32_t index) {
// Instance size is negative.
return reinterpret_cast<const uint8_t*>(obj + 1) -
obj->type_info()->instanceSize_ * index;
}
inline uint32_t ArrayDataSizeBytes(const ArrayHeader* obj) {
// Instance size is negative.
return -obj->type_info()->instanceSize_ * obj->count_;
@@ -266,6 +254,8 @@ void InitMemory();
ObjHeader* AllocInstance(const TypeInfo* type_info, PlacementHint hint);
ArrayHeader* AllocArrayInstance(
const TypeInfo* type_info, PlacementHint hint, uint32_t elements);
ArrayHeader* AllocStringInstance(const char* cstring);
#ifdef __cplusplus
}
#endif
-11
View File
@@ -180,15 +180,4 @@ KString Kotlin_String_subSequence(KString thiz, KInt startIndex, KInt endIndex)
return result;
}
KString makeString(const char* cstring) {
uint32_t length = strlen(cstring);
ArrayHeader* result = ArrayContainer(
theStringTypeInfo, length).GetPlace();
memcpy(
ByteArrayAddressOfElementAt(result, 0),
cstring,
length);
return result;
}
} // extern "C"
+12 -2
View File
@@ -3,6 +3,18 @@
#include "Types.h"
inline void* AddressOfElementAt(ArrayHeader* obj, int32_t index) {
// Instance size is negative.
return reinterpret_cast<uint8_t*>(obj + 1) -
obj->type_info()->instanceSize_ * index;
}
inline const void* AddressOfElementAt(const ArrayHeader* obj, int32_t index) {
// Instance size is negative.
return reinterpret_cast<const uint8_t*>(obj + 1) -
obj->type_info()->instanceSize_ * index;
}
// Optimized versions not accessing type info.
inline KByte* ByteArrayAddressOfElementAt(ArrayHeader* obj, KInt index) {
return reinterpret_cast<KByte*>(obj + 1) + index;
@@ -39,8 +51,6 @@ extern "C" {
KString TheEmptyString();
KString makeString(const char* cstring);
// Any.kt
KBoolean Kotlin_Any_equals(KConstRef thiz, KConstRef other);
KInt Kotlin_Any_hashCode(KConstRef thiz);
+15
View File
@@ -7,6 +7,21 @@
#include "Natives.h"
#include "Types.h"
namespace {
KString makeString(const char* cstring) {
uint32_t length = strlen(cstring);
ArrayHeader* result = ArrayContainer(
theStringTypeInfo, length).GetPlace();
memcpy(
ByteArrayAddressOfElementAt(result, 0),
cstring,
length);
return result;
}
} // namespace
extern "C" {
KString Kotlin_Byte_toString(KByte value) {
+1
View File
@@ -24,6 +24,7 @@ extern "C" {
extern const TypeInfo* theAnyTypeInfo;
extern const TypeInfo* theCloneableTypeInfo;
extern const TypeInfo* theArrayTypeInfo;
extern const TypeInfo* theByteArrayTypeInfo;
extern const TypeInfo* theCharArrayTypeInfo;
extern const TypeInfo* theShortArrayTypeInfo;