Created
December 18, 2018 21:01
-
-
Save moritz/8612f6200f9e34e9ee63f02b6bcbbdc7 to your computer and use it in GitHub Desktop.
Perl 6 phase interleaving
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Perl 6 first compiles code, and then runs it. | |
The C<BEGIN> phaser interleaves a run time phase into the | |
compilation phase, that is, the code inside the C<BEGIN> | |
phaser is first compiled, then run, and then the rest of the | |
compilation continues. | |
In the hypothetical code example | |
A; | |
BEGIN { B } | |
C; | |
the phases are: | |
=item compilation of A | |
=item compilation of B | |
=item run time of B | |
=item compilation of C | |
=item run time of A | |
=item run time of C | |
The same happens when C<use>ing a module that is not precompiled; in a code | |
like C<use SomeModule;>, the C<use> statement runs at compile time, which | |
first compiles C<SomeModule>, runs the mainline of C<SomeModule>, and then | |
continues compiling the rest of the program that contains the C<use> statement. | |
The inverse of this operation is the C<EVAL> function, which compiles | |
and then runs code during the run time phase. For instance the phases of | |
A; | |
EVAL 'B'; | |
C | |
are | |
=item compilation of the whole program | |
=item run time of A | |
=item run time of EVAL | |
=item compilation time of B | |
=item run time of B | |
=item run time of C | |
Interleaving of run time and compile time can be arbitrarily nested. If | |
you C<use> a module that C<use>s another module, that already constitutes two | |
levels of nesting. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment