go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

cookbook.html (8541B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
      4 <head>
      5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      6 <!-- Released 2023 under AGPL3 -->
      7 <title>cookbook (vise)</title>
      8 
      9 <meta name="description" content="cookbook (vise)">
     10 <meta name="keywords" content="cookbook (vise)">
     11 <meta name="resource-type" content="document">
     12 <meta name="distribution" content="global">
     13 <meta name="Generator" content="makeinfo">
     14 <meta name="viewport" content="width=device-width,initial-scale=1">
     15 
     16 <link href="index.html" rel="start" title="Top">
     17 <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
     18 <link href="index.html" rel="up" title="Top">
     19 <link href="dev.html" rel="prev" title="dev">
     20 <style type="text/css">
     21 <!--
     22 a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
     23 div.example {margin-left: 3.2em}
     24 span:hover a.copiable-link {visibility: visible}
     25 ul.mark-bullet {list-style-type: disc}
     26 -->
     27 </style>
     28 
     29 
     30 </head>
     31 
     32 <body lang="en">
     33 <div class="chapter-level-extent" id="cookbook">
     34 <div class="nav-panel">
     35 <p>
     36 Previous: <a href="dev.html" accesskey="p" rel="prev">Developing with vise</a>, Up: <a href="index.html" accesskey="u" rel="up">Introduction</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
     37 </div>
     38 <hr>
     39 <h2 class="chapter" id="Common-patterns"><span>12 Common patterns<a class="copiable-link" href="#Common-patterns"> &para;</a></span></h2>
     40 
     41 
     42 <ul class="mini-toc">
     43 <li><a href="#Hello-world" accesskey="1">Hello world</a></li>
     44 <li><a href="#Handling-menus-and-inputs" accesskey="2">Handling menus and inputs</a></li>
     45 <li><a href="#Signal-flow-control" accesskey="3">Signal flow control</a></li>
     46 <li><a href="#Multiple-pages" accesskey="4">Multiple pages</a></li>
     47 <li><a href="#Multi_002dpage-menus" accesskey="5">Multi-page menus</a></li>
     48 <li><a href="#Default-input-handler" accesskey="6">Default input handler</a></li>
     49 <li><a href="#Graceful-quit" accesskey="7">Graceful quit</a></li>
     50 </ul>
     51 <div class="section-level-extent" id="Hello-world">
     52 <h3 class="section"><span>12.1 Hello world<a class="copiable-link" href="#Hello-world"> &para;</a></span></h3>
     53 
     54 <div class="example">
     55 <pre class="example-preformatted">HALT
     56 </pre></div>
     57 
     58 <p>Will render a template without any external symbols and terminate execution immediately.
     59 </p>
     60 
     61 <a class="anchor" id="handling_005fmenus"></a></div>
     62 <div class="section-level-extent" id="Handling-menus-and-inputs">
     63 <h3 class="section"><span>12.2 Handling menus and inputs<a class="copiable-link" href="#Handling-menus-and-inputs"> &para;</a></span></h3>
     64 
     65 <div class="example">
     66 <pre class="example-preformatted">MOUT to_foo 0
     67 MOUT to_bar 1
     68 MOUT upup 2
     69 HALT
     70 INCMP foo 0
     71 INCMP bar 1
     72 INCMP _ 2
     73 </pre></div>
     74 
     75 <p>Create three menu items, resolving the menu symbols <code class="code">to_foo</code>, <code class="code">to_bar</code> and <code class="code">upup</code> respectively to translated text and pairing with the selectors.
     76 </p>
     77 <p>Yield for client input. Then attempt to match input to selectors:
     78 </p>
     79 <ul class="itemize mark-bullet">
     80 <li>if selector is <code class="code">0</code>, execute node <code class="code">foo</code>.
     81 </li><li>if selector is <code class="code">1</code>, execute node <code class="code">bar</code>.
     82 </li><li>if selector is <code class="code">2</code>, execute previous node in stack.
     83 </li></ul>
     84 
     85 
     86 <ul class="mini-toc">
     87 <li><a href="#Menu-batch-version" accesskey="1">Menu batch version</a></li>
     88 </ul>
     89 <div class="subsection-level-extent" id="Menu-batch-version">
     90 <h4 class="subsection"><span>12.2.1 Menu batch version<a class="copiable-link" href="#Menu-batch-version"> &para;</a></span></h4>
     91 
     92 <div class="example">
     93 <pre class="example-preformatted">DOWN foo 0 to_foo
     94 DOWN bar 1 to_bar
     95 UP 2 upup
     96 </pre></div>
     97 
     98 <p>This example produces exactly the same bytecode result as the <a class="ref" href="#handling_005fmenus">previous example</a>.
     99 </p>
    100 
    101 </div>
    102 </div>
    103 <div class="section-level-extent" id="Signal-flow-control">
    104 <h3 class="section"><span>12.3 Signal flow control<a class="copiable-link" href="#Signal-flow-control"> &para;</a></span></h3>
    105 
    106 <div class="example">
    107 <pre class="example-preformatted">LOAD foo 1
    108 CATCH bar 8 1
    109 MOVE baz
    110 </pre></div>
    111 
    112 <p>If loading the external symbol <code class="code">foo</code> sets the flag <code class="code">8</code>, then immediately move to <code class="code">bar</code>.
    113 </p>
    114 <p>Otherwise, move to <code class="code">baz</code>.
    115 </p>
    116 
    117 <a class="anchor" id="multiple_005fpages"></a></div>
    118 <div class="section-level-extent" id="Multiple-pages">
    119 <h3 class="section"><span>12.4 Multiple pages<a class="copiable-link" href="#Multiple-pages"> &para;</a></span></h3>
    120 
    121 <div class="example">
    122 <pre class="example-preformatted">LOAD foo 0
    123 MNEXT to_fwd 11 
    124 MPREV to_back 22
    125 HALT
    126 INCMP &gt; 11
    127 INCMP &lt; 22
    128 </pre></div>
    129 
    130 <p>Load external symbol <code class="code">foo</code> as a <em class="emph">sink</em>.
    131 </p>
    132 <p>If content spans multiple pages, resolve <code class="code">to_fwd</code> and <code class="code">to_back</code> as labels for lateral navigation options in the menu.
    133 </p>
    134 <p>Also handle the lateral navigation inputs.
    135 </p>
    136 <ul class="mini-toc">
    137 <li><a href="#Menu-batch-version-1" accesskey="1">Menu batch version</a></li>
    138 </ul>
    139 <div class="subsection-level-extent" id="Menu-batch-version-1">
    140 <h4 class="subsection"><span>12.4.1 Menu batch version<a class="copiable-link" href="#Menu-batch-version-1"> &para;</a></span></h4>
    141 
    142 <div class="example">
    143 <pre class="example-preformatted">LOAD foo 0
    144 NEXT 11 to_fwd
    145 PREVIOUS 22 to_back
    146 </pre></div>
    147 
    148 <p>This example produces exactly the same bytecode result as the <a class="ref" href="#multiple_005fpages">previous example</a>.
    149 </p>
    150 
    151 <a class="anchor" id="multiple_005fmenus"></a></div>
    152 </div>
    153 <div class="section-level-extent" id="Multi_002dpage-menus">
    154 <h3 class="section"><span>12.5 Multi-page menus<a class="copiable-link" href="#Multi_002dpage-menus"> &para;</a></span></h3>
    155 
    156 <div class="example">
    157 <pre class="example-preformatted">MSINK
    158 MNEXT to_fwd 11 
    159 MPREV to_back 22
    160 MOUT inky 0
    161 MOUT pinky 1
    162 MOUT blinky 2
    163 MOUT clyde 3
    164 MOUT tinkywinky 4
    165 MOUT dipsy 5
    166 MOUT lala 6
    167 MOUT pu 7
    168 HALT
    169 INCMP foo 0
    170 INCMP foo 1
    171 INCMP foo 2
    172 INCMP foo 3
    173 INCMP foo 4
    174 INCMP foo 5
    175 INCMP foo 6
    176 INCMP bar 7
    177 </pre></div>
    178 
    179 <p>Enable splitting menu over several pages, and route all valid inputs to the <code class="code">foo</code> node, except for <code class="code">7</code> which is routed to the <code class="code">bar</code> node.
    180 </p>
    181 
    182 <ul class="mini-toc">
    183 <li><a href="#Menu-batch-version-2" accesskey="1">Menu batch version</a></li>
    184 </ul>
    185 <div class="subsection-level-extent" id="Menu-batch-version-2">
    186 <h4 class="subsection"><span>12.5.1 Menu batch version<a class="copiable-link" href="#Menu-batch-version-2"> &para;</a></span></h4>
    187 
    188 <div class="example">
    189 <pre class="example-preformatted">MSINK
    190 MNEXT to_fwd 11 
    191 MPREV to_back 22
    192 DOWN foo 0 inky
    193 DOWN foo 1 pinky
    194 DOWN foo 2 blinky
    195 DOWN foo 3 clyde
    196 DOWN foo 4 tinkywinky
    197 DOWN foo 5 dipsy
    198 DOWN foo 6 lala
    199 DOWN bar 7 pu
    200 </pre></div>
    201 
    202 <p>This example produces exactly the same bytecode result as the <a class="ref" href="#multiple_005fmenus">previous example</a>.
    203 </p>
    204 
    205 </div>
    206 </div>
    207 <div class="section-level-extent" id="Default-input-handler">
    208 <h3 class="section"><span>12.6 Default input handler<a class="copiable-link" href="#Default-input-handler"> &para;</a></span></h3>
    209 
    210 <div class="example">
    211 <pre class="example-preformatted">MOUT to_foo 0
    212 HALT
    213 INCMP foo 0
    214 INCMP bar *
    215 </pre></div>
    216 
    217 <p>If input is <code class="code">0</code>, route to the <code class="code">foo</code>. Any other input will route to the <code class="code">bar</code> node.
    218 </p>
    219 
    220 </div>
    221 <div class="section-level-extent" id="Graceful-quit">
    222 <h3 class="section"><span>12.7 Graceful quit<a class="copiable-link" href="#Graceful-quit"> &para;</a></span></h3>
    223 
    224 <div class="example">
    225 <pre class="example-preformatted">LOAD msg 0
    226 HALT
    227 </pre></div>
    228 
    229 <p>Execution will stop (without error) and the node template render will be displayed. Any content returned from the execution of the <code class="code">msg</code> symbol will be appended to the render. Lastly the <code class="code">MOVE ^</code> will be appended automatically to the state bytecode.
    230 </p></div>
    231 </div>
    232 <hr>
    233 <div class="nav-panel">
    234 <p>
    235 Previous: <a href="dev.html">Developing with vise</a>, Up: <a href="index.html">Introduction</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
    236 </div>
    237 
    238 
    239 
    240 </body>
    241 </html>