Wc3C.net

Wc3C.net (http://www.wc3c.net/forums.php)
-   Triggers & Scripts (http://www.wc3c.net/forumdisplay.php?f=8)
-   -   C preprocessor in jasshelper (http://www.wc3c.net/showthread.php?t=110568)

cohadar 12-24-2011 02:18 PM

C preprocessor in jasshelper
 
Do you think jasshelper should have C preprocessor?

EDIT:
I uploaded experimental version with C prepreprocessor, try it and vote.

Quote:

#include
#define
#if
#elif
#ifdef
#ifndef
#else
#endif
#undef
#foreach
#endforeach
#bigdef
#endbigdef
#error
#warning
#comment


Troll-Brain 12-26-2011 11:28 AM

I've voted yes, because actual text macros are not only really limited, it's also fugly to use.
Not to mention that hooks are most of time useless in the current state.
And finally i've always found the use of static ifs not enough clear with the actual syntax (i mean the syntax difference between static ifs and classic ifs is not enough)

But public resources shoudn't use bigdef for a native function define.

Btw, is it possible to define a native function instead of using it like vJass textmacros ?
EDIT : Ok, just tested and you can.
A pretty new toy to play with it, i would say :

Why bigdef and just not def, or define btw ?

EDIT 2 : Oh wait, i was trying to define RemoveUnit for my Personnal Unit Indexer, but sadly it defines also GroupRemoveUnit, and i suppose anything which have RemoveUnit in its name :/
I'm also wondering if it defines strings "" (can't test it right now).

EDIT 3 : bigdefs are considered even in comments block (/* */), plus i tends to add line breaks and make a new line with the last character (usually a ")" ) and then make the jass script invalid.

So if you plan to let them in the current state, you should just remove them instead.
Ofc you are welcome to improve them, if you're willing to it.

cohadar 12-30-2011 01:53 PM

#bigdef is for multi-line macros.
#define is for one-line macros.

It seems all your problems can be simply solved by reading the manual.

cohadar 01-04-2012 06:30 AM

Humm, maybe it is just the new year thing but it seems there are not enough people to even make a decent poll.
(or not enough people willing to learn something new)

Anyways I will probably put a turn on/off option (default off) for C preprocessor in jasshelper menu bar since it does not seems it is gonna be uber-mega-popular.
(which is a shame considering how easy it is to use)

0zyx0 01-04-2012 12:32 PM

I would find #define to be useful, but not the others. Perhaps also #foreach, to replace short loops with something more efficient. But the other features seem (to me) either useless, or uglier alternatives to what exists.

Troll-Brain 01-04-2012 03:17 PM

For some reasons i didn't saw the documentation, neither #define, my bad.

Anyway, unless a space " " is a valid first character for a #define i fail to see how to define RemoveUnit, without breaking other functions such as GroupRemoveUnit.
Or maybe defines will work as intented without the need of a space, i can't test it now.

Same for this :

Code:

/*
    #define ...
    #endfine

*/


I can't even use the tool in command line before jasshelper to remove comments, since it will also remove all external commands (//!...)

Also, i have not tried yet but i'm stll wondering if strings "..." are affected by the defines.
And also not tested, but i suppose you handle requirements (library A requires B, scopes, ...) before doing any defines, else that wouldn't work that much.

Anyway thx for this and jasshelper, i had almost no interest in wc3 modding but you gave me some.

cohadar 01-06-2012 06:39 AM

Quote:

Originally Posted by 0zyx0
I would find #define to be useful, but not the others. Perhaps also #foreach, to replace short loops with something more efficient. But the other features seem (to me) either useless, or uglier alternatives to what exists.


Most parts of macro preprocessor have already been implemented by vexorian,
the problem is they do not all look like preprocessor constructs.
  • //! include
  • //! external
  • //! textmacro
  • optional
  • static if
  • module

The last three clearly do not look like preprocessing statements but rather like jass extensions.
This kind of programming stile is misleading.

As for comments on the estetics of this stuff vs C preprocessor directives,
I think that should have to wait for someone to make proper color coding for #statements.



Quote:

Originally Posted by Troll-Brain
Anyway, unless a space " " is a valid first character for a #define i fail to see how to define RemoveUnit, without breaking other functions such as GroupRemoveUnit.
Or maybe defines will work as intented without the need of a space, i can't test it now.

It takes some time for people to learn how to use C preprocessing properly.
Here is a tip for your particular problem:
Make a macro for GroupRemoveUnit before you make a macro for RemoveUnit.

Quote:

Originally Posted by Troll-Brain
I can't even use the tool in command line before jasshelper to remove comments, since it will also remove all external commands (//!...)

You got that the wrong way.
Removing comments has been disabled so preprocessor would not destroy old external commands and textmacros. Compatibility ftw.

Quote:

Originally Posted by Troll-Brain
Also, i have not tried yet but i'm stll wondering if strings "..." are affected by the defines.

Yes they are.
There is an option to turn it off but I see no reason for it.

Quote:

Originally Posted by Troll-Brain
And also not tested, but i suppose you handle requirements (library A requires B, scopes, ...) before doing any defines, else that wouldn't work that much.

No, C preprocessing happens before EVERYTHING else.
That way you can do things like this:
Collapse JASS:
ifdef PUI
library mylib uses PUI
elif Autoindex
library mylib uses Autoindex
else
  error "mylib needs at least one indexing system"
endif
Of course optional keyword does the same in one line,
but than again it does not error if you have both libraries at the same time
or if you don't have either.

Quote:

Originally Posted by Troll-Brain
Anyway thx for this and jasshelper, i had almost no interest in wc3 modding but you gave me some.

:evil_laughter:

Troll-Brain 01-06-2012 11:55 AM

Quote:

Originally Posted by cohadar
It takes some time for people to learn how to use C preprocessing properly.
Here is a tip for your particular problem:
Make a macro for GroupRemoveUnit before you make a macro for RemoveUnit.


Expand JASS:

compiles to :

Expand JASS:

I've also tried to use GroupRemoveUnit instead of that awesome BJ created by myself : same result.
Or i'm missing something ?

Quote:

You got that the wrong way.
Removing comments has been disabled so preprocessor would not destroy old external commands and textmacros. Compatibility ftw.

What i mean is that it doesn't make sense that preprocessors are evaluated if they are commented, they should be disabled.

Quote:

Yes they are.
There is an option to turn it off but I see no reason for it.

Leave a tag option in the file jasshelper.conf wouldn't hurt.

Quote:

No, C preprocessing happens before EVERYTHING else.
That way you can do things like this:
Collapse JASS:
ifdef PUI
library mylib uses PUI
elif Autoindex
library mylib uses Autoindex
else
  error "mylib needs at least one indexing system"
endif
Of course optional keyword does the same in one line,
but than again it does not error if you have both libraries at the same time
or if you don't have either.

Well, the real problem is that the wc3 editor doesn't handle really well relative trigger order
So requirements are a must, and also despite some people says, really most of the time scripting inside the editor is the only way to go (preplaced units, object editor stuff, ...)
It breaks the concepts of vJass requirements, which is not a plus here.

Now, if it is just too much and/or will make the compile time much longer, i think you should just leave this stuff.

Quote:

:evil_laughter:

You have no idea of what you did.

cohadar 01-06-2012 02:38 PM

Preprocessor directives exist before everything else, even comments.
Therefore putting them inside multiline comments /* */ will not work
To disable a preprocesor directive use single line comment before directive //#

Collapse JASS:
 call GronullpRemoveUnitBJ(null , null) // u -> null
Give longer argument names for macro params and make sure they don't appear as part of other macro names.
"u" is obviously a very bad name :)
Try something like UNIT

Troll-Brain 01-06-2012 04:25 PM

I still don't get how the jass code is generated in my example, for me it's a bug.
But well, i've changed the macro param name and it works.
Too bad we can't define a function to itself and make a wrapper of it instead, sure it will be inlined but meh ...

This preprocessor is far more powerfull than what we already have in jasshelper, but i wouldn't say :

Quote:

which is a shame considering how easy it is to use

Actually it is not, and quite tricky.
Also considering that most of the stuff you allow shouldn't be used in a public ressource, i repeat myself, this preprocessor should be removed, even if i've voted yes in the first place.

cohadar 01-06-2012 04:39 PM

Well it is easy to use to me, but I guess that is because I know C programming, so I don't really count.

That is it I guess.

C preprocessor will be removed because:
  • It is too complicated to use for average mapper
  • most of it's functionality is already implemented in different ways
  • It slows down compilation even if you don't use it

It would have been a great thing if it was inserted at the beginning of jasshelper development,
but now it is a bit late for it.

Next jasshelper version will have no C preprocessor.


All times are GMT. The time now is 08:14 AM.

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services