IDE perf tests for Kotlin/Native projects
Issue #MMPP-201
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
build
|
||||
.idea
|
||||
.gradle
|
||||
gradlew*
|
||||
@@ -0,0 +1,15 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "{{kotlin_plugin_version}}"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
ios() {
|
||||
compilations["main"].enableEndorsedLibs = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation={{disable_commonizer}}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-{{gradle_version}}-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,7 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ByteVar
|
||||
import kotlinx.cinterop.allocArray
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toKString
|
||||
import kotlinx.cli.ArgParser
|
||||
import kotlinx.cli.ArgType
|
||||
import kotlinx.cli.required
|
||||
import platform.posix.fclose
|
||||
import platform.posix.fgets
|
||||
import platform.posix.fopen
|
||||
import platform.posix.perror
|
||||
import kotlin.collections.set
|
||||
|
||||
private fun parseLine(line: String, separator: Char) : List<String> {
|
||||
val result = mutableListOf<String>()
|
||||
val builder = StringBuilder()
|
||||
var quotes = 0
|
||||
for (ch in line) {
|
||||
when {
|
||||
ch == '\"' -> {
|
||||
quotes++
|
||||
builder.append(ch)
|
||||
}
|
||||
(ch == '\n') || (ch == '\r') -> {}
|
||||
(ch == separator) && (quotes % 2 == 0) -> {
|
||||
result.add(builder.toString())
|
||||
builder.setLength(0)
|
||||
}
|
||||
else -> builder.append(ch)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val argParser = ArgParser("csvparser")
|
||||
val fileName by argParser.argument(ArgType.String, description = "CSV file")
|
||||
val column by argParser.option(ArgType.Int, description = "Column to parse").required()
|
||||
val count by argParser.option(ArgType.Int, description = "Count of lines to parse").required()
|
||||
argParser.parse(args)
|
||||
|
||||
val file = fopen(fileName, "r")
|
||||
if (file == null) {
|
||||
perror("cannot open input file $fileName")
|
||||
return
|
||||
}
|
||||
|
||||
val keyValue = mutableMapOf<String, Int>()
|
||||
|
||||
try {
|
||||
memScoped {
|
||||
val bufferLength = 64 * 1024
|
||||
val buffer = allocArray<ByteVar>(bufferLength)
|
||||
|
||||
for (i in 1..count) {
|
||||
val nextLine = fgets(buffer, bufferLength, file)?.toKString()
|
||||
if (nextLine == null || nextLine.isEmpty()) break
|
||||
|
||||
val records = parseLine(nextLine, ',')
|
||||
val key = records[column]
|
||||
val current = keyValue[key] ?: 0
|
||||
keyValue[key] = current + 1
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fclose(file)
|
||||
}
|
||||
|
||||
keyValue.forEach {
|
||||
println("${it.key} -> ${it.value}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ByteVar
|
||||
import kotlinx.cinterop.allocArray
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toKString
|
||||
import kotlinx.cli.ArgParser
|
||||
import kotlinx.cli.ArgType
|
||||
import kotlinx.cli.required
|
||||
import platform.posix.fclose
|
||||
import platform.posix.fgets
|
||||
import platform.posix.fopen
|
||||
import platform.posix.perror
|
||||
import kotlin.collections.set
|
||||
|
||||
private fun parseLine(line: String, separator: Char) : List<String> {
|
||||
val result = mutableListOf<String>()
|
||||
val builder = StringBuilder()
|
||||
var quotes = 0
|
||||
for (ch in line) {
|
||||
when {
|
||||
ch == '\"' -> {
|
||||
quotes++
|
||||
builder.append(ch)
|
||||
}
|
||||
(ch == '\n') || (ch == '\r') -> {}
|
||||
(ch == separator) && (quotes % 2 == 0) -> {
|
||||
result.add(builder.toString())
|
||||
builder.setLength(0)
|
||||
}
|
||||
else -> builder.append(ch)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val argParser = ArgParser("csvparser")
|
||||
val fileName by argParser.argument(ArgType.String, description = "CSV file")
|
||||
val column by argParser.option(ArgType.Int, description = "Column to parse").required()
|
||||
val count by argParser.option(ArgType.Int, description = "Count of lines to parse").required()
|
||||
argParser.parse(args)
|
||||
|
||||
val file = fopen(fileName, "r")
|
||||
if (file == null) {
|
||||
perror("cannot open input file $fileName")
|
||||
return
|
||||
}
|
||||
|
||||
val keyValue = mutableMapOf<String, Int>()
|
||||
|
||||
try {
|
||||
memScoped {
|
||||
val bufferLength = 64 * 1024
|
||||
val buffer = allocArray<ByteVar>(bufferLength)
|
||||
|
||||
for (i in 1..count) {
|
||||
val nextLine = fgets(buffer, bufferLength, file)?.toKString()
|
||||
if (nextLine == null || nextLine.isEmpty()) break
|
||||
|
||||
val records = parseLine(nextLine, ',')
|
||||
val key = records[column]
|
||||
val current = keyValue[key] ?: 0
|
||||
keyValue[key] = current + 1
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fclose(file)
|
||||
}
|
||||
|
||||
keyValue.forEach {
|
||||
println("${it.key} -> ${it.value}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ByteVar
|
||||
import kotlinx.cinterop.allocArray
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toKString
|
||||
import kotlinx.cli.ArgParser
|
||||
import kotlinx.cli.ArgType
|
||||
import kotlinx.cli.required
|
||||
import platform.posix.fclose
|
||||
import platform.posix.fgets
|
||||
import platform.posix.fopen
|
||||
import platform.posix.perror
|
||||
import kotlin.collections.set
|
||||
|
||||
private fun parseLine(line: String, separator: Char) : List<String> {
|
||||
val result = mutableListOf<String>()
|
||||
val builder = StringBuilder()
|
||||
var quotes = 0
|
||||
for (ch in line) {
|
||||
when {
|
||||
ch == '\"' -> {
|
||||
quotes++
|
||||
builder.append(ch)
|
||||
}
|
||||
(ch == '\n') || (ch == '\r') -> {}
|
||||
(ch == separator) && (quotes % 2 == 0) -> {
|
||||
result.add(builder.toString())
|
||||
builder.setLength(0)
|
||||
}
|
||||
else -> builder.append(ch)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val argParser = ArgParser("csvparser")
|
||||
val fileName by argParser.argument(ArgType.String, description = "CSV file")
|
||||
val column by argParser.option(ArgType.Int, description = "Column to parse").required()
|
||||
val count by argParser.option(ArgType.Int, description = "Count of lines to parse").required()
|
||||
argParser.parse(args)
|
||||
|
||||
val file = fopen(fileName, "r")
|
||||
if (file == null) {
|
||||
perror("cannot open input file $fileName")
|
||||
return
|
||||
}
|
||||
|
||||
val keyValue = mutableMapOf<String, Int>()
|
||||
|
||||
try {
|
||||
memScoped {
|
||||
val bufferLength = 64 * 1024
|
||||
val buffer = allocArray<ByteVar>(bufferLength)
|
||||
|
||||
for (i in 1..count) {
|
||||
val nextLine = fgets(buffer, bufferLength, file)?.toKString()
|
||||
if (nextLine == null || nextLine.isEmpty()) break
|
||||
|
||||
val records = parseLine(nextLine, ',')
|
||||
val key = records[column]
|
||||
val current = keyValue[key] ?: 0
|
||||
keyValue[key] = current + 1
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fclose(file)
|
||||
}
|
||||
|
||||
keyValue.forEach {
|
||||
println("${it.key} -> ${it.value}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
build
|
||||
.idea
|
||||
.gradle
|
||||
gradlew*
|
||||
@@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "{{kotlin_plugin_version}}"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
ios()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation={{disable_commonizer}}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-{{gradle_version}}-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,7 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello World!")
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello World!")
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello World!")
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
private const val GREETING = "Hello, Kotlin/Native!"
|
||||
|
||||
class HelloTest {
|
||||
@Test
|
||||
fun testHello() {
|
||||
assertTrue("Kotlin/Native" in GREETING)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
private const val GREETING = "Hello, Kotlin/Native!"
|
||||
|
||||
class HelloTest2 {
|
||||
@Test
|
||||
fun testHello() {
|
||||
assertTrue("Kotlin/Native" in GREETING)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
private const val GREETING = "Hello, Kotlin/Native!"
|
||||
|
||||
class HelloTest3 {
|
||||
@Test
|
||||
fun testHello() {
|
||||
assertTrue("Kotlin/Native" in GREETING)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
build
|
||||
.idea
|
||||
.gradle
|
||||
gradlew*
|
||||
@@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "{{kotlin_plugin_version}}"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
ios()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation={{disable_commonizer}}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-{{gradle_version}}-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,7 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ExportObjCClass
|
||||
import kotlinx.cinterop.ObjCAction
|
||||
import kotlinx.cinterop.ObjCOutlet
|
||||
import kotlinx.cinterop.autoreleasepool
|
||||
import kotlinx.cinterop.cstr
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toCValues
|
||||
import kotlinx.cinterop.useContents
|
||||
import platform.CoreGraphics.CGPointMake
|
||||
import platform.CoreGraphics.CGRectMake
|
||||
import platform.Foundation.NSCoder
|
||||
import platform.Foundation.NSSelectorFromString
|
||||
import platform.Foundation.NSStringFromClass
|
||||
import platform.UIKit.NSTextAlignmentCenter
|
||||
import platform.UIKit.UIApplication
|
||||
import platform.UIKit.UIApplicationDelegateProtocol
|
||||
import platform.UIKit.UIApplicationDelegateProtocolMeta
|
||||
import platform.UIKit.UIApplicationMain
|
||||
import platform.UIKit.UIButton
|
||||
import platform.UIKit.UIColor
|
||||
import platform.UIKit.UIControlEventTouchUpInside
|
||||
import platform.UIKit.UIControlStateNormal
|
||||
import platform.UIKit.UIFont
|
||||
import platform.UIKit.UILabel
|
||||
import platform.UIKit.UIResponder
|
||||
import platform.UIKit.UIResponderMeta
|
||||
import platform.UIKit.UIScreen
|
||||
import platform.UIKit.UIView
|
||||
import platform.UIKit.UIViewController
|
||||
import platform.UIKit.UIWindow
|
||||
import platform.UIKit.addSubview
|
||||
import platform.UIKit.backgroundColor
|
||||
import platform.UIKit.font
|
||||
import platform.UIKit.heightAnchor
|
||||
import platform.UIKit.leadingAnchor
|
||||
import platform.UIKit.setFrame
|
||||
import platform.UIKit.topAnchor
|
||||
import platform.UIKit.translatesAutoresizingMaskIntoConstraints
|
||||
import platform.UIKit.widthAnchor
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
memScoped {
|
||||
val argc = args.size + 1
|
||||
val argv = (arrayOf("konan") + args).map { it.cstr.ptr }.toCValues()
|
||||
|
||||
autoreleasepool {
|
||||
UIApplicationMain(argc, argv, null, NSStringFromClass(AppDelegate))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class AppDelegate : UIResponder, UIApplicationDelegateProtocol {
|
||||
companion object : UIResponderMeta(), UIApplicationDelegateProtocolMeta {}
|
||||
|
||||
@OverrideInit
|
||||
constructor() : super()
|
||||
|
||||
private var _window: UIWindow? = null
|
||||
override fun window() = _window
|
||||
override fun setWindow(window: UIWindow?) {
|
||||
_window = window
|
||||
}
|
||||
|
||||
override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean {
|
||||
window = UIWindow(frame = UIScreen.mainScreen.bounds)
|
||||
window!!.rootViewController = ViewController()
|
||||
window!!.makeKeyAndVisible()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@ExportObjCClass
|
||||
private class ViewController : UIViewController {
|
||||
|
||||
@OverrideInit
|
||||
constructor() : super(nibName = null, bundle = null)
|
||||
|
||||
@OverrideInit
|
||||
constructor(coder: NSCoder) : super(coder)
|
||||
|
||||
@ObjCOutlet
|
||||
lateinit var label: UILabel
|
||||
|
||||
@ObjCOutlet
|
||||
lateinit var button: UIButton
|
||||
|
||||
var pressed = 0
|
||||
|
||||
@ObjCAction
|
||||
fun buttonPressed() {
|
||||
label.text = "Hello #${pressed++} from Konan!"
|
||||
println("Button pressed")
|
||||
}
|
||||
|
||||
override fun viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
val (width, height) = UIScreen.mainScreen.bounds.useContents {
|
||||
this.size.width to this.size.height
|
||||
}
|
||||
|
||||
val header = UIView().apply {
|
||||
backgroundColor = UIColor.lightGrayColor
|
||||
view.addSubview(this)
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
leadingAnchor.constraintEqualToAnchor(view.leadingAnchor).active = true
|
||||
topAnchor.constraintEqualToAnchor(view.topAnchor).active = true
|
||||
widthAnchor.constraintEqualToAnchor(view.widthAnchor).active = true
|
||||
heightAnchor.constraintEqualToAnchor(view.heightAnchor).active = true
|
||||
}
|
||||
|
||||
label = UILabel().apply {
|
||||
setFrame(CGRectMake(x = 10.0, y = 10.0, width = width - 100.0, height = 40.0))
|
||||
center = CGPointMake(x = width / 2, y = 40.0 )
|
||||
textAlignment = NSTextAlignmentCenter
|
||||
text = "Press OK"
|
||||
header.addSubview(this)
|
||||
}
|
||||
|
||||
button = UIButton().apply {
|
||||
setFrame(CGRectMake(x = 10.0, y = height - 100.0, width = width - 100.0, height = 40.0))
|
||||
center = CGPointMake(x = width / 2, y = height / 2)
|
||||
backgroundColor = UIColor.blueColor
|
||||
setTitle("OK", forState = UIControlStateNormal)
|
||||
font = UIFont.fontWithName(fontName = font.fontName, size = 28.0)!!
|
||||
layer.borderWidth = 1.0
|
||||
layer.borderColor = UIColor.colorWithRed(0x47 / 255.0, 0x43 / 255.0, 0x70 / 255.0, 1.0).CGColor
|
||||
layer.masksToBounds = true
|
||||
addTarget(target = this@ViewController, action = NSSelectorFromString("buttonPressed"),
|
||||
forControlEvents = UIControlEventTouchUpInside)
|
||||
header.addSubview(this)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ExportObjCClass
|
||||
import kotlinx.cinterop.ObjCAction
|
||||
import kotlinx.cinterop.ObjCOutlet
|
||||
import kotlinx.cinterop.autoreleasepool
|
||||
import kotlinx.cinterop.cstr
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toCValues
|
||||
import kotlinx.cinterop.useContents
|
||||
import platform.CoreGraphics.CGPointMake
|
||||
import platform.CoreGraphics.CGRectMake
|
||||
import platform.Foundation.NSCoder
|
||||
import platform.Foundation.NSSelectorFromString
|
||||
import platform.Foundation.NSStringFromClass
|
||||
import platform.UIKit.NSTextAlignmentCenter
|
||||
import platform.UIKit.UIApplication
|
||||
import platform.UIKit.UIApplicationDelegateProtocol
|
||||
import platform.UIKit.UIApplicationDelegateProtocolMeta
|
||||
import platform.UIKit.UIApplicationMain
|
||||
import platform.UIKit.UIButton
|
||||
import platform.UIKit.UIColor
|
||||
import platform.UIKit.UIControlEventTouchUpInside
|
||||
import platform.UIKit.UIControlStateNormal
|
||||
import platform.UIKit.UIFont
|
||||
import platform.UIKit.UILabel
|
||||
import platform.UIKit.UIResponder
|
||||
import platform.UIKit.UIResponderMeta
|
||||
import platform.UIKit.UIScreen
|
||||
import platform.UIKit.UIView
|
||||
import platform.UIKit.UIViewController
|
||||
import platform.UIKit.UIWindow
|
||||
import platform.UIKit.addSubview
|
||||
import platform.UIKit.backgroundColor
|
||||
import platform.UIKit.font
|
||||
import platform.UIKit.heightAnchor
|
||||
import platform.UIKit.leadingAnchor
|
||||
import platform.UIKit.setFrame
|
||||
import platform.UIKit.topAnchor
|
||||
import platform.UIKit.translatesAutoresizingMaskIntoConstraints
|
||||
import platform.UIKit.widthAnchor
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
memScoped {
|
||||
val argc = args.size + 1
|
||||
val argv = (arrayOf("konan") + args).map { it.cstr.ptr }.toCValues()
|
||||
|
||||
autoreleasepool {
|
||||
UIApplicationMain(argc, argv, null, NSStringFromClass(AppDelegate))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class AppDelegate : UIResponder, UIApplicationDelegateProtocol {
|
||||
companion object : UIResponderMeta(), UIApplicationDelegateProtocolMeta {}
|
||||
|
||||
@OverrideInit
|
||||
constructor() : super()
|
||||
|
||||
private var _window: UIWindow? = null
|
||||
override fun window() = _window
|
||||
override fun setWindow(window: UIWindow?) {
|
||||
_window = window
|
||||
}
|
||||
|
||||
override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean {
|
||||
window = UIWindow(frame = UIScreen.mainScreen.bounds)
|
||||
window!!.rootViewController = ViewController()
|
||||
window!!.makeKeyAndVisible()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@ExportObjCClass
|
||||
private class ViewController : UIViewController {
|
||||
|
||||
@OverrideInit
|
||||
constructor() : super(nibName = null, bundle = null)
|
||||
|
||||
@OverrideInit
|
||||
constructor(coder: NSCoder) : super(coder)
|
||||
|
||||
@ObjCOutlet
|
||||
lateinit var label: UILabel
|
||||
|
||||
@ObjCOutlet
|
||||
lateinit var button: UIButton
|
||||
|
||||
var pressed = 0
|
||||
|
||||
@ObjCAction
|
||||
fun buttonPressed() {
|
||||
label.text = "Hello #${pressed++} from Konan!"
|
||||
println("Button pressed")
|
||||
}
|
||||
|
||||
override fun viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
val (width, height) = UIScreen.mainScreen.bounds.useContents {
|
||||
this.size.width to this.size.height
|
||||
}
|
||||
|
||||
val header = UIView().apply {
|
||||
backgroundColor = UIColor.lightGrayColor
|
||||
view.addSubview(this)
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
leadingAnchor.constraintEqualToAnchor(view.leadingAnchor).active = true
|
||||
topAnchor.constraintEqualToAnchor(view.topAnchor).active = true
|
||||
widthAnchor.constraintEqualToAnchor(view.widthAnchor).active = true
|
||||
heightAnchor.constraintEqualToAnchor(view.heightAnchor).active = true
|
||||
}
|
||||
|
||||
label = UILabel().apply {
|
||||
setFrame(CGRectMake(x = 10.0, y = 10.0, width = width - 100.0, height = 40.0))
|
||||
center = CGPointMake(x = width / 2, y = 40.0 )
|
||||
textAlignment = NSTextAlignmentCenter
|
||||
text = "Press OK"
|
||||
header.addSubview(this)
|
||||
}
|
||||
|
||||
button = UIButton().apply {
|
||||
setFrame(CGRectMake(x = 10.0, y = height - 100.0, width = width - 100.0, height = 40.0))
|
||||
center = CGPointMake(x = width / 2, y = height / 2)
|
||||
backgroundColor = UIColor.blueColor
|
||||
setTitle("OK", forState = UIControlStateNormal)
|
||||
font = UIFont.fontWithName(fontName = font.fontName, size = 28.0)!!
|
||||
layer.borderWidth = 1.0
|
||||
layer.borderColor = UIColor.colorWithRed(0x47 / 255.0, 0x43 / 255.0, 0x70 / 255.0, 1.0).CGColor
|
||||
layer.masksToBounds = true
|
||||
addTarget(target = this@ViewController, action = NSSelectorFromString("buttonPressed"),
|
||||
forControlEvents = UIControlEventTouchUpInside)
|
||||
header.addSubview(this)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ExportObjCClass
|
||||
import kotlinx.cinterop.ObjCAction
|
||||
import kotlinx.cinterop.ObjCOutlet
|
||||
import kotlinx.cinterop.autoreleasepool
|
||||
import kotlinx.cinterop.cstr
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toCValues
|
||||
import kotlinx.cinterop.useContents
|
||||
import platform.CoreGraphics.CGPointMake
|
||||
import platform.CoreGraphics.CGRectMake
|
||||
import platform.Foundation.NSCoder
|
||||
import platform.Foundation.NSSelectorFromString
|
||||
import platform.Foundation.NSStringFromClass
|
||||
import platform.UIKit.NSTextAlignmentCenter
|
||||
import platform.UIKit.UIApplication
|
||||
import platform.UIKit.UIApplicationDelegateProtocol
|
||||
import platform.UIKit.UIApplicationDelegateProtocolMeta
|
||||
import platform.UIKit.UIApplicationMain
|
||||
import platform.UIKit.UIButton
|
||||
import platform.UIKit.UIColor
|
||||
import platform.UIKit.UIControlEventTouchUpInside
|
||||
import platform.UIKit.UIControlStateNormal
|
||||
import platform.UIKit.UIFont
|
||||
import platform.UIKit.UILabel
|
||||
import platform.UIKit.UIResponder
|
||||
import platform.UIKit.UIResponderMeta
|
||||
import platform.UIKit.UIScreen
|
||||
import platform.UIKit.UIView
|
||||
import platform.UIKit.UIViewController
|
||||
import platform.UIKit.UIWindow
|
||||
import platform.UIKit.addSubview
|
||||
import platform.UIKit.backgroundColor
|
||||
import platform.UIKit.font
|
||||
import platform.UIKit.heightAnchor
|
||||
import platform.UIKit.leadingAnchor
|
||||
import platform.UIKit.setFrame
|
||||
import platform.UIKit.topAnchor
|
||||
import platform.UIKit.translatesAutoresizingMaskIntoConstraints
|
||||
import platform.UIKit.widthAnchor
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
memScoped {
|
||||
val argc = args.size + 1
|
||||
val argv = (arrayOf("konan") + args).map { it.cstr.ptr }.toCValues()
|
||||
|
||||
autoreleasepool {
|
||||
UIApplicationMain(argc, argv, null, NSStringFromClass(AppDelegate))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class AppDelegate : UIResponder, UIApplicationDelegateProtocol {
|
||||
companion object : UIResponderMeta(), UIApplicationDelegateProtocolMeta {}
|
||||
|
||||
@OverrideInit
|
||||
constructor() : super()
|
||||
|
||||
private var _window: UIWindow? = null
|
||||
override fun window() = _window
|
||||
override fun setWindow(window: UIWindow?) {
|
||||
_window = window
|
||||
}
|
||||
|
||||
override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean {
|
||||
window = UIWindow(frame = UIScreen.mainScreen.bounds)
|
||||
window!!.rootViewController = ViewController()
|
||||
window!!.makeKeyAndVisible()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@ExportObjCClass
|
||||
private class ViewController : UIViewController {
|
||||
|
||||
@OverrideInit
|
||||
constructor() : super(nibName = null, bundle = null)
|
||||
|
||||
@OverrideInit
|
||||
constructor(coder: NSCoder) : super(coder)
|
||||
|
||||
@ObjCOutlet
|
||||
lateinit var label: UILabel
|
||||
|
||||
@ObjCOutlet
|
||||
lateinit var button: UIButton
|
||||
|
||||
var pressed = 0
|
||||
|
||||
@ObjCAction
|
||||
fun buttonPressed() {
|
||||
label.text = "Hello #${pressed++} from Konan!"
|
||||
println("Button pressed")
|
||||
}
|
||||
|
||||
override fun viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
val (width, height) = UIScreen.mainScreen.bounds.useContents {
|
||||
this.size.width to this.size.height
|
||||
}
|
||||
|
||||
val header = UIView().apply {
|
||||
backgroundColor = UIColor.lightGrayColor
|
||||
view.addSubview(this)
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
leadingAnchor.constraintEqualToAnchor(view.leadingAnchor).active = true
|
||||
topAnchor.constraintEqualToAnchor(view.topAnchor).active = true
|
||||
widthAnchor.constraintEqualToAnchor(view.widthAnchor).active = true
|
||||
heightAnchor.constraintEqualToAnchor(view.heightAnchor).active = true
|
||||
}
|
||||
|
||||
label = UILabel().apply {
|
||||
setFrame(CGRectMake(x = 10.0, y = 10.0, width = width - 100.0, height = 40.0))
|
||||
center = CGPointMake(x = width / 2, y = 40.0 )
|
||||
textAlignment = NSTextAlignmentCenter
|
||||
text = "Press OK"
|
||||
header.addSubview(this)
|
||||
}
|
||||
|
||||
button = UIButton().apply {
|
||||
setFrame(CGRectMake(x = 10.0, y = height - 100.0, width = width - 100.0, height = 40.0))
|
||||
center = CGPointMake(x = width / 2, y = height / 2)
|
||||
backgroundColor = UIColor.blueColor
|
||||
setTitle("OK", forState = UIControlStateNormal)
|
||||
font = UIFont.fontWithName(fontName = font.fontName, size = 28.0)!!
|
||||
layer.borderWidth = 1.0
|
||||
layer.borderColor = UIColor.colorWithRed(0x47 / 255.0, 0x43 / 255.0, 0x70 / 255.0, 1.0).CGColor
|
||||
layer.masksToBounds = true
|
||||
addTarget(target = this@ViewController, action = NSSelectorFromString("buttonPressed"),
|
||||
forControlEvents = UIControlEventTouchUpInside)
|
||||
header.addSubview(this)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user