[Avida-SVN] r2096 - development/source/cpu

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Sep 17 11:45:16 PDT 2007


Author: brysonda
Date: 2007-09-17 14:45:15 -0400 (Mon, 17 Sep 2007)
New Revision: 2096

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareExperimental.cc
   development/source/cpu/cHardwareGX.cc
   development/source/cpu/cHardwareSMT.cc
   development/source/cpu/cHardwareTransSMT.cc
   development/source/cpu/cInstLib.h
   development/source/cpu/cInstSet.cc
   development/source/cpu/cInstSet.h
   development/source/cpu/tInstLib.h
Log:
Change instruction error, default, and null handling to properly store library function ids rather than holding them in cInstruction objects.

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/cHardwareCPU.cc	2007-09-17 18:45:15 UTC (rev 2096)
@@ -392,11 +392,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
-	const cInstruction error(255);
-	const cInstruction def(0);
-  const cInstruction null_inst(f_size - 1);
+	const int def = 0;
+  const int null_inst = f_size - 1;
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/cHardwareExperimental.cc	2007-09-17 18:45:15 UTC (rev 2096)
@@ -136,11 +136,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
-	const cInstruction error(255);
-	const cInstruction def(0);
-  const cInstruction null_inst(4);
+	const int def = 0;
+  const int null_inst = 4;
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 cHardwareExperimental::cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareGX.cc
===================================================================
--- development/source/cpu/cHardwareGX.cc	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/cHardwareGX.cc	2007-09-17 18:45:15 UTC (rev 2096)
@@ -301,11 +301,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
-	const cInstruction error(255);
-	const cInstruction def(0);
-  const cInstruction null_inst(f_size - 1);
+	const int def = 0;
+  const int null_inst = f_size - 1;
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 

Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/cHardwareSMT.cc	2007-09-17 18:45:15 UTC (rev 2096)
@@ -127,11 +127,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 	
-	const cInstruction error(255);
-	const cInstruction def(0);
-	const cInstruction null_inst(f_size - 1);
+	const int def = 0;
+  const int null_inst = f_size - 1;
   
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 cHardwareSMT::cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/cHardwareTransSMT.cc	2007-09-17 18:45:15 UTC (rev 2096)
@@ -126,11 +126,10 @@
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 	
-	const cInstruction error(255);
-	const cInstruction def(0);
-  const cInstruction null_inst(f_size - 1);
+	const int def = 0;
+  const int null_inst = f_size - 1;
 	
-  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
+  return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
 cHardwareTransSMT::cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)

Modified: development/source/cpu/cInstLib.h
===================================================================
--- development/source/cpu/cInstLib.h	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/cInstLib.h	2007-09-17 18:45:15 UTC (rev 2096)
@@ -45,15 +45,14 @@
   const int m_size;
   tDictionary<int> m_namemap;
 
-  const cInstruction m_inst_error;
-  const cInstruction m_inst_default;
-  const cInstruction m_inst_null;
+  int m_inst_default;
+  int m_inst_null;
   
   cInstLib(); // @not_implemented
   
 public:
-  cInstLib(int size, const cInstruction inst_error, const cInstruction inst_default, const cInstruction inst_null)
-    : m_size(size), m_inst_error(inst_error), m_inst_default(inst_default), m_inst_null(inst_null) { ; }
+  cInstLib(int size, int inst_default, int inst_null)
+    : m_size(size), m_inst_default(inst_default), m_inst_null(inst_null) { ; }
   virtual ~cInstLib() { ; }
 
   inline int GetSize() const { return m_size; }
@@ -69,11 +68,13 @@
   virtual int GetNopMod(const unsigned int id) = 0;
   virtual int GetNopMod(const cInstruction& inst) = 0;
   
-  inline cInstruction GetInst(const cString& name);
 
