about summary refs log tree commit diff stats
path: root/html
diff options
context:
space:
mode:
Diffstat (limited to 'html')
-rw-r--r--html/020run.cc.html5
-rw-r--r--html/032array.cc.html6
-rw-r--r--html/035lookup.cc.html4
-rw-r--r--html/075channel.mu.html1
-rw-r--r--html/082scenario_screen.cc.html6
-rw-r--r--html/087file.cc.html4
-rw-r--r--html/088file.mu.html32
-rw-r--r--html/filesystem.mu.html24
8 files changed, 51 insertions, 31 deletions
diff --git a/html/020run.cc.html b/html/020run.cc.html
index acfcb8a4..61706723 100644
--- a/html/020run.cc.html
+++ b/html/020run.cc.html
@@ -327,7 +327,10 @@ vector&lt;<span class="Normal">double</span>&gt; read_memory<span class="Delimit
   <span class="Normal">if</span> <span class="Delimiter">(</span>is_dummy<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
   <span class="Comment">// End Preprocess write_memory(x, data)</span>
-  <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
+    raise &lt;&lt; <span class="Constant">&quot;can't write to location 0 in '&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
+    <span class="Identifier">return</span><span class="Delimiter">;</span>
+  <span class="Delimiter">}</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>size_mismatch<span class="Delimiter">(</span>x<span class="Delimiter">,</span> data<span class="Delimiter">))</span> <span class="Delimiter">{</span>
     raise &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;size mismatch in storing to '&quot;</span> &lt;&lt; x<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;' (&quot;</span> &lt;&lt; size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot; vs &quot;</span> &lt;&lt; SIZE<span class="Delimiter">(</span>data<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;) at '&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
     <span class="Identifier">return</span><span class="Delimiter">;</span>
diff --git a/html/032array.cc.html b/html/032array.cc.html
index cd0955f2..78c802e6 100644
--- a/html/032array.cc.html
+++ b/html/032array.cc.html
@@ -441,7 +441,7 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
   <span class="Comment">// Update PUT_INDEX index in Run</span>
   vector&lt;<span class="Normal">double</span>&gt; index_val<span class="Delimiter">(</span>read_memory<span class="Delimiter">(</span>index<span class="Delimiter">));</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> &lt; <span class="Constant">0</span> || index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> &gt;= get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base_address<span class="Delimiter">))</span> <span class="Delimiter">{</span>
-    raise &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;invalid index &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> &lt;&lt; <span class="cSpecial">'\n'</span> &lt;&lt; end<span class="Delimiter">();</span>
+    raise &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;invalid index &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>index_val<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot; in '&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
     <span class="Identifier">break</span><span class="Delimiter">;</span>
   <span class="Delimiter">}</span>
   reagent element<span class="Delimiter">;</span>
@@ -473,7 +473,7 @@ def main [
   <span class="Constant">8</span>:point<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span>
   <span class="Constant">1</span>:array:point<span class="Special"> &lt;- </span>put-index <span class="Constant">1</span>:array:point<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">,</span> <span class="Constant">8</span>:point  <span class="Comment"># '4' is less than size of array in locations, but larger than its length in elements</span>
 ]
-<span class="traceContains">+error: main: invalid index 4</span>
+<span class="traceContains">+error: main: invalid index 4 in '1:array:point &lt;- put-index 1:array:point, 4, 8:point'</span>
 
 <span class="Delimiter">:(scenario put_index_out_of_bounds_2)</span>
 <span class="Special">% Hide_errors = true;</span>
@@ -488,7 +488,7 @@ def main [
   <span class="Constant">8</span>:point<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span>
   <span class="Constant">1</span>:array:point<span class="Special"> &lt;- </span>put-index <span class="Constant">1</span>:array:point<span class="Delimiter">,</span> -<span class="Constant">1</span><span class="Delimiter">,</span> <span class="Constant">8</span>:point
 ]
-<span class="traceContains">+error: main: invalid index -1</span>
+<span class="traceContains">+error: main: invalid index -1 in '1:array:point &lt;- put-index 1:array:point, -1, 8:point'</span>
 
 <span class="Delimiter">:(scenario put_index_product_error)</span>
 <span class="Special">% Hide_errors = true;</span>
