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

http://ambienttalk.googlecode.com/ · Java · 109 lines · 12 code · 8 blank · 89 comment · 0 complexity · 8b7332f4e1eede2c7085ce7c45ba171d MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * ATMethod.java created on Jul 24, 2006 at 9:42:24 PM
  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;
  29. import edu.vub.at.exceptions.InterpreterException;
  30. import edu.vub.at.objects.grammar.ATBegin;
  31. import edu.vub.at.objects.grammar.ATSymbol;
  32. /**
  33. * ATMethods are the AmbientTalk's representation of methods as named functions. These
  34. * functions do not close over an environment allowing for them to be shared between
  35. * different clones. The environment is to be supplied during lookup (which wraps an
  36. * ATMethod into {@link ATClosure}). As a consequence, it is not possible to
  37. * get hold of an ATMethod at the base-level (since lookup implies wrapping).
  38. *
  39. * @author smostinc
  40. * @author tvcutsem
  41. */
  42. public interface ATMethod extends ATObject {
  43. /**
  44. * Wrap the receiver method into a closure which packs together the code (method) and the scope (context)
  45. * in which the code should be evaluated.
  46. *
  47. * @param lexicalScope the lexical scope in which the method was created. During method invocation,
  48. * lexical lookup should proceed along this scope.
  49. * @param dynamicReceiver the dynamic receiver (value of <tt>self</tt>) at the time the method is
  50. * selected from an object.
  51. * @return a closure wrapping this method.
  52. */
  53. public ATClosure base_wrap(ATObject lexicalScope, ATObject dynamicReceiver) throws InterpreterException;
  54. /**
  55. * Applies the method to the given arguments in the given context.
  56. * The context is usually supplied by a closure and is necessary in order to
  57. * pair a method with its current receiver (its 'self').
  58. * <p>
  59. * The method itself is responsible for creating the appropriate 'call frame'
  60. * or activation record in which to define temporary variables and parameter bindings.
  61. *
  62. * @param arguments the actual arguments, already eagerly evaluated.
  63. * @param ctx the context in which to evaluate the method body, call frame not yet inserted.
  64. * @return the value of evaluating the method body in a context derived from the given context.
  65. */
  66. public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException;
  67. /**
  68. * Applies the method to the given arguments in the given context.
  69. * The context is usually supplied by a closure and is necessary in order to
  70. * pair a method with its current receiver (its 'self').
  71. * <p>
  72. * The method will use the given context 'as-is', and will *not* insert an additional call frame.
  73. *
  74. * @param arguments the actual arguments, already eagerly evaluated.
  75. * @param ctx the context in which to evaluate the method body, to be used without inserting a call frame.
  76. * @return the value of evaluating the method body in the given context.
  77. */
  78. public ATObject base_applyInScope(ATTable arguments, ATContext ctx) throws InterpreterException;
  79. /**
  80. * Returns the name of the method.
  81. * <p>
  82. * Note that all methods (defined using <code>def name( ...args... ) { ... }</code> or <code>def foo: arg bar: arg { ... }</code>)
  83. * retain the name with which they were first bound. Literal blocks which may be created
  84. * outside of a definition are implicitly named 'lambda'.
  85. *
  86. * @return an {@link ATSymbol} representing the name by which the method can be identified.
  87. */
  88. public ATSymbol base_name() throws InterpreterException;
  89. /**
  90. * Returns the parameter list of the method which is normally a table of symbols.
  91. *
  92. * @return an {@link ATTable} representing the parameter list of the method.
  93. */
  94. public ATTable base_parameters() throws InterpreterException;
  95. /**
  96. * Returns the body of the method.
  97. *
  98. * @return an {@link ATBegin} representing the body of the method.
  99. */
  100. public ATBegin base_bodyExpression() throws InterpreterException;
  101. }