source: branches/1.1.x/src/org/armedbear/lisp/SynonymStream.java

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

Rename writeToString() to printObject() since that's what it's being used for.
Additionally, create princToString() for use in error messages, making the

required replacement where appropriate.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1/*
2 * SynonymStream.java
3 *
4 * Copyright (C) 2004 Peter Graves
5 * $Id: SynonymStream.java 13440 2011-08-05 21:25:10Z 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 SynonymStream extends Stream
39{
40    final Symbol symbol;
41
42    SynonymStream(Symbol symbol)
43    {
44        super(Symbol.SYNONYM_STREAM);
45        this.symbol = symbol;
46    }
47
48    @Override
49    public boolean isInputStream()
50    {
51        return checkStream(symbol.symbolValue()).isInputStream();
52    }
53
54    @Override
55    public boolean isOutputStream()
56    {
57        return checkStream(symbol.symbolValue()).isOutputStream();
58    }
59
60    @Override
61    public boolean isCharacterInputStream()
62    {
63        return checkStream(symbol.symbolValue()).isCharacterInputStream();
64    }
65
66    @Override
67    public boolean isBinaryInputStream()
68    {
69        return checkStream(symbol.symbolValue()).isBinaryInputStream();
70    }
71
72    @Override
73    public boolean isCharacterOutputStream()
74    {
75        return checkStream(symbol.symbolValue()).isCharacterOutputStream();
76    }
77
78    @Override
79    public boolean isBinaryOutputStream()
80    {
81        return checkStream(symbol.symbolValue()).isBinaryOutputStream();
82    }
83
84    @Override
85    public LispObject typeOf()
86    {
87        return Symbol.SYNONYM_STREAM;
88    }
89
90    @Override
91    public LispObject classOf()
92    {
93        return BuiltInClass.SYNONYM_STREAM;
94    }
95
96    @Override
97    public LispObject typep(LispObject typeSpecifier)
98    {
99        if (typeSpecifier == Symbol.SYNONYM_STREAM)
100            return T;
101        if (typeSpecifier == BuiltInClass.SYNONYM_STREAM)
102            return T;
103        return super.typep(typeSpecifier);
104    }
105
106    @Override
107    public LispObject getElementType()
108    {
109        return checkStream(symbol.symbolValue()).getElementType();
110    }
111
112    @Override
113    public LispObject listen()
114    {
115        return checkStream(symbol.symbolValue()).listen();
116    }
117
118    @Override
119    public LispObject fileLength()
120    {
121        return checkStream(symbol.symbolValue()).fileLength();
122    }
123
124    @Override
125    public LispObject fileStringLength(LispObject arg)
126    {
127        return checkStream(symbol.symbolValue()).fileStringLength(arg);
128    }
129
130    @Override
131    protected int _readChar() throws java.io.IOException
132    {
133        return checkStream(symbol.symbolValue())._readChar();
134    }
135
136    @Override
137    protected void _unreadChar(int n) throws java.io.IOException
138    {
139        checkStream(symbol.symbolValue())._unreadChar(n);
140    }
141
142    @Override
143    protected boolean _charReady() throws java.io.IOException
144    {
145        return checkStream(symbol.symbolValue())._charReady();
146    }
147
148    @Override
149    public void _writeChar(char c)
150    {
151        checkStream(symbol.symbolValue())._writeChar(c);
152    }
153
154    @Override
155    public void _writeChars(char[] chars, int start, int end)
156
157    {
158        checkStream(symbol.symbolValue())._writeChars(chars, start, end);
159    }
160
161    @Override
162    public void _writeString(String s)
163    {
164        checkStream(symbol.symbolValue())._writeString(s);
165    }
166
167    @Override
168    public void _writeLine(String s)
169    {
170        checkStream(symbol.symbolValue())._writeLine(s);
171    }
172
173    // Reads an 8-bit byte.
174    @Override
175    public int _readByte()
176    {
177        return checkStream(symbol.symbolValue())._readByte();
178    }
179
180    // Writes an 8-bit byte.
181    @Override
182    public void _writeByte(int n)
183    {
184        checkStream(symbol.symbolValue())._writeByte(n);
185    }
186
187    @Override
188    public void _finishOutput()
189    {
190        checkStream(symbol.symbolValue())._finishOutput();
191    }
192
193    @Override
194    public void _clearInput()
195    {
196        checkStream(symbol.symbolValue())._clearInput();
197    }
198
199    @Override
200    protected long _getFilePosition()
201    {
202        return checkStream(symbol.symbolValue())._getFilePosition();
203    }
204
205    @Override
206    protected boolean _setFilePosition(LispObject arg)
207    {
208        return checkStream(symbol.symbolValue())._setFilePosition(arg);
209    }
210
211    @Override
212    public void _close()
213    {
214        checkStream(symbol.symbolValue())._close();
215    }
216
217    @Override
218    public String printObject()
219    {
220        StringBuffer sb = new StringBuffer("SYNONYM-STREAM ");
221        sb.append(symbol.printObject());
222        return unreadableString(sb.toString());
223    }
224
225    // ### make-synonym-stream symbol => synonym-stream
226    private static final Primitive MAKE_SYNONYM_STREAM =
227        new Primitive("make-synonym-stream", "symbol")
228    {
229        @Override
230        public LispObject execute(LispObject arg)
231        {
232            return new SynonymStream(checkSymbol(arg));
233        }
234    };
235
236    // ### synonym-stream-symbol synonym-stream => symbol
237    private static final Primitive SYNONYM_STREAM_STREAMS =
238        new Primitive("synonym-stream-symbol", "synonym-stream")
239    {
240        @Override
241        public LispObject execute(LispObject arg)
242        {
243            if (arg instanceof SynonymStream) 
244                return ((SynonymStream)arg).symbol;
245            return error(new TypeError(arg, Symbol.SYNONYM_STREAM));
246        }
247    };
248}
Note: See TracBrowser for help on using the repository browser.