1 21 22 package org.armedbear.lisp; 23 24 public final class Layout extends LispObject 25 { 26 private final LispClass cls; 27 private final LispObject length; 28 private final LispObject instanceSlots; 30 public Layout(LispClass cls, LispObject length, LispObject instanceSlots) 31 { 32 this.cls = cls; 33 this.length = length; 34 this.instanceSlots = instanceSlots; 35 } 36 37 public LispClass getLispClass() 38 { 39 return cls; 40 } 41 42 private static final Primitive3 MAKE_LAYOUT = 44 new Primitive3("make-layout", PACKAGE_SYS, false) 45 { 46 public LispObject execute(LispObject first, LispObject second, 47 LispObject third) 48 throws ConditionThrowable 49 { 50 try { 51 return new Layout((LispClass)first, second, third); 52 } 53 catch (ClassCastException e) { 54 return signal(new TypeError(first, "class")); 55 } 56 } 57 58 }; 59 60 private static final Primitive1 LAYOUT_CLASS = 62 new Primitive1("layout-class", PACKAGE_SYS, false) 63 { 64 public LispObject execute(LispObject arg) throws ConditionThrowable 65 { 66 try { 67 return ((Layout)arg).cls; 68 } 69 catch (ClassCastException e) { 70 return signal(new TypeError(arg, "layout")); 71 } 72 } 73 }; 74 75 private static final Primitive1 LAYOUT_LENGTH = 77 new Primitive1("layout-length", PACKAGE_SYS, false) 78 { 79 public LispObject execute(LispObject arg) throws ConditionThrowable 80 { 81 try { 82 return ((Layout)arg).length; 83 } 84 catch (ClassCastException e) { 85 return signal(new TypeError(arg, "layout")); 86 } 87 } 88 }; 89 90 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 }; 114 } 115 | Popular Tags |