about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-11-13 09:37:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-11-13 09:37:50 -0800
commit20a7d37f74625962c946f027074031d7cd2cbbcb (patch)
treeaefb3ffc7cf040c1e115a4ab58f95e115b50a22b
parenta513c19fd61de8c4b253a307ccfaea628b5960ed (diff)
downloadmu-20a7d37f74625962c946f027074031d7cd2cbbcb.tar.gz
3673
-rw-r--r--html/029tools.cc.html11
-rw-r--r--html/038new_text.cc.html38
-rw-r--r--html/058to_text.cc.html2
-rw-r--r--html/061text.mu.html83
-rw-r--r--html/089scenario_filesystem.cc.html8
5 files changed, 127 insertions, 15 deletions
diff --git a/html/029tools.cc.html b/html/029tools.cc.html
index a6322f9c..da2f41ab 100644
--- a/html/029tools.cc.html
+++ b/html/029tools.cc.html
@@ -70,7 +70,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
   ostringstream out<span class="Delimiter">;</span>
   <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">2</span><span class="Delimiter">;</span>  i &lt; SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span>  ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
     <span class="Normal">if</span> <span class="Delimiter">(</span>i &gt; <span class="Constant">2</span><span class="Delimiter">)</span> out &lt;&lt; <span class="Constant">' '</span><span class="Delimiter">;</span>
-    out &lt;&lt; print_mu<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
+    out &lt;&lt; inspect<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
   <span class="Delimiter">}</span>
   trace<span class="Delimiter">(</span>depth<span class="Delimiter">,</span> label<span class="Delimiter">)</span> &lt;&lt; out<span class="Delimiter">.</span>str<span class="Delimiter">()</span> &lt;&lt; end<span class="Delimiter">();</span>
   <span class="Identifier">break</span><span class="Delimiter">;</span>
@@ -91,7 +91,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
   ostringstream out<span class="Delimiter">;</span>
   <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span>  i &lt; SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span>  ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
     <span class="Normal">if</span> <span class="Delimiter">(</span>i<span class="Delimiter">)</span> out &lt;&lt; <span class="Constant">' '</span><span class="Delimiter">;</span>
-    out &lt;&lt; print_mu<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
+    out &lt;&lt; inspect<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
   <span class="Delimiter">}</span>
   trace<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <span class="Constant">&quot;app&quot;</span><span class="Delimiter">)</span> &lt;&lt; out<span class="Delimiter">.</span>str<span class="Delimiter">()</span> &lt;&lt; end<span class="Delimiter">();</span>
   <span class="Identifier">break</span><span class="Delimiter">;</span>
@@ -117,10 +117,10 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
 <span class="traceContains">+app: foo: 34</span>
 
 <span class="Delimiter">:(code)</span>
-string print_mu<span class="Delimiter">(</span><span class="Normal">const</span> reagent&amp; r<span class="Delimiter">,</span> <span class="Normal">const</span> vector&lt;<span class="Normal">double</span>&gt;&amp; data<span class="Delimiter">)</span> <span class="Delimiter">{</span>
+string inspect<span class="Delimiter">(</span><span class="Normal">const</span> reagent&amp; r<span class="Delimiter">,</span> <span class="Normal">const</span> vector&lt;<span class="Normal">double</span>&gt;&amp; data<span class="Delimiter">)</span> <span class="Delimiter">{</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>r<span class="Delimiter">))</span>
     <span class="Identifier">return</span> r<span class="Delimiter">.</span>name<span class="Delimiter">;</span>
-  <span class="Comment">// End print Special-cases(r, data)</span>
+  <span class="Comment">// End inspect Special-cases(r, data)</span>
   ostringstream out<span class="Delimiter">;</span>
   <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">long</span> <span class="Normal">long</span> i = <span class="Constant">0</span><span class="Delimiter">;</span>  i &lt; SIZE<span class="Delimiter">(</span>data<span class="Delimiter">);</span>  ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
     <span class="Normal">if</span> <span class="Delimiter">(</span>i<span class="Delimiter">)</span> out &lt;&lt; <span class="Constant">' '</span><span class="Delimiter">;</span>
@@ -285,6 +285,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
         cout &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
       <span class="Delimiter">}</span>
     <span class="Delimiter">}</span>
