Review feedback, part 2:
implement return to any target from FinalizingScope
This commit is contained in:
+13
-14
@@ -748,26 +748,25 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
private abstract inner class FinalizingScope() : CatchingScope() {
|
private abstract inner class FinalizingScope() : CatchingScope() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The [ContinuationBlock] to be used for `return` from the function.
|
* Cache for [genReturn].
|
||||||
* Expects return value as its value.
|
*
|
||||||
|
* `returnBlocks[func]` contains the [ContinuationBlock] to be used for `return` from `func`;
|
||||||
|
* the block expects return value as its value.
|
||||||
*/
|
*/
|
||||||
private val returnFromCurrent: ContinuationBlock by lazy {
|
private val returnBlocks = mutableMapOf<CallableDescriptor, ContinuationBlock>()
|
||||||
using(outerContext) {
|
|
||||||
val target = codegen.currentFunction!!
|
|
||||||
continuationBlock(target.returnType!!) { returnValue ->
|
|
||||||
genFinalize()
|
|
||||||
outerContext.genReturn(target, returnValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jump to finalize-and-return instead of simply returning.
|
// Jump to finalize-and-return instead of simply returning.
|
||||||
override fun genReturn(target: CallableDescriptor, value: LLVMValueRef?) {
|
override fun genReturn(target: CallableDescriptor, value: LLVMValueRef?) {
|
||||||
if (target != codegen.currentFunction) {
|
val block = returnBlocks.getOrPut(target) {
|
||||||
TODO()
|
using(outerContext) {
|
||||||
|
continuationBlock(target.returnType!!) { returnValue ->
|
||||||
|
genFinalize()
|
||||||
|
outerContext.genReturn(target, returnValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jump(returnFromCurrent, value)
|
jump(block, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun genBreak(loop: IrLoop) = TODO()
|
override fun genBreak(loop: IrLoop) = TODO()
|
||||||
|
|||||||
Reference in New Issue
Block a user