[avida-cvs] avida(kaben) CVS commits: /current/source defs.hh /current/source/cpu hardware_4stack.cc hardware_cpu.cc hardware_util.cc /current/source/main analyze.cc avida.cc inst_set.cc inst_set.hh /current/source/qt-viewer setup_avida.cc

kaben avida-cvs at alife.org
Fri May 23 10:36:35 PDT 2003


kaben		Fri May 23 02:36:35 2003 EDT

  Modified files:              (Branch: kaben)
    /avida/current/source	defs.hh 
    /avida/current/source/cpu	hardware_4stack.cc hardware_cpu.cc 
                             	hardware_util.cc 
    /avida/current/source/main	analyze.cc avida.cc inst_set.cc 
                              	inst_set.hh 
    /avida/current/source/qt-viewer	setup_avida.cc 
  Log:
  
  defs.hh contains "#define USE_INST_SET_CODE" to use new inst_set code.
  If the macro is commented-out, Avida uses the old inst_set code;
  so we can try to verify transparency of the changes by comparing
  identically configured Avida runs under the new and the old code.
  
  
  
-------------- next part --------------
Index: avida/current/source/defs.hh
diff -u avida/current/source/defs.hh:1.25.2.2 avida/current/source/defs.hh:1.25.2.3
--- avida/current/source/defs.hh:1.25.2.2	Tue May 20 05:12:19 2003
+++ avida/current/source/defs.hh	Fri May 23 02:36:34 2003
@@ -18,6 +18,8 @@
 #define HTMLDIR "../work/doc_html/"
 #endif
 
+//#define USE_INST_SET_CODE
+
 // -= Various view modes =-
 #define VIEW_NEWVIEWER
 // #define VIEW_VISTA
Index: avida/current/source/cpu/hardware_4stack.cc
diff -u avida/current/source/cpu/hardware_4stack.cc:1.2.2.2 avida/current/source/cpu/hardware_4stack.cc:1.2.2.3
--- avida/current/source/cpu/hardware_4stack.cc:1.2.2.2	Thu May 22 01:15:01 2003
+++ avida/current/source/cpu/hardware_4stack.cc	Fri May 23 02:36:34 2003
@@ -145,12 +145,18 @@
 
   char marker; fp>>marker; assert( marker == '|' );
   /* YIKES!  data loss below: */
+#ifdef USE_INST_SET_CODE
   char the_cur_stack = cur_stack;
   char the_cur_head = cur_head;
   char the_input_pointer = input_pointer;
   fp.get(the_cur_stack);
   fp.get(the_cur_head);
   fp.get(the_input_pointer);
+#else /* USE_INST_SET_CODE */
+  fp.get((char)cur_stack);
+  fp.get((char)cur_head);
+  fp.get((char)input_pointer);
+#endif /* USE_INST_SET_CODE */
 
   // IO buffers
   input_buf.LoadState(fp);
@@ -162,6 +168,7 @@
 }
 
 
+#ifdef USE_INST_SET_CODE
 ///////////////
 //  cInstLib4Stack
 ///////////////
@@ -217,12 +224,13 @@
   const cInstruction & GetInstDefault(){ return inst_default; }
   const cInstruction & GetInstError(){ return inst_error; }
 };
-
+#endif /* USE_INST_SET_CODE */
 
 ///////////////
 //  cHardware4Stack
 ///////////////
 
+#ifdef USE_INST_SET_CODE
 const cInstruction cInstLib4Stack::inst_error(255);
 const cInstruction cInstLib4Stack::inst_default(0);
 cInstLibBase *cHardware4Stack::GetInstLib(){ return s_inst_slib; }
@@ -246,9 +254,17 @@
     tHardware4StackMethod function;
   };
   static const cInstEntry4Stack s_f_array[] = {
+    /*
+    Note: all entries of cNOPEntryCPU s_n_array must have corresponding
+    in the same order in cInstEntryCPU s_f_array, and these entries must
+    be the first elements of s_f_array.
+    */
     cInstEntry4Stack("nop-A",     &cHardware4Stack::Inst_Nop),
     cInstEntry4Stack("nop-B",     &cHardware4Stack::Inst_Nop),
     cInstEntry4Stack("nop-C",     &cHardware4Stack::Inst_Nop),
+
+    // Added "map-null" for use in analyze mode. -- kgn
+    cInstEntry4Stack("map-null",  &cHardware4Stack::Inst_Nop),
     cInstEntry4Stack("nop-X",     &cHardware4Stack::Inst_Nop),
     cInstEntry4Stack("if-equ-0",  &cHardware4Stack::Inst_If0),
     cInstEntry4Stack("if-not-0",  &cHardware4Stack::Inst_IfNot0),
@@ -365,7 +381,7 @@
   );
 
   cout <<
-  "<cHardware4Stack::initInstLib> test of ick" <<endl<<
+  "<cHardware4Stack::initInstLib> debug: important post-init values:" <<endl<<
   " --- GetSize(): " << inst_lib->GetSize() <<endl<<
   " --- GetNumNops(): " << inst_lib->GetNumNops() <<endl<<
   " --- GetName(last): " <<
@@ -374,13 +390,16 @@
 
   return inst_lib;
 }
+#endif /* USE_INST_SET_CODE */
 
 cHardware4Stack::cHardware4Stack(cOrganism * in_organism, cInstSet * in_inst_set)
   : cHardwareBase(in_organism, in_inst_set)
 {
+#ifdef USE_INST_SET_CODE
   /* FIXME:  reorganize storage of m_functions.  -- kgn */
   m_functions = s_inst_slib->GetFunctions();
   /**/
+#endif /* USE_INST_SET_CODE */
   memory = in_organism->GetGenome();  // Initialize memory...
   Reset();                            // Setup the rest of the hardware...
 }