-  const cInstruction GetInstError() const { return m_inst_error; }
-  const cInstruction GetInstDefault() const { return m_inst_default; }
-  const cInstruction GetInstNull() const { return m_inst_null; }
+  int GetInstDefault() const { return m_inst_default; }
+  int GetInstNull() const { return m_inst_null; }
+
+private:
+    inline cInstruction GetInst(const cString& name);
+
 };
 
 
@@ -88,7 +89,7 @@
 {
   int idx;
   if (m_namemap.Find(name, idx)) return cInstruction(idx);
-  return m_inst_error;
+  return cInstruction(255);
 }
 
 

Modified: development/source/cpu/cInstSet.cc
===================================================================
--- development/source/cpu/cInstSet.cc	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/cInstSet.cc	2007-09-17 18:45:15 UTC (rev 2096)
@@ -38,7 +38,7 @@
 
 bool cInstSet::OK() const
 {
-  assert(m_lib_name_map.GetSize() < 256);
+  assert(m_lib_name_map.GetSize() < 255);
   assert(m_lib_nopmod_map.GetSize() < m_lib_name_map.GetSize());
 
   // Make sure that all of the redundancies are represented the appropriate
@@ -67,7 +67,7 @@
 cInstruction cInstSet::ActivateNullInst()
 {  
   const int inst_id = m_lib_name_map.GetSize();
-  const int null_fun_id = m_inst_lib->GetInstNull().GetOp();
+  const int null_fun_id = m_inst_lib->GetInstNull();
   
   assert(inst_id < 255);
   
@@ -196,7 +196,7 @@
     }
     
     // Check to make sure we are not inserting the special NULL instruction
-    if (fun_id == m_inst_lib->GetInstNull().GetOp()) {
+    if (fun_id == m_inst_lib->GetInstNull()) {
       errors.PushRear(new cString("Invalid use of NULL instruction"));
       success = false;
       continue;
@@ -342,7 +342,7 @@
 
     
     
-    if (fun_id == m_inst_lib->GetInstNull().GetOp())
+    if (fun_id == m_inst_lib->GetInstNull())
       m_world->GetDriver().RaiseFatalException(1,"Invalid use of NULL instruction");
     
     const int inst_id = m_lib_name_map.GetSize();

Modified: development/source/cpu/cInstSet.h
===================================================================
--- development/source/cpu/cInstSet.h	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/cInstSet.h	2007-09-17 18:45:15 UTC (rev 2096)
@@ -133,8 +133,8 @@
   cString FindBestMatch(const cString& in_name) const;
   bool InstInSet(const cString& in_name) const;
 
-  cInstruction GetInstDefault() const { return m_inst_lib->GetInstDefault(); }
-  cInstruction GetInstError() const { return m_inst_lib->GetInstError(); }
+  cInstruction GetInstDefault() const { return cInstruction(m_inst_lib->GetInstDefault()); }
+  cInstruction GetInstError() const { return cInstruction(255); }
   
   void LoadFromConfig();
   void LoadFromFile(const cString& filename);
@@ -183,12 +183,7 @@
 
 
   // 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);
+  return cInstruction(255);
 }
 
 #endif

Modified: development/source/cpu/tInstLib.h
===================================================================
--- development/source/cpu/tInstLib.h	2007-09-17 14:55:34 UTC (rev 2095)
+++ development/source/cpu/tInstLib.h	2007-09-17 18:45:15 UTC (rev 2096)
@@ -47,8 +47,8 @@
 
 public:
   tInstLib(int size, const tInstLibEntry<MethodType>* entries, cString* nopmod_names, const int* nopmods,
-           const MethodType* functions, const cInstruction error, const cInstruction def, const cInstruction null_inst)
-  : cInstLib(size, error, def, null_inst), m_entries(entries), 
+           const MethodType* functions, int def, int null_inst)
+  : cInstLib(size, def, null_inst), m_entries(entries), 
     m_nopmod_names(nopmod_names),
     m_nopmods(nopmods),
     m_functions(functions)




More information about the Avida-cvs mailing list