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

Last change on this file was 13445, checked in by ehuelsmann, 13 years ago

Print unreadable strings with unreadableString() exclusively,
so it can throw a Lisp error when printing something unreadable.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1/*
2 * SpecialOperator.java
3 *
4 * Copyright (C) 2002-2005 Peter Graves
5 * $Id: SpecialOperator.java 13445 2011-08-06 14:46:28Z 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 class SpecialOperator extends Operator
39{
40    private int callCount;
41    private int hotCount;
42
43    public SpecialOperator(Symbol symbol)
44    {
45        symbol.setSymbolFunction(this);
46        setLambdaName(symbol);
47    }
48
49    public SpecialOperator(Symbol symbol, String arglist)
50    {
51        symbol.setSymbolFunction(this);
52        setLambdaName(symbol);
53        setLambdaList(new SimpleString(arglist));
54    }
55
56    public SpecialOperator(String name, Package pkg, boolean exported,
57                           String arglist)
58    {
59        Symbol symbol;
60        if (exported)
61           symbol = pkg.internAndExport(name.toUpperCase());
62        else
63           symbol = pkg.intern(name.toUpperCase());
64        symbol.setSymbolFunction(this);
65        setLambdaName(symbol);
66        setLambdaList(new SimpleString(arglist));
67    }
68
69    @Override
70    public LispObject execute()
71    {
72        return error(new UndefinedFunction(getLambdaName()));
73    }
74
75    @Override
76    public LispObject execute(LispObject arg)
77    {
78        return error(new UndefinedFunction(getLambdaName()));
79    }
80
81    @Override
82    public LispObject execute(LispObject first, LispObject second)
83
84    {
85        return error(new UndefinedFunction(getLambdaName()));
86    }
87
88    @Override
89    public LispObject execute(LispObject first, LispObject second,
90                              LispObject third)
91
92    {
93        return error(new UndefinedFunction(getLambdaName()));
94    }
95
96    @Override
97    public LispObject execute(LispObject first, LispObject second,
98                              LispObject third, LispObject fourth)
99
100    {
101        return error(new UndefinedFunction(getLambdaName()));
102    }
103
104    @Override
105    public LispObject execute(LispObject first, LispObject second,
106                              LispObject third, LispObject fourth,
107                              LispObject fifth)
108
109    {
110        return error(new UndefinedFunction(getLambdaName()));
111    }
112
113    @Override
114    public LispObject execute(LispObject first, LispObject second,
115                              LispObject third, LispObject fourth,
116                              LispObject fifth, LispObject sixth)
117
118    {
119        return error(new UndefinedFunction(getLambdaName()));
120    }
121
122    @Override
123    public LispObject execute(LispObject first, LispObject second,
124                              LispObject third, LispObject fourth,
125                              LispObject fifth, LispObject sixth,
126                              LispObject seventh)
127
128    {
129        return error(new UndefinedFunction(getLambdaName()));
130    }
131
132    @Override
133    public LispObject execute(LispObject first, LispObject second,
134                              LispObject third, LispObject fourth,
135                              LispObject fifth, LispObject sixth,
136                              LispObject seventh, LispObject eighth)
137
138    {
139        return error(new UndefinedFunction(getLambdaName()));
140    }
141
142    @Override
143    public LispObject execute(LispObject[] args)
144    {
145        return error(new UndefinedFunction(getLambdaName()));
146    }
147
148    @Override
149    public String printObject()
150    {
151        StringBuilder sb = new StringBuilder("SPECIAL-OPERATOR ");
152        sb.append(lambdaName.princToString());
153        return unreadableString(sb.toString(), false);
154    }
155
156    // Profiling.
157    @Override
158    public final int getCallCount()
159    {
160        return callCount;
161    }
162
163    @Override
164    public final void setCallCount(int n)
165    {
166        callCount = n;
167    }
168
169    @Override
170    public final void incrementCallCount()
171    {
172        ++callCount;
173    }
174
175    @Override
176    public final int getHotCount()
177    {
178        return hotCount;
179    }
180
181    @Override
182    public final void setHotCount(int n)
183    {
184        callCount = n;
185    }
186
187    @Override
188    public final void incrementHotCount()
189    {
190        ++hotCount;
191    }
192}
Note: See TracBrowser for help on using the repository browser.