public static Cons getClassInstances(Stella_Object classref, boolean directP) {
    { Surrogate classtype = LoomApi.getInstanceSurrogate(classref);

      if (Logic.classP(classtype)) {
        if (directP) {
          { Cons instances = Logic.allClassInstances(classtype);
            Cons directinstances = Stella.NIL;
            Cons directsubs = NamedDescription.allDirectSubrelations(((NamedDescription)(Logic.getInstance(classref))), true);
            boolean instanceOfSubP = false;

            { Stella_Object i = null;
              Cons iter000 = instances;

              for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
                i = iter000.value;
                instanceOfSubP = false;
                { NamedDescription s = null;
                  Cons iter001 = directsubs;

                  loop001 : for (;!(iter001 == Stella.NIL); iter001 = iter001.rest) {
                    s = ((NamedDescription)(iter001.value));
                    if (LoomApi.instanceOfP(i, s)) {
                      instanceOfSubP = true;
                      break loop001;
                    }
                  }
                }
                if (!(instanceOfSubP)) {
                  directinstances = Cons.cons(i, directinstances);
                }
              }
            }
            return (directinstances);
          }
        }
        else {
          return (Logic.allClassInstances(classtype));
        }
      }
      else {
        return (Stella.NIL);
      }
    }
  }