diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/builtins/IrBuiltInsMapGenerated.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/builtins/IrBuiltInsMapGenerated.kt index b8b703cfc2b..a62933f579c 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/builtins/IrBuiltInsMapGenerated.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/builtins/IrBuiltInsMapGenerated.kt @@ -16,13 +16,21 @@ package org.jetbrains.kotlin.backend.common.interpreter.builtins -import org.jetbrains.kotlin.backend.common.interpreter.stack.State +import org.jetbrains.kotlin.backend.common.interpreter.stack.* /** This file is generated by org.jetbrains.kotlin.backend.common.interpreter.builtins.GenerateBuiltInsMap.generateMap(). DO NOT MODIFY MANUALLY */ val unaryFunctions = mapOf>( unaryOperation("not", "Boolean") { a -> a.not() }, unaryOperation("toString", "Boolean") { a -> a.toString() }, + unaryOperation("toByte", "Char") { a -> a.toByte() }, + unaryOperation("toChar", "Char") { a -> a.toChar() }, + unaryOperation("toDouble", "Char") { a -> a.toDouble() }, + unaryOperation("toFloat", "Char") { a -> a.toFloat() }, + unaryOperation("toInt", "Char") { a -> a.toInt() }, + unaryOperation("toLong", "Char") { a -> a.toLong() }, + unaryOperation("toShort", "Char") { a -> a.toShort() }, + unaryOperation("toString", "Char") { a -> a.toString() }, unaryOperation("toByte", "Byte") { a -> a.toByte() }, unaryOperation("toChar", "Byte") { a -> a.toChar() }, unaryOperation("toDouble", "Byte") { a -> a.toDouble() }, @@ -33,34 +41,16 @@ val unaryFunctions = mapOf>( unaryOperation("toString", "Byte") { a -> a.toString() }, unaryOperation("unaryMinus", "Byte") { a -> a.unaryMinus() }, unaryOperation("unaryPlus", "Byte") { a -> a.unaryPlus() }, - unaryOperation("toByte", "Char") { a -> a.toByte() }, - unaryOperation("toChar", "Char") { a -> a.toChar() }, - unaryOperation("toDouble", "Char") { a -> a.toDouble() }, - unaryOperation("toFloat", "Char") { a -> a.toFloat() }, - unaryOperation("toInt", "Char") { a -> a.toInt() }, - unaryOperation("toLong", "Char") { a -> a.toLong() }, - unaryOperation("toShort", "Char") { a -> a.toShort() }, - unaryOperation("toString", "Char") { a -> a.toString() }, - unaryOperation("toByte", "Double") { a -> a.toByte() }, - unaryOperation("toChar", "Double") { a -> a.toChar() }, - unaryOperation("toDouble", "Double") { a -> a.toDouble() }, - unaryOperation("toFloat", "Double") { a -> a.toFloat() }, - unaryOperation("toInt", "Double") { a -> a.toInt() }, - unaryOperation("toLong", "Double") { a -> a.toLong() }, - unaryOperation("toShort", "Double") { a -> a.toShort() }, - unaryOperation("toString", "Double") { a -> a.toString() }, - unaryOperation("unaryMinus", "Double") { a -> a.unaryMinus() }, - unaryOperation("unaryPlus", "Double") { a -> a.unaryPlus() }, - unaryOperation("toByte", "Float") { a -> a.toByte() }, - unaryOperation("toChar", "Float") { a -> a.toChar() }, - unaryOperation("toDouble", "Float") { a -> a.toDouble() }, - unaryOperation("toFloat", "Float") { a -> a.toFloat() }, - unaryOperation("toInt", "Float") { a -> a.toInt() }, - unaryOperation("toLong", "Float") { a -> a.toLong() }, - unaryOperation("toShort", "Float") { a -> a.toShort() }, - unaryOperation("toString", "Float") { a -> a.toString() }, - unaryOperation("unaryMinus", "Float") { a -> a.unaryMinus() }, - unaryOperation("unaryPlus", "Float") { a -> a.unaryPlus() }, + unaryOperation("toByte", "Short") { a -> a.toByte() }, + unaryOperation("toChar", "Short") { a -> a.toChar() }, + unaryOperation("toDouble", "Short") { a -> a.toDouble() }, + unaryOperation("toFloat", "Short") { a -> a.toFloat() }, + unaryOperation("toInt", "Short") { a -> a.toInt() }, + unaryOperation("toLong", "Short") { a -> a.toLong() }, + unaryOperation("toShort", "Short") { a -> a.toShort() }, + unaryOperation("toString", "Short") { a -> a.toString() }, + unaryOperation("unaryMinus", "Short") { a -> a.unaryMinus() }, + unaryOperation("unaryPlus", "Short") { a -> a.unaryPlus() }, unaryOperation("inv", "Int") { a -> a.inv() }, unaryOperation("toByte", "Int") { a -> a.toByte() }, unaryOperation("toChar", "Int") { a -> a.toChar() }, @@ -72,6 +62,16 @@ val unaryFunctions = mapOf>( unaryOperation("toString", "Int") { a -> a.toString() }, unaryOperation("unaryMinus", "Int") { a -> a.unaryMinus() }, unaryOperation("unaryPlus", "Int") { a -> a.unaryPlus() }, + unaryOperation("toByte", "Float") { a -> a.toByte() }, + unaryOperation("toChar", "Float") { a -> a.toChar() }, + unaryOperation("toDouble", "Float") { a -> a.toDouble() }, + unaryOperation("toFloat", "Float") { a -> a.toFloat() }, + unaryOperation("toInt", "Float") { a -> a.toInt() }, + unaryOperation("toLong", "Float") { a -> a.toLong() }, + unaryOperation("toShort", "Float") { a -> a.toShort() }, + unaryOperation("toString", "Float") { a -> a.toString() }, + unaryOperation("unaryMinus", "Float") { a -> a.unaryMinus() }, + unaryOperation("unaryPlus", "Float") { a -> a.unaryPlus() }, unaryOperation("inv", "Long") { a -> a.inv() }, unaryOperation("toByte", "Long") { a -> a.toByte() }, unaryOperation("toChar", "Long") { a -> a.toChar() }, @@ -83,20 +83,18 @@ val unaryFunctions = mapOf>( unaryOperation("toString", "Long") { a -> a.toString() }, unaryOperation("unaryMinus", "Long") { a -> a.unaryMinus() }, unaryOperation("unaryPlus", "Long") { a -> a.unaryPlus() }, - unaryOperation("toByte", "Short") { a -> a.toByte() }, - unaryOperation("toChar", "Short") { a -> a.toChar() }, - unaryOperation("toDouble", "Short") { a -> a.toDouble() }, - unaryOperation("toFloat", "Short") { a -> a.toFloat() }, - unaryOperation("toInt", "Short") { a -> a.toInt() }, - unaryOperation("toLong", "Short") { a -> a.toLong() }, - unaryOperation("toShort", "Short") { a -> a.toShort() }, - unaryOperation("toString", "Short") { a -> a.toString() }, - unaryOperation("unaryMinus", "Short") { a -> a.unaryMinus() }, - unaryOperation("unaryPlus", "Short") { a -> a.unaryPlus() }, + unaryOperation("toByte", "Double") { a -> a.toByte() }, + unaryOperation("toChar", "Double") { a -> a.toChar() }, + unaryOperation("toDouble", "Double") { a -> a.toDouble() }, + unaryOperation("toFloat", "Double") { a -> a.toFloat() }, + unaryOperation("toInt", "Double") { a -> a.toInt() }, + unaryOperation("toLong", "Double") { a -> a.toLong() }, + unaryOperation("toShort", "Double") { a -> a.toShort() }, + unaryOperation("toString", "Double") { a -> a.toString() }, + unaryOperation("unaryMinus", "Double") { a -> a.unaryMinus() }, + unaryOperation("unaryPlus", "Double") { a -> a.unaryPlus() }, unaryOperation("length", "String") { a -> a.length }, unaryOperation("toString", "String") { a -> a.toString() }, - unaryOperation>("size", "Array") { a -> a.size }, - unaryOperation>("iterator", "Array") { a -> a.iterator() }, unaryOperation("size", "BooleanArray") { a -> a.size }, unaryOperation("iterator", "BooleanArray") { a -> a.iterator() }, unaryOperation("size", "CharArray") { a -> a.size }, @@ -113,11 +111,13 @@ val unaryFunctions = mapOf>( unaryOperation("iterator", "LongArray") { a -> a.iterator() }, unaryOperation("size", "DoubleArray") { a -> a.size }, unaryOperation("iterator", "DoubleArray") { a -> a.iterator() }, + unaryOperation>("size", "Array") { a -> a.size }, + unaryOperation>("iterator", "Array") { a -> a.iterator() }, unaryOperation("hashCode", "Any") { a -> a.hashCode() }, - unaryOperation("toString", "Any") { a -> - if (a is State) "${a.irClass.name}@" + System.identityHashCode(a).toString(16).padStart(8) else a.toString() - }, - unaryOperation("CHECK_NOT_NULL", "T0?") { a -> a!! } + unaryOperation("toString", "Any") { a -> a.defaultToString() }, + unaryOperation("CHECK_NOT_NULL", "T0?") { a -> a!! }, + unaryOperation("", "Throwable") { a -> a.getMessage() }, + unaryOperation("", "Throwable") { a -> a.getCause() } ) val binaryFunctions = mapOf>( @@ -126,6 +126,11 @@ val binaryFunctions = mapOf>( binaryOperation("equals", "Boolean", "Any?") { a, b -> a.equals(b) }, binaryOperation("or", "Boolean", "Boolean") { a, b -> a.or(b) }, binaryOperation("xor", "Boolean", "Boolean") { a, b -> a.xor(b) }, + binaryOperation("compareTo", "Char", "Char") { a, b -> a.compareTo(b) }, + binaryOperation("equals", "Char", "Any?") { a, b -> a.equals(b) }, + binaryOperation("minus", "Char", "Char") { a, b -> a.minus(b) }, + binaryOperation("minus", "Char", "Int") { a, b -> a.minus(b) }, + binaryOperation("plus", "Char", "Int") { a, b -> a.plus(b) }, binaryOperation("compareTo", "Byte", "Byte") { a, b -> a.compareTo(b) }, binaryOperation("compareTo", "Byte", "Double") { a, b -> a.compareTo(b) }, binaryOperation("compareTo", "Byte", "Float") { a, b -> a.compareTo(b) }, @@ -167,85 +172,47 @@ val binaryFunctions = mapOf>( binaryOperation("times", "Byte", "Int") { a, b -> a.times(b) }, binaryOperation("times", "Byte", "Long") { a, b -> a.times(b) }, binaryOperation("times", "Byte", "Short") { a, b -> a.times(b) }, - binaryOperation("compareTo", "Char", "Char") { a, b -> a.compareTo(b) }, - binaryOperation("equals", "Char", "Any?") { a, b -> a.equals(b) }, - binaryOperation("minus", "Char", "Char") { a, b -> a.minus(b) }, - binaryOperation("minus", "Char", "Int") { a, b -> a.minus(b) }, - binaryOperation("plus", "Char", "Int") { a, b -> a.plus(b) }, - binaryOperation("compareTo", "Double", "Byte") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Double", "Double") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Double", "Float") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Double", "Int") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Double", "Long") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Double", "Short") { a, b -> a.compareTo(b) }, - binaryOperation("div", "Double", "Byte") { a, b -> a.div(b) }, - binaryOperation("div", "Double", "Double") { a, b -> a.div(b) }, - binaryOperation("div", "Double", "Float") { a, b -> a.div(b) }, - binaryOperation("div", "Double", "Int") { a, b -> a.div(b) }, - binaryOperation("div", "Double", "Long") { a, b -> a.div(b) }, - binaryOperation("div", "Double", "Short") { a, b -> a.div(b) }, - binaryOperation("equals", "Double", "Any?") { a, b -> a.equals(b) }, - binaryOperation("minus", "Double", "Byte") { a, b -> a.minus(b) }, - binaryOperation("minus", "Double", "Double") { a, b -> a.minus(b) }, - binaryOperation("minus", "Double", "Float") { a, b -> a.minus(b) }, - binaryOperation("minus", "Double", "Int") { a, b -> a.minus(b) }, - binaryOperation("minus", "Double", "Long") { a, b -> a.minus(b) }, - binaryOperation("minus", "Double", "Short") { a, b -> a.minus(b) }, - binaryOperation("plus", "Double", "Byte") { a, b -> a.plus(b) }, - binaryOperation("plus", "Double", "Double") { a, b -> a.plus(b) }, - binaryOperation("plus", "Double", "Float") { a, b -> a.plus(b) }, - binaryOperation("plus", "Double", "Int") { a, b -> a.plus(b) }, - binaryOperation("plus", "Double", "Long") { a, b -> a.plus(b) }, - binaryOperation("plus", "Double", "Short") { a, b -> a.plus(b) }, - binaryOperation("rem", "Double", "Byte") { a, b -> a.rem(b) }, - binaryOperation("rem", "Double", "Double") { a, b -> a.rem(b) }, - binaryOperation("rem", "Double", "Float") { a, b -> a.rem(b) }, - binaryOperation("rem", "Double", "Int") { a, b -> a.rem(b) }, - binaryOperation("rem", "Double", "Long") { a, b -> a.rem(b) }, - binaryOperation("rem", "Double", "Short") { a, b -> a.rem(b) }, - binaryOperation("times", "Double", "Byte") { a, b -> a.times(b) }, - binaryOperation("times", "Double", "Double") { a, b -> a.times(b) }, - binaryOperation("times", "Double", "Float") { a, b -> a.times(b) }, - binaryOperation("times", "Double", "Int") { a, b -> a.times(b) }, - binaryOperation("times", "Double", "Long") { a, b -> a.times(b) }, - binaryOperation("times", "Double", "Short") { a, b -> a.times(b) }, - binaryOperation("compareTo", "Float", "Byte") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Float", "Double") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Float", "Float") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Float", "Int") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Float", "Long") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Float", "Short") { a, b -> a.compareTo(b) }, - binaryOperation("div", "Float", "Byte") { a, b -> a.div(b) }, - binaryOperation("div", "Float", "Double") { a, b -> a.div(b) }, - binaryOperation("div", "Float", "Float") { a, b -> a.div(b) }, - binaryOperation("div", "Float", "Int") { a, b -> a.div(b) }, - binaryOperation("div", "Float", "Long") { a, b -> a.div(b) }, - binaryOperation("div", "Float", "Short") { a, b -> a.div(b) }, - binaryOperation("equals", "Float", "Any?") { a, b -> a.equals(b) }, - binaryOperation("minus", "Float", "Byte") { a, b -> a.minus(b) }, - binaryOperation("minus", "Float", "Double") { a, b -> a.minus(b) }, - binaryOperation("minus", "Float", "Float") { a, b -> a.minus(b) }, - binaryOperation("minus", "Float", "Int") { a, b -> a.minus(b) }, - binaryOperation("minus", "Float", "Long") { a, b -> a.minus(b) }, - binaryOperation("minus", "Float", "Short") { a, b -> a.minus(b) }, - binaryOperation("plus", "Float", "Byte") { a, b -> a.plus(b) }, - binaryOperation("plus", "Float", "Double") { a, b -> a.plus(b) }, - binaryOperation("plus", "Float", "Float") { a, b -> a.plus(b) }, - binaryOperation("plus", "Float", "Int") { a, b -> a.plus(b) }, - binaryOperation("plus", "Float", "Long") { a, b -> a.plus(b) }, - binaryOperation("plus", "Float", "Short") { a, b -> a.plus(b) }, - binaryOperation("rem", "Float", "Byte") { a, b -> a.rem(b) }, - binaryOperation("rem", "Float", "Double") { a, b -> a.rem(b) }, - binaryOperation("rem", "Float", "Float") { a, b -> a.rem(b) }, - binaryOperation("rem", "Float", "Int") { a, b -> a.rem(b) }, - binaryOperation("rem", "Float", "Long") { a, b -> a.rem(b) }, - binaryOperation("rem", "Float", "Short") { a, b -> a.rem(b) }, - binaryOperation("times", "Float", "Byte") { a, b -> a.times(b) }, - binaryOperation("times", "Float", "Double") { a, b -> a.times(b) }, - binaryOperation("times", "Float", "Float") { a, b -> a.times(b) }, - binaryOperation("times", "Float", "Int") { a, b -> a.times(b) }, - binaryOperation("times", "Float", "Long") { a, b -> a.times(b) }, - binaryOperation("times", "Float", "Short") { a, b -> a.times(b) }, + binaryOperation("compareTo", "Short", "Byte") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Short", "Double") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Short", "Float") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Short", "Int") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Short", "Long") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Short", "Short") { a, b -> a.compareTo(b) }, + binaryOperation("div", "Short", "Byte") { a, b -> a.div(b) }, + binaryOperation("div", "Short", "Double") { a, b -> a.div(b) }, + binaryOperation("div", "Short", "Float") { a, b -> a.div(b) }, + binaryOperation("div", "Short", "Int") { a, b -> a.div(b) }, + binaryOperation("div", "Short", "Long") { a, b -> a.div(b) }, + binaryOperation("div", "Short", "Short") { a, b -> a.div(b) }, + binaryOperation("equals", "Short", "Any?") { a, b -> a.equals(b) }, + binaryOperation("minus", "Short", "Byte") { a, b -> a.minus(b) }, + binaryOperation("minus", "Short", "Double") { a, b -> a.minus(b) }, + binaryOperation("minus", "Short", "Float") { a, b -> a.minus(b) }, + binaryOperation("minus", "Short", "Int") { a, b -> a.minus(b) }, + binaryOperation("minus", "Short", "Long") { a, b -> a.minus(b) }, + binaryOperation("minus", "Short", "Short") { a, b -> a.minus(b) }, + binaryOperation("plus", "Short", "Byte") { a, b -> a.plus(b) }, + binaryOperation("plus", "Short", "Double") { a, b -> a.plus(b) }, + binaryOperation("plus", "Short", "Float") { a, b -> a.plus(b) }, + binaryOperation("plus", "Short", "Int") { a, b -> a.plus(b) }, + binaryOperation("plus", "Short", "Long") { a, b -> a.plus(b) }, + binaryOperation("plus", "Short", "Short") { a, b -> a.plus(b) }, + binaryOperation("rangeTo", "Short", "Byte") { a, b -> a.rangeTo(b) }, + binaryOperation("rangeTo", "Short", "Int") { a, b -> a.rangeTo(b) }, + binaryOperation("rangeTo", "Short", "Long") { a, b -> a.rangeTo(b) }, + binaryOperation("rangeTo", "Short", "Short") { a, b -> a.rangeTo(b) }, + binaryOperation("rem", "Short", "Byte") { a, b -> a.rem(b) }, + binaryOperation("rem", "Short", "Double") { a, b -> a.rem(b) }, + binaryOperation("rem", "Short", "Float") { a, b -> a.rem(b) }, + binaryOperation("rem", "Short", "Int") { a, b -> a.rem(b) }, + binaryOperation("rem", "Short", "Long") { a, b -> a.rem(b) }, + binaryOperation("rem", "Short", "Short") { a, b -> a.rem(b) }, + binaryOperation("times", "Short", "Byte") { a, b -> a.times(b) }, + binaryOperation("times", "Short", "Double") { a, b -> a.times(b) }, + binaryOperation("times", "Short", "Float") { a, b -> a.times(b) }, + binaryOperation("times", "Short", "Int") { a, b -> a.times(b) }, + binaryOperation("times", "Short", "Long") { a, b -> a.times(b) }, + binaryOperation("times", "Short", "Short") { a, b -> a.times(b) }, binaryOperation("and", "Int", "Int") { a, b -> a.and(b) }, binaryOperation("compareTo", "Int", "Byte") { a, b -> a.compareTo(b) }, binaryOperation("compareTo", "Int", "Double") { a, b -> a.compareTo(b) }, @@ -293,6 +260,43 @@ val binaryFunctions = mapOf>( binaryOperation("times", "Int", "Short") { a, b -> a.times(b) }, binaryOperation("ushr", "Int", "Int") { a, b -> a.ushr(b) }, binaryOperation("xor", "Int", "Int") { a, b -> a.xor(b) }, + binaryOperation("compareTo", "Float", "Byte") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Float", "Double") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Float", "Float") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Float", "Int") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Float", "Long") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Float", "Short") { a, b -> a.compareTo(b) }, + binaryOperation("div", "Float", "Byte") { a, b -> a.div(b) }, + binaryOperation("div", "Float", "Double") { a, b -> a.div(b) }, + binaryOperation("div", "Float", "Float") { a, b -> a.div(b) }, + binaryOperation("div", "Float", "Int") { a, b -> a.div(b) }, + binaryOperation("div", "Float", "Long") { a, b -> a.div(b) }, + binaryOperation("div", "Float", "Short") { a, b -> a.div(b) }, + binaryOperation("equals", "Float", "Any?") { a, b -> a.equals(b) }, + binaryOperation("minus", "Float", "Byte") { a, b -> a.minus(b) }, + binaryOperation("minus", "Float", "Double") { a, b -> a.minus(b) }, + binaryOperation("minus", "Float", "Float") { a, b -> a.minus(b) }, + binaryOperation("minus", "Float", "Int") { a, b -> a.minus(b) }, + binaryOperation("minus", "Float", "Long") { a, b -> a.minus(b) }, + binaryOperation("minus", "Float", "Short") { a, b -> a.minus(b) }, + binaryOperation("plus", "Float", "Byte") { a, b -> a.plus(b) }, + binaryOperation("plus", "Float", "Double") { a, b -> a.plus(b) }, + binaryOperation("plus", "Float", "Float") { a, b -> a.plus(b) }, + binaryOperation("plus", "Float", "Int") { a, b -> a.plus(b) }, + binaryOperation("plus", "Float", "Long") { a, b -> a.plus(b) }, + binaryOperation("plus", "Float", "Short") { a, b -> a.plus(b) }, + binaryOperation("rem", "Float", "Byte") { a, b -> a.rem(b) }, + binaryOperation("rem", "Float", "Double") { a, b -> a.rem(b) }, + binaryOperation("rem", "Float", "Float") { a, b -> a.rem(b) }, + binaryOperation("rem", "Float", "Int") { a, b -> a.rem(b) }, + binaryOperation("rem", "Float", "Long") { a, b -> a.rem(b) }, + binaryOperation("rem", "Float", "Short") { a, b -> a.rem(b) }, + binaryOperation("times", "Float", "Byte") { a, b -> a.times(b) }, + binaryOperation("times", "Float", "Double") { a, b -> a.times(b) }, + binaryOperation("times", "Float", "Float") { a, b -> a.times(b) }, + binaryOperation("times", "Float", "Int") { a, b -> a.times(b) }, + binaryOperation("times", "Float", "Long") { a, b -> a.times(b) }, + binaryOperation("times", "Float", "Short") { a, b -> a.times(b) }, binaryOperation("and", "Long", "Long") { a, b -> a.and(b) }, binaryOperation("compareTo", "Long", "Byte") { a, b -> a.compareTo(b) }, binaryOperation("compareTo", "Long", "Double") { a, b -> a.compareTo(b) }, @@ -340,52 +344,47 @@ val binaryFunctions = mapOf>( binaryOperation("times", "Long", "Short") { a, b -> a.times(b) }, binaryOperation("ushr", "Long", "Int") { a, b -> a.ushr(b) }, binaryOperation("xor", "Long", "Long") { a, b -> a.xor(b) }, - binaryOperation("compareTo", "Short", "Byte") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Short", "Double") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Short", "Float") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Short", "Int") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Short", "Long") { a, b -> a.compareTo(b) }, - binaryOperation("compareTo", "Short", "Short") { a, b -> a.compareTo(b) }, - binaryOperation("div", "Short", "Byte") { a, b -> a.div(b) }, - binaryOperation("div", "Short", "Double") { a, b -> a.div(b) }, - binaryOperation("div", "Short", "Float") { a, b -> a.div(b) }, - binaryOperation("div", "Short", "Int") { a, b -> a.div(b) }, - binaryOperation("div", "Short", "Long") { a, b -> a.div(b) }, - binaryOperation("div", "Short", "Short") { a, b -> a.div(b) }, - binaryOperation("equals", "Short", "Any?") { a, b -> a.equals(b) }, - binaryOperation("minus", "Short", "Byte") { a, b -> a.minus(b) }, - binaryOperation("minus", "Short", "Double") { a, b -> a.minus(b) }, - binaryOperation("minus", "Short", "Float") { a, b -> a.minus(b) }, - binaryOperation("minus", "Short", "Int") { a, b -> a.minus(b) }, - binaryOperation("minus", "Short", "Long") { a, b -> a.minus(b) }, - binaryOperation("minus", "Short", "Short") { a, b -> a.minus(b) }, - binaryOperation("plus", "Short", "Byte") { a, b -> a.plus(b) }, - binaryOperation("plus", "Short", "Double") { a, b -> a.plus(b) }, - binaryOperation("plus", "Short", "Float") { a, b -> a.plus(b) }, - binaryOperation("plus", "Short", "Int") { a, b -> a.plus(b) }, - binaryOperation("plus", "Short", "Long") { a, b -> a.plus(b) }, - binaryOperation("plus", "Short", "Short") { a, b -> a.plus(b) }, - binaryOperation("rangeTo", "Short", "Byte") { a, b -> a.rangeTo(b) }, - binaryOperation("rangeTo", "Short", "Int") { a, b -> a.rangeTo(b) }, - binaryOperation("rangeTo", "Short", "Long") { a, b -> a.rangeTo(b) }, - binaryOperation("rangeTo", "Short", "Short") { a, b -> a.rangeTo(b) }, - binaryOperation("rem", "Short", "Byte") { a, b -> a.rem(b) }, - binaryOperation("rem", "Short", "Double") { a, b -> a.rem(b) }, - binaryOperation("rem", "Short", "Float") { a, b -> a.rem(b) }, - binaryOperation("rem", "Short", "Int") { a, b -> a.rem(b) }, - binaryOperation("rem", "Short", "Long") { a, b -> a.rem(b) }, - binaryOperation("rem", "Short", "Short") { a, b -> a.rem(b) }, - binaryOperation("times", "Short", "Byte") { a, b -> a.times(b) }, - binaryOperation("times", "Short", "Double") { a, b -> a.times(b) }, - binaryOperation("times", "Short", "Float") { a, b -> a.times(b) }, - binaryOperation("times", "Short", "Int") { a, b -> a.times(b) }, - binaryOperation("times", "Short", "Long") { a, b -> a.times(b) }, - binaryOperation("times", "Short", "Short") { a, b -> a.times(b) }, + binaryOperation("compareTo", "Double", "Byte") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Double", "Double") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Double", "Float") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Double", "Int") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Double", "Long") { a, b -> a.compareTo(b) }, + binaryOperation("compareTo", "Double", "Short") { a, b -> a.compareTo(b) }, + binaryOperation("div", "Double", "Byte") { a, b -> a.div(b) }, + binaryOperation("div", "Double", "Double") { a, b -> a.div(b) }, + binaryOperation("div", "Double", "Float") { a, b -> a.div(b) }, + binaryOperation("div", "Double", "Int") { a, b -> a.div(b) }, + binaryOperation("div", "Double", "Long") { a, b -> a.div(b) }, + binaryOperation("div", "Double", "Short") { a, b -> a.div(b) }, + binaryOperation("equals", "Double", "Any?") { a, b -> a.equals(b) }, + binaryOperation("minus", "Double", "Byte") { a, b -> a.minus(b) }, + binaryOperation("minus", "Double", "Double") { a, b -> a.minus(b) }, + binaryOperation("minus", "Double", "Float") { a, b -> a.minus(b) }, + binaryOperation("minus", "Double", "Int") { a, b -> a.minus(b) }, + binaryOperation("minus", "Double", "Long") { a, b -> a.minus(b) }, + binaryOperation("minus", "Double", "Short") { a, b -> a.minus(b) }, + binaryOperation("plus", "Double", "Byte") { a, b -> a.plus(b) }, + binaryOperation("plus", "Double", "Double") { a, b -> a.plus(b) }, + binaryOperation("plus", "Double", "Float") { a, b -> a.plus(b) }, + binaryOperation("plus", "Double", "Int") { a, b -> a.plus(b) }, + binaryOperation("plus", "Double", "Long") { a, b -> a.plus(b) }, + binaryOperation("plus", "Double", "Short") { a, b -> a.plus(b) }, + binaryOperation("rem", "Double", "Byte") { a, b -> a.rem(b) }, + binaryOperation("rem", "Double", "Double") { a, b -> a.rem(b) }, + binaryOperation("rem", "Double", "Float") { a, b -> a.rem(b) }, + binaryOperation("rem", "Double", "Int") { a, b -> a.rem(b) }, + binaryOperation("rem", "Double", "Long") { a, b -> a.rem(b) }, + binaryOperation("rem", "Double", "Short") { a, b -> a.rem(b) }, + binaryOperation("times", "Double", "Byte") { a, b -> a.times(b) }, + binaryOperation("times", "Double", "Double") { a, b -> a.times(b) }, + binaryOperation("times", "Double", "Float") { a, b -> a.times(b) }, + binaryOperation("times", "Double", "Int") { a, b -> a.times(b) }, + binaryOperation("times", "Double", "Long") { a, b -> a.times(b) }, + binaryOperation("times", "Double", "Short") { a, b -> a.times(b) }, binaryOperation("compareTo", "String", "String") { a, b -> a.compareTo(b) }, binaryOperation("equals", "String", "Any?") { a, b -> a.equals(b) }, binaryOperation("get", "String", "Int") { a, b -> a.get(b) }, binaryOperation("plus", "String", "Any?") { a, b -> a.plus(b) }, - binaryOperation, Int>("get", "Array", "Int") { a, b -> a.get(b) }, binaryOperation("get", "BooleanArray", "Int") { a, b -> a.get(b) }, binaryOperation("get", "CharArray", "Int") { a, b -> a.get(b) }, binaryOperation("get", "ByteArray", "Int") { a, b -> a.get(b) }, @@ -394,6 +393,7 @@ val binaryFunctions = mapOf>( binaryOperation("get", "FloatArray", "Int") { a, b -> a.get(b) }, binaryOperation("get", "LongArray", "Int") { a, b -> a.get(b) }, binaryOperation("get", "DoubleArray", "Int") { a, b -> a.get(b) }, + binaryOperation, Int>("get", "Array", "Int") { a, b -> a.get(b) }, binaryOperation("equals", "Any", "Any?") { a, b -> a.equals(b) }, binaryOperation("less", "Char", "Char") { a, b -> a < b }, binaryOperation("less", "Byte", "Byte") { a, b -> a < b }, @@ -430,9 +430,9 @@ val binaryFunctions = mapOf>( binaryOperation("ANDAND", "Boolean", "Boolean") { a, b -> a && b }, binaryOperation("OROR", "Boolean", "Boolean") { a, b -> a || b } ) + val ternaryFunctions = mapOf>( ternaryOperation("subSequence", "String", "Int", "Int") { a, b, c -> a.subSequence(b, c) }, - ternaryOperation, Int, Any?>("set", "Array", "Int", "T") { a, b, c -> a.set(b, c) }, ternaryOperation("set", "BooleanArray", "Int", "Boolean") { a, b, c -> a.set(b, c) }, ternaryOperation("set", "CharArray", "Int", "Char") { a, b, c -> a.set(b, c) }, ternaryOperation("set", "ByteArray", "Int", "Byte") { a, b, c -> a.set(b, c) }, @@ -440,6 +440,14 @@ val ternaryFunctions = mapOf("set", "IntArray", "Int", "Int") { a, b, c -> a.set(b, c) }, ternaryOperation("set", "FloatArray", "Int", "Float") { a, b, c -> a.set(b, c) }, ternaryOperation("set", "LongArray", "Int", "Long") { a, b, c -> a.set(b, c) }, - ternaryOperation("set", "DoubleArray", "Int", "Double") { a, b, c -> a.set(b, c) } + ternaryOperation("set", "DoubleArray", "Int", "Double") { a, b, c -> a.set(b, c) }, + ternaryOperation, Int, Any?>("set", "Array", "Int", "T") { a, b, c -> a.set(b, c) } ) +private fun Any.defaultToString(): String { + return when (this) { + is State -> "${this.irClass.name}@" + System.identityHashCode(this).toString(16).padStart(8, '0') + else -> this.toString().replaceAfter("@", System.identityHashCode(this).toString(16).padStart(8, '0')) + } +} + diff --git a/generators/evaluate/GenerateBuiltInsMap.kt b/generators/evaluate/GenerateBuiltInsMap.kt index 463ff924017..7129c4448fd 100644 --- a/generators/evaluate/GenerateBuiltInsMap.kt +++ b/generators/evaluate/GenerateBuiltInsMap.kt @@ -41,7 +41,7 @@ fun generateMap(): String { p.println(File("license/COPYRIGHT.txt").readText()) p.println("package org.jetbrains.kotlin.backend.common.interpreter.builtins") p.println() - p.println("import org.jetbrains.kotlin.backend.common.interpreter.stack.State") + p.println("import org.jetbrains.kotlin.backend.common.interpreter.stack.*") p.println() p.println("/** This file is generated by org.jetbrains.kotlin.backend.common.interpreter.builtins.GenerateBuiltInsMap.generateMap(). DO NOT MODIFY MANUALLY */") p.println() @@ -52,11 +52,8 @@ fun generateMap(): String { val builtIns = DefaultBuiltIns.Instance //save common builtins - @Suppress("UNCHECKED_CAST") - val allPrimitiveTypes = builtIns.builtInsPackageScope.getContributedDescriptors() - .filter { it is ClassDescriptor && KotlinBuiltIns.isPrimitiveType(it.defaultType) } as List - - val arrays = listOf(builtIns.array) + PrimitiveType.values().map { builtIns.getPrimitiveArrayClassDescriptor(it) } + val allPrimitiveTypes = PrimitiveType.values().map { builtIns.getBuiltInClassByFqName(it.typeFqName) } + val arrays = PrimitiveType.values().map { builtIns.getPrimitiveArrayClassDescriptor(it) } + builtIns.array for (descriptor in allPrimitiveTypes + builtIns.string + arrays + builtIns.any) { val typeParameters = descriptor.typeConstructor.parameters.map { it.name.asString() } @@ -118,12 +115,13 @@ fun generateMap(): String { val unaryBody = unaryOperationsMap.entries.joinToString(",\n", postfix = ",\n") { (function, parameters) -> val methodName = "${function.name}" val parentheses = if (function is FunctionDescriptor) "()" else "" - val body = if (methodName == "toString" && parameters.first == "") - "\n\t\tif (a is State) \"\${a.irClass.name}@\" + System.identityHashCode(a).toString(16).padStart(8) else a.toString()\n\t" - else - "a.$methodName$parentheses " - " unaryOperation${parameters.first}(\"$methodName\", ${parameters.second}) { a -> $body}" - } + " unaryOperation(\"${irNullCheck.name}\", \"${irNullCheck.valueParameters.first().type}\") { a -> a!! }" + val body = + if (methodName == "toString" && parameters.first == "") "a.defaultToString()" + else "a.$methodName$parentheses" + " unaryOperation${parameters.first}(\"$methodName\", ${parameters.second}) { a -> $body }" + } + " unaryOperation(\"${irNullCheck.name}\", \"${irNullCheck.valueParameters.first().type}\") { a -> a!! },\n" + + " unaryOperation(\"\", \"Throwable\") { a -> a.getMessage() },\n" + + " unaryOperation(\"\", \"Throwable\") { a -> a.getCause() }" p.println(unaryBody) p.println(")") p.println() @@ -150,6 +148,7 @@ fun generateMap(): String { } p.println(binaryBody) p.println(")") + p.println() p.println("val ternaryFunctions = mapOf>(") val ternaryBody = ternaryOperationsMap.entries.joinToString(",\n") { (function, parameters) -> @@ -160,6 +159,18 @@ fun generateMap(): String { p.println(")") p.println() + p.println( + """ + private fun Any.defaultToString(): String { + return when (this) { + is State -> "${'$'}{this.irClass.name}@" + System.identityHashCode(this).toString(16).padStart(8, '0') + else -> this.toString().replaceAfter("@", System.identityHashCode(this).toString(16).padStart(8, '0')) + } + } + """.trimIndent() + ) + p.println() + return sb.toString() }