Rename writeToString() to printObject() since that's what it's being used for.

Additionally, create princToString() for use in error messages, making the
  required replacement where appropriate.
parent aa8900ad
......@@ -160,7 +160,7 @@ public abstract class AbstractArray extends LispObject implements java.io.Serial
// ### i18n
final String errorMsg =
"Invalid index %d for array %s.";
error(new ProgramError(String.format(errorMsg, n, writeToString())));
error(new ProgramError(String.format(errorMsg, n, printObject())));
}
sum += n * lastSize;
}
......@@ -218,7 +218,7 @@ public abstract class AbstractArray extends LispObject implements java.io.Serial
sb.append('(');
if (this instanceof SimpleArray_T)
sb.append("SIMPLE-");
sb.append("ARRAY " + getElementType().writeToString() + " (");
sb.append("ARRAY " + getElementType().printObject() + " (");
for (int i = 0; i < dimv.length; i++) {
sb.append(dimv[i]);
if (i < dimv.length - 1)
......@@ -228,7 +228,7 @@ public abstract class AbstractArray extends LispObject implements java.io.Serial
return unreadableString(sb.toString());
}
// Helper for writeToString().
// Helper for printObject().
private void appendContents(int[] dimensions, int index, StringBuilder sb,
LispThread thread)
......@@ -240,7 +240,7 @@ public abstract class AbstractArray extends LispObject implements java.io.Serial
AREF(index), stream);
sb.append(stream.getString().getStringValue());
} else
sb.append(AREF(index).writeToString());
sb.append(AREF(index).printObject());
} else {
final LispObject printReadably =
Symbol.PRINT_READABLY.symbolValue(thread);
......
......@@ -172,7 +172,7 @@ public abstract class AbstractBitVector extends AbstractVector
}
@Override
public String writeToString()
public String printObject()
{
final LispThread thread = LispThread.currentThread();
final int length = length();
......
......@@ -110,7 +110,7 @@ public abstract class AbstractString extends AbstractVector
}
@Override
public String writeToString()
public String printObject()
{
return writeToString(0, length());
}
......
......@@ -154,7 +154,7 @@ public abstract class AbstractVector extends AbstractArray
StringBuilder sb = new StringBuilder("Invalid array index ");
sb.append(index);
sb.append(" for ");
sb.append(writeToString());
sb.append(princToString());
if (limit > 0)
{
sb.append(" (should be >= 0 and < ");
......@@ -204,7 +204,7 @@ public abstract class AbstractVector extends AbstractArray
}
@Override
public String writeToString()
public String printObject()
{
final LispThread thread = LispThread.currentThread();
if (Symbol.PRINT_READABLY.symbolValue(thread) != NIL)
......@@ -215,7 +215,7 @@ public abstract class AbstractVector extends AbstractArray
{
if (i > 0)
sb.append(' ');
sb.append(AREF(i).writeToString());
sb.append(AREF(i).printObject());
}
sb.append(')');
return sb.toString();
......@@ -248,7 +248,7 @@ public abstract class AbstractVector extends AbstractArray
{
if (i > 0)
sb.append(' ');
sb.append(AREF(i).writeToString());
sb.append(AREF(i).printObject());
}
}
finally
......
......@@ -153,7 +153,7 @@ public class Autoload extends Function
if (debug) {
if (symbol != null) {
if (symbol.getSymbolFunction() instanceof Autoload) {
Debug.trace("Unable to autoload " + symbol.writeToString());
Debug.trace("Unable to autoload " + symbol.princToString());
throw new IntegrityError();
}
}
......@@ -259,10 +259,10 @@ public class Autoload extends Function
}
@Override
public String writeToString()
public String printObject()
{
StringBuffer sb = new StringBuffer("#<AUTOLOAD ");
sb.append(symbol.writeToString());
sb.append(symbol.princToString());
sb.append(" \"");
if (className != null) {
int index = className.lastIndexOf('.');
......
......@@ -64,10 +64,10 @@ public final class AutoloadMacro extends Autoload
}
@Override
public String writeToString()
public String printObject()
{
StringBuffer sb = new StringBuffer("#<AUTOLOAD-MACRO ");
sb.append(getSymbol().writeToString());
sb.append(getSymbol().princToString());
sb.append(" \"");
sb.append(getFileName());
sb.append("\">");
......
......@@ -289,7 +289,7 @@ public final class Bignum extends LispInteger
{
float f = value.floatValue();
if (Float.isInfinite(f))
error(new TypeError("The value " + writeToString() +
error(new TypeError("The value " + princToString() +
" is too large to be converted to a single float."));
return f;
}
......@@ -299,7 +299,7 @@ public final class Bignum extends LispInteger
{
double d = value.doubleValue();
if (Double.isInfinite(d))
error(new TypeError("The value " + writeToString() +
error(new TypeError("The value " + princToString() +
" is too large to be converted to a double float."));
return d;
}
......@@ -755,7 +755,7 @@ public final class Bignum extends LispInteger
}
@Override
public String writeToString()
public String printObject()
{
final LispThread thread = LispThread.currentThread();
final int base = Fixnum.getValue(Symbol.PRINT_BASE.symbolValue(thread));
......
......@@ -219,7 +219,7 @@ public final class BroadcastStream extends Stream
}
@Override
public String writeToString()
public String printObject()
{
return unreadableString("BROADCAST-STREAM");
}
......
......@@ -73,14 +73,14 @@ public class BuiltInClass extends LispClass
@Override
public LispObject getDescription()
{
return new SimpleString(writeToString());
return new SimpleString(princToString());
}
@Override
public String writeToString()
public String printObject()
{
StringBuilder sb = new StringBuilder("#<BUILT-IN-CLASS ");
sb.append(getName().writeToString());
sb.append(getName().printObject());
sb.append('>');
return sb.toString();
}
......
......@@ -209,7 +209,7 @@ public abstract class CaseFrobStream extends Stream
}
@Override
public String writeToString()
public String printObject()
{
return unreadableString("CASE-FROB-STREAM");
}
......
......@@ -102,9 +102,9 @@ public class CellError extends LispError
{
if (Symbol.PRINT_ESCAPE.symbolValue() == NIL)
return super.getMessage();
StringBuffer sb = new StringBuffer(typeOf().writeToString());
StringBuffer sb = new StringBuffer(typeOf().princToString());
sb.append(' ');
sb.append(getCellName().writeToString());
sb.append(getCellName().princToString());
return unreadableString(sb.toString());
}
}
......@@ -131,7 +131,7 @@ public class Closure extends Function
final LispObject lambdaList = lambdaExpression.cadr();
setLambdaList(lambdaList);
if (!(lambdaList == NIL || lambdaList instanceof Cons))
error(new ProgramError("The lambda list " + lambdaList.writeToString() +
error(new ProgramError("The lambda list " + lambdaList.princToString() +
" is invalid."));
boolean _andKey = false;
boolean _allowOtherKeys = false;
......@@ -387,7 +387,7 @@ public class Closure extends Function
private static final void invalidParameter(LispObject obj)
{
error(new ProgramError(obj.writeToString() +
error(new ProgramError(obj.princToString() +
" may not be used as a variable in a lambda list."));
}
......@@ -860,7 +860,7 @@ public class Closure extends Function
if (!allowOtherKeys &&
(allowOtherKeysValue == null || allowOtherKeysValue == NIL))
error(new ProgramError("Unrecognized keyword argument " +
unrecognizedKeyword.writeToString()));
unrecognizedKeyword.printObject()));
}
}
}
......
......@@ -236,10 +236,10 @@ public class CompiledClosure extends Closure
return loadClassBytes((byte[]) arg.javaInstance(byte[].class));
} catch(Throwable t) {
Debug.trace(t);
return error(new LispError("Unable to load " + arg.writeToString()));
return error(new LispError("Unable to load " + arg.princToString()));
}
}
return error(new LispError("Unable to load " + arg.writeToString()));
return error(new LispError("Unable to load " + arg.princToString()));
}
};
......
......@@ -343,12 +343,12 @@ public final class Complex extends LispObject
}
@Override
public String writeToString()
public String printObject()
{
StringBuilder sb = new StringBuilder("#C(");
sb.append(realpart.writeToString());
sb.append(realpart.printObject());
sb.append(' ');
sb.append(imagpart.writeToString());
sb.append(imagpart.printObject());
sb.append(')');
return sb.toString();
}
......
......@@ -233,7 +233,7 @@ public final class ComplexArray extends AbstractArray
}
@Override
public String writeToString()
public String printObject()
{
return writeToString(dimv);
}
......
......@@ -229,7 +229,7 @@ public final class ComplexArray_UnsignedByte32 extends AbstractArray
}
@Override
public String writeToString()
public String printObject()
{
return writeToString(dimv);
}
......
......@@ -226,7 +226,7 @@ public final class ComplexArray_UnsignedByte8 extends AbstractArray
}
@Override
public String writeToString()
public String printObject()
{
if (Symbol.PRINT_READABLY.symbolValue() != NIL) {
error(new PrintNotReadable(list(Keyword.OBJECT, this)));
......
......@@ -178,11 +178,11 @@ public class Condition extends StandardObject
{
return format(formatControl, getFormatArguments());
}
return unreadableString(typeOf().writeToString());
return unreadableString(typeOf().princToString());
}
@Override
public final String writeToString()
public final String printObject()
{
final LispThread thread = LispThread.currentThread();
if (Symbol.PRINT_ESCAPE.symbolValue(thread) == NIL)
......@@ -216,6 +216,6 @@ public class Condition extends StandardObject
int currentLevel = ((Fixnum)currentPrintLevel).value;
if (currentLevel >= maxLevel)
return "#";
return unreadableString(typeOf().writeToString());
return unreadableString(typeOf().princToString());
}
}
......@@ -498,7 +498,7 @@ public final class Cons extends LispObject implements java.io.Serializable
}
@Override
public String writeToString()
public String printObject()
{
final LispThread thread = LispThread.currentThread();
final LispObject printLength = Symbol.PRINT_LENGTH.symbolValue(thread);
......@@ -522,7 +522,7 @@ public final class Cons extends LispObject implements java.io.Serializable
if (cdr.cdr() == NIL)
{
sb.append('\'');
sb.append(cdr.car().writeToString());
sb.append(cdr.car().printObject());
return sb.toString();
}
}
......@@ -535,7 +535,7 @@ public final class Cons extends LispObject implements java.io.Serializable
if (cdr.cdr() == NIL)
{
sb.append("#'");
sb.append(cdr.car().writeToString());
sb.append(cdr.car().printObject());
return sb.toString();
}
}
......@@ -555,14 +555,14 @@ public final class Cons extends LispObject implements java.io.Serializable
if (count < maxLength)
{
LispObject p = this;
sb.append(p.car().writeToString());
sb.append(p.car().printObject());
++count;
while ((p = p.cdr()) instanceof Cons)
{
sb.append(' ');
if (count < maxLength)
{
sb.append(p.car().writeToString());
sb.append(p.car().printObject());
++count;
}
else
......@@ -574,7 +574,7 @@ public final class Cons extends LispObject implements java.io.Serializable
if (!truncated && p != NIL)
{
sb.append(" . ");
sb.append(p.writeToString());
sb.append(p.printObject());
}
}
else
......
......@@ -529,26 +529,26 @@ public final class DoubleFloat extends LispObject
else
m = (bits & 0xfffffffffffffL) | 0x10000000000000L;
LispObject significand = number(m);
// Debug.trace("significand = " + significand.writeToString());
// Debug.trace("significand = " + significand.printObject());
Fixnum exponent = Fixnum.getInstance(e - 1075);
// Debug.trace("exponent = " + exponent.writeToString());
// Debug.trace("exponent = " + exponent.printObject());
Fixnum sign = Fixnum.getInstance(s);
// Debug.trace("sign = " + sign.writeToString());
// Debug.trace("sign = " + sign.printObject());
LispObject result = significand;
// Debug.trace("result = " + result.writeToString());
// Debug.trace("result = " + result.printObject());
result =
result.multiplyBy(MathFunctions.EXPT.execute(Fixnum.TWO, exponent));
// Debug.trace("result = " + result.writeToString());
// Debug.trace("result = " + result.printObject());
result = result.truncate(Fixnum.ONE);
LispObject remainder = coerceToFloat(thread._values[1]);
result = result.multiplyBy(sign);
// Debug.trace("result = " + result.writeToString());
// Debug.trace("result = " + result.printObject());
// // Calculate remainder.
// LispObject product = result.multiplyBy(obj);
// Debug.trace("product = " + product.writeToString());
// Debug.trace("product = " + product.printObject());
// LispObject remainder = subtract(product);
return thread.setValues(result, remainder);
}
......@@ -572,16 +572,16 @@ public final class DoubleFloat extends LispObject
}
@Override
public String writeToString()
public String printObject()
{
if (value == Double.POSITIVE_INFINITY) {
StringBuilder sb = new StringBuilder("#.");
sb.append(Symbol.DOUBLE_FLOAT_POSITIVE_INFINITY.writeToString());
sb.append(Symbol.DOUBLE_FLOAT_POSITIVE_INFINITY.printObject());
return sb.toString();
}
if (value == Double.NEGATIVE_INFINITY) {
StringBuilder sb = new StringBuilder("#.");
sb.append(Symbol.DOUBLE_FLOAT_NEGATIVE_INFINITY.writeToString());
sb.append(Symbol.DOUBLE_FLOAT_NEGATIVE_INFINITY.printObject());
return sb.toString();
}
......@@ -646,7 +646,7 @@ public final class DoubleFloat extends LispObject
return new DoubleFloat(((SingleFloat)obj).value);
if (obj instanceof Ratio)
return new DoubleFloat(((Ratio)obj).doubleValue());
error(new TypeError("The value " + obj.writeToString() +
error(new TypeError("The value " + obj.princToString() +
" cannot be converted to type DOUBLE-FLOAT."));
// Not reached.
return null;
......
......@@ -245,7 +245,7 @@ public final class Environment extends LispObject
}
@Override
public String writeToString()
public String printObject()
{
return unreadableString(Symbol.ENVIRONMENT);
}
......
......@@ -183,7 +183,7 @@ public final class FileStream extends Stream
String namestring = pathname.getNamestring();
if (namestring == null)
return error(new SimpleError("Pathname has no namestring: " +
pathname.writeToString()));
pathname.princToString()));
File file = new File(namestring);
length = file.length(); // in 8-bit bytes
}
......@@ -263,7 +263,7 @@ public final class FileStream extends Stream
}
@Override
public String writeToString()
public String printObject()
{
return unreadableString(Symbol.FILE_STREAM);
}
......
......@@ -939,7 +939,7 @@ public final class Fixnum extends LispInteger
}
@Override
public String writeToString()
public String printObject()
{
final LispThread thread = LispThread.currentThread();
int base = Fixnum.getValue(Symbol.PRINT_BASE.symbolValue(thread));
......
......@@ -63,13 +63,13 @@ public final class FloatFunctions
trap_underflow = true;
else
error(new LispError("Unsupported floating point trap: " +
car.writeToString()));
car.princToString()));
value = value.cdr();
}
TRAP_OVERFLOW = trap_overflow;
TRAP_UNDERFLOW = trap_underflow;
} else
error(new LispError("Unrecognized keyword: " + key.writeToString()));
error(new LispError("Unrecognized keyword: " + key.princToString()));
}
return LispThread.currentThread().nothing();
}
......
......@@ -65,13 +65,13 @@ public class ForwardReferencedClass extends LispClass
}
@Override
public String writeToString()
public String printObject()
{
StringBuffer sb =
new StringBuffer(Symbol.FORWARD_REFERENCED_CLASS.writeToString());
new StringBuffer(Symbol.FORWARD_REFERENCED_CLASS.printObject());
if (getName() != null) {
sb.append(' ');
sb.append(getName().writeToString());
sb.append(getName().printObject());
}
return unreadableString(sb.toString());
}
......@@ -90,7 +90,7 @@ public class ForwardReferencedClass extends LispClass
LispClass.addClass(name, c);
return c;
}
return error(new TypeError(arg.writeToString() +
return error(new TypeError(arg.princToString() +
" is not a valid class name."));
}
};
......
......@@ -313,12 +313,12 @@ public abstract class Function extends Operator
}
@Override
public String writeToString()
public String printObject()
{
LispObject name = getLambdaName();
if (name != null && name != NIL) {
StringBuffer sb = new StringBuffer("#<FUNCTION ");
sb.append(name.writeToString());
sb.append(name.printObject());
sb.append(" {");
sb.append(Integer.toHexString(System.identityHashCode(this)).toUpperCase());
sb.append("}>");
......@@ -336,7 +336,7 @@ public abstract class Function extends Operator
final SpecialBindingsMark mark = thread.markSpecialBindings();
thread.bindSpecial(Symbol.PRINT_LENGTH, Fixnum.THREE);
try {
sb.append(lambdaList.writeToString());
sb.append(lambdaList.printObject());
}
finally {
thread.resetSpecialBindings(mark);
......
......@@ -58,7 +58,7 @@ public final class Go extends ControlTransfer
public LispObject getCondition()
{
StringBuffer sb = new StringBuffer("No tag named ");
sb.append(tag.writeToString());
sb.append(tag.princToString());
sb.append(" is currently visible");
return new ControlError(sb.toString());
}
......
......@@ -225,14 +225,14 @@ public class HashTable
}
@Override
public String writeToString() {
public String printObject() {
if (Symbol.PRINT_READABLY.symbolValue(LispThread.currentThread()) != NIL) {
error(new PrintNotReadable(list(Keyword.OBJECT, this)));
return null; // Not reached.
}
StringBuilder sb = new StringBuilder(getTest().writeToString());
StringBuilder sb = new StringBuilder(getTest().princToString());
sb.append(' ');
sb.append(Symbol.HASH_TABLE.writeToString());
sb.append(Symbol.HASH_TABLE.princToString());
sb.append(' ');
sb.append(count);
if (count == 1) {
......
......@@ -69,7 +69,7 @@ public final class HashTableFunctions
if (test == FUNCTION_EQUALP)
return HashTable.newEqualpHashTable(n, rehashSize, rehashThreshold);
return error(new LispError("Unsupported test for MAKE-HASH-TABLE: " +
test.writeToString()));
test.princToString()));
}
};
......@@ -102,7 +102,7 @@ public final class HashTableFunctions
return WeakHashTable.newEqualpHashTable(n, rehashSize,
rehashThreshold, weakness);
return error(new LispError("Unsupported test for MAKE-HASH-TABLE: " +
test.writeToString()));
test.princToString()));
}
};
......
......@@ -309,14 +309,14 @@ public final class Interpreter
StringBuilder sb = new StringBuilder();
sb.append(separator);
sb.append("Caught ");
sb.append(c.getCondition().typeOf().writeToString());
sb.append(c.getCondition().typeOf().printObject());
sb.append(" while processing --eval option \"" +
args[i + 1] + "\":");
sb.append(separator);
sb.append(" ");
final LispThread thread = LispThread.currentThread();
thread.bindSpecial(Symbol.PRINT_ESCAPE, NIL);
sb.append(c.getCondition().writeToString());
sb.append(c.getCondition().princToString());
sb.append(separator);
System.err.print(sb.toString());
exit(2); // FIXME
......@@ -408,10 +408,10 @@ public final class Interpreter
slash = new Cons(values[i], slash);
Symbol.SLASH.setSymbolValue(slash);
for (int i = 0; i < values.length; i++)
out._writeLine(values[i].writeToString());
out._writeLine(values[i].printObject());
} else {
Symbol.SLASH.setSymbolValue(new Cons(result));
out._writeLine(result.writeToString());
out._writeLine(result.printObject());
}
out._finishOutput();
}
......@@ -445,7 +445,7 @@ public final class Interpreter
out.freshLine();
Condition condition = (Condition) c.getCondition();
out._writeLine("Error: unhandled condition: " +
condition.writeToString());
condition.princToString());
if (thread != null)
thread.printBacktrace();
}
......@@ -457,7 +457,7 @@ public final class Interpreter
out.freshLine();
Condition condition = (Condition) c.getCondition();
out._writeLine("Error: unhandled condition: " +
condition.writeToString());
condition.princToString());
if (thread != null)
thread.printBacktrace();
}
......@@ -516,7 +516,7 @@ public final class Interpreter
SpecialBindingsMark mark = thread.markSpecialBindings();
thread.bindSpecial(Symbol.PRINT_ESCAPE, NIL);
try {
conditionText = getCondition().writeToString();
conditionText = getCondition().princToString();
} catch (Throwable t) {
conditionText = "<error printing Lisp condition>";
} finally {
......@@ -552,14 +552,14 @@ public final class Interpreter
final int offset =
((Stream)stream).getOffset();
Debug.trace("Error loading " +
truename.writeToString() +
truename.princToString() +
" at line " + lineNumber +
" (offset " + offset + ")");
}
}
Debug.trace("Encountered unhandled condition of type " +
condition.typeOf().writeToString() + ':');
Debug.trace(" " + condition.writeToString());
condition.typeOf().princToString() + ':');
Debug.trace(" " + condition.princToString());
}
catch (Throwable t) {} // catch any exception to throw below
finally {
......
......@@ -136,10 +136,10 @@ public final class JarStream extends Stream
}
@Override
public String writeToString()
public String printObject()
{
StringBuffer sb = new StringBuffer();
sb.append(Symbol.JAR_STREAM.writeToString());
sb.append(Symbol.JAR_STREAM.princToString());
String namestring = pathname.getNamestring();
if (namestring != null) {
sb.append(" ");
......
......@@ -413,7 +413,7 @@ public final class Java
sb.append(methodName);
sb.append('(');
for (int i = 2; i < args.length; i++) {
sb.append(args[i].writeToString());
sb.append(args[i].princToString());
if (i < args.length - 1)
sb.append(',');
}
......@@ -558,7 +558,7 @@ public final class Java
} else if(object instanceof Class<?>) {
constructor = findConstructor((Class<?>) object, args);
} else {