Changeset 10306


Ignore:
Timestamp:
11/01/05 02:13:27 (16 years ago)
Author:
piso
Message:

Cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/TwoWayStream.java

    r8087 r10306  
    22 * TwoWayStream.java
    33 *
    4  * Copyright (C) 2003-2004 Peter Graves
    5  * $Id: TwoWayStream.java,v 1.25 2004-11-03 15:39:02 piso Exp $
     4 * Copyright (C) 2003-2005 Peter Graves
     5 * $Id: TwoWayStream.java,v 1.26 2005-11-01 02:13:27 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2424public class TwoWayStream extends Stream
    2525{
    26     private final Stream in;
    27     private final Stream out;
     26    public final Stream in;
     27    public final Stream out;
    2828
    2929    public TwoWayStream(Stream in, Stream out)
     
    177177    }
    178178
    179     public String writeToString()
    180     {
    181         return unreadableString("TWO-WAY-STREAM");
    182     }
    183 
    184     // ### make-two-way-stream
    185     // input-stream output-stream => two-way-stream
     179    public String writeToString() throws ConditionThrowable
     180    {
     181        return unreadableString(Symbol.TWO_WAY_STREAM);
     182    }
     183
     184    // ### make-two-way-stream input-stream output-stream => two-way-stream
    186185    private static final Primitive MAKE_TWO_WAY_STREAM =
    187         new Primitive("make-two-way-stream", "input-stream output-stream")
     186        new Primitive(Symbol.MAKE_TWO_WAY_STREAM, "input-stream output-stream")
    188187    {
    189188        public LispObject execute(LispObject first, LispObject second)
    190189            throws ConditionThrowable
    191190        {
    192             if (!(first instanceof Stream))
    193                 return signal(new TypeError(first, Symbol.STREAM));
    194             if (!(second instanceof Stream))
    195                 return signal(new TypeError(second, Symbol.STREAM));
    196             Stream in = (Stream) first;
     191            final Stream in;
     192            try {
     193                in = (Stream) first;
     194            }
     195            catch (ClassCastException e) {
     196                return signalTypeError(first, Symbol.STREAM);
     197            }
     198            final Stream out;
     199            try {
     200                out = (Stream) second;
     201            }
     202            catch (ClassCastException e) {
     203                return signalTypeError(second, Symbol.STREAM);
     204            }
    197205            if (!in.isInputStream())
    198                 return signal(new TypeError(in, "input stream"));
    199             Stream out = (Stream) second;
     206                return signalTypeError(in, list2(Symbol.SATISFIES,
     207                                                 Symbol.INPUT_STREAM_P));
    200208            if (!out.isOutputStream())
    201                 return signal(new TypeError(out, "output stream"));
     209                return signalTypeError(out, list2(Symbol.SATISFIES,
     210                                                  Symbol.OUTPUT_STREAM_P));
    202211            return new TwoWayStream(in, out);
    203212        }
    204213    };
    205214
    206     // ### two-way-stream-input-stream
    207     // two-way-stream => input-stream
     215    // ### two-way-stream-input-stream two-way-stream => input-stream
    208216    private static final Primitive TWO_WAY_STREAM_INPUT_STREAM =
    209         new Primitive("two-way-stream-input-stream", "two-way-stream")
     217        new Primitive(Symbol.TWO_WAY_STREAM_INPUT_STREAM, "two-way-stream")
    210218    {
    211219        public LispObject execute(LispObject arg) throws ConditionThrowable
    212220        {
    213             if (arg instanceof TwoWayStream)
    214                 return ((TwoWayStream)arg).getInputStream();
    215             return signal(new TypeError(arg, Symbol.TWO_WAY_STREAM));
     221            try {
     222                return ((TwoWayStream)arg).in;
     223            }
     224            catch (ClassCastException e) {
     225                return signalTypeError(arg, Symbol.TWO_WAY_STREAM);
     226            }
    216227        }
    217228    };
    218229
    219     // ### two-way-stream-output-stream
    220     // two-way-stream => output-stream
     230    // ### two-way-stream-output-stream two-way-stream => output-stream
    221231    private static final Primitive TWO_WAY_STREAM_OUTPUT_STREAM =
    222         new Primitive("two-way-stream-output-stream", "two-way-stream")
     232        new Primitive(Symbol.TWO_WAY_STREAM_OUTPUT_STREAM, "two-way-stream")
    223233    {
    224234        public LispObject execute(LispObject arg) throws ConditionThrowable
    225235        {
    226             if (arg instanceof TwoWayStream)
    227                 return ((TwoWayStream)arg).getOutputStream();
    228             return signal(new TypeError(arg, Symbol.TWO_WAY_STREAM));
     236            try {
     237                return ((TwoWayStream)arg).out;
     238            }
     239            catch (ClassCastException e) {
     240                return signalTypeError(arg, Symbol.TWO_WAY_STREAM);
     241            }
    229242        }
    230243    };
Note: See TracChangeset for help on using the changeset viewer.