/interpreter/tags/at2dist170907/src/edu/vub/at/objects/natives/NATMethodInvocation.java

http://ambienttalk.googlecode.com/ · Java · 102 lines · 50 code · 9 blank · 43 comment · 0 complexity · b2174ee0c55cbaece61371f75da51fd7 MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * NATMethodInvocation.java created on 31-jul-2006 at 12:40:42
  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.eval.Evaluator;
  30. import edu.vub.at.exceptions.InterpreterException;
  31. import edu.vub.at.objects.ATMessage;
  32. import edu.vub.at.objects.ATMethodInvocation;
  33. import edu.vub.at.objects.ATObject;
  34. import edu.vub.at.objects.ATTypeTag;
  35. import edu.vub.at.objects.ATTable;
  36. import edu.vub.at.objects.coercion.NativeTypeTags;
  37. import edu.vub.at.objects.grammar.ATSymbol;
  38. import java.util.LinkedList;
  39. import java.util.Vector;
  40. /**
  41. * Instances of this class represent first-class method invocations.
  42. * They encapsulate a selector and arguments and may be turned into an actual invocation by invoking meta_sendTo.
  43. * This method provides the invocation with a receiver to apply itself to.
  44. *
  45. * @author tvcutsem
  46. */
  47. public final class NATMethodInvocation extends NATMessage implements ATMethodInvocation {
  48. public NATMethodInvocation(ATSymbol sel, ATTable arg, ATTable annotations) throws InterpreterException {
  49. super(sel, arg, annotations, NativeTypeTags._METHODINV_);
  50. }
  51. /**
  52. * Copy constructor.
  53. */
  54. private NATMethodInvocation(FieldMap map,
  55. Vector state,
  56. LinkedList originalCustomFields,
  57. MethodDictionary methodDict,
  58. ATObject dynamicParent,
  59. ATObject lexicalParent,
  60. byte flags,
  61. ATTypeTag[] types) throws InterpreterException {
  62. super(map, state, originalCustomFields, methodDict, dynamicParent, lexicalParent, flags, types);
  63. }
  64. /**
  65. * To evaluate a method invocation, invoke the method corresponding to the encapsulated
  66. * selector to the given receiver with the encapsulated arguments.
  67. *
  68. * @return the return value of the invoked method.
  69. */
  70. public ATObject prim_sendTo(ATMessage self, ATObject receiver, ATObject sender) throws InterpreterException {
  71. return receiver.meta_invoke(receiver, self.base_selector(), self.base_arguments());
  72. }
  73. public NATText meta_print() throws InterpreterException {
  74. return NATText.atValue("<method invocation:"+base_selector()+Evaluator.printAsList(base_arguments()).javaValue+">");
  75. }
  76. protected NATObject createClone(FieldMap map,
  77. Vector state,
  78. LinkedList originalCustomFields,
  79. MethodDictionary methodDict,
  80. ATObject dynamicParent,
  81. ATObject lexicalParent,
  82. byte flags,
  83. ATTypeTag[] types) throws InterpreterException {
  84. return new NATMethodInvocation(map,
  85. state,
  86. originalCustomFields,
  87. methodDict,
  88. dynamicParent,
  89. lexicalParent,
  90. flags,
  91. types);
  92. }
  93. }