|Newbie questions about Pliant
On meta programming
|Message posted by maybe Marcus on 2002/07/17 16:00:42
|Shaking the apparent lethargy off the forums, most likely caused by these hot,
long, and yet delightful summer days, let me ask you for a sanity check.
Does the assertion below make sense?
To compile an expression, the compiler traverses the expression tree, checking
the various possible functions that can be used for computing the expression,
and attaching the instruction that performs the correct operation. If, however,
while traversing the expression, the compiler finds a subexpression representing
a meta function call, then the meta function itself will define how the
(sub)expression will be compiled.
|Message posted by maybe Hubert Tonneau on 2002/07/17 22:51:57
|The start point for compiling is active types.
Each expression is attached a value.
For compiling the expression, the active type generic method of the value
Here is the prototype of the active type generic method (it's a function, not
a method, but you known, it's the same in Pliant)
function active_type object access expression
arg Universal object ; arg Int access ; arg_rw Expression expression
For 'ordinary' data types such as 'Int' 'Str' and so on, the default 'active_type'
method is set the result of the expression as constant, the constant beeing the
Now, some data types have very different active types:
Ident: the value is used to scan the main dictionary, and call the active type
method of the found entries.
Function: the expression will be checked against the prototype of the function.
Meta: the meta function will be executed and is responsible for compiling
There are other less important active types, and all the built in ones are
defined in module /pliant/language/compiler/active.c
Of course, you can write your own one for any of your data types.
PS: here, 'compiling' means attaching to the expression the set of instructions
that compute the result, and specifying where the result is (in what
argument) when these instructions have been executed.
|Message posted by maybe Marcus on 2002/08/02 19:29:49
I am (still) documenting metaprogramming. I wonder if you can send me
a simple example of a meta function. E.g., one that compiles 0+E as E, or
one that compiles 0*E as 0.
These ones seem simple, but I am not sure if their code, in the general case,
is short and intuitive.
Thanks in advance for your time.
|Message posted by maybe Hubert Tonneau on 2002/08/02 19:42:45
|Implementing 0*E=0 as a meta is probably a bad idea because this is an
optimization rule, and the Pliant optimizer is another part.
|Message posted by maybe Marcus on 2002/08/02 21:47:04
|I have picked the 0+E example from the original meta programming documentation,
namely, samples.page. It mentions that metaprogramming can also be used
to optmize (rewrite) code. Now I am confused...
|Message posted by maybe Hubert Tonneau on 2002/08/02 21:58:25
|Yes it can, but it's only one 'special' usage of meta programming, so if the
only example I provided about meta programming was optimizing related, then
I was wrong.
|Message posted by maybe Marcus on 2002/09/04 14:10:51
|Continuing our discussion on meta programming:
Does pliant allow the programmer to 'play' with the low-level compiling stage in
a similar way that it does via meta programming with the high-level compiling stage?
|Message posted by maybe Hubert Tonneau on 2002/09/04 14:15:18
|Yes, it does, through recording filters in the low level compiler engine.
Basically, we have one encoding for low level compiling, which is a function
as a set of instructions, each instruction beeing a call to a function, with
Now, each filter can make changes to the set of instructions, and are called
in a well defined order (a bit like the well defined order for calling parse
When all filters have been called, we have only processor specific instructions,
so can generate the binary version of the function.
Through recording your filter, you can make changes to the instructions set
so that it will overwrite the normal way since the standard filters set will
not touch the already low level instructions.
|Message posted by maybe Marcus on 2002/09/04 14:23:29
|Hi, Hubert. Nice to hear from you.
Are you aware of other programming languages which endow the programmer with such
The reason I am asking that is because I have plans to write a paper based on the documentation for metaprogramming that I am currently (and still) writing. It would be interesting to have the answer to the above question mentioned there.
|Message posted by maybe Hubert Tonneau on 2002/09/04 14:26:35
|I'm awared of tools for providing abstraction to the low level engine, but
as far as I know, they are more designed a tools to help write standard
compilers, so the freedom does not exist at language level.
Also take with care since I'm not very awared about reseach papers.