2 cl.c -- Common Lisp Goodness, the fast version
3 Copyright (C) 2006, 2007 Sebastian Freundt
5 Author: Sebastian Freundt <hroptatyr@sxemacs.org>
7 * This file is part of SXEmacs.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the author nor the names of any contributors
21 * may be used to endorse or promote products derived from this
22 * software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 /* Synched up with: Not in FSF. */
42 #ifdef EMOD_CL_MONOMOD
47 #if !defined EMOD_CL_MONOMOD
48 #define INIT cl_LTX_init
49 #define REINIT cl_LTX_reinit
50 #define DEINIT cl_LTX_deinit
52 #define INIT cl_mono_LTX_init
53 #define REINIT cl_mono_LTX_reinit
54 #define DEINIT cl_mono_LTX_deinit
59 DEFUN("cl:pop", Fcl_pop, 1, UNEVALLED, 0, /*
63 /* This function can GC */
64 Lisp_Object place = XCAR(args);
65 Lisp_Object result = Qnil;
66 struct gcpro gcpro1, gcpro2;
68 GCPRO2(result, place);
72 ls = Fsymbol_value(place);
75 Fset(place, XCDR(ls));
84 DEFUN("cl:push", Fcl_push, 2, UNEVALLED, 0, /*
88 /* This function can GC */
89 Lisp_Object x = XCAR(args);
90 Lisp_Object place = XCAR(XCDR(args));
91 Lisp_Object result = Qnil;
92 struct gcpro gcpro1, gcpro2, gcpro3;
94 GCPRO3(result, x, place);
98 ls = Fsymbol_value(place);
100 Fset(place, (result = Fcons(x, ls)));
108 DEFUN("cl:pushnew", Fcl_pushnew, 2, UNEVALLED, 0, /*
112 /* This function can GC */
113 Lisp_Object x = XCAR(args);
114 Lisp_Object place = XCAR(XCDR(args));
115 Lisp_Object result = Qnil;
116 struct gcpro gcpro1, gcpro2, gcpro3;
118 GCPRO3(result, x, place);
120 if (SYMBOLP(place)) {
122 result = ls = Fsymbol_value(place);
123 if (0) { /* !X_NOT_FOUND_IN_LS_P */
125 Fset(place, (result = Fcons(x, ls)));
133 #define EMOD_CL_EQL(_a, _b) \
134 ((!FLOATP(_a)) ? (EQ((_a), (_b))) : (!NILP(Fequal((_a), (_b)))))
136 int emodcl_eql(Lisp_Object a, Lisp_Object b)
138 return EMOD_CL_EQL(a, b);
142 DEFUN("cl:eql", Fcl_eql, 2, 2, 0, /*
146 if (EMOD_CL_EQL(a, b))
153 DEFUN("cl:list*", Fcl_list_, 1, MANY, 0, /*
155 (int nargs, Lisp_Object *args))
160 Lisp_Object result = args[--nargs];
161 for (; nargs > 0; ) {
162 result = Fcons(args[--nargs], result);
169 DEFUN("cl:tailp", Fcl_tailp, 2, 2, 0, /*
173 Lisp_Object trav1 = Qnil, trav2 = Qnil;
178 trav2 = XCAR(object);
179 for (trav1 = list; CONSP(trav1); trav1 = XCDR(trav1)) {
180 if (EMOD_CL_EQL(XCAR(trav1), trav2))
186 for (trav1 = XCDR(trav1), trav2 = XCDR(object);
187 CONSP(trav1) && CONSP(trav2);
188 trav1 = XCDR(trav1), trav2 = XCDR(trav2)) {
189 if (!EMOD_CL_EQL(XCAR(trav1), XCAR(trav2))) {
193 if (EMOD_CL_EQL(trav1, trav2))
199 for (trav1 = list; CONSP(trav1); trav1 = XCDR(trav1));
200 if (EMOD_CL_EQL(trav1, object))
209 DEFUN("cl:ldiff", Fcl_ldiff, 2, 2, 0, /*
213 Lisp_Object result = Qnil, tmp1 = Qnil, tmp2 = Qnil;
214 Lisp_Object trav1 = Qnil, trav2 = Qnil;
220 trav2 = XCAR(object);
221 for (trav1 = list; CONSP(trav1); trav1 = XCDR(trav1)) {
222 if (EMOD_CL_EQL(XCAR(trav1), trav2))
224 tmp1 = Fcons(XCAR(trav1), tmp1);
226 /* we traversed list and haven't found a match yet */
235 for (trav1 = XCDR(trav1), trav2 = XCDR(object);
236 CONSP(trav1) && CONSP(trav2);
237 trav1 = XCDR(trav1), trav2 = XCDR(trav2)) {
238 if (yes && !EMOD_CL_EQL(XCAR(trav1), XCAR(trav2))) {
242 if (!yes || !EMOD_CL_EQL(trav1, trav2)) {
243 /* if not, just pump the rest */
244 for (trav1 = tmp2; CONSP(trav1); trav1 = XCDR(trav1)) {
245 tmp1 = Fcons(XCAR(trav1), tmp1);
250 for (trav1 = list; CONSP(trav1); trav1 = XCDR(trav1))
251 tmp1 = Fcons(XCAR(trav1), tmp1);
252 if (!EMOD_CL_EQL(trav1, object))
258 for (trav1 = tmp1; CONSP(trav1); trav1 = XCDR(trav1)) {
259 result = Fcons(XCAR(trav1), result);
267 D3FUN("cl:adjoin", Fcl_adjoin, 2, MANY, 0, /*
269 (int nargs, Lisp_Object *args))
276 /* simplified initialiser */
282 DEFSUBR(Fcl_pushnew);
290 #if defined EMOD_CL_MONOMOD
294 Fprovide(intern("cl"));
305 Frevoke(intern("cl"));