From 9200992024d9d384806a27fc53a0f2d75261b2fb Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 1 Jun 2020 23:49:25 +0200 Subject: [PATCH] slightly improved asm gen error messages --- .../src/prog8/ast/processing/AstChecker.kt | 2 +- .../target/c64/codegen/AssignmentAsmGen.kt | 21 +++++++++---------- .../target/c64/codegen/ExpressionsAsmGen.kt | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index 2018cfc62..cf8034f6e 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -849,7 +849,7 @@ internal class AstChecker(private val program: Program, if(functionCallStatement.target.nameInSource.last() in setOf("lsl", "lsr", "rol", "ror", "rol2", "ror2", "swap", "sort", "reverse")) { // in-place modification, can't be done on literals if(functionCallStatement.args.any { it !is IdentifierReference && it !is RegisterExpr && it !is ArrayIndexedExpression && it !is DirectMemoryRead }) { - errors.err("can't use that as argument to a in-place modifying function", functionCallStatement.args.first().position) + errors.err("invalid argument to a in-place modifying function", functionCallStatement.args.first().position) } } super.visit(functionCallStatement) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt index af5c60e52..608696261 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt @@ -88,7 +88,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors DataType.ARRAY_F -> { assignFromFloatConstant(assign.target, constValue.toDouble()) } - else -> throw AssemblyError("invalid array dt $arrayDt") + else -> throw AssemblyError("assignment to array: invalid array dt $arrayDt") } } else { TODO() @@ -156,7 +156,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors """) } DataType.ARRAY_F -> return false // TODO optimize? - else -> throw AssemblyError("invalid array dt $arrayDt") + else -> throw AssemblyError("assignment to array: invalid array dt $arrayDt") } return true } @@ -174,7 +174,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors when(arrayDt) { DataType.ARRAY_UB -> { if (arrayDt != DataType.ARRAY_B && arrayDt != DataType.ARRAY_UB && arrayDt != DataType.STR) - throw AssemblyError("expected byte array or string") + throw AssemblyError("assignment to array: expected byte array or string") if (assign.aug_op == "setvalue") { if (valueArrayIndex is NumericLiteralValue) asmgen.out(" ldy #${valueArrayIndex.number.toHex()}") @@ -194,7 +194,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors DataType.ARRAY_UW -> TODO() DataType.ARRAY_W -> TODO() DataType.ARRAY_F -> TODO() - else -> throw AssemblyError("invalid array dt") + else -> throw AssemblyError("assignment to array: invalid array dt") } return true } @@ -418,7 +418,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors val variablename = asmgen.asmIdentifierName(arrayExpr.identifier) val arrayDt = arrayExpr.identifier.inferType(program).typeOrElse(DataType.STRUCT) if (arrayDt != DataType.ARRAY_B && arrayDt != DataType.ARRAY_UB && arrayDt != DataType.STR) - throw AssemblyError("expected byte array or string") + throw AssemblyError("assign to memory byte: expected byte array or string source") if (arrayIndex is NumericLiteralValue) asmgen.out(" ldy #${arrayIndex.number.toHex()}") else @@ -518,7 +518,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors val variablename = asmgen.asmIdentifierName(arrayExpr.identifier) val arrayDt = arrayExpr.identifier.inferType(program).typeOrElse(DataType.STRUCT) if (arrayDt != DataType.ARRAY_B && arrayDt != DataType.ARRAY_UB && arrayDt != DataType.STR) - throw AssemblyError("expected byte array or string") + throw AssemblyError("assign to identifier: expected byte array or string source") if (arrayIndex is NumericLiteralValue) asmgen.out(" ldy #${arrayIndex.number.toHex()}") else @@ -637,7 +637,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors val variablename = asmgen.asmIdentifierName(arrayExpr.identifier) val arrayDt = arrayExpr.identifier.inferType(program).typeOrElse(DataType.STRUCT) if (arrayDt != DataType.ARRAY_W && arrayDt != DataType.ARRAY_UW) - throw AssemblyError("expected word array") + throw AssemblyError("assign to identifier: expected word array source") if (arrayIndex is NumericLiteralValue) asmgen.out(" lda #${arrayIndex.number.toHex()}") else @@ -741,7 +741,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors val variablename = asmgen.asmIdentifierName(arrayExpr.identifier) val arrayDt = arrayExpr.identifier.inferType(program).typeOrElse(DataType.STRUCT) if (arrayDt != DataType.ARRAY_F) - throw AssemblyError("expected float array") + throw AssemblyError("assign to identifier: expected float array source") if (arrayIndex is NumericLiteralValue) asmgen.out(" lda #${arrayIndex.number.toHex()}") else @@ -775,7 +775,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors } } } - else -> throw AssemblyError("invalid dt") + else -> throw AssemblyError("assignment to identifier: invalid target datatype: $targetType") } return false } @@ -1086,7 +1086,7 @@ internal class AssignmentAsmGen(private val program: Program, private val errors val variablename = asmgen.asmIdentifierName(arrayExpr.identifier) val arrayDt = arrayExpr.identifier.inferType(program).typeOrElse(DataType.STRUCT) if (arrayDt != DataType.ARRAY_B && arrayDt != DataType.ARRAY_UB && arrayDt != DataType.STR) - throw AssemblyError("expected byte array or string") + throw AssemblyError("assign to register: expected byte array or string source") if (arrayIndex is NumericLiteralValue) asmgen.out(" ldy #${arrayIndex.number.toHex()}") else @@ -1141,7 +1141,6 @@ internal class AssignmentAsmGen(private val program: Program, private val errors // old code-generation below: // eventually, all of this should have been replaced by newer more optimized code above. - private fun translateNormalAssignment(assign: Assignment) { require(assign.aug_op == null) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt index 17d6c7fe5..400c88504 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt @@ -110,7 +110,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge else -> throw AssemblyError("weird type") } } - in PassByReferenceDatatypes -> throw AssemblyError("cannot case a pass-by-reference datatypes into something else") + in PassByReferenceDatatypes -> throw AssemblyError("cannot cast pass-by-reference value into another type") else -> throw AssemblyError("weird type") } }