1 | /* |
---|
2 | * LispObject.java |
---|
3 | * |
---|
4 | * Copyright (C) 2002-2007 Peter Graves |
---|
5 | * $Id: LispObject.java 13750 2012-01-10 20:11:27Z mevenson $ |
---|
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 instanceof StandardGenericFunction) { |
---|
674 | return |
---|
675 | StandardGenericFunction.checkStandardGenericFunction(fn) |
---|
676 | .slots[StandardGenericFunctionClass.SLOT_INDEX_DOCUMENTATION]; |
---|
677 | } |
---|
678 | } |
---|
679 | } |
---|
680 | } |
---|
681 | return NIL; |
---|
682 | } |
---|
683 | |
---|
684 | public void setDocumentation(LispObject docType, LispObject documentation) |
---|
685 | |
---|
686 | { |
---|
687 | synchronized (documentationHashTable) { |
---|
688 | LispObject alist = documentationHashTable.get(this); |
---|
689 | if (alist == null) |
---|
690 | alist = NIL; |
---|
691 | LispObject entry = assq(docType, alist); |
---|
692 | if (entry instanceof Cons) |
---|
693 | { |
---|
694 | ((Cons)entry).cdr = documentation; |
---|
695 | } |
---|
696 | else |
---|
697 | { |
---|
698 | alist = alist.push(new Cons(docType, documentation)); |
---|
699 | documentationHashTable.put(this, alist); |
---|
700 | } |
---|
701 | } |
---|
702 | } |
---|
703 | |
---|
704 | public LispObject getPropertyList() |
---|
705 | { |
---|
706 | return null; |
---|
707 | } |
---|
708 | |
---|
709 | public void setPropertyList(LispObject obj) |
---|
710 | { |
---|
711 | } |
---|
712 | |
---|
713 | public LispObject getSymbolValue() |
---|
714 | { |
---|
715 | return type_error(this, Symbol.SYMBOL); |
---|
716 | } |
---|
717 | |
---|
718 | public LispObject getSymbolFunction() |
---|
719 | { |
---|
720 | return type_error(this, Symbol.SYMBOL); |
---|
721 | } |
---|
722 | |
---|
723 | public LispObject getSymbolFunctionOrDie() |
---|
724 | { |
---|
725 | return type_error(this, Symbol.SYMBOL); |
---|
726 | } |
---|
727 | |
---|
728 | public LispObject getSymbolSetfFunction() |
---|
729 | { |
---|
730 | return type_error(this, Symbol.SYMBOL); |
---|
731 | } |
---|
732 | |
---|
733 | public LispObject getSymbolSetfFunctionOrDie() |
---|
734 | { |
---|
735 | return type_error(this, Symbol.SYMBOL); |
---|
736 | } |
---|
737 | |
---|
738 | /** PRINC-TO-STRING function to be used with Java objects |
---|
739 | * |
---|
740 | * @return A string in human-readable format, as per PRINC definition |
---|
741 | */ |
---|
742 | public String princToString() |
---|
743 | { |
---|
744 | LispThread thread = LispThread.currentThread(); |
---|
745 | SpecialBindingsMark mark = thread.markSpecialBindings(); |
---|
746 | try { |
---|
747 | thread.bindSpecial(Symbol.PRINT_READABLY, NIL); |
---|
748 | thread.bindSpecial(Symbol.PRINT_ESCAPE, NIL); |
---|
749 | return printObject(); |
---|
750 | } |
---|
751 | finally { |
---|
752 | thread.resetSpecialBindings(mark); |
---|
753 | } |
---|
754 | } |
---|
755 | |
---|
756 | public String printObject() |
---|
757 | { |
---|
758 | return unreadableString(toString(), false); |
---|
759 | } |
---|
760 | |
---|
761 | /** Calls unreadableString(String s, boolean identity) with a default |
---|
762 | * identity value of 'true'. |
---|
763 | * |
---|
764 | * This function is a helper for printObject() |
---|
765 | * |
---|
766 | * @param s String representation of this object. |
---|
767 | * @return String enclosed in the non-readable #< ... > markers |
---|
768 | */ |
---|
769 | public final String unreadableString(String s) { |
---|
770 | return unreadableString(s, true); |
---|
771 | } |
---|
772 | |
---|
773 | /** Creates a non-readably (as per CLHS terminology) representation |
---|
774 | * of the 'this' object, using string 's'. |
---|
775 | * |
---|
776 | * If the current value of the variable *PRINT-READABLY* is T, a |
---|
777 | * Lisp error is thrown and no value is returned. |
---|
778 | * |
---|
779 | * This function is a helper for printObject() |
---|
780 | * |
---|
781 | * @param s |
---|
782 | * @param identity when 'true', includes Java's identityHash for the object |
---|
783 | * in the output. |
---|
784 | * @return a non reabable string (i.e. one enclosed in the #< > markers) |
---|
785 | */ |
---|
786 | public final String unreadableString(String s, boolean identity) |
---|
787 | { |
---|
788 | if (Symbol.PRINT_READABLY.symbolValue() != NIL) { |
---|
789 | error(new PrintNotReadable(list(Keyword.OBJECT, this))); |
---|
790 | return null; // not reached |
---|
791 | } |
---|
792 | StringBuilder sb = new StringBuilder("#<"); |
---|
793 | sb.append(s); |
---|
794 | if (identity) { |
---|
795 | sb.append(" {"); |
---|
796 | sb.append(Integer.toHexString(System.identityHashCode(this)).toUpperCase()); |
---|
797 | sb.append("}"); |
---|
798 | } |
---|
799 | sb.append(">"); |
---|
800 | return sb.toString(); |
---|
801 | } |
---|
802 | |
---|
803 | // Special operator |
---|
804 | public LispObject execute(LispObject args, Environment env) |
---|
805 | |
---|
806 | { |
---|
807 | return error(new LispError()); |
---|
808 | } |
---|
809 | |
---|
810 | public LispObject execute() |
---|
811 | { |
---|
812 | return type_error(this, Symbol.FUNCTION); |
---|
813 | } |
---|
814 | |
---|
815 | public LispObject execute(LispObject arg) |
---|
816 | { |
---|
817 | return type_error(this, Symbol.FUNCTION); |
---|
818 | } |
---|
819 | |
---|
820 | public LispObject execute(LispObject first, LispObject second) |
---|
821 | |
---|
822 | { |
---|
823 | return type_error(this, Symbol.FUNCTION); |
---|
824 | } |
---|
825 | |
---|
826 | public LispObject execute(LispObject first, LispObject second, |
---|
827 | LispObject third) |
---|
828 | |
---|
829 | { |
---|
830 | return type_error(this, Symbol.FUNCTION); |
---|
831 | } |
---|
832 | |
---|
833 | public LispObject execute(LispObject first, LispObject second, |
---|
834 | LispObject third, LispObject fourth) |
---|
835 | |
---|
836 | { |
---|
837 | return type_error(this, Symbol.FUNCTION); |
---|
838 | } |
---|
839 | |
---|
840 | public LispObject execute(LispObject first, LispObject second, |
---|
841 | LispObject third, LispObject fourth, |
---|
842 | LispObject fifth) |
---|
843 | |
---|
844 | { |
---|
845 | return type_error(this, Symbol.FUNCTION); |
---|
846 | } |
---|
847 | |
---|
848 | public LispObject execute(LispObject first, LispObject second, |
---|
849 | LispObject third, LispObject fourth, |
---|
850 | LispObject fifth, LispObject sixth) |
---|
851 | |
---|
852 | { |
---|
853 | return type_error(this, Symbol.FUNCTION); |
---|
854 | } |
---|
855 | |
---|
856 | public LispObject execute(LispObject first, LispObject second, |
---|
857 | LispObject third, LispObject fourth, |
---|
858 | LispObject fifth, LispObject sixth, |
---|
859 | LispObject seventh) |
---|
860 | |
---|
861 | { |
---|
862 | return type_error(this, Symbol.FUNCTION); |
---|
863 | } |
---|
864 | |
---|
865 | public LispObject execute(LispObject first, LispObject second, |
---|
866 | LispObject third, LispObject fourth, |
---|
867 | LispObject fifth, LispObject sixth, |
---|
868 | LispObject seventh, LispObject eighth) |
---|
869 | |
---|
870 | { |
---|
871 | return type_error(this, Symbol.FUNCTION); |
---|
872 | } |
---|
873 | |
---|
874 | public LispObject execute(LispObject[] args) |
---|
875 | { |
---|
876 | return type_error(this, Symbol.FUNCTION); |
---|
877 | } |
---|
878 | |
---|
879 | // Used by COMPILE-MULTIPLE-VALUE-CALL. |
---|
880 | public LispObject dispatch(LispObject[] args) |
---|
881 | { |
---|
882 | switch (args.length) |
---|
883 | { |
---|
884 | case 0: |
---|
885 | return execute(); |
---|
886 | case 1: |
---|
887 | return execute(args[0]); |
---|
888 | case 2: |
---|
889 | return execute(args[0], args[1]); |
---|
890 | case 3: |
---|
891 | return execute(args[0], args[1], args[2]); |
---|
892 | case 4: |
---|
893 | return execute(args[0], args[1], args[2], args[3]); |
---|
894 | case 5: |
---|
895 | return execute(args[0], args[1], args[2], args[3], args[4]); |
---|
896 | case 6: |
---|
897 | return execute(args[0], args[1], args[2], args[3], args[4], |
---|
898 | args[5]); |
---|
899 | case 7: |
---|
900 | return execute(args[0], args[1], args[2], args[3], args[4], |
---|
901 | args[5], args[6]); |
---|
902 | case 8: |
---|
903 | return execute(args[0], args[1], args[2], args[3], args[4], |
---|
904 | args[5], args[6], args[7]); |
---|
905 | default: |
---|
906 | return execute(args); |
---|
907 | } |
---|
908 | } |
---|
909 | |
---|
910 | public int intValue() |
---|
911 | { |
---|
912 | type_error(this, Symbol.INTEGER); |
---|
913 | // Not reached. |
---|
914 | return 0; |
---|
915 | } |
---|
916 | |
---|
917 | public long longValue() |
---|
918 | { |
---|
919 | type_error(this, Symbol.INTEGER); |
---|
920 | // Not reached. |
---|
921 | return 0; |
---|
922 | } |
---|
923 | |
---|
924 | public float floatValue() |
---|
925 | { |
---|
926 | type_error(this, Symbol.SINGLE_FLOAT); |
---|
927 | // Not reached |
---|
928 | return 0; |
---|
929 | } |
---|
930 | |
---|
931 | public double doubleValue() |
---|
932 | { |
---|
933 | type_error(this, Symbol.DOUBLE_FLOAT); |
---|
934 | // Not reached |
---|
935 | return 0; |
---|
936 | } |
---|
937 | |
---|
938 | public LispObject incr() |
---|
939 | { |
---|
940 | return type_error(this, Symbol.NUMBER); |
---|
941 | } |
---|
942 | |
---|
943 | public LispObject decr() |
---|
944 | { |
---|
945 | return type_error(this, Symbol.NUMBER); |
---|
946 | } |
---|
947 | |
---|
948 | public LispObject negate() |
---|
949 | { |
---|
950 | return Fixnum.ZERO.subtract(this); |
---|
951 | } |
---|
952 | |
---|
953 | public LispObject add(int n) |
---|
954 | { |
---|
955 | return add(Fixnum.getInstance(n)); |
---|
956 | } |
---|
957 | |
---|
958 | public LispObject add(LispObject obj) |
---|
959 | { |
---|
960 | return type_error(this, Symbol.NUMBER); |
---|
961 | } |
---|
962 | |
---|
963 | public LispObject subtract(int n) |
---|
964 | { |
---|
965 | return subtract(Fixnum.getInstance(n)); |
---|
966 | } |
---|
967 | |
---|
968 | public LispObject subtract(LispObject obj) |
---|
969 | { |
---|
970 | return type_error(this, Symbol.NUMBER); |
---|
971 | } |
---|
972 | |
---|
973 | public LispObject multiplyBy(int n) |
---|
974 | { |
---|
975 | return multiplyBy(Fixnum.getInstance(n)); |
---|
976 | } |
---|
977 | |
---|
978 | public LispObject multiplyBy(LispObject obj) |
---|
979 | { |
---|
980 | return type_error(this, Symbol.NUMBER); |
---|
981 | } |
---|
982 | |
---|
983 | public LispObject divideBy(LispObject obj) |
---|
984 | { |
---|
985 | return type_error(this, Symbol.NUMBER); |
---|
986 | } |
---|
987 | |
---|
988 | public boolean isEqualTo(int n) |
---|
989 | { |
---|
990 | return isEqualTo(Fixnum.getInstance(n)); |
---|
991 | } |
---|
992 | |
---|
993 | public boolean isEqualTo(LispObject obj) |
---|
994 | { |
---|
995 | type_error(this, Symbol.NUMBER); |
---|
996 | // Not reached. |
---|
997 | return false; |
---|
998 | } |
---|
999 | |
---|
1000 | public final LispObject IS_E(LispObject obj) |
---|
1001 | { |
---|
1002 | return isEqualTo(obj) ? T : NIL; |
---|
1003 | } |
---|
1004 | |
---|
1005 | public boolean isNotEqualTo(int n) |
---|
1006 | { |
---|
1007 | return isNotEqualTo(Fixnum.getInstance(n)); |
---|
1008 | } |
---|
1009 | |
---|
1010 | public boolean isNotEqualTo(LispObject obj) |
---|
1011 | { |
---|
1012 | type_error(this, Symbol.NUMBER); |
---|
1013 | // Not reached. |
---|
1014 | return false; |
---|
1015 | } |
---|
1016 | |
---|
1017 | public final LispObject IS_NE(LispObject obj) |
---|
1018 | { |
---|
1019 | return isNotEqualTo(obj) ? T : NIL; |
---|
1020 | } |
---|
1021 | |
---|
1022 | public boolean isLessThan(int n) |
---|
1023 | { |
---|
1024 | return isLessThan(Fixnum.getInstance(n)); |
---|
1025 | } |
---|
1026 | |
---|
1027 | public boolean isLessThan(LispObject obj) |
---|
1028 | { |
---|
1029 | type_error(this, Symbol.REAL); |
---|
1030 | // Not reached. |
---|
1031 | return false; |
---|
1032 | } |
---|
1033 | |
---|
1034 | public final LispObject IS_LT(LispObject obj) |
---|
1035 | { |
---|
1036 | return isLessThan(obj) ? T : NIL; |
---|
1037 | } |
---|
1038 | |
---|
1039 | public boolean isGreaterThan(int n) |
---|
1040 | { |
---|
1041 | return isGreaterThan(Fixnum.getInstance(n)); |
---|
1042 | } |
---|
1043 | |
---|
1044 | public boolean isGreaterThan(LispObject obj) |
---|
1045 | { |
---|
1046 | type_error(this, Symbol.REAL); |
---|
1047 | // Not reached. |
---|
1048 | return false; |
---|
1049 | } |
---|
1050 | |
---|
1051 | public final LispObject IS_GT(LispObject obj) |
---|
1052 | { |
---|
1053 | return isGreaterThan(obj) ? T : NIL; |
---|
1054 | } |
---|
1055 | |
---|
1056 | public boolean isLessThanOrEqualTo(int n) |
---|
1057 | { |
---|
1058 | return isLessThanOrEqualTo(Fixnum.getInstance(n)); |
---|
1059 | } |
---|
1060 | |
---|
1061 | public boolean isLessThanOrEqualTo(LispObject obj) |
---|
1062 | { |
---|
1063 | type_error(this, Symbol.REAL); |
---|
1064 | // Not reached. |
---|
1065 | return false; |
---|
1066 | } |
---|
1067 | |
---|
1068 | public final LispObject IS_LE(LispObject obj) |
---|
1069 | { |
---|
1070 | return isLessThanOrEqualTo(obj) ? T : NIL; |
---|
1071 | } |
---|
1072 | |
---|
1073 | public boolean isGreaterThanOrEqualTo(int n) |
---|
1074 | { |
---|
1075 | return isGreaterThanOrEqualTo(Fixnum.getInstance(n)); |
---|
1076 | } |
---|
1077 | |
---|
1078 | public boolean isGreaterThanOrEqualTo(LispObject obj) |
---|
1079 | { |
---|
1080 | type_error(this, Symbol.REAL); |
---|
1081 | // Not reached. |
---|
1082 | return false; |
---|
1083 | } |
---|
1084 | |
---|
1085 | public final LispObject IS_GE(LispObject obj) |
---|
1086 | { |
---|
1087 | return isGreaterThanOrEqualTo(obj) ? T : NIL; |
---|
1088 | } |
---|
1089 | |
---|
1090 | public LispObject truncate(LispObject obj) |
---|
1091 | { |
---|
1092 | return type_error(this, Symbol.REAL); |
---|
1093 | } |
---|
1094 | |
---|
1095 | public LispObject MOD(LispObject divisor) |
---|
1096 | { |
---|
1097 | truncate(divisor); |
---|
1098 | final LispThread thread = LispThread.currentThread(); |
---|
1099 | LispObject remainder = thread._values[1]; |
---|
1100 | thread.clearValues(); |
---|
1101 | if (!remainder.zerop()) |
---|
1102 | { |
---|
1103 | if (divisor.minusp()) |
---|
1104 | { |
---|
1105 | if (plusp()) |
---|
1106 | return remainder.add(divisor); |
---|
1107 | } |
---|
1108 | else |
---|
1109 | { |
---|
1110 | if (minusp()) |
---|
1111 | return remainder.add(divisor); |
---|
1112 | } |
---|
1113 | } |
---|
1114 | return remainder; |
---|
1115 | } |
---|
1116 | |
---|
1117 | public LispObject MOD(int divisor) |
---|
1118 | { |
---|
1119 | return MOD(Fixnum.getInstance(divisor)); |
---|
1120 | } |
---|
1121 | |
---|
1122 | public LispObject ash(int shift) |
---|
1123 | { |
---|
1124 | return ash(Fixnum.getInstance(shift)); |
---|
1125 | } |
---|
1126 | |
---|
1127 | public LispObject ash(LispObject obj) |
---|
1128 | { |
---|
1129 | return type_error(this, Symbol.INTEGER); |
---|
1130 | } |
---|
1131 | |
---|
1132 | public LispObject LOGNOT() |
---|
1133 | { |
---|
1134 | return type_error(this, Symbol.INTEGER); |
---|
1135 | } |
---|
1136 | |
---|
1137 | public LispObject LOGAND(int n) |
---|
1138 | { |
---|
1139 | return LOGAND(Fixnum.getInstance(n)); |
---|
1140 | } |
---|
1141 | |
---|
1142 | public LispObject LOGAND(LispObject obj) |
---|
1143 | { |
---|
1144 | return type_error(this, Symbol.INTEGER); |
---|
1145 | } |
---|
1146 | |
---|
1147 | public LispObject LOGIOR(int n) |
---|
1148 | { |
---|
1149 | return LOGIOR(Fixnum.getInstance(n)); |
---|
1150 | } |
---|
1151 | |
---|
1152 | public LispObject LOGIOR(LispObject obj) |
---|
1153 | { |
---|
1154 | return type_error(this, Symbol.INTEGER); |
---|
1155 | } |
---|
1156 | |
---|
1157 | public LispObject LOGXOR(int n) |
---|
1158 | { |
---|
1159 | return LOGXOR(Fixnum.getInstance(n)); |
---|
1160 | } |
---|
1161 | |
---|
1162 | public LispObject LOGXOR(LispObject obj) |
---|
1163 | { |
---|
1164 | return type_error(this, Symbol.INTEGER); |
---|
1165 | } |
---|
1166 | |
---|
1167 | public LispObject LDB(int size, int position) |
---|
1168 | { |
---|
1169 | return type_error(this, Symbol.INTEGER); |
---|
1170 | } |
---|
1171 | |
---|
1172 | public int sxhash() |
---|
1173 | { |
---|
1174 | return hashCode() & 0x7fffffff; |
---|
1175 | } |
---|
1176 | |
---|
1177 | // For EQUALP hash tables. |
---|
1178 | public int psxhash() |
---|
1179 | { |
---|
1180 | return sxhash(); |
---|
1181 | } |
---|
1182 | |
---|
1183 | public int psxhash(int depth) |
---|
1184 | { |
---|
1185 | return psxhash(); |
---|
1186 | } |
---|
1187 | |
---|
1188 | public LispObject STRING() |
---|
1189 | { |
---|
1190 | return error(new TypeError(princToString() + " cannot be coerced to a string.")); |
---|
1191 | } |
---|
1192 | |
---|
1193 | public char[] chars() |
---|
1194 | { |
---|
1195 | type_error(this, Symbol.STRING); |
---|
1196 | // Not reached. |
---|
1197 | return null; |
---|
1198 | } |
---|
1199 | |
---|
1200 | public char[] getStringChars() |
---|
1201 | { |
---|
1202 | type_error(this, Symbol.STRING); |
---|
1203 | // Not reached. |
---|
1204 | return null; |
---|
1205 | } |
---|
1206 | |
---|
1207 | /** Returns a string representing the value |
---|
1208 | * of a 'string designator', if the instance is one. |
---|
1209 | * |
---|
1210 | * Throws an error if the instance isn't a string designator. |
---|
1211 | */ |
---|
1212 | public String getStringValue() |
---|
1213 | { |
---|
1214 | type_error(this, Symbol.STRING); |
---|
1215 | // Not reached. |
---|
1216 | return null; |
---|
1217 | } |
---|
1218 | |
---|
1219 | public LispObject getSlotValue_0() |
---|
1220 | { |
---|
1221 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1222 | } |
---|
1223 | |
---|
1224 | public LispObject getSlotValue_1() |
---|
1225 | { |
---|
1226 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1227 | } |
---|
1228 | |
---|
1229 | public LispObject getSlotValue_2() |
---|
1230 | { |
---|
1231 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1232 | } |
---|
1233 | |
---|
1234 | public LispObject getSlotValue_3() |
---|
1235 | { |
---|
1236 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1237 | } |
---|
1238 | |
---|
1239 | public LispObject getSlotValue(int index) |
---|
1240 | { |
---|
1241 | return type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1242 | } |
---|
1243 | |
---|
1244 | public int getFixnumSlotValue(int index) |
---|
1245 | { |
---|
1246 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1247 | // Not reached. |
---|
1248 | return 0; |
---|
1249 | } |
---|
1250 | |
---|
1251 | public boolean getSlotValueAsBoolean(int index) |
---|
1252 | { |
---|
1253 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1254 | // Not reached. |
---|
1255 | return false; |
---|
1256 | } |
---|
1257 | |
---|
1258 | public void setSlotValue_0(LispObject value) |
---|
1259 | |
---|
1260 | { |
---|
1261 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1262 | } |
---|
1263 | |
---|
1264 | public void setSlotValue_1(LispObject value) |
---|
1265 | |
---|
1266 | { |
---|
1267 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1268 | } |
---|
1269 | |
---|
1270 | public void setSlotValue_2(LispObject value) |
---|
1271 | |
---|
1272 | { |
---|
1273 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1274 | } |
---|
1275 | |
---|
1276 | public void setSlotValue_3(LispObject value) |
---|
1277 | |
---|
1278 | { |
---|
1279 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1280 | } |
---|
1281 | |
---|
1282 | public void setSlotValue(int index, LispObject value) |
---|
1283 | |
---|
1284 | { |
---|
1285 | type_error(this, Symbol.STRUCTURE_OBJECT); |
---|
1286 | } |
---|
1287 | |
---|
1288 | public LispObject SLOT_VALUE(LispObject slotName) |
---|
1289 | { |
---|
1290 | return type_error(this, Symbol.STANDARD_OBJECT); |
---|
1291 | } |
---|
1292 | |
---|
1293 | public void setSlotValue(LispObject slotName, LispObject newValue) |
---|
1294 | |
---|
1295 | { |
---|
1296 | type_error(this, Symbol.STANDARD_OBJECT); |
---|
1297 | } |
---|
1298 | |
---|
1299 | // Profiling. |
---|
1300 | public int getCallCount() |
---|
1301 | { |
---|
1302 | return 0; |
---|
1303 | } |
---|
1304 | |
---|
1305 | public void setCallCount(int n) |
---|
1306 | { |
---|
1307 | } |
---|
1308 | |
---|
1309 | public void incrementCallCount() |
---|
1310 | { |
---|
1311 | } |
---|
1312 | |
---|
1313 | public int getHotCount() |
---|
1314 | { |
---|
1315 | return 0; |
---|
1316 | } |
---|
1317 | |
---|
1318 | public void setHotCount(int n) |
---|
1319 | { |
---|
1320 | } |
---|
1321 | |
---|
1322 | public void incrementHotCount() |
---|
1323 | { |
---|
1324 | } |
---|
1325 | } |
---|