This commit is contained in:
crumbtoo
2023-12-04 19:52:35 -07:00
parent cb7c4fed95
commit cb0de3b26b
23 changed files with 218 additions and 92 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
dist-newstyle/ dist-newstyle/
docs/build/ doc/build/

View File

@@ -11,7 +11,7 @@ imitating Haskell.
$ cabal build # Build the rlpc compiler $ cabal build # Build the rlpc compiler
$ cabal install # Install rlpc to $PATH $ cabal install # Install rlpc to $PATH
$ cabal haddock # Build the API docs w/ Haddock $ cabal haddock # Build the API docs w/ Haddock
$ make -C docs html # Build the primary docs w/ Sphinx $ make -C doc html # Build the primary docs w/ Sphinx
``` ```
### Use ### Use

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
# Sphinx build info version 1 # Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: c908097bffb8af037d3087e1a2a33716 config: 5e2d340d1e45c11873a642aae3004db1
tags: 645f666f9bcd5a90fca523b33c5a78b7 tags: 645f666f9bcd5a90fca523b33c5a78b7

View File

@@ -147,6 +147,29 @@ Core Transition Rules
& m & m
} }
#. Again, building on the previous rules, this rule makes the machine consider
unapplied supercombinators to be in WHNF
.. math::
\gmrule
{ \mathtt{Unwind} : \nillist
& a_0 : \ldots : a_n : \nillist
& \langle i, s \rangle : d
& h
\begin{bmatrix}
a_0 : \mathtt{NGlobal} \; k \; c
\end{bmatrix}
& m
}
{ i
& a_n : s
& d
& h
& m \\
\SetCell[c=2]{c}
\text{when $n < k$}
}
#. If an application is on top of the stack, :code:`Unwind` continues unwinding #. If an application is on top of the stack, :code:`Unwind` continues unwinding
.. math:: .. math::
@@ -340,28 +363,47 @@ Core Transition Rules
& m & m
} }
#. Consider unapplied functions to be in WHNF #. Pack a constructor if there are sufficient arguments
.. math:: .. math::
\gmrule \gmrule
{ \mathtt{Unwind} : \nillist { \mathtt{Pack} \; t \; n : i
& a_0 : \ldots : a_n : \nillist & a_1 : \ldots : a_n : s
& \langle i, s \rangle : d & d
& h & h
\begin{bmatrix}
a_0 : \mathtt{NGlobal} \; k \; c
\end{bmatrix}
& m & m
} }
{ i { i
& a_n : s & a : s
& d & d
& h & h
& m \\ \begin{bmatrix}
\SetCell[c=2]{c} a : \mathtt{NConstr} \; t \; [a_1,\ldots,a_n]
\text{when $n < k$} \end{bmatrix}
& m
} }
#. Evaluate a case
.. math::
\gmrule
{ \mathtt{CaseJump} \begin{bmatrix} t \to c \end{bmatrix} : i
& a : s
& d
& h
\begin{bmatrix}
a : \mathtt{NConstr} \; t \; v
\end{bmatrix}
& m
}
{ c \concat i
& d
& h
& m
}
*************** ***************
Extension Rules Extension Rules
*************** ***************

View File

