Move everything under kotlin-native folder

I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
This commit is contained in:
Stanislav Erokhin
2020-10-27 21:00:28 +03:00
parent 91e4162dad
commit f624800b84
2830 changed files with 0 additions and 0 deletions
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
</plist>
@@ -0,0 +1,81 @@
apply plugin: 'org.jetbrains.kotlin.multiplatform'
kotlin {
targets {
fromPreset(determineIosPreset(), 'ios') {
binaries {
framework()
}
}
fromPreset(presets.jvm, 'jvm')
}
sourceSets {
commonMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
}
}
jvmMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
}
}
}
}
// Workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations {
compileClasspath
}
// If custom preset specified in 'calculator.preset.name' property, then use it for building.
// Otherwise build for iPhone simulator (by default).
def determineIosPreset() {
String presetName = project.hasProperty('calculator.preset.name') ? project.properties['calculator.preset.name'] : 'iosX64'
def preset = project.kotlin.presets[presetName]
println("$project has been configured for $presetName platform.")
preset
}
// Special Gradle task that is called from Xcode.
// Two Gradle properties must be specified for this task:
// - calculator.configuration.name=[Release|Debug]
// - calculator.framework.location
task buildFrameworkForXcode {
if (isCalledFromXcode()) {
dependsOn kotlin.targets.ios.binaries.getFramework(getBuildTypeForXcode()).linkTask
}
doLast {
if (!isCalledFromXcode()) {
throw new Exception("Please run 'buildFrameworkForXcode' task with all necessary properties!")
}
def frameworkDir = kotlin.targets.ios.binaries.getFramework(getBuildTypeForXcode()).outputFile
println("from: ${frameworkDir.parentFile}")
println("into: ${getXcodeConfigurationBuildDir()}")
copy {
from frameworkDir.parentFile
into getXcodeConfigurationBuildDir()
include "${frameworkDir.name}/**"
include "${frameworkDir.name}.dSYM/**"
}
}
}
private boolean isCalledFromXcode() {
project.hasProperty('calculator.configuration.name') && project.hasProperty('calculator.framework.location')
}
private String getBuildTypeForXcode() {
project.properties['calculator.configuration.name'] as String
}
private String getXcodeConfigurationBuildDir() {
project.properties['calculator.framework.location'] as String
}
@@ -0,0 +1 @@
kotlin.code.style=official
@@ -0,0 +1,284 @@
/*
* 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.
*/
package sample.calculator.arithmeticparser
fun parseAndCompute(expression: String): PartialParser.Result<Double, String> =
PartialParser(Calculator(), PartialRenderer()).parseWithPartial(expression)
class Calculator : ExpressionComposer<Double> {
override fun number(value: Double) = value
override fun plus(left: Double, right: Double) = left + right
override fun minus(left: Double, right: Double) = left - right
override fun mult(left: Double, right: Double) = left * right
override fun div(left: Double, right: Double) = left / right
}
class PartialRenderer : PartialExpressionComposer<Double, String> {
override fun missing() = "..."
override fun ending(expression: Double) = "$expression ..."
override fun plus(left: Double, partialRight: String) = "$left + $partialRight"
override fun minus(left: Double, partialRight: String) = "$left - $partialRight"
override fun mult(left: Double, partialRight: String) = "$left * $partialRight"
override fun div(left: Double, partialRight: String) = "$left / $partialRight"
override fun leftParenthesized(partialExpression: String) = "($partialExpression"
}
interface ExpressionComposer<E : Any> {
fun number(value: Double): E
fun plus(left: E, right: E): E
fun minus(left: E, right: E): E
fun mult(left: E, right: E): E
fun div(left: E, right: E): E
}
open class Parser<E : Any>(private val composer: ExpressionComposer<E>) {
fun parse(expression: String): E? {
val tokenizer = Tokenizer(expression)
val prefix = parseAsPrefix(tokenizer)
if (prefix is EndedWithExpression && !tokenizer.hasNext()) {
val reduced = prefix.reduced()
if (reduced.prefix is Empty) {
return reduced.expression
}
}
return null
}
internal fun parseAsPrefix(tokenizer: Tokenizer): ExpressionPrefix<E> =
generateSequence<ExpressionPrefix<E>>(Empty) {
it.tryExtend(tokenizer)
}.last()
private fun ExpressionPrefix<E>.tryExtend(tokenizer: Tokenizer): ExpressionPrefix<E>? = when (this) {
is ContinuableWithExpression -> {
val number = tokenizer.tryReadNumber()
when {
number != null -> this.with(composer.number(number))
tokenizer.tryReadLeftParenthesis() -> this.withLeftParenthesis()
else -> null
}
}
is EndedWithExpression -> {
val operator = tokenizer.tryReadBinaryOperator()
if (operator != null) {
this.extendedWithOperator(operator)
} else {
val reduced = this.reduced()
if (reduced.prefix is EndedWithLeftParenthesis && tokenizer.tryReadRightParenthesis()) {
// Drop parens:
reduced.prefix.prefix.with(reduced.expression)
} else {
null
}
}
}
}
private tailrec fun EndedWithExpression<E>.extendedWithOperator(operator: BinaryOperator): EndedWithOperator<E> =
if (this.prefix is EndedWithOperator && this.prefix.operator.precedence >= operator.precedence) {
// Apply the operator
this.prefix
.withOperatorApplied(this.expression)
.extendedWithOperator(operator)
} else {
EndedWithOperator(this.prefix, this.expression, operator)
}
internal tailrec fun EndedWithExpression<E>.reduced(): EndedWithExpression<E> = when (this.prefix) {
Empty, is EndedWithLeftParenthesis -> this
is EndedWithOperator ->
this.prefix
.withOperatorApplied(this.expression)
.reduced()
}
private fun EndedWithOperator<E>.withOperatorApplied(rightOperand: E) =
this.prefix.with(composer.compose(this.operator, this.leftOperand, rightOperand))
private fun ExpressionComposer<E>.compose(
binaryOperator: BinaryOperator, left: E, right: E
): E = when (binaryOperator) {
BinaryOperator.PLUS -> plus(left, right)
BinaryOperator.MINUS -> minus(left, right)
BinaryOperator.MULT -> mult(left, right)
BinaryOperator.DIV -> div(left, right)
}
}
interface PartialExpressionComposer<E : Any, PE : Any> {
fun missing(): PE
fun ending(expression: E): PE
fun plus(left: E, partialRight: PE): PE
fun minus(left: E, partialRight: PE): PE
fun mult(left: E, partialRight: PE): PE
fun div(left: E, partialRight: PE): PE
fun leftParenthesized(partialExpression: PE): PE
}
class PartialParser<E : Any, PE : Any>(
composer: ExpressionComposer<E>,
private val partialComposer: PartialExpressionComposer<E, PE>
) : Parser<E>(composer) {
data class Result<E : Any, PE : Any>(val expression: E?, val partialExpression: PE, val remainder: String?)
fun parseWithPartial(expression: String): Result<E, PE> {
val tokenizer = Tokenizer(expression)
val prefix = parseAsPrefix(tokenizer)
val remainder = tokenizer.getRemainder()
return Result(
if (remainder != null) null else tryReduce(prefix),
prefix.toPartialExpression(),
remainder
)
}
private fun tryReduce(prefix: ExpressionPrefix<E>): E? {
if (prefix is EndedWithExpression) {
val reduced = prefix.reduced()
if (reduced.prefix is Empty) {
return reduced.expression
}
}
return null
}
private fun ExpressionPrefix<E>.toPartialExpression(): PE = when (this) {
is EndedWithExpression -> this.prefix.toPartialExpressionWith(
ending = partialComposer.ending(this.expression)
)
is ContinuableWithExpression -> this.toPartialExpressionWith(ending = partialComposer.missing())
}
private tailrec fun ContinuableWithExpression<E>.toPartialExpressionWith(
ending: PE
): PE = when (this) {
Empty -> ending
is EndedWithLeftParenthesis -> this.prefix.toPartialExpressionWith(
ending = partialComposer.leftParenthesized(ending)
)
is EndedWithOperator -> this.prefix.toPartialExpressionWith(
ending = partialComposer.compose(this.operator, this.leftOperand, ending)
)
}
private fun PartialExpressionComposer<E, PE>.compose(
binaryOperator: BinaryOperator,
left: E,
right: PE
): PE = when (binaryOperator) {
BinaryOperator.PLUS -> plus(left, right)
BinaryOperator.MINUS -> minus(left, right)
BinaryOperator.MULT -> mult(left, right)
BinaryOperator.DIV -> div(left, right)
}
}
/**
* Immutable prefix of expression partially parsed to combination of abstractly represented expressions.
* The prefix representation can be thought as "almost AST", i.e. AST with unfinished rightmost leaf
* (referenced by this object), and its nodes contain links to parent and (if needed) left child.
*
* @param E abstract representation of expression, e.g. its value, AST etc.
*/
internal sealed class ExpressionPrefix<out E>
internal data class EndedWithExpression<E>(
val prefix: ContinuableWithExpression<E>,
val expression: E
) : ExpressionPrefix<E>()
internal sealed class ContinuableWithExpression<out E> : ExpressionPrefix<E>()
private fun <E> ContinuableWithExpression<E>.with(expression: E) =
EndedWithExpression(this, expression)
private object Empty : ContinuableWithExpression<Nothing>()
private data class EndedWithLeftParenthesis<out E>(
val prefix: ContinuableWithExpression<E>
) : ContinuableWithExpression<E>()
private fun <E> ContinuableWithExpression<E>.withLeftParenthesis() =
EndedWithLeftParenthesis(this)
private data class EndedWithOperator<out E>(
val prefix: ContinuableWithExpression<E>,
val leftOperand: E,
val operator: BinaryOperator
) : ContinuableWithExpression<E>()
internal enum class BinaryOperator(val sign: Char, val precedence: Int) {
PLUS('+', 2),
MINUS('-', 2),
MULT('*', 3),
DIV('/', 3)
}
internal class Tokenizer(private val expression: String) {
private var index = 0
init {
skipSpaces()
}
fun hasNext(): Boolean = (index < expression.length)
fun getRemainder(): String? = if (this.hasNext()) {
expression.substring(index)
} else {
null
}
fun tryReadNumber(): Double? {
var endIndex = index
while (expression.getOrNull(endIndex)?.isNumberChar() == true) {
++endIndex
}
return expression.substring(index, endIndex).toDoubleOrNull()?.also {
index = endIndex
skipSpaces()
}
}
private fun Char.isNumberChar(): Boolean = this in '0'..'9' || this == '.'
fun tryReadBinaryOperator(): BinaryOperator? = BinaryOperator.values().firstOrNull { tryRead(it.sign) }
fun tryReadLeftParenthesis(): Boolean = tryRead('(')
fun tryReadRightParenthesis(): Boolean = tryRead(')')
private fun tryRead(char: Char): Boolean = if (hasNext() && expression[index] == char) {
++index
skipSpaces()
true
} else {
false
}
private fun skipSpaces() {
while (expression.getOrNull(index)?.isWhitespace() == true) {
++index
}
}
}