Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefine MACROs defined in the context of a chain #32

Open
hike-eclat opened this issue Jan 6, 2022 · 2 comments
Open

undefine MACROs defined in the context of a chain #32

hike-eclat opened this issue Jan 6, 2022 · 2 comments
Assignees
Milestone

Comments

@hike-eclat
Copy link
Collaborator

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

@hike-eclat
Copy link
Collaborator Author

hike-eclat commented Jan 7, 2022

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...)

@skorpion17
Copy link
Collaborator

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.

@hike-eclat hike-eclat added this to the 1.2 short milestone May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants