diff --git a/compiler/src/main/kotlin/gay/pizza/pork/compiler/CodeBuilder.kt b/compiler/src/main/kotlin/gay/pizza/pork/compiler/CodeBuilder.kt index 8463c0e..2c1ddf4 100644 --- a/compiler/src/main/kotlin/gay/pizza/pork/compiler/CodeBuilder.kt +++ b/compiler/src/main/kotlin/gay/pizza/pork/compiler/CodeBuilder.kt @@ -40,6 +40,8 @@ class CodeBuilder(val symbol: CompilableSymbol) { ops.add(PatchSymOp(Op(code, arguments), patches)) } + fun lastOp(): StubOp? = ops.lastOrNull() + fun annotate(text: String) { annotations.add(StubOpAnnotation(symbol, nextOpInst(), text)) } diff --git a/compiler/src/main/kotlin/gay/pizza/pork/compiler/IrStubOpEmitter.kt b/compiler/src/main/kotlin/gay/pizza/pork/compiler/IrStubOpEmitter.kt index 00d8ac4..3ef1617 100644 --- a/compiler/src/main/kotlin/gay/pizza/pork/compiler/IrStubOpEmitter.kt +++ b/compiler/src/main/kotlin/gay/pizza/pork/compiler/IrStubOpEmitter.kt @@ -17,8 +17,9 @@ class IrStubOpEmitter(val irDefinition: IrDefinition, val code: CodeBuilder) : I } fun final() { - code.emit(Opcode.Return) - code.emit(Opcode.End) + if (code.lastOp()?.op?.code != Opcode.Return) { + code.emit(Opcode.Return) + } } private fun resolve(symbol: IrSymbol): Loadable = code.localState.resolve(symbol)