From 38a6c6a866988ae0db5cee165af1a64eeae2924a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 24 Dec 2020 03:25:46 +0100 Subject: [PATCH] error message for too large repeat iteration count --- compiler/src/prog8/ast/processing/AstChecker.kt | 7 +++++++ compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index 22418d681..e83d81820 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -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) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index b0f3ea42f..2c39c0a47 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -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 -> {}