error message for too large repeat iteration count

This commit is contained in:
Irmen de Jong 2020-12-24 03:25:46 +01:00
parent 8f224afed9
commit 38a6c6a866
2 changed files with 8 additions and 1 deletions

View File

@ -365,6 +365,13 @@ internal class AstChecker(private val program: Program,
super.visit(whileLoop)
}
override fun visit(repeatLoop: RepeatLoop) {
val iterations = repeatLoop.iterations?.constValue(program)
if(iterations != null && iterations.number.toInt() > 65535)
errors.err("repeat cannot go over 65535 iterations", iterations.position)
super.visit(repeatLoop)
}
override fun visit(assignment: Assignment) {
if(assignment.value is FunctionCall) {
val stmt = (assignment.value as FunctionCall).target.targetStatement(program.namespace)

View File

@ -910,7 +910,7 @@ internal class AsmGen(private val program: Program,
}
is NumericLiteralValue -> {
val iterations = (stmt.iterations as NumericLiteralValue).number.toInt()
if(iterations<0 || iterations > 65536)
if(iterations<0 || iterations > 65535)
throw AssemblyError("invalid number of iterations")
when {
iterations == 0 -> {}