do..until condition can now refer to variables defined in the loop's inner scope.

This commit is contained in:
Irmen de Jong 2020-09-23 23:24:32 +02:00
parent 1d1fe364d0
commit e1d0dbed0c
3 changed files with 23 additions and 3 deletions

View File

@ -137,7 +137,15 @@ interface INameScope {
}
return null
} else {
// unqualified name, find the scope the localContext is in, look in that first
// unqualified name
// special case: the do....until statement can also look INSIDE the anonymous scope
if(localContext.parent.parent is UntilLoop) {
val symbolFromInnerScope = (localContext.parent.parent as UntilLoop).body.getLabelOrVariable(scopedName[0])
if(symbolFromInnerScope!=null)
return symbolFromInnerScope
}
// find the scope the localContext is in, look in that first
var statementScope = localContext
while(statementScope !is ParentSentinel) {
val localScope = statementScope.definingScope()
@ -312,6 +320,16 @@ class GlobalNamespace(val modules: List<Module>): Node, INameScope {
}
}
}
// special case: the do....until statement can also look INSIDE the anonymous scope
if(localContext.parent.parent is UntilLoop) {
val symbolFromInnerScope = (localContext.parent.parent as UntilLoop).body.lookup(scopedName, localContext)
if(symbolFromInnerScope!=null)
return symbolFromInnerScope
}
val p1 = localContext.parent
val p2 = localContext.parent.parent
// lookup something from the module.
return when (val stmt = localContext.definingModule().lookup(scopedName, localContext)) {
is Label, is VarDecl, is Block, is Subroutine, is StructDecl -> stmt

View File

@ -4,7 +4,6 @@ TODO
- get rid of all other TODO's in the code ;-)
- line-circle-gfx examples are now a few hundred bytes larger than before (~4.0/4.1 version i think?). Why is that, can it be fixed?
- until condition should be able to refer to variables defined IN the do-until block itself.
- add support? example? for processing arguments to a sys call : sys 999, 1, 2, "aaa"
- make it possible for array literals to not only contain compile time constants
- further optimize assignment codegeneration
@ -20,6 +19,7 @@ More optimizations
Add more compiler optimizations to the existing ones.
- better assembly for comparison expressions most notably == and != (these use eval stack all the time)
- more targeted optimizations for assigment asm code, such as the following:
- subroutine calling convention? like: 1 byte arg -> pass in A, 2 bytes -> pass in A+Y, return value likewise.
- can such parameter passing to subroutines be optimized to avoid copying?

View File

@ -8,8 +8,10 @@ main $0900{
sub start() {
ubyte x= 1
do {
ubyte v = 1
ubyte v = x
x++
} until v==0
; @($c000) *= 99 ; TODO implement