diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 7dd0fe931..291cfd33a 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -205,7 +205,7 @@ internal class AstChecker(private val program: Program, if(subroutine.inline) { if (subroutine.containsDefinedVariables()) - err("can't inline a subroutine that defines variables") + err("can't inline a subroutine that defines variables (might also be a generated intermediate variable for complex return expressions)") if (!subroutine.isAsmSubroutine && subroutine.parameters.isNotEmpty()) err("can't inline a non-asm subroutine that has parameters") } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 93dd5395a..2e98e58fe 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,6 +2,7 @@ TODO ==== +- allow inlining of subroutines with vardecls - optimize several inner loops in gfx2 - hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine) - optimize swap of two memread values with index, using the same pointer expression/variable, like swap(@(ptr+1), @(ptr+2)) diff --git a/examples/test.p8 b/examples/test.p8 index 7eb4329cf..4ac15b131 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,27 +1,11 @@ %import textio %zeropage basicsafe -%option no_sysinit main { sub start() { - - ubyte color=0 - ubyte xx - uword ptr = $0400 - - @($02) = 0 - - repeat { - sys.waitvsync() - %asm {{ - ldy $02 - lda #'*' - sta $0400,y - inc $02 - }} - } - txt.print("hello") + ubyte thing = otherblock.othersub() + txt.print_ub(thing) ; should print 99! ; str filename = "titlescreen.bin" ; ubyte success = cx16.vload(filename, 8, 0, $0000) @@ -38,3 +22,16 @@ main { } } +otherblock { + + ubyte othervar=20 + ubyte calcparam=10 + + sub calc(ubyte zz) -> ubyte { + return zz+1 + } + + inline sub othersub() -> ubyte { + return calc(calcparam) + } +}