This is a fix for scripting where the compiler will now correctly handle that a constant exists.
There is no change to the scope - it is that IF CONSTANT or IF DEF(CONSTANT) now works are expected. This has been a very long standing issue.
The following code shows the issue. The existence of the MYNONEXISTANTCONSTANT is ignore in the existing compiler. The result is that SCRIPTNUMBER in the ASM will always be 2 - regardless if MYNONEXISTANTCONSTANT is defined or not.
As this is a huge change to the compiler there is a need to disable if this causes issues. Add the following constant to the program to disable this change - then report via the forum. What will go wrong? Dunno.... but, someone may have write a script that has been passive up to now that will suddenly burst into life.
To disable, add
#DEFINE DISABLECHANGE1042
Enjoy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been asked of show the working commands. This code shows the commands in the code below show the use
Case 1: IF and IF DEF() are the same operation
Case 2: IF NOTDEF() has no other equivalent
Example is code - change the chip to see the difference.
#chip16f88'#chipmega328p#SCRIPTifNODEF(PIC)thenwarning"Not a PIC"endififPICthenwarning"PIC using IF"endififDEF(PIC)thenwarning"PIC using IF DEF()"endififNODEF(AVR)thenwarning"Not an AVR"endififAVRthenwarning"AVR using IF"endififDEF(AVR)thenwarning"AVR using IF DEF()"endif#ENDSCRIPT
Enjoy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
IF CONSTANT or IF DEF(CONSTANT) now works are expected. This has been a very long standing issue.
Again, not bothered me. I use gcb in like simple mode. The problems that have been sorted I never found. Maybe I was lucky I never found the problems. If var suits me. What's the difference between a defined constant and a dimmed var? ie a dimmed var stays constant unless changed. Is this a different topic?
It's like sinclair basic vs bbc basic... if that's when you first learned "basic"... then there's commodore basic. It's what you could afford at the time. MS basic wasn't around until pc's like amstrad. Forgot amstrad 464 basic. :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Stan, you are totally right. This is a library developer issue that is fixed. Before the fix there were many hoops we had to implement to understand if a constant existed.
So, your points are totally valid for most users.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
An observation. It seems that the existence of a constant can only be tested IF the constant has a null value.
'--- This Works as Expected ---#DEFINE MYCONSTANT#ScriptIFMYCONSTANTthenWarning"MYCONSTANT DEFINED"ENDIF#ENDSCRIPT'----------------------------'--- This does *NOT* Work as expected#DEFINE MYCONSTANT 0#ScriptIFMYCONSTANTthenWarning"MYCONSTANT DEFINED"ENDIF#ENDSCRIPT'----------------------------'If the constant is not a Null value then'existence cannot be tested for
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This also does not work as expected. "MyConstant" clearly exists and is defined with a value of 255. However the script determines that MyConstant is NOT defined.
'---Thisdoes*NOT*Workasexpected#DEFINEMYCONSTANT255#ScriptIFNODEF(MYCONSTANT)thenWarning"MYCONSTANT NOT DEFINED"ENDIF#ENDSCRIPT'----------------------------
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This ensure script functions DEF() and NODEF() work as expected.
'#chip 16f88#CHIP MEGA328P#DEFINE MYCONSTANT 0#Script IF PIC Then Warning "PIC1" End IF IF AVR Then Warning "AVR1" End IF IF DEF(PIC) Then Warning "PIC2" End IF IF DEF(AVR) Then Warning "AVR2" End IF IF NODEF(PIC) Then Warning "!PIC" End IF IF NODEF(AVR) Then Warning "!AVR" End IF IF MYCONSTANT then Warning "MYCONSTANT EXISTS1" Warning "MYCONSTANT value = "MYCONSTANT END IF IF DEF(MYCONSTANT) then Warning "MYCONSTANT EXISTS2" Warning "DEF(MYCONSTANT) value = "MYCONSTANT END IF IF NODEF(MYCONSTANT) then Warning "MYCONSTANT DOES NOT EXIST" END IF Warning "end"#ENDSCRIPT
Yields - which means a script can now detect constants.
This is a fix for scripting where the compiler will now correctly handle that a constant exists.
There is no change to the scope - it is that
IF CONSTANT
or IF DEF(CONSTANT) now works are expected. This has been a very long standing issue.The following code shows the issue. The existence of the MYNONEXISTANTCONSTANT is ignore in the existing compiler. The result is that SCRIPTNUMBER in the ASM will always be 2 - regardless if MYNONEXISTANTCONSTANT is defined or not.
The new compiler build #1042 resolves.
As this is a huge change to the compiler there is a need to disable if this causes issues. Add the following constant to the program to disable this change - then report via the forum. What will go wrong? Dunno.... but, someone may have write a script that has been passive up to now that will suddenly burst into life.
To disable, add
Enjoy
I have been asked of show the working commands. This code shows the commands in the code below show the use
Case 1: IF and IF DEF() are the same operation
Case 2: IF NOTDEF() has no other equivalent
Example is code - change the chip to see the difference.
Enjoy
IF CONSTANT or IF DEF(CONSTANT) now works are expected. This has been a very long standing issue.
Again, not bothered me. I use gcb in like simple mode. The problems that have been sorted I never found. Maybe I was lucky I never found the problems. If var suits me. What's the difference between a defined constant and a dimmed var? ie a dimmed var stays constant unless changed. Is this a different topic?
It's like sinclair basic vs bbc basic... if that's when you first learned "basic"... then there's commodore basic. It's what you could afford at the time. MS basic wasn't around until pc's like amstrad. Forgot amstrad 464 basic. :)
Stan, you are totally right. This is a library developer issue that is fixed. Before the fix there were many hoops we had to implement to understand if a constant existed.
So, your points are totally valid for most users.
An observation. It seems that the existence of a constant can only be tested IF the constant has a null value.
Good spot. Needs to be sorted out.
This also does not work as expected. "MyConstant" clearly exists and is defined with a value of 255. However the script determines that MyConstant is NOT defined.
should that not read
IF NDEF rather than IF NODEF
I am not near a copy of GCBASIC to test so just an observation.
Last edit: Chris Roper 2021-10-13
It is NODEF. :-)
Somewhat related ....
If #ENDSCRIPT is missing from the script construct ... G+Stools hangs instead of issuing an error or warning.
#ENDSCRIPT
issued fixed in build 1043Evan
Update SCRIPT capability in build 1045.
This ensure script functions DEF() and NODEF() work as expected.
Yields - which means a script can now detect constants.