+    <span class="Comment">// End $print Special-cases</span>
     <span class="Normal">else</span> <span class="Delimiter">{</span>
       <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span>  j &lt; SIZE<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>  ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span>
         trace<span class="Delimiter">(</span><span class="Constant">9998</span><span class="Delimiter">,</span> <span class="Constant">&quot;run&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;$print: &quot;</span> &lt;&lt; ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)</span> &lt;&lt; end<span class="Delimiter">();</span>
@@ -368,7 +369,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
 <span class="Normal">case</span> _LOG: <span class="Delimiter">{</span>
   ostringstream out<span class="Delimiter">;</span>
   <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span>  i &lt; SIZE<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">);</span>  ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
-    out &lt;&lt; print_mu<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
+    out &lt;&lt; inspect<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
   <span class="Delimiter">}</span>
   LOG &lt;&lt; out<span class="Delimiter">.</span>str<span class="Delimiter">()</span> &lt;&lt; <span class="cSpecial">'\n'</span><span class="Delimiter">;</span>
   <span class="Identifier">break</span><span class="Delimiter">;</span>
diff --git a/html/038new_text.cc.html b/html/038new_text.cc.html
index 0cd1e165..f86c1683 100644
--- a/html/038new_text.cc.html
+++ b/html/038new_text.cc.html
@@ -16,6 +16,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 .Constant { color: #00a0a0; }
 .CommentedCode { color: #6c6c6c; }
 .muRecipe { color: #ff8700; }
+.SalientComment { color: #00ffff; }
 .Comment { color: #9090ff; }
 .Delimiter { color: #800080; }
 .Special { color: #c00000; }
@@ -106,12 +107,17 @@ put<span class="Delimiter">(</span>Type_abbreviations<span class="Delimiter">,</
 ]
 <span class="traceContains">+app: foo: abc</span>
 
-<span class="Delimiter">:(before &quot;End print Special-cases(r, data)&quot;)</span>
+<span class="Delimiter">:(before &quot;End inspect Special-cases(r, data)&quot;)</span>
 <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_text<span class="Delimiter">(</span>r<span class="Delimiter">))</span> <span class="Delimiter">{</span>
   assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>data<span class="Delimiter">));</span>
   <span class="Identifier">return</span> read_mu_text<span class="Delimiter">(</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
 <span class="Delimiter">}</span>
 
+<span class="Delimiter">:(before &quot;End $print Special-cases&quot;)</span>
+<span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_text<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span>
+  cout &lt;&lt; read_mu_text<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="Delimiter">:(scenario unicode_string)</span>
 <span class="muRecipe">def</span> main [
   <span class="Constant">1</span>:text<span class="Special"> &lt;- </span><span class="Normal">new</span> [♠]
@@ -172,6 +178,36 @@ string read_mu_text<span class="Delimiter">(</span><span class="Normal">int</spa
   <span class="Delimiter">}</span>
   <span class="Identifier">return</span> tmp<span class="Delimiter">.</span>str<span class="Delimiter">();</span>
 <span class="Delimiter">}</span>
+
+<span class="SalientComment">//:: 'cheating' by using the host system</span>
+
+<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
+_READ<span class="Delimiter">,</span>
+<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
+put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;$read&quot;</span><span class="Delimiter">,</span> _READ<span class="Delimiter">);</span>
+<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
+<span class="Normal">case</span> _READ: <span class="Delimiter">{</span>
+  <span class="Identifier">break</span><span class="Delimiter">;</span>
+<span class="Delimiter">}</span>
+<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
+<span class="Normal">case</span> _READ: <span class="Delimiter">{</span>
+  skip_whitespace<span class="Delimiter">(</span>cin<span class="Delimiter">);</span>
+  string result<span class="Delimiter">;</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>has_data<span class="Delimiter">(</span>cin<span class="Delimiter">))</span>
+    cin &gt;&gt; result<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>new_mu_text<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">:(code)</span>
+<span class="Normal">void</span> skip_whitespace<span class="Delimiter">(</span>istream&amp; in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
+  <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
+    <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
+    <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
+    <span class="Normal">else</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
+  <span class="Delimiter">}</span>
+<span class="Delimiter">}</span>
 </pre>
 </body>
 </html>
diff --git a/html/058to_text.cc.html b/html/058to_text.cc.html
index 961df126..e2be9a6f 100644
--- a/html/058to_text.cc.html
+++ b/html/058to_text.cc.html
@@ -50,7 +50,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
 <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
 <span class="Normal">case</span> TO_TEXT: <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>new_mu_text<span class="Delimiter">(</span>print_mu<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</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>new_mu_text<span class="Delimiter">(</span>inspect<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))));</span>
   <span class="Identifier">break</span><span class="Delimiter">;</span>
 <span class="Delimiter">}</span>
 </pre>
diff --git a/html/061text.mu.html b/html/061text.mu.html
index e438b576..08a836b3 100644
--- a/html/061text.mu.html
+++ b/html/061text.mu.html
@@ -1341,6 +1341,89 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
     1:array:character <span class="Special">&lt;-</span> <span class="Constant">[]</span>
   ]
 ]
