diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index b34600567..d3e1184f1 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -585,14 +585,22 @@ internal class AstChecker(private val program: Program, checkMultiAssignment(assignment, fcall, fcallTarget) } else if(fcallTarget!=null) { if(fcallTarget.returntypes.size!=1) { - errors.err("number of assignment targets doesn't match number of return values from the subroutine", fcall.position) - return + return numberOfReturnValuesError(1, fcallTarget.returntypes, fcall.position) } } super.visit(assignment) } + private fun numberOfReturnValuesError(actual: Int, expectedTypes: List, position: Position) { + if(actual val (returnType, target) = p diff --git a/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt index 7d1d1088a..765652734 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt @@ -27,6 +27,15 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter, errors.warn("name '$name' shadows the definition at ${existing.position.file} line ${existing.position.line}", position) } + private fun invalidNumberOfArgsError(pos: Position, numArgs: Int, params: List) { + if(numArgs { @@ -174,7 +183,7 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter, val expectedNumberOfArgs: Int = func.parameters.size if(call.args.size != expectedNumberOfArgs) { val pos = (if(call.args.any()) call.args[0] else (call as Node)).position - errors.err("invalid number of arguments", pos) + invalidNumberOfArgsError(pos, call.args.size, func.parameters.map {it.name }) } if(target.name=="memory") { val name = call.args[0] as? StringLiteral diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 30fc7523b..315082023 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,12 +3,6 @@ TODO Regenerate skeleton doc files. -"invalid number of arguments" -> print the list of missing arguments - -callfar() should allow setting an argument in the X register as well? - -Add a new SublimeText syntax file for prog8, and also install this for bat: https://github.com/sharkdp/bat?tab=readme-ov-file#adding-new-syntaxes--language-definitions - Improve register load order in subroutine call args assignments: in certain situations, the "wrong" order of evaluation of function call arguments is done which results in overwriting registers that already got their value, which requires a lot of stack juggling (especially on plain 6502 cpu!) @@ -17,8 +11,9 @@ Maybe this routine can be made more intelligent. See usesOtherRegistersWhileEva Future Things and Ideas ^^^^^^^^^^^^^^^^^^^^^^^ -Compiler: +- Add a new SublimeText syntax file for prog8, and also install this for bat: https://github.com/sharkdp/bat?tab=readme-ov-file#adding-new-syntaxes--language-definitions +- callfar() should allow setting an argument in the X register as well? - AST weirdness: why is call(...) a normal FunctionCallStatement and not a BuiltinFunctionCall? What does ror() produce for instance? - Can we support signed % (remainder) somehow? - Don't add "random" rts to %asm blocks but instead give a warning about it? (but this breaks existing behavior that others already depend on... command line switch? block directive?) diff --git a/examples/test.p8 b/examples/test.p8 index 5ad16997f..ac9bfdfd8 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,48 +1,19 @@ %import textio -%import string -%import compression -%import test_stack %zeropage basicsafe %option no_sysinit main { sub start() { - test_stack.test() + cx16.r0L = returns3() + cx16.r0L, cx16.r1L, cx16.r2L, cx16.r3L = returns3() + txt.print_uwhex() + txt.print_uwhex(1, true, 2, 3) + } - txt.print_uwhex(cbm.CHROUT, true) - txt.print_uwhex(&cbm.CHROUT, true) - txt.nl() - - cx16.r0 = &function1 - callfar(0, $ffd2, $0031) - callfar(0, cbm.CHROUT, $000d) - callfar(0, function1, $6660) - callfar(0, cx16.r0, $ffff) - cx16.r0 -=10 - callfar(0, cx16.r0+10, $eeee) - - cx16.r0 = &function2 - callfar(0, $ffd2, $0032) - callfar(0, cbm.CHROUT, $000d) - callfar(0, function2, $6660) - callfar(0, cx16.r0, $ffff) - cx16.r0 -=10 - callfar(0, cx16.r0+10, $eeee) - - test_stack.test() - cx16.r0++ - - sub function1(uword arg) { - txt.print("function 1 arg=") - txt.print_uwhex(arg, false) - txt.nl() - } - - sub function2(uword arg) { - txt.print("function 2 arg=") - txt.print_uwhex(arg, false) - txt.nl() - } + asmsub returns3() -> ubyte @A, ubyte @X, bool @Pc { + %asm {{ + rts + }} } }