From c40fc584d6fc0983ec05e9b1df008daf7aba7813 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 21 Nov 2018 22:07:13 +0100 Subject: [PATCH] added warning about using X as sub parameter --- compiler/examples/test.p8 | 37 +++++++++++----------------- compiler/src/prog8/ast/AstChecker.kt | 5 ++++ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/compiler/examples/test.p8 b/compiler/examples/test.p8 index cebdae339..bcebb40aa 100644 --- a/compiler/examples/test.p8 +++ b/compiler/examples/test.p8 @@ -16,33 +16,24 @@ sub start() { byte b1 - ;v1=foo() + address =c64.MEMBOT(1, 40000.w) ; ok! + address =c64.MEMBOT(1, address) ; ok! + address =c64.MEMBOT(1, memaddr) ; ok! - ;address =c64.MEMBOT(1, 40000.w) ; ok! - ;address =c64.MEMBOT(1, address) ; ok! - ;address =c64.MEMBOT(1, memaddr) ; ok!i - ;address =c64.MEMBOT(1, wordarray[1]) ; @todo nice error about loading X register from stack - - ;A, Y =c64.GETADR() ; ok! - ;Y, A =c64.GETADR() ; ok! - ;address = c64flt.GETADRAY() ; ok! - ;memaddr = c64flt.GETADRAY() ; ok! - ;wordarray[1] = c64flt.GETADRAY() ; ok! - ;v1, v2 =c64.GETADR() ; ok! - ;address =c64.IOBASE() ; ok! - ;A = c64.CHRIN() ; ok ! - ;X = c64.CHRIN() ; ok ! - ;Y = c64.CHRIN() ; ok! - ;v1 = c64.CHRIN() ; ok ! + A, Y =c64.GETADR() ; ok! + Y, A =c64.GETADR() ; ok! + address = c64flt.GETADRAY() ; ok! + memaddr = c64flt.GETADRAY() ; ok! + wordarray[1] = c64flt.GETADRAY() ; ok! + v1, v2 =c64.GETADR() ; ok! + address =c64.IOBASE() ; ok! + A = c64.CHRIN() ; ok ! + X = c64.CHRIN() ; ok ! + Y = c64.CHRIN() ; ok! + v1 = c64.CHRIN() ; ok ! return } -sub foo() -> float { - return 1 ; @todo fix error: '1' as byte or float literal (not ubyte) -} - - - } diff --git a/compiler/src/prog8/ast/AstChecker.kt b/compiler/src/prog8/ast/AstChecker.kt index fd90973b9..6b108ff01 100644 --- a/compiler/src/prog8/ast/AstChecker.kt +++ b/compiler/src/prog8/ast/AstChecker.kt @@ -693,6 +693,11 @@ class AstChecker(private val namespace: INameScope, for (arg in args.withIndex().zip(target.parameters)) { if(arg.first.value.resultingDatatype(namespace, heap) != arg.second.type) checkResult.add(ExpressionError("argument ${arg.first.index+1} has invalid type, expected ${arg.second.type}", position)) + + if(target.asmParameterRegisters[arg.first.index].registerOrPair in setOf(RegisterOrPair.AX, RegisterOrPair.XY, RegisterOrPair.X)) { + if(arg.first.value !is LiteralValue && arg.first.value !is IdentifierReference) + printWarning("calling a subroutine that expects X as a parameter is problematic, more so when providing complex arguments. If you see a compiler error/crash about this later, try to simplify this call", position) + } } } }