Autrijus Tang wrote:
On Thu, Aug 18, 2005 at 04:51:58PM +0200, Leopold Toetsch wrote:

There was some recent discussion [1] [2] on p6l about BEGIN blocks and constant, which is executed at compile time too.

Parrot has since quite a time the @IMMEDIATE subroutine pragma, which causes execution of subs during compilation.


You mean, during PIR compilation?

Yes.

As PMC constants are already represented as frozen images in PBC this would work for nested data strucuters, objects, and their classes too.

Comments welcome,


I think it's interesting, but as BEGIN blocks may affect subsequent
parsing, as well as trigger compilation of other source files, I wonder
how to address this.  Hmm.

This shouldn't be a problem (at least when the last few globals from imcc are gone), i.e. compilation / running code should be fully re-rentrant.

Also I wonder about scoping issues:

    {
        my $a = $a / 2;
        BEGIN { $a = 10 };
    }
    say $a; # this should to print 5

How is @IMMEDIATE going to handle this?

@IMEDIATE subs will execute in the initial interpreter context. This context gets an initial lexical pad. (Either per default or we mandate that the first BEGIN{} has to create it).
So subsequenct BEGIN blocks can use this pad to communicate lexical state.

Then when @MAIN is frozen to bytecode and *if* there is a lexical pad, we consider @MAIN being a closure, which should freeze the pad too.

At runtime thawing the closure makes the pad available as the outermost pad.

BTW can you explain why the above example prints 5?

Thanks,
/Autrijus/

leo

Reply via email to