1. Fuzhou Chen
  2. esch

Commits

Fuzhou Chen  committed ee5c656

[New] Support Lisp style list/pair.

This is the implementation + basic test for implementing LISP sytle
list object, also with empty list (aka, null type) defined. Unlike LISP
pair, the pair in C level is an enumeratable object.

NOTE: this may have impact on GC. Do we really want list element
enumeratable?

  • Participants
  • Parent commits 0e6a426
  • Branches default

Comments (0)

Files changed (5)

File src/SConstruct

View file
  • Ignore whitespace
         'esch_config.c', 'esch_gc.c', \
         'esch_string.c', 'esch_range.c', \
         'esch_vector.c', 'esch_value.c', \
+        'esch_pair.c', \
         ]
 esch = env.StaticLibrary('esch', libesch_src)
 # Unit test
               'utest/esch_t_alloc.c', \
               'utest/esch_t_string.c', \
               'utest/esch_t_gc.c', \
-              'utest/esch_t_vector.c' \
+              'utest/esch_t_vector.c', \
+              'utest/esch_t_pair.c' \
             ]
 esch_utest = env.Program('esch_utest', utest_src, LIBS=[ 'esch' ], \
                          LIBPATH=[ '.' ])

File src/esch.h

View file
  • Ignore whitespace
 typedef struct esch_ast             esch_ast;
 typedef struct esch_string          esch_string;
 typedef struct esch_vector          esch_vector;
+typedef struct esch_pair            esch_pair;
 typedef char                        esch_utf8;
 typedef int32_t                     esch_unicode;
 typedef unsigned char               esch_bool;
  */
 esch_error esch_vector_set_float(esch_vector* vec, int index, double f);
 
+/* --- Pair --- */
+/**
+ * Create a new pair.
+ * @param config Given config object.
+ * @param head Head object.
+ * @param tail Tail object.
+ * @param pair Out parameter of created pair.
+ * @return ESCH_OK if correct.
+ */
+esch_error esch_pair_new(esch_config* config,
+                         esch_value* head, esch_value* tail,
+                         esch_pair** pair);
+/**
+ * Create an empty list.
+ * @param config Given config object.
+ * @param head Head object.
+ * @param tail Tail object.
+ * @param pair Out parameter of created pair.
+ * @return ESCH_OK if correct.
+ */
+esch_error esch_pair_new_empty(esch_config* config, esch_pair** pair);
+
 
 /* --- Number -- */
 

File src/utest/esch_utest.c

View file
  • Ignore whitespace
                     ret);
     esch_log_info(testLog, "[PASSED] test_vectorDifferentValues()");
 
+    esch_log_info(testLog, "Start: test_pairBase()");
+    ret = test_pairBase(config);
+    ESCH_TEST_CHECK(ret == ESCH_OK, "test_pairBase() failed", ret);
+    esch_log_info(testLog, "[PASSED] test_pairBase()");
+
     /*
     ret = test_config();
     ESCH_TEST_CHECK(ret == ESCH_OK, "test_config() failed", ret);

File src/utest/esch_utest.h

View file
  • Ignore whitespace
 extern esch_error test_gcRecycleLogic(esch_config* config);
 extern esch_error test_gcNoExpand(esch_config* config);
 extern esch_error test_gcExpand(esch_config* config);
+extern esch_error test_pairBase(esch_config* config);
 
 #ifdef __cplusplus
 }

File tasks.rst

View file
  • Ignore whitespace
 
 * Implement list type (requires GC for verification)
   - Update esch_string to allow iteration.
-  - Implement list/pair type with GC.
-  - Implement null type.
+  - [DONE] Implement list/pair type with GC.
+  - [DONE] Implement null type (via esch_list_new_empty())
   - [DONE] Set vector slots resizing configurable.
 
 * [DONE] Allow vector store primitive types.