about summary refs log blame commit diff stats
path: root/html/075scenario_keyboard.cc.html
blob: 2a61289997d1da9b64c09569d46bcd2eeabb14e2 (plain) (tree)
1
2
3
4
5



                                                                                          
                                                     









































                                                                                                                                                                                                                                   
                                                                                                      
                                                                                                                                           
                                                                                                      
                                                                                                                                           


                                                                                                                                          





                                                                                              
                                                                                                                                                                                                                                                











                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                  





                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                     

                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                  




                                     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>~/Desktop/s/mu/075scenario_keyboard.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; }
body { font-family: monospace; color: #d0d0d0; background-color: #000000; }
* { font-size: 1em; }
.Constant { color: #008080; }
.Comment { color: #8080ff; }
.Delimiter { color: #c000c0; }
.Special { color: #ff6060; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Clean syntax to manipulate and check the keyboard in scenarios.</span>
<span class="Comment">//: Instruction 'assume-keyboard' implicitly creates a variable called</span>
<span class="Comment">//: 'keyboard' that is accessible inside other 'run' instructions in the</span>
<span class="Comment">//: scenario.</span>

<span class="Delimiter">:(scenarios run_mu_scenario)</span>
<span class="Delimiter">:(scenario keyboard_in_scenario)</span>
scenario keyboard-in-scenario [
  assume-keyboard [abc]
  run [
    <span class="Constant">1</span>:character<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean<span class="Delimiter">,</span> keyboard:address<span class="Special"> &lt;- </span>read-key keyboard:address
    <span class="Constant">3</span>:character<span class="Delimiter">,</span> <span class="Constant">4</span>:boolean<span class="Delimiter">,</span> keyboard:address<span class="Special"> &lt;- </span>read-key keyboard:address
    <span class="Constant">5</span>:character<span class="Delimiter">,</span> <span class="Constant">6</span>:boolean<span class="Delimiter">,</span> keyboard:address<span class="Special"> &lt;- </span>read-key keyboard:address
    <span class="Constant">7</span>:character<span class="Delimiter">,</span> <span class="Constant">8</span>:boolean<span class="Delimiter">,</span> keyboard:address<span class="Special"> &lt;- </span>read-key keyboard:address
  ]
  memory-should-contain [
    <span class="Constant">1</span><span class="Special"> &lt;- </span><span class="Constant">97</span>  <span class="Comment"># 'a'</span>
    <span class="Constant">2</span><span class="Special"> &lt;- </span><span class="Constant">1</span>
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">98</span>  <span class="Comment"># 'b'</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">1</span>
    <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">99</span>  <span class="Comment"># 'c'</span>
    <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">1</span>
    <span class="Constant">7</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># eof</span>
    <span class="Constant">8</span><span class="Special"> &lt;- </span><span class="Constant">1</span>
  ]
]

<span class="Delimiter">:(before &quot;End Scenario Globals&quot;)</span>
const size_t KEYBOARD = Next_predefined_global_for_scenarios++<span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Predefined Scenario Locals In Run&quot;)</span>
Name[tmp_recipe<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span>][<span class="Constant">&quot;keyboard&quot;</span>] = KEYBOARD<span class="Delimiter">;</span>

<span class="Delimiter">:(before &quot;End Rewrite Instruction(curr)&quot;)</span>
<span class="Comment">// rewrite `assume-keyboard string` to</span>
<span class="Comment">//   ```</span>
<span class="Comment">//   keyboard:address &lt;- new string  # hacky reuse of location</span>
<span class="Comment">//   keyboard:address &lt;- init-fake-keyboard keyboard:address</span>
<span class="Comment">//   ```</span>
if <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>name == <span class="Constant">&quot;assume-keyboard&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Comment">// insert first instruction</span>
  curr<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">&quot;new&quot;</span>]<span class="Delimiter">;</span>
  assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
  curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">&quot;keyboard:address&quot;</span><span class="Delimiter">));</span>
  curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>KEYBOARD<span class="Delimiter">);</span>
  result<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span>  <span class="Comment">// hacky that &quot;Rewrite Instruction&quot; is converting to multiple instructions</span>
  <span class="Comment">// leave second instruction in curr</span>
  curr<span class="Delimiter">.</span>clear<span class="Delimiter">();</span>
  curr<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">&quot;init-fake-keyboard&quot;</span>]<span class="Delimiter">;</span>
  assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
  curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">&quot;keyboard:address&quot;</span><span class="Delimiter">));</span>
  curr<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>KEYBOARD<span class="Delimiter">);</span>
  assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
  curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>reagent<span class="Delimiter">(</span><span class="Constant">&quot;keyboard:address&quot;</span><span class="Delimiter">));</span>
  curr<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>set_value<span class="Delimiter">(</span>KEYBOARD<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->