about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--010vm.cc2
-rw-r--r--011load.cc3
-rw-r--r--040brace.cc31
-rw-r--r--043space.cc9
4 files changed, 27 insertions, 18 deletions
diff --git a/010vm.cc b/010vm.cc
index b35d39d8..fea11a50 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -33,7 +33,6 @@ struct instruction {
   bool is_label;
   string label;  // only if is_label
   string name;  // only if !is_label
-  string old_name;  // before our automatic rewrite rules
   string original_string;  // for error messages
   recipe_ordinal operation;  // get(Recipe_ordinal, name)
   vector<reagent> ingredients;  // only if !is_label
@@ -266,7 +265,6 @@ void instruction::clear() {
   is_label=false;
   label.clear();
   name.clear();
-  old_name.clear();
   operation=IDLE;
   ingredients.clear();
   products.clear();
diff --git a/011load.cc b/011load.cc
index 0a473394..926a02ad 100644
--- a/011load.cc
+++ b/011load.cc
@@ -143,7 +143,7 @@ bool next_instruction(istream& in, instruction* curr) {
     raise << "instruction prematurely ended with '<-'\n" << end();
     return false;
   }
-  curr->old_name = curr->name = *p;  ++p;
+  curr->name = *p;  ++p;
   // curr->operation will be set at transform time
 
   for (;  p != words.end();  ++p)
@@ -159,6 +159,7 @@ bool next_instruction(istream& in, instruction* curr) {
     raise << "9: unbalanced '[' for recipe\n" << end();
     return false;
   }
+  // End next_instruction(curr)
   return true;
 }
 
diff --git a/040brace.cc b/040brace.cc
index 4a6bfd10..cf9a401c 100644
--- a/040brace.cc
+++ b/040brace.cc
@@ -67,28 +67,29 @@ void transform_braces(const recipe_ordinal r) {
       continue;
     }
     if (inst.is_label) continue;
-    if (inst.old_name != "loop"
-         && inst.old_name != "loop-if"
-         && inst.old_name != "loop-unless"
-         && inst.old_name != "break"
-         && inst.old_name != "break-if"
-         && inst.old_name != "break-unless") {
-      trace(9992, "transform") << inst.old_name << " ..." << end();
+    if (inst.name != "loop"
+         && inst.name != "loop-if"
+         && inst.name != "loop-unless"
+         && inst.name != "break"
+         && inst.name != "break-if"
+         && inst.name != "break-unless") {
+      trace(9992, "transform") << inst.name << " ..." << end();
       continue;
     }
     // check for errors
-    if (inst.old_name.find("-if") != string::npos || inst.old_name.find("-unless") != string::npos) {
+    if (inst.name.find("-if") != string::npos || inst.name.find("-unless") != string::npos) {
       if (inst.ingredients.empty()) {
-        raise << "'" << inst.old_name << "' expects 1 or 2 ingredients, but got none\n" << end();
+        raise << "'" << inst.name << "' expects 1 or 2 ingredients, but got none\n" << end();
         continue;
       }
     }
     // update instruction operation
-    if (inst.old_name.find("-if") != string::npos) {
+    string old_name = inst.name;  // save a copy
+    if (inst.name.find("-if") != string::npos) {
       inst.name = "jump-if";
       inst.operation = JUMP_IF;
     }
-    else if (inst.old_name.find("-unless") != string::npos) {
+    else if (inst.name.find("-unless") != string::npos) {
       inst.name = "jump-unless";
       inst.operation = JUMP_UNLESS;
     }
@@ -97,7 +98,7 @@ void transform_braces(const recipe_ordinal r) {
       inst.operation = JUMP;
     }
     // check for explicitly provided targets
-    if (inst.old_name.find("-if") != string::npos || inst.old_name.find("-unless") != string::npos) {
+    if (inst.name.find("-if") != string::npos || inst.name.find("-unless") != string::npos) {
       // conditional branches check arg 1
       if (SIZE(inst.ingredients) > 1 && is_literal(inst.ingredients.at(1))) {
         trace(9992, "transform") << inst.name << ' ' << inst.ingredients.at(1).name << ":offset" << end();
@@ -116,8 +117,8 @@ void transform_braces(const recipe_ordinal r) {
     target.type = new type_tree("offset");
     target.set_value(0);
     if (open_braces.empty())
-      raise << "'" << inst.old_name << "' needs a '{' before\n" << end();
-    else if (inst.old_name.find("loop") != string::npos)
+      raise << "'" << old_name << "' needs a '{' before\n" << end();
+    else if (old_name.find("loop") != string::npos)
       target.set_value(open_braces.top()-index);
     else  // break instruction
       target.set_value(matching_brace(open_braces.top(), braces, r) - index - 1);
@@ -430,7 +431,7 @@ void emit_return_block(recipe& out, const string& break_command, const instructi
   // <break command> <condition>
   instruction break_inst;
   break_inst.operation = get(Recipe_ordinal, break_command);
-  break_inst.name = break_inst.old_name = break_command;
+  break_inst.name = break_command;
   break_inst.ingredients.push_back(condition);
   out.steps.push_back(break_inst);
 
diff --git a/043space.cc b/043space.cc
index 5b3c6084..33c4bb09 100644
--- a/043space.cc
+++ b/043space.cc
@@ -258,6 +258,15 @@ void try_reclaim_locals() {
           /*refcount*/1 + /*array length*/1 + /*number-of-locals*/Name[r][""]);
 }
 
+//: Reclaiming local variables above requires remembering what name an
+//: instruction had before any rewrites or transforms.
+:(before "End instruction Fields")
+string old_name;
+:(before "End instruction Clear")
+old_name.clear();
+:(before "End next_instruction(curr)")
+curr->old_name = curr->name;  // before rewrite rules modify it
+
 :(code)
 // is this reagent one of the values returned by the current (return) instruction?
 // is the corresponding ingredient saved in the caller?