Exemplo n.º 1
0
 @Override
 public String printObject() {
   try {
     final LispThread thread = LispThread.currentThread();
     // FIXME
     if (typep(Symbol.RESTART) != NIL) {
       Symbol PRINT_RESTART = PACKAGE_SYS.intern("PRINT-RESTART");
       LispObject fun = PRINT_RESTART.getSymbolFunction();
       StringOutputStream stream = new StringOutputStream();
       thread.execute(fun, this, stream);
       return stream.getString().getStringValue();
     }
     if (_PRINT_STRUCTURE_.symbolValue(thread) == NIL)
       return unreadableString(structureClass.getName().printObject());
     int maxLevel = Integer.MAX_VALUE;
     LispObject printLevel = Symbol.PRINT_LEVEL.symbolValue(thread);
     if (printLevel instanceof Fixnum) maxLevel = ((Fixnum) printLevel).value;
     LispObject currentPrintLevel = _CURRENT_PRINT_LEVEL_.symbolValue(thread);
     int currentLevel = Fixnum.getValue(currentPrintLevel);
     if (currentLevel >= maxLevel && slots.length > 0) return "#";
     StringBuilder sb = new StringBuilder("#S(");
     sb.append(structureClass.getName().printObject());
     if (currentLevel < maxLevel) {
       LispObject effectiveSlots = structureClass.getSlotDefinitions();
       LispObject[] effectiveSlotsArray = effectiveSlots.copyToArray();
       Debug.assertTrue(effectiveSlotsArray.length == slots.length);
       final LispObject printLength = Symbol.PRINT_LENGTH.symbolValue(thread);
       final int limit;
       if (printLength instanceof Fixnum)
         limit = Math.min(slots.length, ((Fixnum) printLength).value);
       else limit = slots.length;
       final boolean printCircle = (Symbol.PRINT_CIRCLE.symbolValue(thread) != NIL);
       for (int i = 0; i < limit; i++) {
         sb.append(' ');
         SimpleVector slotDefinition = (SimpleVector) effectiveSlotsArray[i];
         // FIXME AREF(1)
         LispObject slotName = slotDefinition.AREF(1);
         Debug.assertTrue(slotName instanceof Symbol);
         sb.append(':');
         sb.append(((Symbol) slotName).name.getStringValue());
         sb.append(' ');
         if (printCircle) {
           StringOutputStream stream = new StringOutputStream();
           thread.execute(Symbol.OUTPUT_OBJECT.getSymbolFunction(), slots[i], stream);
           sb.append(stream.getString().getStringValue());
         } else sb.append(slots[i].printObject());
       }
       if (limit < slots.length) sb.append(" ...");
     }
     sb.append(')');
     return sb.toString();
   } catch (StackOverflowError e) {
     error(new StorageCondition("Stack overflow."));
     return null; // Not reached.
   }
 }
Exemplo n.º 2
0
 protected int getSlotIndex(LispObject slotName) {
   LispObject effectiveSlots = structureClass.getSlotDefinitions();
   LispObject[] effectiveSlotsArray = effectiveSlots.copyToArray();
   for (int i = 0; i < slots.length; i++) {
     SimpleVector slotDefinition = (SimpleVector) effectiveSlotsArray[i];
     LispObject candidateSlotName = slotDefinition.AREF(1);
     if (slotName == candidateSlotName) {
       return i;
     }
   }
   return -1;
 }
Exemplo n.º 3
0
 @Override
 public LispObject getParts() {
   LispObject result = NIL;
   result = result.push(new Cons("class", structureClass));
   LispObject effectiveSlots = structureClass.getSlotDefinitions();
   LispObject[] effectiveSlotsArray = effectiveSlots.copyToArray();
   Debug.assertTrue(effectiveSlotsArray.length == slots.length);
   for (int i = 0; i < slots.length; i++) {
     SimpleVector slotDefinition = (SimpleVector) effectiveSlotsArray[i];
     LispObject slotName = slotDefinition.AREF(1);
     result = result.push(new Cons(slotName, slots[i]));
   }
   return result.nreverse();
 }