public static Stella_Object helpCreateLogicInstance(Surrogate name, Surrogate type) {
    Logic.enforceCodeOnly();
    if (type == null) {
      type = ((Surrogate)(Logic.$DEFAULTCREATIONTYPE$.get()));
    }
    { NamedDescription description = ((type != null) ? Logic.getDescription(type) : ((NamedDescription)(null)));
      Stella_Class nativeclass = null;
      Stella_Object newobject = null;

      if ((type != null) &&
          (description == null)) {
        { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

          stream000.nativeStream.print("Can't create an instance of the undefined class `" + type.symbolName + "'");
          throw ((UndefinedClassException)(UndefinedClassException.newUndefinedClassException(stream000.theStringReader()).fillInStackTrace()));
        }
      }
      if (description == null) {
        newobject = LogicObject.newLogicObject();
      }
      else {
        {
          if (!NamedDescription.classDescriptionP(description)) {
            { OutputStringStream stream001 = OutputStringStream.newOutputStringStream();

              stream001.nativeStream.print("Can't create an instance of a relation: `" + type.symbolName + "'");
              throw ((ObjectNotClassException)(ObjectNotClassException.newObjectNotClassException(stream001.theStringReader()).fillInStackTrace()));
            }
          }
          nativeclass = ((Stella_Class)(description.nativeRelation()));
          if ((nativeclass == null) ||
              nativeclass.abstractP) {
            newobject = LogicObject.newLogicObject();
          }
          else if (Surrogate.subtypeOfP(nativeclass.classType, Logic.SGT_STELLA_THING)) {
            newobject = Surrogate.createObject(type, Stella.NIL);
          }
          else {
            { OutputStringStream stream002 = OutputStringStream.newOutputStringStream();

              {
                stream002.nativeStream.println("Can't create an instance of the class `" + type.symbolName + "'");
                stream002.nativeStream.print("   because it doesn't inherit the class 'THING'.");
              }
;
              throw ((BadArgumentException)(BadArgumentException.newBadArgumentException(stream002.theStringReader()).fillInStackTrace()));
            }
          }
        }
      }
      if (name != null) {
        if (name.surrogateValue != null) {
          { ObjectAlreadyExistsException self008 = ObjectAlreadyExistsException.newObjectAlreadyExistsException("An object named " + name.symbolName + " already exists.");

            self008.existingObject = name.surrogateValue;
            { ObjectAlreadyExistsException error = self008;

              throw ((ObjectAlreadyExistsException)(error.fillInStackTrace()));
            }
          }
        }
        name.surrogateValue = newobject;
        { Surrogate testValue000 = Stella_Object.safePrimaryType(newobject);

          if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_LOGIC_OBJECT)) {
            { LogicObject newobject000 = ((LogicObject)(newobject));

              newobject000.surrogateValueInverse = name;
            }
          }
          else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_THING)) {
            { Thing newobject000 = ((Thing)(newobject));

              newobject000.surrogateValueInverse = name;
            }
          }
          else {
            { OutputStringStream stream003 = OutputStringStream.newOutputStringStream();

              stream003.nativeStream.print("`" + testValue000 + "' is not a valid case option");
              throw ((StellaException)(StellaException.newStellaException(stream003.theStringReader()).fillInStackTrace()));
            }
          }
        }
      }
      return (newobject);
    }
  }