compiler error for duplicate when choice labels

This commit is contained in:
Irmen de Jong 2021-02-21 21:26:15 +01:00
parent 00d735249b
commit 5540482888
3 changed files with 22 additions and 13 deletions

View File

@ -1141,12 +1141,18 @@ internal class AstChecker(private val program: Program,
val conditionType = whenStatement.condition.inferType(program).typeOrElse(DataType.STRUCT) val conditionType = whenStatement.condition.inferType(program).typeOrElse(DataType.STRUCT)
if(conditionType !in IntegerDatatypes) if(conditionType !in IntegerDatatypes)
errors.err("when condition must be an integer value", whenStatement.position) errors.err("when condition must be an integer value", whenStatement.position)
val choiceValues = whenStatement.choiceValues(program) val tally = mutableSetOf<Int>()
val occurringValues = choiceValues.map {it.first} for((choices, choiceNode) in whenStatement.choiceValues(program)) {
val tally = choiceValues.associate { it.second to occurringValues.count { ov->it.first==ov} } if(choices!=null) {
tally.filter { it.value>1 }.forEach { for (c in choices) {
errors.err("choice value occurs multiple times", it.key.position) if(c in tally)
errors.err("choice value already occurs earlier", choiceNode.position)
else
tally.add(c)
}
}
} }
if(whenStatement.choices.isEmpty()) if(whenStatement.choices.isEmpty())
errors.err("empty when statement", whenStatement.position) errors.err("empty when statement", whenStatement.position)

View File

@ -2,8 +2,6 @@
TODO TODO
==== ====
- compiler error for double when labels
- add sound to the cx16 tehtriz - add sound to the cx16 tehtriz
- add const arrays and cost strings - add const arrays and cost strings

View File

@ -6,14 +6,19 @@ main {
; $1F9C0 - $1F9FF PSG registers ; $1F9C0 - $1F9FF PSG registers
sub init(uword addr, ubyte length) {
@(addr+length) = $ea
}
sub start() { sub start() {
init($4000, 0) ubyte xx=33
txt.print_uwhex(@($4000), true) when xx {
1 -> {
}
2 -> {
}
else -> {
}
else -> {
}
}
; uword freq = 1181 ; uword freq = 1181
; cx16.vpoke(1, $f9c0, lsb(freq)) ; cx16.vpoke(1, $f9c0, lsb(freq))