If I added that line and compiled it in an older (Mac) version tomorrow would it prove (or not) the same thing?
I've got to make some changes to the program tomorrow for a one off version of the hardware I built up and installed in a cabinet today. The 'original' version compiled as normal earlier on when I was working on it though.
If not, I'm really sorry, but I don't think I can.
The program this is for is a work project. My work 'PC' is still an iMac and it is running an older version of GCB than I have here. I'm no longer able to compile any GCB compiler for the Mac as I no longer have an iMac at home. That program just happened to open in SynWrite after the installer finished, and I attempted to compile it to see if the update had worked.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Looks like a variable issue when declaring the variable in a sub.
This seems to work OK. Declare the variable first outside of the sub
'Initalize the "reduce" variable here first and also in SubDimreduceasintegerReduce=0CallDoCountDownSub(100,-2)DoLoopSubDoCountDownSub(StartAsWord,ReduceAsInteger)DimLoopCntasWordIfStart>9999ThenLetStart=9999EndIfForLoopCnt=Startto0StepReduce'Do not negate reduceHserprintLoopCntHserprintCRLFNextEndSub
I'm using the 'ReduceVal' value in a few places where it is normally required to be a positive value.
So could I do this?
'Initalize the "reduce" variable here first and also in SubDimReduceAsIntegerDimReduceValAsByteLetReduceVal=2LetReduce=ReduceVal*-1CallDoCountDownSub(100,Reduce)DoLoopSubDoCountDownSub(StartAsWord,ReduceAsInteger)'Reduce has a negative integer valueDimLoopCntasWordIfStart>9999ThenLetStart=9999EndIfForLoopCnt=Startto0StepReduce'Do not negate reduce again it is already negativeHserprintLoopCntHserprintCRLFNextEndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And, this is only exists on 0.98.07 after RC 43. So, if the MAC is earlier... the error wont happen but you will have all the FOR-NEXT bugs in the legacy code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think we are heading towards a different solution as proposed by Bill Roth.
I need to maintain legacy FOR-NEXT support, and, it is essential that the new FOR-NEXT works to resolve the issues with FOR-NEXT support.
Transformation of a negated step variable is creating a mutually exclusive situation where if we support 'negated step variable' then this breaks legacy FOR-NEXT support.
The resolution is to pass an integer that has been negated in previous operations, or, pass a variable with a negative value.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Even...sir...I think you need a break!!!
You are the team leader and have undertaken stuff others would not have tried.
Take a rest mate. If it's not broken don't fix it.
It's Jack James fault... we were all happy before then :) :) joking JJ. Well spotted.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You need to have the latest build then apply these patches on top of the installation.
To install these patches:
Download the zip
unzip all files to a temp folder
apply all files to your installation replacing all the existing files
then, rename the compiler EXE for your operating system - you need to ensure either GCBASIC64.exe or GCBASIC32.exe is renamed as GCBASIC.exe
Enjoy
Using single files may make your installation unstable. Use ALL the patch files.
Root cause analysis
The root cause in the compiler was unable to transform the negated step variable in a sub-routine as the compiler assumed the variable was of type byte. Therefore, the original error message was actually correct. Shown below.
The compiler will rationalise variables as the rationalisation when negating an integer in a subroutine was reporting the step variable as byte. We could workaround this using casting and a bit of maths but that is not the way to resolve.
Resolution
Ensure a negated Step parameter is not permitted.
Ensure that the Step variable in cast as an integer.
The code at build 1008 reflects these changes.
So, you cannot negate a step value on the FOR-NEXT command. You can negate prior, you can cast, you can pass integer values there are many ways to make this work but this is no permitted.
For LoopCnt = Start to 0 Step -Reduce 'NOTE the minus sign.. not acceptable.
...
....
Next
This will issue the error Case0.gcb (35): Error: You cannot negate a step value. Negate the integer variable as a prior operation or pass a negative or positive value integer variable.
Testing of this change
I have created five program to test the change. All programs do the same. They shown the FOR-NEXT values on a serial terminal with a decrementing STEP of 2
200..198..nn..2..0
Case0 - fails as it negates the step parameter
Case1- works. Pass a byte, negate in the calling the method, with the method second parameter defined as an Integer. 542 words
Case2- works. Pass an Integer, negate in calling method with the method second parameter defined as an Integer. 544 words
Case3- works. Pass an integer... use and integer throughout, 545 words
Case4- works. Pass a byte, cast on the step parameter, this uses casting and a bit of maths. 645 words.
Case5- works. Pass an byte and do some integer maths. 546 words.
I have normalised the program when documenting the progmem size by removing the variable length string.
If I were doing this I would have used Case3 but clearly Case1 is smaller.. three words smaller.
Change log
1008: "Fix: For FOR-NEXT loop when using a negated step value. A negated step value is no longer permitted as this is cast as byte, and, the transform in preprocessor breaks legacy FOR-NEXT support. Resolution: 1) Inspect step variable type and negate is not present 2) Cast in the compiler as integer when the loop variable is an integer[1247,1248]
Considered non critical issue as use of negating was issuing a valid error message."
As I can't compile the Mac version anymore, I'm having to test this on an old compiler.
Case5 however compiles and executes correctly on 0.98.07 RC42 2021-02-27 (Darwin 64 bit)
'Start of program...DimReduceVarasIntegerLetReduceVar=-ReduceForLoopCnt=Startto0StepReduceVarShowValuesSub(LoopCnt)'Rest of loop...Next'Rest of program
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I realise that RC42 does not test the new methods, but it should make the code work within both the new and old versions.
Once I get my office 'PC' changed over to a Windows machine, I will need to rewrite portions of a large number of programs which will suddenly fail to compile. If I can at least have a road forward, I can start making those changes each time I need to compile something which uses this negative step For - Next.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And, another. This time avoiding the FOR-NEXT loop entirely. However, this is not a utility routine and code growth and variable growth would not be pretty.
And, this supports only ONE type of loop. Change the step increment to a positive, or, change the range to be a negative number.... the code falls over,
But, this does the same as the FOR-NEXT loop . The DO-LOOP is what is really going on inside the ASM for one use case. There are 34 use cases encoded in the compiler.
Case8 -Pass a byte.. create a do while loop. 546 words.
The compiler now works as intended so any additional checks are not needed. And, as with your code and Case8. They are very expensive in terms of memory and Ram.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And, the test plan for FOR-NEXT was extensive.. but, I did miss the negated STEP variable.
The PDF shows the 144 tests. The SV (start value ) type of variable/constant, EV (end value ) type of variable/constant and the StepV type, present or not, increment, decrement .
And, yes. I created 144 test programs. I have added another six today.
This FOR-NEXT discussion closed in March 2021
I can revert all the changes back in about 2 seconds. It will revert back to the broken FOR-NEXT loop.
Get involved to test and resolve the issue, or, I will revert.
https://sourceforge.net/p/gcbasic/discussion/596084/thread/59d24215/#bcf9/bd14
Sorry. I am trying to understand the issue and to help. Clearly I'm not helping, apologies again.
@mkstevo
Can you please test this ?
Start to 0 Step [INTEGER](Reduce*-1)
Does this work on real silicon ? No point in my encoding if this does not work.
Evan
If I added that line and compiled it in an older (Mac) version tomorrow would it prove (or not) the same thing?
I've got to make some changes to the program tomorrow for a one off version of the hardware I built up and installed in a cabinet today. The 'original' version compiled as normal earlier on when I was working on it though.
If not, I'm really sorry, but I don't think I can.
The program this is for is a work project. My work 'PC' is still an iMac and it is running an older version of GCB than I have here. I'm no longer able to compile any GCB compiler for the Mac as I no longer have an iMac at home. That program just happened to open in SynWrite after the installer finished, and I attempted to compile it to see if the update had worked.
Looks like a variable issue when declaring the variable in a sub.
This seems to work OK. Declare the variable first outside of the sub
Last edit: William Roth 2021-07-27
Many thanks for your suggestion.
I'm using the 'ReduceVal' value in a few places where it is normally required to be a positive value.
So could I do this?
I am trying to fix the compiler.
Did this test https://sourceforge.net/p/gcbasic/discussion/596084/thread/a56563e36f/#07d1 work? Did it increment in a negative direction ?
And, this is only exists on 0.98.07 after RC 43. So, if the MAC is earlier... the error wont happen but you will have all the FOR-NEXT bugs in the legacy code.
If you are referring to your suggestion:
I can't test this until I'm at work tomorrow, where I can only test it on my (legacy compiler) Mac.
OK. Thank you.
I think we are heading towards a different solution as proposed by Bill Roth.
I need to maintain legacy FOR-NEXT support, and, it is essential that the new FOR-NEXT works to resolve the issues with FOR-NEXT support.
Transformation of a negated step variable is creating a mutually exclusive situation where if we support 'negated step variable' then this breaks legacy FOR-NEXT support.
The resolution is to pass an integer that has been negated in previous operations, or, pass a variable with a negative value.
Even...sir...I think you need a break!!!
You are the team leader and have undertaken stuff others would not have tried.
Take a rest mate. If it's not broken don't fix it.
It's Jack James fault... we were all happy before then :) :) joking JJ. Well spotted.
Mwah Stan.
Sorry, I have been busy with work. Please send me test code and I can test on real silicon. AVR and PIC.
See the post below. https://sourceforge.net/p/gcbasic/discussion/596084/thread/a56563e36f/#b481
I have posted all the updated to SourceForge - please take a look. Anything else broken?
Revised compiler.
The intent is to resolve the FOR-NEXT-NEGATED STEP error.
Use https://sourceforge.net/projects/gcbasic/files/Release%20Candidates/Patches/ files. The source for MAC can be downloaded from https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/ please download the BAS, BI and MESSAGE.DAT
Installation
You need to have the latest build then apply these patches on top of the installation.
To install these patches:
Using single files may make your installation unstable. Use ALL the patch files.
Root cause analysis
The root cause in the compiler was unable to transform the negated step variable in a sub-routine as the compiler assumed the variable was of type byte. Therefore, the original error message was actually correct. Shown below.
The compiler will rationalise variables as the rationalisation when negating an integer in a subroutine was reporting the step variable as byte. We could workaround this using casting and a bit of maths but that is not the way to resolve.
Resolution
The code at build 1008 reflects these changes.
So, you cannot negate a step value on the FOR-NEXT command. You can negate prior, you can cast, you can pass integer values there are many ways to make this work but this is no permitted.
For LoopCnt = Start to 0 Step -Reduce 'NOTE the minus sign.. not acceptable.
...
....
Next
This will issue the error Case0.gcb (35): Error: You cannot negate a step value. Negate the integer variable as a prior operation or pass a negative or positive value integer variable.
Testing of this change
I have created five program to test the change. All programs do the same. They shown the FOR-NEXT values on a serial terminal with a decrementing STEP of 2
Case0 - fails as it negates the step parameter
Case1- works. Pass a byte, negate in the calling the method, with the method second parameter defined as an Integer. 542 words
Case2- works. Pass an Integer, negate in calling method with the method second parameter defined as an Integer. 544 words
Case3- works. Pass an integer... use and integer throughout, 545 words
Case4- works. Pass a byte, cast on the step parameter, this uses casting and a bit of maths. 645 words.
Case5- works. Pass an byte and do some integer maths. 546 words.
I have normalised the program when documenting the progmem size by removing the variable length string.
If I were doing this I would have used Case3 but clearly Case1 is smaller.. three words smaller.
Change log
1008: "Fix: For FOR-NEXT loop when using a negated step value. A negated step value is no longer permitted as this is cast as byte, and, the transform in preprocessor breaks legacy FOR-NEXT support. Resolution: 1) Inspect step variable type and negate is not present 2) Cast in the compiler as integer when the loop variable is an integer[1247,1248]
Considered non critical issue as use of negating was issuing a valid error message."
For the full list details of the changes see https://onedrive.live.com/edit.aspx?resid=2F87FFE77F3DBEC7!67634&authkey=!ADmkT3exl5l4Pkc
What a pain this was.
Enjoy
Last edit: Anobium 2021-07-28
Thanks.
As I can't compile the Mac version anymore, I'm having to test this on an old compiler.
Case5 however compiles and executes correctly on 0.98.07 RC42 2021-02-27 (Darwin 64 bit)
Old compiler at RC42 does not support the new method of FOR-NEXT loop. You will not see the error.
Please see https://sourceforge.net/p/gcbasic/discussion/596084/thread/a56563e36f/#b481 and https://sourceforge.net/p/gcbasic/discussion/596084/thread/a56563e36f/#2d23
I realise that RC42 does not test the new methods, but it should make the code work within both the new and old versions.
Once I get my office 'PC' changed over to a Windows machine, I will need to rewrite portions of a large number of programs which will suddenly fail to compile. If I can at least have a road forward, I can start making those changes each time I need to compile something which uses this negative step For - Next.
Yes. If you use the new compiler then all should work correctly.
And. it worth remembering why this FOR-NEXT change is very important.
Try the test. Case7. I simply use the legacy FOR-NEXT loop with a negated step value of 3.
Uses the legacy FOR-NEXT loop just changed the step value to a non-even number. Everything else is the same. ooppps lots and lots of loops.
This DOES NOT operate correctly.
`200,197,194,191,188,185,182,179,176,173,170,167,164,161,158,155,152,149,146,143,140,137,134,131,128,125,122,119,116,113,110,107,104,101,98,95,92,89,86,83,80,77,74,71,68,65,62,59,56,53,50,47,44,41,38,35,32,29,26,23,20,17,14,11,8,5,2,65535,65532,65529,65526,65523,65520,65517,65514,65511,65508,65505,65502,65499,65496,65493,65490,65487,65484,65481,65478,65475,65472,65469,65466,65463,65460,65457,65454,65451,65448,65445,65442,65439,65436,65433,65430,65427,65424,65421,65418,65415,65412,65409,65406,65403,65400,65397,65394,65391,65388,65385,65382,65379,65376,65373,65370,65367,65364,65361,65358,65355,65352,65349,65346,65343,65340,65337,65334,65331,65328,65325,65322,65319,65316,65313,65310,65307,65304,65301,65298,65295,65292,65289,65286,65283,65280,65277,65274,65271,65268,65265,65262,65259,65256,65253,65250,65247,65244,65241,65238,65235,65232,65229,6
lots and lots of loops
finally..
774,771,768,765,762,759,756,753,750,747,744,741,738,735,732,729,726,723,720,717,714,711,708,705,702,699,696,693,690,687,684,681,678,675,672,669,666,663,660,657,654,651,648,645,642,639,636,633,630,627,624,621,618,615,612,609,606,603,600,597,594,591,588,585,582,579,576,573,570,567,564,561,558,555,552,549,546,543,540,537,534,531,528,525,522,519,516,513,510,507,504,501,498,495,492,489,486,483,480,477,474,471,468,465,462,459,456,453,450,447,444,441,438,435,432,429,426,423,420,417,414,411,408,405,402,399,396,393,390,387,384,381,378,375,372,369,366,363,360,357,354,351,348,345,342,339,336,333,330,327,324,321,318,315,312,309,306,303,300,297,294,291,288,285,282,279,276,273,270,267,264,261,258,255,252,249,246,243,240,237,234,231,228,225,222,219,216,213,210,207,204,201,198,195,192,189,186,183,180,177,174,171,168,165,162,159,156,153,150,147,144,141,138,135,132,129,126,123,120,117,114,111,108,105,102,99,96,93,90,87,84,81,78,75,72,69,66,63,60,57,54,51,48,45,42,39,36,33,30,27,24,21,18,15,12,9,6,3,0,
`
Last edit: Anobium 2021-07-28
I'd noticed on occasions that a condition could be created where the For - Next repeated round a few times before exiting.
I put it down to my poor programming.
Down at the bottom of my For - Next I have this sanity check:
That is the old bug....coming to life
And, another. This time avoiding the FOR-NEXT loop entirely. However, this is not a utility routine and code growth and variable growth would not be pretty.
And, this supports only ONE type of loop. Change the step increment to a positive, or, change the range to be a negative number.... the code falls over,
But, this does the same as the FOR-NEXT loop . The DO-LOOP is what is really going on inside the ASM for one use case. There are 34 use cases encoded in the compiler.
Case8 -Pass a byte.. create a do while loop. 546 words.
Last edit: Anobium 2021-07-28
I was thinking last night when I couldn't sleep...
I had wondered if it wouldn't be more elegant than using a For - Next loop to instead set up a Repeat loop for the value of Start / Reduce.
Something similar to this perhaps?
The compiler now works as intended so any additional checks are not needed. And, as with your code and Case8. They are very expensive in terms of memory and Ram.
And, the test plan for FOR-NEXT was extensive.. but, I did miss the negated STEP variable.
The PDF shows the 144 tests. The SV (start value ) type of variable/constant, EV (end value ) type of variable/constant and the StepV type, present or not, increment, decrement .
And, yes. I created 144 test programs. I have added another six today.