/interpreter/tags/at2-build270707/src/edu/vub/at/objects/natives/OBJNil.java

http://ambienttalk.googlecode.com/ · Java · 123 lines · 46 code · 17 blank · 60 comment · 0 complexity · e82c8eeb22cc0bd2dfe04c3f7e833734 MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * NATNil.java created on 15 jul 2007 at 18:33:28
  4. * (c) Programming Technology Lab, 2006 - 2007
  5. * Authors: Tom Van Cutsem & Stijn Mostinckx
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use,
  11. * copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following
  14. * conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  21. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  23. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  24. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. package edu.vub.at.objects.natives;
  29. import edu.vub.at.exceptions.InterpreterException;
  30. import edu.vub.at.objects.ATBoolean;
  31. import edu.vub.at.objects.ATClosure;
  32. import edu.vub.at.objects.ATNil;
  33. import edu.vub.at.objects.ATObject;
  34. import edu.vub.at.objects.ATTable;
  35. import edu.vub.at.objects.grammar.ATAssignmentSymbol;
  36. import edu.vub.at.objects.grammar.ATSymbol;
  37. /**
  38. * This class encapsulates the behaviour of the native
  39. * <tt>nil</tt> AmbientTalk object.
  40. *
  41. * @author tvcutsem
  42. */
  43. public class OBJNil extends NATByCopy implements ATNil {
  44. /**
  45. * This field holds the sole instance of this class. In AmbientTalk,
  46. * this is the object that represents <tt>nil</tt>.
  47. */
  48. public final static OBJNil _INSTANCE_ = new OBJNil();
  49. /**
  50. * Constructor made private for singleton design pattern
  51. */
  52. private OBJNil() { }
  53. /**
  54. * Nil has a special parent object which ends the recursion
  55. * along the dynamic delegation chain. These methods cannot be implemented
  56. * directly in this class because this class still implements useful
  57. * <tt>base_</tt> Java methods which have to be invoked by means of the
  58. * implementations defined in {@link NativeATObject}.
  59. */
  60. private final NativeATObject dynamicSentinel_ = new NATByCopy() {
  61. private static final long serialVersionUID = -1307795172754062220L;
  62. // METHODS THAT END THE DYNAMIC DELEGATION CHAIN
  63. public ATBoolean meta_respondsTo(ATSymbol selector) throws InterpreterException {
  64. // no more delegation
  65. return NATBoolean._FALSE_;
  66. }
  67. /**
  68. * When performing <tt>o.m()</tt> and <tt>m</tt> is not found, invoke
  69. * <tt>doesNotUnderStand</tt> and apply the resulting closure to the given arguments.
  70. */
  71. public ATObject impl_invokeAccessor(ATObject receiver, ATSymbol selector, ATTable arguments) throws InterpreterException {
  72. return receiver.meta_doesNotUnderstand(selector).base_apply(arguments);
  73. }
  74. public ATObject impl_invokeMutator(ATObject receiver, ATAssignmentSymbol selector, ATTable arguments) throws InterpreterException {
  75. return receiver.meta_doesNotUnderstand(selector).base_apply(arguments);
  76. }
  77. /**
  78. * When performing <tt>o.x</tt> and <tt>x</tt> is not found, invoke
  79. * <tt>doesNotUnderStand</tt> and apply the corresponding closure with zero arguments.
  80. */
  81. public ATObject meta_invokeField(ATObject receiver, ATSymbol selector) throws InterpreterException {
  82. return receiver.meta_doesNotUnderstand(selector).base_apply(NATTable.EMPTY);
  83. }
  84. public ATClosure impl_selectAccessor(ATObject receiver, final ATSymbol selector) throws InterpreterException {
  85. return receiver.meta_doesNotUnderstand(selector);
  86. }
  87. public ATClosure impl_selectMutator(ATObject receiver, final ATAssignmentSymbol selector) throws InterpreterException {
  88. return receiver.meta_doesNotUnderstand(selector);
  89. }
  90. public NATText meta_print() throws InterpreterException {
  91. return NATText.atValue("dynamicsentinel");
  92. }
  93. };
  94. public ATObject base_super() {
  95. return dynamicSentinel_;
  96. }
  97. /**
  98. * After deserialization, ensure that nil remains unique.
  99. */
  100. public ATObject meta_resolve() throws InterpreterException {
  101. return OBJNil._INSTANCE_;
  102. }
  103. public NATText meta_print() throws InterpreterException {
  104. return NATText.atValue("nil");
  105. }
  106. }