@@ -520,10 +539,13 @@
 bool cHardware4Stack::SingleProcess_ExecuteInst(const cInstruction & cur_inst) 
 {
   // Get a pointer to the corrisponding method...
+#ifdef USE_INST_SET_CODE
   /* XXX start -- kgn */
-  //tHardwareMethod inst_ptr = GetInstSet().GetFunction(cur_inst);
   int inst_idx = GetInstSet().GetLibFunctionIndex(cur_inst);
   /* XXX end */
+#else /* USE_INST_SET_CODE */
+  tHardwareMethod inst_ptr = GetInstSet().GetFunction(cur_inst);
+#endif /* USE_INST_SET_CODE */
       
   // Mark the instruction as executed
   IP().FlagExecuted() = true;
@@ -539,12 +561,15 @@
 #endif
 	
   // And execute it.
+#ifdef USE_INST_SET_CODE
   /* XXX start -- kgn */
-  //const bool exec_success = (this->*inst_ptr)();
   const bool exec_success
   //= (this->*(s_inst_slib->GetFunctions()[inst_idx]))();
   = (this->*(m_functions[inst_idx]))();
   /* XXX end */
+#else /* USE_INST_SET_CODE */
+  const bool exec_success = (this->*inst_ptr)();
+#endif /* USE_INST_SET_CODE */
 	
 #ifdef INSTRUCTION_COUNT
   // decremenet if the instruction was not executed successfully
Index: avida/current/source/cpu/hardware_cpu.cc
diff -u avida/current/source/cpu/hardware_cpu.cc:1.34.2.3 avida/current/source/cpu/hardware_cpu.cc:1.34.2.4
--- avida/current/source/cpu/hardware_cpu.cc:1.34.2.3	Tue May 20 05:12:19 2003
+++ avida/current/source/cpu/hardware_cpu.cc	Fri May 23 02:36:34 2003
@@ -13,9 +13,10 @@
 #include "../tools/string_util.hh"
 
 #include "../main/config.hh"
-#include "../main/inst_set.hh"
+#ifdef USE_INST_SET_CODE
+  #include "../main/inst_set.hh"
+#endif /* USE_INST_SET_CODE */
 #include "../main/inst_lib.hh"
-#include "../main/inst_superlib.hh"
 #include "../main/genome_util.hh"
 #include "../main/organism.hh"
 #include "../main/phenotype.hh"
@@ -23,8 +24,6 @@
 #include "test_cpu.hh"
 #include <limits.h>
 
-using namespace std;
-
 
 using namespace std;
 
@@ -148,6 +147,7 @@
   stack.LoadState(fp);
 
   char marker; fp>>marker; assert( marker == '|' );
+#ifdef USE_INST_SET_CODE
   /* YIKES!  data loss below: */
   char the_cur_stack = cur_stack;
   char the_cur_head = cur_head;
@@ -155,6 +155,11 @@
   fp.get(the_cur_stack);
   fp.get(the_cur_head);
   fp.get(the_input_pointer);
+#else /* USE_INST_SET_CODE */
+  fp.get((char)cur_stack);
+  fp.get((char)cur_head);
+  fp.get((char)input_pointer);
+#endif /* USE_INST_SET_CODE */
 
   // IO buffers
   input_buf.LoadState(fp);
@@ -166,6 +171,7 @@
 }
 
 
+#ifdef USE_INST_SET_CODE
 ///////////////
 //  cInstLibCPU
 ///////////////
@@ -221,12 +227,13 @@
   const cInstruction & GetInstDefault(){ return inst_default; }
   const cInstruction & GetInstError(){ return inst_error; }
 };
-
+#endif /* USE_INST_SET_CODE */
 
 ///////////////
 //  cHardwareCPU
 ///////////////
 
+#ifdef USE_INST_SET_CODE
 const cInstruction cInstLibCPU::inst_error(255);
 const cInstruction cInstLibCPU::inst_default(0);
 cInstLibBase *cHardwareCPU::GetInstLib(){ return s_inst_slib; }
@@ -250,9 +257,17 @@
     tHardwareCPUMethod function;
   };
   static const cInstEntryCPU s_f_array[] = {
+    /*
+    Note: all entries of cNOPEntryCPU s_n_array must have corresponding
+    in the same order in cInstEntryCPU s_f_array, and these entries must
+    be the first elements of s_f_array.
+    */
     cInstEntryCPU("nop-A",     &cHardwareCPU::Inst_Nop),
     cInstEntryCPU("nop-B",     &cHardwareCPU::Inst_Nop),
     cInstEntryCPU("nop-C",     &cHardwareCPU::Inst_Nop),
+
+    // Added "map-null" for use in analyze mode. -- kgn
+    cInstEntryCPU("map-null",     &cHardwareCPU::Inst_Nop),
     cInstEntryCPU("nop-X",     &cHardwareCPU::Inst_Nop),
     cInstEntryCPU("if-equ-0",  &cHardwareCPU::Inst_If0),
     cInstEntryCPU("if-not-0",  &cHardwareCPU::Inst_IfNot0),
@@ -447,6 +462,11 @@
   };
 
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
+
+  cout << "<cHardwareCPU::initInstLib> Instruction Library has "
+  << n_size << " instructions." << endl;
+
+
   static cString n_names[n_size];
   static int nop_mods[n_size];
   for (int i = 0; i < n_size; i++){
@@ -472,7 +492,7 @@
   );
 
   cout <<
-  "<cHardwareCPU::initInstLib> test of ick" <<endl<<
+  "<cHardwareCPU::initInstLib> debug: important post-init values:" <<endl<<
   " --- GetSize(): " << inst_lib->GetSize() <<endl<<
   " --- GetNumNops(): " << inst_lib->GetNumNops() <<endl<<
   " --- GetName(last): " <<
@@ -481,13 +501,16 @@
 
   return inst_lib;
 }
+#endif /* USE_INST_SET_CODE */
 
 cHardwareCPU::cHardwareCPU(cOrganism * in_organism, cInstSet * in_inst_set)
   : cHardwareBase(in_organism, in_inst_set)
 {
+#ifdef USE_INST_SET_CODE
   /* FIXME:  reorganize storage of m_functions.  -- kgn */
   m_functions = s_inst_slib->GetFunctions();
   /**/
+#endif /* USE_INST_SET_CODE */
   memory = in_organism->GetGenome();  // Initialize memory...
   Reset();                            // Setup the rest of the hardware...
 }
