mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-11 12:29:46 +00:00
Better error messages for arays without sizes
This commit is contained in:
parent
97c7d0ffed
commit
dc087ed887
41
src/main/scala/millfork/env/Environment.scala
vendored
41
src/main/scala/millfork/env/Environment.scala
vendored
@ -1832,28 +1832,31 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
|||||||
if (stmt.const && stmt.address.isEmpty) {
|
if (stmt.const && stmt.address.isEmpty) {
|
||||||
log.error(s"Constant array `${stmt.name}` without contents nor address", stmt.position)
|
log.error(s"Constant array `${stmt.name}` without contents nor address", stmt.position)
|
||||||
}
|
}
|
||||||
stmt.length match {
|
val l = stmt.length match {
|
||||||
case None => log.error(s"Array `${stmt.name}` without size nor contents", stmt.position)
|
case None =>
|
||||||
case Some(l) =>
|
log.error(s"Array `${stmt.name}` without size nor contents", stmt.position)
|
||||||
// array arr[...]
|
LiteralExpression(1,1)
|
||||||
val address = stmt.address.map(a => eval(a).getOrElse(log.fatal(s"Array `${stmt.name}` has non-constant address", stmt.position)))
|
case Some(l) => l
|
||||||
val (indexType, lengthConst) = l match {
|
}
|
||||||
case VariableExpression(name) =>
|
// array arr[...]
|
||||||
maybeGet[Type](name) match {
|
val address = stmt.address.map(a => eval(a).getOrElse(log.fatal(s"Array `${stmt.name}` has non-constant address", stmt.position)))
|
||||||
case Some(typ@EnumType(_, Some(count))) =>
|
val (indexType, lengthConst) = l match {
|
||||||
typ -> NumericConstant(count, Constant.minimumSize(count))
|
case VariableExpression(name) =>
|
||||||
case Some(typ) =>
|
maybeGet[Type](name) match {
|
||||||
log.error(s"Type $name cannot be used as an array index", l.position)
|
case Some(typ@EnumType(_, Some(count))) =>
|
||||||
w -> Constant.Zero
|
typ -> NumericConstant(count, Constant.minimumSize(count))
|
||||||
case _ =>
|
case Some(typ) =>
|
||||||
val constant = eval(l).getOrElse(errorConstant(s"Array `${stmt.name}` has non-constant length", Some(l), stmt.position))
|
log.error(s"Type $name cannot be used as an array index", l.position)
|
||||||
w -> constant
|
w -> Constant.Zero
|
||||||
}
|
|
||||||
case _ =>
|
case _ =>
|
||||||
val constant = eval(l).getOrElse(errorConstant(s"Array `${stmt.name}` has non-constant length", Some(l), stmt.position))
|
val constant = eval(l).getOrElse(errorConstant(s"Array `${stmt.name}` has non-constant length", Some(l), stmt.position))
|
||||||
w -> constant
|
w -> constant
|
||||||
}
|
}
|
||||||
lengthConst match {
|
case _ =>
|
||||||
|
val constant = eval(l).getOrElse(errorConstant(s"Array `${stmt.name}` has non-constant length", Some(l), stmt.position))
|
||||||
|
w -> constant
|
||||||
|
}
|
||||||
|
lengthConst match {
|
||||||
case NumericConstant(length, _) =>
|
case NumericConstant(length, _) =>
|
||||||
if (length > 0xffff || length < 0) log.error(s"Array `${stmt.name}` has invalid length", stmt.position)
|
if (length > 0xffff || length < 0) log.error(s"Array `${stmt.name}` has invalid length", stmt.position)
|
||||||
val alignment = stmt.alignment.getOrElse(defaultArrayAlignment(options, length))
|
val alignment = stmt.alignment.getOrElse(defaultArrayAlignment(options, length))
|
||||||
@ -1902,7 +1905,7 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
|||||||
}
|
}
|
||||||
case _ => log.error(s"Array `${stmt.name}` has weird length", stmt.position)
|
case _ => log.error(s"Array `${stmt.name}` has weird length", stmt.position)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case Some(contents1) =>
|
case Some(contents1) =>
|
||||||
val contents = extractArrayContents(contents1)
|
val contents = extractArrayContents(contents1)
|
||||||
val indexType = stmt.length match {
|
val indexType = stmt.length match {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user