fix inlining of sub with var that has default initialization

This commit is contained in:
Irmen de Jong 2021-04-08 00:03:38 +02:00
parent e5ff61f201
commit a9d297ee31
3 changed files with 8 additions and 9 deletions

View File

@ -22,7 +22,7 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, val errors: I
if(decl.allowInitializeWithZero)
{
val nextAssign = decl.definingScope().nextSibling(decl) as? Assignment
if (nextAssign != null && nextAssign.target.isSameAs(IdentifierReference(listOf(decl.name), Position.DUMMY)))
if (nextAssign != null && nextAssign.target isSameAs IdentifierReference(listOf(decl.name), Position.DUMMY))
decl.value = null
else
decl.value = decl.zeroElementValue()

View File

@ -124,7 +124,8 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
if(it is Return) {
asmgen.translate(it, false) // don't use RTS for the inlined return statement
} else {
asmgen.translate(it)
if(!sub.inline || it !is VarDecl)
asmgen.translate(it)
}
}
asmgen.out(" \t; inlined routine end: ${sub.name}")

View File

@ -1,5 +1,5 @@
%import textio
%zeropage basicsafe
%zeropage dontuse
main {
@ -9,17 +9,15 @@ main {
; cx16.rambank(4)
; cx16.rambank(4)
; cx16.rambank(4)
uword yy = 12345
ubyte xx
xx = calc2(41, 12345)
xx = calc2(41, 12345)
xx = calc2(41, 12345)
xx = calc2(41, 12345)
txt.print_ub(xx) ; must be 99
txt.nl()
}
inline sub calc2(ubyte a1, uword a2) -> ubyte {
uword thesum = a2 + a1
return lsb(thesum+a2)
uword thesum
thesum = a2 + a1
return lsb(thesum)
}
}