mirror of
https://github.com/KarolS/millfork.git
synced 2024-10-09 13:57:05 +00:00
Early name check improvements
This commit is contained in:
parent
372d341763
commit
013bcd63f1
11
src/main/scala/millfork/env/Environment.scala
vendored
11
src/main/scala/millfork/env/Environment.scala
vendored
@ -694,9 +694,9 @@ class Environment(val parent: Option[Environment], val prefix: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def checkName[T <: Thing : Manifest](name: String, pos: Option[Position]): Unit = {
|
private def checkName[T <: Thing : Manifest](objType: String, name: String, pos: Option[Position]): Unit = {
|
||||||
if (maybeGet[T](name).isEmpty) {
|
if (maybeGet[T](name).isEmpty) {
|
||||||
ErrorReporting.error(s"`$name` is not defined", pos)
|
ErrorReporting.error(s"$objType `$name` is not defined", pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,9 +707,10 @@ class Environment(val parent: Option[Environment], val prefix: String) {
|
|||||||
case _:DeclarationStatement => ()
|
case _:DeclarationStatement => ()
|
||||||
case s:Statement => nameCheck(s.getAllExpressions)
|
case s:Statement => nameCheck(s.getAllExpressions)
|
||||||
case _:LiteralExpression => ()
|
case _:LiteralExpression => ()
|
||||||
case VariableExpression(name) => checkName[Thing](name, node.position)
|
case VariableExpression(name) =>
|
||||||
|
checkName[VariableLikeThing]("Variable or constant", name, node.position)
|
||||||
case IndexedExpression(name, index) =>
|
case IndexedExpression(name, index) =>
|
||||||
checkName[Thing](name, node.position)
|
checkName[IndexableThing]("Array or pointer", name, node.position)
|
||||||
nameCheck(index)
|
nameCheck(index)
|
||||||
case SeparateBytesExpression(h, l) =>
|
case SeparateBytesExpression(h, l) =>
|
||||||
nameCheck(h)
|
nameCheck(h)
|
||||||
@ -718,7 +719,7 @@ class Environment(val parent: Option[Environment], val prefix: String) {
|
|||||||
nameCheck(params.map(_._2))
|
nameCheck(params.map(_._2))
|
||||||
case FunctionCallExpression(name, params) =>
|
case FunctionCallExpression(name, params) =>
|
||||||
if (name.exists(_.isLetter) && name != "not") {
|
if (name.exists(_.isLetter) && name != "not") {
|
||||||
checkName[MangledFunction](name, node.position)
|
checkName[CallableThing]("Function or type", name, node.position)
|
||||||
}
|
}
|
||||||
nameCheck(params)
|
nameCheck(params)
|
||||||
}
|
}
|
||||||
|
19
src/main/scala/millfork/env/Thing.scala
vendored
19
src/main/scala/millfork/env/Thing.scala
vendored
@ -8,7 +8,13 @@ sealed trait Thing {
|
|||||||
def name: String
|
def name: String
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed trait Type extends Thing {
|
sealed trait CallableThing extends Thing
|
||||||
|
|
||||||
|
sealed trait VariableLikeThing extends Thing
|
||||||
|
|
||||||
|
sealed trait IndexableThing extends Thing
|
||||||
|
|
||||||
|
sealed trait Type extends CallableThing {
|
||||||
|
|
||||||
def size: Int
|
def size: Int
|
||||||
|
|
||||||
@ -87,13 +93,13 @@ case class Label(name: String) extends ThingInMemory {
|
|||||||
override def toAddress: MemoryAddressConstant = MemoryAddressConstant(this)
|
override def toAddress: MemoryAddressConstant = MemoryAddressConstant(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed trait Variable extends TypedThing
|
sealed trait Variable extends TypedThing with VariableLikeThing
|
||||||
|
|
||||||
case class BlackHole(typ: Type) extends Variable {
|
case class BlackHole(typ: Type) extends Variable {
|
||||||
override def name = "<black hole>"
|
override def name = "<black hole>"
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed trait VariableInMemory extends Variable with ThingInMemory {
|
sealed trait VariableInMemory extends Variable with ThingInMemory with IndexableThing {
|
||||||
|
|
||||||
def zeropage: Boolean
|
def zeropage: Boolean
|
||||||
}
|
}
|
||||||
@ -144,7 +150,7 @@ case class InitializedMemoryVariable(name: String, address: Option[Constant], ty
|
|||||||
override def alloc: VariableAllocationMethod.Value = VariableAllocationMethod.Static
|
override def alloc: VariableAllocationMethod.Value = VariableAllocationMethod.Static
|
||||||
}
|
}
|
||||||
|
|
||||||
trait MfArray extends ThingInMemory
|
trait MfArray extends ThingInMemory with IndexableThing
|
||||||
|
|
||||||
case class UninitializedArray(name: String, sizeInBytes: Int) extends MfArray with UninitializedMemory {
|
case class UninitializedArray(name: String, sizeInBytes: Int) extends MfArray with UninitializedMemory {
|
||||||
override def toAddress: MemoryAddressConstant = MemoryAddressConstant(this)
|
override def toAddress: MemoryAddressConstant = MemoryAddressConstant(this)
|
||||||
@ -164,8 +170,7 @@ case class RelativeVariable(name: String, address: Constant, typ: Type, zeropage
|
|||||||
override def toAddress: Constant = address
|
override def toAddress: Constant = address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed trait MangledFunction extends CallableThing {
|
||||||
sealed trait MangledFunction extends Thing {
|
|
||||||
def name: String
|
def name: String
|
||||||
|
|
||||||
def returnType: Type
|
def returnType: Type
|
||||||
@ -218,7 +223,7 @@ case class NormalFunction(name: String,
|
|||||||
override def shouldGenerate = true
|
override def shouldGenerate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
case class ConstantThing(name: String, value: Constant, typ: Type) extends TypedThing
|
case class ConstantThing(name: String, value: Constant, typ: Type) extends TypedThing with VariableLikeThing with IndexableThing
|
||||||
|
|
||||||
trait ParamSignature {
|
trait ParamSignature {
|
||||||
def types: List[Type]
|
def types: List[Type]
|
||||||
|
Loading…
Reference in New Issue
Block a user