Changeset 4116


Ignore:
Timestamp:
09/28/03 20:17:06 (19 years ago)
Author:
piso
Message:

LispStream? class hierarchy refactoring.

Location:
trunk/j/src/org/armedbear/lisp
Files:
3 edited

Legend:

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

    r4095 r4116  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: Lisp.java,v 1.155 2003-09-28 14:14:04 piso Exp $
     5 * $Id: Lisp.java,v 1.156 2003-09-28 20:13:26 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    763763    }
    764764
    765     public static final CharacterInputStream checkInputStream(LispObject obj)
     765    public static final CharacterInputStream checkCharacterInputStream(LispObject obj)
    766766        throws ConditionThrowable
    767767    {
     
    770770        if (obj instanceof CharacterInputStream)
    771771            return (CharacterInputStream) obj;
    772         if (obj instanceof TwoWayStream)
    773             return ((TwoWayStream)obj).getInputStream();
    774         throw new ConditionThrowable(new TypeError(obj, "input stream"));
    775     }
    776 
    777     public static final CharacterOutputStream checkOutputStream(LispObject obj)
     772        if (obj instanceof TwoWayStream) {
     773            LispInputStream in = ((TwoWayStream)obj).getInputStream();
     774            if (in instanceof CharacterInputStream)
     775                return (CharacterInputStream) in;
     776        }
     777        throw new ConditionThrowable(new TypeError(obj, "character input stream"));
     778    }
     779
     780    public static final CharacterOutputStream checkCharacterOutputStream(LispObject obj)
    778781        throws ConditionThrowable
    779782    {
     
    782785        if (obj instanceof CharacterOutputStream)
    783786            return (CharacterOutputStream) obj;
    784         if (obj instanceof TwoWayStream)
    785             return ((TwoWayStream)obj).getOutputStream();
     787        if (obj instanceof TwoWayStream) {
     788            LispOutputStream out = ((TwoWayStream)obj).getOutputStream();
     789            if (out instanceof CharacterOutputStream)
     790                return (CharacterOutputStream) out;
     791        }
    786792        throw new ConditionThrowable(new TypeError(obj, "output stream"));
    787793    }
     
    791797    {
    792798        if (obj == T)
    793             return checkInputStream(_TERMINAL_IO_.symbolValue());
     799            return checkCharacterInputStream(_TERMINAL_IO_.symbolValue());
    794800        if (obj == NIL)
    795             return checkInputStream(_STANDARD_INPUT_.symbolValue());
     801            return checkCharacterInputStream(_STANDARD_INPUT_.symbolValue());
    796802        if (obj instanceof CharacterInputStream)
    797803            return (CharacterInputStream) obj;
    798         if (obj instanceof TwoWayStream)
    799             return ((TwoWayStream)obj).getInputStream();
     804        if (obj instanceof TwoWayStream) {
     805            LispInputStream in = ((TwoWayStream)obj).getInputStream();
     806            if (in instanceof CharacterInputStream)
     807                return (CharacterInputStream) in;
     808        }
    800809        throw new ConditionThrowable(new TypeError(obj, "character input stream"));
    801810    }
     
    805814    {
    806815        if (obj == T)
    807             return checkOutputStream(_TERMINAL_IO_.symbolValue());
     816            return checkCharacterOutputStream(_TERMINAL_IO_.symbolValue());
    808817        if (obj == NIL)
    809             return checkOutputStream(_STANDARD_OUTPUT_.symbolValue());
     818            return checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue());
    810819        if (obj instanceof CharacterOutputStream)
    811820            return (CharacterOutputStream) obj;
    812         if (obj instanceof TwoWayStream)
    813             return ((TwoWayStream)obj).getOutputStream();
     821        if (obj instanceof TwoWayStream) {
     822            LispOutputStream out = ((TwoWayStream)obj).getOutputStream();
     823            if (out instanceof CharacterOutputStream)
     824                return (CharacterOutputStream) out;
     825        }
    814826        throw new ConditionThrowable(new TypeError(obj, "character output stream"));
    815827    }
     
    10441056    public static final CharacterOutputStream getStandardOutput() throws ConditionThrowable
    10451057    {
    1046         return checkOutputStream(_STANDARD_OUTPUT_.symbolValueNoThrow());
     1058        return checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValueNoThrow());
    10471059    }
    10481060
  • trunk/j/src/org/armedbear/lisp/Primitives.java

    r4103 r4116  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: Primitives.java,v 1.450 2003-09-28 16:25:31 piso Exp $
     5 * $Id: Primitives.java,v 1.451 2003-09-28 20:14:12 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    619619            final CharacterOutputStream out;
    620620            if (args.length == 1)
    621                 out = checkOutputStream(_STANDARD_OUTPUT_.symbolValue());
     621                out = checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue());
    622622            else
    623623                out = outSynonymOf(args[1]);
     
    647647        {
    648648            CharacterOutputStream out =
    649                 checkOutputStream(_STANDARD_OUTPUT_.symbolValue());
     649                checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue());
    650650            out.prin1(arg);
    651651            return arg;
     
    676676        {
    677677            CharacterOutputStream out =
    678                 checkOutputStream(_STANDARD_OUTPUT_.symbolValue());
     678                checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue());
    679679            out.terpri();
    680680            out.prin1(arg);
     
    702702            final CharacterOutputStream out;
    703703            if (args.length == 0)
    704                 out = checkOutputStream(_STANDARD_OUTPUT_.symbolValue());
     704                out = checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue());
    705705            else
    706706                out = outSynonymOf(args[0]);
     
    718718            CharacterOutputStream out;
    719719            if (args.length == 0)
    720                 out = checkOutputStream(_STANDARD_OUTPUT_.symbolValue());
     720                out = checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue());
    721721            else
    722722                out = outSynonymOf(args[0]);
     
    11291129            String s = _format(_args);
    11301130            if (destination == T) {
    1131                 checkOutputStream(_STANDARD_OUTPUT_.symbolValue()).writeString(s);
     1131                checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue()).writeString(s);
    11321132                return NIL;
    11331133            }
     
    11391139            }
    11401140            if (destination instanceof TwoWayStream) {
    1141                 ((TwoWayStream)destination).getOutputStream().writeString(s);
    1142                 return NIL;
     1141                LispOutputStream out = ((TwoWayStream)destination).getOutputStream();
     1142                if (out instanceof CharacterOutputStream) {
     1143                    ((CharacterOutputStream)out).writeString(s);
     1144                    return NIL;
     1145                }
     1146                throw new ConditionThrowable(new TypeError(destination, "character output stream"));
    11431147            }
    11441148            // Destination can also be a string with a fill pointer.
     
    33013305            final CharacterOutputStream out;
    33023306            if (args.length == 1)
    3303                 out = checkOutputStream(_STANDARD_OUTPUT_.symbolValue());
     3307                out = checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue());
    33043308            else
    33053309                out = outSynonymOf(args[1]);
     
    33663370        final CharacterOutputStream out;
    33673371        if (args.length == 0)
    3368             out = checkOutputStream(_STANDARD_OUTPUT_.symbolValue());
     3372            out = checkCharacterOutputStream(_STANDARD_OUTPUT_.symbolValue());
    33693373        else
    33703374            out = outSynonymOf(args[0]);
     
    33823386            final CharacterInputStream in;
    33833387            if (args.length == 0)
    3384                 in = checkInputStream(_STANDARD_INPUT_.symbolValue());
     3388                in = checkCharacterInputStream(_STANDARD_INPUT_.symbolValue());
    33853389            else
    33863390                in = inSynonymOf(args[0]);
     
    35163520            if (length > 4)
    35173521                throw new ConditionThrowable(new WrongNumberOfArgumentsException(this));
    3518             CharacterInputStream stream;
     3522            CharacterInputStream stream = null;
    35193523            if (length == 0)
    35203524                stream = getStandardInput();
    35213525            else if (args[0] instanceof CharacterInputStream)
    35223526                stream = (CharacterInputStream) args[0];
    3523             else if (args[0] instanceof TwoWayStream)
    3524                 stream = ((TwoWayStream)args[0]).getInputStream();
    3525             else
    3526                 throw new ConditionThrowable(new TypeError(args[0], "input stream"));
     3527            else if (args[0] instanceof TwoWayStream) {
     3528                LispInputStream in = ((TwoWayStream)args[0]).getInputStream();
     3529                if (in instanceof CharacterInputStream)
     3530                    stream = (CharacterInputStream) in;
     3531            }
     3532            if (stream == null)
     3533                throw new ConditionThrowable(new TypeError(args[0], "character input stream"));
    35273534            boolean eofError = length > 1 ? (args[1] != NIL) : true;
    35283535            LispObject eofValue = length > 2 ? args[2] : NIL;
     
    37253732                throw new ConditionThrowable(new WrongNumberOfArgumentsException(this));
    37263733            CharacterInputStream stream =
    3727                 length > 0 ? checkInputStream(args[0]) : getStandardInput();
     3734                length > 0 ? checkCharacterInputStream(args[0]) : getStandardInput();
    37283735            boolean eofError = length > 1 ? (args[1] != NIL) : true;
    37293736            LispObject eofValue = length > 2 ? args[2] : NIL;
     
    37423749                throw new ConditionThrowable(new WrongNumberOfArgumentsException(this));
    37433750            CharacterInputStream stream =
    3744                 length > 0 ? checkInputStream(args[0]) : getStandardInput();
     3751                length > 0 ? checkCharacterInputStream(args[0]) : getStandardInput();
    37453752            boolean eofError = length > 1 ? (args[1] != NIL) : true;
    37463753            LispObject eofValue = length > 2 ? args[2] : NIL;
     
    37593766                throw new ConditionThrowable(new WrongNumberOfArgumentsException(this));
    37603767            CharacterInputStream stream =
    3761                 length > 1 ? checkInputStream(args[1]) : getStandardInput();
     3768                length > 1 ? checkCharacterInputStream(args[1]) : getStandardInput();
    37623769            return stream.unreadChar(checkCharacter(args[0]));
    37633770        }
  • trunk/j/src/org/armedbear/lisp/TwoWayStream.java

    r3887 r4116  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: TwoWayStream.java,v 1.5 2003-09-19 12:32:14 piso Exp $
     5 * $Id: TwoWayStream.java,v 1.6 2003-09-28 20:17:06 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2424public final class TwoWayStream extends LispStream
    2525{
    26     private final CharacterInputStream in;
    27     private final CharacterOutputStream out;
     26    private final LispInputStream in;
     27    private final LispOutputStream out;
    2828
    29     public TwoWayStream(CharacterInputStream in, CharacterOutputStream out)
     29    public TwoWayStream(LispInputStream in, LispOutputStream out)
    3030    {
    3131        this.in = in;
     
    3333    }
    3434
    35     public CharacterInputStream getInputStream()
     35    public LispInputStream getInputStream()
    3636    {
    3737        return in;
    3838    }
    3939
    40     public CharacterOutputStream getOutputStream()
     40    public LispOutputStream getOutputStream()
    4141    {
    4242        return out;
     
    6969            throws ConditionThrowable
    7070        {
    71             if (!(first instanceof CharacterInputStream))
     71            if (!(first instanceof LispInputStream))
    7272                throw new ConditionThrowable(new TypeError(first, "input stream"));
    73             if (!(second instanceof CharacterOutputStream))
     73            if (!(second instanceof LispOutputStream))
    7474                throw new ConditionThrowable(new TypeError(second, "output stream"));
    75             return new TwoWayStream((CharacterInputStream) first,
    76                 (CharacterOutputStream) second);
     75            return new TwoWayStream((LispInputStream) first,
     76                                    (LispOutputStream) second);
    7777        }
    7878    };
Note: See TracChangeset for help on using the changeset viewer.