@@ -627,10 +650,13 @@
 bool cHardwareCPU::SingleProcess_ExecuteInst(const cInstruction & cur_inst) 
 {
   // Get a pointer to the corrisponding method...
+#ifdef USE_INST_SET_CODE
   /* XXX start -- kgn */
-  //tHardwareMethod inst_ptr = GetInstSet().GetFunction(cur_inst);
   int inst_idx = GetInstSet().GetLibFunctionIndex(cur_inst);
   /* XXX end */
+#else /* USE_INST_SET_CODE */
+  tHardwareMethod inst_ptr = GetInstSet().GetFunction(cur_inst);
+#endif /* USE_INST_SET_CODE */
       
   // Mark the instruction as executed
   IP().FlagExecuted() = true;
@@ -646,12 +672,15 @@
 #endif
 	
   // And execute it.
+#ifdef USE_INST_SET_CODE
   /* XXX start -- kgn */
-  //const bool exec_success = (this->*inst_ptr)();
   const bool exec_success
   //= (this->*(s_inst_slib->GetFunctions()[inst_idx]))();
   = (this->*(m_functions[inst_idx]))();
   /* XXX end */
+#else /* USE_INST_SET_CODE */
+  const bool exec_success = (this->*inst_ptr)();
+#endif /* USE_INST_SET_CODE */
 	
 #ifdef INSTRUCTION_COUNT
   // decremenet if the instruction was not executed successfully
@@ -980,8 +1009,7 @@
 // direction which the heads[HEAD_IP] should progress through a creature.
 cCPUHead cHardwareCPU::FindFullLabel(const cCodeLabel & in_label)
 {
-  // cout << "Running FindFullLabel with " << in_label.AsString() <<
-  // endl;
+  // cout << "Running FindFullLabel with " << in_label.AsString() << endl;
 
   assert(in_label.GetSize() > 0); // Trying to find label of 0 size!
 
@@ -1011,8 +1039,7 @@
       continue;
     }
 
-    // cout << "Testing label at line " << temp_head.GetPosition() <<
-    // endl;
+    // cout << "Testing label at line " << temp_head.GetPosition() << endl;
 
     // ...and do the comparison...
 
Index: avida/current/source/cpu/hardware_util.cc
diff -u avida/current/source/cpu/hardware_util.cc:1.12.2.4 avida/current/source/cpu/hardware_util.cc:1.12.2.5
--- avida/current/source/cpu/hardware_util.cc:1.12.2.4	Thu May 22 01:15:01 2003
+++ avida/current/source/cpu/hardware_util.cc	Fri May 23 02:36:34 2003
@@ -52,39 +52,39 @@
     
     // Otherwise, this instruction will be in the set.
     // First, determine if it is a nop...
-    int nop_mod = -1;
+#ifdef USE_INST_SET_CODE
     /* XXX start -- kgn */
     int nop_mod_2 = -1;
+    if(nop_dict_2.Find(inst_name, nop_mod_2) == true) {
+      inst_set.AddNop2(nop_mod_2, redundancy, ft_cost, cost, prob_fail);
+      continue;
+    }
     /* XXX end */
+#else /* USE_INST_SET_CODE */
+    int nop_mod = -1;
     if (nop_dict.Find(inst_name, nop_mod) == true) {
       inst_set.AddNop(inst_name, &cHardwareBase::Inst_Nop, nop_mod,
 		 redundancy, ft_cost, cost, prob_fail);
-      /* XXX start -- kgn */
-      if(nop_dict_2.Find(inst_name, nop_mod_2) == true) {
-        inst_set.AddNop2(nop_mod_2, redundancy, ft_cost, cost, prob_fail);
-      } else { /* dicts mismatch! die horribly. */
-	cerr << "Warning: instruction set mismatch!" << endl;
-      }
-      /* XXX end */
       continue;
     }
+#endif /* USE_INST_SET_CODE */
 
     // Otherwise, it had better be in the main dictionary...
-    tHardwareMethod cpu_method = NULL;
+#ifdef USE_INST_SET_CODE
     /* XXX start -- kgn */
     int fun_id = -1;
+    if(inst_dict_2.Find(inst_name, fun_id) == true){
+      inst_set.Add2(fun_id, redundancy, ft_cost, cost, prob_fail);
+      continue;
+    }
     /* XXX end */
+#else /* USE_INST_SET_CODE */
+    tHardwareMethod cpu_method = NULL;
     if (inst_dict.Find(inst_name, cpu_method) == true) {
       inst_set.Add(inst_name, cpu_method, redundancy, ft_cost, cost, prob_fail);
-      /* XXX start -- kgn */
-      if(inst_dict_2.Find(inst_name, fun_id) == true){
-        inst_set.Add2(fun_id, redundancy, ft_cost, cost, prob_fail);
-      } else { /* dicts mismatch! die horribly. */
-	cerr << "Warning: instruction set mismatch!" << endl;
-      }
-      /* XXX end */
       continue;
     }
+#endif /* USE_INST_SET_CODE */
 
     // Oh oh!  Didn't find an instruction!
     cerr << endl
@@ -103,13 +103,16 @@
   // Nops (or other modifying-instructions...)  Note: Nops must be the
   //  first instructions added to the set.
   tDictionary< int > nop_dict;
+#ifndef USE_INST_SET_CODE
   nop_dict.Add("nop-A", REG_AX);
   nop_dict.Add("nop-B", REG_BX);
   nop_dict.Add("nop-C", REG_CX);
+#endif /* !USE_INST_SET_CODE */
 
   // Build a dictionary of instructions and their corresponding methods...
   tDictionary< tHardwareMethod > inst_dict;
 
+#ifndef USE_INST_SET_CODE
   // Remaining instructions.
   inst_dict.Add("nop-X",    (tHardwareMethod) &cHardwareCPU::Inst_Nop);
   inst_dict.Add("if-equ-0", (tHardwareMethod) &cHardwareCPU::Inst_If0);
@@ -310,15 +313,20 @@
   // Placebo instructions
   // nop-x (included with nops)
   inst_dict.Add("skip", (tHardwareMethod) &cHardwareCPU::Inst_Skip);
+#endif /* !USE_INST_SET_CODE */
   
   /* XXX start -- kgn */
   tDictionary<int> nop_dict_2;
+#ifdef USE_INST_SET_CODE
   for(int i=0; i<inst_set.GetInstLib()->GetNumNops(); i++)
     nop_dict_2.Add(inst_set.GetInstLib()->GetNopName(i), i);
+#endif /* USE_INST_SET_CODE */
 
   tDictionary<int> inst_dict_2;
+#ifdef USE_INST_SET_CODE
   for(int i=0; i<inst_set.GetInstLib()->GetSize(); i++)
     inst_dict_2.Add(inst_set.GetInstLib()->GetName(i), i);
+#endif /* USE_INST_SET_CODE */
   /* XXX end */
 
   // And load it on up!
@@ -330,13 +338,16 @@
   // Nops (or other modifying-instructions...)  Note: Nops must be the
   //  first instructions added to the set.
   tDictionary< int > nop_dict;
+#ifndef USE_INST_SET_CODE
   nop_dict.Add("nop-A", REG_AX);
   nop_dict.Add("nop-B", REG_BX);
   nop_dict.Add("nop-C", REG_CX);
+#endif /* !USE_INST_SET_CODE */
 
   // Build a dictionary of instructions and their corresponding methods...
   tDictionary< tHardwareMethod > inst_dict;
 
+#ifndef USE_INST_SET_CODE
   // Remaining instructions.
   inst_dict.Add("nop-X",    (tHardwareMethod) &cHardware4Stack::Inst_Nop);
   inst_dict.Add("if-equ-0", (tHardwareMethod) &cHardware4Stack::Inst_If0);
@@ -537,18 +548,23 @@
   // Placebo instructions
   // nop-x (included with nops)
   inst_dict.Add("skip", (tHardwareMethod) &cHardware4Stack::Inst_Skip);
+#endif /* !USE_INST_SET_CODE */
   
   cout << "Instruction Library in util has " << inst_dict.GetSize()
        << " instructions." << endl;
 
   /* XXX start -- kgn */
   tDictionary<int> nop_dict_2;
+#ifdef USE_INST_SET_CODE
   for(int i=0; i<inst_set.GetInstLib()->GetNumNops(); i++)
     nop_dict_2.Add(inst_set.GetInstLib()->GetNopName(i), i);
+#endif /* USE_INST_SET_CODE */
 
   tDictionary<int> inst_dict_2;
+#ifdef USE_INST_SET_CODE
   for(int i=0; i<inst_set.GetInstLib()->GetSize(); i++)
     inst_dict_2.Add(inst_set.GetInstLib()->GetName(i), i);
+#endif /* USE_INST_SET_CODE */
   /* XXX end */
 
   // And load it on up!
@@ -563,11 +579,15 @@
   // set it up.
   if (inst_filename != "" && inst_set.GetSize() == 0) {
     if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_ORIGINAL) {
+#ifdef USE_INST_SET_CODE
       inst_set.SetInstLib(cHardwareCPU::GetInstLib());
+#endif /* USE_INST_SET_CODE */
       LoadInstSet_CPUOriginal(inst_filename, inst_set);
     }
     else if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_4STACK) {
+#ifdef USE_INST_SET_CODE
       inst_set.SetInstLib(cHardware4Stack::GetInstLib());
+#endif /* USE_INST_SET_CODE */
       LoadInstSet_CPU4Stack(inst_filename, inst_set);
     }
   }
