• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Baremetal Lisp interpreter and compiler for low-resource devices


Commit MetaInfo

Revisionb515d4458fb8c1dab6173340e3df10c89d065806 (tree)
Zeit2020-09-14 08:40:58
AutorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Add pointer and protocol support to SL_S_Compare and SL_S_Match

Ändern Zusammenfassung

Diff

--- a/sl_s.c
+++ b/sl_s.c
@@ -250,8 +250,12 @@ SL_S_FUNC(int) SL_S_Compare(const void *a, const void *b){
250250 /* Handle nil's */
251251 union {
252252 void *ptr;
253+ int i;
253254 struct SL_S_Atom *atom;
254255 struct SL_S_List *list;
256+#ifdef SL_S_ENABLE_POINTERS
257+ struct SL_S_Pointer *pointer;
258+#endif
255259 } a_val, b_val;
256260 int a_tag, b_tag, r;
257261
@@ -280,23 +284,65 @@ SL_S_FUNC(int) SL_S_Compare(const void *a, const void *b){
280284 b_val.atom->text,
281285 a_val.atom->len);
282286 }
283- else{
284-compare_list_again:
285- r = SL_S_Compare(a_val.list->head, b_val.list->head);
286- if(r != 0)
287- return r;
288-
289- a_val.list = a_val.list->tail;
290- b_val.list = b_val.list->tail;
291-
292- if(SL_S_IS_NIL(a_val.list) && SL_S_IS_NIL(b_val.list))
287+#ifdef SL_S_ENABLE_POINTERS
288+ if(a_tag == SL_S_POINTER_TAG){
289+ if(a_val.ptr == b_val.ptr ||
290+ a_val.pointer->data == b_val.pointer->data){
291+
293292 return 0;
294- else if(SL_S_IS_NIL(a_val.list))
293+ }
294+ /* We can take a little shorcut when ints and ptrs are comparable. */
295+ if(sizeof(void*) <= sizeof(int)){
296+ a_val.ptr = a_val.pointer->data;
297+ b_val.ptr = a_val.pointer->data;
298+ return a_val.i - b_val.i;
299+ }
300+
301+ if((char*)(a_val.pointer->data) - (char*)SL_S_NIL >
302+ (char*)(b_val.pointer->data) - (char*)SL_S_NIL){
303+
304+ return 1;
305+ }
306+ else{
295307 return -1;
296- else if(SL_S_IS_NIL(b_val.list))
308+ }
309+ }
310+#endif
311+#ifdef SL_S_ENABLE_PROTOCOLS
312+ if(a_tag == SL_S_PROTOCOL_TAG){
313+ if(a_val.ptr == b_val.ptr)
314+ return 0;
315+
316+ /* We can take a little shorcut when ints and ptrs are comparable. */
317+ if(sizeof(void*) <= sizeof(int))
318+ return a_val.i - b_val.i;
319+
320+ if((char*)(a_val.ptr) - (char*)SL_S_NIL >
321+ (char*)(b_val.ptr) - (char*)SL_S_NIL){
322+
297323 return 1;
298- goto compare_list_again;
324+ }
325+ else{
326+ return -1;
327+ }
299328 }
329+#endif
330+
331+compare_list_again:
332+ r = SL_S_Compare(a_val.list->head, b_val.list->head);
333+ if(r != 0)
334+ return r;
335+
336+ a_val.list = a_val.list->tail;
337+ b_val.list = b_val.list->tail;
338+
339+ if(SL_S_IS_NIL(a_val.list) && SL_S_IS_NIL(b_val.list))
340+ return 0;
341+ else if(SL_S_IS_NIL(a_val.list))
342+ return -1;
343+ else if(SL_S_IS_NIL(b_val.list))
344+ return 1;
345+ goto compare_list_again;
300346 }
301347
302348 /*****************************************************************************/
@@ -325,13 +371,10 @@ SL_S_FUNC(int) SL_S_Match(const struct SL_S_List *in,
325371 else if((flags[i] & SL_S_ANY_MASK) == SL_S_ANY){
326372 /* Is an any. */
327373 }
328- else if(flags[i] & SL_S_ATOM_TAG){
329- if(!SL_S_IS_ATOM(in->head))
330- return -(int)i;
331- }
332- else{
333- if(!SL_S_IS_LIST(in->head))
334- return -(int)i;
374+ else if(SL_S_PTR_TAG(in->head, SL_S_NUM_TAG_BITS) !=
375+ (flags[i] & SL_S_PTR_TAG_MASK(SL_S_NUM_TAG_BITS))){
376+
377+ return -1;
335378 }
336379
337380 if((flags[i] & SL_S_IN_OUT_MASK) == SL_S_IN){
--- a/sl_s.h
+++ b/sl_s.h
@@ -387,9 +387,13 @@ union SL_S_SizeofUnion{
387387 * @brief Accesses the line for an item.
388388 */
389389 #ifdef SL_S_NO_PARSER_INFO
390-#define SL_S_LINE(X) (0)
390+#define SL_S_LINE(X) ((void)(sizeof(X)))
391+#define SL_S_SET_LINE(X, LN) ((void)(sizeof(X), sizeof((LN) | 0)))
392+#define SL_S_PTR_SET_LINE(X, LN) ((void)(sizeof(X), sizeof((LN) | 0)))
391393 #else
392394 #define SL_S_LINE(X) (((struct SL_S_Line*)SL_S_PTR_FROM_TAG((X)))->line)
395+#define SL_S_SET_LINE(X, LN) ((void)(SL_S_LINE(X) = (LN)|0))
396+#define SL_S_PTR_SET_LINE(X, LN) ((void)((X)->line = (LN) | 0))
393397 #endif
394398
395399 /*****************************************************************************/