about summary refs log blame commit diff stats
path: root/html/022boolean.cc.html
blob: f1c0b5b27451d4733db9754c9ffe04b5bcb707fd (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12



                                                                                          
                                 






                                                                                         

                                                                                                 
                        
                             
                                  

                              
                            
                               
                             















                                                                                      
                                                                                                   
                                                                                         






                                                                                                                                                                                                                                                                                                                                                                                                                                                                   



                                                                                                                                                                                                                                                




                                                                       

                                                                                                                 
                                                                                                                                                                                                
 

                                                                
                                                
             
                                                                                                                                                                                




                                                                
                                                                                                                                                                                                                                                


                                                                
                                                         
             
                                                                                                                                                                                                                                                


                                                                


                                                                                      
                                                                                                 
                                                                                         






                                                                                                                                                                                                                                                                                                                                                                                                                                                                  



                                                                                                                                                                                                                                        




                                                                       

                                                                                                                 
                                                                                                                                                                                               
 

                                                                
                                               
             
                                                                                                                                                                               




                                                                
                                                                                                                                                                                                                                                


                                                                
                                                        
             
                                                                                                                                                                                                                                               


                                                                


                                                                                      
                                                                                                   
                                                                                         
                                          
                                                                                                                                                                 




                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

                                                                                                                                                                                                                                                                                                                                                                            




                                                                       
                                                                                                                 
                                                                                                                        
 
                                                                


                                                       
                                                                                                                                                                                                                                                                                                                                                                                                



                                                                



                                     
<!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>Mu - 022boolean.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: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.cSpecial { color: #008000; }
.traceContains { color: #008000; }
.Comment { color: #9090ff; }
.Delimiter { color: #a04060; }
.Special { color: #ff6060; }
.Identifier { color: #804000; }
.Constant { color: #00a0a0; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Boolean primitives</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
AND<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
Recipe_ordinal[<span class="Constant">&quot;and&quot;</span>] = AND<span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
case AND: <span class="Delimiter">{</span>
  bool result = <span class="Constant">true</span><span class="Delimiter">;</span>
  for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span>
      raise &lt;&lt; current_recipe_name<span class="Delimiter">()</span> &lt;&lt; <span class="Constant">&quot;: 'and' requires boolean ingredients, but got &quot;</span> &lt;&lt; current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
      <span class="Identifier">goto</span> finish_instruction<span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    result = result &amp;&amp; ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
  products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>
  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario and)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>
  <span class="Constant">2</span>:boolean<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">3</span>:boolean<span class="Special"> &lt;- </span>and <span class="Constant">1</span>:boolean<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean
]
<span class="traceContains">+mem: storing 0 in location 3</span>

<span class="Delimiter">:(scenario and_2)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>and <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+mem: storing 1 in location 1</span>

<span class="Delimiter">:(scenario and_multiple)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>and <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">0</span>
]
<span class="traceContains">+mem: storing 0 in location 1</span>

<span class="Delimiter">:(scenario and_multiple_2)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>and <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+mem: storing 1 in location 1</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
OR<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
Recipe_ordinal[<span class="Constant">&quot;or&quot;</span>] = OR<span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
case OR: <span class="Delimiter">{</span>
  bool result = <span class="Constant">false</span><span class="Delimiter">;</span>
  for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span>
      raise &lt;&lt; current_recipe_name<span class="Delimiter">()</span> &lt;&lt; <span class="Constant">&quot;: 'or' requires boolean ingredients, but got &quot;</span> &lt;&lt; current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
      <span class="Identifier">goto</span> finish_instruction<span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    result = result || ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
  products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>
  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario or)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>
  <span class="Constant">2</span>:boolean<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">3</span>:boolean<span class="Special"> &lt;- </span>or <span class="Constant">1</span>:boolean<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean
]
<span class="traceContains">+mem: storing 1 in location 3</span>

<span class="Delimiter">:(scenario or_2)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>or <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span>
]
<span class="traceContains">+mem: storing 0 in location 1</span>

<span class="Delimiter">:(scenario or_multiple)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>and <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span>
]
<span class="traceContains">+mem: storing 0 in location 1</span>

<span class="Delimiter">:(scenario or_multiple_2)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>or <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+mem: storing 1 in location 1</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
NOT<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
Recipe_ordinal[<span class="Constant">&quot;not&quot;</span>] = NOT<span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
case NOT: <span class="Delimiter">{</span>
  products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">));</span>
  for <span class="Delimiter">(</span>long long int i = <span class="Constant">0</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    if <span class="Delimiter">(</span>!scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span>
      raise &lt;&lt; current_recipe_name<span class="Delimiter">()</span> &lt;&lt; <span class="Constant">&quot;: 'not' requires boolean ingredients, but got &quot;</span> &lt;&lt; current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>original_string &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
      <span class="Identifier">goto</span> finish_instruction<span class="Delimiter">;</span>
    <span class="Delimiter">}</span>
    products<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>!ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario not)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>
  <span class="Constant">2</span>:boolean<span class="Special"> &lt;- </span>not <span class="Constant">1</span>:boolean
]
<span class="traceContains">+mem: storing 0 in location 2</span>

<span class="Delimiter">:(scenario not_multiple)</span>
recipe main [
  <span class="Constant">1</span>:boolean<span class="Delimiter">,</span> <span class="Constant">2</span>:boolean<span class="Delimiter">,</span> <span class="Constant">3</span>:boolean<span class="Special"> &lt;- </span>not <span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">1</span>
]
<span class="traceContains">+mem: storing 0 in location 1</span>
<span class="traceContains">+mem: storing 1 in location 2</span>
<span class="traceContains">+mem: storing 0 in location 3</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->