Index: avida/current/source/main/analyze.cc
diff -u avida/current/source/main/analyze.cc:1.63.2.4 avida/current/source/main/analyze.cc:1.63.2.5
--- avida/current/source/main/analyze.cc:1.63.2.4	Tue May 20 05:12:21 2003
+++ avida/current/source/main/analyze.cc	Fri May 23 02:36:34 2003
@@ -1805,10 +1805,31 @@
       col_fail_count[i] = 0;
     }
 
-    // Build an empty instruction into the an instruction library.
     cInstSet map_inst_set(inst_set);
+#ifdef USE_INST_SET_CODE
+    /* XXX start -- kgn */
+    // Locate instruction corresponding to "map-null" in the instruction library.
+    {
+      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("map-null");
+      if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
+        cout << "<cAnalyze::CommandMapTasks> got error:" << endl;
+        cout << " --- instruction \"map-null\" isn't in the instruction library;" << endl;
+        cout << " --- get somebody to map a function to \"map-null\" in the library." << endl;
+        cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
+        cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
+        cout << " --- bailing-out." << endl;
+        exit(1);
+      }
+      // Add mapping to located instruction. 
+      map_inst_set.Add2(inst_lib_null_inst.GetOp());
+    }
+    const cInstruction null_inst = map_inst_set.GetInst("map-null");
+    /* XXX end */
+#else /* USE_INST_SET_CODE */
+    // Build an empty instruction into the instruction set.
     map_inst_set.Add("map-null", &cHardwareBase::Inst_Nop);
     const cInstruction null_inst = map_inst_set.GetInst("map-null");
