[Avida-SVN] r2465 - development/source/script

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Tue Mar 18 10:29:58 PDT 2008


Author: brysonda
Date: 2008-03-18 13:29:58 -0400 (Tue, 18 Mar 2008)
New Revision: 2465

Modified:
   development/source/script/cDirectInterpretASTVisitor.cc
   development/source/script/cDirectInterpretASTVisitor.h
Log:
AS:
Ground work for interpreter dictionary handling.

Modified: development/source/script/cDirectInterpretASTVisitor.cc
===================================================================
--- development/source/script/cDirectInterpretASTVisitor.cc	2008-03-18 16:20:32 UTC (rev 2464)
+++ development/source/script/cDirectInterpretASTVisitor.cc	2008-03-18 17:29:58 UTC (rev 2465)
@@ -1415,6 +1415,31 @@
 }
 
 
+bool cDirectInterpretASTVisitor::sAggregateValue::operator==(const sAggregateValue& lval)
+{
+  if (type == lval.type) {
+    switch (type) {
+      case TYPE(BOOL):    return val.as_bool == lval.val.as_bool;
+      case TYPE(CHAR):    return val.as_char == lval.val.as_char;
+      case TYPE(INT):     return val.as_int == lval.val.as_int;
+      case TYPE(FLOAT):   return val.as_float == lval.val.as_float;
+      case TYPE(STRING):  return *val.as_string == *lval.val.as_string;
+      case TYPE(ARRAY):   return val.as_array == lval.val.as_array;
+        
+      case TYPE(DICT): // @TODO - aggregate value compare
+      case TYPE(MATRIX): // @TODO - aggregate value compare
+      case TYPE(OBJECT_REF): // @TODO - aggregate value compare
+        return val.as_void == lval.val.as_void;
+      
+      default:
+        break;
+    }
+  }
+  
+  return false;
+}
+
+                                                             
 void cDirectInterpretASTVisitor::cLocalArray::Set(int i, const sASTypeInfo& type, uAnyType value)
 {
   m_storage[i].type = type;

Modified: development/source/script/cDirectInterpretASTVisitor.h
===================================================================
--- development/source/script/cDirectInterpretASTVisitor.h	2008-03-18 16:20:32 UTC (rev 2464)
+++ development/source/script/cDirectInterpretASTVisitor.h	2008-03-18 17:29:58 UTC (rev 2465)
@@ -37,6 +37,7 @@
 private:
   // --------  Internal Type Declarations  --------
   class cLocalArray;
+  class cLocalDict;
   class cLocalMatrix;
   class cObjectRef;
   
@@ -47,13 +48,17 @@
     double as_float;
     cString* as_string;
     cLocalArray* as_array;
+    cLocalDict* as_dict;
     cLocalMatrix* as_matrix;
     cObjectRef* as_ref;
+    void* as_void;
   } uAnyType;
   
   struct sAggregateValue {
     uAnyType value;
     sASTypeInfo type;
+    
+    bool operator==(const sAggregateValue& rval);
   };
     
 
@@ -155,6 +160,12 @@
   };
   
   
+  class cLocalDict
+  {
+    
+  };
+  
+  
   class cLocalMatrix
   {
     
@@ -215,7 +226,21 @@
   };
 };
 
+namespace nHashTable {
+  template<> inline int HashKey<sAggregateValue>(const sAggregateValue& key)
+  {
+    switch (key.type) {
+      case AS_TYPE_BOOL:    return HashKey<int>(key.value.as_bool);
+      case AS_TYPE_CHAR:    return HashKey<int>(key.value.as_char);
+      case AS_TYPE_INT:     return HashKey<int>(key.value.as_int);
+      case AS_TYPE_FLOAT:   return HashKey<int>((int)key.value.as_float);
+      case AS_TYPE_STRING:  return HashKey<cString>(*key.value.as_string);
+      default:              return HashKey<void*>(key.value.as_void);
+    }
+  }
+}
 
+
 inline cDirectInterpretASTVisitor::cLocalArray::cLocalArray(cLocalArray* in_array)
   : m_storage(in_array->m_storage.GetSize()), m_ref_count(1)
 {




More information about the Avida-cvs mailing list