diff --git a/html/035lookup.cc.html b/html/035lookup.cc.html
index c6fa72cf..0cab088a 100644
--- a/html/035lookup.cc.html
+++ b/html/035lookup.cc.html
@@ -92,10 +92,6 @@ def main [
 
 <span class="Delimiter">:(before &quot;End Preprocess write_memory(x, data)&quot;)</span>
 canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
-<span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
-  raise &lt;&lt; <span class="Constant">&quot;can't write to location 0 in '&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
-  <span class="Identifier">return</span><span class="Delimiter">;</span>
-<span class="Delimiter">}</span>
 
 <span class="Comment">//: writes to address 0 always loudly fail</span>
 <span class="Delimiter">:(scenario store_to_0_fails)</span>
diff --git a/html/075channel.mu.html b/html/075channel.mu.html
index 8d87a38d..49bb5fb3 100644
--- a/html/075channel.mu.html
+++ b/html/075channel.mu.html
@@ -337,7 +337,6 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   closed?:boolean<span class="Special"> &lt;- </span>get *chan, <span class="Constant">closed?:offset</span>
   <span class="muControl">return-if</span> closed?
 ]
-
 <span class="muRecipe">after</span> <span class="Constant">&lt;channel-read-empty&gt;</span> [
   closed?:boolean<span class="Special"> &lt;- </span>get *chan, <span class="Constant">closed?:offset</span>
   <span class="Delimiter">{</span>
diff --git a/html/082scenario_screen.cc.html b/html/082scenario_screen.cc.html
index fe7b980d..df06104d 100644
--- a/html/082scenario_screen.cc.html
+++ b/html/082scenario_screen.cc.html
@@ -35,9 +35,9 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 <pre id='vimCodeElement'>
 <span class="Comment">//: Clean syntax to manipulate and check the screen in scenarios.</span>
 <span class="Comment">//: Instructions 'assume-screen' and 'screen-should-contain' implicitly create</span>
-<span class="Comment">//: a variable called 'screen' that is accessible inside other 'run'</span>
-<span class="Comment">//: instructions in the scenario. 'screen-should-contain' can check unicode</span>
-<span class="Comment">//: characters in the fake screen</span>
+<span class="Comment">//: a variable called 'screen' that is accessible to later instructions in the</span>
+<span class="Comment">//: scenario. 'screen-should-contain' can check unicode characters in the fake</span>
+<span class="Comment">//: screen</span>
 
 <span class="Comment">//: first make sure we don't mangle these functions in other transforms</span>
 <span class="Delimiter">:(before &quot;End initialize_transform_rewrite_literal_string_to_text()&quot;)</span>
diff --git a/html/087file.cc.html b/html/087file.cc.html
index 7a0843f5..d8af7ae0 100644
--- a/html/087file.cc.html
+++ b/html/087file.cc.html
@@ -158,8 +158,8 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
     raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;first ingredient of '$write-to-file' should be a number, but got '&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
     <span class="Identifier">break</span><span class="Delimiter">;</span>
   <span class="Delimiter">}</span>
-  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_number<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
-    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;second ingredient of '$write-to-file' should be a number, but got '&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_character<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
+    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;second ingredient of '$write-to-file' should be a character, but got '&quot;</span> &lt;&lt; to_string<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
     <span class="Identifier">break</span><span class="Delimiter">;</span>
   <span class="Delimiter">}</span>
   <span class="Identifier">break</span><span class="Delimiter">;</span>
diff --git a/html/088file.mu.html b/html/088file.mu.html
index a8f2153c..e2dec15c 100644
--- a/html/088file.mu.html
+++ b/html/088file.mu.html
@@ -41,15 +41,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 <span class="muRecipe">def</span> start-reading fs:address:filesystem, filename:address:array:character<span class="muRecipe"> -&gt; </span>contents:address:source:character [
   <span class="Constant">local-scope</span>
   <span class="Constant">load-ingredients</span>
-  x:number/file<span class="Special"> &lt;- </span>$open-file-for-reading filename
+  file:number<span class="Special"> &lt;- </span>$open-file-for-reading filename
   contents:address:source:character, sink:address:sink:character<span class="Special"> &lt;- </span>new-channel <span class="Constant">30</span>
-  $print <span class="Constant">[sink: ]</span>, sink, <span class="Constant">10/newline</span>
-  chan:address:channel:character<span class="Special"> &lt;- </span>get *sink, <span class="Constant">chan:offset</span>
-  $print <span class="Constant">[chan in start-reading: ]</span>, chan, <span class="Constant">10/newline</span>
-  start-running transmit x, sink
+  start-running transmit-from-file file, sink
 ]
 
