001: /*
002: * ArithmeticError.java
003: *
004: * Copyright (C) 2003-2004 Peter Graves
005: * $Id: ArithmeticError.java,v 1.10 2004/03/18 01:41:11 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 ArithmeticError extends LispError {
025: private final LispObject operation;
026: private final LispObject operands;
027:
028: public ArithmeticError() {
029: operation = NIL;
030: operands = NIL;
031: }
032:
033: public ArithmeticError(LispObject initArgs)
034: throws ConditionThrowable {
035: super (initArgs);
036: LispObject operation = NIL;
037: LispObject operands = NIL;
038: LispObject first, second;
039: while (initArgs != NIL) {
040: first = initArgs.car();
041: initArgs = initArgs.cdr();
042: second = initArgs.car();
043: initArgs = initArgs.cdr();
044: if (first == Keyword.OPERATION)
045: operation = second;
046: else if (first == Keyword.OPERANDS)
047: operands = second;
048: }
049: this .operation = operation;
050: this .operands = operands;
051: }
052:
053: public ArithmeticError(String message) {
054: super (message);
055: operation = NIL;
056: operands = NIL;
057: }
058:
059: public LispObject typeOf() {
060: return Symbol.ARITHMETIC_ERROR;
061: }
062:
063: public LispClass classOf() {
064: return BuiltInClass.ARITHMETIC_ERROR;
065: }
066:
067: public LispObject typep(LispObject type) throws ConditionThrowable {
068: if (type == Symbol.ARITHMETIC_ERROR)
069: return T;
070: if (type == BuiltInClass.ARITHMETIC_ERROR)
071: return T;
072: return super .typep(type);
073: }
074:
075: // ### arithmetic-error-operation
076: private static final Primitive1 ARITHMETIC_ERROR_OPERATION = new Primitive1(
077: "arithmetic-error-operation", "condition") {
078: public LispObject execute(LispObject arg)
079: throws ConditionThrowable {
080: try {
081: return ((ArithmeticError) arg).operation;
082: } catch (ClassCastException e) {
083: return signal(new TypeError(arg,
084: Symbol.ARITHMETIC_ERROR));
085: }
086: }
087: };
088: // ### arithmetic-error-operands
089: private static final Primitive1 ARITHMETIC_ERROR_OPERANDS = new Primitive1(
090: "arithmetic-error-operands", "condition") {
091: public LispObject execute(LispObject arg)
092: throws ConditionThrowable {
093: try {
094: return ((ArithmeticError) arg).operands;
095: } catch (ClassCastException e) {
096: return signal(new TypeError(arg,
097: Symbol.ARITHMETIC_ERROR));
098: }
099: }
100: };
101: }
|