1 | /* |
---|
2 | * LispObject.java |
---|
3 | * |
---|
4 | * Copyright (C) 2002-2007 Peter Graves |
---|
5 | * $Id: LispObject.java 14497 2013-05-15 06:42:41Z rschlatte $ |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
20 | * |
---|
21 | * As a special exception, the copyright holders of this library give you |
---|
22 | * permission to link this library with independent modules to produce an |
---|
23 | * executable, regardless of the license terms of these independent |
---|
24 | * modules, and to copy and distribute the resulting executable under |
---|
25 | * terms of your choice, provided that you also meet, for each linked |
---|
26 | * independent module, the terms and conditions of the license of that |
---|
27 | * module. An independent module is a module which is not derived from |
---|
28 | * or based on this library. If you modify this library, you may extend |
---|
29 | * this exception to your version of the library, but you are not |
---|
30 | * obligated to do so. If you do not wish to do so, delete this |
---|
31 | * exception statement from your version. |
---|
32 | */ |
---|
33 | |
---|
34 | package org.armedbear.lisp; |
---|
35 | |
---|
36 | import static org.armedbear.lisp.Lisp.*; |
---|
37 | import java.util.WeakHashMap; |
---|
38 | |
---|
39 | public class LispObject //extends Lisp |
---|
40 | { |
---|
41 | |
---|
42 | /** Function to allow objects to return the value |
---|
43 | * "they stand for". Used by AutoloadedFunctionProxy to return |
---|
44 | * the function it is proxying. |
---|
45 | */ |
---|
46 | public LispObject resolve() |
---|
47 | { |
---|
48 | return this; |
---|
49 | } |
---|
50 | |
---|
51 | public LispObject typeOf() |
---|
52 | { |
---|
53 | return T; |
---|
54 | } |
---|
55 | |
---|
56 | static public LispObject getInstance(boolean b) { |
---|
57 | return b ? T : NIL; |
---|
58 | } |
---|
59 | |
---|
60 | public LispObject classOf() |
---|
61 | { |
---|
62 | return BuiltInClass.CLASS_T; |
---|
63 | } |
---|
64 | |
---|
65 | public LispObject getDescription() |
---|
66 | { |
---|
67 | StringBuilder sb = new StringBuilder("An object of type "); |
---|
68 | sb.append(typeOf().princToString()); |
---|
69 | sb.append(" at #x"); |
---|
70 | sb.append(Integer.toHexString(System.identityHashCode(this)).toUpperCase()); |
---|
71 | return new SimpleString(sb); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * Implementing the getParts() protocol will allow INSPECT to |
---|
76 | * return information about the substructure of a descendent of |
---|
77 | * LispObject. |
---|
78 | * |
---|
79 | * The protocol is to return a List of Cons pairs, where the car of |
---|
80 | * each pair contains a decriptive string, and the cdr returns a |
---|
81 | * subobject for inspection. |
---|
82 | */ |
---|
83 | public LispObject getParts() |
---|
84 | { |
---|
85 | return NIL; |
---|
86 | } |
---|
87 | |
---|
88 | public boolean getBooleanValue() |
---|
89 | { |
---|
90 | return true; |
---|
91 | } |
---|
92 | |
---|
93 | public LispObject typep(LispObject typeSpecifier) |
---|
94 | { |
---|
95 | if (typeSpecifier == T) |
---|
96 | return T; |
---|
97 | if (typeSpecifier == BuiltInClass.CLASS_T) |
---|
98 | return T; |
---|
99 | if (typeSpecifier == Symbol.ATOM) |
---|
100 | return T; |
---|
101 | return NIL; |
---|
102 | } |
---|
103 | |
---|
104 | public boolean constantp() |
---|
105 | { |
---|
106 | return true; |
---|
107 | } |
---|
108 | |
---|
109 | public final LispObject CONSTANTP() |
---|
110 | { |
---|
111 | return constantp() ? T : NIL; |
---|
112 | } |
---|
113 | |
---|
114 | public final LispObject ATOM() |
---|
115 | { |
---|
116 | return atom() ? T : NIL; |
---|
117 | } |
---|
118 | |
---|
119 | public boolean atom() |
---|
120 | { |
---|
121 | return true; |
---|
122 | } |
---|
123 | |
---|
124 | public Object javaInstance() |
---|
125 | { |
---|
126 | return this; |
---|
127 | } |
---|
128 | |
---|
129 | public Object javaInstance(Class<?> c) |
---|
130 | { |
---|
131 | if (c.isAssignableFrom(getClass())) |
---|
132 | return this; |
---|
133 | return error(new LispError("The value " + princToString() + |
---|
134 | " is not of class " + c.getName())); |
---|
135 | } |
---|
136 | |
---|
137 | /** This method returns 'this' by default, but allows |
---|
138 | * objects to return different values to increase Java |
---|
139 | * interoperability |
---|
140 | * |
---|
141 | * @return An object to be used with synchronized, wait, notify, etc |
---|
142 | */ |
---|
143 | public Object lockableInstance() |
---|
144 | { |
---|
145 | return this; |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | public final LispObject car() |
---|
150 | { |
---|
151 | if (this instanceof Cons) { |
---|
152 | return ((Cons)this).car; |
---|
153 | } else if (this instanceof Nil) { |
---|
154 | return NIL; |
---|
155 | } |
---|
156 | return type_error(this, Symbol.LIST); |
---|
157 | } |
---|
158 | |
---|
159 | public final void setCar(LispObject obj) |
---|
160 | { |
---|
161 | if (this instanceof Cons) { |
---|
162 | ((Cons)this).car = obj; |
---|
163 | return; |
---|
164 | } |
---|
165 | type_error(this, Symbol.CONS); |
---|
166 | } |
---|
167 | |
---|
168 | public LispObject RPLACA(LispObject obj) |
---|
169 | { |
---|
170 | return type_error(this, Symbol.CONS); |
---|
171 | } |
---|
172 | |
---|
173 | public final LispObject cdr() |
---|
174 | { |
---|
175 | if (this instanceof Cons) { |
---|
176 | return ((Cons)this).cdr; |
---|
177 | } else if (this instanceof Nil) { |
---|
178 | return NIL; |
---|
179 | } |
---|
180 | return type_error(this, Symbol.LIST); |
---|
181 | } |
---|
182 | |
---|
183 | public final void setCdr(LispObject obj) |
---|
184 | { |
---|
185 | if (this instanceof Cons) { |
---|
186 | ((Cons)this).cdr = obj; |
---|
187 | return; |
---|
188 | } |
---|
189 | |
---|
190 | type_error(this, Symbol.CONS); |
---|
191 | } |
---|
192 | |
---|
193 | public LispObject RPLACD(LispObject obj) |
---|
194 | { |
---|
195 | return type_error(this, Symbol.CONS); |
---|
196 | } |
---|
197 | |
---|
198 | public final LispObject cadr() |
---|
199 | { |
---|
200 | LispObject tail = cdr(); |
---|
201 | if (!(tail instanceof Nil)) { |
---|
202 | return tail.car(); |
---|
203 | } else |
---|
204 | return NIL; |
---|
205 | } |
---|
206 | |
---|
207 | public final LispObject cddr() |
---|
208 | { |
---|
209 | LispObject tail = cdr(); |
---|
210 | if (!(tail instanceof Nil)) { |
---|
211 | return tail.cdr(); |
---|
212 | } else |
---|
213 | return NIL; |
---|
214 | } |
---|
215 | |
---|
216 | public final LispObject caddr() |
---|
217 | { |
---|
218 | LispObject tail = cddr(); |
---|
219 | if (!(tail instanceof Nil)) { |
---|
220 | return tail.car(); |
---|
221 | } else |
---|
222 | return NIL; |
---|
223 | } |
---|
224 | |
---|
225 | public final LispObject nthcdr(int n) |
---|
226 | { |
---|
227 | if (n < 0) |
---|
228 | return type_error(Fixnum.getInstance(n), |
---|
229 | list(Symbol.INTEGER, Fixnum.ZERO)); |
---|
230 | if (this instanceof Cons) { |
---|
231 | LispObject result = this; |
---|
232 | for (int i = n; i-- > 0;) { |
---|
233 | result = result.cdr(); |
---|
234 | if (result == NIL) |
---|
235 | break; |
---|
236 | } |
---|
237 | return result; |
---|
238 | } else if (this instanceof Nil) { |
---|
239 | return NIL; |
---|
240 | } |
---|
241 | return type_error(this, Symbol.LIST); |
---|
242 | } |
---|
243 | |
---|
244 | public final LispObject push(LispObject obj) |
---|
245 | { |
---|
246 | if (this instanceof Cons) { |
---|
247 | return new Cons(obj, this); |
---|
248 | } else if (this instanceof Nil) { |
---|
249 | return new Cons(obj); |
---|
250 | } |
---|
251 | return type_error(this, Symbol.LIST); |
---|
252 | } |
---|
253 | |
---|
254 | final public LispObject EQ(LispObject obj) |
---|
255 | { |
---|
256 | return this == obj ? T : NIL; |
---|
257 | } |
---|
258 | |
---|
259 | public boolean eql(char c) |
---|
260 | { |
---|
261 | return false; |
---|
262 | } |
---|
263 | |
---|
264 | public boolean eql(int n) |
---|
265 | { |
---|
266 | return false; |
---|
267 | } |
---|
268 | |
---|
269 | public boolean eql(LispObject obj) |
---|
270 | { |
---|
271 | return this == obj; |
---|
272 | } |
---|
273 | |
---|
274 | public final LispObject EQL(LispObject obj) |
---|
275 | { |
---|
276 | return eql(obj) ? T : NIL; |
---|
277 | } |
---|
278 | |
---|
279 | public final LispObject EQUAL(LispObject obj) |
---|
280 | { |
---|
281 | return equal(obj) ? T : NIL; |
---|
282 | } |
---|
283 | |
---|
284 | public boolean equal(int n) |
---|
285 | { |
---|
286 | return false; |
---|
287 | } |
---|
288 | |
---|
289 | public boolean equal(LispObject obj) |
---|
290 | { |
---|
291 | return this == obj; |
---|
292 | } |
---|
293 | |
---|
294 | public boolean equalp(int n) |
---|
295 | { |
---|
296 | return false; |
---|
297 | } |
---|
298 | |
---|
299 | public boolean equalp(LispObject obj) |
---|
300 | { |
---|
301 | return this == obj; |
---|
302 | } |
---|
303 | |
---|
304 | public LispObject ABS() |
---|
305 | { |
---|
306 | return type_error(this, Symbol.NUMBER); |
---|
307 | } |
---|
308 | |
---|
309 | public LispObject NUMERATOR() |
---|
310 | { |
---|
311 | return type_error(this, Symbol.RATIONAL); |
---|
312 | } |
---|
313 | |
---|
314 | public LispObject DENOMINATOR() |
---|
315 | { |
---|
316 | return type_error(this, Symbol.RATIONAL); |
---|
317 | } |
---|
318 | |
---|
319 | public final LispObject EVENP() |
---|
320 | { |
---|
321 | return evenp() ? T : NIL; |
---|
322 | } |
---|
323 | |
---|
324 | public boolean evenp() |
---|
325 | { |
---|
326 | type_error(this, Symbol.INTEGER); |
---|
327 | // Not reached. |
---|
328 | return false; |
---|
329 | } |
---|
330 | |
---|
331 | public final LispObject ODDP() |
---|
332 | { |
---|
333 | return oddp() ? T : NIL; |
---|
334 | } |
---|
335 | |
---|
336 | public boolean oddp() |
---|
337 | { |
---|
338 | type_error(this, Symbol.INTEGER); |
---|
339 | // Not reached. |
---|
340 | return false; |
---|
341 | } |
---|
342 | |
---|
343 | public final LispObject PLUSP() |
---|
344 | { |
---|
345 | return plusp() ? T : NIL; |
---|
346 | } |
---|
347 | |
---|
348 | public boolean plusp() |
---|
349 | { |
---|
350 | type_error(this, Symbol.REAL); |
---|
351 | // Not reached. |
---|
352 | return false; |
---|
353 | } |
---|
354 | |
---|
355 | public final LispObject MINUSP() |
---|
356 | { |
---|
357 | return minusp() ? T : NIL; |
---|
358 | } |
---|
359 | |
---|
360 | public boolean minusp() |
---|
361 | { |
---|
362 | type_error(this, Symbol.REAL); |
---|
363 | // Not reached. |
---|
364 | return false; |
---|
365 | } |
---|
366 | |
---|
367 | public final LispObject NUMBERP() |
---|
368 | { |
---|
369 | return numberp() ? T : NIL; |
---|
370 | } |
---|
371 | |
---|
372 | public boolean numberp() |
---|
373 | { |
---|
374 | return false; |
---|
375 | } |
---|
376 | |
---|
377 | public final LispObject ZEROP() |
---|
378 | { |
---|
379 | return zerop() ? T : NIL; |
---|
380 | } |
---|
381 | |
---|
382 | public boolean zerop() |
---|
383 | { |
---|
384 | type_error(this, Symbol.NUMBER); |
---|
385 | // Not reached. |
---|
386 | return false; |
---|
387 | } |
---|
388 | |
---|
389 | public LispObject COMPLEXP() |
---|
390 | { |
---|
391 | return NIL; |
---|
392 | } |
---|
393 | |
---|
394 | public final LispObject FLOATP() |
---|
395 | { |
---|
396 | return floatp() ? T : NIL; |
---|
397 | } |
---|
398 | |
---|
399 | public boolean floatp() |
---|
400 | { |
---|
401 | return false; |
---|
402 | } |
---|
403 | |
---|
404 | public final LispObject INTEGERP() |
---|
405 | { |
---|
406 | return integerp() ? T : NIL; |
---|
407 | } |
---|
408 | |
---|
409 | public boolean integerp() |
---|
410 | { |
---|
411 | return false; |
---|
412 | } |
---|
413 | |
---|
414 | public final LispObject RATIONALP() |
---|
415 | { |
---|
416 | return rationalp() ? T : NIL; |
---|
417 | } |
---|
418 | |
---|
419 | public boolean rationalp() |
---|
420 | { |
---|
421 | return false; |
---|
422 | } |
---|
423 | |
---|
424 | public final LispObject REALP() |
---|
425 | { |
---|
426 | return realp() ? T : NIL; |
---|
427 | } |
---|
428 | |
---|
429 | public boolean realp() |
---|
430 | { |
---|
431 | return false; |
---|
432 | } |
---|
433 | |
---|
434 | public final LispObject STRINGP() |
---|
435 | { |
---|
436 | return stringp() ? T : NIL; |
---|
437 | } |
---|
438 | |
---|
439 | public boolean stringp() |
---|
440 | { |
---|
441 | return false; |
---|
442 | } |
---|
443 | |
---|
444 | public LispObject SIMPLE_STRING_P() |
---|
445 | { |
---|
446 | return NIL; |
---|
447 | } |
---|
448 | |
---|
449 | public final LispObject VECTORP() |
---|
450 | { |
---|
451 | return vectorp() ? T : NIL; |
---|
452 | } |
---|
453 | |
---|
454 | public boolean vectorp() |
---|
455 | { |
---|
456 | return false; |
---|
457 | } |
---|
458 | |
---|
459 | public final LispObject CHARACTERP() |
---|
460 | { |
---|
461 | return characterp() ? T : NIL; |
---|
462 | } |
---|
463 | |
---|
464 | public boolean characterp() |
---|
465 | { |
---|
466 | return false; |
---|
467 | } |
---|
468 | |
---|
469 | public int length() |
---|
470 | { |
---|
471 | type_error(this, Symbol.SEQUENCE); |
---|
472 | // Not reached. |
---|
473 | return 0; |
---|
474 | } |
---|
475 | |
---|
476 | public final LispObject LENGTH() |
---|
477 | { |
---|
478 | return Fixnum.getInstance(length()); |
---|
479 | } |
---|
480 | |
---|
481 | public LispObject CHAR(int index) |
---|
482 | { |
---|
483 | return type_error(this, Symbol.STRING); |
---|
484 | } |
---|
485 | |
---|
486 | public LispObject SCHAR(int index) |
---|
487 | { |
---|
488 | return type_error(this, Symbol.SIMPLE_STRING); |
---|
489 | } |
---|
490 | |
---|
491 | public LispObject NTH(int index) |
---|
492 | { |
---|
493 | return type_error(this, Symbol.LIST); |
---|
494 | } |
---|
495 | |
---|
496 | public final LispObject NTH(LispObject arg) |
---|
497 | { |
---|
498 | return NTH(Fixnum.getValue(arg)); |
---|
499 | } |
---|
500 | |
---|
501 | public LispObject elt(int index) |
---|
502 | { |
---|
503 | return type_error(this, Symbol.SEQUENCE); |
---|
504 | } |
---|
505 | |
---|
506 | public LispObject reverse() |
---|
507 | { |
---|
508 | return type_error(this, Symbol.SEQUENCE); |
---|
509 | } |
---|
510 | |
---|
511 | public LispObject nreverse() |
---|
512 | { |
---|
513 | return type_error(this, Symbol.SEQUENCE); |
---|
514 | } |
---|
515 | |
---|
516 | public long aref_long(int index) |
---|
517 | { |
---|
518 | return AREF(index).longValue(); |
---|
519 | } |
---|
520 | |
---|
521 | public int aref(int index) |
---|
522 | { |
---|
523 | return AREF(index).intValue(); |
---|
524 | } |
---|
525 | |
---|
526 | public LispObject AREF(int index) |
---|
527 | { |
---|
528 | return type_error(this, Symbol.ARRAY); |
---|
529 | } |
---|
530 | |
---|
531 | public final LispObject AREF(LispObject index) |
---|
532 | { |
---|
533 | return AREF(Fixnum.getValue(index)); |
---|
534 | } |
---|
535 | |
---|
536 | public void aset(int index, int n) |
---|
537 | |
---|
538 | { |
---|
539 | aset(index, Fixnum.getInstance(n)); |
---|
540 | } |
---|
541 | |
---|
542 | public void aset(int index, LispObject newValue) |
---|
543 | |
---|
544 | { |
---|
545 | type_error(this, Symbol.ARRAY); |
---|
546 | } |
---|
547 | |
---|
548 | public final void aset(LispObject index, LispObject newValue) |
---|
549 | |
---|
550 | { |
---|
551 | aset(Fixnum.getValue(index), newValue); |
---|
552 | } |
---|
553 | |
---|
554 | public LispObject SVREF(int index) |
---|
555 | { |
---|
556 | return type_error(this, Symbol.SIMPLE_VECTOR); |
---|
557 | } |
---|
558 | |
---|
559 | public void svset(int index, LispObject newValue) |
---|
560 | { |
---|
561 | type_error(this, Symbol.SIMPLE_VECTOR); |
---|
562 | } |
---|
563 | |
---|
564 | public void vectorPushExtend(LispObject element) |
---|
565 | |
---|
566 | { |
---|
567 | noFillPointer(); |
---|
568 | } |
---|
569 | |
---|
570 | public LispObject VECTOR_PUSH_EXTEND(LispObject element) |
---|
571 | |
---|
572 | { |
---|
573 | return noFillPointer(); |
---|
574 | } |
---|
575 | |
---|
576 | public LispObject VECTOR_PUSH_EXTEND(LispObject element, LispObject extension) |
---|
577 | |
---|
578 | { |
---|
579 | return noFillPointer(); |
---|
580 | } |
---|
581 | |
---|
582 | public final LispObject noFillPointer() |
---|
583 | { |
---|
584 | return type_error(this, list(Symbol.AND, Symbol.VECTOR, |
---|
585 | list(Symbol.SATISFIES, |
---|
586 | Symbol.ARRAY_HAS_FILL_POINTER_P))); |
---|
587 | } |
---|
588 | |
---|
589 | public LispObject[] copyToArray() |
---|
590 | { |
---|
591 | type_error(this, Symbol.LIST); |
---|
592 | // Not reached. |
---|
593 | return null; |
---|
594 | } |
---|
595 | |
---|
596 | public final LispObject SYMBOLP() |
---|
597 | { |
---|
598 | return (this instanceof Symbol) ? T : NIL; |
---|
599 | } |
---|
600 | |
---|
601 | public final boolean listp() |
---|
602 | { |
---|
603 | return (this instanceof Cons) || (this instanceof Nil); |
---|
604 | } |
---|
605 | |
---|
606 | public final LispObject LISTP() |
---|
607 | { |
---|
608 | return listp() ? T : NIL; |
---|
609 | } |
---|
610 | |
---|
611 | public final boolean endp() |
---|
612 | { |
---|
613 | if (this instanceof Cons) |
---|
614 | return false; |
---|
615 | else if (this instanceof Nil) |
---|
616 | return true; |
---|
617 | type_error(this, Symbol.LIST); |
---|
618 | // Not reached. |
---|
619 | return false; |
---|
620 | } |
---|
621 | |
---|
622 | public final LispObject ENDP() |
---|
623 | { |
---|
624 | return endp() ? T : NIL; |
---|
625 | } |
---|
626 | |
---|
627 | public LispObject NOT() |
---|
628 | { |
---|
629 | return NIL; |
---|
630 | } |
---|
631 | |
---|
632 | public boolean isSpecialOperator() |
---|
633 | { |
---|
634 | type_error(this, Symbol.SYMBOL); |
---|
635 | // Not reached. |
---|
636 | return false; |
---|
637 | } |
---|
638 | |
---|
639 | public boolean isSpecialVariable() |
---|
640 | { |
---|
641 | return false; |
---|
642 | } |
---|
643 | |
---|
644 | private static final WeakHashMap<LispObject, LispObject> |
---|
645 | documentationHashTable = new WeakHashMap<LispObject, LispObject>(); |
---|
646 | |
---|
647 | public LispObject getDocumentation(LispObject docType) |
---|
648 | |
---|
649 | { |
---|
650 | LispObject alist; |
---|
651 | synchronized (documentationHashTable) { |
---|
652 | alist = documentationHashTable.get(this); |
---|
653 | } |
---|
654 | if (alist != null) |
---|
655 | { |
---|
656 | LispObject entry = assq(docType, alist); |
---|
657 | if (entry instanceof Cons) |
---|
658 | return ((Cons)entry).cdr; |
---|
659 | } |
---|
660 | if(docType == Symbol.FUNCTION && this instanceof Symbol) { |
---|
661 | LispObject fn = ((Symbol)this).getSymbolFunction(); |
---|
662 | if(fn instanceof Function) { |
---|
663 | DocString ds = fn.getClass().getAnnotation(DocString.class); |
---|
664 | if(ds != null) { |
---|
665 | String arglist = ds.args(); |
---|
666 | String docstring = ds.doc(); |
---|
667 | if(arglist.length() != 0) |
---|
668 | ((Function)fn).setLambdaList(new SimpleString(arglist)); |
---|
669 | if(docstring.length() != 0) { |
---|
670 | SimpleString doc = new SimpleString(docstring); |
---|
671 | ((Symbol)this).setDocumentation(Symbol.FUNCTION, doc); |
---|
672 | return doc; |
---|
673 | } else if (fn.typep(Symbol.STANDARD_GENERIC_FUNCTION) != NIL) { |
---|
674 | return Symbol.SLOT_VALUE.execute(fn, Symbol._DOCUMENTATION); |
---|
675 | } |
---|
676 | } |
---|
677 | } |
---|
678 | } |
---|
679 | return NIL; |
---|
680 | } |
---|
681 | |
---|
682 | public void setDocumentation(LispObject docType, LispObject documentation) |
---|
683 | |
---|
684 | { |
---|
685 | synchronized (documentationHashTable) { |
---|
686 | LispObject alist = documentationHashTable.get(this); |
---|
687 | if (alist == null) |
---|
688 | alist = NIL; |
---|
689 | LispObject entry = assq(docType, alist); |
---|
690 | if (entry instanceof Cons) |
---|
691 | { |
---|
692 | ((Cons)entry).cdr = documentation; |
---|
693 | } |
---|
694 | else |
---|
695 | { |
---|
696 | alist = alist.push(new Cons(docType, documentation)); |
---|
697 | documentationHashTable.put(this, alist); |
---|
698 | } |
---|
699 | } |
---|
700 | } |
---|
701 | |
---|
702 | public LispObject getPropertyList() |
---|
703 | { |
---|
704 | return null; |
---|
705 | } |
---|
706 | |
---|
707 | public void setPropertyList(LispObject obj) |
---|
708 | { |
---|
709 | } |
---|
710 | |
---|
711 | public LispObject getSymbolValue() |
---|
712 | { |
---|
713 | return type_error(this, Symbol.SYMBOL); |
---|
714 | } |
---|
715 | |
---|
716 | public LispObject getSymbolFunction() |
---|
717 | { |
---|
718 | return type_error(this, Symbol.SYMBOL); |
---|
719 | } |
---|
720 | |
---|
721 | public LispObject getSymbolFunctionOrDie() |
---|
722 | { |
---|
723 | return type_error(this, Symbol.SYMBOL); |
---|
724 | } |
---|
725 | |
---|
726 | public LispObject getSymbolSetfFunction() |
---|
727 | { |
---|
728 | return type_error(this, Symbol.SYMBOL); |
---|
729 | } |
---|
730 | |
---|
731 | public LispObject getSymbolSetfFunctionOrDie() |
---|
732 | { |
---|
733 | return type_error(this, Symbol.SYMBOL); |
---|
734 | } |
---|
735 | |
---|
736 | /** PRINC-TO-STRING function to be used with Java objects |
---|
737 | * |
---|
738 | * @return A string in human-readable format, as per PRINC definition |
---|
739 | */ |
---|
740 | public String princToString() |
---|
741 | { |
---|
742 | LispThread thread = LispThread.currentThread(); |
---|
743 | SpecialBindingsMark mark = thread.markSpecialBindings(); |
---|
744 | try { |
---|
745 | thread.bindSpecial(Symbol.PRINT_READABLY, NIL); |
---|
746 | thread.bindSpecial(Symbol.PRINT_ESCAPE, NIL); |
---|
747 | return printObject(); |
---|
748 | } |
---|
749 | finally { |
---|
750 | thread.resetSpecialBindings(mark); |
---|
751 | } |
---|
752 | } |
---|
753 | |
---|
754 | public String printObject() |
---|
755 | { |
---|
756 | return unreadableString(toString(), false); |
---|
757 | } |
---|
758 | |
---|
759 | /** Calls unreadableString(String s, boolean identity) with a default |
---|
760 | * identity value of 'true'. |
---|
761 | * |
---|
762 | * This function is a helper for printObject() |
---|
763 | * |
---|
764 | * @param s String representation of this object. |
---|
765 | * @return String enclosed in the non-readable #< ... > markers |
---|
766 | */ |
---|
767 | public final String unreadableString(String s) { |
---|
768 | return unreadableString(s, true); |
---|
769 | } |
---|
770 | |
---|
771 | /** Creates a non-readably (as per CLHS terminology) representation |
---|
772 | * of the 'this' object, using string 's'. |
---|
773 | * |
---|
774 | * If the current value of the variable *PRINT-READABLY* is T, a |
---|
775 | * Lisp error is thrown and no value is returned. |
---|
776 | * |
---|
777 | * This function is a helper for printObject() |
---|
778 | * |
---|
779 | * @param s |
---|
780 | * @param identity when 'true', includes Java's identityHash for the object |
---|
781 | * in the output. |
---|
782 | * @return a non reabable string (i.e. one enclosed in the #< > markers) |
---|
783 | */ |
---|
784 | public final String unreadableString(String s, boolean identity) |
---|
785 | { |
---|
786 | if (Symbol.PRINT_READABLY.symbolValue() != NIL) { |
---|
787 | error(new PrintNotReadable(list(Keyword.OBJECT, this))); |
---|
788 | return null; // not reached |
---|
789 | } |
---|
790 | StringBuilder sb = new StringBuilder("#<"); |
---|
791 | sb.append(s); |
---|
792 | if (identity) { |
---|
793 | sb.append(" {"); |
---|
794 | sb.append(Integer.toHexString(System.identityHashCode(this)).toUpperCase()); |
---|
795 | sb.append("}"); |
---|
796 | } |
---|
797 | sb.append(">"); |
---|
798 | return sb.toString(); |
---|
799 | } |
---|
800 | |
---|
801 | // Special operator |
---|
802 | public LispObject execute(LispObject args, Environment env) |
---|
803 | |
---|
804 | { |
---|
805 | return error(new LispError()); |
---|
806 | } |
---|
807 | |
---|
808 | public LispObject execute() |
---|
809 | { |
---|
810 | return type_error(this, Symbol.FUNCTION); |
---|
811 | } |
---|
812 | |
---|
813 | public LispObject execute(LispObject arg) |
---|
814 | { |
---|
815 | return type_error(this, Symbol.FUNCTION); |
---|
816 | } |
---|
817 | |
---|
818 | public LispObject execute(LispObject first, LispObject second) |
---|
819 | |
---|
820 | { |
---|
821 | return type_error(this, Symbol.FUNCTION); |
---|
822 | } |
---|
823 | |
---|
824 | public LispObject execute(LispObject first, LispObject second, |
---|
825 | LispObject third) |
---|
826 | |
---|
827 | { |
---|
828 | return type_error(this, Symbol.FUNCTION); |
---|
829 | } |
---|
830 | |
---|
831 | public LispObject execute(LispObject first, LispObject second, |
---|
832 | LispObject third, LispObject fourth) |
---|
833 | |
---|
834 | { |
---|
835 | return type_error(this, Symbol.FUNCTION); |
---|
836 | } |
---|
837 | |
---|
838 | public LispObject execute(LispObject first, LispObject second, |
---|
839 | LispObject third, LispObject fourth, |
---|
840 | LispObject fifth) |
---|
841 | |
---|
842 | { |
---|
843 | return type_error(this, Symbol.FUNCTION); |
---|
844 | } |
---|
845 | |
---|
846 | public LispObject execute(LispObject first, LispObject second, |
---|
847 | LispObject third, LispObject fourth, |
---|
848 | LispObject fifth, LispObject sixth) |
---|
849 | |
---|
850 | { |
---|
851 | return type_error(this, Symbol.FUNCTION); |
---|
852 | } |
---|
853 | |
---|
854 | public LispObject execute(LispObject first, LispObject second, |
---|
855 | LispObject third, LispObject fourth, |
---|
856 | LispObject fifth, LispObject sixth, |
---|
857 | LispObject seventh) |
---|
858 | |
---|
859 | { |
---|
860 | return type_error(this, Symbol.FUNCTION); |
---|
861 | } |
---|
862 | |
---|
863 | public LispObject execute(LispObject first, LispObject second, |
---|
864 | LispObject third, LispObject fourth, |
---|
865 | LispObject fifth, LispObject sixth, |
---|
866 | LispObject seventh, LispObject eighth) |
---|
867 | |
---|
868 | { |
---|
869 | return type_error(this, Symbol.FUNCTION); |
---|
870 | } |
---|
871 | |
---|
872 | public LispObject execute(LispObject[] args) |
---|
873 | { |
---|
874 | return type_error(this, Symbol.FUNCTION); |
---|
875 | } |
---|
876 | |
---|
877 | // Used by COMPILE-MULTIPLE-VALUE-CALL. |
---|
878 | public LispObject dispatch(LispObject[] args) |
---|
879 | { |
---|
880 | switch (args.length) |
---|
881 | { |
---|
882 | case 0: |
---|
883 | return execute(); |
---|
884 | case 1: |
---|
885 | return execute(args[0]); |
---|
886 | case 2: |
---|
887 | return execute(args[0], args[1]); |
---|
888 | case 3: |
---|
889 | return execute(args[0], args[1], args[2]); |
---|
890 | case 4: |
---|
891 | return execute(args[0], args[1], args[2], args[3]); |
---|
892 | case 5: |
---|
893 | return execute(args[0], args[1], args[2], args[3], args[4]); |
---|
894 | case 6: |
---|
895 | return execute(args[0], args[1], args[2], args[3], args[4], |
---|
896 | args[5]); |
---|
897 | case 7: |
---|
898 | return execute(args[0], args[1], args[2], args[3], args[4], |
---|
899 | args[5], args[6]); |
---|
900 | case 8: |
---|
901 | return execute(args[0], args[1], args[2], args[3], args[4], |
---|
902 | args[5], args[6], args[7]); |
---|
903 | default: |
---|
904 | return execute(args); |
---|
905 | } |
---|
906 | } |
---|
907 | |
---|
908 | public int intValue() |
---|
909 | { |
---|
910 | type_error(this, Symbol.INTEGER); |
---|
911 | // Not reached. |
---|
912 | return 0; |
---|
913 | } |
---|
914 | |
---|
915 | public long longValue() |
---|
916 | { |
---|
917 | type_error(this, Symbol.INTEGER); |
---|
918 | // Not reached. |
---|
919 | return 0; |
---|
920 | } |
---|
921 | |
---|
922 | public float floatValue() |
---|
923 | { |
---|
924 | type_error(this, Symbol.SINGLE_FLOAT); |
---|
925 | // Not reached |
---|
926 | return 0; |
---|
927 | } |
---|
928 | |
---|
929 | public double doubleValue() |
---|
930 | { |
---|
931 | type_error(this, Symbol.DOUBLE_FLOAT); |
---|
932 | // Not reached |
---|
933 | return 0; |
---|
934 | } |
---|
935 | |
---|
936 | public LispObject incr() |
---|
937 | { |
---|
938 | return type_error(this, Symbol.NUMBER); |
---|
939 | } |
---|
940 | |
---|
941 | public LispObject decr() |
---|
942 | { |
---|
943 | return type_error(this, Symbol.NUMBER); |
---|
944 | } |
---|
945 | |
---|
946 | public LispObject negate() |
---|
947 | { |
---|
948 | return Fixnum.ZERO.subtract(this); |
---|
949 | } |
---|
950 | |
---|
951 | public LispObject add(int n) |
---|
952 | { |
---|
953 | return add(Fixnum.getInstance(n)); |
---|
954 | } |
---|
955 | |
---|
956 | public LispObject add(LispObject obj) |
---|
957 | { |
---|
958 | return type_error(this, Symbol.NUMBER); |
---|
959 | } |
---|
960 | |
---|
961 | public LispObject subtract(int n) |
---|
962 | { |
---|
963 | return subtract(Fixnum.getInstance(n)); |
---|
964 | } |
---|
965 | |
---|
966 | public LispObject subtract(LispObject obj) |
---|
967 | { |
---|
968 | return type_error(this, Symbol.NUMBER); |
---|
969 | } |
---|
970 | |
---|
971 | public LispObject multiplyBy(int n) |
---|
972 | { |
---|
973 | return multiplyBy(Fixnum.getInstance(n)); |
---|
974 | } |
---|
975 | |
---|
976 | public LispObject multiplyBy(LispObject obj) |
---|
977 | { |
---|
978 | return type_error(this, Symbol.NUMBER); |
---|
979 | } |
---|
980 | |
---|
981 | public LispObject divideBy(LispObject obj) |
---|
982 | { |
---|
983 | return type_error(this, Symbol.NUMBER); |
---|
984 | } |
---|
985 | |
---|
986 | public boolean isEqualTo(int n) |
---|
987 | { |
---|
988 | return isEqualTo(Fixnum.getInstance(n)); |
---|
989 | } |
---|
990 | |
---|
991 | public boolean isEqualTo(LispObject obj) |
---|
992 | { |
---|
993 | type_error(this, Symbol.NUMBER); |
---|
994 | // Not reached. |
---|
995 | return false; |
---|
996 | } |
---|
997 | |
---|
998 | public final LispObject IS_E(LispObject obj) |
---|
999 | { |
---|
1000 | return isEqualTo(obj) ? T : NIL; |
---|
1001 | } |
---|
1002 | |
---|
1003 | public boolean isNotEqualTo(int n) |
---|
1004 | { |
---|
1005 | return isNotEqualTo(Fixnum.getInstance(n)); |
---|
1006 | } |
---|
1007 | |
---|
1008 | public boolean isNotEqualTo(LispObject obj) |
---|
1009 | { |
---|
1010 | type_error(this, Symbol.NUMBER); |
---|
1011 | // Not reached. |
---|
1012 | return false; |
---|
1013 | } |
---|
1014 | |
---|
1015 | public final LispObject IS_NE(LispObject obj) |
---|
1016 | { |
---|
1017 | return isNotEqualTo(obj) ? T : NIL; |
---|
1018 | } |
---|
1019 | |
---|
1020 | public boolean isLessThan(int n) |
---|
1021 | { |
---|
1022 | return isLessThan(Fixnum.getInstance(n)); |
---|
1023 | } |
---|
1024 | |
---|
1025 | public boolean isLessThan(LispObject obj) |
---|
1026 | { |
---|
1027 | type_error(this, Symbol.REAL); |
---|
1028 | // Not reached. |
---|
1029 | return false; |
---|
1030 | } |
---|
1031 | |
---|
1032 | public final LispObject IS_LT(LispObject obj) |
---|
1033 | { |
---|
1034 | return isLessThan(obj) ? T : NIL; |
---|
1035 | } |
---|
1036 | |
---|
1037 | public boolean isGreaterThan(int n) |
---|
1038 | { |
---|
1039 | return isGreaterThan(Fixnum.getInstance(n)); |
---|
1040 | } |
---|
1041 | |
---|
1042 | public boolean isGreaterThan(LispObject obj) |
---|
1043 | { |
---|
1044 | type_error(this, Symbol.REAL); |
---|
1045 | // Not reached. |
---|
1046 | return false; |
---|
1047 | } |
---|
1048 | |
---|
1049 | public final LispObject IS_GT(LispObject obj) |
---|
1050 | { |
---|
1051 | return isGreaterThan(obj) ? T : NIL; |
---|
1052 | } |
---|
1053 | |
---|
1054 | public boolean isLessThanOrEqualTo(int n) |
---|
1055 | { |
---|
1056 | return isLessThanOrEqualTo(Fixnum.getInstance(n)); |
---|
1057 | } |
---|
1058 | |
---|
1059 | public boolean isLessThanOrEqualTo(LispObject obj) |
---|
1060 | { |
---|
1061 | type_error(this, Symbol.REAL); |
---|
1062 | // Not reached. |
---|
1063 | return false; |
---|
1064 | } |
---|
1065 | |
---|
1066 | public final LispObject IS_LE(LispObject obj) |
---|
1067 | { |
---|
1068 | return isLessThanOrEqualTo(obj) ? T : NIL; |
---|
1069 | } |
---|
1070 | |
---|
1071 | public boolean isGreaterThanOrEqualTo(int n) |
---|
1072 | { |
---|
1073 | return isGreaterThanOrEqualTo(Fixnum.getInstance(n)); |
---|
1074 | } |
---|
1075 | |
---|
1076 | public boolean isGreaterThanOrEqualTo(LispObject obj) |
---|
1077 | { |
---|
1078 | type_error(this, Symbol.REAL); |
---|
1079 | // Not reached. |
---|
1080 | return false; |
---|
1081 | } |
---|
1082 | |
---|
1083 | public final LispObject IS_GE(LispObject obj) |
---|
1084 | { |
---|
1085 | return isGreaterThanOrEqualTo(obj) ? T : NIL; |
---|
1086 | } |
---|
1087 | |
---|
1088 | public LispObject truncate(LispObject obj) |
---|
1089 | { |
---|
1090 | return type_error(this, Symbol.REAL); |
---|
1091 | } |
---|
1092 | |
---|
1093 | public LispObject MOD(LispObject divisor) |
---|
1094 | { |
---|
1095 | truncate(divisor); |
---|
1096 | final LispThread thread = LispThread.currentThread(); |
---|
1097 | LispObject remainder = thread._values[1]; |
---|
1098 | thread.clearValues(); |
---|
1099 | if (!remainder.zerop()) |
---|
1100 | { |
---|
1101 | if (divisor.minusp()) |
---|
1102 | { |
---|
1103 | if (plusp()) |
---|
1104 | return remainder.add(divisor); |
---|
1105 | } |
---|
1106 | else |
---|
1107 | { |
---|
1108 | if (minusp()) |
---|
1109 | return remainder.add(divisor); |
---|
1110 | } |
---|
1111 | } |
---|
1112 | return remainder; |
---|
1113 | } |
---|
1114 | |
---|
1115 | public LispObject MOD(int divisor) |
---|
1116 | { |
---|
1117 | return MOD(Fixnum.getInstance(divisor)); |
---|
1118 | } |
---|
1119 | |
---|
1120 | public LispObject ash(int shift) |
---|
1121 | { |
---|
1122 | return ash(Fixnum.getInstance(shift)); |
---|
1123 | } |
---|
1124 | |
---|
1125 | public LispObject ash(LispObject obj) |
---|
1126 | { |
---|
1127 | return type_error(this, Symbol.INTEGER); |
---|
1128 | } |
---|
1129 | |
---|
1130 | public LispObject LOGNOT() |
---|
1131 | { |
---|
1132 | return type_error(this, Symbol.INTEGER); |
---|
1133 | } |
---|
1134 | |
---|
1135 | public LispObject LOGAND(int n) |
---|
1136 | { |
---|
1137 | return LOGAND(Fixnum.getInstance(n)); |
---|
1138 | } |
---|
1139 | |
---|
1140 | public LispObject LOGAND(LispObject obj) |
---|
1141 | { |
---|
1142 | return type_error(this, Symbol.INTEGER); |
---|
1143 | } |
---|
1144 | |
---|
1145 | public LispObject LOGIOR(int n) |
---|
1146 | { |
---|
1147 | return LOGIOR(Fixnum.getInstance(n)); |
---|
1148 | } |
---|
1149 | |
---|
1150 | public LispObject LOGIOR(LispObject obj) |
---|
1151 | { |
---|
1152 | return type_error(this, Symbol.INTEGER); |
---|
1153 | } |
---|
1154 | |
---|
1155 | public LispObject LOGXOR(int n) |
---|
1156 | { |
---|
1157 | return LOGXOR(Fixnum.getInstance(n)); |
---|
1158 | } |
---|
1159 | |
---|
1160 | public LispObject LOGXOR(LispObject obj) |
---|
1161 | { |
---|
1162 | return type_error(this, Symbol.INTEGER); |
---|
1163 | } |
---|
1164 | |
---|
1165 | public LispObject LDB(int size, int position) |
---|
1166 | { |
---|
1167 | return type_error(this, Symbol.INTEGER); |
---|
1168 | } |
---|
1169 | |
---|
1170 | public int sxhash() |
---|
1171 | { |
---|
1172 | return hashCode() & 0x7fffffff; |
---|
1173 | } |
---|
1174 | |
---|
1175 | // For EQUALP hash tables. |
---|
1176 | public int psxhash() |
---|
1177 | { |
---|
1178 | return sxhash(); |
---|
1179 | } |
---|
1180 | |
---|
1181 | public int psxhash(int depth) |
---|
1182 | { |
---|
1183 | return psxhash(); |
---|
1184 | } |
---|
1185 | |
---|
1186 | public LispObject STRING() |
---|
1187 | { |
---|
1188 | return error(new TypeError(princToString() + " cannot be coerced to a string.")); |
---|
1189 | } |
---|
1190 | |
---|
1191 | public char[] chars() |
---|
1192 | { |
---|
1193 | type_error(this, Symbol.STRING); |
---|
1194 | // Not reached. |
---|
1195 | return null; |
---|
1196 | } |
---|
1197 | |
---|
1198 | public char[] getStringChars() |
---|
1199 | { |
---|
1200 | type_error(this, Symbol.STRING); |
---|
1201 | // Not reached. |
---|
1202 | return null; |
---|
1203 | } |
---|
1204 | |
---|
1205 | /** Returns a string representing the value |
---|
1206 | * of a 'string designator', if the instance is one. |
---|
1207 | * |
---|
1208 | * Throws an error if the instance isn't a string designator. |
---|
1209 | */ |
---|
1210 | public String getStringValue() |
---|
1211 | { |
---|
1212 | type_error(this, Symbol.STRING); |
---|
1213 | // Not reached. |
---|
1214 | return null; |
---|
1215 | } |
---|
1216 | |
---|
1217 | public LispObject getSlotValue_0() |
---|
1218 | { |
---|
1219 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1220 | } |
---|
1221 | |
---|
1222 | public LispObject getSlotValue_1() |
---|
1223 | { |
---|
1224 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1225 | } |
---|
1226 | |
---|
1227 | public LispObject getSlotValue_2() |
---|
1228 | { |
---|
1229 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1230 | } |
---|
1231 | |
---|
1232 | public LispObject getSlotValue_3() |
---|
1233 | { |
---|
1234 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1235 | } |
---|
1236 | |
---|
1237 | public LispObject getSlotValue(int index) |
---|
1238 | { |
---|
1239 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1240 | } |
---|
1241 | |
---|
1242 | public int getFixnumSlotValue(int index) |
---|
1243 | { |
---|
1244 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1245 | // Not reached. |
---|
1246 | return 0; |
---|
1247 | } |
---|
1248 | |
---|
1249 | public boolean getSlotValueAsBoolean(int index) |
---|
1250 | { |
---|
1251 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1252 | // Not reached. |
---|
1253 | return false; |
---|
1254 | } |
---|
1255 | |
---|
1256 | public void setSlotValue_0(LispObject value) |
---|
1257 | |
---|
1258 | { |
---|
1259 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1260 | } |
---|
1261 | |
---|
1262 | public void setSlotValue_1(LispObject value) |
---|
1263 | |
---|
1264 | { |
---|
1265 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1266 | } |
---|
1267 | |
---|
1268 | public void setSlotValue_2(LispObject value) |
---|
1269 | |
---|
1270 | { |
---|
1271 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1272 | } |
---|
1273 | |
---|
1274 | public void setSlotValue_3(LispObject value) |
---|
1275 | |
---|
1276 | { |
---|
1277 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1278 | } |
---|
1279 | |
---|
1280 | public void setSlotValue(int index, LispObject value) |
---|
1281 | |
---|
1282 | { |
---|
1283 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1284 | } |
---|
1285 | |
---|
1286 | public LispObject SLOT_VALUE(LispObject slotName) |
---|
1287 | { |
---|
1288 | return type_error(this, Symbol.STANDARD_OBJECT); |
---|
1289 | } |
---|
1290 | |
---|
1291 | public void setSlotValue(LispObject slotName, LispObject newValue) |
---|
1292 | |
---|
1293 | { |
---|
1294 | type_error(this, Symbol.STANDARD_OBJECT); |
---|
1295 | } |
---|
1296 | |
---|
1297 | // Profiling. |
---|
1298 | public int getCallCount() |
---|
1299 | { |
---|
1300 | return 0; |
---|
1301 | } |
---|
1302 | |
---|
1303 | public void setCallCount(int n) |
---|
1304 | { |
---|
1305 | } |
---|
1306 | |
---|
1307 | public void incrementCallCount() |
---|
1308 | { |
---|
1309 | } |
---|
1310 | |
---|
1311 | public int getHotCount() |
---|
1312 | { |
---|
1313 | return 0; |
---|
1314 | } |
---|
1315 | |
---|
1316 | public void setHotCount(int n) |
---|
1317 | { |
---|
1318 | } |
---|
1319 | |
---|
1320 | public void incrementHotCount() |
---|
1321 | { |
---|
1322 | } |
---|
1323 | } |
---|