+#endif /* USE_INST_SET_CODE */
 
     // Loop through all the lines of code, testing the removal of each.
     for (int line_num = 0; line_num < max_line; line_num++) {
@@ -1995,8 +2016,30 @@
 
     // Build an empty instruction into the an instruction library.
     cInstSet map_inst_set(inst_set);
+#ifdef USE_INST_SET_CODE
+    /* XXX start -- kgn */
+    // Locate instruction corresponding to "map-null" in the instruction library.
+    {
+      const cInstruction inst_lib_null_inst = map_inst_set.GetInstLib()->GetInst("map-null");
+      if(inst_lib_null_inst == map_inst_set.GetInstLib()->GetInstError()){
+        cout << "<cAnalyze::CommandMapMutations> got error:" << endl;
+        cout << " --- instruction \"map-null\" isn't in the instruction library;" << endl;
+        cout << " --- get somebody to map a function to \"map-null\" in the library." << endl;
+        cout << " --- (probably to class method \"cHardware-of-some-type::initInstLib\"" << endl;
+        cout << " --- in file named \"cpu/hardware-of-some-type.cc\".)" << endl;
+        cout << " --- bailing-out." << endl;
+        exit(1);
+      }
+      // Add mapping to located instruction. 
+      map_inst_set.Add2(inst_lib_null_inst.GetOp());
+    }
+    const cInstruction null_inst = map_inst_set.GetInst("map-null");
+    /* XXX end */
+#else /* USE_INST_SET_CODE */
+    // Build an empty instruction into the instruction set.
     map_inst_set.Add("map-null", &cHardwareBase::Inst_Nop);
     const cInstruction null_inst = map_inst_set.GetInst("map-null");
+#endif /* USE_INST_SET_CODE */
 
     cString color_string;  // For coloring cells...
 
Index: avida/current/source/main/avida.cc
diff -u avida/current/source/main/avida.cc:1.34.2.3 avida/current/source/main/avida.cc:1.34.2.4
--- avida/current/source/main/avida.cc:1.34.2.3	Tue May 20 05:12:21 2003
+++ avida/current/source/main/avida.cc	Fri May 23 02:36:35 2003
@@ -81,12 +81,16 @@
   }
   
   if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_ORIGINAL) {
+#ifdef USE_INST_SET_CODE
     environment.GetInstSet().SetInstLib(cHardwareCPU::GetInstLib());
+#endif /* USE_INST_SET_CODE */
     cHardwareUtil::LoadInstSet_CPUOriginal(cConfig::GetInstFilename(),
 					   environment.GetInstSet());
   }
   else if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_4STACK) {
+#ifdef USE_INST_SET_CODE
     environment.GetInstSet().SetInstLib(cHardware4Stack::GetInstLib());
+#endif /* USE_INST_SET_CODE */
     cHardwareUtil::LoadInstSet_CPU4Stack(cConfig::GetInstFilename(),
 					   environment.GetInstSet());
   }
Index: avida/current/source/main/inst_set.cc
diff -u avida/current/source/main/inst_set.cc:1.1.2.1 avida/current/source/main/inst_set.cc:1.1.2.2
--- avida/current/source/main/inst_set.cc:1.1.2.1	Tue May 20 05:12:22 2003
+++ avida/current/source/main/inst_set.cc	Fri May 23 02:36:35 2003
@@ -19,11 +19,14 @@
 
 // Initialize static variables
 /* XXX start -- kgn */
+#ifdef USE_INST_SET_CODE
 cInstruction cInstSet::inst_default2(   0 );
 cInstruction cInstSet::inst_error2  ( 255 );
+#else /* USE_INST_SET_CODE */
 /* XXX end */
 const cInstruction cInstSet::inst_default(   0 );
 const cInstruction cInstSet::inst_error  ( 255 );
