On Saturday 29 October 2005 17:35, Javier Martinez wrote:
> Hi Marco,
Hi Javier,
I apologize for the late answer, but I've been out of town.
>
> Can you post a brief example in JAL?
of course.
The main use of preprocessor support in jal is to write macros, short
sequences of statements used quite often, but for which a function call would
be overkill (or too expensive in some cases). Macros should be used with
caution and moderation though, because it's easy to use them improperly or to
get burned with unforeseen "side effects" of expansion.
A short, and silly, example could be:
silly-example.jal
------------------------------------------------------------------------
include f877_4
include jlib
pragma target fuses 0x3F32
disable_a_d_functions
var bit LED1 is pin_a0
var bit LED2 is pin_a1
pin_a0_direction = output
pin_a1_direction = output
#define CYCLE_1(ms) \
delay_10ms( (ms) ) \
LED1 = high \
LED2 = low
#define CYCLE_2(ms) \
delay_10ms( (ms) ) \
LED1 = low \
LED2 = high
forever loop
CYCLE_1(25)
CYCLE_2(25)
end loop
To use this example, we have to call the preprocessor before jal.
For example:
$ cpp silly-example.jal silly-example-expanded.jal
$ jal silly-example-expanded.jal
This first command will process "silly-example.jal" emitting its output in
"silly-example-expanded.jal". Then with the second command we simply compile
the generated file.
If you like, I'll add a command line switch to jal to invoke automatically the
preprocessor, thus avoiding the two separate commands shown above.
Cheers,
Marco
--
Marco Pantaleoni
elastiC language developer
http://www.elasticworld.org