1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-02-05 09:32:59 +00:00

Early name check improvements

This commit is contained in:
Karol Stasiak 2018-01-20 02:04:58 +01:00
parent ba9e1b6475
commit 8d818f7624
3 changed files with 38 additions and 1 deletions

View File

@ -705,6 +705,22 @@ class Environment(val parent: Option[Environment], val prefix: String) {
def nameCheck(node: Node): Unit = node match {
case _:AssemblyStatement => ()
case _:DeclarationStatement => ()
case s:BlockStatement => nameCheck(s.body)
case s:ForStatement =>
checkName[Variable]("Variable", s.variable, s.position)
nameCheck(s.start)
nameCheck(s.end)
nameCheck(s.body)
case s:IfStatement =>
nameCheck(s.condition)
nameCheck(s.thenBranch)
nameCheck(s.elseBranch)
case s:WhileStatement =>
nameCheck(s.condition)
nameCheck(s.body)
case s:DoWhileStatement =>
nameCheck(s.body)
nameCheck(s.condition)
case s:Statement => nameCheck(s.getAllExpressions)
case _:LiteralExpression => ()
case VariableExpression(name) =>

View File

@ -16,6 +16,26 @@ class BasicSymonTest extends FunSuite with Matchers {
""".stripMargin)
}
test("Panic test") {
EmuUnoptimizedRun(
"""
| byte output @$c000
| void main () {
| panic()
| }
| inline asm void panic() {
| JSR _panic
| }
| void _panic() {
| asm {
| JSR doNothing
| }
| output = 1
| }
| void doNothing() { }
""".stripMargin).readByte(0xc000) should equal(1)
}
test("Allocation test") {
val src =
"""

View File

@ -98,7 +98,8 @@ class EmuRun(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimization],
))
ErrorReporting.hasErrors = false
ErrorReporting.verbosity = 999
val parserF = MfParser("", source + "\n void _panic(){while(true){}}", "", options)
val sourceWithPanic = if (source.contains("_panic")) source else source + "\n void _panic(){while(true){}}"
val parserF = MfParser("", sourceWithPanic, "", options)
parserF.toAst match {
case Success(unoptimized, _) =>
ErrorReporting.assertNoErrors("Parse failed")