Forum
ELSE issue? (*solved*) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: ELSE issue? (*solved*) (/showthread.php?tid=316)



ELSE issue? (*solved*) - LTee - 02-23-2011

Have you had enough of me yet? :-D

I'm having a weird issue with ELSE, but I'm not sure if I'm doing something wrong or not. Take a look at this test program:
Code:
dim num as ubyte

cls
num = 1
test()
num = 2
test()
num = 3
test()
num = 4
test ()

sub test
    IF num = 1 THEN
        PRINT "1"
    ELSEIF num = 2 THEN
        PRINT "2"
    ELSEIF num = 3 THEN
        PRINT "3"
    ELSE
        PRINT "X"
    END IF
    PRINT "---"
end sub

I would expect the output from this to be like this:
Code:
1
---
2
---
3
---
X
---

But it's actually like this:
Code:
1
---
2
---
3
X
---
X
---

Condition "3" is running correctly, but the final ELSE block is also being processed so you get two lines output if num is 3. Have I messed up the syntax there? The behaviour is certainly different to how it used to be, as an old program that used to be okay is now failing.

I've tried this in 2100 and also 1866 and it does the same in both, so it must've been a while since I compiled it! :-)


Re: ELSE issue? - boriel - 02-23-2011

It's another, and this one is related to the ELSEIF sentence (not very tested sorry). This is really an important one. Let me fix it... and again, thanks! :oops:


Re: ELSE issue? - LTee - 02-24-2011

I'll try not to find anything else today. :-D


Re: ELSE issue? - boriel - 02-24-2011

I've located the bug. But this one is harder to fix. :oops: (still working on it...)


Re: ELSE issue? - boriel - 02-24-2011

Ok, seems to be fixed now. Please, download 1.2.7-r2105, as always, from the Download page and check, please. :roll:


Re: ELSE issue? - LTee - 02-25-2011

Looking good! All the tests I've run so far have worked great.

Great work as usual, boriel - thanks! :-)


Re: ELSE issue? (*solved*) - boriel - 02-25-2011

Thanks! So should we release 1.2.7 final and go for 1.2.8 (e.g. Dynamic arrays or read/data/restore or whatever new feature?)


Re: ELSE issue? (*solved*) - LTee - 02-28-2011

I certainly don't have any more problems at the moment, and the ones I have had have been pretty obscure (apart from the -Z thing, he he). All seems good for a release from my point of view.


Re: ELSE issue? (*solved*) - boriel - 02-28-2011

LTee Wrote:I certainly don't have any more problems at the moment, and the ones I have had have been pretty obscure (apart from the -Z thing, he he). All seems good for a release from my point of view.
Done. Latest 1.2.7 release fixes a bug with DRAW and OVER 1.

I've started 1.2.8 and, again, it will be a major code refactorization (headed towards 2.x release). In this release, I think I could introduce dynamic arrays, or probably READ/DATA/RESTORE and GOTO/GOSUB <variables>...
But currently 1.2.8 just does the same 1.2.7 does (Just rearranged yesterday some objects and files). Let's hope... it works :|


Re: ELSE issue? (*solved*) - LTee - 02-28-2011

Will download and test asap. :-)


Re: ELSE issue? (*solved*) - LTee - 02-28-2011

Everything seems to be compiling and running okay with the release 1.2.7!

Just one minor difference I can see, and I'm not sure what the implications of this are. When I compile the project that requires -Z, I now get an extra 'WARNING' from the compiler, which is this:
Code:
alloc.bas:73: warning: FUNCTION 'reallocate' declared as FASTCALL with 2 parameters

The Wiki says that FASTCALL functions can only have a single parameter, and sure enough 'reallocate' in alloc.bas has two parameters. This doesn't seem to affect anything in my program, but is this a problem? I note that in the previous build the function was the same, but the warning wasn't generated. :-D


Re: ELSE issue? (*solved*) - boriel - 02-28-2011

LTee Wrote:Everything seems to be compiling and running okay with the release 1.2.7!

Just one minor difference I can see, and I'm not sure what the implications of this are. When I compile the project that requires -Z, I now get an extra 'WARNING' from the compiler, which is this:
Code:
alloc.bas:73: warning: FUNCTION 'reallocate' declared as FASTCALL with 2 parameters

The Wiki says that FASTCALL functions can only have a single parameter, and sure enough 'reallocate' in alloc.bas has two parameters. This doesn't seem to affect anything in my program, but is this a problem? I note that in the previous build the function was the same, but the warning wasn't generated. :-D
Yes, that's ok.
This is because if you're using -Z the compiler ALLOCates 21*8 = 168 bytes for UDG in the heap, and updates system variable UDG (23675) to point to that address. If you don't do this, you can surely use POKE USR "a", ... to create UDG (the legacy way), but this can corrupt the heap (which now also maps into that memory space).


Re: ELSE issue? (*solved*) - LTee - 03-01-2011

Cool, thanks for the reply. All systems are GO, then! :-)