Skip to content

Commit

Permalink
Merge pull request #79 from sjn/nom
Browse files Browse the repository at this point in the history
Updates to the architecture document and SVG
  • Loading branch information
pmichaud committed Sep 4, 2012
2 parents 2948c89 + 103e95a commit cc18589
Show file tree
Hide file tree
Showing 2 changed files with 435 additions and 485 deletions.
151 changes: 68 additions & 83 deletions docs/architecture.html
@@ -1,104 +1,89 @@
<html> <html>
<head> <head>
<title>Rakudo architectural overview</title> <title>How Rakudo compiles a Perl 6 program</title>
</head> </head>
<body style="margin:2ex"> <body style="margin:2ex">


<h1>Rakudo architectural overview</h1> <h1>How Rakudo compiles a Perl 6 program</h1>

<p>(This started off <a
href="http://perlgeek.de/blog-en/perl-6/rakudo-overview.html">as a blog
post</a>, which didn't have the fancy clickable SVG image).</p>


<object <object
style="margin:2ex; float:left" style="margin:2ex; float:left"
data="/architecture.svg" data="architecture.svg"
type="image/svg+xml" type="image/svg+xml"
alt="Rakudo flow chart" alt="Rakudo flow chart"
> >
</object> </object>

<a id="action-methods" /> <a id="action-methods" />
<h2 id="parser" >Parser and action methods</h2> <h2 id="parser" >Parser and Action Methods</h2>


<p>The source code is entered at the top of the machine named Rakudo, and is <p>The Perl 6 source code is transformed in various stages, of which the first two are the Parser and Action Method stages. The Parser creates a parse tree out of the Perl 6 source code and then gives control to appropriate action methods that annotate the parse tree, incrementally turning it into an Abstract Syntax Tree (AST). When an action method is done annotating, control is handed back to the parser, which then continues parsing the Perl 6 code and "fire off" new action methods as it goes.</p>
transformed in various stages. The first two, parser and action methods, are
actually part of Rakudo, and are hosted in the Rakudo repository. They are <p>The result of these two stages interacting is an "improved PAST" (Perl 6 Abstract Syntax Tree) called QAST. This tree is then passed on to the QAST compiler.</p>
written in two different subsets of Perl 6, the regexes (parser), and "Not
Quite Perl 6", short NQP (action methods).</p> <p>The parser and action methods are implemented in "Not Quite Perl 6" (NQP) and are part of Rakudo and hosted in the Rakudo repository at <a href="../src/Perl6/Grammar.pm">src/Perl6/Grammar.pm</a> and <a href="../src/Perl6/Actions.pm">src/Perl6/Actions.pm</a>.</p>


<a id="post-compiler" /> <h2 id="the-world">The World</h2>
<h2 id="past-compiler">PAST and POST
compiler</h2> <p>The World is where the parser and the action methods store any declarations they encouter during their runs, including Classes, Types, Signatures, Constants, Subs and Methods.</p>


<p>The next two stages (PAST and POST compiler) are part of the so-called
"Parrot Compiler Toolkit", short PCT. Both PAST and POST are structural <h2 id="qast-compiler">QAST compiler</h2>
representations of the program, with PAST being more high-level than POST.
Both compilers are written in PIR, the parrot <p>The QAST compiler transforms the abstract syntax tree into a PIRT (Parrot Intermediate Representation Tree). To do this, the QAST compiler does a series of translations on the AST, creating PIRT nodes that implement the operations specified by the QAST nodes.</p>
assembly language, and are distributed along with parrot. They are also used
by many other parrot based languages.</p> <p>In addition, the QAST compiler is responsible for serializing <em>The World</em> in such a way that later stages can get access to the declarations stored there during the parser and action methods stages.</p>


<a id="parrot-runloops" /> <p>There's also opportunity to apply some VM-specific optimizations at this point. When this is done, the resulting PIRT is passed to the PIRT serializer.</p>
<h2 id="imcc">IMCC and Parrot runcores</h2>

<p>This stage is described in the different files in the <a href="../nqp/src/QAST/">nqp/src/QAST/</a> directory.</p>
<p>The POST compiler emits PIR, which IMCC transforms into byte code. IMCC is
parrot's PIR compiler, written in C and statically linked into parrot. The <h2 id="pirt-serializer">PIRT serializer</h2>
byte code (PBC) can then be stored to disk, or executed in memory by a
so-called <em>run core</em> or <em>run loop</em>, which is in some sense <p>The PIRT serializer "squashes" the PIR Tree into a format that can be passed to Parrot itself and it's IMCC (InterMediate Code Compiler) stage.</p>
the heart
of parrot - or one of the hearts, because there are several different ones <p>You can read more about this at <a href="../nqp/src/QAST/PIRT.nqp">nqp/src/QAST/PIRT.nqp</a>.</p>
available (one for just-in-time compilation (JIT), one for debugging etc.).</p>


<p>There are also some supporting custom types and operations in Rakudo called <a id="parrot-runtime" />
<em>dynamic PMCs</em> and <em>dynamic ops</em> which are written in C, and <h2 id="imcc">IMCC and Parrot runtime</h2>
helper functions written in other languages (namely NQP and PIR). Those do
not show up in the flow chart.</p> <p>The IMCC (InterMediate Code Compiler) receives the PIR code from the PIRT serializer and then transforms it into Parrot Byte Code (PBC). IMCC is parrot's PIR compiler, written in C and statically linked into parrot. The byte code can then be stored to disk or executed in memory by one of the <em>run cores</em> availabe as part of the Parrot runtime. This is in some sense the heart of Parrot - or one of the hearts; There are several different cores available, including one for just-in-time compilation (JIT), one for debugging and others.</p>


<h2 id="setting">Setting library</h2> <p>You can find out more about the IMCC in the <a href="../parrot/docs/imcc/">parrot/docs/imcc/</a> directory, and about the different run cores in the <a href="../parrot/docs/running.pod">parrot/docs/running.pod</a></p>


<p>The part of Rakudo described so far is the <em>stage one</em> compiler. <h2 id="pmc-dynops">PMCs and dynops</h2>
In the build process it is compiled first, and then it compiles the <em>setting
library</em> down to PBC. "Setting library" is a fancy term describing the <p>There are also some supporting custom types and operations in Rakudo called <em>dynamic PMCs</em> and <em>dynamic ops</em> (dynops) which are written in C, and helper functions written in NQP and PIR. These supporting libraries exist for adding features to Parrot that are needed to handle special features in Perl 6.</p>
built-in functions which are written in Perl 6. The result of this compilation
(together with a low level runtime library in PIR) is linked together with the <h2 id="core-setting">Core setting library</h2>
stage one compiler and parrot, the result is the <code>perl6</code>
executable.</p> <p>The core settings library is the library containing the methods, classes and almost all other features that make up the Rakudo Perl 6 implementation. This library is tightly coupled with the <code>perl6</code> binary, and loaded by default every time <code>perl6</code> is run.</p>


<h2 id="glossary">Glossary</h2> <h2 id="glossary">Glossary</h2>


<dl> <dl>
<dt>PGE</dt>
<dd>Parrot Grammar Engine, parrot's grammar engine for Perl 6 regexes and
grammars.</dd>

<dt>NQP</dt> <dt>NQP</dt>
<dd>Not Quite Perl 6, a small subset of Perl 6 that is used for tree <dd>Not Quite Perl 6, a small subset of Perl 6 that is used for tree transformations in compilers.</dd>
transformations in compilers.</dd>

<dt>PIR</dt>
<dt>PAST</dt> <dd>Parrot Intermediate Representation, the most commonly used for of parrot assembly (which is still high-level enough to be written by humans).</dd>
<dd>Parrot Abstract Syntax Tree, an in-memory representation of
structures common to many programming languages (like variable <dt>IMCC</dt>
declarations, branches, loops, subroutine calls).</dd> <dd>InterMediate Code Compiler, the part of parrot that compiles PIR into byte code.</dd>


<dt>POST</dt> <dt>PBC</dt>
<dd>Parrot Opcode Syntax Tree, an in-memory low level representation <dd>Parrot Byte Code, the binary form to which all parrot programs are compiled in the end.</dd>
of programs.</dd>

<dt>Core setting</dt>
<dt>PCT</dt> <dd>The core setting is the Perl 6 standard library. It is part of the perl6 executable, and contains all the standard features available in Perl 6.</dd>
<dd>Parrot Compiler Toolkit, a collection of tools and compilers useful
for writing other compilers.</dd> <dt>QAST</dt>

<dd>The "improved" Abstract Syntax Tree used in Rakudo Perl 6. It contains information about how the program is structured, and what it is supposed to do.</dd>
<dt>PIR</dt>
<dd>Parrot Intermediate Representation, the most commonly used for of <dt>PIRT</dt>
parrot assembly (which is still high-level enough to be written by <dd>Parrot Intermediate Representation Tree.</dd>
humans).</dd>

<dt>IMCC</dt>
<dd>InterMediate Code Compiler, the part of parrot that compiles PIR
into byte code.</dd>

<dt>PBC</dt>
<dd>Parrot Byte Code, the binary form to which all parrot programs are
compiled in the end.</dd>
</dl> </dl>


</body> </body>
Expand Down

0 comments on commit cc18589

Please sign in to comment.