diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 7518bd6d2..0aeb80c5d 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -1005,7 +1005,7 @@ internal class AstChecker(private val program: Program, // It's not (yet) possible to handle these multiple return values because assignments // are only to a single unique target at the same time. // EXCEPTION: - // if the asmsub returns multiple values and one of them is via a status register bit, + // if the asmsub returns multiple values and one of them is via a status register bit (such as carry), // it *is* possible to handle them by just actually assigning the register value and // dealing with the status bit as just being that, the status bit after the call. val (returnRegisters, _) = stmt.asmReturnvaluesRegisters.partition { rr -> rr.registerOrPair != null } diff --git a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt index f72627916..011306334 100644 --- a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt +++ b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt @@ -91,6 +91,10 @@ internal class VerifyFunctionArgTypes(val program: Program, val errors: IErrorRe if(target.asmReturnvaluesRegisters.size>1) { // multiple return values will NOT work inside an expression. // they MIGHT work in a regular assignment or just a function call statement. + // EXCEPTION: + // if the asmsub returns multiple values and one of them is via a status register bit (such as carry), + // it *is* possible to handle them by just actually assigning the register value and + // dealing with the status bit as just being that, the status bit after the call. val parent = if(call is Statement) call.parent else if(call is Expression) call.parent else null if (call !is FunctionCallStatement) { val checkParent = @@ -99,7 +103,10 @@ internal class VerifyFunctionArgTypes(val program: Program, val errors: IErrorRe else parent if (checkParent !is Assignment && checkParent !is VarDecl) { - return Pair("can't use subroutine call that returns multiple return values here", call.position) + val (returnRegisters, _) = target.asmReturnvaluesRegisters.partition { rr -> rr.registerOrPair != null } + if (returnRegisters.size>1) { + return Pair("can't use subroutine call that returns multiple return values here", call.position) + } } } } diff --git a/examples/test.p8 b/examples/test.p8 index b14e51429..fb3ad4aba 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,9 +1,23 @@ main { - sub start() { - ubyte aa = 42 - ubyte bb = 99 - aa += bb + asmsub multi() -> ubyte @A, ubyte @Pc { + %asm {{ + lda #42 + sec + rts + }} + } - %asmbinary "build.gradle" + sub start() { + ubyte value + + value = multi() + + while 0==multi() { + value++ + } + + if multi() { + value++ + } } }