+#endif /* USE_INST_SET_CODE */
 
 cInstSet::cInstSet()
 {
@@ -43,36 +46,23 @@
 cInstSet & cInstSet::operator=(const cInstSet & _in)
 {
   /* XXX start -- kgn */
+#ifdef USE_INST_SET_CODE
   m_inst_lib = _in.m_inst_lib;
   m_lib_name_map = _in.m_lib_name_map;
   m_lib_nopmod_map = _in.m_lib_nopmod_map;
   mutation_chart2 = _in.mutation_chart2;
+#else /* USE_INST_SET_CODE */
   /* XXX end */
   inst_array = _in.inst_array;
   nop_mods = _in.nop_mods;
   mutation_chart = _in.mutation_chart;
+#endif /* USE_INST_SET_CODE */
   return *this;
 }
 
 bool cInstSet::OK() const
 {
-  //// assert(inst_array.OK());
-  //// assert(nop_mods.OK());
-  //assert(inst_array.GetSize() < 256);
-  //assert(nop_mods.GetSize() < inst_array.GetSize());
-
-  //// Make sure that all of the redundancies are represented the appropriate
-  //// number of times.
-  //tArray<int> test_redundancy(inst_array.GetSize());
-  //test_redundancy.SetAll(0);
-  //for (int i = 0; i < mutation_chart.GetSize(); i++) {
-  //  int test_id = mutation_chart[i];
-  //  test_redundancy[test_id]++;
-  //}
-  //for (int i = 0; i < inst_array.GetSize(); i++) {
-  //  assert(inst_array[i].redundancy == test_redundancy[i]);
-  //}
-
+#ifdef USE_INST_SET_CODE
   /* XXX start -- kgn */
   assert(m_lib_name_map.GetSize() < 256);
   assert(m_lib_nopmod_map.GetSize() < m_lib_name_map.GetSize());
@@ -82,81 +72,48 @@
   tArray<int> test_redundancy2(m_lib_name_map.GetSize());
   test_redundancy2.SetAll(0);
   for (int i = 0; i < mutation_chart2.GetSize(); i++) {
-    int test_id = mutation_chart[i];
+    int test_id = mutation_chart2[i];
     test_redundancy2[test_id]++;
   }
   for (int i = 0; i < m_lib_name_map.GetSize(); i++) {
     assert(m_lib_name_map[i].redundancy == test_redundancy2[i]);
   }
   /* XXX end */
+#else /* USE_INST_SET_CODE */
+
+  // assert(inst_array.OK());
+  // assert(nop_mods.OK());
+  assert(inst_array.GetSize() < 256);
+  assert(nop_mods.GetSize() < inst_array.GetSize());
+
+  // Make sure that all of the redundancies are represented the appropriate
+  // number of times.
+  tArray<int> test_redundancy(inst_array.GetSize());
+  test_redundancy.SetAll(0);
+  for (int i = 0; i < mutation_chart.GetSize(); i++) {
+    int test_id = mutation_chart[i];
+    test_redundancy[test_id]++;
+  }
+  for (int i = 0; i < inst_array.GetSize(); i++) {
+    assert(inst_array[i].redundancy == test_redundancy[i]);
+  }
+#endif /* USE_INST_SET_CODE */
 
   return true;
 }
 
 cInstruction cInstSet::GetRandomInst() const
 {
-  ///* XXX start -- kgn */
-  //if(mutation_chart.GetSize() != mutation_chart2.GetSize()){
-  //  cout << "<cInstSet::GetRandomInst> mutation_charts'.GetSize()es mismatch!" << endl;
-  //}
-  //unsigned int rand = g_random.GetUInt(mutation_chart.GetSize());
-  //int inst_op = mutation_chart[rand];
-  //int inst_op2 = mutation_chart2[rand];
-  //if(inst_op != inst_op2){
-  //  cout << "<cInstSet::GetRandomInst> inst_op, inst_op2 mismatch!" << endl;
-  //}
-  ///* XXX end */
-
-  ////int inst_op = mutation_chart[g_random.GetUInt(mutation_chart.GetSize())];
-
+#ifdef USE_INST_SET_CODE
   int inst_op = mutation_chart2[g_random.GetUInt(mutation_chart2.GetSize())];
+#else /* USE_INST_SET_CODE */
+  int inst_op = mutation_chart[g_random.GetUInt(mutation_chart.GetSize())];
+#endif /* USE_INST_SET_CODE */
   return cInstruction(inst_op);
 }
 
-int cInstSet::Add(const cString & _name, tHardwareMethod _fun,
-		  const int redundancy, const int ft_cost, const int cost,
-		  const double prob_fail)
-{
-  const int inst_id = inst_array.GetSize();
-
-  assert(inst_id < 255);
-
-  // Increase the size of the array...
-  inst_array.Resize(inst_id + 1);
-
-  // Setup the new function...
-  inst_array[inst_id].name = _name;
-  inst_array[inst_id].function = _fun;
-  inst_array[inst_id].redundancy = redundancy;
-  inst_array[inst_id].cost = cost;
-  inst_array[inst_id].ft_cost = ft_cost;
-  inst_array[inst_id].prob_fail = prob_fail;
-
-  const int total_redundancy = mutation_chart.GetSize();
-  mutation_chart.Resize(total_redundancy + redundancy);
-  for (int i = 0; i < redundancy; i++) {
-    mutation_chart[total_redundancy + i] = inst_id;
-  }
-
-  return inst_id;
-}
-
-int cInstSet::AddNop(const cString & _name, tHardwareMethod _fun,
-		     const int reg, const int redundancy, const int ft_cost,
-		     const int cost, const double prob_fail)
-{ 
-  // Assert nops are at the _beginning_ of an inst_set.
-  assert(inst_array.GetSize() == nop_mods.GetSize());
-
-  const int inst_id = Add(_name, _fun, redundancy, ft_cost, cost, prob_fail);
-
-  nop_mods.Resize(inst_id + 1);
-  nop_mods[inst_id] = reg;
-
-  return inst_id;
-}
-
 /**/
+#ifdef USE_INST_SET_CODE
 int cInstSet::Add2(
   const int lib_fun_id,
   const int redundancy,
@@ -206,7 +163,52 @@
 
   return inst_id;
 }
+#else /* USE_INST_SET_CODE */
 /**/
+
+int cInstSet::Add(const cString & _name, tHardwareMethod _fun,
+		  const int redundancy, const int ft_cost, const int cost,
+		  const double prob_fail)
+{
+  const int inst_id = inst_array.GetSize();
+
+  assert(inst_id < 255);
+
+  // Increase the size of the array...
+  inst_array.Resize(inst_id + 1);
+
+  // Setup the new function...
+  inst_array[inst_id].name = _name;
+  inst_array[inst_id].function = _fun;
+  inst_array[inst_id].redundancy = redundancy;
+  inst_array[inst_id].cost = cost;
+  inst_array[inst_id].ft_cost = ft_cost;
+  inst_array[inst_id].prob_fail = prob_fail;
+
+  const int total_redundancy = mutation_chart.GetSize();
+  mutation_chart.Resize(total_redundancy + redundancy);
+  for (int i = 0; i < redundancy; i++) {
+    mutation_chart[total_redundancy + i] = inst_id;
+  }
+
+  return inst_id;
+}
+
+int cInstSet::AddNop(const cString & _name, tHardwareMethod _fun,
+		     const int reg, const int redundancy, const int ft_cost,
+		     const int cost, const double prob_fail)
+{ 
+  // Assert nops are at the _beginning_ of an inst_set.
+  assert(inst_array.GetSize() == nop_mods.GetSize());
+
+  const int inst_id = Add(_name, _fun, redundancy, ft_cost, cost, prob_fail);
+
+  nop_mods.Resize(inst_id + 1);
+  nop_mods[inst_id] = reg;
+
+  return inst_id;
+}
+#endif /* USE_INST_SET_CODE */
 
 cString cInstSet::FindBestMatch(const cString & in_name) const
 {
Index: avida/current/source/main/inst_set.hh
diff -u avida/current/source/main/inst_set.hh:1.1.2.1 avida/current/source/main/inst_set.hh:1.1.2.2
--- avida/current/source/main/inst_set.hh:1.1.2.1	Tue May 20 05:12:22 2003
+++ avida/current/source/main/inst_set.hh	Fri May 23 02:36:35 2003
@@ -86,14 +86,13 @@
   // Accessors
   const cString & GetName(int id) const
   { 
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( inst_array[id].name
-    //  !=m_inst_lib->GetName(m_lib_name_map[id].lib_fun_id)
-    //){ std::cout << "<cInstSet::GetName> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return inst_array[id].name;
-
     return m_inst_lib->GetName(m_lib_name_map[id].lib_fun_id);
+    ///* XXX end */
+#else /* USE_INST_SET_CODE */
+    return inst_array[id].name;
+#endif /* USE_INST_SET_CODE */
   }
   const cString & GetName(const cInstruction & inst) const
   {
@@ -101,117 +100,110 @@
   }
   int GetCost(const cInstruction & inst) const
   {
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( inst_array[inst.GetOp()].cost
-    //  !=m_lib_name_map[inst.GetOp()].cost
-    //){ std::cout << "<cInstSet::GetCost> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return inst_array[inst.GetOp()].cost;
-
     return m_lib_name_map[inst.GetOp()].cost;
+    ///* XXX end */
+#else /* USE_INST_SET_CODE */
+    return inst_array[inst.GetOp()].cost;
+#endif /* USE_INST_SET_CODE */
   }
   int GetFTCost(const cInstruction & inst) const
   {
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( inst_array[inst.GetOp()].ft_cost
-    //  !=m_lib_name_map[inst.GetOp()].ft_cost
-    //){ std::cout << "<cInstSet::GetFTCost> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return inst_array[inst.GetOp()].ft_cost;
-
     return m_lib_name_map[inst.GetOp()].ft_cost;
+    ///* XXX end */
+#else /* USE_INST_SET_CODE */
+    return inst_array[inst.GetOp()].ft_cost;
+#endif /* USE_INST_SET_CODE */
   }
   double GetProbFail(const cInstruction & inst) const
   {
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( inst_array[inst.GetOp()].prob_fail
-    //  !=m_lib_name_map[inst.GetOp()].prob_fail
-    //){ std::cout << "<cInstSet::GetProbFail> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return inst_array[inst.GetOp()].prob_fail;
-
     return m_lib_name_map[inst.GetOp()].prob_fail;
+    ///* XXX end */
+#else /* USE_INST_SET_CODE */
+    return inst_array[inst.GetOp()].prob_fail;
+#endif /* USE_INST_SET_CODE */
   }
   int GetRedundancy(const cInstruction & inst) const
   {
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( inst_array[inst.GetOp()].redundancy
-    //  !=m_lib_name_map[inst.GetOp()].redundancy
-    //){ std::cout << "<cInstSet::GetRedundancy> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return inst_array[inst.GetOp()].redundancy;
-
     return m_lib_name_map[inst.GetOp()].redundancy;
+#else /* USE_INST_SET_CODE */
+    ///* XXX end */
+    return inst_array[inst.GetOp()].redundancy;
+#endif /* USE_INST_SET_CODE */
   }
 
-  tHardwareMethod GetFunction(const cInstruction & inst) const
-  {
-    return inst_array[inst.GetOp()].function;
-  }
-
+#ifdef USE_INST_SET_CODE
   /* XXX start -- kgn */
   int GetLibFunctionIndex(const cInstruction & inst) const
   {
     return m_lib_name_map[inst.GetOp()].lib_fun_id;
   }
   /* XXX end */
+#else /* USE_INST_SET_CODE */
+  tHardwareMethod GetFunction(const cInstruction & inst) const
+  {
+    return inst_array[inst.GetOp()].function;
+  }
+#endif /* USE_INST_SET_CODE */
 
   int GetNopMod(const cInstruction & inst) const
   {
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( nop_mods[inst.GetOp()]
-    //  !=m_inst_lib->GetNopMod(m_lib_nopmod_map[inst.GetOp()])
-    //){ std::cout << "<cInstSet::GetNopMod> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return nop_mods[inst.GetOp()];
-
     return m_inst_lib->GetNopMod(m_lib_nopmod_map[inst.GetOp()]);
+    ///* XXX end */
+#else /* USE_INST_SET_CODE */
+    return nop_mods[inst.GetOp()];
+#endif /* USE_INST_SET_CODE */
   }
 
   cInstruction GetRandomInst() const;
+  /* FIXME:  provide equivalent for USE_INST_SET_CODE section -- kgn */
   tHardwareMethod GetRandFunction() const
   {
     return inst_array[ GetRandomInst().GetOp() ].function;
   }
 
   int GetSize() const {
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( inst_array.GetSize() != m_lib_name_map.GetSize() )
-    //{ std::cout << "<cInstSet::GetSize> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return inst_array.GetSize();
-
     return m_lib_name_map.GetSize();
+    ///* XXX end */
+#else /* USE_INST_SET_CODE */
+    return inst_array.GetSize();
+#endif /* USE_INST_SET_CODE */
   }
   int GetNumNops() const {
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( nop_mods.GetSize() != m_lib_nopmod_map.GetSize() )
-    //{ std::cout << "<cInstSet::GetNumNops> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return nop_mods.GetSize();
-
     return m_lib_nopmod_map.GetSize();
+#else /* USE_INST_SET_CODE */
+    ///* XXX end */
+    return nop_mods.GetSize();
+#endif /* USE_INST_SET_CODE */
   }
 
   // Instruction Analysis.
   int IsNop(const cInstruction & inst) const
   {
+#ifdef USE_INST_SET_CODE
     ///* XXX start -- kgn */
-    //if( nop_mods.GetSize() != m_lib_nopmod_map.GetSize() )
-    //{ std::cout << "<cInstSet::IsNop> mismatch!" << std::endl; }
-    ///* XXX end */
-    //return (inst.GetOp() < nop_mods.GetSize());
-
     return (inst.GetOp() < m_lib_nopmod_map.GetSize());
+    ///* XXX end */
+#else /* USE_INST_SET_CODE */
+    return (inst.GetOp() < nop_mods.GetSize());
+#endif /* USE_INST_SET_CODE */
   }
 
   // Insertion of new instructions...
-  int Add(const cString & _name, tHardwareMethod _fun, const int redundancy=1,
-	  const int ft_cost=0, const int cost=0, const double prob_fail=0.0);
-  int AddNop(const cString & _name, tHardwareMethod _fun, const int reg,
-	     const int redundancy=1, const int ft_cost=0, const int cost=0,
-	     const double prob_fail=0.0);
-
+#ifdef USE_INST_SET_CODE
   int Add2(
     const int lib_fun_id,
     const int redundancy=1,
@@ -226,7 +218,15 @@
     const int cost=0,
     const double prob_fail=0.0
   );
+#else /* USE_INST_SET_CODE */
+  int Add(const cString & _name, tHardwareMethod _fun, const int redundancy=1,
+	  const int ft_cost=0, const int cost=0, const double prob_fail=0.0);
+  int AddNop(const cString & _name, tHardwareMethod _fun, const int reg,
+	     const int redundancy=1, const int ft_cost=0, const int cost=0,
+	     const double prob_fail=0.0);
+#endif /* USE_INST_SET_CODE */
 
+#ifdef USE_INST_SET_CODE
   /* XXX start -- kgn */
   // accessors for instruction library
   cInstLibBase *GetInstLib(){ return m_inst_lib; }
@@ -236,24 +236,33 @@
     inst_default2 = inst_lib->GetInstDefault();
   }
   /* XXX end */
+#endif /* USE_INST_SET_CODE */
 
   inline cInstruction GetInst(const cString & in_name) const;
   cString FindBestMatch(const cString & in_name) const;
 
   // Static methods..
   static const cInstruction & GetInstDefault() {
+#ifdef USE_INST_SET_CODE
     /* XXX start --- kgn */
-    if(inst_default != inst_default2)
-    { std::cout << "<cInstSet::GetInstDefault> mismatch!" << std::endl; }
+    //if(inst_default != inst_default2)
+    //{ std::cout << "<cInstSet::GetInstDefault> mismatch!" << std::endl; }
+    return inst_default2;
     /* XXX end */
+#else /* USE_INST_SET_CODE */
     return inst_default;
+#endif /* USE_INST_SET_CODE */
   }
   static const cInstruction & GetInstError()   {
     /* XXX start --- kgn */
-    if(inst_error != inst_error2)
-    { std::cout << "<cInstSet::GetInstError> mismatch!" << std::endl; }
+    //if(inst_error != inst_error2)
+    //{ std::cout << "<cInstSet::GetInstError> mismatch!" << std::endl; }
+#ifdef USE_INST_SET_CODE
+    return inst_error2;
+#else /* USE_INST_SET_CODE */
     /* XXX end */
     return inst_error;
+#endif /* USE_INST_SET_CODE */
   }
   // static const cInstruction & GetInstNone()    { return inst_none; }
 };
@@ -261,54 +270,28 @@
 
 inline cInstruction cInstSet::GetInst(const cString & in_name) const
 {
-
-  ///* XXX start --- kgn */
-  //int i, i1=-1, i2=-1;
-  //std::cout <<
-  //  "<cInstSet::GetInst> inst_array.GetSize():" <<
-  //  inst_array.GetSize() <<
-  //  std::endl;
-  //for (i = 0; i < inst_array.GetSize(); i++) {
-  //  if (inst_array[i].name == in_name){
-  //    i1 = i;
-  //  }
-  ////if (inst_array[i].name == in_name) return cInstruction(i);
-  //}
-  //std::cout <<
-  //  "<cInstSet::GetInst> i:" <<
-  //  i <<
-  //  std::endl;
-  //std::cout <<
-  //  "<cInstSet::GetInst> inst_array.GetSize():" <<
-  //  inst_array.GetSize() <<
-  //  std::endl;
-  //for (i = 0; i < m_lib_name_map.GetSize(); i++) {
-  //  if (m_inst_lib->GetName(m_lib_name_map[i].lib_fun_id) == in_name){
-  //    i2 = i;
-  //  }
-  //}
-  //std::cout <<
-  //  "<cInstSet::GetInst> i:" <<
-  //  i <<
-  //  std::endl;
-  //if(i1 != i2){
-  //  std::cout << "<cInstSet::GetInst> mismatch!" << std::endl;
-  //}
-  //if(i1>-1){ return cInstruction(i1); }
-  ///* XXX end */
-
-  //// assert(false); // Requesting ID for unknown inst.
-  //return cInstSet::GetInstError();
-
+#ifdef USE_INST_SET_CODE
   for (int i = 0; i < m_lib_name_map.GetSize(); i++) {
-    if (m_inst_lib->
-	GetName(m_lib_name_map[i].lib_fun_id) == in_name) {
+    if (m_inst_lib->GetName(m_lib_name_map[i].lib_fun_id) == in_name) {
       return cInstruction(i);
     }
   }
-
   // Adding default answer if nothing is found...
+  /*
+  FIXME:  this return value is supposed to be cInstSet::GetInstError
+  which should be the same as m_inst_lib->GetInstError().
+  -- kgn
+  */
   return cInstruction(0);
+#else /* USE_INST_SET_CODE */
+  /* XXX start --- kgn */
+  for (int i = 0; i < inst_array.GetSize(); i++) {
+    if (inst_array[i].name == in_name) return cInstruction(i);
+  }
+  // assert(false); // Requesting ID for unknown inst.
+  return cInstSet::GetInstError();
+  /* XXX end */
+#endif /* USE_INST_SET_CODE */
 }
 
 
Index: avida/current/source/qt-viewer/setup_avida.cc
diff -u avida/current/source/qt-viewer/setup_avida.cc:1.15.2.3 avida/current/source/qt-viewer/setup_avida.cc:1.15.2.4
--- avida/current/source/qt-viewer/setup_avida.cc:1.15.2.3	Tue May 20 05:12:36 2003
+++ avida/current/source/qt-viewer/setup_avida.cc	Fri May 23 02:36:35 2003
@@ -80,12 +80,16 @@
   }
 
   if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_ORIGINAL) {
+#ifdef USE_INST_SET_CODE
     environment.GetInstSet().SetInstLib(cHardwareCPU::GetInstLib());
+#endif /* USE_INST_SET_CODE */
     cHardwareUtil::LoadInstSet_CPUOriginal(cConfig::GetInstFilename(),
 					   environment.GetInstSet());
   }
   else if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_4STACK) {
+#ifdef USE_INST_SET_CODE
     environment.GetInstSet().SetInstLib(cHardware4Stack::GetInstLib());
+#endif /* USE_INST_SET_CODE */
     cHardwareUtil::LoadInstSet_CPU4Stack(cConfig::GetInstFilename(),
 					   environment.GetInstSet());
   }


More information about the Avida-cvs mailing list