@@ -42,7 +42,7 @@ heap nodes for supercombinators hold uninstantiated expressions, i.e. raw ASTs
straight from the parser. When a supercombinator is found on the stack during straight from the parser. When a supercombinator is found on the stack during
evaluation, the template expression is instantiated (compiled) on the spot.</p> evaluation, the template expression is instantiated (compiled) on the spot.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/20219b0570be52c3f596972c4cd5461a162cccf9.svg" alt="\transrule <p><img src="../_images/math/80185f417c32abbbd850f4429d27d4111dd55ce6.svg" alt="\transrule
{ a_0 : a_1 : \ldots : a_n : s { a_0 : a_1 : \ldots : a_n : s
&amp; d &amp; d
&amp; h &amp; h

View File

@@ -130,10 +130,10 @@ select few keywords, (with a minor exception; TODO: elaborate) being <code class
<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) <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 (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 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 is either <img class="math" src="../_images/math/6faf6a045e27fb9580834eb16635f0b1b12383f7.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 and semicolons, or a <img class="math" src="../_images/math/e5dd0a588910147c24912f9e7af7b4d0341033f0.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 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> <img class="math" src="../_images/math/dd0f75121d1d307be1181c273815e8532abda5ff.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> <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="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>
@@ -154,9 +154,9 @@ implicitly inserted by the compiler. With the presented ideas in mind, we may
begin to introduce a small set of informal rules describing the lexers handling begin to introduce a small set of informal rules describing the lexers handling
of layouts, the first being:</p> of layouts, the first being:</p>
<ol class="arabic simple"> <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"/> <li><p>If a layout keyword is followed by the token {, push <img class="math" src="../_images/math/6faf6a045e27fb9580834eb16635f0b1b12383f7.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 onto the layout context stack. Otherwise, push <img class="math" src="../_images/math/e5dd0a588910147c24912f9e7af7b4d0341033f0.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 the layout context stack where <img class="math" src="../_images/math/dd0f75121d1d307be1181c273815e8532abda5ff.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 following the layout keyword. Additionally, the lexer is to insert a virtual
opening brace after the token representing the layout keyword.</p></li> opening brace after the token representing the layout keyword.</p></li>
</ol> </ol>
@@ -179,10 +179,10 @@ numeric value is referred to as <em>offside</em> by myself internally and th
Haskell report describing layouts. We informally formalise this rule as follows:</p> Haskell report describing layouts. We informally formalise this rule as follows:</p>
<ol class="arabic simple" start="2"> <ol class="arabic simple" start="2">
<li><p>When the first token on a line is preceeded only by whitespace, if the <li><p>When the first token on a line is preceeded only by whitespace, if the
tokens first grapheme resides on a column number <img class="math" src="../_images/math/422ce4de46a354723a0f5b33995d885c86bb0e70.svg" alt="m" style="vertical-align: 0px"/> equal to the tokens first grapheme resides on a column number <img class="math" src="../_images/math/3fe28d6b2db64823422b040f22663ee146752df9.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 indentation level of the enclosing context i.e. the <img class="math" src="../_images/math/e867fb287fff102859aafc9f9cdf2bdef24793c1.svg" alt="\langle n
\rangle" style="vertical-align: -5px"/> on top of the layout stack. Should no such context exist on the \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 &gt; n" style="vertical-align: -1px"/>.</p></li> stack, assume <img class="math" src="../_images/math/7752bffe36066cce1a71cee99ba78f9a8de27750.svg" alt="m &gt; n" style="vertical-align: -1px"/>.</p></li>
</ol> </ol>
<p>We have an idea of how to begin layouts, delimit the enclosed items, and last <p>We have an idea of how to begin layouts, delimit the enclosed items, and last
well need to end layouts. This is where the distinction between virtual and well need to end layouts. This is where the distinction between virtual and
@@ -192,7 +192,7 @@ 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 naïvely inserting a virtual closing brace when a token is indented right of the
layout.</p> layout.</p>
<ol class="arabic simple" start="3"> <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 &lt; n" style="vertical-align: -1px"/> the lexer shall <li><p>Under the same conditions as rule 2., when <img class="math" src="../_images/math/621c205d829260a0ef518dbf23fd02478575f1d5.svg" alt="m &lt; n" style="vertical-align: -1px"/> the lexer shall
insert a virtual closing brace and pop the layout stack.</p></li> insert a virtual closing brace and pop the layout stack.</p></li>
</ol> </ol>
<p>This rule covers some cases including the top-level, however, consider <p>This rule covers some cases including the top-level, however, consider
@@ -271,7 +271,7 @@ system, see <a class="reference external" href="https://www.haskell.org/onlinere
</ul> </ul>
<p class="caption" role="heading"><span class="caption-text">References</span></p> <p class="caption" role="heading"><span class="caption-text">References</span></p>
<ul> <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/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> <li class="toctree-l1"><a class="reference internal" href="../references/ti-state-transitions.html">Template Instantiator State Transition Rules</a></li>
</ul> </ul>

View File

@@ -13,7 +13,7 @@
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script> <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="../genindex.html" /> <link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.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="next" title="G-Machine State Transition Rules" href="../references/gm-state-transitions.html" />
<link rel="prev" title="Lexing, Parsing, and Layouts" href="layout-lexing.html" /> <link rel="prev" title="Lexing, Parsing, and Layouts" href="layout-lexing.html" />
<link rel="stylesheet" href="../_static/custom.css" type="text/css" /> <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
@@ -66,7 +66,7 @@ machine.</p>
</ul> </ul>
<p class="caption" role="heading"><span class="caption-text">References</span></p> <p class="caption" role="heading"><span class="caption-text">References</span></p>
<ul> <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/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> <li class="toctree-l1"><a class="reference internal" href="../references/ti-state-transitions.html">Template Instantiator State Transition Rules</a></li>
</ul> </ul>
@@ -75,7 +75,7 @@ machine.</p>
<ul> <ul>
<li><a href="../index.html">Documentation overview</a><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>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> <li>Next: <a href="../references/gm-state-transitions.html" title="next chapter">G-Machine State Transition Rules</a></li>
</ul></li> </ul></li>
</ul> </ul>
</div> </div>

View File

@@ -76,7 +76,7 @@ code using alignment and newlines.</p>
</ul> </ul>
<p class="caption" role="heading"><span class="caption-text">References</span></p> <p class="caption" role="heading"><span class="caption-text">References</span></p>
<ul> <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/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> <li class="toctree-l1"><a class="reference internal" href="references/ti-state-transitions.html">Template Instantiator State Transition Rules</a></li>
</ul> </ul>

View File

@@ -38,7 +38,7 @@
<ol class="arabic"> <ol class="arabic">
<li><p>Lookup a global by name and push its value onto the stack</p> <li><p>Lookup a global by name and push its value onto the stack</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/18d81e1fc22e6feb876a993fe30fd9e8336f5bf6.svg" alt="\gmrule <p><img src="../_images/math/60f03d9ff8b2e1f335d16830ee203156e6d3a0e0.svg" alt="\gmrule
{ \mathtt{PushGlobal} \; f : i { \mathtt{PushGlobal} \; f : i
&amp; s &amp; s
&amp; d &amp; d
@@ -58,7 +58,7 @@
<li><p>Allocate an int node on the heap, and push the address of the newly created <li><p>Allocate an int node on the heap, and push the address of the newly created
node onto the stack</p> node onto the stack</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/ed6af2733291dcf5001173a8dbaf8f59c817212a.svg" alt="\gmrule <p><img src="../_images/math/0fabf97e10f5c112eb5642765c57eee467a61a24.svg" alt="\gmrule
{ \mathtt{PushInt} \; n : i { \mathtt{PushInt} \; n : i
&amp; s &amp; s
&amp; d &amp; d
@@ -79,7 +79,7 @@ node onto the stack</p>
the address directly below it. The address of the application node is pushed the address directly below it. The address of the application node is pushed
onto the stack.</p> onto the stack.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/607985174357bbbea2e2b47ab0694b2d21a71b35.svg" alt="\gmrule <p><img src="../_images/math/9d2842813d1c6c9703d6ebe1e7eeaf0d7ae121a6.svg" alt="\gmrule
{ \mathtt{MkAp} : i { \mathtt{MkAp} : i
&amp; f : x : s &amp; f : x : s
&amp; d &amp; d
@@ -98,7 +98,7 @@ onto the stack.</p>
</div></li> </div></li>
<li><p>Push a functions argument onto the stack</p> <li><p>Push a functions argument onto the stack</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/643dd082a2b49d9ebdb87533aac62fdd342f4fd5.svg" alt="\gmrule <p><img src="../_images/math/172a9e6498882cf2bfd038cf83d83f03e4c0313f.svg" alt="\gmrule
{ \mathtt{Push} \; n : i { \mathtt{Push} \; n : i
&amp; a_0 : \ldots : a_n : s &amp; a_0 : \ldots : a_n : s
&amp; d &amp; d
@@ -114,7 +114,7 @@ onto the stack.</p>
</div></li> </div></li>
<li><p>Tidy up the stack after instantiating a supercombinator</p> <li><p>Tidy up the stack after instantiating a supercombinator</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/f02d55fb6c249a7da5a9df6b7e5c96ab6be7672b.svg" alt="\gmrule <p><img src="../_images/math/4924a6c6d457db21cd5e02efdc8efd2af4210a19.svg" alt="\gmrule
{ \mathtt{Slide} \; n : i { \mathtt{Slide} \; n : i
&amp; a_0 : \ldots : a_n : s &amp; a_0 : \ldots : a_n : s
&amp; d &amp; d
@@ -133,7 +133,7 @@ top of the stack, <code class="code docutils literal notranslate"><span class="p
where the dump is <strong>not</strong> empty, the instruction queue and stack is restored where the dump is <strong>not</strong> empty, the instruction queue and stack is restored
from the top.</p> from the top.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/2417422cdf63ed202b16462208f8a62630f99679.svg" alt="\gmrule <p><img src="../_images/math/efc4a40c79bae27675f22ac6011dde9806c845b9.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist { \mathtt{Unwind} : \nillist
&amp; a : s &amp; a : s
&amp; \langle i', s' \rangle : d &amp; \langle i', s' \rangle : d
@@ -153,7 +153,7 @@ from the top.</p>
<li><p>Bulding on the previous rule, in the case where the dump <strong>is</strong> empty, leave <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> the machine in a halt state (i.e. with an empty instruction queue).</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/60f4e38bb9ff4a7bcb201e82cb956a3ccf064632.svg" alt="\gmrule <p><img src="../_images/math/fd11e2b1ffa20589ec72bb3f1ba70c82573f3f84.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist { \mathtt{Unwind} : \nillist
&amp; a : s &amp; a : s
&amp; \nillist &amp; \nillist
@@ -170,9 +170,31 @@ the machine in a halt state (i.e. with an empty instruction queue).</p>
&amp; m &amp; m
}"/></p> }"/></p>
</div></li> </div></li>
<li><p>Again, building on the previous rules, this rule makes the machine consider
unapplied supercombinators to be in WHNF</p>
<div class="math">
<p><img src="../_images/math/36a64918095793044bc603da838873e5db145350.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>
<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><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"> <div class="math">
<p><img src="../_images/math/b04167eaade600ab592e2a4441ffc27f5268cccf.svg" alt="\gmrule <p><img src="../_images/math/428dd88b1a0f02d8880a57efc2aff1aff732e58b.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist { \mathtt{Unwind} : \nillist
&amp; a : s &amp; a : s
&amp; d &amp; d
@@ -191,9 +213,9 @@ the machine in a halt state (i.e. with an empty instruction queue).</p>
</div></li> </div></li>
<li><p>When a supercombinator is on top of the stack (and the correct number of <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 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> the supercombinators code (<img class="math" src="../_images/math/4e04b3f70eef23aff9592405c5b32293f5f8f3d0.svg" alt="\beta" style="vertical-align: -4px"/>-reduction)</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/2dc5e48f0f26f08073e6e1cdd70ff876c6ec2434.svg" alt="\gmrule <p><img src="../_images/math/022f085a854e1a5039b4ce9ff514ae19e6e5731d.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist { \mathtt{Unwind} : \nillist
&amp; a_0 : \ldots : a_n : s &amp; a_0 : \ldots : a_n : s
&amp; d &amp; d
@@ -215,7 +237,7 @@ the supercombinators code (<img class="math" src="../_images/math/90592e98232
</div></li> </div></li>
<li><p>Pop the stack, and update the nth node to point to the popped address</p> <li><p>Pop the stack, and update the nth node to point to the popped address</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/e299a147e6e958303111e813e82a3507ded25437.svg" alt="\gmrule <p><img src="../_images/math/1e7730846a205754c25caa9bc83215d4c9a2fd0f.svg" alt="\gmrule
{ \mathtt{Update} \; n : i { \mathtt{Update} \; n : i
&amp; e : f : a_1 : \ldots : a_n : s &amp; e : f : a_1 : \ldots : a_n : s
&amp; d &amp; d
@@ -239,7 +261,7 @@ the supercombinators code (<img class="math" src="../_images/math/90592e98232
</div></li> </div></li>
<li><p>Pop the stack.</p> <li><p>Pop the stack.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/aec9099fc8c459eb433947bd6c9cc0f96fe38f98.svg" alt="\gmrule <p><img src="../_images/math/a8350470d1099f2c9d25787f232cd6d48128e2b9.svg" alt="\gmrule
{ \mathtt{Pop} \; n : i { \mathtt{Pop} \; n : i
&amp; a_1 : \ldots : a_n : s &amp; a_1 : \ldots : a_n : s
&amp; d &amp; d
@@ -255,7 +277,7 @@ the supercombinators code (<img class="math" src="../_images/math/90592e98232
</div></li> </div></li>
<li><p>Follow indirections while unwinding</p> <li><p>Follow indirections while unwinding</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/7648bfc0796ff33966fbc002c446b2242d296fd9.svg" alt="\gmrule <p><img src="../_images/math/7b51ed63c4f01626ae64caca9b8aa37ef8c04e3e.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist { \mathtt{Unwind} : \nillist
&amp; a : s &amp; a : s
&amp; d &amp; d
@@ -274,7 +296,7 @@ the supercombinators code (<img class="math" src="../_images/math/90592e98232
</div></li> </div></li>
<li><p>Allocate uninitialised heap space</p> <li><p>Allocate uninitialised heap space</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/5380d8227d0a06608b108a26b4a618972b4b7e28.svg" alt="\gmrule <p><img src="../_images/math/59c33027716f0d0c66a4cabdbb821415f2b561d5.svg" alt="\gmrule
{ \mathtt{Alloc} \; n : i { \mathtt{Alloc} \; n : i
&amp; s &amp; s
&amp; d &amp; d
@@ -295,7 +317,7 @@ the supercombinators code (<img class="math" src="../_images/math/90592e98232
</div></li> </div></li>
<li><p>Evaluate the top of the stack to WHNF</p> <li><p>Evaluate the top of the stack to WHNF</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/ce745b5797483cfcb6ff4816364d91d3d5b6e6c4.svg" alt="\gmrule <p><img src="../_images/math/99ee76fb86a35795feb0b604d9fa8f46e6bcbbc8.svg" alt="\gmrule
{ \mathtt{Eval} : i { \mathtt{Eval} : i
&amp; a : s &amp; a : s
&amp; d &amp; d
@@ -309,9 +331,9 @@ the supercombinators code (<img class="math" src="../_images/math/90592e98232
&amp; m &amp; m
}"/></p> }"/></p>
</div></li> </div></li>
<li><p>Reduce a primitive binary operator <img class="math" src="../_images/math/43434266ad5b9f36d523d70ff88db5c4e9366b03.svg" alt="*" style="vertical-align: 0px"/>.</p> <li><p>Reduce a primitive binary operator <img class="math" src="../_images/math/a5e51bd4f30d980b8599ff18ffd339c6d844d9e8.svg" alt="*" style="vertical-align: 0px"/>.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/176a0e2360b1e342041d8129c3a264321ae806ce.svg" alt="\gmrule <p><img src="../_images/math/6618a79153ccc671049ed4fb1f9cbf31b272d53c.svg" alt="\gmrule
{ * : i { * : i
&amp; a_1 : a_2 : s &amp; a_1 : a_2 : s
&amp; d &amp; d
@@ -332,9 +354,9 @@ the supercombinators code (<img class="math" src="../_images/math/90592e98232
&amp; m &amp; m
}"/></p> }"/></p>
</div></li> </div></li>
<li><p>Reduce a primitive unary operator <img class="math" src="../_images/math/604a42b94739b04fa9559a97c3703816bf57aa5c.svg" alt="\neg" style="vertical-align: 0px"/>.</p> <li><p>Reduce a primitive unary operator <img class="math" src="../_images/math/2d33478fc695c01e3ba58758bbdc809235dc6a3e.svg" alt="\neg" style="vertical-align: 0px"/>.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/6de99ea1d6d13dbeedcdfcf7e3807cdd4f2e8594.svg" alt="\gmrule <p><img src="../_images/math/fd61456b36d2327ea4950605d2e282d6a362685c.svg" alt="\gmrule
{ \neg : i { \neg : i
&amp; a : s &amp; a : s
&amp; d &amp; d
@@ -354,25 +376,41 @@ the supercombinators code (<img class="math" src="../_images/math/90592e98232
&amp; m &amp; m
}"/></p> }"/></p>
</div></li> </div></li>
<li><p>Consider unapplied functions to be in WHNF</p> <li><p>Pack a constructor if there are sufficient arguments</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/702f28367db2bbf757f819d55f238962369384ad.svg" alt="\gmrule <p><img src="../_images/math/ceba2ed1f0be639cb0841ed19d1980c77657c74b.svg" alt="\gmrule
{ \mathtt{Unwind} : \nillist { \mathtt{Pack} \; t \; n : i
&amp; a_0 : \ldots : a_n : \nillist &amp; a_1 : \ldots : a_n : s
&amp; \langle i, s \rangle : d &amp; d
&amp; h &amp; h
\begin{bmatrix}
a_0 : \mathtt{NGlobal} \; k \; c
\end{bmatrix}
&amp; m &amp; m
} }
{ i { i
&amp; a_n : s &amp; a : s
&amp; d &amp; d
&amp; h &amp; h
&amp; m \\ \begin{bmatrix}
\SetCell[c=2]{c} a : \mathtt{NConstr} \; t \; [a_1,\ldots,a_n]
\text{when $n &lt; k$} \end{bmatrix}
&amp; m
}"/></p>
</div></li>
<li><p>Evaluate a case</p>
<div class="math">
<p><img src="../_images/math/23e5e14aff97d56bdcb7e5847a5610baaa4b3040.svg" alt="\gmrule
{ \mathtt{CaseJump} \begin{bmatrix} t \to c \end{bmatrix} : i
&amp; a : s
&amp; d
&amp; h
\begin{bmatrix}
a : \mathtt{NConstr} \; t \; v
\end{bmatrix}
&amp; m
}
{ c \concat i
&amp; d
&amp; h
&amp; m
}"/></p> }"/></p>
</div></li> </div></li>
</ol> </ol>
@@ -388,7 +426,7 @@ this by modifying Core Rule 2 to update the global environment with the new
nodes address. Consider how this rule might impact garbage collection nodes address. Consider how this rule might impact garbage collection
(remember that the environment is intended for <em>globals</em>).</p> (remember that the environment is intended for <em>globals</em>).</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/0fc7c9df5cc4f923f6953e615c1f28a6531c0b68.svg" alt="\gmrule <p><img src="../_images/math/e8e88c3770a0c3cf4169abbee703c4a6bcffc0f5.svg" alt="\gmrule
{ \mathtt{PushInt} \; n : i { \mathtt{PushInt} \; n : i
&amp; s &amp; s
&amp; d &amp; d
@@ -414,7 +452,7 @@ nodes address. Consider how this rule might impact garbage collection
<li><p>In order for the previous rule to be effective, we are also required to take <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> action when a number already exists in the environment:</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/d56941a661a880391bd898f16e5dcf9c0b8a7e59.svg" alt="\gmrule <p><img src="../_images/math/321b47cc7986e581fdc26fb6b63195c1cf5409a2.svg" alt="\gmrule
{ \mathtt{PushInt} \; n : i { \mathtt{PushInt} \; n : i
&amp; s &amp; s
&amp; d &amp; d

View File

@@ -13,7 +13,7 @@
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script> <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="../genindex.html" /> <link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.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="prev" title="G-Machine State Transition Rules" href="gm-state-transitions.html" />
<link rel="stylesheet" href="../_static/custom.css" type="text/css" /> <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
@@ -35,7 +35,7 @@
<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 <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> dump is empty.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/90d7e53e2606d1ffdcc0d85fcc0be2db9b919797.svg" alt="\transrule <p><img src="../_images/math/96cf11c4b33f0179fcb72d62060f25fc6fa8b550.svg" alt="\transrule
{ a : \nillist { a : \nillist
&amp; \nillist &amp; \nillist
&amp; h &amp; h
@@ -48,7 +48,7 @@ dump is empty.</p>
}"/></p> }"/></p>
</div><p>Dereference an indirection passed as an argument to a function.</p> </div><p>Dereference an indirection passed as an argument to a function.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/2e21d478eedaa358bccb9aa3c57a5b290e671863.svg" alt="\transrule <p><img src="../_images/math/ecdbb83ab452d27fcd79c1567929508177d87f1f.svg" alt="\transrule
{a : s &amp; d &amp; h {a : s &amp; d &amp; h
\begin{bmatrix} \begin{bmatrix}
a : \mathtt{NAp} \; a_1 \; a_2 \\ a : \mathtt{NAp} \; a_1 \; a_2 \\
@@ -57,16 +57,16 @@ dump is empty.</p>
{a : s &amp; d &amp; h[a : \mathtt{NAp} \; a_1 \; a_3] &amp; g}"/></p> {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><p>Dereference an indirection on top of the stack.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/d30cef88d057bcc5920fca7d63d0682f802d9006.svg" alt="\transrule <p><img src="../_images/math/f51999c7c2b53f5ff66f0d4f339a64b99dccbbc0.svg" alt="\transrule
{p : s &amp; d &amp; h {p : s &amp; d &amp; h
\begin{bmatrix} \begin{bmatrix}
p : \mathtt{NInd} \; a p : \mathtt{NInd} \; a
\end{bmatrix} &amp; g} \end{bmatrix} &amp; g}
{a : s &amp; d &amp; h &amp; g}"/></p> {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 </div><p>Perform a unary operation <img class="math" src="../_images/math/11e676863b0ccfe854bc89167c23a5bd514bf5f9.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> <code class="code docutils literal notranslate"><span class="pre">O</span></code> on an argument in normal form.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/e4dc66520823a07e0df31b43dda92f9b2ea9e792.svg" alt="\transrule <p><img src="../_images/math/c2ff2f8e287ecf001479d047291f611c49ae7bde.svg" alt="\transrule
{ f : a : s { f : a : s
&amp; d &amp; d
&amp; h &amp; h
@@ -88,7 +88,7 @@ dump is empty.</p>
</div><p>Evaluate the argument of a unary operation with internal <code class="code docutils literal notranslate"><span class="pre">Prim</span></code> </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> constructor <code class="code docutils literal notranslate"><span class="pre">O</span></code>.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/620e45afe56ccc0dae7d9566d244b13bb6cb0631.svg" alt="\transrule <p><img src="../_images/math/226b15d1faaf510988b3ca3cb75ddd6c120c53ea.svg" alt="\transrule
{ f : a : \nillist { f : a : \nillist
&amp; d &amp; d
&amp; h &amp; h
@@ -105,7 +105,7 @@ constructor <code class="code docutils literal notranslate"><span class="pre">O<
}"/></p> }"/></p>
</div><p>Restore the stack when a sub-computation has completed.</p> </div><p>Restore the stack when a sub-computation has completed.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/4d427448f9b8b54db19e316c805033a7abfe11d2.svg" alt="\transrule <p><img src="../_images/math/1c0e1003d2e9980d635c8e79475e53226b5e7264.svg" alt="\transrule
{ a : \nillist { a : \nillist
&amp; s : d &amp; s : d
&amp; h &amp; h
@@ -119,9 +119,9 @@ constructor <code class="code docutils literal notranslate"><span class="pre">O<
&amp; h &amp; h
&amp; g &amp; g
}"/></p> }"/></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><p>Reduce a supercombinator and update the root with the <img class="math" src="../_images/math/4e04b3f70eef23aff9592405c5b32293f5f8f3d0.svg" alt="\beta" style="vertical-align: -4px"/>-reduced form</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/20219b0570be52c3f596972c4cd5461a162cccf9.svg" alt="\transrule <p><img src="../_images/math/80185f417c32abbbd850f4429d27d4111dd55ce6.svg" alt="\transrule
{ a_0 : a_1 : \ldots : a_n : s { a_0 : a_1 : \ldots : a_n : s
&amp; d &amp; d
&amp; h &amp; h
@@ -138,10 +138,10 @@ constructor <code class="code docutils literal notranslate"><span class="pre">O<
&amp; \SetCell[c=3]{c} &amp; \SetCell[c=3]{c}
\text{where } h' = \mathtt{instantiateU} \; e \; a_n \; h \; g \text{where } h' = \mathtt{instantiateU} \; e \; a_n \; h \; g
}"/></p> }"/></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> </div><p>Perform a binary operation <img class="math" src="../_images/math/70ba514f09b40f948e1a3673347f656c7dc33f27.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> 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"> <div class="math">
<p><img src="../_images/math/7c31cda93cce15a6bef0ecb07b4221f15d15cc9f.svg" alt="\transrule <p><img src="../_images/math/703648dab56048f07869054b5257b846f55a4dec.svg" alt="\transrule
{ f : a_1 : a_2 : s { f : a_1 : a_2 : s
&amp; d &amp; d
&amp; h &amp; h
@@ -163,7 +163,7 @@ constructor <code class="code docutils literal notranslate"><span class="pre">O<
</div><p>In a conditional primitive, perform the reduction if the condition has been </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> 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"> <div class="math">
<p><img src="../_images/math/1543958253280895e6abea369c0f9abf4898649c.svg" alt="\transrule <p><img src="../_images/math/d9911cffb6ee41316d3f017754491dab76c920a9.svg" alt="\transrule
{ f : a_1 : a_2 : a_3 : s { f : a_1 : a_2 : a_3 : s
&amp; d &amp; d
&amp; h &amp; h
@@ -184,7 +184,7 @@ evaluated as True (<code class="code docutils literal notranslate"><span class="
</div><p>In a conditional primitive, perform the reduction if the condition has been </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> 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"> <div class="math">
<p><img src="../_images/math/6d95eec30809d2f72c4d645e69ee6ba5fd3f0767.svg" alt="\transrule <p><img src="../_images/math/11e48d7396763a8f0e16cba061b46966844e3191.svg" alt="\transrule
{ f : a_1 : a_2 : a_3 : s { f : a_1 : a_2 : a_3 : s
&amp; d &amp; d
&amp; h &amp; h
@@ -204,7 +204,7 @@ evaluated as False (<code class="code docutils literal notranslate"><span class=
}"/></p> }"/></p>
</div><p>In a conditional primitive, evaluate the condition.</p> </div><p>In a conditional primitive, evaluate the condition.</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/625a1ccce064b171eb9d5ec015e07d234ef26c74.svg" alt="\transrule <p><img src="../_images/math/4480a4e8409efd17a2bb57789e584bba66af268c.svg" alt="\transrule
{ f : a_1 : \nillist { f : a_1 : \nillist
&amp; d &amp; d
&amp; h &amp; h
@@ -221,7 +221,7 @@ evaluated as False (<code class="code docutils literal notranslate"><span class=
}"/></p> }"/></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><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"> <div class="math">
<p><img src="../_images/math/b0285722e6eed4a0fa69945efe4dfe0fbe124582.svg" alt="\transrule <p><img src="../_images/math/8d27e16980b44cbe4694fb91353c71239780608d.svg" alt="\transrule
{ c : a_1 : \ldots : a_n : \nillist { c : a_1 : \ldots : a_n : \nillist
&amp; d &amp; d
&amp; h &amp; h
@@ -245,7 +245,7 @@ evaluated as False (<code class="code docutils literal notranslate"><span class=
<h2>Pairs<a class="headerlink" href="#pairs" title="Link to this heading"></a></h2> <h2>Pairs<a class="headerlink" href="#pairs" title="Link to this heading"></a></h2>
<p>Evaluate the first argument if necessary</p> <p>Evaluate the first argument if necessary</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/478aeca314882e29dc3a52d64624061fb36948f0.svg" alt="\transrule <p><img src="../_images/math/292cba3e41608acd2957a5e9aa29ab8f2cbc346d.svg" alt="\transrule
{ c : a_1 : a_2 : \nillist { c : a_1 : a_2 : \nillist
&amp; d &amp; d
&amp; h &amp; h
@@ -264,7 +264,7 @@ evaluated as False (<code class="code docutils literal notranslate"><span class=
}"/></p> }"/></p>
</div><p>Perform the reduction if the first argument is in normal form</p> </div><p>Perform the reduction if the first argument is in normal form</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/c5937687478d980ab66b85de909dcb73d4bc9b13.svg" alt="\transrule <p><img src="../_images/math/34c5ba211557474d30a91f5ea6cf5692b3b88610.svg" alt="\transrule
{ c : a_1 : a_2 : s { c : a_1 : a_2 : s
&amp; d &amp; d
&amp; h &amp; h
@@ -290,7 +290,7 @@ evaluated as False (<code class="code docutils literal notranslate"><span class=
<h2>Lists<a class="headerlink" href="#lists" title="Link to this heading"></a></h2> <h2>Lists<a class="headerlink" href="#lists" title="Link to this heading"></a></h2>
<p>Evaluate the scrutinee</p> <p>Evaluate the scrutinee</p>
<div class="math"> <div class="math">
<p><img src="../_images/math/5bd3cd582dce130ac602d5d805972076e5bc0f56.svg" alt="\transrule <p><img src="../_images/math/f653751fa1b1ef5e1eb9a12fbb4df556a501606f.svg" alt="\transrule
{ c : a_1 : a_2 : a_3 : \nillist { c : a_1 : a_2 : a_3 : \nillist
&amp; d &amp; d
&amp; h &amp; h
@@ -307,7 +307,7 @@ evaluated as False (<code class="code docutils literal notranslate"><span class=
}"/></p> }"/></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><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"> <div class="math">
<p><img src="../_images/math/a6502e03af9f1e3d8a7dce9053c7125364a0cae5.svg" alt="\transrule <p><img src="../_images/math/fd3674c541392d348d835034f858018e7a614a41.svg" alt="\transrule
{ c : a_1 : a_2 : a_3 : s { c : a_1 : a_2 : a_3 : s
&amp; d &amp; d
&amp; h &amp; h
@@ -360,7 +360,7 @@ evaluated as False (<code class="code docutils literal notranslate"><span class=
</ul> </ul>
<p class="caption" role="heading"><span class="caption-text">References</span></p> <p class="caption" role="heading"><span class="caption-text">References</span></p>
<ul class="current"> <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"><a class="reference internal" href="gm-state-transitions.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> <li class="toctree-l1 current"><a class="current reference internal" href="#">Template Instantiator State Transition Rules</a></li>
</ul> </ul>
@@ -368,7 +368,7 @@ evaluated as False (<code class="code docutils literal notranslate"><span class=
<h3>Related Topics</h3> <h3>Related Topics</h3>
<ul> <ul>
<li><a href="../index.html">Documentation overview</a><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> <li>Previous: <a href="gm-state-transitions.html" title="previous chapter">G-Machine State Transition Rules</a></li>
</ul></li> </ul></li>
</ul> </ul>
</div> </div>

File diff suppressed because one or more lines are too long

View File

@@ -50,6 +50,8 @@ imgmath_latex_preamble = r'''
\end{tblr} } \end{tblr} }
\newcommand{\nillist}{[\,]} \newcommand{\nillist}{[\,]}
\newcommand{\concat}{+\kern-1.3ex+\kern0.8ex}
''' '''
imgmath_image_format = 'svg' imgmath_image_format = 'svg'

View File

@@ -363,6 +363,47 @@ Core Transition Rules
& m & m
} }
#. Pack a constructor if there are sufficient arguments
.. math::
\gmrule
{ \mathtt{Pack} \; t \; n : i
& a_1 : \ldots : a_n : s
& d
& h
& m
}
{ i
& a : s
& d
& h
\begin{bmatrix}
a : \mathtt{NConstr} \; t \; [a_1,\ldots,a_n]
\end{bmatrix}
& m
}
#. Evaluate a case
.. math::
\gmrule
{ \mathtt{CaseJump} \begin{bmatrix} t \to c \end{bmatrix} : i
& a : s
& d
& h
\begin{bmatrix}
a : \mathtt{NConstr} \; t \; v
\end{bmatrix}
& m
}
{ c \concat i
& d
& h
& m
}
*************** ***************
Extension Rules Extension Rules
*************** ***************

View File

@@ -11,7 +11,6 @@ module Control.Monad.Errorful
where where
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
import Control.Monad.Trans import Control.Monad.Trans
import Control.Monad.Except
import Data.Functor.Identity import Data.Functor.Identity
import Data.Coerce import Data.Coerce
import Lens.Micro import Lens.Micro

View File

@@ -55,11 +55,10 @@ data Instr = Unwind
| Alloc Int | Alloc Int
| Eval | Eval
-- primitive ops -- primitive ops
| Neg | Neg | Add | Sub | Mul | Div
| Add | Pack Int Int -- Pack Tag Arity
| Sub | CaseJump [(Int, Code)]
| Mul | Split Int
| Div
deriving (Show, Eq) deriving (Show, Eq)
data Node = NNum Int data Node = NNum Int
@@ -70,6 +69,7 @@ data Node = NNum Int
| NGlobal Int Code | NGlobal Int Code
| NInd Addr | NInd Addr
| NUninitialised | NUninitialised
| NConstr Int [Addr] -- NConstr Tag Components
deriving (Show, Eq) deriving (Show, Eq)
data Stats = Stats data Stats = Stats
@@ -707,5 +707,9 @@ showCode c = "Code" <+> braces instrs
where instrs = vcat $ showInstr <$> c where instrs = vcat $ showInstr <$> c
showInstr :: Instr -> Doc showInstr :: Instr -> Doc
showInstr (CaseJump alts) = "CaseJump" $$ nest pprTabstop alternatives
where
showAlt (t,c) = "<" <> int t <> ">" <> showCodeShort c
alternatives = foldr (\a acc -> showAlt a $$ acc) mempty alts
showInstr i = text $ show i showInstr i = text $ show i