Beispiel #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.
   }
 }
  private static void copySubArray(AbstractArray a1, AbstractArray a2, int[] subscripts, int axis) {

    if (axis < subscripts.length) {
      final int limit = Math.min(a1.getDimension(axis), a2.getDimension(axis));
      for (int i = 0; i < limit; i++) {
        subscripts[axis] = i;
        copySubArray(a1, a2, subscripts, axis + 1);
      }
    } else {
      int i1 = a1.getRowMajorIndex(subscripts);
      int i2 = a2.getRowMajorIndex(subscripts);
      a2.aset(i2, a1.AREF(i1));
    }
  }