From 76e102a2d256a7aec5b16c24d8c0553ebc62ef67 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Thu, 12 Apr 2018 02:46:19 +0300 Subject: [PATCH] [JS IR BE] declare more intrinsics * jsGt * jsGtEq * jsLt * jsLtEq * jsUnaryPlus * jsUnaryMinus * jsPrefixInc * jsPostfixInc * jsPrefixDec * jsPostfixDec * jsAnd * jsOr * jsBitAnd * jsBitOr * jsBitXor * jsBitNot * jsBitShiftR * jsBitShiftRU * jsBitShiftL * jsInstanceOf --- .../kotlin/ir/backend/js/JsIntrinsics.kt | 60 ++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt index 21eeb32d8f0..7baa2e2168a 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIntrinsics.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.js.resolve.JsPlatform.builtIns import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinTypeFactory import org.jetbrains.kotlin.types.Variance @@ -22,24 +23,62 @@ class JsIntrinsics(private val module: ModuleDescriptor, private val irBuiltIns: private val stubBuilder = DeclarationStubGenerator(symbolTable, JsLoweredDeclarationOrigin.JS_INTRINSICS_STUB) - // Equality + // Equality operations: + val jsEqeq = binOpBool("jsEqeq") val jsNotEq = binOpBool("jsNotEq") val jsEqeqeq = binOpBool("jsEqeqeq") val jsNotEqeq = binOpBool("jsNotEqeq") - // Unary operations + val jsGt = binOpBool("jsGt") + val jsGtEq = binOpBool("jsGtEq") + val jsLt = binOpBool("jsLt") + val jsLtEq = binOpBool("jsLtEq") + + + // Unary operations: + val jsNot = unOpBool("jsNot") - // Binary operations + val jsUnaryPlus = unOp("jsUnaryPlus") + val jsUnaryMinus = unOp("jsUnaryMinus") + + val jsPrefixInc = unOp("jsPrefixInc") + val jsPostfixInc = unOp("jsPostfixInc") + val jsPrefixDec = unOp("jsPrefixDec") + val jsPostfixDec = unOp("jsPostfixDec") + + // Binary operations: + val jsPlus = binOp("jsPlus") val jsMinus = binOp("jsMinus") val jsMult = binOp("jsMult") val jsDiv = binOp("jsDiv") val jsMod = binOp("jsMod") + val jsAnd = binOp("jsAnd") + val jsOr = binOp("jsOr") + + + // Bit operations: + + val jsBitAnd = binOpInt("jsBitAnd") + val jsBitOr = binOpInt("jsBitOr") + val jsBitXor = binOpInt("jsBitXor") + val jsBitNot = unOpInt("jsBitNot") + + val jsBitShiftR = binOpInt("jsBitShiftR") + val jsBitShiftRU = binOpInt("jsBitShiftRU") + val jsBitShiftL = binOpInt("jsBitShiftL") + + + // Other: + + val jsInstanceOf = binOpBool("jsInstanceOf") + val jsObjectCreate: IrSimpleFunction = defineObjectCreateIntrinsic() + // Helpers: // TODO: unify how we create intrinsic symbols @@ -70,8 +109,15 @@ class JsIntrinsics(private val module: ModuleDescriptor, private val irBuiltIns: return stubBuilder.generateFunctionStub(desc) } - private fun unOpBool(name: String) = irBuiltIns.run { defineOperator(name, bool, listOf(anyN, anyN)) } - private fun binOpBool(name: String) = irBuiltIns.run { defineOperator(name, bool, listOf(anyN, anyN)) } - private fun unOp(name: String) = irBuiltIns.run { defineOperator(name, anyN, listOf(anyN, anyN)) } - private fun binOp(name: String) = irBuiltIns.run { defineOperator(name, anyN, listOf(anyN, anyN)) } + private fun unOp(name: String, returnType: KotlinType = irBuiltIns.anyN) = + irBuiltIns.run { defineOperator(name, returnType, listOf(anyN)) } + + private fun unOpBool(name: String) = unOp(name, irBuiltIns.bool) + private fun unOpInt(name: String) = unOp(name, irBuiltIns.int) + + private fun binOp(name: String, returnType: KotlinType = irBuiltIns.anyN) = + irBuiltIns.run { defineOperator(name, returnType, listOf(anyN, anyN)) } + + private fun binOpBool(name: String) = binOp(name, irBuiltIns.bool) + private fun binOpInt(name: String) = binOp(name, irBuiltIns.int) }