Changeset 12604


Ignore:
Timestamp:
04/14/10 20:28:17 (14 years ago)
Author:
ehuelsmann
Message:

Further consolidation of copy/pasted code.

Patch by: David Kirkman, dkirkman at ucsd dot edu

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

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/FaslReader.java

    r12602 r12604  
    102102
    103103        {
    104             final LispThread thread = LispThread.currentThread();
    105             LispObject list = stream.readList(true, Stream.faslReadtable);
    106             if (_BACKQUOTE_COUNT_.symbolValue(thread).zerop()) {
    107                 if (n >= 0) {
    108                     LispObject[] array = new LispObject[n];
    109                     for (int i = 0; i < n; i++) {
    110                         array[i] = list.car();
    111                         if (list.cdr() != NIL)
    112                             list = list.cdr();
    113                     }
    114                     return new SimpleVector(array);
    115                 } else
    116                     return new SimpleVector(list);
    117             }
    118             return new Cons(_BQ_VECTOR_FLAG_.symbolValue(thread), list);
     104          return stream.readSharpLeftParen(c, n, Stream.faslReadtable);
    119105        }
    120106    };
     
    129115
    130116        {
    131             final LispThread thread = LispThread.currentThread();
    132             final Readtable rt = FaslReadtable.getInstance();
    133             final boolean suppress =
    134                 (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL);
    135             StringBuilder sb = new StringBuilder();
    136       try
    137         {
    138     while (true) {
    139       int ch = stream._readChar();
    140       if (ch < 0)
    141                     break;
    142       char c = (char) ch;
    143       if (c == '0' || c == '1')
    144                     sb.append(c);
    145       else {
    146                     int syntaxType = rt.getSyntaxType(c);
    147                     if (syntaxType == Readtable.SYNTAX_TYPE_WHITESPACE ||
    148                         syntaxType == Readtable.SYNTAX_TYPE_TERMINATING_MACRO) {
    149           stream._unreadChar(c);
    150           break;
    151                     } else if (!suppress) {
    152           String name = LispCharacter.charToName(c);
    153           if (name == null)
    154       name = "#\\" + c;
    155           error(new ReaderError("Illegal element for bit-vector: " + name,
    156               stream));
    157                     }
    158       }
    159     }
    160         }
    161       catch (java.io.IOException e)
    162         {
    163     error(new ReaderError("IO error: ",
    164               stream));
    165     return NIL;
    166         }
    167 
    168             if (suppress)
    169                 return NIL;
    170             if (n >= 0) {
    171                 // n was supplied.
    172                 final int length = sb.length();
    173                 if (length == 0) {
    174                     if (n > 0)
    175                         return error(new ReaderError("No element specified for bit vector of length " +
    176                                                       n + '.',
    177                                                       stream));
    178                 }
    179                 if (n > length) {
    180                     final char c = sb.charAt(length - 1);
    181                     for (int i = length; i < n; i++)
    182                         sb.append(c);
    183                 } else if (n < length) {
    184                     return error(new ReaderError("Bit vector is longer than specified length: #" +
    185                                                   n + '*' + sb.toString(),
    186                                                   stream));
    187                 }
    188             }
    189             return new SimpleBitVector(sb.toString());
     117          return stream.readSharpStar(ignored, n, Stream.faslReadtable);
    190118        }
    191119    };
     
    200128
    201129        {
    202             final LispThread thread = LispThread.currentThread();
    203             if (Symbol.READ_EVAL.symbolValue(thread) == NIL)
    204                 return error(new ReaderError("Can't read #. when *READ-EVAL* is NIL.",
    205                                               stream));
    206             else
    207                 return eval(stream.read(true, NIL, true, thread,
    208                                         Stream.faslReadtable),
    209                             new Environment(), thread);
     130          return stream.readSharpDot(c, n, Stream.faslReadtable);
    210131        }
    211132    };
  • trunk/abcl/src/org/armedbear/lisp/LispReader.java

    r12602 r12604  
    141141
    142142        {
    143             final LispThread thread = LispThread.currentThread();
    144             LispObject list = stream.readList(true, Stream.currentReadtable);
    145             if (_BACKQUOTE_COUNT_.symbolValue(thread).zerop()) {
    146                 if (n >= 0) {
    147                     LispObject[] array = new LispObject[n];
    148                     for (int i = 0; i < n; i++) {
    149                         array[i] = list.car();
    150                         if (list.cdr() != NIL)
    151                             list = list.cdr();
    152                     }
    153                     return new SimpleVector(array);
    154                 } else
    155                     return new SimpleVector(list);
    156             }
    157             return new Cons(_BQ_VECTOR_FLAG_.symbolValue(thread), list);
     143          return stream.readSharpLeftParen(c, n, Stream.currentReadtable);
    158144        }
    159145    };
     
    168154
    169155        {
    170             final LispThread thread = LispThread.currentThread();
    171             final Readtable rt = (Readtable) Symbol.CURRENT_READTABLE.symbolValue(thread);
    172             final boolean suppress = Symbol.READ_SUPPRESS.symbolValue(thread) != NIL;
    173             StringBuilder sb = new StringBuilder();
    174             try
    175               {
    176                 while (true) {
    177                   int ch = stream._readChar();
    178                   if (ch < 0)
    179                     break;
    180                   char c = (char) ch; // ### BUG: Codepoint conversion
    181                   if (c == '0' || c == '1')
    182                     sb.append(c);
    183                   else {
    184                     int syntaxType = rt.getSyntaxType(c);
    185                     if (syntaxType == Readtable.SYNTAX_TYPE_WHITESPACE ||
    186                         syntaxType == Readtable.SYNTAX_TYPE_TERMINATING_MACRO) {
    187                       stream._unreadChar(c);
    188                       break;
    189                     } else if (!suppress) {
    190                       String name = LispCharacter.charToName(c);
    191                       if (name == null)
    192                         name = "#\\" + c;
    193                       error(new ReaderError("Illegal element for bit-vector: " + name,
    194                                             stream));
    195                     }
    196                   }
    197                 }
    198               }
    199             catch (java.io.IOException e)
    200               {
    201                 error(new ReaderError("IO error-vector: ",
    202                                       stream));
    203               }
    204             if (suppress)
    205                 return NIL;
    206             if (n >= 0) {
    207                 // n was supplied.
    208                 final int length = sb.length();
    209                 if (length == 0) {
    210                     if (n > 0)
    211                         return error(new ReaderError("No element specified for bit vector of length " +
    212                                                       n + '.',
    213                                                       stream));
    214                 }
    215                 if (n > length) {
    216                     final char c = sb.charAt(length - 1);
    217                     for (int i = length; i < n; i++)
    218                         sb.append(c);
    219                 } else if (n < length) {
    220                     return error(new ReaderError("Bit vector is longer than specified length: #" +
    221                                                   n + '*' + sb.toString(),
    222                                                   stream));
    223                 }
    224             }
    225             return new SimpleBitVector(sb.toString());
     156          return stream.readSharpStar(ignored, n, Stream.currentReadtable);
    226157        }
    227158    };
     
    236167
    237168        {
    238             final LispThread thread = LispThread.currentThread();
    239             if (Symbol.READ_EVAL.symbolValue(thread) == NIL)
    240                 return error(new ReaderError("Can't read #. when *READ-EVAL* is NIL.",
    241                                               stream));
    242             else
    243                 return eval(stream.read(true, NIL, true,
    244                                         thread, Stream.currentReadtable),
    245                             new Environment(), thread);
     169          return stream.readSharpDot(c, n, Stream.currentReadtable);
    246170        }
    247171    };
  • trunk/abcl/src/org/armedbear/lisp/Stream.java

    r12602 r12604  
    734734        return error(new ReaderError("No dispatch function defined for #\\" + c,
    735735                                     this));
     736    }
     737
     738    public LispObject readSharpLeftParen(char c, int n,
     739                                         ReadtableAccessor rta)
     740    {
     741        final LispThread thread = LispThread.currentThread();
     742        LispObject list = readList(true, rta);
     743        if (_BACKQUOTE_COUNT_.symbolValue(thread).zerop()) {
     744            if (n >= 0) {
     745                LispObject[] array = new LispObject[n];
     746                for (int i = 0; i < n; i++) {
     747                    array[i] = list.car();
     748                    if (list.cdr() != NIL)
     749                        list = list.cdr();
     750                }
     751                return new SimpleVector(array);
     752            } else
     753                return new SimpleVector(list);
     754        }
     755        return new Cons(_BQ_VECTOR_FLAG_.symbolValue(thread), list);
     756    }
     757
     758    public LispObject readSharpStar(char ignored, int n,
     759                                    ReadtableAccessor rta)
     760    {
     761        final LispThread thread = LispThread.currentThread();
     762        final Readtable rt = rta.rt(thread);
     763
     764        final boolean suppress =
     765            (Symbol.READ_SUPPRESS.symbolValue(thread) != NIL);
     766        StringBuilder sb = new StringBuilder();
     767        try
     768            {
     769    while (true) {
     770                    int ch = _readChar();
     771                    if (ch < 0)
     772                        break;
     773                    char c = (char) ch;
     774                    if (c == '0' || c == '1')
     775                        sb.append(c);
     776                    else {
     777                        int syntaxType = rt.getSyntaxType(c);
     778                        if (syntaxType == Readtable.SYNTAX_TYPE_WHITESPACE ||
     779                            syntaxType == Readtable.SYNTAX_TYPE_TERMINATING_MACRO) {
     780                            _unreadChar(c);
     781                            break;
     782                        } else if (!suppress) {
     783                            String name = LispCharacter.charToName(c);
     784                            if (name == null)
     785                                name = "#\\" + c;
     786                            error(new ReaderError("Illegal element for bit-vector: " + name,
     787                                                  this));
     788                        }
     789                    }
     790    }
     791            }
     792        catch (java.io.IOException e)
     793            {
     794    error(new ReaderError("IO error: ",
     795              this));
     796    return NIL;
     797            }
     798       
     799        if (suppress)
     800            return NIL;
     801        if (n >= 0) {
     802            // n was supplied.
     803            final int length = sb.length();
     804            if (length == 0) {
     805                if (n > 0)
     806                    return error(new ReaderError("No element specified for bit vector of length " +
     807                                                 n + '.',
     808                                                 this));
     809            }
     810            if (n > length) {
     811                final char c = sb.charAt(length - 1);
     812                for (int i = length; i < n; i++)
     813                    sb.append(c);
     814            } else if (n < length) {
     815                return error(new ReaderError("Bit vector is longer than specified length: #" +
     816                                             n + '*' + sb.toString(),
     817                                             this));
     818            }
     819        }
     820        return new SimpleBitVector(sb.toString());
     821    }
     822
     823
     824    public LispObject readSharpDot(char c, int n,
     825                                   ReadtableAccessor rta)
     826    {
     827        final LispThread thread = LispThread.currentThread();
     828        if (Symbol.READ_EVAL.symbolValue(thread) == NIL)
     829            return error(new ReaderError("Can't read #. when *READ-EVAL* is NIL.",
     830                                         this));
     831        else
     832            return eval(read(true, NIL, true, thread,
     833                             rta),
     834                        new Environment(), thread);
    736835    }
    737836
Note: See TracChangeset for help on using the changeset viewer.