new method program_error, analogous to type_error

parent 10ae83df
......@@ -147,7 +147,7 @@ public abstract class AbstractArray extends LispObject implements java.io.Serial
// ### i18n
final String errorMsg =
"Wrong number of subscripts (%d) for array of rank %d.";
error(new ProgramError(String.format(errorMsg, subscripts.length, rank)));
program_error(String.format(errorMsg, subscripts.length, rank));
}
int sum = 0;
int size = 1;
......@@ -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, printObject())));
program_error(String.format(errorMsg, n, printObject()));
}
sum += n * lastSize;
}
......
......@@ -188,7 +188,7 @@ public class ArgumentListProcessor {
if (remaining.car() == Symbol.AND_WHOLE) {
if (type == LambdaListType.ORDINARY) {
error(new ProgramError("&WHOLE not allowed in ordinary lambda lists."));
program_error("&WHOLE not allowed in ordinary lambda lists.");
} else {
// skip the &WHOLE <var> part of the lambda list
remaining = remaining.cdr().cdr();
......@@ -203,9 +203,9 @@ public class ArgumentListProcessor {
{
if (obj == Symbol.AND_WHOLE) {
if (type == LambdaListType.ORDINARY)
error(new ProgramError("&WHOLE not allowed in ordinary lambda lists."));
program_error("&WHOLE not allowed in ordinary lambda lists.");
else
error(new ProgramError("&WHOLE must appear first in macro lambda list."));
program_error("&WHOLE must appear first in macro lambda list.");
}
if (state == STATE_AUX)
{
......@@ -223,24 +223,21 @@ public class ArgumentListProcessor {
{
if (_andKey)
{
error(new ProgramError(
"&REST/&BODY must precede &KEY."));
program_error("&REST/&BODY must precede &KEY.");
}
if (type == LambdaListType.ORDINARY && obj == Symbol.AND_BODY)
error(new ProgramError("&BODY not allowed in ordinary lambda lists."));
program_error("&BODY not allowed in ordinary lambda lists.");
state = STATE_REST;
arity = -1;
maxArgs = -1;
remaining = remaining.cdr();
if (remaining == NIL)
{
error(new ProgramError(
"&REST/&BODY must be followed by a variable."));
program_error("&REST/&BODY must be followed by a variable.");
}
if (restVar != null)
{
error(new ProgramError(
"&REST/&BODY may occur only once."));
program_error("&REST/&BODY may occur only once.");
}
final LispObject remainingcar = remaining.car();
if (remainingcar instanceof Symbol)
......@@ -250,14 +247,13 @@ public class ArgumentListProcessor {
}
else
{
error(new ProgramError(
"&REST/&BODY must be followed by a variable."));
program_error("&REST/&BODY must be followed by a variable.");
}
}
else if (obj == Symbol.AND_ENVIRONMENT)
{
if (type == LambdaListType.ORDINARY)
error(new ProgramError("&ENVIRONMENT not allowed in ordinary lambda lists."));
program_error("&ENVIRONMENT not allowed in ordinary lambda lists.");
remaining = remaining.cdr();
envVar = (Symbol) remaining.car();
envParam = new EnvironmentParam(envVar, isSpecial(envVar, specials));
......@@ -304,8 +300,7 @@ public class ArgumentListProcessor {
{
if (state != STATE_REQUIRED)
{
error(new ProgramError(
"required parameters cannot appear after &REST/&BODY."));
program_error("required parameters cannot appear after &REST/&BODY.");
}
if (required == null)
required = new ArrayList<Param>();
......@@ -545,8 +540,8 @@ public class ArgumentListProcessor {
}
private static void invalidParameter(LispObject obj) {
error(new ProgramError(obj.princToString() +
" may not be used as a variable in a lambda list."));
program_error(obj.princToString()
+ " may not be used as a variable in a lambda list.");
}
private Symbol[] extractVariables()
......@@ -618,8 +613,8 @@ public class ArgumentListProcessor {
if (k.keyword == key)
continue next_key;
error(new ProgramError("Unrecognized keyword argument " +
key.printObject()));
program_error("Unrecognized keyword argument "
+ key.printObject() + ".");
}
}
}
......@@ -702,8 +697,8 @@ public class ArgumentListProcessor {
arglist.consume();
if (key != Keyword.ALLOW_OTHER_KEYS)
error(new ProgramError("Invalid keyword argument " + key.printObject()));
program_error("Invalid keyword argument "
+ key.printObject() + ".");
allowOtherKeysValue = null;
}
......@@ -756,7 +751,7 @@ public class ArgumentListProcessor {
/** Asserts the number of remaining arguments is even. */
void assertRemainderKeywords() {
if (((len - argsConsumed) & 1) == 1)
error(new ProgramError("Odd number of keyword arguments."));
program_error("Odd number of keyword arguments.");
}
/** Returns the next unconsumed value from the argument set, or 'null'
......
......@@ -86,8 +86,8 @@ 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.princToString() +
" is invalid."));
program_error("The lambda list " + lambdaList.princToString()
+ " is invalid.");
this.body = lambdaExpression.cddr();
LispObject bodyAndDecls = parseBody(this.body, false);
this.executionBody = bodyAndDecls.car();
......
......@@ -48,7 +48,7 @@ public final class FloatFunctions
public LispObject execute(LispObject[] args)
{
if (args.length % 2 != 0)
error(new ProgramError("Odd number of keyword arguments."));
program_error("Odd number of keyword arguments.");
for (int i = 0; i < args.length; i += 2) {
LispObject key = checkSymbol(args[i]);
LispObject value = args[i+1];
......
......@@ -197,7 +197,8 @@ public class FuncallableStandardObject extends StandardObject
if (arg.typep(StandardClass.FUNCALLABLE_STANDARD_CLASS) != NIL) {
LispObject l = Symbol.CLASS_LAYOUT.execute(arg);
if (! (l instanceof Layout)) {
return error(new ProgramError("Invalid standard class layout for: " + arg.princToString()));
return program_error("Invalid standard class layout for: "
+ arg.princToString() + ".");
}
if (Symbol.SUBTYPEP.execute(arg, StandardClass.STANDARD_GENERIC_FUNCTION) != NIL) {
return new StandardGenericFunction((Layout)l);
......
......@@ -805,7 +805,7 @@ public final class Java
instance = instanceArg.javaInstance();
}
if(instance == null) {
return error(new ProgramError("JRESOLVE-METHOD: instance must not be null"));
return program_error("JRESOLVE-METHOD: instance must not be null.");
}
String methodName = methodArg.getStringValue();
Object[] methodArgs = translateMethodArguments(args, 2);
......
......@@ -418,11 +418,20 @@ public final class Lisp
public static final LispObject type_error(LispObject datum,
LispObject expectedType)
{
return error(new TypeError(datum, expectedType));
}
public static final LispObject program_error(String message)
{
return error(new ProgramError(message));
}
public static final LispObject program_error(LispObject initArgs)
{
return error(new ProgramError(initArgs));
}
public static volatile boolean interrupted;
public static synchronized final void setInterrupted(boolean b)
......@@ -526,8 +535,8 @@ public final class Lisp
return evalCall(closure, ((Cons)obj).cdr, env, thread);
}
else
return error(new ProgramError("Illegal function object: " +
first.princToString()));
return program_error("Illegal function object: "
+ first.princToString() + ".");
}
}
else
......
......@@ -915,14 +915,14 @@ public final class LispThread extends LispObject
LispObject name = NIL;
if (length > 1) {
if ((length - 1) % 2 != 0)
error(new ProgramError("Odd number of keyword arguments."));
program_error("Odd number of keyword arguments.");
if (length > 3)
error(new WrongNumberOfArgumentsException(this, -1, 2)); // don't count the keyword itself as an argument
if (args[1] == Keyword.NAME)
name = args[2].STRING();
else
error(new ProgramError("Unrecognized keyword argument " +
args[1].princToString() + "."));
program_error("Unrecognized keyword argument "
+ args[1].princToString() + ".");
}
return new LispThread(checkFunction(args[0]), name);
}
......
......@@ -1306,7 +1306,7 @@ public class Pathname extends LispObject {
static final Pathname _makePathname(LispObject[] args) {
if (args.length % 2 != 0) {
error(new ProgramError("Odd number of keyword arguments."));
program_error("Odd number of keyword arguments.");
}
LispObject host = NIL;
LispObject device = NIL;
......@@ -1908,8 +1908,8 @@ public class Pathname extends LispObject {
} else if (second == Keyword.VERSION) {
value = pathname.version;
} else {
return error(new ProgramError("Unrecognized keyword "
+ second.princToString() + "."));
return program_error("Unrecognized keyword "
+ second.princToString() + ".");
}
if (value == Keyword.WILD || value == Keyword.WILD_INFERIORS) {
return T;
......
......@@ -1780,9 +1780,7 @@ public final class Primitives {
if (name instanceof Symbol) {
Symbol symbol = (Symbol) name;
if (symbol.getSymbolFunction() instanceof SpecialOperator) {
String message =
symbol.getName() + " is a special operator and may not be redefined.";
return error(new ProgramError(message));
return program_error(symbol.getName() + " is a special operator and may not be redefined.");
}
} else if (!isValidSetfFunctionName(name))
return type_error(name, FUNCTION_NAME);
......@@ -2310,7 +2308,8 @@ public final class Primitives {
sb.append(args.length - 1);
sb.append(") for array of rank ");
sb.append(rank);
error(new ProgramError(sb.toString()));
sb.append(".");
program_error(sb.toString());
}
for (int i = 0; i < rank; i++) {
LispObject arg = args[i+1];
......@@ -2366,7 +2365,7 @@ public final class Primitives {
new StringBuilder("Wrong number of subscripts (0) for array of rank ");
sb.append(array.getRank());
sb.append('.');
return error(new ProgramError(sb.toString()));
return program_error(sb.toString());
}
@Override
public LispObject execute(LispObject first, LispObject second)
......
......@@ -258,7 +258,7 @@ public final class SimpleArray_T extends AbstractArray
sb.append(") for array of rank ");
sb.append(rank);
sb.append('.');
error(new ProgramError(sb.toString()));
program_error(sb.toString());
}
int sum = 0;
int size = 1;
......@@ -275,7 +275,7 @@ public final class SimpleArray_T extends AbstractArray
sb.append(" for array ");
sb.append(this);
sb.append('.');
error(new ProgramError(sb.toString()));
program_error(sb.toString());
}
sum += n * lastSize;
}
......
......@@ -235,7 +235,7 @@ public final class SimpleArray_UnsignedByte16 extends AbstractArray
sb.append(") for array of rank ");
sb.append(rank);
sb.append('.');
error(new ProgramError(sb.toString()));
program_error(sb.toString());
}
int sum = 0;
int size = 1;
......@@ -250,7 +250,7 @@ public final class SimpleArray_UnsignedByte16 extends AbstractArray
sb.append(" for array ");
sb.append(this);
sb.append('.');
error(new ProgramError(sb.toString()));
program_error(sb.toString());
}
sum += n * lastSize;
}
......
......@@ -226,7 +226,7 @@ public final class SimpleArray_UnsignedByte32 extends AbstractArray
sb.append(") for array of rank ");
sb.append(rank);
sb.append('.');
error(new ProgramError(sb.toString()));
program_error(sb.toString());
}
int sum = 0;
int size = 1;
......@@ -241,7 +241,7 @@ public final class SimpleArray_UnsignedByte32 extends AbstractArray
sb.append(" for array ");
sb.append(this);
sb.append('.');
error(new ProgramError(sb.toString()));
program_error(sb.toString());
}
sum += n * lastSize;
}
......
......@@ -222,7 +222,7 @@ public final class SimpleArray_UnsignedByte8 extends AbstractArray
sb.append(") for array of rank ");
sb.append(rank);
sb.append('.');
error(new ProgramError(sb.toString()));
program_error(sb.toString());
}
int sum = 0;
int size = 1;
......@@ -237,7 +237,7 @@ public final class SimpleArray_UnsignedByte8 extends AbstractArray
sb.append(" for array ");
sb.append(this);
sb.append('.');
error(new ProgramError(sb.toString()));
program_error(sb.toString());
}
sum += n * lastSize;
}
......
......@@ -199,16 +199,14 @@ for (Cons x : nonSequentialVars)
Symbol symbol = checkSymbol(obj.car());
if (symbol.isSpecialVariable()
|| ext.isDeclaredSpecial(symbol)) {
return error(new ProgramError(
"Attempt to bind the special variable " +
symbol.princToString() +
" with SYMBOL-MACROLET."));
return program_error("Attempt to bind the special variable "
+ symbol.princToString()
+ " with SYMBOL-MACROLET.");
}
ext.bind(symbol, new SymbolMacro(obj.cadr()));
} else {
return error(new ProgramError(
"Malformed symbol-expansion pair in SYMBOL-MACROLET: " +
obj.princToString()));
return program_error("Malformed symbol-expansion pair in SYMBOL-MACROLET: "
+ obj.princToString() + ".");
}
}
return progn(body, ext, thread);
......@@ -322,9 +320,8 @@ for (Cons x : nonSequentialVars)
if (name instanceof Symbol) {
symbol = checkSymbol(name);
if (symbol.getSymbolFunction() instanceof SpecialOperator) {
String message =
symbol.getName() + " is a special operator and may not be redefined";
return error(new ProgramError(message));
return program_error(symbol.getName()
+ " is a special operator and may not be redefined.");
}
} else if (isValidSetfFunctionName(name))
symbol = checkSymbol(name.cadr());
......@@ -521,8 +518,8 @@ for (Cons x : nonSequentialVars)
while (args != NIL) {
Symbol symbol = checkSymbol(args.car());
if (symbol.isConstant()) {
return error(new ProgramError(symbol.princToString() +
" is a constant and thus cannot be set."));
return program_error(symbol.princToString()
+ " is a constant and thus cannot be set.");
}
args = args.cdr();
if (symbol.isSpecialVariable() || env.isDeclaredSpecial(symbol)) {
......
......@@ -448,9 +448,8 @@ public class StandardObject extends LispObject
list(Symbol.INTEGER, Fixnum.ZERO,
Fixnum.getInstance(instance.slots.length - 1)));
else
return error(new ProgramError("The object "
+ instance.princToString() +
" has no slots."));
return program_error("The object " + instance.princToString()
+ " has no slots.");
}
// We let UNBOUND_VALUE escape here, since invoking
......@@ -495,10 +494,8 @@ public class StandardObject extends LispObject
list(Symbol.INTEGER, Fixnum.ZERO,
Fixnum.getInstance(instance.slots.length - 1)));
else
return error(new ProgramError("The object "
+ instance.princToString() +
" has no slots."));
return program_error("The object " + instance.princToString()
+ " has no slots.");
}
return third;
}
......@@ -664,21 +661,21 @@ public class StandardObject extends LispObject
FuncallableStandardClass cls = (FuncallableStandardClass)arg;
Layout layout = cls.getClassLayout();
if (layout == null) {
error(new ProgramError("No layout for funcallable class "
+ cls.princToString()));
program_error("No layout for funcallable class " + cls.princToString() + ".");
}
return new FuncallableStandardObject(cls, layout.getLength());
} else if (arg instanceof StandardClass) {
StandardClass cls = (StandardClass)arg;
Layout layout = cls.getClassLayout();
if (layout == null) {
error(new ProgramError("No layout for class " + cls.princToString()));
program_error("No layout for class " + cls.princToString() + ".");
}
return new StandardObject(cls, layout.getLength());
} else if (arg.typep(StandardClass.STANDARD_CLASS) != NIL) {
LispObject l = Symbol.CLASS_LAYOUT.execute(arg);
if (! (l instanceof Layout)) {
error(new ProgramError("Invalid standard class layout for class " + arg.princToString()));
program_error("Invalid standard class layout for class "
+ arg.princToString() + ".");
}
return new StandardObject((Layout)l);
} else {
......
......@@ -2233,8 +2233,8 @@ public class Stream extends StructureObject {
final Stream stream = checkStream(first);
if (second == Keyword.ABORT)
return stream.close(third);
return error(new ProgramError("Unrecognized keyword argument " +
second.princToString() + "."));
return program_error("Unrecognized keyword argument "
+ second.princToString() + ".");
}
};
......
......@@ -295,7 +295,8 @@ public class Symbol extends LispObject implements java.io.Serializable
{
if (isConstant())
// Complement the check already done in SpecialOperators.sf_setq
error(new ProgramError("Can't change value of constant symbol " + princToString() + "."));
program_error("Can't change value of constant symbol "
+ princToString() + ".");
this.value = value;
}
......@@ -311,7 +312,7 @@ public class Symbol extends LispObject implements java.io.Serializable
public void setSymbolMacro(SymbolMacro symbolMacro) {
if(isSpecialVariable()) {
error(new ProgramError("Symbol " + princToString() + " names a special variable; can't install symbol macro."));
program_error("Symbol " + princToString() + " names a special variable; can't install symbol macro.");
}
put(this, SYMBOL_MACRO, symbolMacro);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment