docs -> doc
lol
This commit is contained in:
220
doc/build/html/commentary/gm.html
vendored
Normal file
220
doc/build/html/commentary/gm.html
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en" data-content_root="../">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<title>The G-Machine — rl' documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=4f649999" />
|
||||
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css?v=039e1c02" />
|
||||
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
|
||||
<script src="../_static/doctools.js?v=888ff710"></script>
|
||||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||||
<link rel="index" title="Index" href="../genindex.html" />
|
||||
<link rel="search" title="Search" href="../search.html" />
|
||||
<link rel="next" title="Lexing, Parsing, and Layouts" href="layout-lexing.html" />
|
||||
<link rel="prev" title="Glossary" href="../glossary.html" />
|
||||
|
||||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||||
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||||
|
||||
</head><body>
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
|
||||
|
||||
<div class="body" role="main">
|
||||
|
||||
<section id="the-g-machine">
|
||||
<h1>The <em>G-Machine</em><a class="headerlink" href="#the-g-machine" title="Link to this heading">¶</a></h1>
|
||||
<section id="motivation">
|
||||
<h2>Motivation<a class="headerlink" href="#motivation" title="Link to this heading">¶</a></h2>
|
||||
<p>Our initial model, the <em>Template Instantiator</em> (TI) was a very
|
||||
straightforward solution to compilation, but its core design has a major
|
||||
Achilles’ heel, being that Compilation is interleaved with evaluation – The
|
||||
heap nodes for supercombinators hold uninstantiated expressions, i.e. raw ASTs
|
||||
straight from the parser. When a supercombinator is found on the stack during
|
||||
evaluation, the template expression is instantiated (compiled) on the spot.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/20219b0570be52c3f596972c4cd5461a162cccf9.svg" alt="\transrule
|
||||
{ a_0 : a_1 : \ldots : a_n : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_0 : \mathtt{NSupercomb} \; [x_1,\ldots,x_n] \; e
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_n : s
|
||||
& d
|
||||
& h'
|
||||
& g
|
||||
\\
|
||||
& \SetCell[c=3]{c}
|
||||
\text{where } h' = \mathtt{instantiateU} \; e \; a_n \; h \; g
|
||||
}"/></p>
|
||||
</div><p>The process of instantiating a supercombinator goes something like this</p>
|
||||
<ol class="arabic simple">
|
||||
<li><p>Augment the environment with bindings to the arguments.</p></li>
|
||||
<li><p>Using the local augmented environment, instantiate the supercombinator body
|
||||
on the heap.</p></li>
|
||||
<li><p>Remove the nodes applying the supercombinator to its arguments from the
|
||||
stack.</p></li>
|
||||
<li><p>Push the address to the newly instantiated body onto the stack.</p></li>
|
||||
</ol>
|
||||
<div class="literal-block-wrapper docutils container" id="id1">
|
||||
<div class="code-block-caption"><span class="caption-text">src/TI.hs</span><a class="headerlink" href="#id1" title="Link to this code">¶</a></div>
|
||||
<div class="highlight-haskell notranslate"><div class="highlight"><pre><span></span><span class="nf">scStep</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">Name</span><span class="w"> </span><span class="ow">-></span><span class="w"> </span><span class="p">[</span><span class="kt">Name</span><span class="p">]</span><span class="w"> </span><span class="ow">-></span><span class="w"> </span><span class="kt">Expr</span><span class="w"> </span><span class="ow">-></span><span class="w"> </span><span class="kt">TiState</span><span class="w"> </span><span class="ow">-></span><span class="w"> </span><span class="kt">TiState</span>
|
||||
<span class="nf">scStep</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="n">as</span><span class="w"> </span><span class="n">e</span><span class="w"> </span><span class="p">(</span><span class="kt">TiState</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="n">h</span><span class="w"> </span><span class="n">g</span><span class="w"> </span><span class="n">sts</span><span class="p">)</span><span class="w"> </span><span class="ow">=</span>
|
||||
<span class="w"> </span><span class="kt">TiState</span><span class="w"> </span><span class="n">s'</span><span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="n">h'</span><span class="w"> </span><span class="n">g</span><span class="w"> </span><span class="n">sts</span>
|
||||
<span class="w"> </span><span class="kr">where</span>
|
||||
<span class="w"> </span><span class="n">s'</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">rootAddr</span><span class="w"> </span><span class="kt">:</span><span class="w"> </span><span class="n">drop</span><span class="w"> </span><span class="p">(</span><span class="n">length</span><span class="w"> </span><span class="n">as</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="c1">-- 3., 4.</span>
|
||||
<span class="w"> </span><span class="n">h'</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">instantiateU</span><span class="w"> </span><span class="n">e</span><span class="w"> </span><span class="n">rootAddr</span><span class="w"> </span><span class="n">h</span><span class="w"> </span><span class="n">env</span><span class="w"> </span><span class="c1">-- 2.</span>
|
||||
<span class="w"> </span><span class="n">rootAddr</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">!!</span><span class="w"> </span><span class="n">length</span><span class="w"> </span><span class="n">as</span>
|
||||
|
||||
<span class="w"> </span><span class="n">env</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">argBinds</span><span class="w"> </span><span class="o">++</span><span class="w"> </span><span class="n">g</span><span class="w"> </span><span class="c1">-- 1.</span>
|
||||
<span class="w"> </span><span class="n">argBinds</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">as</span><span class="w"> </span><span class="p">`</span><span class="n">zip</span><span class="p">`</span><span class="w"> </span><span class="n">argAddrs</span>
|
||||
<span class="w"> </span><span class="n">argAddrs</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">getArgs</span><span class="w"> </span><span class="n">h</span><span class="w"> </span><span class="n">s</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<p>Instantiating the supercombinator’s body in this way is the root of our
|
||||
Achilles’ heel. Traversing a tree structure is a very non-linear task unfit for
|
||||
an assembly target. The goal of our new G-Machine is to compile a <em>linear
|
||||
sequence of instructions</em> which instantiate the expression at execution.</p>
|
||||
</section>
|
||||
<section id="trees-and-vines-in-theory">
|
||||
<h2>Trees and Vines, in Theory<a class="headerlink" href="#trees-and-vines-in-theory" title="Link to this heading">¶</a></h2>
|
||||
<p>WIP.</p>
|
||||
</section>
|
||||
<section id="evaluation-slurping-vines">
|
||||
<h2>Evaluation: Slurping Vines<a class="headerlink" href="#evaluation-slurping-vines" title="Link to this heading">¶</a></h2>
|
||||
<p>WIP.</p>
|
||||
<section id="laziness">
|
||||
<h3>Laziness<a class="headerlink" href="#laziness" title="Link to this heading">¶</a></h3>
|
||||
<p>WIP.</p>
|
||||
<ul class="simple">
|
||||
<li><p>Instead of <code class="code docutils literal notranslate"><span class="pre">Slide</span> <span class="pre">(n+1);</span> <span class="pre">Unwind</span></code>, do <code class="code docutils literal notranslate"><span class="pre">Update</span> <span class="pre">n;</span> <span class="pre">Pop</span> <span class="pre">n;</span> <span class="pre">Unwind</span></code></p></li>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
<section id="compilation-squashing-trees">
|
||||
<h2>Compilation: Squashing Trees<a class="headerlink" href="#compilation-squashing-trees" title="Link to this heading">¶</a></h2>
|
||||
<p>WIP.</p>
|
||||
<p>Notice that we do not keep a (local) environment at run-time. The environment
|
||||
only exists at compile-time to map local names to stack indices. When compiling
|
||||
a supercombinator, the arguments are enumerated from zero (the top of the
|
||||
stack), and passed to <code class="code docutils literal notranslate"><span class="pre">compileR</span></code> as an environment.</p>
|
||||
<div class="literal-block-wrapper docutils container" id="id2">
|
||||
<div class="code-block-caption"><span class="caption-text">src/GM.hs</span><a class="headerlink" href="#id2" title="Link to this code">¶</a></div>
|
||||
<div class="highlight-haskell notranslate"><div class="highlight"><pre><span></span><span class="c1">-- type CompiledSC = (Name, Int, Code)</span>
|
||||
|
||||
<span class="nf">compileSc</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">ScDef</span><span class="w"> </span><span class="ow">-></span><span class="w"> </span><span class="kt">CompiledSC</span>
|
||||
<span class="nf">compileSc</span><span class="w"> </span><span class="p">(</span><span class="kt">ScDef</span><span class="w"> </span><span class="n">n</span><span class="w"> </span><span class="n">as</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="w"> </span><span class="n">d</span><span class="p">,</span><span class="w"> </span><span class="n">compileR</span><span class="w"> </span><span class="n">env</span><span class="w"> </span><span class="n">b</span><span class="p">)</span>
|
||||
<span class="w"> </span><span class="kr">where</span>
|
||||
<span class="w"> </span><span class="n">env</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">as</span><span class="w"> </span><span class="p">`</span><span class="n">zip</span><span class="p">`</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="o">..</span><span class="p">]</span>
|
||||
<span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">length</span><span class="w"> </span><span class="n">as</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<p>Of course, variables being indexed relative to the top of the stack means that
|
||||
they will become inaccurate the moment we push or pop the stack a single time.
|
||||
The way around this is quite simple: simply offset the stack when w</p>
|
||||
<div class="literal-block-wrapper docutils container" id="id3">
|
||||
<div class="code-block-caption"><span class="caption-text">src/GM.hs</span><a class="headerlink" href="#id3" title="Link to this code">¶</a></div>
|
||||
<div class="highlight-haskell notranslate"><div class="highlight"><pre><span></span><span class="nf">compileC</span><span class="w"> </span><span class="n">g</span><span class="w"> </span><span class="p">(</span><span class="kt">App</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">compileC</span><span class="w"> </span><span class="n">g</span><span class="w"> </span><span class="n">x</span>
|
||||
<span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="n">compileC</span><span class="w"> </span><span class="p">(</span><span class="n">argOffset</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="n">g</span><span class="p">)</span><span class="w"> </span><span class="n">f</span>
|
||||
<span class="w"> </span><span class="o"><></span><span class="w"> </span><span class="p">[</span><span class="kt">MkAp</span><span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h1 class="logo"><a href="../index.html">rl'</a></h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3>Navigation</h3>
|
||||
<p class="caption" role="heading"><span class="caption-text">Index</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
|
||||
</ul>
|
||||
<p class="caption" role="heading"><span class="caption-text">Commentary</span></p>
|
||||
<ul class="current">
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">The <em>G-Machine</em></a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="layout-lexing.html">Lexing, Parsing, and Layouts</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="ti.html">The <em>Template Instantiator</em></a></li>
|
||||
</ul>
|
||||
<p class="caption" role="heading"><span class="caption-text">References</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../references/gm-state-transitions.html">G-Machine State Transition Rules</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../references/ti-state-transitions.html">Template Instantiator State Transition Rules</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="relations">
|
||||
<h3>Related Topics</h3>
|
||||
<ul>
|
||||
<li><a href="../index.html">Documentation overview</a><ul>
|
||||
<li>Previous: <a href="../glossary.html" title="previous chapter">Glossary</a></li>
|
||||
<li>Next: <a href="layout-lexing.html" title="next chapter">Lexing, Parsing, and Layouts</a></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3 id="searchlabel">Quick search</h3>
|
||||
<div class="searchformwrapper">
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
©2023, madeleine sydney ślaga.
|
||||
|
||||
|
|
||||
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a>
|
||||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
|
||||
|
||||
|
|
||||
<a href="../_sources/commentary/gm.rst.txt"
|
||||
rel="nofollow">Page source</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
325
doc/build/html/commentary/layout-lexing.html
vendored
Normal file
325
doc/build/html/commentary/layout-lexing.html
vendored
Normal file
@@ -0,0 +1,325 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en" data-content_root="../">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<title>Lexing, Parsing, and Layouts — rl' documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=4f649999" />
|
||||
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css?v=039e1c02" />
|
||||
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
|
||||
<script src="../_static/doctools.js?v=888ff710"></script>
|
||||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||||
<link rel="index" title="Index" href="../genindex.html" />
|
||||
<link rel="search" title="Search" href="../search.html" />
|
||||
<link rel="next" title="The Template Instantiator" href="ti.html" />
|
||||
<link rel="prev" title="The G-Machine" href="gm.html" />
|
||||
|
||||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||||
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||||
|
||||
</head><body>
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
|
||||
|
||||
<div class="body" role="main">
|
||||
|
||||
<section id="lexing-parsing-and-layouts">
|
||||
<h1>Lexing, Parsing, and Layouts<a class="headerlink" href="#lexing-parsing-and-layouts" title="Link to this heading">¶</a></h1>
|
||||
<p>The C-style languages of my previous experiences have all had quite trivial
|
||||
lexical analysis stages, peaking in complexity when I streamed tokens lazily in
|
||||
C. The task of tokenising a C-style language is very simple in description: you
|
||||
ignore all whitespace and point out what you recognise. If you don’t recognise
|
||||
something, check if it’s a literal or an identifier. Should it be neither,
|
||||
return an error.</p>
|
||||
<p>On paper, both lexing and parsing a Haskell-like language seem to pose a few
|
||||
greater challenges. Listed by ascending intimidation factor, some of the
|
||||
potential roadblocks on my mind before making an attempt were:</p>
|
||||
<ul class="simple">
|
||||
<li><p>Operators; Haskell has not only user-defined infix operators, but user-defined
|
||||
precedence levels and associativities. I recall using an algorithm that looked
|
||||
up infix, prefix, postfix, and even mixfix operators up in a global table to
|
||||
call their appropriate parser (if their precedence was appropriate, also
|
||||
stored in the table). I never modified the table at runtime, however this
|
||||
could be a very nice solution for Haskell.</p></li>
|
||||
<li><p>Context-sensitive keywords; Haskell allows for some words to be used as identifiers in
|
||||
appropriate contexts, such as <code class="code docutils literal notranslate"><span class="pre">family</span></code>, <code class="code docutils literal notranslate"><span class="pre">role</span></code>, <code class="code docutils literal notranslate"><span class="pre">as</span></code>.
|
||||
Reading a <a class="reference external" href="https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/coding-style#2-using-notes">note</a> found in <a class="reference external" href="https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/Parser/Lexer.x#L1133">GHC’s lexer</a>,
|
||||
it appears that keywords are only considered in bodies for which their use is
|
||||
relevant, e.g. <code class="code docutils literal notranslate"><span class="pre">family</span></code> and <code class="code docutils literal notranslate"><span class="pre">role</span></code> in type declarations,
|
||||
<code class="code docutils literal notranslate"><span class="pre">as</span></code> after <code class="code docutils literal notranslate"><span class="pre">case</span></code>; <code class="code docutils literal notranslate"><span class="pre">if</span></code>, <code class="code docutils literal notranslate"><span class="pre">then</span></code>, and <code class="code docutils literal notranslate"><span class="pre">else</span></code> in
|
||||
expressions, etc.</p></li>
|
||||
<li><p>Whitespace sensitivity; While I was comfortable with the idea of a system
|
||||
similar to Python’s INDENT/DEDENT tokens, Haskell seemed to use whitespace to
|
||||
section code in a way that <em>felt</em> different.</p></li>
|
||||
</ul>
|
||||
<p>After a bit of thought and research, whitespace sensitivity in the form of
|
||||
<em>layouts</em> as Haskell and I will refer to them as, are easily the scariest thing
|
||||
on this list – however they are achievable!</p>
|
||||
<section id="a-lexical-primer-python">
|
||||
<h2>A Lexical Primer: Python<a class="headerlink" href="#a-lexical-primer-python" title="Link to this heading">¶</a></h2>
|
||||
<p>We will compare and contrast with Python’s lexical analysis. Much to my dismay,
|
||||
Python uses newlines and indentation to separate statements and resolve scope
|
||||
instead of the traditional semicolons and braces found in C-style languages (we
|
||||
may generally refer to these C-style languages as <em>explicitly-sectioned</em>).
|
||||
Internally during tokenisation, when the Python lexer begins a new line, they
|
||||
compare the indentation of the new line with that of the previous and apply the
|
||||
following rules:</p>
|
||||
<ol class="arabic simple">
|
||||
<li><p>If the new line has greater indentation than the previous, insert an INDENT
|
||||
token and push the new line’s indentation level onto the indentation stack
|
||||
(the stack is initialised with an indentation level of zero).</p></li>
|
||||
<li><p>If the new line has lesser indentation than the previous, pop the stack until
|
||||
the top of the stack is greater than the new line’s indentation level. A
|
||||
DEDENT token is inserted for each level popped.</p></li>
|
||||
<li><p>If the indentation is equal, insert a NEWLINE token to terminate the previous
|
||||
line, and leave it at that!</p></li>
|
||||
</ol>
|
||||
<p>Parsing Python with the INDENT, DEDENT, and NEWLINE tokens is identical to
|
||||
parsing a language with braces and semicolons. This is a solution pretty in line
|
||||
with Python’s philosophy of the “one correct answer” (TODO: this needs a
|
||||
source). In developing our <em>layout</em> rules, we will follow in the pattern of
|
||||
translating the whitespace-sensitive source language to an explicitly sectioned
|
||||
language.</p>
|
||||
</section>
|
||||
<section id="but-what-about-haskell">
|
||||
<h2>But What About Haskell?<a class="headerlink" href="#but-what-about-haskell" title="Link to this heading">¶</a></h2>
|
||||
<p>We saw that Python, the most notable example of an implicitly sectioned
|
||||
language, is pretty simple to lex. Why then am I so afraid of Haskell’s layouts?
|
||||
To be frank, I’m far less scared after asking myself this – however there are
|
||||
certainly some new complexities that Python needn’t concern. Haskell has
|
||||
implicit line <em>continuation</em>: forms written over multiple lines; indentation
|
||||
styles often seen in Haskell are somewhat esoteric compared to Python’s
|
||||
“s/[{};]//”.</p>
|
||||
<div class="highlight-haskell notranslate"><div class="highlight"><pre><span></span><span class="c1">-- line continuation</span>
|
||||
<span class="nf">something</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">this</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">a</span>
|
||||
<span class="w"> </span><span class="n">single</span><span class="w"> </span><span class="n">expression</span>
|
||||
|
||||
<span class="c1">-- an extremely common style found in haskell</span>
|
||||
<span class="kr">data</span><span class="w"> </span><span class="kt">Python</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kt">Users</span>
|
||||
<span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">are</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">Crying</span>
|
||||
<span class="w"> </span><span class="p">,</span><span class="w"> </span><span class="n">right</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">About</span>
|
||||
<span class="w"> </span><span class="p">,</span><span class="w"> </span><span class="n">now</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">Sorry</span>
|
||||
<span class="w"> </span><span class="p">}</span>
|
||||
|
||||
<span class="c1">-- another formatting oddity</span>
|
||||
<span class="c1">-- note that this is not a single</span>
|
||||
<span class="c1">-- continued line! `look at`,</span>
|
||||
<span class="c1">-- `this`, and `alignment` are all</span>
|
||||
<span class="c1">-- separate expressions!</span>
|
||||
<span class="nf">anotherThing</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kr">do</span><span class="w"> </span><span class="n">look</span><span class="w"> </span><span class="n">at</span>
|
||||
<span class="w"> </span><span class="n">this</span>
|
||||
<span class="w"> </span><span class="n">alignment</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>But enough fear, lets actually think about implementation. Firstly, some
|
||||
formality: what do we mean when we say layout? We will define layout as the
|
||||
rules we apply to an implicitly-sectioned language in order to yield one that is
|
||||
explicitly-sectioned. We will also define indentation of a lexeme as the column
|
||||
number of its first character.</p>
|
||||
<p>Thankfully for us, our entry point is quite clear; layouts only appear after a
|
||||
select few keywords, (with a minor exception; TODO: elaborate) being <code class="code docutils literal notranslate"><span class="pre">let</span></code>
|
||||
(followed by supercombinators), <code class="code docutils literal notranslate"><span class="pre">where</span></code> (followed by supercombinators),
|
||||
<code class="code docutils literal notranslate"><span class="pre">do</span></code> (followed by expressions), and <code class="code docutils literal notranslate"><span class="pre">of</span></code> (followed by alternatives)
|
||||
(TODO: all of these terms need linked glossary entries). In order to manage the
|
||||
cascade of layout contexts, our lexer will record a stack for which each element
|
||||
is either <img class="math" src="../_images/math/66eb37710389b629d7ffa626fb55276426bef938.svg" alt="\varnothing" style="vertical-align: -2px"/>, denoting an explicit layout written with braces
|
||||
and semicolons, or a <img class="math" src="../_images/math/d04fe0dc2dd02e9d27dfd46e93827894feb96d1f.svg" alt="\langle n \rangle" style="vertical-align: -5px"/>, denoting an implicitly laid-out
|
||||
layout where the start of each item belonging to the layout is indented
|
||||
<img class="math" src="../_images/math/4713e4c065d6aabec3acece28c5ecc882faa119a.svg" alt="n" style="vertical-align: 0px"/> columns.</p>
|
||||
<div class="highlight-haskell notranslate"><div class="highlight"><pre><span></span><span class="c1">-- layout stack: []</span>
|
||||
<span class="kr">module</span><span class="w"> </span><span class="nn">M</span><span class="w"> </span><span class="kr">where</span><span class="w"> </span><span class="c1">-- layout stack: [∅]</span>
|
||||
|
||||
<span class="nf">f</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kr">let</span><span class="w"> </span><span class="c1">-- layout keyword; remember indentation of next token</span>
|
||||
<span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">w</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">w</span><span class="w"> </span><span class="c1">-- layout stack: [∅, <10>]</span>
|
||||
<span class="w"> </span><span class="n">w</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">x</span>
|
||||
<span class="w"> </span><span class="c1">-- layout ends here</span>
|
||||
<span class="w"> </span><span class="kr">in</span><span class="w"> </span><span class="kr">do</span><span class="w"> </span><span class="c1">-- layout keyword; next token is a brace!</span>
|
||||
<span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">-- layout stack: [∅]</span>
|
||||
<span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="n">y</span><span class="p">;</span>
|
||||
<span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="n">x</span><span class="p">;</span>
|
||||
<span class="w"> </span><span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Finally, we also need the concept of “virtual” brace tokens, which as far as
|
||||
we’re concerned at this moment are exactly like normal brace tokens, except
|
||||
implicitly inserted by the compiler. With the presented ideas in mind, we may
|
||||
begin to introduce a small set of informal rules describing the lexer’s handling
|
||||
of layouts, the first being:</p>
|
||||
<ol class="arabic simple">
|
||||
<li><p>If a layout keyword is followed by the token ‘{’, push <img class="math" src="../_images/math/66eb37710389b629d7ffa626fb55276426bef938.svg" alt="\varnothing" style="vertical-align: -2px"/>
|
||||
onto the layout context stack. Otherwise, push <img class="math" src="../_images/math/d04fe0dc2dd02e9d27dfd46e93827894feb96d1f.svg" alt="\langle n \rangle" style="vertical-align: -5px"/> onto
|
||||
the layout context stack where <img class="math" src="../_images/math/4713e4c065d6aabec3acece28c5ecc882faa119a.svg" alt="n" style="vertical-align: 0px"/> is the indentation of the token
|
||||
following the layout keyword. Additionally, the lexer is to insert a virtual
|
||||
opening brace after the token representing the layout keyword.</p></li>
|
||||
</ol>
|
||||
<p>Consider the following observations from that previous code sample:</p>
|
||||
<ul class="simple">
|
||||
<li><p>Function definitions should belong to a layout, each of which may start at
|
||||
column 1.</p></li>
|
||||
<li><p>A layout can enclose multiple bodies, as seen in the <code class="code docutils literal notranslate"><span class="pre">let</span></code>-bindings and
|
||||
the <code class="code docutils literal notranslate"><span class="pre">do</span></code>-expression.</p></li>
|
||||
<li><p>Semicolons should <em>terminate</em> items, rather than <em>separate</em> them.</p></li>
|
||||
</ul>
|
||||
<p>Our current focus is the semicolons. In an implicit layout, items are on
|
||||
separate lines each aligned with the previous. A naïve implementation would be
|
||||
to insert the semicolon token when the EOL is reached, but this proves unideal
|
||||
when you consider the alignment requirement. In our implementation, our lexer
|
||||
will wait until the first token on a new line is reached, then compare
|
||||
indentation and insert a semicolon if appropriate. This comparison – the
|
||||
nondescript measurement of “more, less, or equal indentation” rather than a
|
||||
numeric value – is referred to as <em>offside</em> by myself internally and the
|
||||
Haskell report describing layouts. We informally formalise this rule as follows:</p>
|
||||
<ol class="arabic simple" start="2">
|
||||
<li><p>When the first token on a line is preceeded only by whitespace, if the
|
||||
token’s first grapheme resides on a column number <img class="math" src="../_images/math/422ce4de46a354723a0f5b33995d885c86bb0e70.svg" alt="m" style="vertical-align: 0px"/> equal to the
|
||||
indentation level of the enclosing context – i.e. the <img class="math" src="../_images/math/c067c4215cbfc6897d6e5eaf14ded0dc221b972c.svg" alt="\langle n
|
||||
\rangle" style="vertical-align: -5px"/> on top of the layout stack. Should no such context exist on the
|
||||
stack, assume <img class="math" src="../_images/math/3fa33eeafbc80a0bcf2766e8f56e9cb2b6148e79.svg" alt="m > n" style="vertical-align: -1px"/>.</p></li>
|
||||
</ol>
|
||||
<p>We have an idea of how to begin layouts, delimit the enclosed items, and last
|
||||
we’ll need to end layouts. This is where the distinction between virtual and
|
||||
non-virtual brace tokens comes into play. The lexer needs only partial concern
|
||||
towards closing layouts; the complete responsibility is shared with the parser.
|
||||
This will be elaborated on in the next section. For now, we will be content with
|
||||
naïvely inserting a virtual closing brace when a token is indented right of the
|
||||
layout.</p>
|
||||
<ol class="arabic simple" start="3">
|
||||
<li><p>Under the same conditions as rule 2., when <img class="math" src="../_images/math/d696439e8724d5b54e9b4b344b9c99d0facc8b7c.svg" alt="m < n" style="vertical-align: -1px"/> the lexer shall
|
||||
insert a virtual closing brace and pop the layout stack.</p></li>
|
||||
</ol>
|
||||
<p>This rule covers some cases including the top-level, however, consider
|
||||
tokenising the <code class="code docutils literal notranslate"><span class="pre">in</span></code> in a <code class="code docutils literal notranslate"><span class="pre">let</span></code>-expression. If our lexical analysis
|
||||
framework only allows for lexing a single token at a time, we cannot return both
|
||||
a virtual right-brace and a <code class="code docutils literal notranslate"><span class="pre">in</span></code>. Under this model, the lexer may simply
|
||||
pop the layout stack and return the <code class="code docutils literal notranslate"><span class="pre">in</span></code> token. As we’ll see in the next
|
||||
section, as long as the lexer keeps track of its own context (i.e. the stack),
|
||||
the parser will cope just fine without the virtual end-brace.</p>
|
||||
</section>
|
||||
<section id="parsing-lonely-braces">
|
||||
<h2>Parsing Lonely Braces<a class="headerlink" href="#parsing-lonely-braces" title="Link to this heading">¶</a></h2>
|
||||
<p>When viewed in the abstract, parsing and tokenising are near-identical tasks yet
|
||||
the two are very often decomposed into discrete systems with very different
|
||||
implementations. Lexers operate on streams of text and tokens, while parsers
|
||||
are typically far less linear, using a parse stack or recursing top-down. A
|
||||
big reason for this separation is state management: the parser aims to be as
|
||||
context-free as possible, while the lexer tends to burden the necessary
|
||||
statefulness. Still, the nature of a stream-oriented lexer makes backtracking
|
||||
difficult and quite inelegant.</p>
|
||||
<p>However, simply declaring a parse error to be not an error at all
|
||||
counterintuitively proves to be an elegant solution our layout problem which
|
||||
minimises backtracking and state in both the lexer and the parser. Consider the
|
||||
following definitions found in rlp’s BNF:</p>
|
||||
<pre>
|
||||
<strong id="grammar-token-rlp-VOpen">VOpen </strong> ::= <code class="xref docutils literal notranslate"><span class="pre">vopen</span></code>
|
||||
<strong id="grammar-token-rlp-VClose">VClose</strong> ::= <code class="xref docutils literal notranslate"><span class="pre">vclose</span></code> | <code class="xref docutils literal notranslate"><span class="pre">error</span></code>
|
||||
</pre>
|
||||
<p>A parse error is recovered and treated as a closing brace. Another point of note
|
||||
in the BNF is the difference between virtual and non-virtual braces (TODO: i
|
||||
don’t like that the BNF is formatted without newlines :/):</p>
|
||||
<pre>
|
||||
<strong id="grammar-token-rlp-LetExpr">LetExpr</strong> ::= <code class="xref docutils literal notranslate"><span class="pre">let</span></code> VOpen Bindings VClose <code class="xref docutils literal notranslate"><span class="pre">in</span></code> Expr | <code class="xref docutils literal notranslate"><span class="pre">let</span></code> `{` Bindings `}` <code class="xref docutils literal notranslate"><span class="pre">in</span></code> Expr
|
||||
</pre>
|
||||
<p>This ensures that non-virtual braces are closed explicitly.</p>
|
||||
<p>This set of rules is adequete enough to satisfy our basic concerns about line
|
||||
continations and layout lists. For a more pedantic description of the layout
|
||||
system, see <a class="reference external" href="https://www.haskell.org/onlinereport/haskell2010/haskellch10.html">chapter 10</a> of the
|
||||
2010 Haskell Report, which I heavily referenced here.</p>
|
||||
<section id="references">
|
||||
<h3>References<a class="headerlink" href="#references" title="Link to this heading">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference external" href="https://docs.python.org/3/reference/lexical_analysis.html">Python’s lexical analysis</a></p></li>
|
||||
<li><p><a class="reference external" href="https://www.haskell.org/onlinereport/haskell2010/haskellch10.html">Haskell syntax reference</a></p></li>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h1 class="logo"><a href="../index.html">rl'</a></h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3>Navigation</h3>
|
||||
<p class="caption" role="heading"><span class="caption-text">Index</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
|
||||
</ul>
|
||||
<p class="caption" role="heading"><span class="caption-text">Commentary</span></p>
|
||||
<ul class="current">
|
||||
<li class="toctree-l1"><a class="reference internal" href="gm.html">The <em>G-Machine</em></a></li>
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">Lexing, Parsing, and Layouts</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="ti.html">The <em>Template Instantiator</em></a></li>
|
||||
</ul>
|
||||
<p class="caption" role="heading"><span class="caption-text">References</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../references/gm-state-transition-rules.html">G-Machine State Transition Rules</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../references/ti-state-transitions.html">Template Instantiator State Transition Rules</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="relations">
|
||||
<h3>Related Topics</h3>
|
||||
<ul>
|
||||
<li><a href="../index.html">Documentation overview</a><ul>
|
||||
<li>Previous: <a href="gm.html" title="previous chapter">The <em>G-Machine</em></a></li>
|
||||
<li>Next: <a href="ti.html" title="next chapter">The <em>Template Instantiator</em></a></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3 id="searchlabel">Quick search</h3>
|
||||
<div class="searchformwrapper">
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
©2023, madeleine sydney ślaga.
|
||||
|
||||
|
|
||||
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a>
|
||||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
|
||||
|
||||
|
|
||||
<a href="../_sources/commentary/layout-lexing.rst.txt"
|
||||
rel="nofollow">Page source</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
409
doc/build/html/commentary/stg.html
vendored
Normal file
409
doc/build/html/commentary/stg.html
vendored
Normal file
@@ -0,0 +1,409 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en" data-content_root="../">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<title>The Spineless Tagless G-Machine — rlp documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=4f649999" />
|
||||
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css?v=039e1c02" />
|
||||
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
|
||||
<script src="../_static/doctools.js?v=888ff710"></script>
|
||||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||||
<link rel="index" title="Index" href="../genindex.html" />
|
||||
<link rel="search" title="Search" href="../search.html" />
|
||||
<link rel="prev" title="Lexing, Parsing, and Layouts" href="layout-lexing.html" />
|
||||
|
||||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||||
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||||
|
||||
</head><body>
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
|
||||
|
||||
<div class="body" role="main">
|
||||
|
||||
<section id="the-spineless-tagless-g-machine">
|
||||
<h1>The <em>Spineless Tagless G-Machine</em><a class="headerlink" href="#the-spineless-tagless-g-machine" title="Link to this heading">¶</a></h1>
|
||||
<p>WIP. This will hopefully be expanded into a thorough walkthrough of the state
|
||||
machine.</p>
|
||||
<p>Evaluation is complete when a single <code class="code docutils literal notranslate"><span class="pre">NNum</span></code> remains on the stack and the
|
||||
dump is empty.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/51b8ee3def56618c3d5c55841743d53ffbedbcfb.svg" alt="\transrule
|
||||
{ a : \nillist
|
||||
& \nillist
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a : \mathtt{NNum} \; n
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ \mathtt{HALT}
|
||||
}"/></p>
|
||||
</div><p>Dereference an indirection passed as an argument to a function.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/e91c8c9e0530c873480544a154b5156c1a3bc5cf.svg" alt="\transrule
|
||||
{a : s & d & h
|
||||
\begin{bmatrix}
|
||||
a : \mathtt{NAp} \; a_1 \; a_2 \\
|
||||
a_2 : \mathtt{NInd} \; a_3
|
||||
\end{bmatrix} & g}
|
||||
{a : s & d & h[a : \mathtt{NAp} \; a_1 \; a_3] & g}"/></p>
|
||||
</div><p>Dereference an indirection on top of the stack.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/7a5577f4835bea58fb5e61feccfb2cac76ad365a.svg" alt="\transrule
|
||||
{p : s & d & h
|
||||
\begin{bmatrix}
|
||||
p : \mathtt{NInd} \; a
|
||||
\end{bmatrix} & g}
|
||||
{a : s & d & h & g}"/></p>
|
||||
</div><p>Perform a unary operation <img class="math" src="../_images/math/996b14e88c00afb0c157a014c7b04c192a6667d8.svg" alt="o(n)" style="vertical-align: -5px"/> with internal <code class="code docutils literal notranslate"><span class="pre">Prim</span></code> constructor
|
||||
<code class="code docutils literal notranslate"><span class="pre">O</span></code> on an argument in normal form.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/758e69f9e44c00c28db11caa744ce8468e26062d.svg" alt="\transrule
|
||||
{ f : a : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{O} \\
|
||||
a : \mathtt{NAp} \; f \; x \\
|
||||
x : \mathtt{NNum} \; n
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a : \mathtt{NNum} \; (o(n))
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Evaluate the argument of a unary operation with internal <code class="code docutils literal notranslate"><span class="pre">Prim</span></code>
|
||||
constructor <code class="code docutils literal notranslate"><span class="pre">O</span></code>.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/9264520765ac3abdf00f5cff93232ef8f436c08c.svg" alt="\transrule
|
||||
{ f : a : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{O} \\
|
||||
a : \mathtt{NAp} \; f \; x
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ x : \nillist
|
||||
& (f : a : \nillist) : d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Restore the stack when a sub-computation has completed.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/8dd8da75ac6612b08aa1c953fe79f69d9614a370.svg" alt="\transrule
|
||||
{ a : \nillist
|
||||
& s : d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a : \mathtt{NNum} \; n
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ s
|
||||
& d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Reduce a supercombinator and update the root with the <img class="math" src="../_images/math/cc9ad1bf37cbb0cbc3156f31e10ce7d8148d5e06.svg" alt="\beta" style="vertical-align: -4px"/>-reduced form</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/34e91bc0685dd54adb3e06c06e6fc0cc4d8ad419.svg" alt="\transrule
|
||||
{ a_0 : a_1 : \ldots : a_n : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_0 : \mathtt{NSupercomb} \; [x_1,\ldots,x_n] \; e
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_n : s
|
||||
& d
|
||||
& h'
|
||||
& g
|
||||
\\
|
||||
& \SetCell[c=3]{c}
|
||||
\text{where } h' = \mathtt{instantiateU} \; e \; a_n \; h \; g
|
||||
}"/></p>
|
||||
</div><p>Perform a binary operation <img class="math" src="../_images/math/a86f901ae855d64263ac2ab365517c5a7e5ccd14.svg" alt="o(x,y)" style="vertical-align: -5px"/> associated with internal <code class="code docutils literal notranslate"><span class="pre">Prim</span></code>
|
||||
constructor <code class="code docutils literal notranslate"><span class="pre">O</span></code> on two <code class="code docutils literal notranslate"><span class="pre">NNum</span></code> s both in normal form.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/021357ee48ac0e35395fa99353083fee184026dd.svg" alt="\transrule
|
||||
{ f : a_1 : a_2 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{O} \\
|
||||
a_1 : \mathtt{NAp} \; f \; (\mathtt{NNum} \; x) \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; (\mathtt{NNum} \; y)
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_2 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_2 : \mathtt{NNum} \; (o(x,y))
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>In a conditional primitive, perform the reduction if the condition has been
|
||||
evaluated as True (<code class="code docutils literal notranslate"><span class="pre">NData</span> <span class="pre">1</span> <span class="pre">[]</span></code>).</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/0a0458d62ece3f6e5019d53d0245ff5facdc5fdf.svg" alt="\transrule
|
||||
{ f : a_1 : a_2 : a_3 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{IfP} \\
|
||||
c : \mathtt{NPrim} \; (\mathtt{NData} \; 1 \; \nillist) \\
|
||||
a_1 : \mathtt{NAp} \; f \; c \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; x \\
|
||||
a_3 : \mathtt{NAp} \; a_2 \; y
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ x : s
|
||||
& d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>In a conditional primitive, perform the reduction if the condition has been
|
||||
evaluated as False (<code class="code docutils literal notranslate"><span class="pre">NData</span> <span class="pre">0</span> <span class="pre">[]</span></code>).</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/5acebcc879cae1694dcc537b99796e0dc0e0ff05.svg" alt="\transrule
|
||||
{ f : a_1 : a_2 : a_3 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{IfP} \\
|
||||
c : \mathtt{NPrim} \; (\mathtt{NData} \; 0 \; \nillist) \\
|
||||
a_1 : \mathtt{NAp} \; f \; c \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; x \\
|
||||
a_3 : \mathtt{NAp} \; a_2 \; y
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ y : s
|
||||
& d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>In a conditional primitive, evaluate the condition.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/1d1d05c2792b02598e523fd646d6268749231320.svg" alt="\transrule
|
||||
{ f : a_1 : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{IfP} \\
|
||||
a_1 : \mathtt{NAp} \; f \; x
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ x : \nillist
|
||||
& (f : a_1 : \nillist) : d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Construct <code class="code docutils literal notranslate"><span class="pre">NData</span></code> out of a constructor and its arguments</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/a540630fbb5173bbf2de2d38326e10e6977b2c18.svg" alt="\transrule
|
||||
{ c : a_1 : \ldots : a_n : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; (\mathtt{ConP} \; t \; n) \\
|
||||
a_1 : \mathtt{NAp} \; c \; x_1 \\
|
||||
\vdots \\
|
||||
a_n : \mathtt{NAp} \; a_{n-1} \; x_n
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_n : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_n : \mathtt{NData} \; t \; [x_1, \ldots, x_n]
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div><section id="pairs">
|
||||
<h2>Pairs<a class="headerlink" href="#pairs" title="Link to this heading">¶</a></h2>
|
||||
<p>Evaluate the first argument if necessary</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/1fc5e2a4ce5b523a6e99c0937d45b0f285461097.svg" alt="\transrule
|
||||
{ c : a_1 : a_2 : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; \mathtt{CasePairP} \\
|
||||
p : \mathtt{NAp} \; \_ \: \_ \\
|
||||
a_1 : \mathtt{NAp} \; c \; p \\
|
||||
a_2 : \mathtt{NAp} \; a_2 \; f
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ p : \nillist
|
||||
& (a_1 : a_2 : \nillist) : d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Perform the reduction if the first argument is in normal form</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/d13e748def2419af7ed6d97286f8f8ba95d695ab.svg" alt="\transrule
|
||||
{ c : a_1 : a_2 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; \mathtt{CasePairP} \\
|
||||
p : \mathtt{NData} \; 0 \; [x,y] \\
|
||||
a_1 : \mathtt{NAp} \; c \; p \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; f
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_1 : a_2 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_1 : \mathtt{NAp} \; f \; x \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; y
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div></section>
|
||||
<section id="lists">
|
||||
<h2>Lists<a class="headerlink" href="#lists" title="Link to this heading">¶</a></h2>
|
||||
<p>Evaluate the scrutinee</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/f670f05da2f796ded634f483374c8523a2ed0ac4.svg" alt="\transrule
|
||||
{ c : a_1 : a_2 : a_3 : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; \mathtt{CaseListP} \\
|
||||
a_1 : \mathtt{NAp} \; c \; x
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ x : \nillist
|
||||
& (a_1 : a_2 : a_3) : \nillist
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>If the scrutinee is <code class="code docutils literal notranslate"><span class="pre">Nil</span></code>, perform the appropriate reduction.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/2bfab760cd5a82cd980862645b628ea4c2a97f34.svg" alt="\transrule
|
||||
{ c : a_1 : a_2 : a_3 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; \mathtt{CaseListP} \\
|
||||
p : \mathtt{NData} \; 1 \; \nillist \\
|
||||
a_1 : \mathtt{NAp} \; c \; p \\
|
||||
a_2 : \mathtt{NAp} \; p \; f_\text{nil} \\
|
||||
a_3 : \mathtt{NAp} \; a_2 \; f_\text{cons}
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_3 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_3 : \mathtt{NAp} \; f_\text{nil}
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div></section>
|
||||
</section>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h1 class="logo"><a href="../index.html">rlp</a></h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3>Navigation</h3>
|
||||
<p class="caption" role="heading"><span class="caption-text">Index</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
|
||||
</ul>
|
||||
<p class="caption" role="heading"><span class="caption-text">Commentary</span></p>
|
||||
<ul class="current">
|
||||
<li class="toctree-l1"><a class="reference internal" href="layout-lexing.html">Lexing, Parsing, and Layouts</a></li>
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">The <em>Spineless Tagless G-Machine</em></a></li>
|
||||
</ul>
|
||||
|
||||
<div class="relations">
|
||||
<h3>Related Topics</h3>
|
||||
<ul>
|
||||
<li><a href="../index.html">Documentation overview</a><ul>
|
||||
<li>Previous: <a href="layout-lexing.html" title="previous chapter">Lexing, Parsing, and Layouts</a></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3 id="searchlabel">Quick search</h3>
|
||||
<div class="searchformwrapper">
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
©2023, madeleine sydney ślaga.
|
||||
|
||||
|
|
||||
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a>
|
||||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
|
||||
|
||||
|
|
||||
<a href="../_sources/commentary/stg.rst.txt"
|
||||
rel="nofollow">Page source</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
120
doc/build/html/commentary/ti.html
vendored
Normal file
120
doc/build/html/commentary/ti.html
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en" data-content_root="../">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<title>The Template Instantiator — rl' documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=4f649999" />
|
||||
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css?v=039e1c02" />
|
||||
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
|
||||
<script src="../_static/doctools.js?v=888ff710"></script>
|
||||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||||
<link rel="index" title="Index" href="../genindex.html" />
|
||||
<link rel="search" title="Search" href="../search.html" />
|
||||
<link rel="next" title="G-Machine State Transition Rules" href="../references/gm-state-transition-rules.html" />
|
||||
<link rel="prev" title="Lexing, Parsing, and Layouts" href="layout-lexing.html" />
|
||||
|
||||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||||
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||||
|
||||
</head><body>
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
|
||||
|
||||
<div class="body" role="main">
|
||||
|
||||
<section id="the-template-instantiator">
|
||||
<h1>The <em>Template Instantiator</em><a class="headerlink" href="#the-template-instantiator" title="Link to this heading">¶</a></h1>
|
||||
<p>WIP. This will hopefully be expanded into a thorough walkthrough of the state
|
||||
machine.</p>
|
||||
</section>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h1 class="logo"><a href="../index.html">rl'</a></h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3>Navigation</h3>
|
||||
<p class="caption" role="heading"><span class="caption-text">Index</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
|
||||
</ul>
|
||||
<p class="caption" role="heading"><span class="caption-text">Commentary</span></p>
|
||||
<ul class="current">
|
||||
<li class="toctree-l1"><a class="reference internal" href="gm.html">The <em>G-Machine</em></a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="layout-lexing.html">Lexing, Parsing, and Layouts</a></li>
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">The <em>Template Instantiator</em></a></li>
|
||||
</ul>
|
||||
<p class="caption" role="heading"><span class="caption-text">References</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../references/gm-state-transition-rules.html">G-Machine State Transition Rules</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../references/ti-state-transitions.html">Template Instantiator State Transition Rules</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="relations">
|
||||
<h3>Related Topics</h3>
|
||||
<ul>
|
||||
<li><a href="../index.html">Documentation overview</a><ul>
|
||||
<li>Previous: <a href="layout-lexing.html" title="previous chapter">Lexing, Parsing, and Layouts</a></li>
|
||||
<li>Next: <a href="../references/gm-state-transition-rules.html" title="next chapter">G-Machine State Transition Rules</a></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3 id="searchlabel">Quick search</h3>
|
||||
<div class="searchformwrapper">
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
©2023, madeleine sydney ślaga.
|
||||
|
||||
|
|
||||
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a>
|
||||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
|
||||
|
||||
|
|
||||
<a href="../_sources/commentary/ti.rst.txt"
|
||||
rel="nofollow">Page source</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
410
doc/build/html/commentary/tim.html
vendored
Normal file
410
doc/build/html/commentary/tim.html
vendored
Normal file
@@ -0,0 +1,410 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en" data-content_root="../">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<title>The Template Instantiation Machine — rlp documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=4f649999" />
|
||||
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css?v=039e1c02" />
|
||||
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
|
||||
<script src="../_static/doctools.js?v=888ff710"></script>
|
||||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||||
<link rel="index" title="Index" href="../genindex.html" />
|
||||
<link rel="search" title="Search" href="../search.html" />
|
||||
<link rel="prev" title="Lexing, Parsing, and Layouts" href="layout-lexing.html" />
|
||||
|
||||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
|
||||
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||||
|
||||
</head><body>
|
||||
|
||||
|
||||
<div class="document">
|
||||
<div class="documentwrapper">
|
||||
<div class="bodywrapper">
|
||||
|
||||
|
||||
<div class="body" role="main">
|
||||
|
||||
<section id="the-template-instantiation-machine">
|
||||
<h1>The <em>Template Instantiation Machine</em><a class="headerlink" href="#the-template-instantiation-machine" title="Link to this heading">¶</a></h1>
|
||||
<p>WIP. This will hopefully be expanded into a thorough walkthrough of the state
|
||||
machine.</p>
|
||||
<p>Evaluation is complete when a single <code class="code docutils literal notranslate"><span class="pre">NNum</span></code> remains on the stack and the
|
||||
dump is empty.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/cddff17c817c1acda8498e28276cbace394ea817.svg" alt="\transrule
|
||||
{ a : \nillist
|
||||
& \nillist
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a : \mathtt{NNum} \; n
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ \mathtt{HALT}
|
||||
}"/></p>
|
||||
</div><p>Dereference an indirection passed as an argument to a function.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/538b0fab8c90c1abe8c6abaa3c807886040452db.svg" alt="\transrule
|
||||
{a : s & d & h
|
||||
\begin{bmatrix}
|
||||
a : \mathtt{NAp} \; a_1 \; a_2 \\
|
||||
a_2 : \mathtt{NInd} \; a_3
|
||||
\end{bmatrix} & g}
|
||||
{a : s & d & h[a : \mathtt{NAp} \; a_1 \; a_3] & g}"/></p>
|
||||
</div><p>Dereference an indirection on top of the stack.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/d13a272a60d62c8a6b0ae4f178970b34b3cbc34b.svg" alt="\transrule
|
||||
{p : s & d & h
|
||||
\begin{bmatrix}
|
||||
p : \mathtt{NInd} \; a
|
||||
\end{bmatrix} & g}
|
||||
{a : s & d & h & g}"/></p>
|
||||
</div><p>Perform a unary operation <img class="math" src="../_images/math/9074d5122d0889ba7171982a92c523d35a2c447b.svg" alt="o(n)" style="vertical-align: -5px"/> with internal <code class="code docutils literal notranslate"><span class="pre">Prim</span></code> constructor
|
||||
<code class="code docutils literal notranslate"><span class="pre">O</span></code> on an argument in normal form.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/e34c3c7dbb292f28e888bfb49920d7c293055d2b.svg" alt="\transrule
|
||||
{ f : a : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{O} \\
|
||||
a : \mathtt{NAp} \; f \; x \\
|
||||
x : \mathtt{NNum} \; n
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a : \mathtt{NNum} \; (o(n))
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Evaluate the argument of a unary operation with internal <code class="code docutils literal notranslate"><span class="pre">Prim</span></code>
|
||||
constructor <code class="code docutils literal notranslate"><span class="pre">O</span></code>.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/8282bc1515ee7f12235b6cf5ec58b653adacf9ab.svg" alt="\transrule
|
||||
{ f : a : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{O} \\
|
||||
a : \mathtt{NAp} \; f \; x
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ x : \nillist
|
||||
& (f : a : \nillist) : d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Restore the stack when a sub-computation has completed.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/4004b3a0b74a3d25993573e61733383293f43681.svg" alt="\transrule
|
||||
{ a : \nillist
|
||||
& s : d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a : \mathtt{NNum} \; n
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ s
|
||||
& d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Reduce a supercombinator and update the root with the <img class="math" src="../_images/math/22bd53275636be43362c037f2ad50f5f63231e10.svg" alt="\beta" style="vertical-align: -4px"/>-reduced form</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/5cf94fab747054130daaf436fc83ab590969c35f.svg" alt="\transrule
|
||||
{ a_0 : a_1 : \ldots : a_n : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_0 : \mathtt{NSupercomb} \; [x_1,\ldots,x_n] \; e
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_n : s
|
||||
& d
|
||||
& h'
|
||||
& g
|
||||
\\
|
||||
& \SetCell[c=3]{c}
|
||||
\text{where } h' = \mathtt{instantiateU} \; e \; a_n \; h \; g
|
||||
}"/></p>
|
||||
</div><p>Perform a binary operation <img class="math" src="../_images/math/2a63b1f89224cb96d4e2b5a0f9494eac68234a42.svg" alt="o(x,y)" style="vertical-align: -5px"/> associated with internal <code class="code docutils literal notranslate"><span class="pre">Prim</span></code>
|
||||
constructor <code class="code docutils literal notranslate"><span class="pre">O</span></code> on two <code class="code docutils literal notranslate"><span class="pre">NNum</span></code> s both in normal form.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/3939cf0a8e341efac8ba1aeb5ae6271cd00c37c7.svg" alt="\transrule
|
||||
{ f : a_1 : a_2 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{O} \\
|
||||
a_1 : \mathtt{NAp} \; f \; (\mathtt{NNum} \; x) \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; (\mathtt{NNum} \; y)
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_2 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_2 : \mathtt{NNum} \; (o(x,y))
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>In a conditional primitive, perform the reduction if the condition has been
|
||||
evaluated as True (<code class="code docutils literal notranslate"><span class="pre">NData</span> <span class="pre">1</span> <span class="pre">[]</span></code>).</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/6d7f995d88e257359a4ce4f854c967791c1ec71d.svg" alt="\transrule
|
||||
{ f : a_1 : a_2 : a_3 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{IfP} \\
|
||||
c : \mathtt{NPrim} \; (\mathtt{NData} \; 1 \; \nillist) \\
|
||||
a_1 : \mathtt{NAp} \; f \; c \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; x \\
|
||||
a_3 : \mathtt{NAp} \; a_2 \; y
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ x : s
|
||||
& d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>In a conditional primitive, perform the reduction if the condition has been
|
||||
evaluated as False (<code class="code docutils literal notranslate"><span class="pre">NData</span> <span class="pre">0</span> <span class="pre">[]</span></code>).</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/96b775e1d32106f30d74a6fc743db615ea6e51ea.svg" alt="\transrule
|
||||
{ f : a_1 : a_2 : a_3 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{IfP} \\
|
||||
c : \mathtt{NPrim} \; (\mathtt{NData} \; 0 \; \nillist) \\
|
||||
a_1 : \mathtt{NAp} \; f \; c \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; x \\
|
||||
a_3 : \mathtt{NAp} \; a_2 \; y
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ y : s
|
||||
& d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>In a conditional primitive, evaluate the condition.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/fea71c9f02d3639232648b940b80e5b9c1a03db3.svg" alt="\transrule
|
||||
{ f : a_1 : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
f : \mathtt{NPrim} \; \mathtt{IfP} \\
|
||||
a_1 : \mathtt{NAp} \; f \; x
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ x : \nillist
|
||||
& (f : a_1 : \nillist) : d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Construct <code class="code docutils literal notranslate"><span class="pre">NData</span></code> out of a constructor and its arguments</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/00420770ada7197f2dc04dc2cb7be7957619046e.svg" alt="\transrule
|
||||
{ c : a_1 : \ldots : a_n : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; (\mathtt{ConP} \; t \; n) \\
|
||||
a_1 : \mathtt{NAp} \; c \; x_1 \\
|
||||
\vdots \\
|
||||
a_n : \mathtt{NAp} \; a_{n-1} \; x_n
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_n : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_n : \mathtt{NData} \; t \; [x_1, \ldots, x_n]
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div><section id="pairs">
|
||||
<h2>Pairs<a class="headerlink" href="#pairs" title="Link to this heading">¶</a></h2>
|
||||
<p>Evaluate the first argument if necessary</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/eb7dc8445c84c126f6834aa63965b5866af4862f.svg" alt="\transrule
|
||||
{ c : a_1 : a_2 : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; \mathtt{CasePairP} \\
|
||||
p : \mathtt{NAp} \; \_ \: \_ \\
|
||||
a_1 : \mathtt{NAp} \; c \; p \\
|
||||
a_2 : \mathtt{NAp} \; a_2 \; f
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ p : \nillist
|
||||
& (a_1 : a_2 : \nillist) : d
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>Perform the reduction if the first argument is in normal form</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/276f330b47308dae1686a2c0030783ed20a8866d.svg" alt="\transrule
|
||||
{ c : a_1 : a_2 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; \mathtt{CasePairP} \\
|
||||
p : \mathtt{NData} \; 0 \; [x,y] \\
|
||||
a_1 : \mathtt{NAp} \; c \; p \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; f
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_1 : a_2 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_1 : \mathtt{NAp} \; f \; x \\
|
||||
a_2 : \mathtt{NAp} \; a_1 \; y
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div></section>
|
||||
<section id="lists">
|
||||
<h2>Lists<a class="headerlink" href="#lists" title="Link to this heading">¶</a></h2>
|
||||
<p>Evaluate the scrutinee</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/11cdffb9aaad97f1748e14369a93f303987914df.svg" alt="\transrule
|
||||
{ c : a_1 : a_2 : a_3 : \nillist
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; \mathtt{CaseListP} \\
|
||||
a_1 : \mathtt{NAp} \; c \; x
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ x
|
||||
& (a_1 : a_2 : a_3) : \nillist
|
||||
& h
|
||||
& g
|
||||
}"/></p>
|
||||
</div><p>If the scrutinee is <code class="code docutils literal notranslate"><span class="pre">Nil</span></code>, perform the appropriate reduction.</p>
|
||||
<div class="math">
|
||||
<p><img src="../_images/math/3eb2a0684a9c3d7c7a02334d788b2bd85cc83b55.svg" alt="\transrule
|
||||
{ c : a_1 : a_2 : a_3 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
c : \mathtt{NPrim} \; \mathtt{CaseListP} \\
|
||||
p : \mathtt{NData} \; 1 \; \nillist \\
|
||||
a_1 : \mathtt{NAp} \; c \; p \\
|
||||
a_2 : \mathtt{NAp} \; p \; f_\text{nil} \\
|
||||
a_3 : \mathtt{NAp} \; a_2 \; f_\text{cons}
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}
|
||||
{ a_3 : s
|
||||
& d
|
||||
& h
|
||||
\begin{bmatrix}
|
||||
a_3 : \mathtt{NAp} \; f_\text{nil}
|
||||
\end{bmatrix}
|
||||
& g
|
||||
}"/></p>
|
||||
</div></section>
|
||||
</section>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||||
<div class="sphinxsidebarwrapper">
|
||||
<h1 class="logo"><a href="../index.html">rlp</a></h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3>Navigation</h3>
|
||||
<p class="caption" role="heading"><span class="caption-text">Index</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
|
||||
</ul>
|
||||
<p class="caption" role="heading"><span class="caption-text">Commentary</span></p>
|
||||
<ul class="current">
|
||||
<li class="toctree-l1"><a class="reference internal" href="gm.html">The <em>G-Machine</em></a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="layout-lexing.html">Lexing, Parsing, and Layouts</a></li>
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">The <em>Template Instantiation Machine</em></a></li>
|
||||
</ul>
|
||||
|
||||
<div class="relations">
|
||||
<h3>Related Topics</h3>
|
||||
<ul>
|
||||
<li><a href="../index.html">Documentation overview</a><ul>
|
||||
<li>Previous: <a href="layout-lexing.html" title="previous chapter">Lexing, Parsing, and Layouts</a></li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3 id="searchlabel">Quick search</h3>
|
||||
<div class="searchformwrapper">
|
||||
<form class="search" action="../search.html" method="get">
|
||||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||||
<input type="submit" value="Go" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
©2023, madeleine sydney ślaga.
|
||||
|
||||
|
|
||||
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a>
|
||||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
|
||||
|
||||
|
|
||||
<a href="../_sources/commentary/tim.rst.txt"
|
||||
rel="nofollow">Page source</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user