Changeset 11310


Ignore:
Timestamp:
09/12/08 21:40:40 (15 years ago)
Author:
ehuelsmann
Message:

Fold 2 code paths which essentially differ only by 1 conditional in _let().

File:
1 edited

Legend:

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

    r11297 r11310  
    133133          }
    134134        Environment ext = new Environment(env);
    135         if (sequential)
    136           {
    137             // LET*
    138             while (varList != NIL)
    139               {
    140                 final Symbol symbol;
    141                 LispObject value;
    142                 LispObject obj = varList.car();
    143                 if (obj instanceof Cons)
    144                   {
    145                     if (obj.length() > 2)
    146                       return error(new LispError("The LET* binding specification " +
    147                                                   obj.writeToString() +
    148                                                   " is invalid."));
    149                     try
    150                       {
    151                         symbol = (Symbol) ((Cons)obj).car;
    152                       }
    153                     catch (ClassCastException e)
    154                       {
    155                         return type_error(((Cons)obj).car, Symbol.SYMBOL);
    156                       }
    157                     value = eval(obj.cadr(), ext, thread);
    158                   }
    159                 else
    160                   {
    161                     try
    162                       {
    163                         symbol = (Symbol) obj;
    164                       }
    165                     catch (ClassCastException e)
    166                       {
    167                         return type_error(obj, Symbol.SYMBOL);
    168                       }
    169                     value = NIL;
    170                   }
    171                 if (specials != NIL && memq(symbol, specials))
    172                   {
    173                     thread.bindSpecial(symbol, value);
    174                     ext.declareSpecial(symbol);
    175                   }
    176                 else if (symbol.isSpecialVariable())
    177                   {
    178                     thread.bindSpecial(symbol, value);
    179                   }
    180                 else
    181                   ext.bind(symbol, value);
    182                 varList = ((Cons)varList).cdr;
    183               }
    184           }
    185         else
    186           {
    187             // LET
    188             final int length = varList.length();
    189             LispObject[] vals = new LispObject[length];
    190             for (int i = 0; i < length; i++)
    191               {
    192                 LispObject obj = ((Cons)varList).car;
    193                 if (obj instanceof Cons)
    194                   {
    195                     if (obj.length() > 2)
    196                       return error(new LispError("The LET binding specification " +
    197                                                   obj.writeToString() +
    198                                                   " is invalid."));
    199                     vals[i] = eval(obj.cadr(), env, thread);
    200                   }
    201                 else
    202                   vals[i] = NIL;
    203                 varList = ((Cons)varList).cdr;
    204               }
    205             varList = args.car();
    206             int i = 0;
    207             while (varList != NIL)
    208               {
    209                 final Symbol symbol;
    210                 LispObject obj = varList.car();
    211                 if (obj instanceof Cons)
    212                   {
    213                     try
    214                       {
    215                         symbol = (Symbol) ((Cons)obj).car;
    216                       }
    217                     catch (ClassCastException e)
    218                       {
    219                         return type_error(((Cons)obj).car, Symbol.SYMBOL);
    220                       }
    221                   }
    222                 else
    223                   {
    224                     try
    225                       {
    226                         symbol = (Symbol) obj;
    227                       }
    228                     catch (ClassCastException e)
    229                       {
    230                         return type_error(obj, Symbol.SYMBOL);
    231                       }
    232                   }
    233                 LispObject value = vals[i];
    234                 if (specials != NIL && memq(symbol, specials))
    235                   {
    236                     thread.bindSpecial(symbol, value);
    237                     ext.declareSpecial(symbol);
    238                   }
    239                 else if (symbol.isSpecialVariable())
    240                   {
    241                     thread.bindSpecial(symbol, value);
    242                   }
    243                 else
    244                   ext.bind(symbol, value);
    245                 varList = ((Cons)varList).cdr;
    246                 ++i;
    247               }
     135        while (varList != NIL)
     136          {
     137            final Symbol symbol;
     138            LispObject value;
     139            LispObject obj = varList.car();
     140            if (obj instanceof Cons)
     141              {
     142                if (obj.length() > 2)
     143                  return error(new LispError("The LET* binding specification " +
     144                                              obj.writeToString() +
     145                                              " is invalid."));
     146                try
     147                  {
     148                    symbol = (Symbol) ((Cons)obj).car;
     149                  }
     150                catch (ClassCastException e)
     151                  {
     152                    return type_error(((Cons)obj).car, Symbol.SYMBOL);
     153                  }
     154                value = eval(obj.cadr(), sequential ? ext : env, thread);
     155              }
     156            else
     157              {
     158                try
     159                  {
     160                    symbol = (Symbol) obj;
     161                  }
     162                catch (ClassCastException e)
     163                  {
     164                    return type_error(obj, Symbol.SYMBOL);
     165                  }
     166                value = NIL;
     167              }
     168            if (specials != NIL && memq(symbol, specials))
     169              {
     170                thread.bindSpecial(symbol, value);
     171                ext.declareSpecial(symbol);
     172              }
     173            else if (symbol.isSpecialVariable())
     174              {
     175                thread.bindSpecial(symbol, value);
     176              }
     177            else
     178              ext.bind(symbol, value);
     179            varList = ((Cons)varList).cdr;
    248180          }
    249181        // Make sure free special declarations are visible in the body.
Note: See TracChangeset for help on using the changeset viewer.