* @param options
   * @param legaloptionsAtypes
   * @param coercionerrorP
   * @param allowotherkeysP
   * @return PropertyList
   */
  public static PropertyList parseOptions(Stella_Object options, Cons legaloptionsAtypes, boolean coercionerrorP, boolean allowotherkeysP) {
    { PropertyList self000 = PropertyList.newPropertyList();

      self000.thePlist = legaloptionsAtypes;
      { PropertyList legaloptions = self000;
        PropertyList parsedoptions = null;
        Surrogate type = null;
        Stella_Object coercedvalue = null;

        { Surrogate testValue000 = Stella_Object.safePrimaryType(options);

          if (testValue000 == Stella.SGT_STELLA_CONS) {
            { Cons options000 = ((Cons)(options));

              if ((((options000.length()) % 2) == 1)) {
                { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

                  stream000.nativeStream.print("Odd-length options list: `" + options000 + "'");
                  throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
                }
              }
              { PropertyList self003 = PropertyList.newPropertyList();

                self003.thePlist = options000;
                parsedoptions = self003;
              }
            }
          }
          else if (Surrogate.subtypeOfP(testValue000, Stella.SGT_STELLA_PROPERTY_LIST)) {
            { PropertyList options000 = ((PropertyList)(options));

              parsedoptions = options000;
            }
          }
          else {
            { OutputStringStream stream001 = OutputStringStream.newOutputStringStream();

              stream001.nativeStream.print("Illegal options specification: `" + options + "'");
              throw ((StellaException)(StellaException.newStellaException(stream001.theStringReader()).fillInStackTrace()));
            }
          }
        }
        if (legaloptions != null) {
          { Stella_Object key = null;
            Stella_Object value = null;
            Cons iter000 = parsedoptions.thePlist;

            for (;!(iter000 == Stella.NIL); iter000 = iter000.rest.rest) {
              key = iter000.value;
              value = iter000.rest.value;
              type = ((Surrogate)(legaloptions.lookup(key)));
              if ((type == null) &&
                  (!allowotherkeysP)) {
                { OutputStringStream stream002 = OutputStringStream.newOutputStringStream();

                  stream002.nativeStream.print("Illegal option: `" + key + "'");
                  throw ((StellaException)(StellaException.newStellaException(stream002.theStringReader()).fillInStackTrace()));
                }
              }
              if (!((type == Stella.SGT_STELLA_IDENTITY) ||
                  (value == null))) {
                coercedvalue = Stella_Object.coerceValueToType(value, type, coercionerrorP);
                parsedoptions.insertAt(key, coercedvalue);
              }
            }
          }
        }
        return (parsedoptions);
      }
    }
  }