diff --git a/compiler/examples/test.p8 b/compiler/examples/test.p8 index 544278a31..e58a62e13 100644 --- a/compiler/examples/test.p8 +++ b/compiler/examples/test.p8 @@ -4,12 +4,10 @@ ~ main { - c64.TIME_HI=1 ; @todo WARNING about 'free' statements in main - c64.TIME_MID=0 - c64.TIME_LO=0 - ;c64scr.PLOT(screenx(x), screeny(y)) ; @todo fix argument calculation???!!! + ; @todo unify the type cast functions... "wrd(5)" -> "5 as word" + sub toscreenx(float x, float z) -> word { return 42 } diff --git a/compiler/src/prog8/ast/AstChecker.kt b/compiler/src/prog8/ast/AstChecker.kt index 134bfac5f..05633bb42 100644 --- a/compiler/src/prog8/ast/AstChecker.kt +++ b/compiler/src/prog8/ast/AstChecker.kt @@ -80,6 +80,25 @@ class AstChecker(private val namespace: INameScope, checkResult.add(SyntaxError("program entrypoint subroutine can't have parameters and/or return values", startSub.position)) } + if(mainBlock!=null) { + // the main module cannot contain 'regular' statements (they will never be executed!) + for (statement in mainBlock.statements) { + val ok = when(statement) { + is Block->true + is Directive->true + is Label->true + is VarDecl->true + is InlineAssembly->true + is INameScope->true + else->false + } + if(!ok) { + checkResult.add(SyntaxError("main block contains regular statements, this is not allowed (they'll never get executed). Use subroutines.", statement.position)) + break + } + } + } + // there can be an optional 'irq' block with a 'irq' subroutine in it, // which will be used as the 60hz irq routine in the vm if it's present. val irqBlock = module.statements.singleOrNull { it is Block && it.name=="irq" } as? Block?