Skip to content

Commit 944c200

Browse files
author
Mikhael Bogdanov
committed
Initial support of try as expression in JVM IR
1 parent 30aeb8d commit 944c200

File tree

8 files changed

+18
-7
lines changed

8 files changed

+18
-7
lines changed

compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.ir.declarations.*
3333
import org.jetbrains.kotlin.ir.expressions.*
3434
import org.jetbrains.kotlin.ir.symbols.IrSymbol
3535
import org.jetbrains.kotlin.ir.types.IrType
36-
import org.jetbrains.kotlin.ir.types.isMarkedNullable
3736
import org.jetbrains.kotlin.ir.types.toKotlinType
3837
import org.jetbrains.kotlin.ir.util.*
3938
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -1033,6 +1032,14 @@ class ExpressionCodegen(
10331032
val tryBlockStart = markNewLabel()
10341033
mv.nop()
10351034
gen(aTry.tryResult, aTry.asmType, data)
1035+
1036+
val isExpression = true //TODO: more wise check is required
1037+
var savedValue: Local? = null
1038+
if (isExpression) {
1039+
savedValue = local(frame.enterTemp(aTry.asmType), aTry.asmType)
1040+
savedValue.store(onStack(aTry.asmType), mv)
1041+
}
1042+
10361043
val tryBlockEnd = markNewLabel()
10371044

10381045
val tryRegions = getCurrentTryIntervals(tryInfo, tryBlockStart, tryBlockEnd)
@@ -1056,6 +1063,10 @@ class ExpressionCodegen(
10561063
catchBody.markLineNumber(true)
10571064
gen(catchBody, catchBody.asmType, data)
10581065

1066+
savedValue?.let {
1067+
savedValue.store(onStack(aTry.asmType), mv)
1068+
}
1069+
10591070
frame.leave(clause.catchParameter)
10601071

10611072
val clauseEnd = markNewLabel()
@@ -1096,6 +1107,11 @@ class ExpressionCodegen(
10961107
}
10971108

10981109
mv.mark(tryCatchBlockEnd)
1110+
1111+
savedValue?.let {
1112+
savedValue.put(mv)
1113+
frame.leaveTemp(aTry.asmType)
1114+
}
10991115
return aTry.onStack
11001116
}
11011117

compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/finallyInFinally2.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// IGNORE_BACKEND: JVM_IR
21
// FILE: 1.kt
32

43
package test

compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex3.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// IGNORE_BACKEND: JVM_IR
21
// FILE: 1.kt
32

43
package test

compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex4.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// IGNORE_BACKEND: JVM_IR
21
// FILE: 1.kt
32

43
package test

compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite/returnInFinally.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// IGNORE_BACKEND: JVM_IR
21
// FILE: 1.kt
32

43
package test

compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/nestedWithReturns.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// IGNORE_BACKEND: JVM_IR
21
// FILE: 1.kt
32

43
package test

compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/tryCatchInFinally.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// IGNORE_BACKEND: JVM_IR
21
// FILE: 1.kt
32

43
package test

compiler/testData/codegen/bytecodeText/statements/tryCatchFinally.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// IGNORE_BACKEND: JVM_IR
12
fun z() {}
23

34
fun foo() {

0 commit comments

Comments
 (0)