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