Пример #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.
   }
 }
Пример #2
0
 static void maybeSaveSymbolFunction(LispObject first, LispObject fun) {
   if (first instanceof Symbol) {
     Symbol symbol = (Symbol) first;
     LispObject sfun = symbol.getSymbolFunction();
     if (sfun != fun) {
       if (sfun == null) {
         symbol.setSymbolFunction(sfun);
         return;
       }
       // symbol.setSymbolFunction(fun);
     }
   }
 }
Пример #3
0
  public StructureObject(Symbol symbol) {

    structureClass = (StructureClass) LispClass.findClass(symbol /*, true*/); // Might return null.
    if (structureClass == null) {
      System.err.println("No mitens sitten: " + BuiltInClass.SYSTEM_STREAM.toString());
      System.err.println("joopa joo:" + Symbol.SYSTEM_STREAM.name);
      System.err.println(
          "Oh noes, structure object got a null class:"
              + symbol.toString()
              + ", symbol name:"
              + symbol.name);
    }
    slots = new LispObject[0];
  }