001: /*
002: * LispObject.java
003: *
004: * Copyright (C) 2002-2003 Peter Graves
005: * $Id: LispObject.java,v 1.98 2004/09/21 00:37:44 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.lisp;
023:
024: public class LispObject extends Lisp {
025: public int getFunctionalType() {
026: return 0;
027: }
028:
029: public LispObject typeOf() {
030: return T;
031: }
032:
033: public LispClass classOf() {
034: return BuiltInClass.CLASS_T;
035: }
036:
037: public LispObject getDescription() throws ConditionThrowable {
038: StringBuffer sb = new StringBuffer("An object of type ");
039: sb.append(typeOf().writeToString());
040: return new SimpleString(sb);
041: }
042:
043: public LispObject getParts() throws ConditionThrowable {
044: return NIL;
045: }
046:
047: public boolean getBooleanValue() {
048: return true;
049: }
050:
051: public LispObject typep(LispObject typeSpecifier)
052: throws ConditionThrowable {
053: if (typeSpecifier == T)
054: return T;
055: if (typeSpecifier == BuiltInClass.CLASS_T)
056: return T;
057: if (typeSpecifier == Symbol.ATOM)
058: return T;
059: return NIL;
060: }
061:
062: public boolean constantp() {
063: return true;
064: }
065:
066: public LispObject CONSTANTP() {
067: return constantp() ? T : NIL;
068: }
069:
070: public LispObject ATOM() {
071: return T;
072: }
073:
074: public boolean atom() {
075: return true;
076: }
077:
078: public String getName() {
079: return null;
080: }
081:
082: public Object javaInstance() throws ConditionThrowable {
083: return signal(new TypeError("The value " + writeToString()
084: + " is not of primitive type."));
085: }
086:
087: public Object javaInstance(Class c) throws ConditionThrowable {
088: if (c == LispObject.class)
089: return this ;
090: return signal(new TypeError("The value " + writeToString()
091: + " is not of primitive type."));
092: }
093:
094: public LispObject car() throws ConditionThrowable {
095: return signal(new TypeError(this , Symbol.LIST));
096: }
097:
098: public void setCar(LispObject obj) throws ConditionThrowable {
099: signal(new TypeError(this , Symbol.CONS));
100: }
101:
102: public LispObject RPLACA(LispObject obj) throws ConditionThrowable {
103: return signal(new TypeError(this , Symbol.CONS));
104: }
105:
106: public LispObject _RPLACA(LispObject obj) throws ConditionThrowable {
107: return signal(new TypeError(this , Symbol.CONS));
108: }
109:
110: public LispObject cdr() throws ConditionThrowable {
111: return signal(new TypeError(this , Symbol.LIST));
112: }
113:
114: public void setCdr(LispObject obj) throws ConditionThrowable {
115: signal(new TypeError(this , Symbol.CONS));
116: }
117:
118: public LispObject RPLACD(LispObject obj) throws ConditionThrowable {
119: return signal(new TypeError(this , Symbol.CONS));
120: }
121:
122: public LispObject _RPLACD(LispObject obj) throws ConditionThrowable {
123: return signal(new TypeError(this , Symbol.CONS));
124: }
125:
126: public LispObject cadr() throws ConditionThrowable {
127: return signal(new TypeError(this , Symbol.LIST));
128: }
129:
130: public LispObject cddr() throws ConditionThrowable {
131: return signal(new TypeError(this , Symbol.LIST));
132: }
133:
134: public LispObject push(LispObject obj) throws ConditionThrowable {
135: return signal(new TypeError(this , Symbol.LIST));
136: }
137:
138: public LispObject EQ(LispObject obj) {
139: return this == obj ? T : NIL;
140: }
141:
142: public boolean eql(LispObject obj) {
143: return this == obj;
144: }
145:
146: public final LispObject EQL(LispObject obj) {
147: return eql(obj) ? T : NIL;
148: }
149:
150: public final LispObject EQUAL(LispObject obj)
151: throws ConditionThrowable {
152: return equal(obj) ? T : NIL;
153: }
154:
155: public boolean equal(LispObject obj) throws ConditionThrowable {
156: return this == obj;
157: }
158:
159: public boolean equalp(LispObject obj) throws ConditionThrowable {
160: return this == obj;
161: }
162:
163: public LispObject ABS() throws ConditionThrowable {
164: return signal(new TypeError(this , Symbol.NUMBER));
165: }
166:
167: public LispObject NUMERATOR() throws ConditionThrowable {
168: return signal(new TypeError(this , Symbol.RATIONAL));
169: }
170:
171: public LispObject DENOMINATOR() throws ConditionThrowable {
172: return signal(new TypeError(this , Symbol.RATIONAL));
173: }
174:
175: public LispObject EVENP() throws ConditionThrowable {
176: return evenp() ? T : NIL;
177: }
178:
179: public boolean evenp() throws ConditionThrowable {
180: signal(new TypeError(this , Symbol.INTEGER));
181: // Not reached.
182: return false;
183: }
184:
185: public LispObject ODDP() throws ConditionThrowable {
186: return oddp() ? T : NIL;
187: }
188:
189: public boolean oddp() throws ConditionThrowable {
190: signal(new TypeError(this , Symbol.INTEGER));
191: // Not reached.
192: return false;
193: }
194:
195: public LispObject PLUSP() throws ConditionThrowable {
196: return plusp() ? T : NIL;
197: }
198:
199: public boolean plusp() throws ConditionThrowable {
200: signal(new TypeError(this , Symbol.REAL));
201: // Not reached.
202: return false;
203: }
204:
205: public LispObject MINUSP() throws ConditionThrowable {
206: return minusp() ? T : NIL;
207: }
208:
209: public boolean minusp() throws ConditionThrowable {
210: signal(new TypeError(this , Symbol.REAL));
211: // Not reached.
212: return false;
213: }
214:
215: public LispObject NUMBERP() {
216: return NIL;
217: }
218:
219: public boolean numberp() {
220: return false;
221: }
222:
223: public LispObject ZEROP() throws ConditionThrowable {
224: return zerop() ? T : NIL;
225: }
226:
227: public boolean zerop() throws ConditionThrowable {
228: signal(new TypeError(this , Symbol.NUMBER));
229: // Not reached.
230: return false;
231: }
232:
233: public LispObject BIT_VECTOR_P() {
234: return NIL;
235: }
236:
237: public LispObject COMPLEXP() {
238: return NIL;
239: }
240:
241: public LispObject FLOATP() {
242: return NIL;
243: }
244:
245: public boolean floatp() {
246: return false;
247: }
248:
249: public LispObject INTEGERP() {
250: return integerp() ? T : NIL;
251: }
252:
253: public boolean integerp() {
254: return false;
255: }
256:
257: public LispObject RATIONALP() {
258: return rationalp() ? T : NIL;
259: }
260:
261: public boolean rationalp() {
262: return false;
263: }
264:
265: public LispObject REALP() {
266: return realp() ? T : NIL;
267: }
268:
269: public boolean realp() {
270: return false;
271: }
272:
273: public LispObject STRINGP() {
274: return NIL;
275: }
276:
277: public boolean stringp() {
278: return false;
279: }
280:
281: public LispObject SIMPLE_STRING_P() {
282: return NIL;
283: }
284:
285: public LispObject VECTORP() {
286: return NIL;
287: }
288:
289: public boolean vectorp() {
290: return false;
291: }
292:
293: public LispObject CHARACTERP() {
294: return NIL;
295: }
296:
297: public boolean characterp() {
298: return false;
299: }
300:
301: public int length() throws ConditionThrowable {
302: signal(new TypeError(this , Symbol.SEQUENCE));
303: // Not reached.
304: return 0;
305: }
306:
307: public final LispObject LENGTH() throws ConditionThrowable {
308: return new Fixnum(length());
309: }
310:
311: public LispObject elt(int index) throws ConditionThrowable {
312: return signal(new TypeError(this , Symbol.SEQUENCE));
313: }
314:
315: public LispObject nreverse() throws ConditionThrowable {
316: return signal(new TypeError(this , Symbol.SEQUENCE));
317: }
318:
319: public LispObject AREF(LispObject index) throws ConditionThrowable {
320: return signal(new TypeError(this , Symbol.ARRAY));
321: }
322:
323: public LispObject[] copyToArray() throws ConditionThrowable {
324: signal(new TypeError(this , Symbol.LIST));
325: // Not reached.
326: return null;
327: }
328:
329: public LispObject SYMBOLP() {
330: return NIL;
331: }
332:
333: public boolean listp() {
334: return false;
335: }
336:
337: public LispObject LISTP() {
338: return NIL;
339: }
340:
341: public boolean endp() throws ConditionThrowable {
342: signal(new TypeError(this , Symbol.LIST));
343: // Not reached.
344: return false;
345: }
346:
347: public LispObject ENDP() throws ConditionThrowable {
348: return signal(new TypeError(this , Symbol.LIST));
349: }
350:
351: public LispObject NOT() {
352: return NIL;
353: }
354:
355: public boolean isSpecialVariable() {
356: return false;
357: }
358:
359: public LispObject getSymbolValue() throws ConditionThrowable {
360: return signal(new TypeError(this , Symbol.SYMBOL));
361: }
362:
363: public LispObject getSymbolFunction() throws ConditionThrowable {
364: return signal(new TypeError(this , Symbol.SYMBOL));
365: }
366:
367: public LispObject getSymbolFunctionOrDie()
368: throws ConditionThrowable {
369: return signal(new TypeError(this , Symbol.SYMBOL));
370: }
371:
372: public String writeToString() throws ConditionThrowable {
373: return toString();
374: }
375:
376: public String unreadableString(String s) {
377: StringBuffer sb = new StringBuffer("#<");
378: sb.append(s);
379: sb.append(" @ #x");
380: sb.append(Integer.toHexString(System.identityHashCode(this )));
381: sb.append(">");
382: return sb.toString();
383: }
384:
385: // Special operator
386: public LispObject execute(LispObject args, Environment env)
387: throws ConditionThrowable {
388: return signal(new LispError());
389: }
390:
391: // Primitive
392: public LispObject execute(LispObject[] args)
393: throws ConditionThrowable {
394: return signal(new TypeError(this , Symbol.FUNCTION));
395: }
396:
397: // Primitive0
398: public LispObject execute() throws ConditionThrowable {
399: return signal(new TypeError(this , Symbol.FUNCTION));
400: }
401:
402: // Primitive1
403: public LispObject execute(LispObject arg) throws ConditionThrowable {
404: return signal(new TypeError(this , Symbol.FUNCTION));
405: }
406:
407: // Primitive2
408: public LispObject execute(LispObject first, LispObject second)
409: throws ConditionThrowable {
410: return signal(new TypeError(this , Symbol.FUNCTION));
411: }
412:
413: // Primitive3
414: public LispObject execute(LispObject first, LispObject second,
415: LispObject third) throws ConditionThrowable {
416: return signal(new TypeError(this , Symbol.FUNCTION));
417: }
418:
419: // Primitive4
420: public LispObject execute(LispObject first, LispObject second,
421: LispObject third, LispObject fourth)
422: throws ConditionThrowable {
423: return signal(new TypeError(this , Symbol.FUNCTION));
424: }
425:
426: public LispObject execute(LispObject[] args, LispObject[] context)
427: throws ConditionThrowable {
428: return signal(new TypeError(this , Symbol.FUNCTION));
429: }
430:
431: public LispObject execute(LispObject[] args, LispObject[][] context)
432: throws ConditionThrowable {
433: return signal(new TypeError(this , Symbol.FUNCTION));
434: }
435:
436: public LispObject incr() throws ConditionThrowable {
437: return signal(new TypeError(this , Symbol.NUMBER));
438: }
439:
440: public LispObject decr() throws ConditionThrowable {
441: return signal(new TypeError(this , Symbol.NUMBER));
442: }
443:
444: public LispObject add(LispObject obj) throws ConditionThrowable {
445: return signal(new TypeError(this , Symbol.NUMBER));
446: }
447:
448: public LispObject subtract(LispObject obj)
449: throws ConditionThrowable {
450: return signal(new TypeError(this , Symbol.NUMBER));
451: }
452:
453: public LispObject multiplyBy(LispObject obj)
454: throws ConditionThrowable {
455: return signal(new TypeError(this , Symbol.NUMBER));
456: }
457:
458: public LispObject divideBy(LispObject obj)
459: throws ConditionThrowable {
460: return signal(new TypeError(this , Symbol.NUMBER));
461: }
462:
463: public boolean isEqualTo(LispObject obj) throws ConditionThrowable {
464: signal(new TypeError(this , Symbol.NUMBER));
465: // Not reached.
466: return false;
467: }
468:
469: public LispObject IS_E(LispObject obj) throws ConditionThrowable {
470: return isEqualTo(obj) ? T : NIL;
471: }
472:
473: public boolean isNotEqualTo(LispObject obj)
474: throws ConditionThrowable {
475: signal(new TypeError(this , Symbol.NUMBER));
476: // Not reached.
477: return false;
478: }
479:
480: public LispObject IS_NE(LispObject obj) throws ConditionThrowable {
481: return isNotEqualTo(obj) ? T : NIL;
482: }
483:
484: public boolean isLessThan(LispObject obj) throws ConditionThrowable {
485: signal(new TypeError(this , Symbol.NUMBER));
486: // Not reached.
487: return false;
488: }
489:
490: public LispObject IS_LT(LispObject obj) throws ConditionThrowable {
491: return isLessThan(obj) ? T : NIL;
492: }
493:
494: public boolean isGreaterThan(LispObject obj)
495: throws ConditionThrowable {
496: signal(new TypeError(this , Symbol.NUMBER));
497: // Not reached.
498: return false;
499: }
500:
501: public LispObject IS_GT(LispObject obj) throws ConditionThrowable {
502: return isGreaterThan(obj) ? T : NIL;
503: }
504:
505: public boolean isLessThanOrEqualTo(LispObject obj)
506: throws ConditionThrowable {
507: signal(new TypeError(this , Symbol.NUMBER));
508: // Not reached.
509: return false;
510: }
511:
512: public LispObject IS_LE(LispObject obj) throws ConditionThrowable {
513: return isLessThanOrEqualTo(obj) ? T : NIL;
514: }
515:
516: public boolean isGreaterThanOrEqualTo(LispObject obj)
517: throws ConditionThrowable {
518: signal(new TypeError(this , Symbol.NUMBER));
519: // Not reached.
520: return false;
521: }
522:
523: public LispObject IS_GE(LispObject obj) throws ConditionThrowable {
524: return isGreaterThanOrEqualTo(obj) ? T : NIL;
525: }
526:
527: public LispObject truncate(LispObject obj)
528: throws ConditionThrowable {
529: return signal(new TypeError(this , Symbol.REAL));
530: }
531:
532: public LispObject MOD(LispObject divisor) throws ConditionThrowable {
533: truncate(divisor);
534: final LispThread thread = LispThread.currentThread();
535: LispObject remainder = thread._values[1];
536: thread.clearValues();
537: if (!remainder.zerop()) {
538: if (divisor.minusp()) {
539: if (plusp())
540: return remainder.add(divisor);
541: } else {
542: if (minusp())
543: return remainder.add(divisor);
544: }
545: }
546: return remainder;
547: }
548:
549: public LispObject ash(LispObject obj) throws ConditionThrowable {
550: return signal(new TypeError(obj, Symbol.INTEGER));
551: }
552:
553: public int sxhash() throws ConditionThrowable {
554: return hashCode() & 0x7fffffff;
555: }
556:
557: // For EQUALP hash tables.
558: public int psxhash() throws ConditionThrowable {
559: return sxhash();
560: }
561:
562: public LispObject STRING() throws ConditionThrowable {
563: return signal(new TypeError(writeToString()
564: + " cannot be coerced to a string."));
565: }
566:
567: public char[] chars() throws ConditionThrowable {
568: signal(new TypeError(this , Symbol.STRING));
569: // Not reached.
570: return null;
571: }
572:
573: public char[] getStringChars() throws ConditionThrowable {
574: signal(new TypeError(this , Symbol.STRING));
575: // Not reached.
576: return null;
577: }
578:
579: public String getStringValue() throws ConditionThrowable {
580: signal(new TypeError(this , Symbol.STRING));
581: // Not reached.
582: return null;
583: }
584:
585: public LispObject getSlotValue(int index) throws ConditionThrowable {
586: return signal(new TypeError(this , Symbol.STRUCTURE_OBJECT));
587: }
588:
589: public LispObject setSlotValue(int index, LispObject value)
590: throws ConditionThrowable {
591: return signal(new TypeError(this , Symbol.STRUCTURE_OBJECT));
592: }
593:
594: // Profiling.
595: public int getCallCount() {
596: return 0;
597: }
598:
599: public void setCallCount(int n) {
600: }
601:
602: public void incrementCallCount() {
603: }
604: }
|