diff options
Diffstat (limited to 'html')
-rw-r--r-- | html/020run.cc.html | 5 | ||||
-rw-r--r-- | html/032array.cc.html | 6 | ||||
-rw-r--r-- | html/035lookup.cc.html | 4 | ||||
-rw-r--r-- | html/075channel.mu.html | 1 | ||||
-rw-r--r-- | html/082scenario_screen.cc.html | 6 | ||||
-rw-r--r-- | html/087file.cc.html | 4 | ||||
-rw-r--r-- | html/088file.mu.html | 32 | ||||
-rw-r--r-- | html/filesystem.mu.html | 24 |
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<<span class="Normal">double</span>> 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 << <span class="Constant">"can't write to location 0 in '"</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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 << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"size mismatch in storing to '"</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">"' ("</span> << size_of<span class="Delimiter">(</span>x<span class="Delimiter">)</span> << <span class="Constant">" vs "</span> << SIZE<span class="Delimiter">(</span>data<span class="Delimiter">)</span> << <span class="Constant">") at '"</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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<<span class="Normal">double</span>> 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> < <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> >= get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base_address<span class="Delimiter">))</span> <span class="Delimiter">{</span> - raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"invalid index "</span> << 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> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> + raise << maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> << <span class="Constant">"invalid index "</span> << 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> << <span class="Constant">" in '"</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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"> <- </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"> <- </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 <- 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"> <- </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"> <- </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 <- 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 "End Preprocess write_memory(x, data)")</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 << <span class="Constant">"can't write to location 0 in '"</span> << to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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"> <- </span>get *chan, <span class="Constant">closed?:offset</span> <span class="muControl">return-if</span> closed? ] - <span class="muRecipe">after</span> <span class="Constant"><channel-read-empty></span> [ closed?:boolean<span class="Special"> <- </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 "End initialize_transform_rewrite_literal_string_to_text()")</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 << 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> << <span class="Constant">"first ingredient of '$write-to-file' should be a number, but got '"</span> << 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> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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 << 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> << <span class="Constant">"second ingredient of '$write-to-file' should be a number, but got '"</span> << 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> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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 << 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> << <span class="Constant">"second ingredient of '$write-to-file' should be a character, but got '"</span> << 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> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << 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"> -> </span>contents:address:source:character [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> - x:number/file<span class="Special"> <- </span>$open-file-for-reading filename + file:number<span class="Special"> <- </span>$open-file-for-reading filename contents:address:source:character, sink:address:sink:character<span class="Special"> <- </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"> <- </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"> -> </span>file:number, sink:address:sink:character [ +<span class="muRecipe">def</span> transmit-from-file file:number, sink:address:sink:character<span class="muRecipe"> -> </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"> <- </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"> <- </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"> -> </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"> <- </span>$open-file-for-writing filename + source:address:source:character, sink:address:sink:character<span class="Special"> <- </span>new-channel <span class="Constant">30</span> + routine-id<span class="Special"> <- </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"> -> </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"> <- </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"> <- </span>copy <span class="Constant">0/real-filesystem</span> - content-source:address:source:character<span class="Special"> <- </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"> <- </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"> <- </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"> <- </span>read content-source + c:character, done?:boolean, source-file<span class="Special"> <- </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"> <- </span>equal c, <span class="Constant">-1</span> + <span class="muControl">break-if</span> eof? + sink-file<span class="Special"> <- </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> |