diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index e4222f490..24841ea5b 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -1039,6 +1039,28 @@ internal class AstChecker(private val program: Program, if (!argIDt.isKnown) return } + + // check that cx16 virtual registers aren't used as arguments in a conflicting way + val params = target.asmParameterRegisters.withIndex().toList() + for(arg in args.withIndex()) { + var ident: IdentifierReference? = null + if(arg.value is IdentifierReference) + ident = arg.value as IdentifierReference + else if(arg.value is FunctionCall) { + val fcall = arg.value as FunctionCall + if(fcall.target.nameInSource == listOf("lsb") || fcall.target.nameInSource == listOf("msb")) + ident = fcall.args[0] as? IdentifierReference + } + if(ident!=null && ident.nameInSource[0] == "cx16" && ident.nameInSource[1].startsWith("r")) { + val reg = RegisterOrPair.valueOf(ident.nameInSource[1].toUpperCase()) + val same = params.filter { it.value.registerOrPair==reg } + for(s in same) { + if(s.index!=arg.index) { + errors.err("conflicting register $reg used as argument but is also a target register for another parameter", ident.position) + } + } + } + } } } } diff --git a/examples/test.p8 b/examples/test.p8 index 7ce2204b6..22a8ab335 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,12 +4,6 @@ main { sub start() { - ubyte bank - - ; TODO give error that a register is used as an argument value and at the same time is a register parameter taking a new value. - ; (note: this is OK if the register is used as an argument for a register param that is the same register) - cx16.vaddr(lsb(cx16.r1), cx16.r0, 0, 1) - txt.print("hello") } }