about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--088file.mu42
-rw-r--r--089scenario_filesystem.cc116
-rw-r--r--090scenario_filesystem_test.mu28
3 files changed, 93 insertions, 93 deletions
diff --git a/088file.mu b/088file.mu
index b0a9b785..b3c724c0 100644
--- a/088file.mu
+++ b/088file.mu
@@ -1,20 +1,20 @@
-# Wrappers around file system primitives that take a 'filesystem' object and
+# Wrappers around file system primitives that take a 'resources' object and
 # are thus easier to test.
 
-container filesystem [
-  data:&:@:file-mapping
+container resources [
+  data:&:@:resource
 ]
 
-container file-mapping [
+container resource [
   name:text
   contents:text
 ]
 
-def start-reading fs:&:filesystem, filename:text -> contents:&:source:char [
+def start-reading resources:&:resources, filename:text -> contents:&:source:char [
   local-scope
   load-ingredients
   {
-    break-if fs
+    break-if resources
     # real file system
     file:num <- $open-file-for-reading filename
     assert file, [file not found]
@@ -24,12 +24,12 @@ def start-reading fs:&:filesystem, filename:text -> contents:&:source:char [
   }
   # fake file system
   i:num <- copy 0
-  data:&:@:file-mapping <- get *fs, data:offset
+  data:&:@:resource <- get *resources, data:offset
   len:num <- length *data
   {
     done?:bool <- greater-or-equal i, len
     break-if done?
-    tmp:file-mapping <- index *data, i
+    tmp:resource <- index *data, i
     i <- add i, 1
     curr-filename:text <- get tmp, name:offset
     found?:bool <- equal filename, curr-filename
@@ -71,12 +71,12 @@ def transmit-from-text contents:text, sink:&:sink:char -> sink:&:sink:char [
   sink <- close sink
 ]
 
-def start-writing fs:&:filesystem, filename:text -> sink:&:sink:char, routine-id:num [
+def start-writing resources:&:resources, filename:text -> sink:&:sink:char, routine-id:num [
   local-scope
   load-ingredients
   source:&:source:char, sink:&:sink:char <- new-channel 30
   {
-    break-if fs
+    break-if resources
     # real file system
     file:num <- $open-file-for-writing filename
     assert file, [no such file]
@@ -85,7 +85,7 @@ def start-writing fs:&:filesystem, filename:text -> sink:&:sink:char, routine-id
   }
   # fake file system
   # beware: doesn't support multiple concurrent writes yet
-  routine-id <- start-running transmit-to-fake-file fs, filename, source
+  routine-id <- start-running transmit-to-fake-file resources, filename, source
 ]
 
 def transmit-to-file file:num, source:&:source:char -> source:&:source:char [
@@ -100,7 +100,7 @@ def transmit-to-file file:num, source:&:source:char -> source:&:source:char [
   file <- $close-file file
 ]
 
-def transmit-to-fake-file fs:&:filesystem, filename:text, source:&:source:char -> fs:&:filesystem, source:&:source:char [
+def transmit-to-fake-file resources:&:resources, filename:text, source:&:source:char -> resources:&:resources, source:&:source:char [
   local-scope
   load-ingredients
   # compute new file contents
@@ -112,35 +112,35 @@ def transmit-to-fake-file fs:&:filesystem, filename:text, source:&:source:char -
     loop
   }
   contents:text <- buffer-to-array buf
-  new-file-mapping:file-mapping <- merge filename, contents
-  # write to filesystem
+  new-resource:resource <- merge filename, contents
+  # write to resources
   curr-filename:text <- copy 0
-  data:&:@:file-mapping <- get *fs, data:offset
+  data:&:@:resource <- get *resources, data:offset
   # replace file contents if it already exists
   i:num <- copy 0
   len:num <- length *data
   {
     done?:bool <- greater-or-equal i, len
     break-if done?
-    tmp:file-mapping <- index *data, i
+    tmp:resource <- index *data, i
     curr-filename <- get tmp, name:offset
     found?:bool <- equal filename, curr-filename
     loop-unless found?
-    put-index *data, i, new-file-mapping
+    put-index *data, i, new-resource
     reply
   }
   # if file didn't already exist, make room for it
   new-len:num <- add len, 1
-  new-data:&:@:file-mapping <- new file-mapping:type, new-len
-  put *fs, data:offset, new-data
+  new-data:&:@:resource <- new resource:type, new-len
+  put *resources, data:offset, new-data
   # copy over old files
   i:num <- copy 0
   {
     done?:bool <- greater-or-equal i, len
     break-if done?
-    tmp:file-mapping <- index *data, i
+    tmp:resource <- index *data, i
     put-index *new-data, i, tmp
   }
   # write new file
-  put-index *new-data, len, new-file-mapping
+  put-index *new-data, len, new-resource
 ]
diff --git a/089scenario_filesystem.cc b/089scenario_filesystem.cc
index 95880cce..6f65b06f 100644
--- a/089scenario_filesystem.cc
+++ b/089scenario_filesystem.cc
@@ -1,14 +1,14 @@
 //: Clean syntax to manipulate and check the file system in scenarios.
-//: Instructions 'assume-filesystem' and 'filesystem-should-contain' implicitly create
-//: a variable called 'filesystem' that is accessible to later instructions in
-//: the scenario. 'filesystem-should-contain' can check unicode characters in
-//: the fake filesystem
+//: Instructions 'assume-resources' and 'resources-should-contain' implicitly create
+//: a variable called 'resources' that is accessible to later instructions in
+//: the scenario. 'resources-should-contain' can check unicode characters in
+//: the fake resources
 
 :(scenarios run_mu_scenario)
 :(scenario simple_filesystem)
 scenario simple-filesystem [
   local-scope
-  assume-filesystem [
+  assume-resources [
     # file 'a' containing two lines of data
     [a] <- [
       |a bc|
@@ -20,18 +20,18 @@ scenario simple-filesystem [
       |xyz|
     ]
   ]
-  data:&:@:file-mapping <- get *filesystem, data:offset
-  file1:file-mapping <- index *data, 0
+  data:&:@:resource <- get *resources, data:offset
+  file1:resource <- index *data, 0
   file1-name:text <- get file1, name:offset
   10:@:char/raw <- copy *file1-name
   file1-contents:text <- get file1, contents:offset
   100:@:char/raw <- copy *file1-contents
-  file2:file-mapping <- index *data, 1
+  file2:resource <- index *data, 1
   file2-name:text <- get file2, name:offset
   30:@:char/raw <- copy *file2-name
   file2-contents:text <- get file2, contents:offset
   40:@:char/raw <- copy *file2-contents
-  file3:file-mapping <- index *data, 2
+  file3:resource <- index *data, 2
   file3-name:text <- get file3, name:offset
   50:@:char/raw <- copy *file3-name
   file3-contents:text <- get file3, contents:offset
@@ -52,15 +52,15 @@ de f
 :(scenario escaping_file_contents)
 scenario escaping-file-contents [
   local-scope
-  assume-filesystem [
+  assume-resources [
     # file 'a' containing a '|'
     # need to escape '\' once for each block
     [a] <- [
       |x\\\\|yz|
     ]
   ]
-  data:&:@:file-mapping <- get *filesystem, data:offset
-  file1:file-mapping <- index *data, 0
+  data:&:@:resource <- get *resources, data:offset
+  file1:resource <- index *data, 0
   file1-name:text <- get file1, name:offset
   10:@:char/raw <- copy *file1-name
   file1-contents:text <- get file1, contents:offset
@@ -73,43 +73,43 @@ scenario escaping-file-contents [
 ]
 
 :(before "End Globals")
-extern const int FILESYSTEM = Next_predefined_global_for_scenarios++;
-//: give 'filesystem' a fixed location in scenarios
+extern const int RESOURCES = Next_predefined_global_for_scenarios++;
+//: give 'resources' a fixed location in scenarios
 :(before "End Special Scenario Variable Names(r)")
-Name[r]["filesystem"] = FILESYSTEM;
-//: make 'filesystem' always a raw location in scenarios
+Name[r]["resources"] = RESOURCES;
+//: make 'resources' always a raw location in scenarios
 :(before "End is_special_name Cases")
-if (s == "filesystem") return true;
+if (s == "resources") return true;
 :(before "End Initialize Type Of Special Name In Scenario(r)")
-if (r.name == "filesystem") r.type = new_type_tree("address:filesystem");
+if (r.name == "resources") r.type = new_type_tree("address:resources");
 
 :(before "End initialize_transform_rewrite_literal_string_to_text()")
-recipes_taking_literal_strings.insert("assume-filesystem");
+recipes_taking_literal_strings.insert("assume-resources");
 
 //: screen-should-contain is a regular instruction
 :(before "End Primitive Recipe Declarations")
-ASSUME_FILESYSTEM,
+ASSUME_RESOURCES,
 :(before "End Primitive Recipe Numbers")
-put(Recipe_ordinal, "assume-filesystem", ASSUME_FILESYSTEM);
+put(Recipe_ordinal, "assume-resources", ASSUME_RESOURCES);
 :(before "End Primitive Recipe Checks")
-case ASSUME_FILESYSTEM: {
+case ASSUME_RESOURCES: {
   break;
 }
 :(before "End Primitive Recipe Implementations")
-case ASSUME_FILESYSTEM: {
+case ASSUME_RESOURCES: {
   assert(scalar(ingredients.at(0)));
-  assume_filesystem(current_instruction().ingredients.at(0).name, current_recipe_name());
+  assume_resources(current_instruction().ingredients.at(0).name, current_recipe_name());
   break;
 }
 
 :(code)
-void assume_filesystem(const string& data, const string& caller) {
+void assume_resources(const string& data, const string& caller) {
   map<string, string> contents;
-  parse_filesystem(data, contents, caller);
-  construct_filesystem_object(contents);
+  parse_resources(data, contents, caller);
+  construct_resources_object(contents);
 }
 
-void parse_filesystem(const string& data, map<string, string>& out, const string& caller) {
+void parse_resources(const string& data, map<string, string>& out, const string& caller) {
   istringstream in(data);
   in >> std::noskipws;
   while (true) {
@@ -118,44 +118,44 @@ void parse_filesystem(const string& data, map<string, string>& out, const string
     if (!has_data(in)) break;
     string filename = next_word(in);
     if (*filename.begin() != '[') {
-      raise << caller << ": assume-filesystem: filename '" << filename << "' must begin with a '['\n" << end();
+      raise << caller << ": assume-resources: filename '" << filename << "' must begin with a '['\n" << end();
       break;
     }
     if (*filename.rbegin() != ']') {
-      raise << caller << ": assume-filesystem: filename '" << filename << "' must end with a ']'\n" << end();
+      raise << caller << ": assume-resources: filename '" << filename << "' must end with a ']'\n" << end();
       break;
     }
     filename.erase(0, 1);
     filename.erase(SIZE(filename)-1);
     if (!has_data(in)) {
-      raise << caller << ": assume-filesystem: no data for filename '" << filename << "'\n" << end();
+      raise << caller << ": assume-resources: no data for filename '" << filename << "'\n" << end();
       break;
     }
     string arrow = next_word(in);
     if (arrow != "<-") {
-      raise << caller << ": assume-filesystem: expected '<-' after filename '" << filename << "' but got '" << arrow << "'\n" << end();
+      raise << caller << ": assume-resources: expected '<-' after filename '" << filename << "' but got '" << arrow << "'\n" << end();
       break;
     }
     if (!has_data(in)) {
-      raise << caller << ": assume-filesystem: no data for filename '" << filename << "' after '<-'\n" << end();
+      raise << caller << ": assume-resources: no data for filename '" << filename << "' after '<-'\n" << end();
       break;
     }
     string contents = next_word(in);
     if (*contents.begin() != '[') {
-      raise << caller << ": assume-filesystem: file contents '" << contents << "' for filename '" << filename << "' must begin with a '['\n" << end();
+      raise << caller << ": assume-resources: file contents '" << contents << "' for filename '" << filename << "' must begin with a '['\n" << end();
       break;
     }
     if (*contents.rbegin() != ']') {
-      raise << caller << ": assume-filesystem: file contents '" << contents << "' for filename '" << filename << "' must end with a ']'\n" << end();
+      raise << caller << ": assume-resources: file contents '" << contents << "' for filename '" << filename << "' must end with a ']'\n" << end();
       break;
     }
     contents.erase(0, 1);
     contents.erase(SIZE(contents)-1);
-    put(out, filename, munge_filesystem_contents(contents, filename, caller));
+    put(out, filename, munge_resources_contents(contents, filename, caller));
   }
 }
 
-string munge_filesystem_contents(const string& data, const string& filename, const string& caller) {
+string munge_resources_contents(const string& data, const string& filename, const string& caller) {
   if (data.empty()) return "";
   istringstream in(data);
   in >> std::noskipws;
@@ -166,7 +166,7 @@ string munge_filesystem_contents(const string& data, const string& filename, con
     skip_whitespace(in);
     if (!has_data(in)) break;
     if (in.peek() != '|') {
-      raise << caller << ": assume-filesystem: file contents for filename '" << filename << "' must be delimited in '|'s\n" << end();
+      raise << caller << ": assume-resources: file contents for filename '" << filename << "' must be delimited in '|'s\n" << end();
       break;
     }
     in.get();  // skip leading '|'
@@ -177,7 +177,7 @@ string munge_filesystem_contents(const string& data, const string& filename, con
       if (line.at(i) == '\\') {
         ++i;  // skip
         if (i == SIZE(line)) {
-          raise << caller << ": assume-filesystem: file contents can't end a line with '\\'\n" << end();
+          raise << caller << ": assume-resources: file contents can't end a line with '\\'\n" << end();
           break;
         }
       }
@@ -189,9 +189,9 @@ string munge_filesystem_contents(const string& data, const string& filename, con
   return out.str();
 }
 
-void construct_filesystem_object(const map<string, string>& contents) {
-  int filesystem_data_address = allocate(SIZE(contents)*2 + /*array length*/1);
-  int curr = filesystem_data_address + /*skip refcount and length*/2;
+void construct_resources_object(const map<string, string>& contents) {
+  int resources_data_address = allocate(SIZE(contents)*2 + /*array length*/1);
+  int curr = resources_data_address + /*skip refcount and length*/2;
   for (map<string, string>::const_iterator p = contents.begin(); p != contents.end(); ++p) {
     put(Memory, curr, new_mu_text(p->first));
     trace(9999, "mem") << "storing file name " << get(Memory, curr) << " in location " << curr << end();
@@ -204,29 +204,29 @@ void construct_filesystem_object(const map<string, string>& contents) {
     trace(9999, "mem") << "storing refcount 1 in location " << get(Memory, curr) << end();
     ++curr;
   }
-  curr = filesystem_data_address+/*skip refcount*/1;
+  curr = resources_data_address+/*skip refcount*/1;
   put(Memory, curr, SIZE(contents));  // size of array
-  trace(9999, "mem") << "storing filesystem size " << get(Memory, curr) << " in location " << curr << end();
-  put(Memory, filesystem_data_address, 1);  // initialize refcount
-  trace(9999, "mem") << "storing refcount 1 in location " << filesystem_data_address << end();
-  // wrap the filesystem data in a filesystem object
-  int filesystem_address = allocate(size_of_filesystem());
-  curr = filesystem_address+/*skip refcount*/1;
-  put(Memory, curr, filesystem_data_address);
-  trace(9999, "mem") << "storing filesystem data address " << filesystem_data_address << " in location " << curr << end();
-  put(Memory, filesystem_address, 1);  // initialize refcount
-  trace(9999, "mem") << "storing refcount 1 in location " << filesystem_address << end();
+  trace(9999, "mem") << "storing resources size " << get(Memory, curr) << " in location " << curr << end();
+  put(Memory, resources_data_address, 1);  // initialize refcount
+  trace(9999, "mem") << "storing refcount 1 in location " << resources_data_address << end();
+  // wrap the resources data in a 'resources' object
+  int resources_address = allocate(size_of_resources());
+  curr = resources_address+/*skip refcount*/1;
+  put(Memory, curr, resources_data_address);
+  trace(9999, "mem") << "storing resources data address " << resources_data_address << " in location " << curr << end();
+  put(Memory, resources_address, 1);  // initialize refcount
+  trace(9999, "mem") << "storing refcount 1 in location " << resources_address << end();
   // save in product
-  put(Memory, FILESYSTEM, filesystem_address);
-  trace(9999, "mem") << "storing filesystem address " << filesystem_address << " in location " << FILESYSTEM << end();
+  put(Memory, RESOURCES, resources_address);
+  trace(9999, "mem") << "storing resources address " << resources_address << " in location " << RESOURCES << end();
 }
 
-int size_of_filesystem() {
+int size_of_resources() {
   // memoize result if already computed
   static int result = 0;
   if (result) return result;
-  assert(get(Type_ordinal, "filesystem"));
-  type_tree* type = new type_tree("filesystem");
+  assert(get(Type_ordinal, "resources"));
+  type_tree* type = new type_tree("resources");
   result = size_of(type)+/*refcount*/1;
   delete type;
   return result;
diff --git a/090scenario_filesystem_test.mu b/090scenario_filesystem_test.mu
index c255e69b..fe737300 100644
--- a/090scenario_filesystem_test.mu
+++ b/090scenario_filesystem_test.mu
@@ -2,12 +2,12 @@
 
 scenario read-from-fake-file [
   local-scope
-  assume-filesystem [
+  assume-resources [
     [a] <- [
       |xyz|
     ]
   ]
-  contents:&:source:char <- start-reading filesystem:&:filesystem, [a]
+  contents:&:source:char <- start-reading resources:&:resources, [a]
   1:char/raw <- read contents
   2:char/raw <- read contents
   3:char/raw <- read contents
@@ -24,14 +24,14 @@ scenario read-from-fake-file [
 
 scenario write-to-fake-file [
   local-scope
-  assume-filesystem [
+  assume-resources [
   ]
-  sink:&:sink:char, writer:num/routine <- start-writing filesystem:&:filesystem, [a]
+  sink:&:sink:char, writer:num/routine <- start-writing resources:&:resources, [a]
   sink <- write sink, 120/x
   sink <- write sink, 121/y
   close sink
   wait-for-routine writer
-  contents-read-back:text <- slurp filesystem, [a]
+  contents-read-back:text <- slurp resources, [a]
   10:bool/raw <- equal contents-read-back, [xy]
   memory-should-contain [
     10 <- 1  # file contents read back exactly match what was written
@@ -40,15 +40,15 @@ scenario write-to-fake-file [
 
 scenario write-to-fake-file-that-exists [
   local-scope
-  assume-filesystem [
+  assume-resources [
     [a] <- []
   ]
-  sink:&:sink:char, writer:num/routine <- start-writing filesystem:&:filesystem, [a]
+  sink:&:sink:char, writer:num/routine <- start-writing resources:&:resources, [a]
   sink <- write sink, 120/x
   sink <- write sink, 121/y
   close sink
   wait-for-routine writer
-  contents-read-back:text <- slurp filesystem, [a]
+  contents-read-back:text <- slurp resources, [a]
   10:bool/raw <- equal contents-read-back, [xy]
   memory-should-contain [
     10 <- 1  # file contents read back exactly match what was written
@@ -57,20 +57,20 @@ scenario write-to-fake-file-that-exists [
 
 scenario write-to-existing-file-preserves-other-files [
   local-scope
-  assume-filesystem [
+  assume-resources [
     [a] <- []
     [b] <- [
       |bcd|
     ]
   ]
-  sink:&:sink:char, writer:num/routine <- start-writing filesystem:&:filesystem, [a]
+  sink:&:sink:char, writer:num/routine <- start-writing resources:&:resources, [a]
   sink <- write sink, 120/x
   sink <- write sink, 121/y
   close sink
   wait-for-routine writer
-  contents-read-back:text <- slurp filesystem, [a]
+  contents-read-back:text <- slurp resources, [a]
   10:bool/raw <- equal contents-read-back, [xy]
-  other-file-contents:text <- slurp filesystem, [b]
+  other-file-contents:text <- slurp resources, [b]
   11:bool/raw <- equal other-file-contents, [bcd
 ]
   memory-should-contain [
@@ -79,10 +79,10 @@ scenario write-to-existing-file-preserves-other-files [
   ]
 ]
 
-def slurp fs:&:filesystem, filename:text -> contents:text [
+def slurp resources:&:resources, filename:text -> contents:text [
   local-scope
   load-ingredients
-  source:&:source:char <- start-reading fs, filename
+  source:&:source:char <- start-reading resources, filename
   buf:&:buffer <- new-buffer 30/capacity
   {
     c:char, done?:bool, source <- read source