max 16 subroutine params

This commit is contained in:
Irmen de Jong 2020-12-25 02:59:19 +01:00
parent 3307f673f6
commit b91aabd3c0
5 changed files with 23 additions and 12 deletions

View File

@ -2,9 +2,10 @@
%import syslib
%import textio
; bitmap pixel graphics module for the CommanderX16
; Bitmap pixel graphics module for the CommanderX16
; wraps the graphics functions that are in ROM.
; only black/white monchrome 320x200 for now.
; only black/white monchrome 320x200 for now. (i.e. truncated at the bottom)
; For full-screen 640x480 or 320x240 graphics, use the "gfx2" module instead. (but that is Cx16-specific)
graphics {
const uword WIDTH = 320
@ -133,5 +134,3 @@ graphics {
cx16.FB_set_pixel(1)
}
}

View File

@ -202,6 +202,9 @@ internal class AstChecker(private val program: Program,
if(subroutine.name in BuiltinFunctions)
err("cannot redefine a built-in function")
if(subroutine.parameters.size>16)
err("subroutines are limited to 16 parameters")
val uniqueNames = subroutine.parameters.asSequence().map { it.name }.toSet()
if(uniqueNames.size!=subroutine.parameters.size)
err("parameter names must be unique")

View File

@ -47,21 +47,19 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
// just a single parameter, no risk of clobbering registers
argumentViaRegister(sub, IndexedValue(0, sub.parameters.single()), stmt.args[0])
} else {
// multiple register arguments, risk of register clobbering.
// evaluate arguments onto the stack, and load the registers from the evaluated values on the stack.
when {
stmt.args.all {it is AddressOf ||
it is NumericLiteralValue ||
it is StringLiteralValue ||
it is ArrayLiteralValue ||
it is IdentifierReference} -> {
// no risk of clobbering for these simple argument types. Optimize the register loading.
// There's no risk of clobbering for these simple argument types. Optimize the register loading directly from these values.
for(arg in sub.parameters.withIndex().zip(stmt.args)) {
argumentViaRegister(sub, arg.first, arg.second)
}
}
else -> {
// Risk of clobbering due to complex expression args. Work via the stack.
// Risk of clobbering due to complex expression args. Work via the evaluation stack.
registerArgsViaStackEvaluation(stmt, sub)
}
}

View File

@ -1,10 +1,17 @@
%target cx16
%import textio
%import graphics
%import test_stack
%zeropage basicsafe
%option no_sysinit
; TODO full-screen graphics mode library, in development. (as replacement for the graphics routines in ROM that are constrained to 200 vertical pixels and lores mode only)
; Bitmap pixel graphics module for the CommanderX16
; Custom routines to use the full-screen 640x480 and 320x240 screen modes.
; This is only compatible with the Cx16.
; For compatible graphics code that words on C64 too, use the "graphics" module instead.
; TODO this is in development.
main {

View File

@ -23,12 +23,16 @@ main {
sub start () {
txt.chrout('!')
ubyte bank = 1
uword bank = 1
uword address = 1000
ubyte value = 123
bank++
vpoke(bank, address, value)
vpokeasm(address, bank, value) ; TODO generates params on stack if expression is used such as lsb(bank). CHECK STACK UNWINDING!!!
test_stack.test()
vpoke(lsb(bank), address, value)
test_stack.test()
vpokeasm(address, lsb(bank), value) ; TODO generates params on stack if expression is used such as lsb(bank). CHECK STACK UNWINDING!!!
test_stack.test()
; TODO also see if we can do this via R0-R15 temp registers rather than using the estack???
}
}