about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-20 20:27:01 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-20 20:27:01 -0700
commitfc55fea025bdb1c6945e6812d49a6d41e8f3c062 (patch)
tree26c1c5e55c5bb3233e77aa77a28b9d216a9f94be /cpp
parentad07fc7faf440b025f7d883664aebf281ea85852 (diff)
downloadmu-fc55fea025bdb1c6945e6812d49a6d41e8f3c062.tar.gz
959
Diffstat (limited to 'cpp')
-rw-r--r--cpp/.traces/convert_names_passes_dummy9
-rw-r--r--cpp/.traces/run_dummy7
-rw-r--r--cpp/010vm1
-rw-r--r--cpp/013run10
-rw-r--r--cpp/019address1
-rw-r--r--cpp/025name22
6 files changed, 46 insertions, 4 deletions
diff --git a/cpp/.traces/convert_names_passes_dummy b/cpp/.traces/convert_names_passes_dummy
new file mode 100644
index 00000000..08f69ed6
--- /dev/null
+++ b/cpp/.traces/convert_names_passes_dummy
@@ -0,0 +1,9 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]}
+parse/0:   product: {name: "_", value: 0, type: , properties: [_: ]}
+parse/0:   product: {name: "x", value: 0, type: 1, properties: [x: integer]}
+name/0: assign x 1
+after-brace/0: recipe main
+after-brace/0: copy ...
+run/0: instruction main/0
+run/0: ingredient 0 is 0
diff --git a/cpp/.traces/run_dummy b/cpp/.traces/run_dummy
new file mode 100644
index 00000000..b6aa736f
--- /dev/null
+++ b/cpp/.traces/run_dummy
@@ -0,0 +1,7 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]}
+parse/0:   product: {name: "_", value: 0, type: , properties: [_: ]}
+after-brace/0: recipe main
+after-brace/0: copy ...
+run/0: instruction main/0
+run/0: ingredient 0 is 0
diff --git a/cpp/010vm b/cpp/010vm
index d8394fdb..45b4c3e5 100644
--- a/cpp/010vm
+++ b/cpp/010vm
@@ -104,6 +104,7 @@ struct type_info {
   bool is_array;
   vector<vector<type_number> > elements;  // only if is_record
   vector<type_number> element;  // only if is_array
+  // End type_info Fields.
   type_info() :size(0), is_record(false), is_array(false) {}
 };
 
diff --git a/cpp/013run b/cpp/013run
index 102a7dfb..b26ce56f 100644
--- a/cpp/013run
+++ b/cpp/013run
@@ -111,6 +111,7 @@ for (size_t i = 0; i < recipes_added_by_test.size(); ++i) {
 recipes_added_by_test.clear();
 
 :(code)
+//: beware: overridden in later layers
 vector<int> read_memory(reagent x) {
 //?   cout << "read_memory: " << x.to_string() << '\n'; //? 1
   vector<int> result;
@@ -127,7 +128,9 @@ vector<int> read_memory(reagent x) {
   return result;
 }
 
+//: beware: overridden in later layers
 void write_memory(reagent x, vector<int> data) {
+  if (x.name == "_") return;  // dummy results are never stored
   int base = x.value;
   size_t size = size_of(x);
   if (size != data.size()) raise << "size mismatch in storing to " << x.to_string();
@@ -153,3 +156,10 @@ recipe main [
 ]
 +run: instruction main/1
 +run: instruction main/2
+-run: instruction main/0
+
+:(scenario run_dummy)
+recipe main [
+  _ <- copy 0:literal
+]
++run: instruction main/0
diff --git a/cpp/019address b/cpp/019address
index 608e5e69..540f18e6 100644
--- a/cpp/019address
+++ b/cpp/019address
@@ -43,6 +43,7 @@ recipe main [
 
 :(replace{} "void write_memory(reagent x, vector<int> data)")
 void write_memory(reagent x, vector<int> data) {
+  if (x.name == "_") return;  // dummy results are never stored
   x = canonize(x);
   int base = x.value;
   if (!Type[x.types[0]].is_array && size_of(x) != data.size())
diff --git a/cpp/025name b/cpp/025name
index 73406a81..24822afb 100644
--- a/cpp/025name
+++ b/cpp/025name
@@ -1,5 +1,5 @@
 //: A big convenience high-level languages provide is the ability to name memory
-//: locations. In mu, a lightweight tool called 'convert-names' provides this
+//: locations. In mu, a transform called 'convert-names' provides this
 //: convenience.
 
 :(scenarios run)
@@ -16,6 +16,8 @@ Transform.push_back(transform_names);
 
 :(before "End Globals")
 unordered_map<recipe_number, unordered_map<string, int> > Name;
+:(before "End Setup")
+Name.clear();
 
 :(code)
 void transform_names(const recipe_number r) {
@@ -26,9 +28,11 @@ void transform_names(const recipe_number r) {
   for (size_t i = 0; i < Recipe[r].steps.size(); ++i) {
 //?     cout << "instruction " << i << '\n'; //? 2
     instruction& inst = Recipe[r].steps[i];
+    // map names to addresses
     for (size_t in = 0; in < inst.ingredients.size(); ++in) {
 //?       cout << "ingredient " << inst.ingredients[in].name << '\n'; //? 1
-      if (inst.ingredients[in].types[0]
+      if (!inst.ingredients[in].types.empty()
+          && inst.ingredients[in].types[0]
           && inst.ingredients[in].name.find_first_not_of("0123456789-.") != string::npos) {
         if (names.find(inst.ingredients[in].name) == names.end()) {
           // todo: test
@@ -38,10 +42,12 @@ void transform_names(const recipe_number r) {
         inst.ingredients[in].initialized = true;
       }
     }
+    // replace names with addresses
     for (size_t out = 0; out < inst.products.size(); ++out) {
-//?       cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 2
+//?       cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 3
 //?       cout << inst.products[out].types[0] << '\n'; //? 1
-      if (inst.products[out].types[0]
+      if (!inst.products[out].types.empty()
+          && inst.products[out].types[0]
           && inst.products[out].name.find_first_not_of("0123456789-.") != string::npos) {
         if (names.find(inst.products[out].name) == names.end()) {
           trace("name") << "assign " << inst.products[out].name << " " << curr_idx;
@@ -54,3 +60,11 @@ void transform_names(const recipe_number r) {
     }
   }
 }
+
+:(scenario "convert_names_passes_dummy")
+# _ is just a dummy result that never gets consumed
+recipe main [
+  _, x:integer <- copy 0:literal
+]
++name: assign x 1
+-name: assign _ 1