Open hike-eclat opened 2 years ago
the workaround is not to define the same macro name in two chains in the same file
(but I've actually have to check if the two chains are compiled at the same time or not!! maybe this is not a problem...)
IMHO this is not the way to go. Because we want to support multiple chains for each compilation unit (CU), the user can choose any name for their constants within each individual chain. We CANNOT force the user to avoid using the same name, since the visibility of constants is per each individual chain (we have never defined constants that are global so far). If we want to keep the constants defined using MACROs, we should define these constants before the chain that uses them and remove them immediately after the chain is defined. To do this, eCLAT should keep track of the constants defined per chain.
If you don't want to go through with this, a possible workaround would be to let the user choose the name they want for their constants and make the transpIler in charge of adjusting things under the hood. Specifically, the eCLAT transpiler should generate a sequence number that is consumed for each const declared. Then, it should add that sequence number to the MACRO name in the translated code, i.e.:
eCLAT
---------
def mychain1():
MYCONST1 = 123;
MYCONST2 = 0xdeadbeef;
# do some stuff
def mychain2():
MYCONST1 = 0xbadcafe;
#do some stuff
HIKe
------
in the single CU (*.hike.c)
HIKE_CHAIN(mychain1)
{
#define __ECLAT_CONST_MYCONST1_1 123
#define __ECLAT_CONST_MYCONST2_2 0xdeadbeaf;
/* transpiled code here */
}
HIKE_CHAIN(mychain2)
{
#define __ECLAT_CONST_MYCONST1_3 0xbadcafe
/* transpiled code here /
}
Whatever the solution is, it is essential to add a prefix or suffix (but I prefer the former) to the macros that define the constants, i.e.: __ECLAT_CONST_XXXXX
This is necessary to avoid collisions with macros already defined in the API or by the HIKe VM.
if #define are not undefined and the same macro is defined in another chain in the same file, it would result in an compilation error