public static Surrogate lookupSlotref(Surrogate self, Symbol slotname) {
    self = ((Surrogate)(Surrogate.realTypeSpecifier(self)));
    { Stella_Class renamed_Class = ((Stella_Class)(self.surrogateValue));
      Slot slot = null;
      Surrogate slotref = null;

      slot = Symbol.lookupFunction(slotname);
      if (slot == null) {
        slot = Stella_Class.lookupSlot(renamed_Class, slotname);
      }
      if (slot == null) {
        if (renamed_Class != null) {
          return (null);
        }
      }
      else {
        self = slot.slotOwner;
        if (self == null) {
          self = Stella.SGT_STELLA_ANY;
        }
        slotref = slot.slotSlotref;
      }
      if (slotref == null) {
        { Object old$Module$000 = Stella.$MODULE$.get();
          Object old$Context$000 = Stella.$CONTEXT$.get();

          try {
            Native.setSpecial(Stella.$MODULE$, ((slot != null) ? slot.homeModule() : ((Module)(((Symbol)(slotname.permanentify())).homeContext))));
            Native.setSpecial(Stella.$CONTEXT$, ((Module)(Stella.$MODULE$.get())));
            slotref = Stella.internSlotref(self.symbolName, slotname.symbolName);

          } finally {
            Stella.$CONTEXT$.set(old$Context$000);
            Stella.$MODULE$.set(old$Module$000);
          }
        }
        slotref.surrogateValue = slot;
        if (slot != null) {
          slot.slotSlotref = slotref;
        }
      }
      return (slotref);
    }
  }