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)
if(conditionType !in IntegerDatatypes)
errors.err("when condition must be an integer value", whenStatement.position)
val choiceValues = whenStatement.choiceValues(program)
val occurringValues = choiceValues.map {it.first}
val tally = choiceValues.associate { it.second to occurringValues.count { ov->it.first==ov} }
tally.filter { it.value>1 }.forEach {
errors.err("choice value occurs multiple times", it.key.position)
val tally = mutableSetOf<Int>()
for((choices, choiceNode) in whenStatement.choiceValues(program)) {
if(choices!=null) {
for (c in choices) {
if(c in tally)
errors.err("choice value already occurs earlier", choiceNode.position)
else
tally.add(c)
}
}
}
if(whenStatement.choices.isEmpty())
errors.err("empty when statement", whenStatement.position)

View File

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

View File

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