commit 6ed7b3405e9d0358f51a4092496c3c08678bd627
parent 2be17bc418f7d887b43f3ddc0297aad6eeef9bd9
Author: m21c <ho*******@gmail.com>
Date: Thu, 2 Feb 2023 04:58:48 +0100
added listappend macros
Diffstat:
| M | compiler.c | | | 40 | ++++++++++++++++++++++------------------ |
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/compiler.c b/compiler.c
@@ -10,6 +10,24 @@
typedef unsigned char uchar;
typedef unsigned int uint;
+#define listappendex(parent, child, head, tail, prev, next) do { \
+ if ((parent)->head) { \
+ assert((parent)->tail); \
+ (child)->prev = (parent)->tail; \
+ (child)->next = NULL; \
+ (parent)->tail->next = (child); \
+ } else { \
+ assert(!(parent)->tail); \
+ (child)->prev = NULL; \
+ (child)->next = NULL; \
+ (parent)->head = (child); \
+ } \
+ (parent)->tail = (child); \
+} while (0)
+
+#define listappend(parent, child) \
+ listappendex(parent, child, head, tail, prev, next)
+
/* SECTION: - forward declarations - */
@@ -1749,14 +1767,9 @@ deferfuncenv(Source *source, int keydeclinfunc)
if (!funcenv->pending) {
funcenv->pending = true;
- if (!source->pendingenvhead) {
- source->pendingenvtail = funcenv;
- source->pendingenvhead = funcenv;
- } else {
- source->pendingenvtail->pendingnext = funcenv;
- funcenv->pendingprev = source->pendingenvtail;
- source->pendingenvtail = funcenv;
- }
+ listappendex(source, funcenv,
+ pendingenvhead, pendingenvtail,
+ pendingprev, pendingnext);
}
} else {
/* TODO(m21c): maybe use getloc(source) instead of
@@ -1801,16 +1814,7 @@ appenddecltoenv(Decl *decl, Env *targetenv)
decl->parentenv = targetenv;
- if (targetenv->tail) {
- targetenv->tail->next = decl;
- decl->prev = targetenv->tail;
- } else {
- assert(targetenv->head == NULL);
- targetenv->head = decl;
- }
-
- targetenv->tail = decl;
-
+ listappend(targetenv, decl);
}
static void