From 513ba3308502df6b576afd95aa20a57e0ec76d1f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 18 Aug 2016 21:31:01 -0700 Subject: 3227 --- html/020run.cc.html | 5 ++++- html/032array.cc.html | 6 +++--- html/035lookup.cc.html | 4 ---- html/075channel.mu.html | 1 - html/082scenario_screen.cc.html | 6 +++--- html/087file.cc.html | 4 ++-- html/088file.mu.html | 32 ++++++++++++++++++++++++-------- html/filesystem.mu.html | 24 +++++++++++++++--------- 8 files changed, 51 insertions(+), 31 deletions(-) (limited to 'html') 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<double> read_memoryif (is_dummy(x)) return; if (is_literal(x)) return; // End Preprocess write_memory(x, data) - if (x.value == 0) return; + if (x.value == 0) { + raise << "can't write to location 0 in '" << to_original_string(current_instruction()) << "'\n" << end(); + return; + } if (size_mismatch(x, data)) { raise << maybe(current_recipe_name()) << "size mismatch in storing to '" << x.original_string << "' (" << size_of(x) << " vs " << SIZE(data) << ") at '" << to_original_string(current_instruction()) << "'\n" << end(); return; 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(Recipe_ordinal,// Update PUT_INDEX index in Run vector<double> index_val(read_memory(index)); if (index_val.at(0) < 0 || index_val.at(0) >= get_or_insert(Memory, base_address)) { - raise << maybe(current_recipe_name()) << "invalid index " << no_scientific(index_val.at(0)) << '\n' << end(); + raise << maybe(current_recipe_name()) << "invalid index " << no_scientific(index_val.at(0)) << " in '" << to_original_string(current_instruction()) << "'\n" << end(); break; } reagent element; @@ -473,7 +473,7 @@ def main [ 8:point <- merge 34, 35 1:array:point <- put-index 1:array:point, 4, 8:point # '4' is less than size of array in locations, but larger than its length in elements ] -+error: main: invalid index 4 ++error: main: invalid index 4 in '1:array:point <- put-index 1:array:point, 4, 8:point' :(scenario put_index_out_of_bounds_2) % Hide_errors = true; @@ -488,7 +488,7 @@ def main [ 8:point <- merge 34, 35 1:array:point <- put-index 1:array:point, -1, 8:point ] -+error: main: invalid index -1 ++error: main: invalid index -1 in '1:array:point <- put-index 1:array:point, -1, 8:point' :(scenario put_index_product_error) % Hide_errors = true; 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 [ :(before "End Preprocess write_memory(x, data)") canonize(x); -if (x.value == 0) { - raise << "can't write to location 0 in '" << to_original_string(current_instruction()) << "'\n" << end(); - return; -} //: writes to address 0 always loudly fail :(scenario store_to_0_fails) 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 <- get *chan, closed?:offset return-if closed? ] - after <channel-read-empty> [ closed?:boolean <- get *chan, closed?:offset { 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
 //: Clean syntax to manipulate and check the screen in scenarios.
 //: Instructions 'assume-screen' and 'screen-should-contain' implicitly create
-//: a variable called 'screen' that is accessible inside other 'run'
-//: instructions in the scenario. 'screen-should-contain' can check unicode
-//: characters in the fake screen
+//: a variable called 'screen' that is accessible to later instructions in the
+//: scenario. 'screen-should-contain' can check unicode characters in the fake
+//: screen
 
 //: first make sure we don't mangle these functions in other transforms
 :(before "End initialize_transform_rewrite_literal_string_to_text()")
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(Recipe_ordinal,(get(Recipe, r).name) << "first ingredient of '$write-to-file' should be a number, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end();
     break;
   }
-  if (!is_mu_number(inst.ingredients.at(1))) {
-    raise << maybe(get(Recipe, r).name) << "second ingredient of '$write-to-file' should be a number, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end();
+  if (!is_mu_character(inst.ingredients.at(1))) {
+    raise << maybe(get(Recipe, r).name) << "second ingredient of '$write-to-file' should be a character, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end();
     break;
   }
   break;
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
 def start-reading fs:address:filesystem, filename:address:array:character -> contents:address:source:character [
   local-scope
   load-ingredients
-  x:number/file <- $open-file-for-reading filename
+  file:number <- $open-file-for-reading filename
   contents:address:source:character, sink:address:sink:character <- new-channel 30
-  $print [sink: ], sink, 10/newline
-  chan:address:channel:character <- get *sink, chan:offset
-  $print [chan in start-reading: ], chan, 10/newline
-  start-running transmit x, sink
+  start-running transmit-from-file file, sink
 ]
 
-def transmit file:number, sink:address:sink:character -> file:number, sink:address:sink:character [
+def transmit-from-file file:number, sink:address:sink:character -> file:number, sink:address:sink:character [
   local-scope
   load-ingredients
   {
@@ -58,9 +55,28 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
     sink <- write sink, c
     loop
   }
-  $print [closing chan after reading file], 10/newline
   sink <- close sink
-  $print [returning from 'transmit'], 10/newline
+  $close-file file
+]
+
+def start-writing fs:address:filesystem, filename:address:array:character -> sink:address:sink:character, routine-id:number [
+  local-scope
+  load-ingredients
+  file:number <- $open-file-for-writing filename
+  source:address:source:character, sink:address:sink:character <- new-channel 30
+  routine-id <- start-running transmit-to-file file, source
+]
+
+def transmit-to-file file:number, source:address:source:character -> file:number, source:address:source:character [
+  local-scope
+  load-ingredients
+  {
+    c:character, done?:boolean, source <- read source
+    break-if done?
+    $write-to-file file, c
+    loop
+  }
+  $close-file file
 ]
 
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
+# example program: copy one file into another, character by character
+# BEWARE: this will modify your file system
+# before running it, put some text into /tmp/mu-x
+# after running it, check /tmp/mu-y
+
 def main [
   local-scope
-  $print [file to read from: ], [/tmp/mu-fs]
-  # initialize filesystem
-  fs:address:filesystem <- copy 0/real-filesystem
-  content-source:address:source:character <- start-reading fs, [/tmp/mu-fs]
-  # read from channel until exhausted and print out characters
+  source-file:address:source:character <- start-reading 0/real-filesystem, [/tmp/mu-x]
+  sink-file:address:sink:character, write-routine:number <- start-writing 0/real-filesystem, [/tmp/mu-y]
   {
-    c:character, done?:boolean, content-source <- read content-source
+    c:character, done?:boolean, source-file <- read source-file
     break-if done?
-    $print [Next: ], c, 10/newline
+    eof?:boolean <- equal c, -1
+    break-if eof?
+    sink-file <- write sink-file, c
     loop
   }
-  $print [Done reading], 10/newline
-  # TODO: writing to file
+  close sink-file
+  # make sure to wait for the file to be actually written to disk
+  # (Mu practices structured concurrency: http://250bpm.com/blog:71)
+  wait-for-routine write-routine
 ]
 
-- cgit 1.4.1-2-gfad0