Changeset 5069


Ignore:
Timestamp:
12/11/03 19:15:23 (17 years ago)
Author:
piso
Message:

private LispClass? cls => private Layout layout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/StandardObject.java

    r4598 r5069  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: StandardObject.java,v 1.10 2003-11-02 00:27:09 piso Exp $
     5 * $Id: StandardObject.java,v 1.11 2003-12-11 19:15:23 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2424public class StandardObject extends LispObject
    2525{
    26     // Slots.
    27     private LispClass cls;
     26    private Layout layout;
    2827    private LispObject slots; // A simple vector.
    2928
    3029    protected StandardObject()
    3130    {
     31        layout = new Layout(BuiltInClass.STANDARD_OBJECT, Fixnum.ZERO);
    3232    }
    3333
    3434    protected StandardObject(LispClass cls, LispObject slots)
    3535    {
    36         this.cls = cls;
     36        layout = cls.getLayout();
     37        Debug.assertTrue(layout != null);
    3738        this.slots = slots;
    3839    }
     
    4041    public final LispClass getLispClass()
    4142    {
    42         return cls;
     43        return layout.getLispClass();
    4344    }
    4445
     
    5051    public LispObject typeOf()
    5152    {
    52         return cls != null ? cls.getSymbol() : Symbol.STANDARD_OBJECT;
     53        return layout.getLispClass().getSymbol();
    5354    }
    5455
    5556    public LispClass classOf()
    5657    {
    57         return cls != null ? cls : BuiltInClass.STANDARD_OBJECT;
     58        return layout.getLispClass();
    5859    }
    5960
     
    6465        if (type == BuiltInClass.STANDARD_OBJECT)
    6566            return T;
     67        LispClass cls = layout != null ? layout.getLispClass() : null;
    6668        if (cls != null) {
    6769            if (type == cls)
     
    8486    {
    8587        StringBuffer sb = new StringBuffer("#<");
     88        LispClass cls = layout.getLispClass();
    8689        if (cls != null)
    8790            sb.append(cls.getSymbol().getName());
     
    9497    }
    9598
     99    // ### std-instance-layout
     100    private static final Primitive1 STD_INSTANCE_LAYOUT =
     101        new Primitive1("std-instance-layout", PACKAGE_SYS, false)
     102    {
     103        public LispObject execute(LispObject arg) throws ConditionThrowable
     104        {
     105            if (arg instanceof StandardObject)
     106                return ((StandardObject)arg).layout;
     107            throw new ConditionThrowable(new TypeError(arg, "standard object"));
     108        }
     109    };
     110
     111    // ### %set-std-instance-layout
     112    private static final Primitive2 _SET_STD_INSTANCE_LAYOUT =
     113        new Primitive2("%set-std-instance-layout", PACKAGE_SYS, false)
     114    {
     115        public LispObject execute(LispObject first, LispObject second)
     116            throws ConditionThrowable
     117        {
     118            try {
     119                ((StandardObject)first).layout = (Layout) second;
     120                return second;
     121            }
     122            catch (ClassCastException e) {
     123                if (!(first instanceof StandardObject))
     124                    throw new ConditionThrowable(new TypeError(first, "standard object"));
     125                if (!(second instanceof Layout))
     126                    throw new ConditionThrowable(new TypeError(second, "layout"));
     127                // Not reached.
     128                return NIL;
     129            }
     130        }
     131    };
     132
    96133    // ### std-instance-class
    97134    private static final Primitive1 STD_INSTANCE_CLASS =
     
    101138        {
    102139            if (arg instanceof StandardObject)
    103                 return ((StandardObject)arg).cls;
     140                return ((StandardObject)arg).layout.getLispClass();
    104141            throw new ConditionThrowable(new TypeError(arg, "standard object"));
    105         }
    106     };
    107 
    108     // ### %set-std-instance-class
    109     private static final Primitive2 _SET_STD_INSTANCE_CLASS =
    110         new Primitive2("%set-std-instance-class", PACKAGE_SYS, false)
    111     {
    112         public LispObject execute(LispObject first, LispObject second)
    113             throws ConditionThrowable
    114         {
    115             if (first instanceof StandardObject) {
    116                 ((StandardObject)first).cls = (LispClass) second;
    117                 return second;
    118             }
    119             throw new ConditionThrowable(new TypeError(first, "standard object"));
    120142        }
    121143    };
Note: See TracChangeset for help on using the changeset viewer.