But has this implementation been added to the new compiler? It gives me an error...
I trying to transport a program that I had written in Mikrobasic on Gcbasic, but I find myself in difficulty on these instructions:
ADDR = 0x80 OR ((Row-1) << 6) OR (Col-1)
Last edit: jackjames 2025-04-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'MyVar = FnLSL( 1, BitNum)' is equivalent to 'MyVar = 1<<BitNum'
But, that is not equivalent to a complex calc such as 0x80 OR ((Row-1) << 6) OR (Col-1). The implementation in the compiler is the issue - the internal transformation is failing... as you can see!
The workaround is to expand the operations.
ADDR = Row-1
ADDR = ADDR << 6
ADDR = 0x80 OR ADDR OR ( Col - 1 )
Once I have completed my current project I will investigate.
Last edit: Anobium 2025-04-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Should be resolved in Build 1480. If you want to test - please email me. You know where....
In Builds prior to 1480. You can see what is happening/broken by editing the USE.INI
Edit USE.INI and change compilerdebug = 0 to compilerdebug = 512. This will show expansion of the shifts.
So, for this test program.
#SKIPTEST
#CHIP 16f1939
Dim BitNum as Byte
Dim MyVar as Word
// Works
MyVar = FnLSL( 1, BitNum)
MyVar = 1<<BitNum
Dim Addr as Word
Dim Row as Byte
Dim Col as Byte
ADDR = 0x80 OR ((Row - 1) << 6) OR (Col-1)
You get, clearly the last entry ( 512 ExpandShifts Out:.. ) is incorrect. The expanded syntax is totally incorrect. The parentheses around Row - 1 are not been handled correctly... actually there is no implementation to handle parentheses in the expansion section of the compiler.
This code is part of the GCBASIC compiler (written in FreeBASIC) that processes bitwise shift operations (<< for left shift and >> for right shift). Let me explain what it's doing:
Overall Purpose
The code parses source code that contains bitwise shift operations and transforms them into function calls (FnLSL for left shift and FnLSR for right shift). This is a common compiler technique where higher-level operations are converted to more primitive function calls.
I'll expand on the three cases for handling shift operators in this code. The Case 1 and the parentheses maangement is what I have added in Build 1480.
Else if
Case 2: Constant Values - constant << constant
Thiscasehandlesshiftoperationswherebothoperandsareconstantvaluesthatcanbeevaluatedatcompiletime.ExampleInput:4<<2Process:1.ThecodechecksthatboththeleftandrightoperandsareconstantsusingIsConst()2.ItconcatenatestheoriginalexpressionleftOperand+operator+rightOperand3.ItevaluatestheresultusingtheCalculate()function4.Itreplacestheshiftoperationwiththecalculatedresult5.Itclearstheoriginaloperandssincethey've been incorporated into the resultExampleOutput:16(theprecalculatedresult)
Else
Case3:StandardVariableShifting-variable<<constantThisisthemoststraightforwardcase,handlingstandardshiftoperationsonvariables.ExampleInput:myVar<<3Process:1.Thecodecapturestheleftoperand(thevaluetobeshifted)asBitsIn2.Itcapturestherightoperand(thenumberofbitstoshift)asNumBits3.Itcreatesafunctioncallbasedontheshiftdirection:-FnLSL(myVar,3)forleftshifts(<<)-FnLSR(myVar,3)forrightshifts(>>)4.Itclearstheoriginaloperandssincethey've been incorporated into the function callExampleOutput:FnLSL(myVar,3)
The purpose of all the transformations is to convert C-style shift operators (<< and >>) into function calls that the GCBASIC compiler can understand and process correctly.
This enables developers to use familiar syntax while ensuring compatibility with the target compiler.
Last edit: Anobium 2025-04-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
MyVar = FnLSL( 1, BitNum)
is Equivalent to
MyVar = 1<<BitNumBut has this implementation been added to the new compiler? It gives me an error...
I trying to transport a program that I had written in Mikrobasic on Gcbasic, but I find myself in difficulty on these instructions:
ADDR = 0x80 OR ((Row-1) << 6) OR (Col-1)
Last edit: jackjames 2025-04-17
See later post... resolved.
'MyVar = FnLSL( 1, BitNum)' is equivalent to 'MyVar = 1<<BitNum'
But, that is not equivalent to a complex calc such as
0x80 OR ((Row-1) << 6) OR (Col-1)
. The implementation in the compiler is the issue - the internal transformation is failing... as you can see!The workaround is to expand the operations.
Once I have completed my current project I will investigate.
Last edit: Anobium 2025-04-18
@JackJames
Should be resolved in Build 1480. If you want to test - please email me. You know where....
In Builds prior to 1480. You can see what is happening/broken by editing the USE.INI
Edit USE.INI and change
compilerdebug = 0
tocompilerdebug = 512
. This will show expansion of the shifts.So, for this test program.
You get, clearly the last entry ( 512 ExpandShifts Out:.. ) is incorrect. The expanded syntax is totally incorrect. The parentheses around
Row - 1
are not been handled correctly... actually there is no implementation to handle parentheses in the expansion section of the compiler.Build 1480 handles correctly.
This code is part of the GCBASIC compiler (written in FreeBASIC) that processes bitwise shift operations (
<<
for left shift and>>
for right shift). Let me explain what it's doing:Overall Purpose
The code parses source code that contains bitwise shift operations and transforms them into function calls (
FnLSL
for left shift andFnLSR
for right shift). This is a common compiler technique where higher-level operations are converted to more primitive function calls.I'll expand on the three cases for handling shift operators in this code. The Case 1 and the parentheses maangement is what I have added in Build 1480.
Process:
Next Operation
Else if
Case 2: Constant Values - constant << constant
Else
The purpose of all the transformations is to convert C-style shift operators (<< and >>) into function calls that the GCBASIC compiler can understand and process correctly.
This enables developers to use familiar syntax while ensuring compatibility with the target compiler.
Last edit: Anobium 2025-04-18
I am amazed that this now works.
Verified as Good.
Just posted a review of this work to KO-FI
Congratulations!
Great job, can't wait to try it.
I'll be back in Rome in a few days and do a functional test.