Improve macro expansion and returns

This commit is contained in:
2025-09-19 23:50:23 -07:00
parent 342bdfb169
commit 7f68c8fcbf
3 changed files with 220 additions and 34 deletions

View File

@ -295,7 +295,7 @@ inline static bool NUMBERP(LispVal *v) {
!NILP(__foreach_cur); \
__foreach_cur = TAIL(__foreach_cur), var = HEAD(__foreach_cur))
#define FOREACH_TAIL(var, list) \
for (LispVal *var = list; !NILP(var); var = TAIL(var))
for (LispVal *var = list; PAIRP(var); var = TAIL(var))
// #############################
// # Allocation and references #
@ -650,5 +650,17 @@ static inline LispVal *TAIL(LispVal *list) {
CHECK_TYPE(TYPE_PAIR, list);
return ((LispPair *) list)->tail;
}
static inline LispVal *HEAD_SAFE(LispVal *list) {
if (!PAIRP(list)) {
return Qnil;
}
return ((LispPair *) list)->head;
}
static inline LispVal *TAIL_SAFE(LispVal *list) {
if (!PAIRP(list)) {
return Qnil;
}
return ((LispPair *) list)->tail;
}
#endif