adds preamble section to tge grammar to allow for includes and global
defines at the top of the PIR generated by TGE
For example, I use
preamble{
.include 'interpinfo.pasm'
}
The diff is relative to
compilers/tge
Compiler.pir | 62
++++++++++++++++++++++++++++++++++++++++++-----------------
Parser.pg | 24 +++++++++++++---------
2 files changed, 59 insertions(+), 27 deletions(-)
Kevin
You're on to an important idea, but it still needs refinement.
A bit of background info: TGE is heading is toward eliminating all PIR
code from the grammar files. A TGE grammar file is essentially a class
definition written in a high-level language.
Since what you're modifying here isn't the grammar, but the
grammar-compiler, it makes more sense as a method on the compiler
object. Something like:
grammar = new 'TGE::Compiler'
grammar.'set_preamble'(preamble_string)
compiled_source = grammar.'precompile'(source)
For compiling on the command line (or in a Makefile), we might provide a
--preamble option on the tree grammar compiler (tgc).
tgc.pir --output=lib/ASTGrammar.pir --preamble=lib/preamble.pir
lib/ASTGrammar.tg
We need to kick the idea around some more. If TGE is adding a feature
like this, it's a good idea to make it work for PGE too. (And to make it
work in the Compiler::Build modules too, when we get those going, so
it's available to all compilers.) At the moment you can get the same
effect by simply concatenating files in the Makefile or .include-ing a
generated file in a wrapper PIR module, but a cleaner interface is a
good idea.
In your particular example, a better solution is probably to put the
.include statement in your main compiler executable pruby.pir, right
next to the '.include "errors.pasm"' line.
> The diff is relative to compilers/tge
I haven't applied the preamble part of your patch, but I have applied
the rule naming cleanups. Thanks!
(Side note: when you're making diffs for patches, it's helpful if you
make them from the top-level directory of parrot. It makes the
patch-applier's job a little easier.)
Glad to have you contributing,
Allison