mirror of
https://github.com/irmen/prog8.git
synced 2024-09-08 10:55:08 +00:00
improved scanning for return statement in routines that should return a value.
This commit is contained in:
parent
1c2e6f9e4c
commit
ee1c43ca91
@ -178,7 +178,7 @@ _found sty P8ZP_SCRATCH_B1
|
|||||||
|
|
||||||
asmsub compare(uword string1 @R0, uword string2 @AY) clobbers(Y) -> byte @A {
|
asmsub compare(uword string1 @R0, uword string2 @AY) clobbers(Y) -> byte @A {
|
||||||
; Compares two strings for sorting.
|
; Compares two strings for sorting.
|
||||||
; Returns -1 (255), 0 or 1 depeding on wether string1 sorts before, equal or after string2.
|
; Returns -1 (255), 0 or 1 depending on wether string1 sorts before, equal or after string2.
|
||||||
; Note that you can also directly compare strings and string values with eachother using
|
; Note that you can also directly compare strings and string values with eachother using
|
||||||
; comparison operators ==, < etcetera (it will use strcmp for you under water automatically).
|
; comparison operators ==, < etcetera (it will use strcmp for you under water automatically).
|
||||||
%asm {{
|
%asm {{
|
||||||
|
@ -196,6 +196,28 @@ internal class AstChecker(private val program: Program,
|
|||||||
super.visit(label)
|
super.visit(label)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun hasReturnOrJump(scope: INameScope): Boolean {
|
||||||
|
class Searcher: IAstVisitor
|
||||||
|
{
|
||||||
|
var count=0
|
||||||
|
|
||||||
|
override fun visit(returnStmt: Return) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
override fun visit(jump: Jump) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val s=Searcher()
|
||||||
|
for(stmt in scope.statements) {
|
||||||
|
stmt.accept(s)
|
||||||
|
if(s.count>0)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return s.count > 0
|
||||||
|
}
|
||||||
|
|
||||||
override fun visit(subroutine: Subroutine) {
|
override fun visit(subroutine: Subroutine) {
|
||||||
fun err(msg: String) = errors.err(msg, subroutine.position)
|
fun err(msg: String) = errors.err(msg, subroutine.position)
|
||||||
|
|
||||||
@ -218,7 +240,7 @@ internal class AstChecker(private val program: Program,
|
|||||||
|
|
||||||
// subroutine must contain at least one 'return' or 'goto'
|
// subroutine must contain at least one 'return' or 'goto'
|
||||||
// (or if it has an asm block, that must contain a 'rts' or 'jmp' or 'bra')
|
// (or if it has an asm block, that must contain a 'rts' or 'jmp' or 'bra')
|
||||||
if(subroutine.statements.count { it is Return || it is Jump } == 0) {
|
if(!hasReturnOrJump(subroutine)) {
|
||||||
if (subroutine.amountOfRtsInAsm() == 0) {
|
if (subroutine.amountOfRtsInAsm() == 0) {
|
||||||
if (subroutine.returntypes.isNotEmpty()) {
|
if (subroutine.returntypes.isNotEmpty()) {
|
||||||
// for asm subroutines with an address, no statement check is possible.
|
// for asm subroutines with an address, no statement check is possible.
|
||||||
|
@ -7,16 +7,22 @@
|
|||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte xx=existing_entry(1,2)
|
ubyte num_entries
|
||||||
|
|
||||||
|
num_entries = 10
|
||||||
|
ubyte ix
|
||||||
|
for ix in (num_entries-1)*2 downto 0 step -2 {
|
||||||
|
txt.print_ub(ix)
|
||||||
|
txt.spc()
|
||||||
}
|
}
|
||||||
|
|
||||||
; TODO FIX COMPILER ERROR ABOUT MISSING RETURN
|
txt.nl()
|
||||||
|
num_entries = 10
|
||||||
sub existing_entry(ubyte hash, uword symbol) -> ubyte {
|
for ix in num_entries-1 downto 0 {
|
||||||
if hash>10
|
txt.print_ub(ix*2)
|
||||||
return 44
|
txt.spc()
|
||||||
else
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user