docs -> doc

lol
This commit is contained in:
crumbtoo
2023-12-04 14:51:44 -07:00
parent cb6321fbf8
commit 6767bd0b4f
304 changed files with 29610 additions and 0 deletions

View File

@@ -0,0 +1,459 @@
<!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>G-Machine State Transition Rules &#8212; rl&#39; 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="Template Instantiator State Transition Rules" href="ti-state-transitions.html" />
<link rel="prev" title="The Template Instantiator" href="../commentary/ti.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="g-machine-state-transition-rules">
<h1>G-Machine State Transition Rules<a class="headerlink" href="#g-machine-state-transition-rules" title="Link to this heading"></a></h1>
<section id="core-transition-rules">
<h2>Core Transition Rules<a class="headerlink" href="#core-transition-rules" title="Link to this heading"></a></h2>
<ol class="arabic simple">
<li><p>Lookup a global by name and push its value onto the stack</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/18d81e1fc22e6feb876a993fe30fd9e8336f5bf6.svg" alt="\gmrule
{ \mathtt{PushGlobal} \; f : i
&amp; s
&amp; d
&amp; h
&amp; m
\begin{bmatrix}
f : a
\end{bmatrix}
}
{ i
&amp; a : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="2">
<li><p>Allocate an int node on the heap, and push the address of the newly created
node onto the stack</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/ed6af2733291dcf5001173a8dbaf8f59c817212a.svg" alt="\gmrule
{ \mathtt{PushInt} \; n : i
&amp; s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; m
}"/></p>
</div><ol class="arabic simple" start="3">
<li><p>Allocate an application node on the heap, applying the top of the stack to
the address directly below it. The address of the application node is pushed
onto the stack.</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/607985174357bbbea2e2b47ab0694b2d21a71b35.svg" alt="\gmrule
{ \mathtt{MkAp} : i
&amp; f : x : s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NAp} \; f \; x
\end{bmatrix}
&amp; m
}"/></p>
</div><ol class="arabic simple" start="4">
<li><p>Push a functions argument onto the stack</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/643dd082a2b49d9ebdb87533aac62fdd342f4fd5.svg" alt="\gmrule
{ \mathtt{Push} \; n : i
&amp; a_0 : \ldots : a_n : s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a_n : a_0 : \ldots : a_n : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="5">
<li><p>Tidy up the stack after instantiating a supercombinator</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/f02d55fb6c249a7da5a9df6b7e5c96ab6be7672b.svg" alt="\gmrule
{ \mathtt{Slide} \; n : i
&amp; a_0 : \ldots : a_n : s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a_0 : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="6">
<li><p>If a number is on top of the stack, <code class="code docutils literal notranslate"><span class="pre">Unwind</span></code> leaves the machine in a
halt state</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/f9a521977b1461b53094f1bae24aa6d1bb757b07.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; m
}
{ \nillist
&amp; a : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="7">
<li><p>If an application is on top of the stack, <code class="code docutils literal notranslate"><span class="pre">Unwind</span></code> continues unwinding</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/b04167eaade600ab592e2a4441ffc27f5268cccf.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NAp} \; f \; x
\end{bmatrix}
&amp; m
}
{ \mathtt{Unwind} : \nillist
&amp; f : a : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="8">
<li><p>When a supercombinator is on top of the stack (and the correct number of
arguments have been provided), <code class="code docutils literal notranslate"><span class="pre">Unwind</span></code> sets up the stack and jumps to
the supercombinators code (<img class="math" src="../_images/math/90592e982322fa08f1b8ae0e6bcdaca11fc8de59.svg" alt="\beta" style="vertical-align: -4px"/>-reduction)</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/2dc5e48f0f26f08073e6e1cdd70ff876c6ec2434.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a_0 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_0 : \mathtt{NGlobal} \; n \; c \\
a_1 : \mathtt{NAp} \; a_0 \; e_1 \\
\vdots \\
a_n : \mathtt{NAp} \; a_{n-1} \; e_n \\
\end{bmatrix}
&amp; m
}
{ c
&amp; e_1 : \ldots : e_n : a_n : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="9">
<li><p>Pop the stack, and update the nth node to point to the popped address</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/e299a147e6e958303111e813e82a3507ded25437.svg" alt="\gmrule
{ \mathtt{Update} \; n : i
&amp; e : f : a_1 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_1 : \mathtt{NAp} \; f \; e \\
\vdots \\
a_n : \mathtt{NAp} \; a_{n-1} \; e_n
\end{bmatrix}
&amp; m
}
{ i
&amp; f : a_1 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_n : \mathtt{NInd} \; e
\end{bmatrix}
&amp; m
}"/></p>
</div><ol class="arabic simple" start="10">
<li><p>Pop the stack.</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/aec9099fc8c459eb433947bd6c9cc0f96fe38f98.svg" alt="\gmrule
{ \mathtt{Pop} \; n : i
&amp; a_1 : \ldots : a_n : s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; s
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="11">
<li><p>Follow indirections while unwinding</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/7648bfc0796ff33966fbc002c446b2242d296fd9.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NInd} \; a'
\end{bmatrix}
&amp; m
}
{ \mathtt{Unwind} : \nillist
&amp; a' : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="12">
<li><p>Allocate uninitialised heap space</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/5380d8227d0a06608b108a26b4a618972b4b7e28.svg" alt="\gmrule
{ \mathtt{Alloc} \; n : i
&amp; s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a_1 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_1 : \mathtt{NUninitialised} \\
\vdots \\
a_n : \mathtt{NUninitialised} \\
\end{bmatrix}
&amp; m
}"/></p>
</div><ol class="arabic simple" start="13">
<li><p>When unwinding, if the top of the stack is in WHNF, pop the dump</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/2417422cdf63ed202b16462208f8a62630f99679.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a : s
&amp; \langle i', s' \rangle : d
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; m
}
{ i'
&amp; a : s'
&amp; d
&amp; h
&amp; m
}"/></p>
</div><ol class="arabic simple" start="14">
<li><p>Evaluate the top of the stack to WHNF</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/e56dfd5625638bc4ad9867951a7818cf20c88a2f.svg" alt="\gmrule
{ \mathtt{Eval} : i
&amp; a : s
&amp; d
&amp; h
&amp; m
}
{ i'
&amp; a : \nillist
&amp; \langle i, s \rangle
&amp; h
&amp; m
}"/></p>
</div></section>
<section id="extension-rules">
<h2>Extension Rules<a class="headerlink" href="#extension-rules" title="Link to this heading"></a></h2>
<ol class="arabic simple">
<li><p>A sneaky trick to enable sharing of <code class="code docutils literal notranslate"><span class="pre">NNum</span></code> nodes. We note that the
global environment is a mapping of <code class="code docutils literal notranslate"><span class="pre">Name</span></code> objects (i.e. identifiers) to
heap addresses. Strings of digits are not considered valid identifiers! We
abuse this by modifying Core Rule 2 to update the global environment with the
new nodes address. Consider how this rule might impact garbage collection
(remember that the environment is intended for <em>globals</em>).</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/5a00c38ab6f040dfa75be56918953af44dc11637.svg" alt="\gmrule
{ \mathtt{PushInt} \; n : i
&amp; s
&amp; h
&amp; m
}
{ i
&amp; a : s
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; m
\begin{bmatrix}
n' : a
\end{bmatrix}
\\
\SetCell[c=5]{c}
\text{where $n'$ is the base-10 string rep. of $n$}
}"/></p>
</div><ol class="arabic simple" start="2">
<li><p>In order for Extension Rule 1. to be effective, we are also required to take
action when a number already exists in the environment:</p></li>
</ol>
<div class="math">
<p><img src="../_images/math/3fc332dc07916d83f75fcddf6da06a7734032ee9.svg" alt="\transrule
{ \mathtt{PushInt} \; n : i
&amp; s
&amp; h
&amp; m
\begin{bmatrix}
n' : a
\end{bmatrix}
}
{ i
&amp; a : s
&amp; h
&amp; m
\\
\SetCell[c=5]{c}
\text{where $n'$ is the base-10 string rep. of $n$}
}"/></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">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>
<li class="toctree-l1"><a class="reference internal" href="../commentary/gm.html">The <em>G-Machine</em></a></li>
<li class="toctree-l1"><a class="reference internal" href="../commentary/layout-lexing.html">Lexing, Parsing, and Layouts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../commentary/ti.html">The <em>Template Instantiator</em></a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">References</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">G-Machine State Transition Rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="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="../commentary/ti.html" title="previous chapter">The <em>Template Instantiator</em></a></li>
<li>Next: <a href="ti-state-transitions.html" title="next chapter">Template Instantiator 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">
&copy;2023, madeleine sydney ślaga.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
|
<a href="../_sources/references/gm-state-transition-rules.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>

View File

@@ -0,0 +1,521 @@
<!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>G-Machine State Transition Rules &#8212; rl&#39; 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="Template Instantiator State Transition Rules" href="ti-state-transitions.html" />
<link rel="prev" title="The Template Instantiator" href="../commentary/ti.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="g-machine-state-transition-rules">
<h1>G-Machine State Transition Rules<a class="headerlink" href="#g-machine-state-transition-rules" title="Link to this heading"></a></h1>
<section id="core-transition-rules">
<h2>Core Transition Rules<a class="headerlink" href="#core-transition-rules" title="Link to this heading"></a></h2>
<ol class="arabic">
<li><p>Lookup a global by name and push its value onto the stack</p>
<div class="math">
<p><img src="../_images/math/18d81e1fc22e6feb876a993fe30fd9e8336f5bf6.svg" alt="\gmrule
{ \mathtt{PushGlobal} \; f : i
&amp; s
&amp; d
&amp; h
&amp; m
\begin{bmatrix}
f : a
\end{bmatrix}
}
{ i
&amp; a : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>Allocate an int node on the heap, and push the address of the newly created
node onto the stack</p>
<div class="math">
<p><img src="../_images/math/ed6af2733291dcf5001173a8dbaf8f59c817212a.svg" alt="\gmrule
{ \mathtt{PushInt} \; n : i
&amp; s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; m
}"/></p>
</div></li>
<li><p>Allocate an application node on the heap, applying the top of the stack to
the address directly below it. The address of the application node is pushed
onto the stack.</p>
<div class="math">
<p><img src="../_images/math/607985174357bbbea2e2b47ab0694b2d21a71b35.svg" alt="\gmrule
{ \mathtt{MkAp} : i
&amp; f : x : s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NAp} \; f \; x
\end{bmatrix}
&amp; m
}"/></p>
</div></li>
<li><p>Push a functions argument onto the stack</p>
<div class="math">
<p><img src="../_images/math/643dd082a2b49d9ebdb87533aac62fdd342f4fd5.svg" alt="\gmrule
{ \mathtt{Push} \; n : i
&amp; a_0 : \ldots : a_n : s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a_n : a_0 : \ldots : a_n : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>Tidy up the stack after instantiating a supercombinator</p>
<div class="math">
<p><img src="../_images/math/f02d55fb6c249a7da5a9df6b7e5c96ab6be7672b.svg" alt="\gmrule
{ \mathtt{Slide} \; n : i
&amp; a_0 : \ldots : a_n : s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a_0 : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>If the top of the stack is in WHNF (currently this just means a number) is on
top of the stack, <code class="code docutils literal notranslate"><span class="pre">Unwind</span></code> considers evaluation complete. In the case
where the dump is <strong>not</strong> empty, the instruction queue and stack is restored
from the top.</p>
<div class="math">
<p><img src="../_images/math/2417422cdf63ed202b16462208f8a62630f99679.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a : s
&amp; \langle i', s' \rangle : d
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; m
}
{ i'
&amp; a : s'
&amp; d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>Bulding on the previous rule, in the case where the dump <strong>is</strong> empty, leave
the machine in a halt state (i.e. with an empty instruction queue).</p>
<div class="math">
<p><img src="../_images/math/60f4e38bb9ff4a7bcb201e82cb956a3ccf064632.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a : s
&amp; \nillist
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; m
}
{ \nillist
&amp; a : s
&amp; \nillist
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>If an application is on top of the stack, <code class="code docutils literal notranslate"><span class="pre">Unwind</span></code> continues unwinding</p>
<div class="math">
<p><img src="../_images/math/b04167eaade600ab592e2a4441ffc27f5268cccf.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NAp} \; f \; x
\end{bmatrix}
&amp; m
}
{ \mathtt{Unwind} : \nillist
&amp; f : a : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>When a supercombinator is on top of the stack (and the correct number of
arguments have been provided), <code class="code docutils literal notranslate"><span class="pre">Unwind</span></code> sets up the stack and jumps to
the supercombinators code (<img class="math" src="../_images/math/90592e982322fa08f1b8ae0e6bcdaca11fc8de59.svg" alt="\beta" style="vertical-align: -4px"/>-reduction)</p>
<div class="math">
<p><img src="../_images/math/2dc5e48f0f26f08073e6e1cdd70ff876c6ec2434.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a_0 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_0 : \mathtt{NGlobal} \; n \; c \\
a_1 : \mathtt{NAp} \; a_0 \; e_1 \\
\vdots \\
a_n : \mathtt{NAp} \; a_{n-1} \; e_n \\
\end{bmatrix}
&amp; m
}
{ c
&amp; e_1 : \ldots : e_n : a_n : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>Pop the stack, and update the nth node to point to the popped address</p>
<div class="math">
<p><img src="../_images/math/e299a147e6e958303111e813e82a3507ded25437.svg" alt="\gmrule
{ \mathtt{Update} \; n : i
&amp; e : f : a_1 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_1 : \mathtt{NAp} \; f \; e \\
\vdots \\
a_n : \mathtt{NAp} \; a_{n-1} \; e_n
\end{bmatrix}
&amp; m
}
{ i
&amp; f : a_1 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_n : \mathtt{NInd} \; e
\end{bmatrix}
&amp; m
}"/></p>
</div></li>
<li><p>Pop the stack.</p>
<div class="math">
<p><img src="../_images/math/aec9099fc8c459eb433947bd6c9cc0f96fe38f98.svg" alt="\gmrule
{ \mathtt{Pop} \; n : i
&amp; a_1 : \ldots : a_n : s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; s
&amp; d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>Follow indirections while unwinding</p>
<div class="math">
<p><img src="../_images/math/7648bfc0796ff33966fbc002c446b2242d296fd9.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NInd} \; a'
\end{bmatrix}
&amp; m
}
{ \mathtt{Unwind} : \nillist
&amp; a' : s
&amp; d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>Allocate uninitialised heap space</p>
<div class="math">
<p><img src="../_images/math/5380d8227d0a06608b108a26b4a618972b4b7e28.svg" alt="\gmrule
{ \mathtt{Alloc} \; n : i
&amp; s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a_1 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_1 : \mathtt{NUninitialised} \\
\vdots \\
a_n : \mathtt{NUninitialised} \\
\end{bmatrix}
&amp; m
}"/></p>
</div></li>
<li><p>Evaluate the top of the stack to WHNF</p>
<div class="math">
<p><img src="../_images/math/ce745b5797483cfcb6ff4816364d91d3d5b6e6c4.svg" alt="\gmrule
{ \mathtt{Eval} : i
&amp; a : s
&amp; d
&amp; h
&amp; m
}
{ \mathtt{Unwind} : \nillist
&amp; a : \nillist
&amp; \langle i, s \rangle : d
&amp; h
&amp; m
}"/></p>
</div></li>
<li><p>Reduce a primitive binary operator <img class="math" src="../_images/math/43434266ad5b9f36d523d70ff88db5c4e9366b03.svg" alt="*" style="vertical-align: 0px"/>.</p>
<div class="math">
<p><img src="../_images/math/176a0e2360b1e342041d8129c3a264321ae806ce.svg" alt="\gmrule
{ * : i
&amp; a_1 : a_2 : s
&amp; d
&amp; h
\begin{bmatrix}
a_1 : x \\
a_2 : y
\end{bmatrix}
&amp; m
}
{ i
&amp; a' : s
&amp; d
&amp; h
\begin{bmatrix}
a' : (x * y)
\end{bmatrix}
&amp; m
}"/></p>
</div></li>
<li><p>Reduce a primitive unary operator <img class="math" src="../_images/math/604a42b94739b04fa9559a97c3703816bf57aa5c.svg" alt="\neg" style="vertical-align: 0px"/>.</p>
<div class="math">
<p><img src="../_images/math/6de99ea1d6d13dbeedcdfcf7e3807cdd4f2e8594.svg" alt="\gmrule
{ \neg : i
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : x
\end{bmatrix}
&amp; m
}
{ i
&amp; a' : s
&amp; d
&amp; h
\begin{bmatrix}
a' : (\neg x)
\end{bmatrix}
&amp; m
}"/></p>
</div></li>
<li><p>Consider unapplied functions to be in WHNF</p>
<div class="math">
<p><img src="../_images/math/702f28367db2bbf757f819d55f238962369384ad.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist
&amp; a_0 : \ldots : a_n : \nillist
&amp; \langle i, s \rangle : d
&amp; h
\begin{bmatrix}
a_0 : \mathtt{NGlobal} \; k \; c
\end{bmatrix}
&amp; m
}
{ i
&amp; a_n : s
&amp; d
&amp; h
&amp; m \\
\SetCell[c=2]{c}
\text{when $n &lt; k$}
}"/></p>
</div></li>
</ol>
</section>
<section id="extension-rules">
<h2>Extension Rules<a class="headerlink" href="#extension-rules" title="Link to this heading"></a></h2>
<ol class="arabic">
<li><p>A sneaky trick to enable sharing of <code class="code docutils literal notranslate"><span class="pre">NNum</span></code> nodes. We note that the
global environment is a mapping of plain old strings to heap addresses.
Strings of digits are not considered valid identifiers, so putting them on
the global environment will never conflict with a supercombinator! We abuse
this by modifying Core Rule 2 to update the global environment with the new
nodes address. Consider how this rule might impact garbage collection
(remember that the environment is intended for <em>globals</em>).</p>
<div class="math">
<p><img src="../_images/math/0fc7c9df5cc4f923f6953e615c1f28a6531c0b68.svg" alt="\gmrule
{ \mathtt{PushInt} \; n : i
&amp; s
&amp; d
&amp; h
&amp; m
}
{ i
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; m
\begin{bmatrix}
n' : a
\end{bmatrix}
\\
\SetCell[c=5]{c}
\text{where $n'$ is the base-10 string rep. of $n$}
}"/></p>
</div></li>
<li><p>In order for the previous rule to be effective, we are also required to take
action when a number already exists in the environment:</p>
<div class="math">
<p><img src="../_images/math/d56941a661a880391bd898f16e5dcf9c0b8a7e59.svg" alt="\gmrule
{ \mathtt{PushInt} \; n : i
&amp; s
&amp; d
&amp; h
&amp; m
\begin{bmatrix}
n' : a
\end{bmatrix}
}
{ i
&amp; a : s
&amp; d
&amp; h
&amp; m
\\
\SetCell[c=5]{c}
\text{where $n'$ is the base-10 string rep. of $n$}
}"/></p>
</div></li>
</ol>
</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>
<li class="toctree-l1"><a class="reference internal" href="../commentary/gm.html">The <em>G-Machine</em></a></li>
<li class="toctree-l1"><a class="reference internal" href="../commentary/layout-lexing.html">Lexing, Parsing, and Layouts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../commentary/ti.html">The <em>Template Instantiator</em></a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">References</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">G-Machine State Transition Rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="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="../commentary/ti.html" title="previous chapter">The <em>Template Instantiator</em></a></li>
<li>Next: <a href="ti-state-transitions.html" title="next chapter">Template Instantiator 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">
&copy;2023, madeleine sydney ślaga.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
|
<a href="../_sources/references/gm-state-transitions.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>

View File

@@ -0,0 +1,413 @@
<!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>Template Instantiator State Transition Rules &#8212; rl&#39; 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="G-Machine State Transition Rules" href="gm-state-transition-rules.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="template-instantiator-state-transition-rules">
<h1>Template Instantiator State Transition Rules<a class="headerlink" href="#template-instantiator-state-transition-rules" title="Link to this heading"></a></h1>
<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/90d7e53e2606d1ffdcc0d85fcc0be2db9b919797.svg" alt="\transrule
{ a : \nillist
&amp; \nillist
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; 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/2e21d478eedaa358bccb9aa3c57a5b290e671863.svg" alt="\transrule
{a : s &amp; d &amp; h
\begin{bmatrix}
a : \mathtt{NAp} \; a_1 \; a_2 \\
a_2 : \mathtt{NInd} \; a_3
\end{bmatrix} &amp; g}
{a : s &amp; d &amp; h[a : \mathtt{NAp} \; a_1 \; a_3] &amp; g}"/></p>
</div><p>Dereference an indirection on top of the stack.</p>
<div class="math">
<p><img src="../_images/math/d30cef88d057bcc5920fca7d63d0682f802d9006.svg" alt="\transrule
{p : s &amp; d &amp; h
\begin{bmatrix}
p : \mathtt{NInd} \; a
\end{bmatrix} &amp; g}
{a : s &amp; d &amp; h &amp; g}"/></p>
</div><p>Perform a unary operation <img class="math" src="../_images/math/6bdb1b0b4006f5b62d10449cd280f311f4cf12f8.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/e4dc66520823a07e0df31b43dda92f9b2ea9e792.svg" alt="\transrule
{ f : a : s
&amp; d
&amp; h
\begin{bmatrix}
f : \mathtt{NPrim} \; \mathtt{O} \\
a : \mathtt{NAp} \; f \; x \\
x : \mathtt{NNum} \; n
\end{bmatrix}
&amp; g
}
{ a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; (o(n))
\end{bmatrix}
&amp; 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/620e45afe56ccc0dae7d9566d244b13bb6cb0631.svg" alt="\transrule
{ f : a : \nillist
&amp; d
&amp; h
\begin{bmatrix}
f : \mathtt{NPrim} \; \mathtt{O} \\
a : \mathtt{NAp} \; f \; x
\end{bmatrix}
&amp; g
}
{ x : \nillist
&amp; (f : a : \nillist) : d
&amp; h
&amp; g
}"/></p>
</div><p>Restore the stack when a sub-computation has completed.</p>
<div class="math">
<p><img src="../_images/math/4d427448f9b8b54db19e316c805033a7abfe11d2.svg" alt="\transrule
{ a : \nillist
&amp; s : d
&amp; h
\begin{bmatrix}
a : \mathtt{NNum} \; n
\end{bmatrix}
&amp; g
}
{ s
&amp; d
&amp; h
&amp; g
}"/></p>
</div><p>Reduce a supercombinator and update the root with the <img class="math" src="../_images/math/90592e982322fa08f1b8ae0e6bcdaca11fc8de59.svg" alt="\beta" style="vertical-align: -4px"/>-reduced form</p>
<div class="math">
<p><img src="../_images/math/20219b0570be52c3f596972c4cd5461a162cccf9.svg" alt="\transrule
{ a_0 : a_1 : \ldots : a_n : s
&amp; d
&amp; h
\begin{bmatrix}
a_0 : \mathtt{NSupercomb} \; [x_1,\ldots,x_n] \; e
\end{bmatrix}
&amp; g
}
{ a_n : s
&amp; d
&amp; h'
&amp; g
\\
&amp; \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/c9ac657e040edf18bbbf248d15d73ab640a93f2d.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/7c31cda93cce15a6bef0ecb07b4221f15d15cc9f.svg" alt="\transrule
{ f : a_1 : a_2 : s
&amp; d
&amp; 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}
&amp; g
}
{ a_2 : s
&amp; d
&amp; h
\begin{bmatrix}
a_2 : \mathtt{NNum} \; (o(x,y))
\end{bmatrix}
&amp; 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/1543958253280895e6abea369c0f9abf4898649c.svg" alt="\transrule
{ f : a_1 : a_2 : a_3 : s
&amp; d
&amp; 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}
&amp; g
}
{ x : s
&amp; d
&amp; h
&amp; 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/6d95eec30809d2f72c4d645e69ee6ba5fd3f0767.svg" alt="\transrule
{ f : a_1 : a_2 : a_3 : s
&amp; d
&amp; 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}
&amp; g
}
{ y : s
&amp; d
&amp; h
&amp; g
}"/></p>
</div><p>In a conditional primitive, evaluate the condition.</p>
<div class="math">
<p><img src="../_images/math/625a1ccce064b171eb9d5ec015e07d234ef26c74.svg" alt="\transrule
{ f : a_1 : \nillist
&amp; d
&amp; h
\begin{bmatrix}
f : \mathtt{NPrim} \; \mathtt{IfP} \\
a_1 : \mathtt{NAp} \; f \; x
\end{bmatrix}
&amp; g
}
{ x : \nillist
&amp; (f : a_1 : \nillist) : d
&amp; h
&amp; 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/b0285722e6eed4a0fa69945efe4dfe0fbe124582.svg" alt="\transrule
{ c : a_1 : \ldots : a_n : \nillist
&amp; d
&amp; 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}
&amp; g
}
{ a_n : \nillist
&amp; d
&amp; h
\begin{bmatrix}
a_n : \mathtt{NData} \; t \; [x_1, \ldots, x_n]
\end{bmatrix}
&amp; 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/478aeca314882e29dc3a52d64624061fb36948f0.svg" alt="\transrule
{ c : a_1 : a_2 : \nillist
&amp; d
&amp; 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}
&amp; g
}
{ p : \nillist
&amp; (a_1 : a_2 : \nillist) : d
&amp; h
&amp; g
}"/></p>
</div><p>Perform the reduction if the first argument is in normal form</p>
<div class="math">
<p><img src="../_images/math/c5937687478d980ab66b85de909dcb73d4bc9b13.svg" alt="\transrule
{ c : a_1 : a_2 : s
&amp; d
&amp; 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}
&amp; g
}
{ a_1 : a_2 : s
&amp; d
&amp; h
\begin{bmatrix}
a_1 : \mathtt{NAp} \; f \; x \\
a_2 : \mathtt{NAp} \; a_1 \; y
\end{bmatrix}
&amp; 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/5bd3cd582dce130ac602d5d805972076e5bc0f56.svg" alt="\transrule
{ c : a_1 : a_2 : a_3 : \nillist
&amp; d
&amp; h
\begin{bmatrix}
c : \mathtt{NPrim} \; \mathtt{CaseListP} \\
a_1 : \mathtt{NAp} \; c \; x
\end{bmatrix}
&amp; g
}
{ x
&amp; (a_1 : a_2 : a_3) : \nillist
&amp; h
&amp; 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/a6502e03af9f1e3d8a7dce9053c7125364a0cae5.svg" alt="\transrule
{ c : a_1 : a_2 : a_3 : s
&amp; d
&amp; 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}
&amp; g
}
{ a_3 : s
&amp; d
&amp; h
\begin{bmatrix}
a_3 : \mathtt{NAp} \; f_\text{nil}
\end{bmatrix}
&amp; 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">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>
<li class="toctree-l1"><a class="reference internal" href="../commentary/gm.html">The <em>G-Machine</em></a></li>
<li class="toctree-l1"><a class="reference internal" href="../commentary/layout-lexing.html">Lexing, Parsing, and Layouts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../commentary/ti.html">The <em>Template Instantiator</em></a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">References</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="gm-state-transition-rules.html">G-Machine State Transition Rules</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">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-state-transition-rules.html" title="previous 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">
&copy;2023, madeleine sydney ślaga.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.2.6</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
|
<a href="../_sources/references/ti-state-transitions.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>