multi_cons macro - gcl.git - GNU Common Lisp

index : gcl.git
GNU Common Lisp
summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamm Maguire <camm@debian.org>2014年09月23日 15:52:20 -0400
committerCamm Maguire <camm@debian.org>2014年09月23日 15:52:20 -0400
commit158de30fd7f34fbeeaeb540d24c94814dc2245e3 (patch)
treea909b2cadbce2d79e94722eb81523f4fff74d192
parent7cdc0ccf9e80134d7ba34a2d8711ab1bd7e01d36 (diff)
downloadgcl-158de30fd7f34fbeeaeb540d24c94814dc2245e3.tar.gz
multi_cons macro
Diffstat
-rwxr-xr-xgcl/o/list.d 159
1 files changed, 98 insertions, 61 deletions
diff --git a/gcl/o/list.d b/gcl/o/list.d
index 1b9339954..b7b9bd212 100755
--- a/gcl/o/list.d
+++ b/gcl/o/list.d
@@ -299,59 +299,67 @@ object list_vector_new(int n,object first,va_list ap)
va_end(ap);
return res;
}*/
+#ifdef WIDE_CONS
+#define maybe_set_type_of(a,b) set_type_of(a,b)
+#else
+#define maybe_set_type_of(a,b)
+#endif
+
+
+#define multi_cons(n_,next_,last_) \
+ ({static struct typemanager *_tm=tm_table+t_cons; \
+ object _lis=OBJNULL; \
+ \
+ if (n<=_tm->tm_nfree) { \
+ \
+ object _tail=_tm->tm_free; \
+ \
+ _lis=_tail; \
+ \
+ BEGIN_NO_INTERRUPT; \
+ \
+ _tm->tm_nfree -= n_; \
+ while (--n_) { \
+ pageinfo(_tail)->in_use++; \
+ maybe_set_type_of(_tail,t_cons); \
+ _tail->c.c_cdr=OBJ_LINK(_tail); \
+ _tail->c.c_car=next_; \
+ _tail=_tail->c.c_cdr; \
+ } \
+ _tm->tm_free=OBJ_LINK(_tail); \
+ pageinfo(_tail)->in_use++; \
+ maybe_set_type_of(_tail,t_cons); \
+ _tail->c.c_car=next_; \
+ _tail->c.c_cdr=SAFE_CDR(last_); \
+ \
+ END_NO_INTERRUPT; \
+ } \
+ _lis;})
+
object listqA(int a,int n,va_list ap) {
- struct typemanager *tm=(&tm_table[(int)t_cons]);
- object tail=tm->tm_free,lis=tail;
+ object x,*p;
if (n<=0) return Cnil;
- CHECK_INTERRUPT;
+ if ((x=multi_cons(n,va_arg(ap,object),a ? va_arg(ap,object) : Cnil))!=OBJNULL)
+ return x;
- if (/* stack_alloc_start || */ tm->tm_nfree < n ) {
-
- object *p = vs_top;
-
- vs_push(Cnil);
- while(--n>=0)
- { *p=make_cons(va_arg(ap,object),Cnil);
- p= &((*p)->c.c_cdr);
- }
- if (a)
- *p=SAFE_CDR(va_arg(ap,object));
- return(vs_pop);
+ CHECK_INTERRUPT;
+ p = vs_top;
+
+ vs_push(Cnil);
+ while(--n>=0) {
+ *p=make_cons(va_arg(ap,object),Cnil);
+ p= &((*p)->c.c_cdr);
}
+ if (a)
+ *p=SAFE_CDR(va_arg(ap,object));
-
- {
-
- BEGIN_NO_INTERRUPT;
-
- tm->tm_nfree -= n;
- while (--n) {
- pageinfo(tail)->in_use++;
-#ifdef WIDE_CONS
- set_type_of(tail,t_cons);
-#endif
- tail->c.c_cdr=OBJ_LINK(tail);
- tail->c.c_car=va_arg(ap,object);
- tail=tail->c.c_cdr;
- }
- tm->tm_free=OBJ_LINK(tail);
- pageinfo(tail)->in_use++;
-#ifdef WIDE_CONS
- set_type_of(tail,t_cons);
-#endif
- tail->c.c_car=va_arg(ap,object);
- tail->c.c_cdr=a ? SAFE_CDR(va_arg(ap,object)) : Cnil;
-
- END_NO_INTERRUPT;
- return lis;
-
- }
+ return(vs_pop);
}
@@ -407,27 +415,56 @@ BEGIN:
}
object
-append(x, y)
-object x, y;
-{
- object z;
-
- if (endp(x))
- return(y);
- z = make_cons(Cnil, Cnil);
- vs_push(z);
- for (;;) {
- z->c.c_car = x->c.c_car;
- x = x->c.c_cdr;
- if (endp(x))
- break;
- z->c.c_cdr = make_cons(Cnil, Cnil);
- z = z->c.c_cdr;
- }
- z->c.c_cdr = SAFE_CDR(y);
- return(vs_pop);
+append(object x, object y) {
+
+ object z;
+ fixnum n;
+
+ if (endp(x))
+ return(y);
+
+ for (z=x,n=0;!endp(z);z=z->c.c_cdr,n++);
+ if ((z=multi_cons(n,({object _t=x->c.c_car;x=x->c.c_cdr;_t;}),y))!=OBJNULL)
+ return z;
+
+ z = make_cons(Cnil, Cnil);
+ vs_push(z);
+ for (;;) {
+ z->c.c_car = x->c.c_car;
+ x = x->c.c_cdr;
+ if (endp(x))
+ break;
+ z->c.c_cdr = make_cons(Cnil, Cnil);
+ z = z->c.c_cdr;
+ }
+ z->c.c_cdr = SAFE_CDR(y);
+ return(vs_pop);
}
+
+
+/* object */
+/* append(x, y) */
+/* object x, y; */
+/* { */
+/* object z; */
+
+/* if (endp(x)) */
+/* return(y); */
+/* z = make_cons(Cnil, Cnil); */
+/* vs_push(z); */
+/* for (;;) { */
+/* z->c.c_car = x->c.c_car; */
+/* x = x->c.c_cdr; */
+/* if (endp(x)) */
+/* break; */
+/* z->c.c_cdr = make_cons(Cnil, Cnil); */
+/* z = z->c.c_cdr; */
+/* } */
+/* z->c.c_cdr = SAFE_CDR(y); */
+/* return(vs_pop); */
+/* } */
+
/*
Copy_list(x) copies list x.
*/
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月06日 01:14:12 +0000

AltStyle によって変換されたページ (->オリジナル) /