-<span class="muRecipe">def</span> transmit file:number, sink:address:sink:character<span class="muRecipe"> -&gt; </span>file:number, sink:address:sink:character [
+<span class="muRecipe">def</span> transmit-from-file file:number, sink:address:sink:character<span class="muRecipe"> -&gt; </span>file:number, sink:address:sink:character [
   <span class="Constant">local-scope</span>
   <span class="Constant">load-ingredients</span>
   <span class="Delimiter">{</span>
@@ -58,9 +55,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
     sink<span class="Special"> &lt;- </span>write sink, c
     <span class="muControl">loop</span>
   <span class="Delimiter">}</span>
-  $print <span class="Constant">[closing chan after reading file]</span>, <span class="Constant">10/newline</span>
   sink<span class="Special"> &lt;- </span>close sink
-  $print <span class="Constant">[returning from 'transmit']</span>, <span class="Constant">10/newline</span>
+  $close-file file
+]
+
+<span class="muRecipe">def</span> start-writing fs:address:filesystem, filename:address:array:character<span class="muRecipe"> -&gt; </span>sink:address:sink:character, routine-id:number [
+  <span class="Constant">local-scope</span>
+  <span class="Constant">load-ingredients</span>
+  file:number<span class="Special"> &lt;- </span>$open-file-for-writing filename
+  source:address:source:character, sink:address:sink:character<span class="Special"> &lt;- </span>new-channel <span class="Constant">30</span>
+  routine-id<span class="Special"> &lt;- </span>start-running transmit-to-file file, source
+]
+
+<span class="muRecipe">def</span> transmit-to-file file:number, source:address:source:character<span class="muRecipe"> -&gt; </span>file:number, source:address:source:character [
+  <span class="Constant">local-scope</span>
+  <span class="Constant">load-ingredients</span>
+  <span class="Delimiter">{</span>
+    c:character, done?:boolean, source<span class="Special"> &lt;- </span>read source
+    <span class="muControl">break-if</span> done?
+    $write-to-file file, c
+    <span class="muControl">loop</span>
+  <span class="Delimiter">}</span>
+  $close-file file
 ]
 </pre>
 </body>
diff --git a/html/filesystem.mu.html b/html/filesystem.mu.html
index 17cecb3a..8fb32b8a 100644
--- a/html/filesystem.mu.html
+++ b/html/filesystem.mu.html
@@ -30,21 +30,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 </head>
 <body>
 <pre id='vimCodeElement'>
+<span class="Comment"># example program: copy one file into another, character by character</span>
+<span class="Comment"># BEWARE: this will modify your file system</span>
+<span class="Comment"># before running it, put some text into /tmp/mu-x</span>
+<span class="Comment"># after running it, check /tmp/mu-y</span>
+
 <span class="muRecipe">def</span> main [
   <span class="Constant">local-scope</span>
-  $print <span class="Constant">[file to read from: ]</span>, <span class="Constant">[/tmp/mu-fs]</span>
-  <span class="Comment"># initialize filesystem</span>
-  fs:address:filesystem<span class="Special"> &lt;- </span>copy <span class="Constant">0/real-filesystem</span>
-  content-source:address:source:character<span class="Special"> &lt;- </span>start-reading fs, <span class="Constant">[/tmp/mu-fs]</span>
-  <span class="Comment"># read from channel until exhausted and print out characters</span>
+  source-file:address:source:character<span class="Special"> &lt;- </span>start-reading <span class="Constant">0/real-filesystem</span>, <span class="Constant">[/tmp/mu-x]</span>
+  sink-file:address:sink:character, write-routine:number<span class="Special"> &lt;- </span>start-writing <span class="Constant">0/real-filesystem</span>, <span class="Constant">[/tmp/mu-y]</span>
   <span class="Delimiter">{</span>
-    c:character, done?:boolean, content-source<span class="Special"> &lt;- </span>read content-source
+    c:character, done?:boolean, source-file<span class="Special"> &lt;- </span>read source-file
     <span class="muControl">break-if</span> done?
-    $print <span class="Constant">[Next: ]</span>, c, <span class="Constant">10/newline</span>
+    eof?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">-1</span>
+    <span class="muControl">break-if</span> eof?
+    sink-file<span class="Special"> &lt;- </span>write sink-file, c
     <span class="muControl">loop</span>
   <span class="Delimiter">}</span>
-  $print <span class="Constant">[Done reading]</span>, <span class="Constant">10/newline</span>
-  <span class="Comment"># TODO: writing to file</span>
+  close sink-file
+  <span class="Comment"># make sure to wait for the file to be actually written to disk</span>
+  <span class="Comment"># (Mu practices structured concurrency: <a href="http://250bpm.com/blog:71)">http://250bpm.com/blog:71)</a></span>
+  wait-for-routine write-routine
 ]
 </pre>
 </body>