1. Fuzhou Chen
  2. esch

Commits

Fuzhou Chen  committed 2ead37a

[Upd] Rename esch_element to esch_value.

  • Participants
  • Parent commits e0bef14
  • Branches default

Comments (0)

Files changed (4)

File src/esch.h

View file
  * - key = "common:alloc", value = esch_alloc
  * - key = "common:log", value = esch_log
  * - key = "common:gc", value = esch_gc
- * - key = "vector:element_type", value = enum_type
- * - key = "vector:initial_length", value = int
- * - key = "vector:delete_element", value = int
+ * - key = "vector:value_type", value = enum_type
+ * - key = "vector:length", value = int
+ * - key = "gc:naive:slots", value = int
+ * - key = "gc:naive:root", value = int
  */
 extern const char* ESCH_CONFIG_KEY_ALLOC;
 extern const char* ESCH_CONFIG_KEY_LOG;
  * The data structure to allow contianer type define an iterator. It's
  * used to access element of container type.
  */
-typedef enum esch_element_type
+typedef enum esch_value_type
 {
-    ESCH_ELEMENT_TYPE_END = 0,
-    ESCH_ELEMENT_TYPE_CHAR,
-    ESCH_ELEMENT_TYPE_UNICODE,
-    ESCH_ELEMENT_TYPE_INTEGER,
-    ESCH_ELEMENT_TYPE_FLOAT,
-    ESCH_ELEMENT_TYPE_OBJECT
-} esch_element_type;
+    ESCH_VALUE_TYPE_END = 0,
+    ESCH_VALUE_TYPE_CHAR,
+    ESCH_VALUE_TYPE_UNICODE,
+    ESCH_VALUE_TYPE_INTEGER,
+    ESCH_VALUE_TYPE_FLOAT,
+    ESCH_VALUE_TYPE_OBJECT
+} esch_value_type;
 
 /* Basic types */
 typedef struct esch_type            esch_type;
 typedef struct esch_object          esch_object;
 typedef struct esch_iterator        esch_iterator;
-typedef struct esch_element         esch_element;
+typedef struct esch_value           esch_value;
 typedef struct esch_config          esch_config;
 typedef struct esch_alloc           esch_alloc;
 typedef struct esch_log             esch_log;
 typedef esch_error (*esch_object_get_iterator_f)(esch_object*,
                                                  esch_iterator*);
 typedef esch_error (*esch_iterator_get_value_f)(esch_iterator*,
-                                                esch_element*);
+                                                esch_value*);
 typedef esch_error (*esch_iterator_get_next_f)(esch_iterator*);
 typedef esch_error (*esch_alloc_realloc_f)(esch_alloc*, void*, size_t,
                                            void**);
 /*                        Object model                               */
 /* ----------------------------------------------------------------- */
 /**
- * Data structure to represent iterator element. Support different types
+ * Data structure to represent general value. Support different types
  * of values.
  */
-struct esch_element
+struct esch_value
 {
-    enum esch_element_type type;
+    enum esch_value_type type;
     union
     {
-        esch_byte    b; /**< byte element */
-        esch_unicode u; /**< unicode element */
-        int          i; /**< integer element */
-        double       f; /**< float element (implemented as double) */
-        esch_object* o; /**< object element */
+        esch_byte    b; /**< byte value */
+        esch_unicode u; /**< unicode value */
+        int          i; /**< integer value */
+        double       f; /**< float value (implemented as double) */
+        esch_object* o; /**< object value */
     } val;
 };
 
 
 /**
  * Create a new vector.
- * @param config Configuration. Give element type and initial length.
+ * @param config Configuration.
  * @param vec Returned vector object.
  * @return Return code. ESCH_OK if success.
  */

File src/esch_gc.c

View file
 {
     esch_error ret = ESCH_OK;
     esch_log* log = NULL;
-    esch_element element = { ESCH_ELEMENT_TYPE_END, 0 };
+    esch_value element = { ESCH_VALUE_TYPE_END, 0 };
     esch_object* child = NULL;
     esch_object** stack_ptr = NULL;
     esch_type* element_type = NULL;
             while(ESCH_TRUE) {
                 ret = iter.get_value(&iter, &element);
                 ESCH_ASSERT(ret == ESCH_OK);
-                if (element.type == ESCH_ELEMENT_TYPE_END) {
+                if (element.type == ESCH_VALUE_TYPE_END) {
                     esch_log_info(log, "gc:recycle: end of objects.");
                     break;
-                } else if (element.type != ESCH_ELEMENT_TYPE_OBJECT) {
+                } else if (element.type != ESCH_VALUE_TYPE_OBJECT) {
                     esch_log_info(log, "gc:recycle: primitive type, skip.");
                     ret = iter.get_next(&iter);
                     continue;

File src/esch_vector.c

View file
     return ret;
 }
 static esch_error
-esch_vector_get_value_i(esch_iterator* iter, esch_element* element)
+esch_vector_get_value_i(esch_iterator* iter, esch_value* value)
 {
     esch_error ret = ESCH_OK;
     size_t offset = 0;
     esch_vector* vec = NULL;
     
     ESCH_CHECK_PARAM_PUBLIC(iter != NULL);
-    ESCH_CHECK_PARAM_PUBLIC(element != NULL);
+    ESCH_CHECK_PARAM_PUBLIC(value != NULL);
     ESCH_CHECK_PARAM_PUBLIC(iter->container != NULL);
     vec = ESCH_CAST_FROM_OBJECT(iter->container, esch_vector);
     ESCH_CHECK_PARAM_PUBLIC(ESCH_IS_VALID_VECTOR(vec));
 
     offset = (size_t)(iter->iterator);
     if (offset >= vec->next - vec->begin) {
-        element->type = ESCH_ELEMENT_TYPE_END;
-        element->val.o = 0;
+        value->type = ESCH_VALUE_TYPE_END;
+        value->val.o = 0;
     } else {
-        element->type = ESCH_ELEMENT_TYPE_OBJECT;
-        element->val.o = vec->begin[offset];
+        value->type = ESCH_VALUE_TYPE_OBJECT;
+        value->val.o = vec->begin[offset];
     }
 Exit:
     return ret;

File src/utest/esch_t_vector.c

View file
                     esch_string* str[], size_t len)
 {
     esch_iterator iter;
-    esch_element element;
+    esch_value element;
     esch_error ret = ESCH_OK;
     size_t i = 0;
     ret = esch_object_get_iterator(ESCH_CAST_TO_OBJECT(vec), &iter);
         ret = iter.get_value(&iter, &element);
         ESCH_TEST_CHECK(ret == ESCH_OK, "Can't get element",
                         ESCH_ERROR_BAD_VALUE_TYPE);
-        if (element.type == ESCH_ELEMENT_TYPE_END) {
+        if (element.type == ESCH_VALUE_TYPE_END) {
             break;
         }
-        ESCH_TEST_CHECK(element.type == ESCH_ELEMENT_TYPE_OBJECT,
+        ESCH_TEST_CHECK(element.type == ESCH_VALUE_TYPE_OBJECT,
                 "Element type is wrong", ESCH_ERROR_BAD_VALUE_TYPE);
         ESCH_TEST_CHECK(element.val.o != NULL,
                 "Element is not object", ESCH_ERROR_BAD_VALUE_TYPE);