shithub: sl

Download patch

ref: f3ac39d0ad96c5a465044e2a38d81713908454c3
parent: 108a9de63855e85b23b98edcffa095ffed9eb9f8
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Feb 10 13:51:40 EST 2025

forwarding: use top bit instead of next cell

--- a/src/flisp.h
+++ b/src/flisp.h
@@ -95,7 +95,6 @@
 #define NONNUMERIC (0xff)
 #define valid_numtype(v) ((v) <= T_DOUBLE)
 #define UNBOUND ((value_t)1) // an invalid value
-#define TAG_FWD UNBOUND
 #define tag(x) ((x) & 7)
 #define ptr(x) ((void*)((uintptr_t)(x) & (~(uintptr_t)7)))
 #define tagptr(p, t) ((value_t)(p) | (t))
@@ -120,13 +119,12 @@
 #define mark_cons(c) bitvector_set(FL(consflags), cons_index(c))
 #define unmark_cons(c) bitvector_reset(FL(consflags), cons_index(c))
 
-#define isforwarded(v) (((value_t*)ptr(v))[0] == TAG_FWD)
-#define forwardloc(v) (((value_t*)ptr(v))[1])
+#define isforwarded(v) (*(value_t*)ptr(v) & TOP_BIT)
+#define forwardloc(v) (*(value_t*)ptr(v) ^ TOP_BIT)
 #define forward(v, to) \
 	do{ \
-		(((value_t*)ptr(v))[0] = TAG_FWD); \
-		(((value_t*)ptr(v))[1] = to); \
-	}while (0)
+		*(value_t*)ptr(v) = (value_t)(to) | TOP_BIT; \
+	}while(0)
 
 #define vector_size(v) (((size_t*)ptr(v))[0]>>2)
 #define vector_setsize(v, n) (((size_t*)ptr(v))[0] = ((n)<<2))
@@ -135,8 +133,8 @@
 // functions ending in _ are unsafe, faster versions
 #define car_(v) (((cons_t*)ptr(v))->car)
 #define cdr_(v) (((cons_t*)ptr(v))->cdr)
-#define car(v) (tocons((v))->car)
-#define cdr(v) (tocons((v))->cdr)
+#define car(v) (tocons(v)->car)
+#define cdr(v) (tocons(v)->cdr)
 #define fn_bcode(f) (((function_t*)ptr(f))->bcode)
 #define fn_vals(f) (((function_t*)ptr(f))->vals)
 #define fn_env(f) (((function_t*)ptr(f))->env)