PageRenderTime 31ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/armedbear/lisp/PackageError.java

https://code.google.com/p/abcl-dynamic-install/
Java | 126 lines | 74 code | 13 blank | 39 comment | 15 complexity | e4c9f6d24cd760bc104b644ae7eaea7c MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * PackageError.java
  3. *
  4. * Copyright (C) 2003-2005 Peter Graves
  5. * $Id$
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *
  21. * As a special exception, the copyright holders of this library give you
  22. * permission to link this library with independent modules to produce an
  23. * executable, regardless of the license terms of these independent
  24. * modules, and to copy and distribute the resulting executable under
  25. * terms of your choice, provided that you also meet, for each linked
  26. * independent module, the terms and conditions of the license of that
  27. * module. An independent module is a module which is not derived from
  28. * or based on this library. If you modify this library, you may extend
  29. * this exception to your version of the library, but you are not
  30. * obligated to do so. If you do not wish to do so, delete this
  31. * exception statement from your version.
  32. */
  33. package org.armedbear.lisp;
  34. import static org.armedbear.lisp.Lisp.*;
  35. public final class PackageError extends LispError
  36. {
  37. public PackageError(LispObject initArgs)
  38. {
  39. super(StandardClass.PACKAGE_ERROR);
  40. initialize(initArgs);
  41. }
  42. @Override
  43. protected void initialize(LispObject initArgs)
  44. {
  45. super.initialize(initArgs);
  46. if (initArgs.listp() && initArgs.car().stringp()) {
  47. setFormatControl(initArgs.car().getStringValue());
  48. // When printing an error string, presumably, if the string contains
  49. // a symbol, we'll want to complain about its full name, not the accessible
  50. // name, because it may omit an (important) package name part.
  51. // Two problems: (1) symbols can be contained in sublists
  52. // (2) symbols may not be printed, but used otherwise.
  53. // ### FIXME: why special-case that here: binding *PRINT-ESCAPE* to T
  54. // will do exactly this, if the reader requests it.
  55. for (LispObject arg = initArgs.cdr(); arg != NIL; arg = arg.cdr()) {
  56. if (arg.car() instanceof Symbol)
  57. arg.setCar(new SimpleString(((Symbol)arg.car()).getQualifiedName()));
  58. }
  59. setFormatArguments(initArgs.cdr());
  60. setPackage(NIL);
  61. return;
  62. }
  63. LispObject pkg = NIL;
  64. LispObject first, second;
  65. while (initArgs != NIL) {
  66. first = initArgs.car();
  67. initArgs = initArgs.cdr();
  68. second = initArgs.car();
  69. initArgs = initArgs.cdr();
  70. if (first == Keyword.PACKAGE)
  71. pkg = second;
  72. }
  73. setPackage(pkg);
  74. }
  75. public PackageError(String message)
  76. {
  77. super(StandardClass.PACKAGE_ERROR);
  78. setFormatControl(message);
  79. }
  80. @Override
  81. public LispObject typeOf()
  82. {
  83. return Symbol.PACKAGE_ERROR;
  84. }
  85. @Override
  86. public LispObject classOf()
  87. {
  88. return StandardClass.PACKAGE_ERROR;
  89. }
  90. @Override
  91. public LispObject typep(LispObject type)
  92. {
  93. if (type == Symbol.PACKAGE_ERROR)
  94. return T;
  95. if (type == StandardClass.PACKAGE_ERROR)
  96. return T;
  97. return super.typep(type);
  98. }
  99. public LispObject getPackage()
  100. {
  101. Debug.assertTrue(layout != null);
  102. int index = layout.getSlotIndex(Symbol.PACKAGE);
  103. Debug.assertTrue(index >= 0);
  104. return slots[index];
  105. }
  106. public void setPackage(LispObject pkg)
  107. {
  108. Debug.assertTrue(layout != null);
  109. int index = layout.getSlotIndex(Symbol.PACKAGE);
  110. Debug.assertTrue(index >= 0);
  111. slots[index] = pkg;
  112. }
  113. }