source: trunk/abcl/src/org/armedbear/lisp/make_condition.java

Last change on this file was 14018, checked in by ehuelsmann, 12 years ago

Fix #206 while moving the definition of the
condition classes to lisp.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1/*
2 * make_condition.java
3 *
4 * Copyright (C) 2003-2005 Peter Graves
5 * $Id: make_condition.java 14018 2012-07-29 11:32:09Z 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
36import static org.armedbear.lisp.Lisp.*;
37
38public final class make_condition extends Primitive
39{
40    private make_condition()
41    {
42        super("%make-condition", PACKAGE_SYS, true);
43    }
44
45    // ### %make-condition
46    // %make-condition type slot-initializations => condition
47    @Override
48    public LispObject execute(LispObject type, LispObject initArgs)
49
50    {
51        final Symbol symbol;
52        if (type instanceof Symbol)
53            symbol = (Symbol) type;
54        else if (type instanceof LispClass)
55            symbol = checkSymbol(((LispClass)type).getName());
56        else {
57            // This function only works on symbols and classes.
58            return NIL;
59        }
60
61        if (symbol == Symbol.ARITHMETIC_ERROR)
62            return new ArithmeticError(initArgs);
63        if (symbol == Symbol.CELL_ERROR)
64            return new CellError(initArgs);
65        if (symbol == Symbol.CONDITION)
66            return new Condition(initArgs);
67        if (symbol == Symbol.CONTROL_ERROR)
68            return new ControlError(initArgs);
69        if (symbol == Symbol.DIVISION_BY_ZERO)
70            return new DivisionByZero(initArgs);
71        if (symbol == Symbol.END_OF_FILE)
72            return new EndOfFile(initArgs);
73        if (symbol == Symbol.ERROR)
74            return new LispError(initArgs);
75        if (symbol == Symbol.FILE_ERROR)
76            return new FileError(initArgs);
77        if (symbol == Symbol.FLOATING_POINT_INEXACT)
78            return new FloatingPointInexact(initArgs);
79        if (symbol == Symbol.FLOATING_POINT_INVALID_OPERATION)
80            return new FloatingPointInvalidOperation(initArgs);
81        if (symbol == Symbol.FLOATING_POINT_OVERFLOW)
82            return new FloatingPointOverflow(initArgs);
83        if (symbol == Symbol.FLOATING_POINT_UNDERFLOW)
84            return new FloatingPointUnderflow(initArgs);
85        if (symbol == Symbol.PACKAGE_ERROR)
86            return new PackageError(initArgs);
87        if (symbol == Symbol.PARSE_ERROR)
88            return new ParseError(initArgs);
89        if (symbol == Symbol.PRINT_NOT_READABLE)
90            return new PrintNotReadable(initArgs);
91        if (symbol == Symbol.PROGRAM_ERROR)
92            return new ProgramError(initArgs);
93        if (symbol == Symbol.READER_ERROR)
94            return new ReaderError(initArgs);
95        if (symbol == Symbol.SERIOUS_CONDITION)
96            return new SeriousCondition(initArgs);
97        if (symbol == Symbol.SIMPLE_CONDITION)
98            return new SimpleCondition(initArgs);
99        if (symbol == Symbol.SIMPLE_ERROR)
100            return new SimpleError(initArgs);
101        if (symbol == Symbol.SIMPLE_TYPE_ERROR)
102            return new SimpleTypeError(initArgs);
103        if (symbol == Symbol.SIMPLE_WARNING)
104            return new SimpleWarning(initArgs);
105        if (symbol == Symbol.STORAGE_CONDITION)
106            return new StorageCondition(initArgs);
107        if (symbol == Symbol.STREAM_ERROR)
108            return new StreamError(initArgs);
109        if (symbol == Symbol.STYLE_WARNING)
110            return new StyleWarning(initArgs);
111        if (symbol == Symbol.TYPE_ERROR)
112            return new TypeError(initArgs);
113        if (symbol == Symbol.UNBOUND_SLOT)
114            return new UnboundSlot(initArgs);
115        if (symbol == Symbol.UNBOUND_VARIABLE)
116            return new UnboundVariable(initArgs);
117        if (symbol == Symbol.UNDEFINED_FUNCTION)
118            return new UndefinedFunction(initArgs);
119        if (symbol == Symbol.WARNING)
120            return new Warning(initArgs);
121
122        return NIL;
123    }
124
125    private static final Primitive MAKE_CONDITION = new make_condition();
126}
Note: See TracBrowser for help on using the repository browser.