source: branches/0.17.x/abcl/src/org/armedbear/lisp/ArithmeticError.java

Last change on this file was 12254, checked in by ehuelsmann, 16 years ago

Remove 'throws ConditionThrowable?' method annotations:

it's an unchecked exception now, so no need to declare it thrown.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/*
2 * ArithmeticError.java
3 *
4 * Copyright (C) 2003-2005 Peter Graves
5 * $Id: ArithmeticError.java 12254 2009-11-06 20:07:54Z ehuelsmann $
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 * 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
34package org.armedbear.lisp;
35
36public class ArithmeticError extends LispError
37{
38    protected ArithmeticError(LispClass cls)
39    {
40        super(cls);
41    }
42
43    public ArithmeticError(LispObject initArgs)
44    {
45        super(StandardClass.ARITHMETIC_ERROR);
46        initialize(initArgs);
47    }
48
49    @Override
50    protected void initialize(LispObject initArgs)
51    {
52        super.initialize(initArgs);
53        LispObject operation = NIL;
54        LispObject operands = NIL;
55        LispObject first, second;
56        while (initArgs != NIL) {
57            first = initArgs.car();
58            initArgs = initArgs.cdr();
59            second = initArgs.car();
60            initArgs = initArgs.cdr();
61            if (first == Keyword.OPERATION)
62                operation = second;
63            else if (first == Keyword.OPERANDS)
64                operands = second;
65        }
66        setOperation(operation);
67        setOperands(operands);
68    }
69
70    public ArithmeticError(String message)
71    {
72        super(StandardClass.ARITHMETIC_ERROR);
73        setFormatControl(message);
74        setFormatArguments(NIL);
75        setOperation(NIL);
76        setOperands(NIL);
77    }
78
79    @Override
80    public LispObject typeOf()
81    {
82        return Symbol.ARITHMETIC_ERROR;
83    }
84
85    @Override
86    public LispObject classOf()
87    {
88        return StandardClass.ARITHMETIC_ERROR;
89    }
90
91    @Override
92    public LispObject typep(LispObject type)
93    {
94        if (type == Symbol.ARITHMETIC_ERROR)
95            return T;
96        if (type == StandardClass.ARITHMETIC_ERROR)
97            return T;
98        return super.typep(type);
99    }
100
101    private final LispObject getOperation()
102    {
103        return getInstanceSlotValue(Symbol.OPERATION);
104    }
105
106    private final void setOperation(LispObject operation)
107
108    {
109        setInstanceSlotValue(Symbol.OPERATION, operation);
110    }
111
112    private final LispObject getOperands()
113    {
114        return getInstanceSlotValue(Symbol.OPERANDS);
115    }
116
117    private final void setOperands(LispObject operands)
118
119    {
120        setInstanceSlotValue(Symbol.OPERANDS, operands);
121    }
122
123    // ### arithmetic-error-operation
124    private static final Primitive ARITHMETIC_ERROR_OPERATION =
125        new Primitive("arithmetic-error-operation", "condition")
126    {
127        @Override
128        public LispObject execute(LispObject arg)
129        {
130            if (arg instanceof ArithmeticError) {
131                return ((ArithmeticError)arg).getOperation();
132            }
133            else {
134                return error(new TypeError(arg, Symbol.ARITHMETIC_ERROR));
135            }
136        }
137    };
138    // ### arithmetic-error-operands
139    private static final Primitive ARITHMETIC_ERROR_OPERANDS =
140        new Primitive("arithmetic-error-operands", "condition")
141    {
142        @Override
143        public LispObject execute(LispObject arg)
144        {
145            if (arg instanceof ArithmeticError) {
146                return ((ArithmeticError)arg).getOperands();
147            }
148            else {
149                return error(new TypeError(arg, Symbol.ARITHMETIC_ERROR));
150            }
151        }
152    };
153}
Note: See TracBrowser for help on using the repository browser.