public static String objectSortString(Stella_Object o) {
    if (o == null) {
      return ("NULL");
    }
    { Surrogate testValue000 = Stella_Object.safePrimaryType(o);

      if (Surrogate.subtypeOfIntegerP(testValue000)) {
        { IntegerWrapper o000 = ((IntegerWrapper)(o));

          return (Native.stringify(o000));
        }
      }
      else if (Surrogate.subtypeOfFloatP(testValue000)) {
        { FloatWrapper o000 = ((FloatWrapper)(o));

          return (Native.stringify(o000));
        }
      }
      else if (Surrogate.subtypeOfBooleanP(testValue000)) {
        { BooleanWrapper o000 = ((BooleanWrapper)(o));

          if (o000 == Stella.FALSE_WRAPPER) {
            return ("FALSE");
          }
          else if (o000 == Stella.TRUE_WRAPPER) {
            return ("TRUE");
          }
          else {
            return ("UNKNOWN");
          }
        }
      }
      else if (Surrogate.subtypeOfStringP(testValue000)) {
        { StringWrapper o000 = ((StringWrapper)(o));

          return (o000.wrapperValue);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_MUTABLE_STRING_WRAPPER)) {
        { MutableStringWrapper o000 = ((MutableStringWrapper)(o));

          return ((o000.wrapperValue).toString());
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_GENERALIZED_SYMBOL)) {
        { GeneralizedSymbol o000 = ((GeneralizedSymbol)(o));

          return (o000.symbolName);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_SKOLEM)) {
        { Skolem o000 = ((Skolem)(o));

          { Stella_Object val = ((Stella_Object)(Stella_Object.accessInContext(o000.variableValue, o000.homeContext, false)));

            if ((val == null) ||
                (val == o000)) {
              return (Native.stringify(o000));
            }
            else {
              return (Logic.objectSortString(((Stella_Object)(Stella_Object.accessInContext(o000.variableValue, o000.homeContext, false)))));
            }
          }
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_LOGIC_OBJECT)) {
        { LogicObject o000 = ((LogicObject)(o));

          return (Logic.objectStringName(o000));
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_CONTEXT)) {
        { Context o000 = ((Context)(o));

          return (o000.contextName());
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_COMPUTED_PROCEDURE)) {
        { ComputedProcedure o000 = ((ComputedProcedure)(o));

          return (o000.surrogateValueInverse.symbolName);
        }
      }
      else {
        if (o.primaryType().homeModule() == Logic.$LOGIC_MODULE$) {
          Stella.STANDARD_WARNING.nativeStream.println("Warning: OBJECT-SORT-STRING: Doesn't specifically handle object `" + o + "' yet!");
        }
        return (Native.stringify(o));
      }
    }
  }