Preprocessor Request: #macroundef and or make macros redefineable

Morganl

Senior Member
I like modular programming, and PE6 make now it easier on PIXAXE, i can #include the modules i want.
Macros are also a long wanted addition.
:)
To automate things i would like the modules I include to add themselves to callers.
My idea is that the caller code is a macro ending with an on-goto statement, and each module add its entry point to it.
I use the functionality that a macro definition can contain another macro:

First i define a macro
#macro taskcaller
on taskptr goto _
#endm

and in each includefile i then have
#macro taskcaller
taskcaller
ppp_includefilename _
#endm
ppp_includefilename:
<code>
goto mainloop

BUT: Currently this fail as macros cannot be redefined.
I would like macros to become redefineable (throw out a warning, but not error)
Have it work to then use a ormer version of same name macro inside the new macro definition.

Alternatively, maybe more easy to implement in PE:
I can make a copy of the original macro under new name, undefine the original, then make a new under original name containing the copy plus additions, then delete the copy:

#macro tempmacro
taskcaller
#endm
#undefmacro taskcaller

#macro taskcaller
tempmacro
ppp_includefilename _
#endm
#undefmacro tempmacro

ppp_includefilename:
<code>
goto mainloop
 

Technical

Technical Support
Staff member
You can use #undefine to kill off a previous macro (a #macro is simply a multiline #define, they are effectively the same thing)

However conceptually you have missed how the preprocessor works.
You are trying to 'run' the macros before they are used, whereas in reality they only 'run' when their keyword is found.

Consider a macro as a pure 'copy/paste' of text without intelligence and then it's operation becomes clearer:

So the word

'taskcaller'

simply becomes its text equivalent

'tempmacro: ppp_includefilename_ '

becomes

'<tempmacro's current text>: ppp_includefilename_'

etc. etc.

However we think all you actually really want to do is 'macro append' - add text to an existing macro?
Does this type of (conceptual idea) meet your requirement?

#macro tempmacro
high b.0
#endm

#appendmacro tempmacro
high b.1
#endm

To give a tempmacro text substitution of

high b.0
high b.1
 

Morganl

Senior Member
Yes! :)
- that conceptual idea is precisely what i try to achieve.

Then tasks in include files can add each on its own add itself to a multiline goto in an macro definition, that is then used for calling the tasks.
Without the programmer needing to remember to insert them, and know their labels.

The main.bas file starts by defining the macro as
on TaskPointer goto _

( _ means command continues on next line )
The tasks are #included, and add their names by each adding a line with its call name, plus comma, space, and underscore, example:
TaskLCD, _

Then the main file must add a final line to get rid of the last comma and underscore... it can as example add a call to a point in program that resets the TaskPointer
TaskPointerReset

So the macro becomes with several tasks as example:
on TaskPointer goto _
TaskLCD, _
TaskSend, _
TaskReceive, _
TaskServo, _
TaskPointerReset



The other thing i was trying to automate, is to name the entry label of the task by the include filename, by using ppp_includefilename.
However that fail at least because the ppp_* functions return a string including ""
It is not important, i should standardise and i.e start all labels in an include file with same as the first letters of the filename, and call point is only that part.


I know preprocessor do not "run" the macros, but i was hoping it could evaluate them enough to rebuild them somehow without needing a new directive.

But if you are willing to make the preprocessor handle #appendmacro i would be glad :)
 

Morganl

Senior Member
And Santa, if you are open for more additions i would like:

#warning
Function: tells programmer important messages he must not forget to finish/check, but let the program compile so it can be used.
instead of stopping and put up a message directly as #error do, it should gather all generated #warning and present them prepended with filename and line (maybe also #region), in a text file popping up after compile (sucessful or not).
Examples:
#warning FIXME: this error handler is a stub

#ifdef somePICAXE
#ifdef somesetting
#warning Remember to Yadayada
#endif
#endif


Then, it would be good if some non-fatal errors were reported in the same #warning file, instead of inhibiting compilation.
I am thinking it could be useable if you let symbol, #define, #macro overwrite the previous definitions throwing warning instead of error.


And then one thing i guess you have on your todo list: Sort files in workspace explorer file listings - by manually dragging or automatically by type, name.
 
Last edited:

Morganl

Senior Member
FYI i now realise there is more needed to reach the automation i wanted, if i do not want to complicate the program so it gets inefficient.
What is needed is compile time calculation of constants.
That would be nice for many things, but in this case specifically to count numbers of lines added to that on..goto above
...this also requires evaluation while parsing, and #redefine working ease it.

;in main
#define count=0

;in some tasks
#redefine count=count+1

;in a special task
#redefine count=count+1
#define SpecialTask=count

;Later task can then
if OOPSSpecialTaskMustRun=1 then
gotopointer=SpecialTask
goto scheduler
endif

-----

Well above is luxory

includes and macros do help a lot already - Thanks!

The add i want most is #warning to help myself note and see important things that must not get forgotten
 
Top