Rename ConditionThrowable to ControlTransfer and remove

  try/catch blocks which don't have anything to do with
  non-local transfer of control.
parent 844bffb0
......@@ -162,17 +162,10 @@ public abstract class AbstractBitVector extends AbstractVector
public int hashCode()
{
int hashCode = 1;
try {
// Consider first 64 bits only.
final int limit = Math.min(length(), 64);
for (int i = 0; i < limit; i++)
hashCode = hashCode * 31 + getBit(i);
}
// ### fixme exception
catch (ConditionThrowable t) {
// Shouldn't happen.
Debug.trace(t);
}
// Consider first 64 bits only.
final int limit = Math.min(length(), 64);
for (int i = 0; i < limit; i++)
hashCode = hashCode * 31 + getBit(i);
return hashCode;
}
......
......@@ -120,17 +120,12 @@ public abstract class AbstractString extends AbstractVector
}
public String toString() {
try {
int length = length();
StringBuilder sb = new StringBuilder(length);
for(int i = 0; i < length; ++i) {
sb.append(charAt(i));
sb.append(charAt(i));
}
return sb.toString();
} catch(ConditionThrowable t) {
// ### FIXME exception
throw new Error(t); //Should never happen
}
}
}
......@@ -79,13 +79,7 @@ public class Autoload extends Function
{
Symbol symbol = intern(symbolName.toUpperCase(), pkg);
if (pkg != PACKAGE_CL && exported) {
try {
pkg.export(symbol);
}
catch (ConditionThrowable t) {
// ### FIXME exception
Debug.assertTrue(false);
}
pkg.export(symbol);
}
if (symbol.getSymbolFunction() == null)
symbol.setSymbolFunction(new Autoload(symbol, null,
......
......@@ -526,15 +526,7 @@ public final class ComplexString extends AbstractString
final int limit = length();
for (int i = 0; i < limit; i++)
{
try
{
hashCode += charAt(i);
}
catch (ConditionThrowable t)
{
// ### FIXME exception
Debug.trace(t);
}
hashCode += charAt(i);
hashCode += (hashCode << 10);
hashCode ^= (hashCode >> 6);
}
......@@ -552,15 +544,7 @@ public final class ComplexString extends AbstractString
final int limit = length();
for (int i = 0; i < limit; i++)
{
try
{
hashCode += Character.toUpperCase(charAt(i));
}
catch (ConditionThrowable t)
{
// ### FIXME exception
Debug.trace(t);
}
hashCode += Character.toUpperCase(charAt(i));
hashCode += (hashCode << 10);
hashCode ^= (hashCode >> 6);
}
......
/*
* ConditionThrowable.java
* ControlTransfer.java
*
* Copyright (C) 2003-2005 Peter Graves
* $Id$
......@@ -33,13 +33,13 @@
package org.armedbear.lisp;
abstract public class ConditionThrowable extends RuntimeException
abstract public class ControlTransfer extends RuntimeException
{
public ConditionThrowable()
public ControlTransfer()
{
}
/**
* Overridden in order to make ConditionThrowable construct
* Overridden in order to make ControlTransfer construct
* faster. This avoids gathering stack trace information.
*/
@Override
......@@ -48,7 +48,7 @@ abstract public class ConditionThrowable extends RuntimeException
return this;
}
public ConditionThrowable(String message)
public ControlTransfer(String message)
{
super(message);
}
......
......@@ -56,16 +56,8 @@ public final class EqualHashTable extends HashTable
HashEntry e = buckets[key.sxhash() & mask];
while (e != null)
{
try
{
if (key == e.key || key.equal(e.key))
return e.value;
}
// ### FIXME exception
catch (ConditionThrowable t)
{
Debug.trace(t);
}
if (key == e.key || key.equal(e.key))
return e.value;
e = e.next;
}
return null;
......
......@@ -54,16 +54,8 @@ public final class EqualpHashTable extends HashTable
HashEntry e = buckets[index];
while (e != null)
{
try
{
if (key.equalp(e.key))
return e.value;
}
// ### FIXME exception
catch (ConditionThrowable t)
{
Debug.trace(t);
}
if (key.equalp(e.key))
return e.value;
e = e.next;
}
return null;
......
......@@ -116,13 +116,7 @@ public final class FileStream extends Stream
}
} else {
isBinaryStream = true;
int width;
try {
width = Fixnum.getValue(elementType.cadr());
}
catch (ConditionThrowable t) {
width = 8;
}
int width = Fixnum.getValue(elementType.cadr());
bytesPerUnit = width / 8;
if (isInputStream) {
initAsBinaryInputStream(racf.getInputStream());
......
......@@ -74,23 +74,9 @@ public final class FillPointerOutputStream extends Stream
int fp = string.getFillPointer();
if (fp >= 0) {
final int limit = Math.min(cbuf.length, off + len);
try {
string.ensureCapacity(fp + limit);
}
catch (ConditionThrowable t) {
// ### FIXME exception
// Shouldn't happen.
Debug.trace(t);
}
string.ensureCapacity(fp + limit);
for (int i = off; i < limit; i++) {
try {
string.setCharAt(fp, cbuf[i]);
}
catch (ConditionThrowable t) {
// ### FIXME exception
// Shouldn't happen.
Debug.trace(t);
}
string.setCharAt(fp, cbuf[i]);
++fp;
}
}
......
......@@ -68,13 +68,8 @@ public abstract class Function extends Operator
setLambdaName(symbol);
setLambdaList(new SimpleString(arglist));
if (docstring != null) {
try {
symbol.setDocumentation(Symbol.FUNCTION,
new SimpleString(docstring));
}
catch (ConditionThrowable t) {
Debug.assertTrue(false);
}
symbol.setDocumentation(Symbol.FUNCTION,
new SimpleString(docstring));
}
}
......@@ -106,23 +101,18 @@ public abstract class Function extends Operator
if (arglist instanceof String)
setLambdaList(new SimpleString(arglist));
if (name != null) {
try {
Symbol symbol;
if (exported)
symbol = pkg.internAndExport(name.toUpperCase());
else
symbol = pkg.intern(name.toUpperCase());
symbol.setSymbolFunction(this);
if (cold)
symbol.setBuiltInFunction(true);
setLambdaName(symbol);
if (docstring != null)
symbol.setDocumentation(Symbol.FUNCTION,
new SimpleString(docstring));
}
catch (ConditionThrowable t) {
Debug.assertTrue(false);
}
Symbol symbol;
if (exported)
symbol = pkg.internAndExport(name.toUpperCase());
else
symbol = pkg.intern(name.toUpperCase());
symbol.setSymbolFunction(this);
if (cold)
symbol.setBuiltInFunction(true);
setLambdaName(symbol);
if (docstring != null)
symbol.setDocumentation(Symbol.FUNCTION,
new SimpleString(docstring));
}
}
......
......@@ -33,7 +33,7 @@
package org.armedbear.lisp;
public final class Go extends ConditionThrowable
public final class Go extends ControlTransfer
{
public final LispObject tagbody;
public final LispObject tag;
......
......@@ -160,16 +160,7 @@ public final class Interpreter extends Lisp
public static synchronized void initializeLisp()
{
if (!initialized) {
try {
Load.loadSystemFile("boot.lisp", false, false, false);
}
catch (ConditionThrowable c) {
// ### FIXME exception
reportError(c, LispThread.currentThread());
}
catch (Throwable t) {
t.printStackTrace();
}
Load.loadSystemFile("boot.lisp", false, false, false);
initialized = true;
}
}
......@@ -184,11 +175,8 @@ public final class Interpreter extends Lisp
Class.forName("org.armedbear.j.LispAPI");
Load.loadSystemFile("j.lisp");
}
catch (ConditionThrowable c) {
// ### FIXME exception
reportError(c, LispThread.currentThread());
}
catch (Throwable t) {
// ### FIXME exception
t.printStackTrace();
}
initialized = true;
......@@ -277,8 +265,7 @@ public final class Interpreter extends Lisp
try {
evaluate(args[i + 1]);
}
catch (ConditionThrowable c) {
// ### FIXME exception
catch (UnhandledCondition c) {
final String separator =
System.getProperty("line.separator");
FastStringBuffer sb = new FastStringBuffer();
......@@ -305,22 +292,12 @@ public final class Interpreter extends Lisp
} else if (arg.equals("--load") ||
arg.equals("--load-system-file")) {
if (i + 1 < args.length) {
try {
if (arg.equals("--load"))
Load.load(new Pathname(args[i + 1]),
args[i + 1],
false, false, true);
else
Load.loadSystemFile(args[i + 1]);
}
catch (ConditionThrowable c) {
// ### FIXME exception
System.err.println("Caught condition: " +
c.getCondition().writeToString() +
" while loading: " +
args[i+1]);
System.exit(2);
}
if (arg.equals("--load"))
Load.load(new Pathname(args[i + 1]),
args[i + 1],
false, false, true);
else
Load.loadSystemFile(args[i + 1]);
++i;
} else {
// Shouldn't happen.
......@@ -387,8 +364,9 @@ public final class Interpreter extends Lisp
getStandardInput().clearInput();
out._writeLine("Stack overflow");
}
catch (ConditionThrowable c) {
// ### FIXME exception
catch (ControlTransfer c) {
// We're on the toplevel, if this occurs,
// we're toast...
reportError(c, thread);
}
catch (Throwable t) {
......@@ -403,7 +381,24 @@ public final class Interpreter extends Lisp
}
}
private static void reportError(ConditionThrowable c, LispThread thread)
private static void reportError(ControlTransfer c, LispThread thread)
{
try {
getStandardInput().clearInput();
Stream out = getStandardOutput();
out.freshLine();
Condition condition = (Condition) c.getCondition();
out._writeLine("Error: unhandled condition: " +
condition.writeToString());
if (thread != null)
thread.printBacktrace();
}
catch (Throwable t) {
}
}
private static void reportError(UnhandledCondition c, LispThread thread)
{
try {
getStandardInput().clearInput();
......
......@@ -81,13 +81,7 @@ public final class JHandler extends Lisp
LispObject lispAsVector = new SimpleVector(lispAs);
LispObject[] args = new LispObject[] //FIXME: count -> seq_num
{ data, new JavaObject(o), lispAiVector, lispAsVector, Keyword.internKeyword(s), count };
try {
f.execute(args);
}
catch (ConditionThrowable t) {
// ### FIXME exception
t.printStackTrace();
}
f.execute(args);
}
}
}
......
......@@ -94,23 +94,15 @@ public final class JProxy extends Lisp
Function f = entry.getLispMethod(methodName);
if (f != null)
{
try
LispObject lispArgs = NIL;
if (args != null)
{
LispObject lispArgs = NIL;
if (args != null)
{
for (int i = args.length - 1 ; 0 <= i ; i--)
lispArgs = lispArgs.push(new JavaObject(args[i]));
}
LispObject result = evalCall(f, lispArgs, new Environment(),
LispThread.currentThread());
return (method.getReturnType() == void.class ? null : result.javaInstance());
}
// ### FIXME exception
catch (ConditionThrowable t)
{
t.printStackTrace();
for (int i = args.length - 1 ; 0 <= i ; i--)
lispArgs = lispArgs.push(new JavaObject(args[i]));
}
LispObject result = evalCall(f, lispArgs, new Environment(),
LispThread.currentThread());
return (method.getReturnType() == void.class ? null : result.javaInstance());
}
}
return null;
......
......@@ -277,7 +277,7 @@ public final class Java extends Lisp
catch (NoSuchMethodException e) {
error(new LispError("no such constructor"));
}
catch (ConditionThrowable e) {
catch (ControlTransfer e) {
throw e;
}
catch (Throwable t) {
......@@ -335,7 +335,7 @@ public final class Java extends Lisp
sb.append(')');
error(new LispError(sb.toString()));
}
catch (ConditionThrowable e) {
catch (ControlTransfer e) {
throw e;
}
catch (Throwable t) {
......@@ -648,7 +648,7 @@ public final class Java extends Lisp
return JavaObject.getInstance(method.invoke(instance, methodArgs),
translate);
}
catch (ConditionThrowable t) {
catch (ControlTransfer t) {
throw t;
}
catch (Throwable t) {
......
......@@ -44,25 +44,21 @@ public class JavaClass extends LispClass {
private void initCPL() {
LispObject cpl = Lisp.NIL;
try {
cpl = cpl.push(BuiltInClass.CLASS_T);
cpl = cpl.push(BuiltInClass.JAVA_OBJECT);
Set<Class<?>> alreadySeen = new HashSet<Class<?>>();
Stack<JavaClass> stack = new Stack<JavaClass>();
Class<?> theClass = javaClass;
boolean stop = false;
while(!stop && theClass != null) {
stop = addClass(alreadySeen, stack, theClass);
for(Class<?> c : theClass.getInterfaces()) {
stop = addClass(alreadySeen, stack, c) && stop; //watch out for short-circuiting!
}
theClass = theClass.getSuperclass();
cpl = cpl.push(BuiltInClass.CLASS_T);
cpl = cpl.push(BuiltInClass.JAVA_OBJECT);
Set<Class<?>> alreadySeen = new HashSet<Class<?>>();
Stack<JavaClass> stack = new Stack<JavaClass>();
Class<?> theClass = javaClass;
boolean stop = false;
while(!stop && theClass != null) {
stop = addClass(alreadySeen, stack, theClass);
for(Class<?> c : theClass.getInterfaces()) {
stop = addClass(alreadySeen, stack, c) && stop; //watch out for short-circuiting!
}
while(!stack.isEmpty()) {
cpl = cpl.push(stack.pop());
}
} catch (ConditionThrowable e) {
throw new Error("Cannot push class in class precedence list", e);
theClass = theClass.getSuperclass();
}
while(!stack.isEmpty()) {
cpl = cpl.push(stack.pop());
}
setCPL(cpl);
}
......
......@@ -223,7 +223,7 @@ public final class JavaObject extends LispObject
@Override
public String writeToString()
{
if (obj instanceof ConditionThrowable)
if (obj instanceof ControlTransfer)
return obj.toString();
final String s;
if(obj != null) {
......
......@@ -53,18 +53,9 @@ public class JavaStackFrame
@Override
public String writeToString() {
String result = null;
final String JAVA_STACK_FRAME = "JAVA-STACK-FRAME";
try {
result = unreadableString(JAVA_STACK_FRAME + " "
+ toLispString().toString());
} catch (ConditionThrowable t) {
// ### FIXME exception
Debug.trace("Implementation error: ");
Debug.trace(t);
result = unreadableString(JAVA_STACK_FRAME);
}
return result;
return unreadableString(JAVA_STACK_FRAME + " "
+ toLispString().toString());
}
@Override
......
......@@ -1453,14 +1453,9 @@ public abstract class Lisp
public static final String safeWriteToString(LispObject obj)
{
try
{
try {
return obj.writeToString();
}
catch (ConditionThrowable t)
{
return obj.toString();
}
catch (NullPointerException e)
{
Debug.trace(e);
......@@ -2173,14 +2168,7 @@ public abstract class Lisp
LispObject value)
{
Symbol symbol = pkg.intern(name);
try
{
pkg.export(symbol); // FIXME Inefficient!
}
catch (ConditionThrowable t)
{
Debug.trace(t);
}
pkg.export(symbol); // FIXME Inefficient!
symbol.setSpecial(true);
symbol.setSymbolValue(value);
return symbol;
......@@ -2190,14 +2178,7 @@ public abstract class Lisp
LispObject value)
{
Symbol symbol = pkg.intern(name);
try
{
pkg.export(symbol); // FIXME Inefficient!
}
catch (ConditionThrowable t)
{
Debug.trace(t);
}
pkg.export(symbol); // FIXME Inefficient!
symbol.initializeConstant(value);
return symbol;
}
......
......@@ -90,12 +90,7 @@ public final class LispThread extends LispObject
}
catch (Throwable t) {
if (isInterrupted()) {
try {
processThreadInterrupts();
}
catch (ConditionThrowable c) {
Debug.trace(c);
}
processThreadInterrupts();
}
}
finally {
......@@ -107,14 +102,8 @@ public final class LispThread extends LispObject
javaThread = new Thread(r);
this.name = name;
map.put(javaThread, this);
try {
if (name != NIL)
javaThread.setName(name.getStringValue());
} catch (ConditionThrowable ex) {
// ### FIXME exception
Debug.trace("Failed to set thread name:");
Debug.trace(ex);
}
if (name != NIL)
javaThread.setName(name.getStringValue());
javaThread.setDaemon(true);
javaThread.start();
}
......@@ -765,38 +754,32 @@ public final class LispThread extends LispObject
}
// Object doesn't fit.
if (obj instanceof Cons) {
try {
boolean newlineBefore = false;
LispObject[] array = obj.copyToArray();
if (array.length > 0) {
LispObject first = array[0];
if (first == Symbol.LET) {
newlineBefore = true;
}
}
int charPos = stream.getCharPos();
if (newlineBefore && charPos != indentBy) {
stream.terpri();
charPos = stream.getCharPos();
}
if (charPos < indentBy) {
StringBuffer sb = new StringBuffer();
for (int i = charPos; i < indentBy; i++)
sb.append(' ');
stream._writeString(sb.toString());
boolean newlineBefore = false;
LispObject[] array = obj.copyToArray();
if (array.length > 0) {
LispObject first = array[0];
if (first == Symbol.LET) {
newlineBefore = true;
}
stream.print('(');
for (int i = 0; i < array.length; i++) {
pprint(array[i], indentBy + 2, stream);
if (i < array.length - 1)
stream.print(' ');
}
stream.print(')');
}
catch (ConditionThrowable t) {
// ### FIXME exception
Debug.trace(t);
int charPos = stream.getCharPos();
if (newlineBefore && charPos != indentBy) {
stream.terpri();
charPos = stream.getCharPos();
}
if (charPos < indentBy) {
StringBuffer sb = new StringBuffer();
for (int i = charPos; i < indentBy; i++)
sb.append(' ');
stream._writeString(sb.toString());
}
stream.print('(');
for (int i = 0; i < array.length; i++) {
pprint(array[i], indentBy + 2, stream);
if (i < array.length - 1)
stream.print(' ');
}
stream.print(')');
} else {
stream.terpri();
StringBuffer sb = new StringBuffer();
......@@ -1054,18 +1037,14 @@ public final class LispThread extends LispObject
static {
//FIXME: this block has been added for pre-0.16 compatibility
// and can be removed the latest at release 0.22
try {
PACKAGE_EXT.export(Symbol.intern("MAKE-THREAD", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("THREADP", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("THREAD-ALIVE-P", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("THREAD-NAME", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("MAPCAR-THREADS", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("DESTROY-THREAD", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("INTERRUPT-THREAD", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("CURRENT-THREAD", PACKAGE_THREADS));
}
// ### FIXME exception
catch (ConditionThrowable ct) { }
PACKAGE_EXT.export(Symbol.intern("MAKE-THREAD", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("THREADP", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("THREAD-ALIVE-P", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("THREAD-NAME", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("MAPCAR-THREADS", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("DESTROY-THREAD", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("INTERRUPT-THREAD", PACKAGE_THREADS));
PACKAGE_EXT.export(Symbol.intern("CURRENT-THREAD", PACKAGE_THREADS));
}
// ### use-fast-calls
......
......@@ -490,90 +490,85 @@ public class Pathname extends LispObject
@Override
public String writeToString()
{
final LispThread thread = LispThread.currentThread();
boolean printReadably = (Symbol.PRINT_READABLY.symbolValue(thread) != NIL);
boolean printEscape = (Symbol.PRINT_ESCAPE.symbolValue(thread) != NIL);
boolean useNamestring;
String s = null;
try {
final LispThread thread = LispThread.currentThread();
boolean printReadably = (Symbol.PRINT_READABLY.symbolValue(thread) != NIL);
boolean printEscape = (Symbol.PRINT_ESCAPE.symbolValue(thread) != NIL);
boolean useNamestring;