• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Baremetal Lisp interpreter and compiler for low-resource devices


Commit MetaInfo

Revision04a05b78b3b72e9e218e1c621b0f695e7365dd55 (tree)
Time2020-09-13 06:39:50
AuthorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Add pointers and protocols to the S-expression library

Change Summary

Incremental Difference

--- a/makefile
+++ b/makefile
@@ -4,7 +4,7 @@
44 # Unix makefile.
55
66 CC=cc
7-CFLAGS=-g -Wall -Wextra -pedantic -Werror -ansi -Wshadow -Wno-old-style-declaration -Wno-unknown-warning-option
7+CFLAGS=-g -Wall -Wextra -pedantic -Werror -ansi -Wshadow -Wno-old-style-declaration -Wno-unknown-warning-option -DSL_S_ENABLE_POINTERS -DSL_S_ENABLE_PROTOCOLS
88 COMPILEFLAG=-c
99 COUT=-o
1010
--- a/sl_s.h
+++ b/sl_s.h
@@ -78,19 +78,26 @@ extern "C"{
7878 * If SL_S_DO_NOT_STRIP_BITS is set, then the tag bits will not be stripped
7979 * from the pointers on unpacking. This is useful for hardware with mirrored
8080 * RAM, although it is likely not useful when SL_S_TAG_LSB is set.
81+ *
82+ * Note that the settings for SL_S_ENABLE_PROTOCOLS and SL_S_ENABLE_POINTERS
83+ * will affect the defaults as well.
8184 */
8285 /*****************************************************************************/
8386
8487 #if !((defined SL_S_TAG_LSB) || (defined SL_S_TAG_MSB))
85-#define SL_S_TAG_LSB
88+# define SL_S_TAG_LSB
8689 #elif (defined SL_S_TAG_LSB) && (defined SL_S_TAG_MSB)
87-#error Invalid configuration: both SL_S_TAG_LSB and SL_S_TAG_MSB are set.
90+# error Invalid configuration: both SL_S_TAG_LSB and SL_S_TAG_MSB are set.
8891 #endif
8992
9093 #ifndef SL_S_NUM_TAG_BITS
91-#define SL_S_NUM_TAG_BITS 1
94+# if (defined SL_S_ENABLE_PROTOCOLS) || (defined SL_D_ENABLE_POINTERS)
95+# define SL_S_NUM_TAG_BITS 2
96+# else
97+# define SL_S_NUM_TAG_BITS 1
98+# endif
9299 #elif SL_S_NUM_TAG_BITS < 1
93-#error Invalid configuration: SL_S_TAG_BITS must be greater than zero.
100+# error Invalid configuration: SL_S_TAG_BITS must be greater than zero.
94101 #endif
95102
96103 /*****************************************************************************/
@@ -100,6 +107,15 @@ extern "C"{
100107 #define SL_S_LIST_TAG 0
101108 #define SL_S_ATOM_TAG 1
102109
110+#ifdef SL_S_ENABLE_PROTOCOLS
111+# define SL_S_PROTOCOL_TAG 2
112+# define SL_S_PROTO_TAG SL_S_PROTOCOL_TAG
113+#endif
114+
115+#ifdef SL_S_ENABLE_POINTERS
116+# define SL_S_POINTER_TAG 3
117+#endif
118+
103119 #define SL_S_PTR_BITS (sizeof(void*)<<3)
104120
105121 #ifdef SL_S_TAG_LSB
@@ -150,11 +166,37 @@ extern "C"{
150166 #define SL_S_IS_LIST(X) (SL_S_PTR_TAG((X), SL_S_NUM_TAG_BITS) == SL_S_LIST_TAG)
151167 #define SL_S_IS_ATOM(X) (SL_S_PTR_TAG((X), SL_S_NUM_TAG_BITS) == SL_S_ATOM_TAG)
152168
169+#ifdef SL_S_ENABLE_PROTOCOLS
170+# define SL_S_IS_PROTOCOL(X) \
171+ (SL_S_PTR_TAG((X), SL_S_NUM_TAG_BITS) == SL_S_PROTOCOL_TAG)
172+# define SL_S_IS_PROTO SL_S_IS_PROTOCOL
173+#endif
174+
175+#ifdef SL_S_ENABLE_POINTERS
176+# define SL_S_IS_POINTER(X) \
177+ (SL_S_PTR_TAG((X), SL_S_NUM_TAG_BITS) == SL_S_POINTER_TAG)
178+# define SL_S_IS_PTR SL_S_IS_POINTER
179+#endif
180+
153181 #define SL_S_MK_LIST(X) SL_S_TAG_PTR((X), SL_S_LIST_TAG)
154182 #define SL_S_MK_ATOM(X) (SL_S_IS_NIL((X)) ? \
155183 SL_S_NIL : \
156184 SL_S_TAG_PTR((X), SL_S_ATOM_TAG))
157185
186+#ifdef SL_S_ENABLE_PROTOCOLS
187+# define SL_S_MK_PROTOCOL(X) (SL_S_IS_NIL(X) ? \
188+ SL_S_NIL : \
189+ SL_S_TAG_PTR((X), SL_S_PROTOCOL_TAG))
190+# define SL_S_MK_PROTO SL_S_MK_PROTOCOL
191+#endif
192+
193+#ifdef SL_S_ENABLE_POINTERS
194+# define SL_S_MK_POINTER(X) (SL_S_IS_NIL(X) ? \
195+ SL_S_NIL : \
196+ SL_S_TAG_PTR((X), SL_S_POINTER_TAG))
197+# define SL_S_MK_PTR SL_S_MK_POINTER
198+#endif
199+
158200 /*****************************************************************************/
159201 /* Len/Refcount typedefs */
160202
@@ -261,6 +303,51 @@ struct SL_S_List{
261303 };
262304
263305 /*****************************************************************************/
306+
307+#ifdef SL_S_ENABLE_PROTOCOLS
308+
309+/*****************************************************************************/
310+/** Represents an protocol object. */
311+struct SL_S_Protocol{
312+ sl_s_ref_t ref;
313+#ifndef SL_S_NO_PARSER_INFO
314+ sl_s_len_t line;
315+#endif
316+ SL_S_FUNC_PTR(void, destroy)(struct SL_S_Protocol *that);
317+};
318+
319+/*****************************************************************************/
320+
321+#endif
322+
323+/*****************************************************************************/
324+
325+#ifdef SL_S_ENABLE_POINTERS
326+
327+/*****************************************************************************/
328+/** Holds a boxed pointer.
329+ *
330+ * Sadly, for use in Sapphire Lisp, all pointers must be boxed to work properly
331+ * with tag bits.
332+ *
333+ * NULL (in C) can still be represented as an unboxed NIL, and SL_S_MK_PTR will
334+ * actually cause this to happen when possible.
335+ *
336+ * The ref-count only applies to the pointer's box.
337+ */
338+struct SL_S_Pointer{
339+ sl_s_ref_t ref;
340+#ifndef SL_S_NO_PARSER_INFO
341+ sl_s_len_t line;
342+#endif
343+ void *data;
344+};
345+
346+/*****************************************************************************/
347+
348+#endif
349+
350+/*****************************************************************************/
264351 /** Shared struct to allow access to refcount without conditional casts */
265352 struct SL_S_Ref{
266353 sl_s_ref_t ref;