Changeset 14134


Ignore:
Timestamp:
08/25/12 21:14:49 (8 years ago)
Author:
rschlatte
Message:

Handle instances of subclasses of standard-slot-definition in accessors

  • Subclasses of standard-(direct|effective)-slot-definition are of Java class StandardObject? and might have different class layout.
  • Keep the fast, fixed-indexing path for objects of Java class SlotDefinition?, handle other objects via slot-name-based indexing.
  • Thanks to Stas Boukarev and Pascal Costanza for error reports and diagnosis.
Location:
trunk/abcl/src/org/armedbear/lisp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/SlotClass.java

    r13956 r14134  
    171171        while (tail != NIL) {
    172172            SlotDefinition slotDefinition = (SlotDefinition) tail.car();
    173             slotDefinition.setLocation(i);
    174             instanceSlotNames[i++] = slotDefinition.getName();
     173            SlotDefinition.SET_SLOT_DEFINITION_LOCATION
     174              .execute(slotDefinition, Fixnum.getInstance(i));
     175            instanceSlotNames[i++] = SlotDefinition._SLOT_DEFINITION_NAME
     176              .execute(slotDefinition);
    175177            tail = tail.cdr();
    176178        }
  • trunk/abcl/src/org/armedbear/lisp/SlotDefinition.java

    r13947 r14134  
    4848
    4949    public SlotDefinition(StandardClass clazz) {
     50      // clazz layout needs to have SlotDefinitionClass layout as prefix
     51      // or indexed slot access won't work
    5052        super(clazz, clazz.getClassLayout().getLength());
    5153        slots[SlotDefinitionClass.SLOT_INDEX_LOCATION] = NIL;
     
    5355
    5456    public SlotDefinition(StandardClass clazz, LispObject name) {
     57      // clazz layout needs to have SlotDefinitionClass layout as prefix
     58      // or indexed slot access won't work
    5559        super(clazz, clazz.getClassLayout().getLength());
    5660        slots[SlotDefinitionClass.SLOT_INDEX_NAME] = name;
     
    119123
    120124  public static StandardObject checkSlotDefinition(LispObject obj) {
    121           if (obj instanceof StandardObject) return (StandardObject)obj;
    122       return (StandardObject)type_error(obj, Symbol.SLOT_DEFINITION);
    123   }
    124 
    125   public final LispObject getName()
    126   {
    127     return slots[SlotDefinitionClass.SLOT_INDEX_NAME];
    128   }
    129 
    130   public final void setLocation(int i)
    131   {
    132     slots[SlotDefinitionClass.SLOT_INDEX_LOCATION] = Fixnum.getInstance(i);
     125    if (obj instanceof StandardObject) return (StandardObject)obj;
     126    return (StandardObject)type_error(obj, Symbol.SLOT_DEFINITION);
    133127  }
    134128
     
    150144    = new pf_make_slot_definition();
    151145  @DocString(name="make-slot-definition",
    152              args="&optional class")
     146             args="&optional class",
     147             doc="Cannot be called with user-defined subclasses of standard-slot-definition.")
    153148  private static final class pf_make_slot_definition extends Primitive
    154149  {
     
    169164  };
    170165
    171   private static final Primitive _SLOT_DEFINITION_NAME
     166  static final Primitive _SLOT_DEFINITION_NAME
    172167    = new pf__slot_definition_name();
    173168  @DocString(name="%slot-definition-name")
     
    181176    public LispObject execute(LispObject arg)
    182177    {
    183       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_NAME];
     178      StandardObject o = checkSlotDefinition(arg);
     179      if (o instanceof SlotDefinition)
     180        return o.slots[SlotDefinitionClass.SLOT_INDEX_NAME];
     181      else
     182        return o.getInstanceSlotValue(Symbol.NAME);
    184183    }
    185184  };
     
    199198    public LispObject execute(LispObject first, LispObject second)
    200199    {
    201       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_NAME] = second;
     200      StandardObject o = checkSlotDefinition(first);
     201      if (o instanceof SlotDefinition)
     202        o.slots[SlotDefinitionClass.SLOT_INDEX_NAME] = second;
     203      else
     204        o.setInstanceSlotValue(Symbol.NAME, second);
    202205      return second;
    203206    }
     
    216219    public LispObject execute(LispObject arg)
    217220    {
    218       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_INITFUNCTION];
     221      StandardObject o = checkSlotDefinition(arg);
     222      if (o instanceof SlotDefinition)
     223        return o.slots[SlotDefinitionClass.SLOT_INDEX_INITFUNCTION];
     224      else
     225        return o.getInstanceSlotValue(Symbol.INITFUNCTION);
    219226    }
    220227  };
     
    234241    public LispObject execute(LispObject first, LispObject second)
    235242    {
    236       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_INITFUNCTION] = second;
     243      StandardObject o = checkSlotDefinition(first);
     244      if (o instanceof SlotDefinition)
     245        o.slots[SlotDefinitionClass.SLOT_INDEX_INITFUNCTION] = second;
     246      else
     247        o.setInstanceSlotValue(Symbol.INITFUNCTION, second);
    237248      return second;
    238249    }
     
    247258    pf__slot_definition_initform()
    248259    {
    249       super("%slot-definition-initform", PACKAGE_SYS, true,
    250             "slot-definition");
    251     }
    252     @Override
    253     public LispObject execute(LispObject arg)
    254     {
    255       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_INITFORM];
     260      super("%slot-definition-initform", PACKAGE_SYS, true, "slot-definition");
     261    }
     262    @Override
     263    public LispObject execute(LispObject arg)
     264    {
     265      StandardObject o = checkSlotDefinition(arg);
     266      if (o instanceof SlotDefinition)
     267        return o.slots[SlotDefinitionClass.SLOT_INDEX_INITFORM];
     268      else
     269        return o.getInstanceSlotValue(Symbol.INITFORM);
    256270    }
    257271  };
     
    271285    public LispObject execute(LispObject first, LispObject second)
    272286    {
    273       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_INITFORM] = second;
     287      StandardObject o = checkSlotDefinition(first);
     288      if (o instanceof SlotDefinition)
     289        o.slots[SlotDefinitionClass.SLOT_INDEX_INITFORM] = second;
     290      else
     291        o.setInstanceSlotValue(Symbol.INITFORM, second);
    274292      return second;
    275293    }
     
    288306    public LispObject execute(LispObject arg)
    289307    {
    290       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_INITARGS];
     308      StandardObject o = checkSlotDefinition(arg);
     309      if (o instanceof SlotDefinition)
     310        return o.slots[SlotDefinitionClass.SLOT_INDEX_INITARGS];
     311      else
     312        return o.getInstanceSlotValue(Symbol.INITARGS);
    291313    }
    292314  };
     
    306328    public LispObject execute(LispObject first, LispObject second)
    307329    {
    308       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_INITARGS] = second;
     330      StandardObject o = checkSlotDefinition(first);
     331      if (o instanceof SlotDefinition)
     332        o.slots[SlotDefinitionClass.SLOT_INDEX_INITARGS] = second;
     333      else
     334        o.setInstanceSlotValue(Symbol.INITARGS, second);
    309335      return second;
    310336    }
     
    324350    public LispObject execute(LispObject arg)
    325351    {
    326       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_READERS];
     352      StandardObject o = checkSlotDefinition(arg);
     353      if (o instanceof SlotDefinition)
     354        return o.slots[SlotDefinitionClass.SLOT_INDEX_READERS];
     355      else
     356        return o.getInstanceSlotValue(Symbol.READERS);
    327357    }
    328358  };
     
    342372    public LispObject execute(LispObject first, LispObject second)
    343373    {
    344       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_READERS] = second;
     374      StandardObject o = checkSlotDefinition(first);
     375      if (o instanceof SlotDefinition)
     376        o.slots[SlotDefinitionClass.SLOT_INDEX_READERS] = second;
     377      else
     378        o.setInstanceSlotValue(Symbol.READERS, second);
    345379      return second;
    346380    }
     
    361395    public LispObject execute(LispObject arg)
    362396    {
    363       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_WRITERS];
     397      StandardObject o = checkSlotDefinition(arg);
     398      if (o instanceof SlotDefinition)
     399        return o.slots[SlotDefinitionClass.SLOT_INDEX_WRITERS];
     400      else
     401        return o.getInstanceSlotValue(Symbol.WRITERS);
    364402    }
    365403  };
     
    379417    public LispObject execute(LispObject first, LispObject second)
    380418    {
    381       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_WRITERS] = second;
     419      StandardObject o = checkSlotDefinition(first);
     420      if (o instanceof SlotDefinition)
     421        o.slots[SlotDefinitionClass.SLOT_INDEX_WRITERS] = second;
     422      else
     423        o.setInstanceSlotValue(Symbol.WRITERS, second);
    382424      return second;
    383425    }
     
    398440    public LispObject execute(LispObject arg)
    399441    {
    400       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION];
     442      StandardObject o = checkSlotDefinition(arg);
     443      if (o instanceof SlotDefinition)
     444        return o.slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION];
     445      else
     446        return o.getInstanceSlotValue(Symbol.ALLOCATION);
    401447    }
    402448  };
     
    416462    public LispObject execute(LispObject first, LispObject second)
    417463    {
    418       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION] = second;
     464      StandardObject o = checkSlotDefinition(first);
     465      if (o instanceof SlotDefinition)
     466        o.slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION] = second;
     467      else
     468        o.setInstanceSlotValue(Symbol.ALLOCATION, second);
    419469      return second;
    420470    }
     
    435485    public LispObject execute(LispObject arg)
    436486    {
    437       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION_CLASS];
     487      StandardObject o = checkSlotDefinition(arg);
     488      if (o instanceof SlotDefinition)
     489        return o.slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION_CLASS];
     490      else
     491        return o.getInstanceSlotValue(Symbol.ALLOCATION_CLASS);
    438492    }
    439493  };
     
    453507    public LispObject execute(LispObject first, LispObject second)
    454508    {
    455       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION_CLASS] = second;
     509      StandardObject o = checkSlotDefinition(first);
     510      if (o instanceof SlotDefinition)
     511        o.slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION_CLASS] = second;
     512      else
     513        o.setInstanceSlotValue(Symbol.ALLOCATION_CLASS, second);
    456514      return second;
    457515    }
     
    470528    public LispObject execute(LispObject arg)
    471529    {
    472       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_LOCATION];
    473     }
    474   };
    475 
    476   private static final Primitive SET_SLOT_DEFINITION_LOCATION
     530      StandardObject o = checkSlotDefinition(arg);
     531      if (o instanceof SlotDefinition)
     532        return o.slots[SlotDefinitionClass.SLOT_INDEX_LOCATION];
     533      else
     534        return o.getInstanceSlotValue(Symbol.LOCATION);
     535    }
     536  };
     537
     538  static final Primitive SET_SLOT_DEFINITION_LOCATION
    477539    = new pf_set_slot_definition_location();
    478540  @DocString(name="set-slot-definition-location",
     
    488550    public LispObject execute(LispObject first, LispObject second)
    489551    {
    490       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_LOCATION] = second;
     552      StandardObject o = checkSlotDefinition(first);
     553      if (o instanceof SlotDefinition)
     554        o.slots[SlotDefinitionClass.SLOT_INDEX_LOCATION] = second;
     555      else
     556        o.setInstanceSlotValue(Symbol.LOCATION, second);
    491557      return second;
    492558    }
     
    505571    public LispObject execute(LispObject arg)
    506572    {
    507       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_TYPE];
     573      StandardObject o = checkSlotDefinition(arg);
     574      if (o instanceof SlotDefinition)
     575        return o.slots[SlotDefinitionClass.SLOT_INDEX_TYPE];
     576      else
     577        return o.getInstanceSlotValue(Symbol._TYPE);
    508578    }
    509579  };
     
    523593    public LispObject execute(LispObject first, LispObject second)
    524594    {
    525       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_TYPE] = second;
     595      StandardObject o = checkSlotDefinition(first);
     596      if (o instanceof SlotDefinition)
     597        o.slots[SlotDefinitionClass.SLOT_INDEX_TYPE] = second;
     598      else
     599        o.setInstanceSlotValue(Symbol._TYPE, second);
    526600      return second;
    527601    }
     
    540614    public LispObject execute(LispObject arg)
    541615    {
    542       return checkSlotDefinition(arg).slots[SlotDefinitionClass.SLOT_INDEX_DOCUMENTATION];
     616      StandardObject o = checkSlotDefinition(arg);
     617      if (o instanceof SlotDefinition)
     618        return o.slots[SlotDefinitionClass.SLOT_INDEX_DOCUMENTATION];
     619      else
     620        return o.getInstanceSlotValue(Symbol._DOCUMENTATION);
    543621    }
    544622  };
     
    558636    public LispObject execute(LispObject first, LispObject second)
    559637    {
    560       checkSlotDefinition(first).slots[SlotDefinitionClass.SLOT_INDEX_DOCUMENTATION] = second;
     638      StandardObject o = checkSlotDefinition(first);
     639      if (o instanceof SlotDefinition)
     640        o.slots[SlotDefinitionClass.SLOT_INDEX_DOCUMENTATION] = second;
     641      else
     642        o.setInstanceSlotValue(Symbol._DOCUMENTATION, second);
    561643      return second;
    562644    }
  • trunk/abcl/src/org/armedbear/lisp/SlotDefinitionClass.java

    r13947 r14134  
    5151
    5252    /**
    53      * For internal use only. This constructor hardcodes the layout of the class, and can't be used
    54      * to create arbitrary subclasses of slot-definition.
     53     * For internal use only. This constructor hardcodes the layout of
     54     * the class, and can't be used to create arbitrary subclasses of
     55     * slot-definition since new slots get added at the beginning.
    5556     */
    5657    public SlotDefinitionClass(Symbol symbol, LispObject cpl) {
     
    5859        Package pkg = PACKAGE_SYS;
    5960        LispObject[] instanceSlotNames = {
    60             pkg.intern("NAME"),
    61             pkg.intern("INITFUNCTION"),
    62             pkg.intern("INITFORM"),
    63             pkg.intern("INITARGS"),
    64             pkg.intern("READERS"),
    65             pkg.intern("WRITERS"),
    66             pkg.intern("ALLOCATION"),
    67             pkg.intern("ALLOCATION-CLASS"),
    68             pkg.intern("LOCATION"),
     61            Symbol.NAME,
     62            Symbol.INITFUNCTION,
     63            Symbol.INITFORM,
     64            Symbol.INITARGS,
     65            Symbol.READERS,
     66            Symbol.WRITERS,
     67            Symbol.ALLOCATION,
     68            Symbol.ALLOCATION_CLASS,
     69            Symbol.LOCATION,
    6970            Symbol._TYPE,
    7071            Symbol._DOCUMENTATION
  • trunk/abcl/src/org/armedbear/lisp/Symbol.java

    r14132 r14134  
    31113111
    31123112  // Internal symbols in SYSTEM package.
     3113  public static final Symbol ALLOCATION =
     3114    PACKAGE_SYS.addInternalSymbol("ALLOCATION");
     3115  public static final Symbol ALLOCATION_CLASS =
     3116    PACKAGE_SYS.addInternalSymbol("ALLOCATION-CLASS");
    31133117  public static final Symbol BACKQUOTE_MACRO =
    31143118    PACKAGE_SYS.addInternalSymbol("BACKQUOTE-MACRO");
     
    31383142  public static final Symbol _GENERIC_FUNCTION =
    31393143    PACKAGE_SYS.addInternalSymbol("%GENERIC-FUNCTION");
     3144  public static final Symbol INITARGS =
     3145    PACKAGE_SYS.addInternalSymbol("INITARGS");
     3146  public static final Symbol INITFORM =
     3147    PACKAGE_SYS.addInternalSymbol("INITFORM");
     3148  public static final Symbol INITFUNCTION =
     3149    PACKAGE_SYS.addInternalSymbol("INITFUNCTION");
    31403150  public static final Symbol INSTANCE =
    31413151    PACKAGE_SYS.addInternalSymbol("INSTANCE");
     3152  public static final Symbol JAVA_STACK_FRAME =
     3153    PACKAGE_SYS.addInternalSymbol("JAVA-STACK-FRAME");
    31423154  public static final Symbol KEYWORDS =
    31433155    PACKAGE_SYS.addInternalSymbol("KEYWORDS");
     3156  public static final Symbol LAMBDA_LIST =
     3157    PACKAGE_SYS.addInternalSymbol("LAMBDA-LIST");
     3158  public static final Symbol LISP_STACK_FRAME =
     3159    PACKAGE_SYS.addInternalSymbol("LISP-STACK-FRAME");
     3160  public static final Symbol LOCATION =
     3161    PACKAGE_SYS.addInternalSymbol("LOCATION");
    31443162  public static final Symbol MACROEXPAND_MACRO =
    31453163    PACKAGE_SYS.addInternalSymbol("MACROEXPAND-MACRO");
     
    31583176  public static final Symbol QUALIFIERS =
    31593177    PACKAGE_SYS.addInternalSymbol("QUALIFIERS");
     3178  public static final Symbol READERS =
     3179    PACKAGE_SYS.addInternalSymbol("READERS");
    31603180  public static final Symbol _SOURCE =
    31613181    PACKAGE_SYS.addInternalSymbol("%SOURCE");
     
    31743194  public static final Symbol _TYPE =
    31753195    PACKAGE_SYS.addInternalSymbol("%TYPE");
    3176   public static final Symbol LISP_STACK_FRAME =
    3177     PACKAGE_SYS.addInternalSymbol("LISP-STACK-FRAME");
    3178   public static final Symbol JAVA_STACK_FRAME =
    3179     PACKAGE_SYS.addInternalSymbol("JAVA-STACK-FRAME");
    3180   public static final Symbol LAMBDA_LIST =
    3181     PACKAGE_SYS.addInternalSymbol("LAMBDA-LIST");
     3196  public static final Symbol WRITERS =
     3197    PACKAGE_SYS.addInternalSymbol("WRITERS");
    31823198
    31833199  // CDR6
Note: See TracChangeset for help on using the changeset viewer.