PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/interpreter/tags/at2dist110511/src/edu/vub/at/objects/ATObject.java

http://ambienttalk.googlecode.com/
Java | 1099 lines | 80 code | 69 blank | 950 comment | 0 complexity | 6f11ce5205811d8be1d4621ec6671376 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, LGPL-2.1
  1. /**
  2. * AmbientTalk/2 Project
  3. * ATObject.java created on 13-jul-2006 at 15:33: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;
  29. import java.util.HashMap;
  30. import edu.vub.at.actors.ATAsyncMessage;
  31. import edu.vub.at.exceptions.InterpreterException;
  32. import edu.vub.at.exceptions.XArityMismatch;
  33. import edu.vub.at.exceptions.XDuplicateSlot;
  34. import edu.vub.at.exceptions.XIllegalQuote;
  35. import edu.vub.at.exceptions.XIllegalUnquote;
  36. import edu.vub.at.exceptions.XObjectOffline;
  37. import edu.vub.at.exceptions.XSelectorNotFound;
  38. import edu.vub.at.exceptions.XUnassignableField;
  39. import edu.vub.at.exceptions.XUndefinedSlot;
  40. import edu.vub.at.objects.coercion.ATConversions;
  41. import edu.vub.at.objects.grammar.ATAssignmentSymbol;
  42. import edu.vub.at.objects.grammar.ATSymbol;
  43. import edu.vub.at.objects.mirrors.NATMirage;
  44. import edu.vub.at.objects.mirrors.NATMirrorRoot;
  45. import edu.vub.at.objects.natives.NATCallframe;
  46. import edu.vub.at.objects.natives.NATMessage;
  47. import edu.vub.at.objects.natives.NATObject;
  48. import edu.vub.at.objects.natives.NATText;
  49. import edu.vub.at.objects.natives.NativeATObject;
  50. import edu.vub.at.objects.natives.grammar.NATAbstractGrammar;
  51. import edu.vub.at.objects.symbiosis.JavaClass;
  52. import edu.vub.at.objects.symbiosis.JavaObject;
  53. import edu.vub.at.parser.SourceLocation;
  54. import edu.vub.util.TempFieldGenerator;
  55. /**
  56. * ATObject represents the public interface common to any AmbientTalk/2 object.
  57. * Any value representing an ambienttalk object should implement this interface.
  58. *
  59. * More specifically, this interface actually defines two interfaces all at once:
  60. * <ul>
  61. * <li>A <b>base-level</b> interface to AmbientTalk objects, describing all
  62. * methods and fields that a regular AmbientTalk object understands.
  63. * <li>A <b>meta-level</b> interface to AmbientTalk objects, describing all
  64. * methods and fields that the <b>mirror</b> on any AmbientTalk object
  65. * understands.
  66. * </ul>
  67. *
  68. * In the AmbientTalk/2 Interpreter implementation, there are only a few classes
  69. * that (almost) fully implement this interface. The principal implementors are:
  70. *
  71. * <ul>
  72. * <li>{@link NativeATObject}: provides a default implementation for all <i>native</i> data types.
  73. * For example, native methods, closures, abstract grammar nodes, booleans, numbers, etc.
  74. * are all represented as AmbientTalk objects with 'native' behaviour.
  75. * <li>{@link NATCallframe}: overrides most of the default behaviour of {@link NativeATObject} to
  76. * implement the behaviour of call frames, also known as <i>activation records</i>. In
  77. * AmbientTalk, call frames are the objects that together define the runtime stack.
  78. * They are objects with support for fields but without support for actual methods.
  79. * <li>{@link NATObject}: extends the behaviour of call frames to include support for
  80. * full-fledged, programmer-defined objects with support for methods and delegation.
  81. * <li>{@link JavaClass} and {@link JavaObject}: adapt the behaviour of native AmbientTalk
  82. * objects to engage in symbiosis with either a Java class or a Java object.
  83. * This implementation makes use of the Java Reflection API to regard Java objects
  84. * as though it were AmbientTalk objects.
  85. * <li>{@link NATMirage} and {@link NATMirrorRoot}: these two classes work in tandem to
  86. * enable reflection on AmbientTalk objects. That is, because of these two classes, an
  87. * AmbientTalk programmer can himself invoke the methods provided in this interface.
  88. * {@link NATMirage} implements each operation in this interface by forwarding a
  89. * downed invocation to a custom so-called <i>mirror</i> object. This mirror object
  90. * can delegate to {@link NATMirrorRoot}, which is a special object that implements
  91. * each meta-level operation of this interface as a base-level operation. Hence, in
  92. * a sense, {@link NATMirrorRoot} also 'implements' this interface, but at the
  93. * AmbientTalk level, rather than at the Java level.
  94. * </ul>
  95. *
  96. * @author tvcutsem
  97. */
  98. public interface ATObject extends ATConversions {
  99. /* ------------------------------
  100. * -- Message Sending Protocol --
  101. * ------------------------------ */
  102. /**
  103. * This behavioural meta-level operation reifies the act of sending
  104. * an asynchronous message.
  105. *
  106. * When the base-level AmbientTalk code <code>rcv<-m()</code> is
  107. * evaluated in the context of an object <tt>o</tt>, an asynchronous message
  108. * <code><-m()</code> is first created by the current actor mirror.
  109. * Subsequently, this message needs to be sent to the receiver. This
  110. * meta-level operation is reified by this method, as if by invoking:
  111. * <pre>(reflect: o).send(message)</pre>
  112. * The default behaviour is to access the current actor's mirror and to
  113. * ask the actor to send the message in this object's stead by invoking
  114. * <pre>actor.send(message)</pre>
  115. * @param receiver the object designated to receive the asynchronous message
  116. * @param message the asynchronous message to be sent by this object
  117. *
  118. * @return the result of message sending, which will be the value of an
  119. * asynchronous message send expression.
  120. */
  121. public ATObject meta_send(ATObject receiver, ATAsyncMessage message) throws InterpreterException;
  122. /**
  123. * This behavioural meta-level operation reifies the act of receiving
  124. * an asynchronous message.
  125. *
  126. * When an asynchronous message is sent to an AmbientTalk object, its mirror
  127. * is notified of this event by the invocation of this method. The method
  128. * is invoked in the same execution turn as the turn in which the message
  129. * is sent. This allows the receiver (e.g. a custom eventual reference proxy)
  130. * to intervene in the message sending process and return a value different
  131. * than the default <tt>nil</tt> value.
  132. * <p>
  133. * The default behaviour of a mirror on a local reference in response to
  134. * the reception of an async
  135. * message is to schedule this message for execution in a later turn
  136. * in its owner's message queue. The actor will then later process
  137. * the message by invoking
  138. * <pre>msg.process(self)</pre>
  139. * In turn, the default message processing behaviour is to invoke
  140. * the method corresponding to the message's selector on this object.
  141. * Hence, usually a <tt>receive</tt> operation is translated into
  142. * a <tt>invoke</tt> operation in a later turn. The reason for having a
  143. * separate <tt>receive</tt>
  144. * operation is that this enables the AmbientTalk meta-level programmer to
  145. * distinguish between synchronously and asynchronously received messages.
  146. *
  147. * Far references react to <tt>receive</tt> by transmitting their message
  148. * to their remote target.
  149. *
  150. * @param message the message that was asynchronously sent to this object
  151. * @return <tt>nil</tt>, by default
  152. */
  153. public ATObject meta_receive(ATAsyncMessage message) throws InterpreterException;
  154. /**
  155. * This meta-level operation reifies synchronous message sending ("method invocation").
  156. * Hence, the meta-level equivalent
  157. * of the base-level code <code>o.m()</code> is:
  158. * <pre>(reflect: o).invoke(o,`m,[])</pre>.
  159. *
  160. * Method invocation comprises selector lookup and the application of the value
  161. * bound to the selector. Selector lookup first queries an object's local
  162. * fields, then the method dictionary:
  163. * <ul>
  164. * <li>If the selector ends with <tt>:=</tt> and matches a field, the field
  165. * is assigned if a unary argument list is specified (i.e. the field is treated
  166. * as a mutator method).
  167. * <li>Otherwise, if the selector is bound to a field containing
  168. * a closure, that closure is applied to the given arguments.
  169. * <li>If the field is not bound to a closure, the field value is returned provided no arguments were
  170. * specified (i.e. the field is treated like an accessor method).
  171. * <li>If the selector is bound to a method, the method is applied.
  172. * <li>If the selector is not found, the search continues in the objects <i>dynamic parent</i>.
  173. * </ul>
  174. * <p>
  175. * Note also that the first argument to <tt>invoke</tt> denotes the
  176. * so-called "receiver" of the invocation. It is this object to which
  177. * the <tt>self</tt> pseudo-variable should be bound during method execution.
  178. *
  179. * @see #meta_doesNotUnderstand(ATSymbol) for what happens if the selector
  180. * is not found.
  181. *
  182. * @param delegate the object to which <tt>self</tt> is bound during execution
  183. * of the method
  184. * @param invocation an object encapsulating at least the invocation's
  185. * <tt>selector</tt> (a {@link ATSymbol}) and <tt>arguments</tt> (a {@link ATTable}).
  186. * @return by default, the object returned from the invoked method
  187. */
  188. public ATObject meta_invoke(ATObject delegate, ATMethodInvocation invocation) throws InterpreterException;
  189. /**
  190. * This meta-level operation reifies "field selection".
  191. * In other words, the base-level code
  192. * <code>o.m</code>
  193. * is interpreted at the meta-level as:
  194. * <code>(reflect: o).invokeField(o, `m)</code>
  195. *
  196. * This meta-level operation is nearly identical to {@link #meta_invoke(ATObject, ATMethodInvocation)} with one
  197. * important difference. When the selector is bound to a field storing a closure, this meta-level operation
  198. * does <b>not</b> auto-apply the closure, but returns the closure instead.
  199. *
  200. * For all other cases, the following equality holds:
  201. * <code>o.m == o.m()</code>
  202. * or, at the meta-level:
  203. * <code>(reflect: o).invokeField(o, `m) == (reflect: o).invoke(o, MethodInvocation.new(`m, []))</code>
  204. *
  205. * This effectively means that for client objects, it should not matter whether
  206. * a property is implemented as a field or as a pair of accessor/mutator methods.
  207. *
  208. * @param receiver the base-level object from which the 'field' should be selected.
  209. * @param selector a symbol denoting the name of the method, accessor or mutator to be invoked
  210. * @return the value of a field, or the return value of a nullary method.
  211. */
  212. public ATObject meta_invokeField(ATObject receiver, ATSymbol selector) throws InterpreterException;
  213. /**
  214. * This meta-level method is used to determine whether an object has a
  215. * field or method corresponding to the given selector, without actually invoking
  216. * or selecting any value associated with that selector.
  217. * <p>
  218. * The lookup process is the same as that for the <tt>invoke</tt> operation (i.e.
  219. * not only the object's own fields and methods are searched, but also those of
  220. * its dynamic parents).
  221. *
  222. * @param selector a symbol denoting the name of a field (accessor or mutator) or method
  223. * @return a boolean denoting whether the object responds to <tt>o.selector</tt>
  224. */
  225. public ATBoolean meta_respondsTo(ATSymbol selector) throws InterpreterException;
  226. /**
  227. * This behavioural meta-level operation reifies a failed dynamic method or field lookup.
  228. *
  229. * When method invocation or field selection fails to find the selector in
  230. * the dynamic parent chain of an object, rather than immediately raising an
  231. * {@link XSelectorNotFound} exception, the mirror of the original receiver
  232. * of the method invocation or field selection is asked to handle failed lookup.
  233. * <p>
  234. * The default behaviour of <tt>doesNotUnderstand</tt> is to raise an
  235. * {@link XSelectorNotFound} exception.
  236. * <p>
  237. * This method is very reminiscent of Smalltalk's well-known
  238. * <tt>doesNotUnderstand:</tt> and of Ruby's <tt>method_missing</tt> methods.
  239. * There are, however, two important differences:
  240. * <ul>
  241. * <li> <tt>doesNotUnderstand</tt> is a <b>meta</b>-level operation in AmbientTalk.
  242. * It is an operation defined on mirrors, not on regular objects.
  243. * <li> <tt>doesNotUnderstand</tt> in AmbientTalk relates to <i>attribute
  244. * selection</i>, not to <i>method invocation</i>. Hence, this operation is
  245. * more general in AmbientTalk than in Smalltalk: it intercepts both failed
  246. * method invocations as well as failed field selections. Hence, it can be used
  247. * to model "virtual" fields. This shows in the interface: this operation
  248. * does not consume the actual arguments of a failed method invocation. Moreover,
  249. * a closure should be returned which can subsequently be applied for failed invocations.
  250. * Failed selections can simply return this closure without application. Hence, arguments
  251. * should be consumed by means of currying, e.g. by making <tt>doesNotUnderstand</tt>
  252. * return a block which can then take the arguments table as its sole parameter.
  253. * </ul>
  254. *
  255. * @param selector a symbol denoting the name of a method or field that could not be found
  256. * @return by default, this operation does not return a value, but raises an exception instead.
  257. * @throws edu.vub.at.exceptions.XSelectorNotFound the default reaction to a failed selection
  258. */
  259. public ATClosure meta_doesNotUnderstand(ATSymbol selector) throws InterpreterException;
  260. /* -----------------------------
  261. * -- Object Passing protocol --
  262. * ----------------------------- */
  263. /**
  264. * This behavioural meta-level operation reifies object serialization.
  265. *
  266. * When an AmbientTalk object crosses actor boundaries, e.g. by means of
  267. * parameter passing, as a return value or because it was explicitly
  268. * exported, this meta-level operation is invoked on the object's mirror.
  269. * <p>
  270. * This operation allows objects to specify themselves how they should
  271. * be parameter-passed during inter-actor communication. The interpreter
  272. * will never pass an object to another actor directly, but instead always
  273. * parameter-passes the <i>return value</i> of invoing <tt>pass()</tt> on
  274. * the object's mirror.
  275. * <p>
  276. * Mirrors on by-copy objects implement <tt>pass</tt> as follows:
  277. * <pre>def pass() { base }</pre>
  278. * Mirrors on by-reference objects implement <tt>pass</tt> by returning
  279. * a far reference to their base-level object.
  280. *
  281. * @return the object to be parameter-passed instead of this object. For objects,
  282. * the default is a far reference to themselves. For isolates, the default is
  283. * to return themselves.
  284. */
  285. public ATObject meta_pass() throws InterpreterException;
  286. /**
  287. * This behavioural meta-level operation reifies object deserialization.
  288. *
  289. * When an AmbientTalk object has just crossed an actor boundary (e.g.
  290. * because of inter-actor message sending) this meta-level operation
  291. * is invoked on the object's mirror.
  292. * <p>
  293. * This meta-level operation gives objects a chance to tell the interpreter
  294. * which object they actually represent, because the object retained
  295. * after parameter passing is the return value of the <tt>resolve</tt>
  296. * operation.
  297. * <p>
  298. * Mirrors on by-copy objects, like isolates, implement <tt>resolve</tt> as follows:
  299. * <pre>def resolve() { base }</pre>
  300. * In other words, by-copy objects represent themselves. By-reference objects
  301. * are paremeter passed as far references. Mirrors on far references implement
  302. * <tt>resolve</tt> by trying to resolve the far reference into a local, regular
  303. * object reference (which is possible if the object they point to is located
  304. * in the actor in which they just arrived). If it is not possible to resolve
  305. * a far reference into a local object, the far reference remains a far reference.
  306. * <p>
  307. * Note that for isolates, this operation also ensures that the isolate's
  308. * lexical scope is rebound to the lexical root of the recipient actor.
  309. *
  310. * @return the object represented by this object
  311. * @throws XObjectOffline if a far reference to a local object can no longer be resolved
  312. * because the object has been taken offline
  313. */
  314. public ATObject meta_resolve() throws InterpreterException;
  315. /* ------------------------------------------
  316. * -- Slot accessing and mutating protocol --
  317. * ------------------------------------------ */
  318. /**
  319. * This meta-level operation reifies first-class field or method selection. Hence, the
  320. * base-level evaluation of <code>o.&x</code> is interpreted at the meta-level as:
  321. * <pre>(reflect: o).select(o, `x)</pre>
  322. *
  323. * The selector lookup follows the same search rules as those for <tt>invoke</tt>.
  324. * That is: first an object's local fields and method dictionary are searched,
  325. * and only then the object's <i>dynamic parent</i>.
  326. * <p>
  327. * The <tt>select</tt> operation can be used to both select fields or methods from
  328. * an object. When the selector is bound to a method, the return value of
  329. * <tt>select</tt> is a closure that wraps the found method in the object in which
  330. * the method was found. This ensures that the method retains its context information,
  331. * such as the lexical scope in which it was defined and the value of <tt>self</tt>, which
  332. * will be bound to the original receiver, i.e. the first argument of <tt>select</tt>.
  333. * <p>
  334. * If the selector matches a field, an accessor is returned. If the selector ends with
  335. * <tt>:=</tt>, a mutator is returned instead. An accessor is a nullary closure which upon
  336. * application yields the field's value. A mutator is a unary closure which upon
  337. * application assigns the field to the specified value.
  338. * Even for fields already bound to a closure, selecting the field returns an accessor
  339. * closure, not the bound closure itself.
  340. *
  341. * @see #meta_doesNotUnderstand(ATSymbol) for what happens if the selector is not found.
  342. *
  343. * @param receiver the dynamic receiver of the selection. If the result of the selection is
  344. * a method, the closure wrapping the method will bind <tt>self</tt> to this object.
  345. * @param selector a symbol denoting the name of the field or method to select.
  346. * @return if selector is bound to a field, an accessor or mutator for the field; otherwise if
  347. * the selector is bound to a method, a closure wrapping the method.
  348. */
  349. public ATClosure meta_select(ATObject receiver, ATSymbol selector) throws InterpreterException;
  350. /**
  351. * This meta-level operation reifies field definition. Hence, the base-level
  352. * code <code>def x := v</code> evaluated in a lexical scope <tt>lex</tt>
  353. * is interpreted at the meta-level as:
  354. * <pre>(reflect: lex).defineField(`x, v)</pre>
  355. *
  356. * Invoking this meta-level operation on an object's mirror adds a new field
  357. * to that object. An object cannot contain two or more fields with the
  358. * same name.
  359. *
  360. * @param name a symbol denoting the name of the new field
  361. * @param value the value of the new field
  362. * @return nil
  363. * @throws edu.vub.at.exceptions.XDuplicateSlot if the object already has a
  364. * local field with the given name
  365. */
  366. public ATNil meta_defineField(ATSymbol name, ATObject value) throws InterpreterException;
  367. /* -----------------------------------------
  368. * -- Cloning and instantiation protocol --
  369. * ---------------------------------------- */
  370. /**
  371. * This meta-level operation reifies the act of cloning the base-level object.
  372. * Hence, the code <code>clone: o</code> is interpreted at the meta-level as
  373. * <pre>(reflect: o).clone()</pre>
  374. *
  375. * AmbientTalk's default cloning semantics are based on shallow copying.
  376. * A cloned object has copies of the original object's fields, but the values
  377. * of the fields are shared between the clones. A clone has the same methods
  378. * as the original object. Methods added at a later stage to the original
  379. * will not affect the clone's methods and vice versa. This means that each
  380. * objects has its own independent fields and methods.
  381. * <p>
  382. * If the cloned AmbientTalk object contains programmer-defined field objects,
  383. * each of these fields is re-instantiated with the clone as a parameter. The
  384. * clone is intialized with the re-instantiated fields rather than with the
  385. * fields of the original object. This property helps to ensure that each
  386. * object has its own independent fields.
  387. * <p>
  388. * If the object has a <i>shares-a</i> relationship with its parent, the object
  389. * and its clone will <b>share</b> the same parent object. Shares-a relationships
  390. * are the default in AmbientTalk, and they match with the semantics of
  391. * shallow copying: the dynamic parent of an object is a regular field, hence
  392. * its contents is shallow-copied.
  393. * <p>
  394. * If the object has an <i>is-a</i> relationship with its parent object, a
  395. * clone of the object will receive a clone of the parent object as its parent.
  396. * Hence, is-a relationships "override" the default shallow copying semantics
  397. * and recursively clone the parent of an object up to a shares-a relationship.
  398. * <p>
  399. * If a mirage is cloned, its mirror is automatically re-instantiated with
  400. * the new mirage, to ensure that each mirage has its independent mirror.
  401. * @return a clone of the mirror's <tt>base</tt> object
  402. */
  403. public ATObject meta_clone() throws InterpreterException;
  404. /**
  405. * This meta-level operation reifies instance creation. The default
  406. * implementation of an AmbientTalk object's <tt>new</tt> method is:
  407. * <pre>def new(@initargs) { (reflect: self).newInstance(initargs) }</pre>
  408. *
  409. * Creating a new instance of an object is a combination of:
  410. * <ul>
  411. * <li>creating a clone of the object
  412. * <li>initializing the clone by invoking its <tt>init</tt> method
  413. * </ul>
  414. *
  415. * The default implementation is:
  416. * <pre>def newInstance(initargs) {
  417. * def instance := self.clone();
  418. * instance.init(@initargs);
  419. * instance;
  420. *}
  421. * </pre>
  422. *
  423. * Instance creation in AmbientTalk is designed to mimick class instantiation
  424. * in a class-based language. Instantiating a class <tt>c</tt> requires <i>allocating</i>
  425. * a new instance <tt>i</tt> and then invoking the <i>constructor</i> on that
  426. * new instance. In AmbientTalk, class allocation is replaced by object
  427. * <i>cloning</i>. The benefit is that an instantiated object its variables are
  428. * already initialized to useful values, being those of the object from which
  429. * it is instantiated. The <tt>init</tt> method plays the role of "constructor"
  430. * in AmbientTalk.
  431. *
  432. * @param initargs a table denoting the actual arguments to be passed to
  433. * the <tt>init</tt> method
  434. * @return the new instance
  435. */
  436. public ATObject meta_newInstance(ATTable initargs) throws InterpreterException;
  437. /* ---------------------------------
  438. * -- Structural Access Protocol --
  439. * --------------------------------- */
  440. /**
  441. * This structural meta-level operation adds a field object to the receiver mirror's
  442. * base object. An object cannot contain two or more fields with the same name.
  443. *
  444. * Note that the field object passed as an argument serves as a <i>prototype</i>
  445. * object: the actual field object added is an <i>instance</i> of the passed field object.
  446. * A field object should always have an <tt>init</tt> method that takes as an argument
  447. * the new host object to which it is added. This is often useful, as the behaviour
  448. * of a field may depend on the object in which it resides. Because <tt>addField</tt>
  449. * creates a new instance of the field, this gives the field object a chance to
  450. * properly refer to its new host.
  451. * <p>
  452. * As an example, here is how to add a read-only field <tt>foo</tt> initialized
  453. * to <tt>5</tt> to an object <tt>obj</tt>:
  454. * <pre>def makeConstantField(nam, val) {
  455. * object: {
  456. * def new(newHost) { self }; // singleton pattern
  457. * def name := nam;
  458. * def readField() { val };
  459. * def writeField(newVal) { nil };
  460. * def accessor() { (&readField).method };
  461. * def mutator() { (&writeField).method };
  462. * } taggedAs: [/.at.types.Field]
  463. * };
  464. * (reflect: obj).addField(makeConstantField(`foo, 5));
  465. * </pre>
  466. *
  467. * @param field the prototype field object whose instance should be added
  468. * to the receiver's base object
  469. * @return nil
  470. * @throws XDuplicateSlot if the base object already has a field with the
  471. * same name as the new field
  472. */
  473. public ATNil meta_addField(ATField field) throws InterpreterException;
  474. /**
  475. * This structural meta-level operation adds a method to the receiver
  476. * mirror's base object. An object cannot contain two or more methods
  477. * with the same name.
  478. *
  479. * @param method a method object to add to the receiver's base object's
  480. * method dictionary.
  481. * @return nil
  482. * @throws XDuplicateSlot if a method with the new method's selector already
  483. * exists in the base object.
  484. */
  485. public ATNil meta_addMethod(ATMethod method) throws InterpreterException;
  486. /**
  487. * This structural meta-level operation allows the metaprogrammer to reify a
  488. * field of the receiver mirror's base object. Hence, unlike <tt>select</tt>
  489. * and <tt>lookup</tt>, <tt>grabField</tt> returns a <i>field object</i> rather
  490. * than the <i>value</i> bound to the field. For example: one could express
  491. * <code>obj.super := val</code> at the meta-level as:
  492. *
  493. * <pre>
  494. * def superField := (reflect: obj).grabField(`super);
  495. * superField.writeField(val);
  496. * </pre>
  497. *
  498. * Another important difference between <tt>select</tt>, <tt>lookup</tt> and
  499. * <tt>grabField</tt> is that <tt>grabField</tt> only considers the fields
  500. * <i>local</i> to the receiver's base object. Fields of lexical or dynamic
  501. * parent objects are <i>not</i> considered.
  502. *
  503. * @param selector a symbol representing the name of the field to select.
  504. * @return a mirror on this object's field slot.
  505. * @throws XUndefinedSlot if the field cannot be found within the receiver's
  506. * base object.
  507. */
  508. public ATField meta_grabField(ATSymbol selector) throws InterpreterException;
  509. /**
  510. * This structural meta-level operation allows the metaprogrammer to
  511. * reify a method defined on the receiver mirror's base object. Note that,
  512. * unlike the <tt>select</tt> or <tt>lookup</tt> operations, <tt>grabMethod</tt>
  513. * returns the bare method object, i.e. <i>not</i> a closure wrapping the method.
  514. * <p>
  515. * Also, unlike <tt>select</tt> and <tt>lookup</tt>, <tt>grabField</tt> only
  516. * considers the locally defined methods of an object, methods of lexical or
  517. * dynamic parent objects are <i>not</i> considered.
  518. *
  519. * @param selector a symbol representing the name of the method to grab from
  520. * the receiver's base object.
  521. * @return the bare method object bound to the given selector.
  522. * @throws XSelectorNotFound if the method object cannot be found within the
  523. * receiver's base object.
  524. */
  525. public ATMethod meta_grabMethod(ATSymbol selector) throws InterpreterException;
  526. /**
  527. * This structural meta-level operation allows access to all of the
  528. * fields defined on the receiver mirror's base object. Note that
  529. * this method only returns the base object's <i>locally</i> defined
  530. * fields. Fields from parent objects are not returned.
  531. *
  532. * @see ATObject#meta_grabField(ATSymbol) for details about the returned
  533. * field objects.
  534. * @return a table of field objects (of type {@link ATField}).
  535. */
  536. public ATTable meta_listFields() throws InterpreterException;
  537. /**
  538. * This structural meta-level operation allows access to all of the
  539. * methods defined on the receiver mirror's base object. Note that
  540. * this method only returns the base object's <i>locally</i> defined
  541. * methods. Methods from parent objects are not returned.
  542. *
  543. * @see ATObject#meta_grabMethod(ATSymbol) for details about the returned
  544. * method objects.
  545. * @return a table of method objects (of type {@link ATMethod}).
  546. */
  547. public ATTable meta_listMethods() throws InterpreterException;
  548. /**
  549. * This structural meta-level operation adds a slot object to the receiver mirror's
  550. * base object. An object cannot contain two or more slots with the same name.
  551. *
  552. * A slot is either a method or a closure. A closure serves to encapsulate access to
  553. * or mutation of a field.
  554. *
  555. * Care must be taken with closures when the object to which they are added is
  556. * cloned or instantiated: the closure will be shared between clones!
  557. * <p>
  558. * As an example, here is how to add a read-only field <tt>foo</tt> initialized
  559. * to <tt>5</tt> to an object <tt>obj</tt>:
  560. * <pre>
  561. * def [accessor,mutator] := /.at.lang.values.createFieldSlot(`foo, 5);
  562. * (reflect: obj).addSlot(accessor);
  563. * </pre>
  564. *
  565. * @param slot the method representing the slot to be added
  566. * to the receiver's base object
  567. * @return nil
  568. * @throws XDuplicateSlot if the base object already has a slot with the
  569. * same name as the new slot
  570. */
  571. public ATNil meta_addSlot(ATMethod slot) throws InterpreterException;
  572. /**
  573. * This structural meta-level operation allows the metaprogrammer to reify a
  574. * slot of the receiver mirror's base object. Hence, unlike <tt>select</tt>
  575. * and <tt>lookup</tt>, <tt>grabSlot</tt> returns a <i>slot object</i> rather
  576. * than the <i>value</i> bound to the slot. For example: one could express
  577. * <code>obj.super := val</code> at the meta-level as:
  578. *
  579. * <pre>
  580. * def superMutator := (reflect: obj).grabSlot(`super:=);
  581. * superMutator(val);
  582. * </pre>
  583. *
  584. * Another important difference between <tt>select</tt>, <tt>lookup</tt> and
  585. * <tt>grabSlot</tt> is that <tt>grabSlot</tt> only considers the slots
  586. * <i>local</i> to the receiver's base object. Slots of lexical or dynamic
  587. * parent objects are <i>not</i> considered.
  588. *
  589. * @param selector a symbol representing the name of the slot to select.
  590. * @return a method representing the selected slot.
  591. * @throws XUndefinedSlot if the field cannot be found within the receiver's
  592. * base object.
  593. */
  594. public ATMethod meta_grabSlot(ATSymbol selector) throws InterpreterException;
  595. /**
  596. * This structural meta-level operation allows access to all of the
  597. * slots defined on the receiver mirror's base object. Note that
  598. * this method only returns the base object's <i>locally</i> defined
  599. * slots. Slots from parent objects are not returned.
  600. *
  601. * @see ATObject#meta_grabSlot(ATSymbol) for details about the returned
  602. * slot objects.
  603. * @return a table of slot objects (of type {@link ATMethod}).
  604. */
  605. public ATTable meta_listSlots() throws InterpreterException;
  606. /**
  607. * This structural meta-level operation removes a slot from the
  608. * object. Note that this method only removes slots that are
  609. * <i>locally</i> defined in the object.
  610. *
  611. * @param selector the name of the slot to remove
  612. * @return the value to which the slot was previously bound
  613. * (e.g. a value or a method object)
  614. * @throws XSelectorNotFound if no slot with the given name is found in the object
  615. */
  616. public ATObject meta_removeSlot(ATSymbol selector) throws InterpreterException;
  617. /**
  618. * This structural meta-level operation returns whether or not
  619. * the receiver mirror's base object is an <i>extension</i> of its
  620. * parent object.
  621. * <p>
  622. * In AmbientTalk, all objects are part of a dynamic parent delegation chain:
  623. * each object has a <tt>super</tt> field that denotes the object to which to
  624. * delegate messages the object cannot understand itself. There are, however,
  625. * two kinds of delegation links:
  626. * <ul>
  627. * <li><b>IS-A</b> links: this kind of link denotes that the child object is
  628. * a true extension of its parent, and cannot meaningfully exist without the
  629. * parent's state. When the child is cloned, its parent will be cloned as well.
  630. * <li><b>SHARES-A</b> links: this kind of link denotes that the child object
  631. * simply delegates to its parent for purposes of sharing or code reuse. The
  632. * child can meaningfully exist without the parent's state. When the child is
  633. * cloned, the clone will delegate to the same parent.
  634. * </ul>
  635. *
  636. * Examples:
  637. * <pre>(reflect: (extend: parent with: code)).isExtensionOfParent() => true
  638. *(reflect: (share: parent with: code)).isExtensionOfParent() => false
  639. * </pre>
  640. *
  641. * Note that accessing the dynamic parent itself is not a meta-level operation,
  642. * the dynamic parent can simply be accessed from the base level by performing
  643. * <code>obj.super</code>.
  644. *
  645. * @return whether the base object extends its parent object via an
  646. * <b>IS-A</b> link or not.
  647. */
  648. public ATBoolean meta_isExtensionOfParent() throws InterpreterException;
  649. /* ------------------------------------------
  650. * -- Abstract Grammar evaluation protocol --
  651. * ------------------------------------------ */
  652. /**
  653. * This behavioural meta-level operation reifies the evaluation of
  654. * abstract grammar objects into values. For objects, this operation
  655. * returns the base object itself, signifying that the evaluation
  656. * function defined on objects is the identity function. In other words,
  657. * objects are <i>self-evaluating</i>. Parse tree objects (first-class
  658. * abstract grammar elements), however, have dedicated evaluation
  659. * functions. For example, evaluating <code>x</code> is equivalent to
  660. * evaluating <code>(reflect: `x).eval(ctx)</code> where <tt>ctx</tt>
  661. * is a reification of the current evaluation context.
  662. *
  663. * @param ctx a context object that stores the current lexical scope and
  664. * the current value of <tt>self</tt>
  665. * @return the value of the abstract grammar element denoted by this mirror's
  666. * base object.
  667. * @throws XIllegalUnquote if an unquote abstract grammar element is evaluated. Such
  668. * abstract grammar elements should only be encountered in a quoted parse tree.
  669. */
  670. public ATObject meta_eval(ATContext ctx) throws InterpreterException;
  671. /**
  672. * This behavioural meta-level operation reifies the quotation of
  673. * abstract grammar elements. Regular objects simply return themselves
  674. * upon quotation. When an abstract grammar element is quoted, rather
  675. * than tree-recursively invoking <tt>eval</tt> on the parse trees,
  676. * <tt>quote</tt> is tree-recursively invoked. When encountering
  677. * an unquote, <tt>eval</tt> is again invoked on the unquoted subtree,
  678. * with the context passed as an argument to <tt>quote</tt>.
  679. *
  680. * @param ctx a context object passed on to be used in subsequent evaluations.
  681. * @throws XIllegalQuote exception whenever an unquote-splice unquotation is discovered
  682. * in an Abstract Grammar node where the resulting table cannot be spliced.
  683. */
  684. public ATObject meta_quote(ATContext ctx) throws InterpreterException;
  685. /**
  686. * This behavioural meta-level operation reifies the act of printing
  687. * the base object in the read-eval-print loop. This operation may be
  688. * overridden by mirrors to customise the printed representation of
  689. * their base object.
  690. *
  691. * @return a text value denoting a human-readable representation of the object.
  692. */
  693. public NATText meta_print() throws InterpreterException;
  694. /**
  695. * This behavioural meta-level operation reifies the act of representing
  696. * the base object as self-containing source code. This operation may be
  697. * overridden by mirrors to customise the printed representation of
  698. * their base object.
  699. *
  700. * @return a text value denoting a human-readable representation of the object.
  701. */
  702. public NATText meta_asCode() throws InterpreterException;
  703. public NATText impl_asCode(TempFieldGenerator objectMap) throws InterpreterException;
  704. public NATText impl_asUnquotedCode(TempFieldGenerator objectMap) throws InterpreterException;
  705. /* ----------------------------------
  706. * -- Object Relational Comparison --
  707. * ---------------------------------- */
  708. /**
  709. * This meta-level operation determines whether this mirror's base object
  710. * is related to the parameter object by a combination of cloning and
  711. * extension operators. The default implementation is:
  712. *
  713. * <pre>def isRelatedTo(object) {
  714. * self.isCloneOf(object).or: { (reflect: base.super).isRelatedTo(object) }
  715. *}</pre>
  716. *
  717. * @param object the object to compare this mirror's base object to
  718. * @return true if the given object is a clone of the base object or a clone
  719. * of the base object's parents.
  720. */
  721. public ATBoolean meta_isRelatedTo(ATObject object) throws InterpreterException;
  722. /**
  723. * This meta-level operation determines whether this mirror's base object
  724. * is a clone of the parameter object. The <i>is-clone-of</i> relation is transitive,
  725. * so if <tt>martin</tt> is a clone of <tt>sally</tt> and <tt>sally</tt> is a clone of
  726. * <tt>dolly</tt>, then <tt>martin</tt> is a clone of <tt>dolly</tt> as well.
  727. * The relation is reflexive: <tt>dolly</tt> is a clone of itself.
  728. * The relation is symmetric: <tt>dolly</tt> is also a clone of <tt>sally</tt>.
  729. *
  730. * @param other the object to check the is-clone-of relationship with.
  731. * @return true if the base object and the parameter object are clones (i.e. one
  732. * was created by cloning the other), false otherwise.
  733. */
  734. public ATBoolean meta_isCloneOf(ATObject other) throws InterpreterException;
  735. /* ---------------------------------
  736. * -- Type Testing and Querying --
  737. * --------------------------------- */
  738. /**
  739. * Tests whether the receiver mirror's base object is tagged as a particular type.
  740. *
  741. * The default implementation first compares the object's local type tags to the given type
  742. * by means of the {@link ATTypeTag#base_isSubtypeOf(ATTypeTag)} method. If no local type
  743. * is found, the test is applied recursively on this object's dynamic parent. In code:
  744. * <pre>def isTaggedAs(type) {
  745. * (nil != (self.tagsOf: object).find: { |localType|
  746. * localType.isSubtypeOf(type)
  747. * }).or: { (reflect: base.super).isTaggedAs(type) }
  748. * };
  749. * </pre>
  750. *
  751. * The primitive method <tt>is: obj taggedAs: type</tt> is defined in terms of this
  752. * method:
  753. * <pre>
  754. * def is: obj taggedAs: type {
  755. * (reflect: obj).isTaggedAs(type)
  756. *};
  757. * </pre>
  758. *
  759. * @param type the type tag object to check for
  760. * @return true if this mirror's base object or one of its parent objects is tagged
  761. * with a subtype of the given type, false otherwise.
  762. */
  763. public ATBoolean meta_isTaggedAs(ATTypeTag type) throws InterpreterException;
  764. /**
  765. * Returns all of the local type tags of this object. The primitive method
  766. * <tt>tagsOf: obj</tt> is defined in terms of this method:
  767. *
  768. * <pre>
  769. * def tagsOf: obj {
  770. * (reflect: obj).typeTags
  771. *};
  772. * </pre>
  773. *
  774. * @return a table of the type tags that were attached directly to this mirror's base
  775. * object. The type tags of its parent objects are not returned.
  776. */
  777. public ATTable meta_typeTags() throws InterpreterException;
  778. /* -------------------------------
  779. * - Base Level Object interface -
  780. * ------------------------------- */
  781. /**
  782. * Bound to the dynamic parent of this object.
  783. *
  784. * The dynamic parent of an object is the object to which failed
  785. * selection or invocation requests or type tests are delegated to.
  786. *
  787. * @return the current dynamic parent of this object.
  788. */
  789. public ATObject base_super() throws InterpreterException;
  790. /**
  791. * The identity operator. In AmbientTalk, equality of objects
  792. * is by default pointer-equality (i.e. objects are equal only
  793. * if they are identical).
  794. *
  795. * @return by default, true if the parameter object and this object are identical,
  796. * false otherwise.
  797. */
  798. // public ATBoolean base__opeql__opeql_(ATObject other) throws InterpreterException;
  799. /**
  800. * The object instantiation method. Note that in class-based OO languages,
  801. * this method is usually at the level of the <i>class</i>. In AmbientTalk,
  802. * this method is situated at the object-level directly. It can be overridden
  803. * to e.g. enforce the singleton pattern or to return instances of other
  804. * objects.
  805. *
  806. * The default implementation of this method is:
  807. * <pre>def new(@args) {
  808. * (reflect: self).newInstance(@args)
  809. *};
  810. * </pre>
  811. *
  812. * This is a primitive method, present by default in every AmbientTalk
  813. * object but redefinable by the programmer.
  814. *
  815. * @see ATObject#meta_newInstance(ATTable) for a description of object instantiation.
  816. * @param initargs the variable argument list to pass to the <tt>init</tt> method.
  817. * @return by default, the new instance of this mirror's base object.
  818. */
  819. // public ATObject base_new(ATObject[] initargs) throws InterpreterException;
  820. /**
  821. * The object initialisation method. In class-based languages, this method
  822. * is often called the constructor. AmbientTalk only supports one constructor
  823. * per object, but thanks to variable argument lists and optional parameters,
  824. * the same flexibility as defining multiple constructors can often be achieved.
  825. * Also, by overriding <tt>new</tt>, the developer may invoke additional methods
  826. * on newly created objects if this is desirable.
  827. *
  828. * The default implementation of this method is:
  829. * <pre>def init(@args) {
  830. * super^init(@args)
  831. *};
  832. * </pre>
  833. *
  834. * This is a primitive method, present by default in every AmbientTalk
  835. * object but redefinable by the programmer.
  836. *
  837. * @see ATObject#meta_newInstance(ATTable) for a description of object initialisation.
  838. * @param initargs the arguments to the <tt>init</tt> constructor method.
  839. * @return the return value of invoking the <tt>init</tt> method. Note that
  840. * this value is <i>discarded</i> when <tt>init</tt> is invoked from the
  841. * <tt>newInstance</tt> meta-level operation.
  842. */
  843. // public ATObject base_init(ATObject[] initargs) throws InterpreterException;
  844. /* -----------------------------------------
  845. * - Implementation-Level Object interface -
  846. * ----------------------------------------- */
  847. /**
  848. * Implementation-level shortcut for method invocation that foregoes the creation of
  849. * a 'method invocation' object, but rather passes the selector and arguments directly
  850. * to the implementation.
  851. */
  852. public ATObject impl_invoke(ATObject delegate, ATSymbol selector, ATTable arguments) throws InterpreterException;
  853. /**
  854. * The <tt>lexicalParent</tt> field of a mirror denotes the lexical parent
  855. * pointer of the mirror's base object. The lexical parent is the enclosing
  856. * <i>lexical scope</i> in which the object was defined.
  857. *
  858. * @return the object denoting this mirror's base object's lexically
  859. * enclosing scope.
  860. */
  861. public ATObject impl_lexicalParent() throws InterpreterException;
  862. /**
  863. * Interprets <code>o.x()</code> or <code>o.m(arg)</code>.
  864. * Implements slot access. This method is an implementation-level method (not part of the MOP).
  865. * @param receiver the dynamic receiver of the slot invocation.
  866. * @param selector a regular symbol denoting the slot accessor.
  867. * @param arguments the actual arguments to the slot invocation.
  868. * @return the result of applying the accessor.
  869. * @throws XArityMismatch if a field accessor is not invoked with exactly zero arguments.
  870. */
  871. public ATObject impl_invokeAccessor(ATObject receiver, ATSymbol selector, ATTable arguments) throws InterpreterException;
  872. /**
  873. * Interprets <code>o.x := v</code>.
  874. * Implements slot mutation. This method is an implementation-level method (not part of the MOP).
  875. * @param receiver the dynamic receiver of the slot invocation.
  876. * @param selector an assignment symbol denoting which slot to invoke.
  877. * @param arguments the actual arguments to the slot invocation.
  878. * @return the result of applying the mutator.
  879. * @throws XArityMismatch if a field mutator is not invoked with exactly one argument.
  880. */
  881. public ATObject impl_invokeMutator(ATObject receiver, ATAssignmentSymbol selector, ATTable arguments) throws InterpreterException;
  882. /**
  883. * Interprets <code>o.&m</code>.
  884. * Implements slot accessor selection. This method is an implementation-level method (not part of the MOP).
  885. * @param receiver the dynamic receiver of the slot selection.
  886. * @param selector a regular symbol denoting the accessor to select.
  887. * @return a closure wrapping the selected method or an accessor for a field.
  888. */
  889. public ATClosure impl_selectAccessor(ATObject receiver, ATSymbol selector) throws InterpreterException;
  890. /**
  891. * Interprets <code>o.&m:=</code>.
  892. * Implements slot mutator selection. This method is an implementation-level method (not part of the MOP).
  893. * @param receiver the dynamic receiver of the slot selection.
  894. * @param selector an assignment symbol denoting the mutator to select.
  895. * @return a closure representing the mutator of a given slot.
  896. */
  897. public ATClosure impl_selectMutator(ATObject receiver, ATAssignmentSymbol selector) throws InterpreterException;
  898. /**
  899. * Interprets <code>x := v</code> (equivalent to <code>x:=(v)</code>) or <code>f(v)</code>.
  900. * Implements functions calls and lexical access to variables.
  901. * This method is an implementation-level method (not part of the MOP).
  902. * Variable lookup first queries the local fields of this object, then the local
  903. * method dictionary. If the selector is not found, the search continues in
  904. * this object's <i>lexical parent</i>. Hence, variable lookup follows
  905. * <b>lexical scoping rules</b>.
  906. * <p>
  907. * Similar to the behaviour of <tt>invoke</tt>, if the selector is bound to a
  908. * field rather than a method, <tt>call</tt> treats the field as an accessor
  909. * or mutator method (depending on the selector).
  910. * <p>
  911. * Note that, unlike <tt>invoke</tt> and <tt>select</tt>, <tt>call</tt> does
  912. * not give rise to the invocation of <tt>doesNotUnderstand</tt> if the selector
  913. * was not found. The reason for this is that lexical lookup is a static process
  914. * for which it makes less sense to provide dynamic interception facilities.
  915. *
  916. * @param selector a symbol denoting the name of the field or method to look up lexically.
  917. * @param arguments the arguments to the lexically scoped function call.
  918. * @return if selector is bound to a field, the value of the field; otherwise if selector
  919. * is bound to a method, the return value of the method.
  920. * @throws XUndefinedSlot if the selector could not be found in the lexical scope of this object.
  921. */
  922. public ATObject impl_call(ATSymbol selector, ATTable arguments) throws InterpreterException;
  923. /**
  924. * Interprets <code>f(v)</code>.
  925. * Implements the protocol to access lexical variables and methods. This operation (which is not exposed
  926. * as part of the MOP) locates the lexically visible binding with the given selector and will return
  927. * the value of the slot.
  928. * <p>
  929. * When this object has a local slot corresponding to the selector:
  930. * <ul>
  931. * <li> and the slot contains a method or closure, it will be applied with the given arguments (within a context
  932. * where self is bound to this object)
  933. * <li> and the slot contains a value and the argumentlist is empty, the value is returned
  934. * <li> and the slot contains a value and the argumentlist is not empty, an arity mismatch exception is raised
  935. * </ul>
  936. * <p>
  937. * When no local slot is found, lookup continues along the lexical parent chain. When the lexical chain is
  938. * completely traversed, an undefined slot exception is raised.
  939. */
  940. public ATObject impl_callAccessor(ATSymbol selector, ATTable arguments) throws InterpreterException;
  941. /**
  942. * Interprets <code>x := v</code> (which is equivalent to <code>x:=(v)</code>.
  943. * Implements the protocol to assign lexical variables. This operation (which is not exposed as part of the MOP)
  944. * locates slots to assign corresponding to a specific assignment symbol (selector + ":=") and looks for:
  945. * <ol>
  946. * <li> a mutator method with the specified assignment symbol (i.e. including the ":=") which can then be
  947. * invoked with the provided arguments.
  948. * <li> a field with a corresponding selector (i.e. without the ":=") which is then treated as if it were
  949. * a unary mutator method.
  950. * </ol>
  951. *
  952. * If the slot is a method slot, an {@link XUnassignableField} exception is raised, otherwise the arity of the
  953. * arguments is verified (should be precisely 1) and the first argument is used as the new value of the slot.
  954. * <p>
  955. * When no local slot is found, lookup continues along the lexical parent chain. When the lexical chain is
  956. * completely traversed, a selector not found exception is reported.
  957. */
  958. public ATObject impl_callMutator(ATAssignmentSymbol selector, ATTable arguments) throws InterpreterException;
  959. /**
  960. * Interprets <code>x</code>.
  961. * This method is an implementation-level method (not part of the MOP).
  962. *
  963. * This method is equivalent to {@link #impl_call(ATSymbol, ATTable)} where
  964. * the arguments equal <tt>[]</tt>, except for one case: when the selector
  965. * resolves to a field containing a closure, the closure is not auto-applied
  966. * with zero arguments, but is instead returned. For all other purposes,
  967. * evaluating <tt>m</tt> is equivalent to evaluating <tt>m()</tt> such that
  968. * fields and nullary methods can be uniformly accessed.
  969. *
  970. * @param selector the name of a lexically visible field or method.
  971. * @return the value of a field or the return value of an accessor method.
  972. */
  973. public ATObject impl_callField(ATSymbol selector) throws InterpreterException;
  974. /**
  975. * Interprets <code>&x</code> or <code>&x:=</code>.
  976. * This method is an implementation-level method (not part of the MOP).
  977. *
  978. * This operation is the lexical counterpart of {@link #meta_select(ATObject, ATSymbol)}.
  979. * @param selector the name of a lexically visible field or method.
  980. * @return a closure wrapping a method, or an accessor or mutator linked to a lexically visible field.
  981. */
  982. public ATClosure impl_lookup(ATSymbol selector) throws InterpreterException;
  983. /**
  984. * Interprets <code>&x</code>.
  985. * This method is an implementation-level method (not part of the MOP).
  986. *
  987. * @param selector the name of a lexically visible field or method.
  988. * @return a closure wrapping a method, or an accessor linked to a lexically visible field.
  989. */
  990. public ATClosure impl_lookupAccessor(ATSymbol selector) throws InterpreterException;
  991. /**
  992. * Interprets <code>&x:=</code>.
  993. * This method is an implementation-level method (not part of the MOP).
  994. *
  995. * If the selector minus <tt>:=</tt> is bound to a field, the field is assigned
  996. * i
  997. * @param selector the name of a lexically visible method or of a field (whose name does not have the <tt>:=</tt> prefix).
  998. * @return a closure wrapping a method, or a mutator linked to a lexically visible field.
  999. */
  1000. public ATClosure impl_lookupMutator(ATAssignmentSymbol selector) throws InterpreterException;
  1001. /**
  1002. * This is a callback method used in AmbientTalk's native equality protocol.
  1003. * When evaluating <tt>o1 == o2</tt> in AmbientTalk, <tt>o1</tt>'s <tt>==</tt>
  1004. * method will invoke <tt>o2.identityEquals(o1)</tt>.
  1005. *
  1006. * The native implementation can make use of Java's <tt>==</tt> operator where
  1007. * appropriate.
  1008. */
  1009. public ATBoolean impl_identityEquals(ATObject other) throws InterpreterException;
  1010. /**
  1011. * @return the source location attached to this AmbientTalk object, or nil
  1012. * if none is present. This field is normally only set for instances of
  1013. * {@link NATAbstractGrammar}, although some non-AG elements such as
  1014. * {@link NATMessage} inherit their source location from their corresponding
  1015. * AG element.
  1016. */
  1017. public SourceLocation impl_getLocation();
  1018. /**
  1019. * Attach a source location to this AmbientTalk object.
  1020. * @param loc the source location
  1021. */
  1022. public void impl_setLocation(SourceLocation loc);
  1023. /**
  1024. * Queries a native object for the source location of one of its slots.
  1025. * @param sel the name of the slot to return the source position for.
  1026. * @return the source location or null if not found.
  1027. */
  1028. public SourceLocation impl_getSourceOf(ATSymbol sel) throws InterpreterException;
  1029. }