KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > ArithmeticError


1 /*
2  * ArithmeticError.java
3  *
4  * Copyright (C) 2003-2004 Peter Graves
5  * $Id: ArithmeticError.java,v 1.10 2004/03/18 01:41:11 piso Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.lisp;
23
24 public class ArithmeticError extends LispError
25 {
26     private final LispObject operation;
27     private final LispObject operands;
28
29     public ArithmeticError()
30     {
31         operation = NIL;
32         operands = NIL;
33     }
34
35     public ArithmeticError(LispObject initArgs) throws ConditionThrowable
36     {
37         super(initArgs);
38         LispObject operation = NIL;
39         LispObject operands = NIL;
40         LispObject first, second;
41         while (initArgs != NIL) {
42             first = initArgs.car();
43             initArgs = initArgs.cdr();
44             second = initArgs.car();
45             initArgs = initArgs.cdr();
46             if (first == Keyword.OPERATION)
47                 operation = second;
48             else if (first == Keyword.OPERANDS)
49                 operands = second;
50         }
51         this.operation = operation;
52         this.operands = operands;
53     }
54
55     public ArithmeticError(String JavaDoc message)
56     {
57         super(message);
58         operation = NIL;
59         operands = NIL;
60     }
61
62     public LispObject typeOf()
63     {
64         return Symbol.ARITHMETIC_ERROR;
65     }
66
67     public LispClass classOf()
68     {
69         return BuiltInClass.ARITHMETIC_ERROR;
70     }
71
72     public LispObject typep(LispObject type) throws ConditionThrowable
73     {
74         if (type == Symbol.ARITHMETIC_ERROR)
75             return T;
76         if (type == BuiltInClass.ARITHMETIC_ERROR)
77             return T;
78         return super.typep(type);
79     }
80
81     // ### arithmetic-error-operation
82
private static final Primitive1 ARITHMETIC_ERROR_OPERATION =
83         new Primitive1("arithmetic-error-operation", "condition")
84     {
85         public LispObject execute(LispObject arg) throws ConditionThrowable
86         {
87             try {
88                 return ((ArithmeticError)arg).operation;
89             }
90             catch (ClassCastException JavaDoc e) {
91                 return signal(new TypeError(arg, Symbol.ARITHMETIC_ERROR));
92             }
93         }
94     };
95     // ### arithmetic-error-operands
96
private static final Primitive1 ARITHMETIC_ERROR_OPERANDS =
97         new Primitive1("arithmetic-error-operands", "condition")
98     {
99         public LispObject execute(LispObject arg) throws ConditionThrowable
100         {
101             try {
102                 return ((ArithmeticError)arg).operands;
103             }
104             catch (ClassCastException JavaDoc e) {
105                 return signal(new TypeError(arg, Symbol.ARITHMETIC_ERROR));
106             }
107         }
108     };
109 }
110
Popular Tags