Skip to content

Commit

Permalink
fix 6502 codegen error for mixed case register params and normal params
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Feb 10, 2025
1 parent c7f0ff1 commit 17334a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as
useCpuRegistersForArgs(call.args, sub)
} else {
// arguments via variables
val (normalParams, registerParams) = sub.parameters.withIndex().partition { it.value.register == null }
val paramValues = sub.parameters.zip(call.args)
val (normalParams, registerParams) = paramValues.partition { it.first.register == null }
if (normalParams.isNotEmpty()) {
for (arg in normalParams.zip(call.args))
argumentViaVariable(sub, arg.first.value, arg.second)
for (p in normalParams)
argumentViaVariable(sub, p.first, p.second)
}
if (registerParams.isNotEmpty()) {
// the R0-R15 'registers' are not really registers. They're just special variables.
for (arg in registerParams.zip(call.args))
argumentViaVariable(sub, arg.first.value, arg.second)
for (p in registerParams)
argumentViaVariable(sub, p.first, p.second)
}
}
asmgen.out(" jsr $subAsmName")
Expand Down
13 changes: 9 additions & 4 deletions examples/test.p8
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
%import textio
%zeropage basicsafe

main {

sub start() {
str minString1 = 1234
str minString2 = func()
func($11,$22,$33,$44)
}

sub func() -> str {
return "zz"
sub func(ubyte arg1, ubyte arg2 @R1, ubyte arg3 @R2, ubyte arg4) {
txt.print_ubhex(arg1, false)
txt.print_ubhex(arg2, false)
txt.print_ubhex(arg3, false)
txt.print_ubhex(arg4, false)
}
}

0 comments on commit 17334a1

Please sign in to comment.