Changeset 5213


Ignore:
Timestamp:
12/20/03 03:05:51 (17 years ago)
Author:
piso
Message:

INSTANCE-SLOT-INDEX

File:
1 edited

Legend:

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

    r5211 r5213  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: Layout.java,v 1.3 2003-12-20 02:16:32 piso Exp $
     5 * $Id: Layout.java,v 1.4 2003-12-20 03:05:51 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2626    private final LispClass cls;
    2727    private final LispObject length;
     28    private final LispObject instanceSlots; // A list of slot names.
    2829
    29     public Layout(LispClass cls, LispObject length)
     30    public Layout(LispClass cls, LispObject length, LispObject instanceSlots)
    3031    {
    3132        this.cls = cls;
    3233        this.length = length;
     34        this.instanceSlots = instanceSlots;
    3335    }
    3436
     
    3941
    4042    // ### make-layout
    41     private static final Primitive2 MAKE_LAYOUT =
    42         new Primitive2("make-layout", PACKAGE_SYS, false)
     43    private static final Primitive3 MAKE_LAYOUT =
     44        new Primitive3("make-layout", PACKAGE_SYS, false)
    4345    {
    44         public LispObject execute(LispObject first, LispObject second)
     46        public LispObject execute(LispObject first, LispObject second,
     47                                  LispObject third)
    4548            throws ConditionThrowable
    4649        {
    4750            try {
    48                 return new Layout((LispClass)first, second);
     51                return new Layout((LispClass)first, second, third);
    4952            }
    5053            catch (ClassCastException e) {
     
    8487        }
    8588    };
     89
     90    // ### instance-slot-index
     91    // instance-slot-index layout slot-name => index
     92    private static final Primitive2 INSTANCE_SLOT_INDEX =
     93        new Primitive2("instance-slot-index", PACKAGE_SYS, false)
     94    {
     95        public LispObject execute(LispObject first, LispObject second)
     96            throws ConditionThrowable
     97        {
     98            try {
     99                LispObject list = ((Layout)first).instanceSlots;
     100                int index = 0;
     101                while (list != NIL) {
     102                    if (list.car() == second)
     103                        return new Fixnum(index);
     104                    list = list.cdr();
     105                    ++index;
     106                }
     107                return NIL;
     108            }
     109            catch (ClassCastException e) {
     110                return signal(new TypeError(first, "layout"));
     111            }
     112        }
     113    };
    86114}
Note: See TracChangeset for help on using the changeset viewer.