diff --git a/compiler/src/prog8/ast/AstToplevel.kt b/compiler/src/prog8/ast/AstToplevel.kt index 602890722..741cdd557 100644 --- a/compiler/src/prog8/ast/AstToplevel.kt +++ b/compiler/src/prog8/ast/AstToplevel.kt @@ -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): 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 diff --git a/docs/source/todo.rst b/docs/source/todo.rst index ca7b72a94..fadad5e4c 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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? diff --git a/examples/test.p8 b/examples/test.p8 index 6e4d53e02..cf174ce28 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -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