+
+<span class="muRecipe">def</span> parse-whole-number in:text<span class="muRecipe"> -&gt; </span>out:num, error?:bool [
+  <span class="Constant">local-scope</span>
+  <span class="Constant">load-ingredients</span>
+  out:num <span class="Special">&lt;-</span> copy<span class="Constant"> 0</span>
+  result:num <span class="Special">&lt;-</span> copy<span class="Constant"> 0</span>  <span class="Comment"># temporary location</span>
+  i:num <span class="Special">&lt;-</span> copy<span class="Constant"> 0</span>
+  len:num <span class="Special">&lt;-</span> length *in
+  <span class="Delimiter">{</span>
+    done?:bool <span class="Special">&lt;-</span> greater-or-equal i, len
+    <span class="muControl">break-if</span> done?
+    c:char <span class="Special">&lt;-</span> index *in, i
+    x:num <span class="Special">&lt;-</span> character-to-code c
+    digit:num, error?:bool <span class="Special">&lt;-</span> character-code-to-digit x
+    <span class="muControl">reply-if</span> error?
+    result <span class="Special">&lt;-</span> multiply result,<span class="Constant"> 10</span>
+    result <span class="Special">&lt;-</span> add result, digit
+    i <span class="Special">&lt;-</span> add i,<span class="Constant"> 1</span>
+    <span class="muControl">loop</span>
+  <span class="Delimiter">}</span>
+  <span class="Comment"># no error; all digits were valid</span>
+  out <span class="Special">&lt;-</span> copy result
+]
+
+<span class="Comment"># (contributed by Ella Couch)</span>
+<span class="muRecipe">recipe</span> character-code-to-digit character-code:number<span class="muRecipe"> -&gt; </span>result:number, error?:boolean [
+  <span class="Constant">local-scope</span>
+  <span class="Constant">load-ingredients</span>
+  result <span class="Special">&lt;-</span> copy<span class="Constant"> 0</span>
+  error? <span class="Special">&lt;-</span> lesser-than character-code,<span class="Constant"> 48</span>  <span class="Comment"># '0'</span>
+  <span class="muControl">reply-if</span> error?
+  error? <span class="Special">&lt;-</span> greater-than character-code,<span class="Constant"> 57</span>  <span class="Comment"># '9'</span>
+  <span class="muControl">reply-if</span> error?
+  result <span class="Special">&lt;-</span> subtract character-code,<span class="Constant"> 48</span>
+]
+
+<span class="muScenario">scenario</span> character-code-to-digit-contain-only-digit [
+  <span class="Constant">local-scope</span>
+  a:number <span class="Special">&lt;-</span> copy<span class="Constant"> 48</span>  <span class="Comment"># character code for '0'</span>
+  run [
+    10:number/<span class="Special">raw</span>, 11:boolean/<span class="Special">raw</span> <span class="Special">&lt;-</span> character-code-to-digit a
+  ]
+  memory-should-contain [
+   <span class="Constant"> 10</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span>
+   <span class="Constant"> 11</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span>  <span class="Comment"># no error</span>
+  ]
+]
+
+<span class="muScenario">scenario</span> character-code-to-digit-contain-only-digit-2 [
+  <span class="Constant">local-scope</span>
+  a:number <span class="Special">&lt;-</span> copy<span class="Constant"> 57</span>  <span class="Comment"># character code for '9'</span>
+  run [
+    1:number/<span class="Special">raw</span>, 2:boolean/<span class="Special">raw</span> <span class="Special">&lt;-</span> character-code-to-digit a
+  ]
+  memory-should-contain [
+   <span class="Constant"> 1</span> <span class="Special">&lt;-</span><span class="Constant"> 9</span>
+   <span class="Constant"> 2</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span>  <span class="Comment"># no error</span>
+  ]
+]
+
+<span class="muScenario">scenario</span> character-code-to-digit-handles-codes-lower-than-zero [
+  <span class="Constant">local-scope</span>
+  a:number <span class="Special">&lt;-</span> copy<span class="Constant"> 47</span>
+  run [
+    10:number/<span class="Special">raw</span>, 11:boolean/<span class="Special">raw</span> <span class="Special">&lt;-</span> character-code-to-digit a
+  ]
+  memory-should-contain [
+   <span class="Constant"> 10</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span>
+   <span class="Constant"> 11</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span>  <span class="Comment"># error</span>
+  ]
+]
+
+<span class="muScenario">scenario</span> character-code-to-digit-handles-codes-larger-than-nine [
+  <span class="Constant">local-scope</span>
+  a:number <span class="Special">&lt;-</span> copy<span class="Constant"> 58</span>
+  run [
+    10:number/<span class="Special">raw</span>, 11:boolean/<span class="Special">raw</span> <span class="Special">&lt;-</span> character-code-to-digit a
+  ]
+  memory-should-contain [
+   <span class="Constant"> 10</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span>
+   <span class="Constant"> 11</span> <span class="Special">&lt;-</span><span class="Constant"> 1</span>  <span class="Comment"># error</span>
+  ]
+]
 </pre>
 </body>
 </html>
diff --git a/html/089scenario_filesystem.cc.html b/html/089scenario_filesystem.cc.html
index d0cc5e17..13cc4a90 100644
--- a/html/089scenario_filesystem.cc.html
+++ b/html/089scenario_filesystem.cc.html
@@ -278,14 +278,6 @@ string munge_resources_contents<span class="Delimiter">(</span><span class="Norm
   <span class="Normal">delete</span> type<span class="Delimiter">;</span>
   <span class="Identifier">return</span> result<span class="Delimiter">;</span>
 <span class="Delimiter">}</span>
-
-<span class="Normal">void</span> skip_whitespace<span class="Delimiter">(</span>istream&amp; in<span class="Delimiter">)</span> <span class="Delimiter">{</span>
-  <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
-    <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
-    <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span>
-    <span class="Normal">else</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
-  <span class="Delimiter">}</span>
-<span class="Delimiter">}</span>
 </pre>
 </body>
 </html>