mirror of
https://github.com/KarolS/millfork.git
synced 2025-02-08 15:30:50 +00:00
Early name check
This commit is contained in:
parent
f8f1af287f
commit
cb5f025ea9
@ -45,6 +45,7 @@ object MlCompiler {
|
|||||||
def nextLabel(prefix: String): String = "." + prefix + "__" + labelCounter.incrementAndGet().formatted("%05d")
|
def nextLabel(prefix: String): String = "." + prefix + "__" + labelCounter.incrementAndGet().formatted("%05d")
|
||||||
|
|
||||||
def compile(ctx: CompilationContext): Chunk = {
|
def compile(ctx: CompilationContext): Chunk = {
|
||||||
|
ctx.env.nameCheck(ctx.function.code)
|
||||||
val chunk = compile(ctx, ctx.function.code)
|
val chunk = compile(ctx, ctx.function.code)
|
||||||
val prefix = (if (ctx.function.interrupt) {
|
val prefix = (if (ctx.function.interrupt) {
|
||||||
if (ctx.options.flag(CompilationFlag.EmitCmosOpcodes)) {
|
if (ctx.options.flag(CompilationFlag.EmitCmosOpcodes)) {
|
||||||
|
31
src/main/scala/millfork/env/Environment.scala
vendored
31
src/main/scala/millfork/env/Environment.scala
vendored
@ -3,7 +3,7 @@ package millfork.env
|
|||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
import millfork.{CompilationFlag, CompilationOptions}
|
import millfork.{CompilationFlag, CompilationOptions}
|
||||||
import millfork.assembly.Opcode
|
import millfork.assembly.{Opcode, OpcodeClasses}
|
||||||
import millfork.compiler._
|
import millfork.compiler._
|
||||||
import millfork.error.ErrorReporting
|
import millfork.error.ErrorReporting
|
||||||
import millfork.node._
|
import millfork.node._
|
||||||
@ -692,4 +692,33 @@ class Environment(val parent: Option[Environment], val prefix: String) {
|
|||||||
case i: ImportStatement => ()
|
case i: ImportStatement => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def checkName[T <: Thing : Manifest](name: String, pos: Option[Position]): Unit = {
|
||||||
|
if (maybeGet[T](name).isEmpty) {
|
||||||
|
ErrorReporting.error(s"`$name` is not defined", pos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def nameCheck(nodes: List[_ <:Node]): Unit = nodes.foreach(nameCheck)
|
||||||
|
|
||||||
|
def nameCheck(node: Node): Unit = node match {
|
||||||
|
case _:AssemblyStatement => ()
|
||||||
|
case _:DeclarationStatement => ()
|
||||||
|
case s:Statement => nameCheck(s.getAllExpressions)
|
||||||
|
case _:LiteralExpression => ()
|
||||||
|
case VariableExpression(name) => checkName[Thing](name, node.position)
|
||||||
|
case IndexedExpression(name, index) =>
|
||||||
|
checkName[Thing](name, node.position)
|
||||||
|
nameCheck(index)
|
||||||
|
case SeparateBytesExpression(h, l) =>
|
||||||
|
nameCheck(h)
|
||||||
|
nameCheck(l)
|
||||||
|
case SumExpression(params, _) =>
|
||||||
|
nameCheck(params.map(_._2))
|
||||||
|
case FunctionCallExpression(name, params) =>
|
||||||
|
if (name.exists(_.isLetter) && name != "not") {
|
||||||
|
checkName[MangledFunction](name, node.position)
|
||||||
|
}
|
||||||
|
nameCheck(params)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ class AssemblyOptimizationSuite extends FunSuite with Matchers {
|
|||||||
| }
|
| }
|
||||||
| a.lo:a.hi=a
|
| a.lo:a.hi=a
|
||||||
| output = a
|
| output = a
|
||||||
| couput
|
| output
|
||||||
| }
|
| }
|
||||||
| void barrier (){}
|
| void barrier (){}
|
||||||
|
|
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user