Note: This change Build1144 does not change the behaviour of #CHIP or #DEFINE. This change is focused on the handling of conditional with the inclusion of #ELSE and #IFNOT
Implementation
The change is implemented as follows, noting many of these changes are not visible to the user but this explains the change in some detail.
The compiler reads a source line from the source program and if the source line contains any of the conditional statement the compiler now caches this source line into an array. The array is required to handle nested conditional statements. The compiler uses the array as a cache (with the source type of condition
a. #IF=2
b. #IFNOT=3
c. #IFDEF=0
d. #IFNDEF=1
If the current source line is #ELSE then the compiler replaces the #ELSE with appropriate code to enable the compiler to handle the #ELSE, as follows:
a. #ELSE when the condition is #IF – is transformed to #ENDIF & #IFNOT plus the condition
b. #ELSE when the condition is #IFNOT – is transformed to #ENDIF & #IF plus the condition
c. #ELSE when the condition is #IFDEF – is transformed to #ENDIF & #IFNDEF plus the condition
d. #ELSE when the condition is #IFNDEF – is transformed to #ENDIF & #IFDEF plus the condition
The compiler increments the array location upon each conditional statement ( #IF… ) that is nested.
The compiler decrements the array location of each #ENDIF
Where the #ELSE is transformed into #ENDIF : #IFNOT condition
A key principle of operation is changing #ELSE to #ENDIF: IF... condition. This leaves the compiler to split the new line of code using the existing split line handler to the new negated condition.
The compiler has been updated to handle #IFNOT. This means the compiler has been updates in appropriate places.
A key principle of operation is the method to support for #IFNOT. #IFNOT is treated as #IF within the compilers IFDEFs handler and using the source type attribute to negate the operation
#IFNOT is source type 3.
The #IFNOT command is transformed from #IFNOT to #IF, and, then the result of the calculation is negated - this creates #IFNOT. There are other trivial changes in IFDEFs method to recognised #IFNOT.
Risks
This is a large change to the compiler but low risk. The risk is minimal as users have to activate most of the new code by using #ELSE, and, the other main risk is the nested condition cache – as most code does not use nested conditions this is assessed as a low risk.
The only way to tell …. compare asm for an old compiler to new compiler.
Note: Buid1144 contains several hard coded error message. Later builds will move the error messages to the language file.
We are testing at the moment but I am looking for people to test.
Last edit: Anobium 2022-08-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Build1144
Adds an extensive handler for #ELSE within conditional statements, and, the additional of #IFNOT to support negated condition of #IF.
Examples:
and
Note: This change Build1144 does not change the behaviour of #CHIP or #DEFINE. This change is focused on the handling of conditional with the inclusion of #ELSE and #IFNOT
Implementation
The change is implemented as follows, noting many of these changes are not visible to the user but this explains the change in some detail.
a. #IF=2
b. #IFNOT=3
c. #IFDEF=0
d. #IFNDEF=1
If the current source line is #ELSE then the compiler replaces the #ELSE with appropriate code to enable the compiler to handle the #ELSE, as follows:
a. #ELSE when the condition is #IF – is transformed to #ENDIF & #IFNOT plus the condition
b. #ELSE when the condition is #IFNOT – is transformed to #ENDIF & #IF plus the condition
c. #ELSE when the condition is #IFDEF – is transformed to #ENDIF & #IFNDEF plus the condition
d. #ELSE when the condition is #IFNDEF – is transformed to #ENDIF & #IFDEF plus the condition
The compiler increments the array location upon each conditional statement ( #IF… ) that is nested.
An example
This is transformed within the compiler to
Where the #ELSE is transformed into #ENDIF : #IFNOT condition
The #IFNOT command is transformed from #IFNOT to #IF, and, then the result of the calculation is negated - this creates #IFNOT. There are other trivial changes in IFDEFs method to recognised #IFNOT.
Risks
This is a large change to the compiler but low risk. The risk is minimal as users have to activate most of the new code by using #ELSE, and, the other main risk is the nested condition cache – as most code does not use nested conditions this is assessed as a low risk.
The only way to tell …. compare asm for an old compiler to new compiler.
Note: Buid1144 contains several hard coded error message. Later builds will move the error messages to the language file.
We are testing at the moment but I am looking for people to test.
Last edit: Anobium 2022-08-07
A working source program - you need build 1145 or later.
Enjoy