/interpreter/tags/at2-build270707/src/edu/vub/at/objects/grammar/ATDefExternalMethod.java

http://ambienttalk.googlecode.com/ · Java · 94 lines · 9 code · 7 blank · 78 comment · 0 complexity · a916b322a504848514c1718269ec4b57 MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * ATDefExternalMethod.java created on 15-nov-2006 at 19:23:51
  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.grammar;
  29. import edu.vub.at.objects.ATTable;
  30. import edu.vub.at.objects.natives.NATClosureMethod;
  31. /**
  32. * The public interface to an external method definition AG element.
  33. *
  34. * <p>
  35. * Example: <code>def o.m() { body }</code>
  36. * </p><p>
  37. * There are three ways to evaluate such expressions with respect to what context should be
  38. * active when the method is invoked upon the object:
  39. * <ol>
  40. * <li> The newly defined method is wrapped in a closure thereby fixing the lexical scope that was
  41. * active at method definition/addition time, as well as the values of 'self' and 'super'.
  42. * This has the advantage that within the externally added method body:
  43. * a) the adding object can still access its lexical scope.
  44. * b) the adding object can *not* access the scope of the object it is adding a method to.
  45. * This has the disadvantage that within the externally added method body,
  46. * 'self' and 'super' keep on referring to the lexically active self and super. This has the
  47. * disadvantage that the newly added method cannot perform 'super sends', nor is the value of
  48. * 'self' correct when the method is invoked through a child of o.</li>
  49. * <li> The newly defined method is added as-is to the object. This has roughly the reverse
  50. * effects of option 1: the adding object loses its lexical scope (error-prone and dangerous!)
  51. * but the values for self and super are correct. It is as if the method was really defined
  52. * in the scope of the original object.</li>
  53. * <li> The newly defined method is wrapped in a special 'objectless' closure that captures the
  54. * lexical scope of the adding object but *not* the values of 'self' and 'super'. When the
  55. * added method is subsequently invoked, its lexical scope will still be that of the adding
  56. * object (hence, having the benefits of option 1) while the values of 'self' and 'super'
  57. * will be correct with respect to the method invocation on o (or a child of o) (hence,
  58. * having the benefits of option 2.</li>
  59. * </ol>
  60. * </p><p>
  61. * AmbientTalk implements the third option, by means of a {@link NATClosureMethod}.
  62. * </p>
  63. *
  64. * @author tvc
  65. */
  66. public interface ATDefExternalMethod extends ATDefinition {
  67. /**
  68. * Example: <code>`{ def o.m() { 5 } }.statements[1].receiver == `o</code>
  69. * @return the receiver on which the method will be defined
  70. */
  71. public ATSymbol base_receiver();
  72. /**
  73. * Example: <code>`{ def o.m() { 5 } }.statements[1].selector == `m</code>
  74. * @return the selector of the new method
  75. */
  76. public ATSymbol base_selector();
  77. /**
  78. * Example: <code>`{ def o.m(a, @b) { b } }.statements[1].arguments == `[a, @b]</code>
  79. * @return the argument list of the new method
  80. */
  81. public ATTable base_arguments();
  82. /**
  83. * Example: <code>`{ def o.m() { o.n(); 1+2+3 } }.statements[1].bodyExpression == `{o.n(); 1.+(2).+(3)}</code>
  84. * @return the body of the new method
  85. */
  86. public ATBegin base_bodyExpression();
  87. }