/interpreter/tags/at_build150307/src/edu/vub/at/objects/grammar/ATDefExternalMethod.java

http://ambienttalk.googlecode.com/ · Java · 69 lines · 8 code · 4 blank · 57 comment · 0 complexity · f9c7708f69d894f0334d13847eef0536 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. /**
  31. * @author tvc
  32. *
  33. * The public interface to an external method definition abstract grammar element.
  34. * Created when evaluating <tt>def o.m() { body }</tt>
  35. *
  36. * There are three ways to evaluate such expressions with respect to what context should be
  37. * active when the method is invoked upon the object:
  38. * 1) The newly defined method is wrapped in a closure thereby fixing the lexical scope that was
  39. * active at method definition/addition time, as well as the values of 'self' and 'super'.
  40. * This has the advantage that within the externally added method body:
  41. * a) the adding object can still access its lexical scope.
  42. * b) the adding object can *not* access the scope of the object it is adding a method to.
  43. * This has the disadvantage that within the externally added method body,
  44. * 'self' and 'super' keep on referring to the lexically active self and super. This has the
  45. * disadvantage that the newly added method cannot perform 'super sends', nor is the value of
  46. * 'self' correct when the method is invoked through a child of o.
  47. * 2) The newly defined method is added as-is to the object. This has roughly the reverse
  48. * effects of option 1: the adding object loses its lexical scope (error-prone and dangerous!)
  49. * but the values for self and super are correct. It is as if the method was really defined
  50. * in the scope of the original object.
  51. * 3) The newly defined method is wrapped in a special 'objectless' closure that captures the
  52. * lexical scope of the adding object but *not* the values of 'self' and 'super'. When the
  53. * added method is subsequently invoked, its lexical scope will still be that of the adding
  54. * object (hence, having the benefits of option 1) while the values of 'self' and 'super'
  55. * will be correct with respect to the method invocation on o (or a child of o) (hence,
  56. * having the benefits of option 2).
  57. *
  58. * AmbientTalk implements the third option, by means of a NATClosureMethod.
  59. */
  60. public interface ATDefExternalMethod extends ATDefinition {
  61. public ATSymbol base_getReceiver();
  62. public ATSymbol base_getSelector();
  63. public ATTable base_getArguments();
  64. public ATBegin base_getBodyExpression();
  65. }