Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #39854] [PATCH] adds preamble section to tge grammar to allow for includes and global defines

4 views
Skip to first unread message

Kevin Tew

unread,
Jul 17, 2006, 12:57:24 PM7/17/06
to bugs-bi...@rt.perl.org
# New Ticket Created by Kevin Tew
# Please include the string: [perl #39854]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=39854 >


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

tge.diff

Allison Randal

unread,
Jul 17, 2006, 3:44:02 PM7/17/06
to perl6-i...@perl.org
Kevin Tew (via RT) wrote:
>
> 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'
> }

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

0 new messages