better error checking for wrong pop()

This commit is contained in:
Irmen de Jong 2021-11-28 02:49:18 +01:00
parent 68b75fd558
commit 1b07637cc4
2 changed files with 14 additions and 3 deletions

View File

@ -994,9 +994,16 @@ internal class AstChecker(private val program: Program,
}
else if(funcName[0] in arrayOf("pop", "popw")) {
// can only pop into a variable, that has to have the correct type
val idref = functionCallStatement.args.singleOrNull() as? IdentifierReference
if(idref==null)
errors.err("invalid argument to pop, must be a variable with the correct type: ${functionCallStatement.args.first()}", functionCallStatement.args.first().position)
val idref = functionCallStatement.args[0]
if(idref !is IdentifierReference) {
if(idref is TypecastExpression) {
val passByRef = idref.expression.inferType(program).isPassByReference
if(idref.type!=DataType.UWORD || !passByRef)
errors.err("invalid argument to pop, must be a variable with the correct type: ${functionCallStatement.args.first()}", functionCallStatement.args.first().position)
} else {
errors.err("invalid argument to pop, must be a variable with the correct type: ${functionCallStatement.args.first()}", functionCallStatement.args.first().position)
}
}
}
if(funcName[0] in arrayOf("rol", "ror", "rol2", "ror2", "swap", "sort", "reverse")) {

View File

@ -1,14 +1,18 @@
%import textio
%import string
%import test_stack
main {
ubyte[23] savedata
ubyte[17] cargohold = 0
uword filenameptr = $c000
sub start() {
test_stack.test()
c64.SETNAM(string.length(filenameptr), filenameptr)
sys.memcopy(&savedata + 2, cargohold, len(cargohold))
sys.memcopy(cargohold, &savedata + 2, len(cargohold))