static Cons sequenceToConsList(Stella_Object sequence) {
    { Surrogate testValue000 = Stella_Object.safePrimaryType(sequence);

      if (testValue000 == Logic.SGT_STELLA_CONS) {
        { Cons sequence000 = ((Cons)(sequence));

          return (sequence000);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_LIST)) {
        { List sequence000 = ((List)(sequence));

          return (sequence000.theConsList);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_VECTOR)) {
        { Vector sequence000 = ((Vector)(sequence));

          { Cons result = Stella.NIL;

            { int i = Stella.NULL_INTEGER;
              int iter000 = 0;
              int upperBound000 = sequence000.length();
              Cons collect000 = null;

              for (;iter000 <= upperBound000; iter000 = iter000 + 1) {
                i = iter000;
                if (collect000 == null) {
                  {
                    collect000 = Cons.cons((sequence000.theArray)[i], Stella.NIL);
                    if (result == Stella.NIL) {
                      result = collect000;
                    }
                    else {
                      Cons.addConsToEndOfConsList(result, collect000);
                    }
                  }
                }
                else {
                  {
                    collect000.rest = Cons.cons((sequence000.theArray)[i], Stella.NIL);
                    collect000 = collect000.rest;
                  }
                }
              }
            }
            return (result);
          }
        }
      }
      else {
        { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

          stream000.nativeStream.print("Don't know how to convert object of type `" + sequence.primaryType() + "' into a cons list.");
          throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
        }
      }
    }
  }