mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 08:29:25 +00:00
check for non-executed statements in main block
This commit is contained in:
parent
c1204b83bd
commit
d305a44557
@ -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
|
||||
}
|
||||
|
@ -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?
|
||||
|
Loading…
Reference in New Issue
Block a user