Feature for ecompile - small Preprocessor

Archive of the older Feature Request Forum Posts

Moderator: POL Developer

Locked
OWHorus
Grandmaster Poster
Posts: 105
Joined: Sat Feb 04, 2006 1:24 pm

Feature for ecompile - small Preprocessor

Post by OWHorus »

Hello,

it would be a fine thing to have at least a few preprocessor commands available in ecompile. (GNU CPP could be adapted, but it would be rather complex and much too large).

Only very few commands would help a lot:

#define VARIABLE [value] ... define a Variable in the Preprocessors namespace and optionally give it a value other than 1 (String or interger number would suffice).

#ifdef VARIABLE
... // Compile this lines only if #ifdef VARIABLE evalues to true.
...
...
#else
... // else compile this lines
...
...
#endif

With this simple commands we could for example have different includes, or could modify an entire code base with the new *.em files, and have it valid for an older version (096) too.

If the preprocessor variables could be replaced at any place in the code, a lot of practical things would be possible.

#ifdef POL_096_1
#define BUFFER 12
#else
#define BUFFER 14
#endif

const BUF_SIZE := BUFFER;
function xyz(x)
...
endfunction

I like eScript, and use it now for years, the only thing missing for me is a preprocessor. It could be written externally, but ecompile has a make function integrated and I think it would be ideally a part of ecompile.

OWHorus
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

It already has this ability, and has for a while..
When you compile something, it only compiles code into the ecl it will actually use.

This means if you have a function in your code that is never called, it doesn't get put into the ECL.

This also means if you have a constant and check its value, it will only compile it if can go into it - thats the preprocessor setup.

Example:
Find a large script, write down its file size.
Edit the script to have at the top

CONST COMPILE := 0;

in the program group put
program SomeProgram(some arguments)
if ( !COMPILE )
//... all the code here
endif
endprogram

compile and look at the ecl file size.. itll be lots smaller.
Marilla

Post by Marilla »

Ahhh.... I had actually suspected just that...

I've been using a nearly globally included "TESTING" const for some time now, to generate different compiles for testing or production, and sometimes it did seem to me that the file size really was different based solely on that single constant. I had mostly been assuming I was going nuts, though. hehe.

I did know, however, that eCompile never includes functions that are not used. I know that because I know that assuming the function block itself is properly defined, you could have an error in an include function's code that goes for a while without being realized, until you compile a script that actually USES the function.

I usually try to remove any 'testing' code, but use the const just as a second level of assurance... but knowing this now, that makes things interesting!
OWHorus
Grandmaster Poster
Posts: 105
Joined: Sat Feb 04, 2006 1:24 pm

Post by OWHorus »

Austin wrote:It already has this ability, and has for a while..
When you compile something, it only compiles code into the ecl it will actually use.

This means if you have a function in your code that is never called, it doesn't get put into the ECL.
This I knew already.
Austin wrote: This also means if you have a constant and check its value, it will only compile it if can go into it - thats the preprocessor setup.

Example:
Find a large script, write down its file size.
Edit the script to have at the top

CONST COMPILE := 0;

in the program group put
program SomeProgram(some arguments)
if ( !COMPILE )
//... all the code here
endif
endprogram

compile and look at the ecl file size.. itll be lots smaller.
This is new to me, thank you. This will help.

Horus
Locked