about summary refs log tree commit diff stats
path: root/cpp/025name
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/025name
parentad07fc7faf440b025f7d883664aebf281ea85852 (diff)
downloadmu-fc55fea025bdb1c6945e6812d49a6d41e8f3c062.tar.gz
959
Diffstat (limited to 'cpp/025name')
-rw-r--r--cpp/025name22
1 files changed, 18 insertions, 4 deletions
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