* @param type
   * @param errorP
   * @return Stella_Object
   */
  public static Stella_Object coerceValueToType(Stella_Object value, Surrogate type, boolean errorP) {
    if (type == Stella.SGT_STELLA_INTEGER) {
      { Surrogate testValue000 = Stella_Object.safePrimaryType(value);

        if (Surrogate.subtypeOfIntegerP(testValue000)) {
          { IntegerWrapper value000 = ((IntegerWrapper)(value));

            return (value000);
          }
        }
        else if (Surrogate.subtypeOfFloatP(testValue000)) {
          { FloatWrapper value000 = ((FloatWrapper)(value));

            return (IntegerWrapper.wrapInteger(Native.floor(value000.wrapperValue)));
          }
        }
        else if (Surrogate.subtypeOfLongIntegerP(testValue000)) {
          { LongIntegerWrapper value000 = ((LongIntegerWrapper)(value));

            if ((value000.wrapperValue >= Stella.NULL_INTEGER) &&
                (value000.wrapperValue <= Stella.MOST_POSITIVE_INTEGER)) {
              return (value000);
            }
          }
        }
        else {
        }
      }
    }
    else if (type == Stella.SGT_STELLA_FLOAT) {
      return (FloatWrapper.wrapFloat(Stella_Object.coerceValueToFloat(value, errorP)));
    }
    else if (type == Stella.SGT_STELLA_NUMBER) {
      { Surrogate testValue001 = Stella_Object.safePrimaryType(value);

        if (Surrogate.subtypeOfIntegerP(testValue001)) {
          { IntegerWrapper value000 = ((IntegerWrapper)(value));

            return (value000);
          }
        }
        else if (Surrogate.subtypeOfLongIntegerP(testValue001)) {
          { LongIntegerWrapper value000 = ((LongIntegerWrapper)(value));

            return (value000);
          }
        }
        else if (Surrogate.subtypeOfFloatP(testValue001)) {
          { FloatWrapper value000 = ((FloatWrapper)(value));

            return (value000);
          }
        }
        else {
        }
      }
    }
    else if (type == Stella.SGT_STELLA_STRING) {
      return (StringWrapper.wrapString(Stella_Object.coerceValueToString(value, errorP)));
    }
    else if (type == Stella.SGT_STELLA_KEYWORD) {
      { Surrogate testValue002 = Stella_Object.safePrimaryType(value);

        if (Surrogate.subtypeOfP(testValue002, Stella.SGT_STELLA_GENERALIZED_SYMBOL)) {
          { GeneralizedSymbol value000 = ((GeneralizedSymbol)(value));

            return (value000.keywordify());
          }
        }
        else if (Surrogate.subtypeOfStringP(testValue002)) {
          { StringWrapper value000 = ((StringWrapper)(value));

            return (value000.keywordify());
          }
        }
        else {
        }
      }
    }
    else if (type == Stella.SGT_STELLA_SYMBOL) {
      { Surrogate testValue003 = Stella_Object.safePrimaryType(value);

        if (Surrogate.subtypeOfKeywordP(testValue003)) {
          { Keyword value000 = ((Keyword)(value));

            return (Symbol.internSymbol(value000.symbolName));
          }
        }
        else if (Surrogate.subtypeOfSurrogateP(testValue003)) {
          { Surrogate value000 = ((Surrogate)(value));

            return (Symbol.internDerivedSymbol(value000, value000.symbolName));
          }
        }
        else if (Surrogate.subtypeOfSymbolP(testValue003)) {
          { Symbol value000 = ((Symbol)(value));

            return (value000);
          }
        }
        else if (Surrogate.subtypeOfStringP(testValue003)) {
          { StringWrapper value000 = ((StringWrapper)(value));

            return (Symbol.internSymbol(value000.wrapperValue));
          }
        }
        else {
        }
      }
    }
    else if (type == Stella.SGT_STELLA_BOOLEAN) {
      return (Stella_Object.coerceValueToBoolean(value, errorP));
    }
    else if (type == Stella.SGT_STELLA_MODULE) {
      { Module module = Stella_Object.coerceToModule(value, false);

        if (module != null) {
          return (module);
        }
      }
    }
    else {
      if (type == null) {
        return (value);
      }
      else if (Stella_Object.isaP(value, type)) {
        return (value);
      }
      else if (Stella_Object.isaP(value, type.typeToWrappedType())) {
        return (value);
      }
    }
    if (errorP) {
      { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

        stream000.nativeStream.print("coerce-value-to-type: don't know how to coerce `" + value + "' to type `" + type + "'");
        throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
      }
    }
    else {
      return (null);
    }
  }