Review feedback, part 2:

implement return to any target from FinalizingScope
This commit is contained in:
Svyatoslav Scherbina
2016-11-29 13:59:24 +07:00
parent d44b79fa51
commit 0c81cfdb24
@@ -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()