PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/interpreter/tags/at2-build190607/src/edu/vub/at/objects/natives/OBJLexicalRoot.java

http://ambienttalk.googlecode.com/
Java | 1490 lines | 338 code | 91 blank | 1061 comment | 8 complexity | 7cca990d5a3e718d406f2d0a45ec94ca MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, LGPL-2.1
  1. /**
  2. * AmbientTalk/2 Project
  3. * OBJLexicalRoot.java created on 8-aug-2006 at 16:51:10
  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.actors.ATActorMirror;
  30. import edu.vub.at.actors.ATFarReference;
  31. import edu.vub.at.actors.natives.ELActor;
  32. import edu.vub.at.actors.natives.ELVirtualMachine;
  33. import edu.vub.at.actors.natives.NATActorMirror;
  34. import edu.vub.at.actors.natives.NATFarReference;
  35. import edu.vub.at.actors.natives.Packet;
  36. import edu.vub.at.actors.net.OBJNetwork;
  37. import edu.vub.at.eval.Evaluator;
  38. import edu.vub.at.exceptions.InterpreterException;
  39. import edu.vub.at.objects.ATAbstractGrammar;
  40. import edu.vub.at.objects.ATBoolean;
  41. import edu.vub.at.objects.ATClosure;
  42. import edu.vub.at.objects.ATHandler;
  43. import edu.vub.at.objects.ATMethod;
  44. import edu.vub.at.objects.ATNil;
  45. import edu.vub.at.objects.ATNumber;
  46. import edu.vub.at.objects.ATNumeric;
  47. import edu.vub.at.objects.ATObject;
  48. import edu.vub.at.objects.ATTypeTag;
  49. import edu.vub.at.objects.ATTable;
  50. import edu.vub.at.objects.ATText;
  51. import edu.vub.at.objects.coercion.NativeTypeTags;
  52. import edu.vub.at.objects.mirrors.NATMirage;
  53. import edu.vub.at.objects.mirrors.OBJMirrorRoot;
  54. import edu.vub.at.parser.NATParser;
  55. /**
  56. * The singleton instance of this class represents the lexical root of an actor.
  57. * Since this lexical root is constant (it cannot be modified) and contains no mutable fields,
  58. * it is possible to share a singleton instance of this class among all actors.
  59. * <p>
  60. * The lexical root is an object containing globally visible AmbientTalk native methods.
  61. * Such methods include control structures such as <tt>if:then:else:</tt>
  62. * but also object creation methods like <tt>object:</tt> and reflective constructs
  63. * like <tt>reflect:</tt>.
  64. *
  65. * Furthermore, the lexical root is also the root of the lexical parent hierarchy for objects.
  66. * This means that this object's mirror is responsible for ending recursive meta-level methods
  67. * such as <tt>lookup</tt> and <tt>assignField</tt>.
  68. * <p>
  69. * Like any class whose instances represent native AmbientTalk objects, this class is a subclass
  70. * of {@link NATNil}. This means that this class can use the typical protocol of native objects
  71. * to implement base-level AmbientTalk methods as Java methods whose name is prefixed with
  72. * <tt>base_</tt>.
  73. * <p>
  74. * Note that OBJLexicalRoot is a <i>sentinel</i> class. The actual object bound to the
  75. * lexical root of an actor (accessible via the field <tt>root</tt> will be a normal
  76. * AmbientTalk object whose lexical parent is this object.
  77. * The real, empty, root object is local to each actor and is mutable. The definitions
  78. * from the <tt>init.at</tt> file are added to that object.
  79. *
  80. * @author smostinc
  81. * @author tvcutsem
  82. */
  83. public final class OBJLexicalRoot extends NATByCopy {
  84. /**
  85. * The singleton instance of the sentinel lexical root
  86. */
  87. static public final OBJLexicalRoot _INSTANCE_ = new OBJLexicalRoot();
  88. /**
  89. * Constructor made private for singleton design pattern
  90. */
  91. private OBJLexicalRoot() { }
  92. /* -----------------------
  93. * -- Primitive Methods --
  94. * ----------------------- */
  95. /* ===============================================================================
  96. * NOTE: the code below has been replaced by dedicated syntax and AST elements.
  97. * However, the skeleton of this code may still prove useful in the future, if
  98. * we ever plan to implement all base_ native methods as true AmbientTalk methods
  99. * (i.e. as PrimitiveMethod instances).
  100. * ===============================================================================
  101. */
  102. /*
  103. private static final AGSymbol _IMPORT_NAME_ = AGSymbol.jAlloc("import:");
  104. private static final AGSymbol _IMPORT_ALIAS_NAME_ = AGSymbol.jAlloc("import:alias:");
  105. private static final AGSymbol _IMPORT_EXCLUDE_NAME_ = AGSymbol.jAlloc("import:exclude:");
  106. private static final AGSymbol _IMPORT_ALIAS_EXCLUDE_NAME_ = AGSymbol.jAlloc("import:alias:exclude:");
  107. private static final AGSymbol _SRC_PARAM_ = AGSymbol.jAlloc("sourceObject");
  108. private static final AGSymbol _ALIAS_PARAM_ = AGSymbol.jAlloc("aliases");
  109. private static final AGSymbol _EXCLUDE_PARAM_ = AGSymbol.jAlloc("exclude");
  110. */
  111. /*protected static final PrimitiveMethod _PRIM_IMPORT_ = new PrimitiveMethod(_IMPORT_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_ })) {
  112. public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
  113. ATObject sourceObject = arguments.base_at(NATNumber.ONE);
  114. return performImport(sourceObject, ctx, new Hashtable(), OBJLexicalRoot.getDefaultExcludedSlots());
  115. }
  116. };*/
  117. /**
  118. * def import: sourceObject alias: [ `oldname -> `newname , ... ]
  119. */
  120. /*protected static final PrimitiveMethod _PRIM_IMPORT_ALIAS_ = new PrimitiveMethod(_IMPORT_ALIAS_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_, _ALIAS_PARAM_ })) {
  121. public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
  122. ATObject sourceObject = arguments.base_at(NATNumber.ONE);
  123. ATObject aliases = arguments.base_at(NATNumber.atValue(2));
  124. return performImport(sourceObject, ctx, preprocessAliases(aliases.base_asTable()), OBJLexicalRoot.getDefaultExcludedSlots());
  125. }
  126. };*/
  127. /**
  128. * def import: sourceObject excludes: [ `name1, `name2, ... ]
  129. */
  130. /*protected static final PrimitiveMethod _PRIM_IMPORT_EXCLUDE_ = new PrimitiveMethod(_IMPORT_EXCLUDE_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_, _EXCLUDE_PARAM_ })) {
  131. public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
  132. ATObject sourceObject = arguments.base_at(NATNumber.ONE);
  133. ATObject exclusions = arguments.base_at(NATNumber.atValue(2));
  134. return performImport(sourceObject, ctx, new Hashtable(), preprocessExcludes(exclusions.base_asTable()));
  135. }
  136. };*/
  137. /**
  138. * def import: sourceObject alias: [ `oldname -> `newname, ... ] excludes: [ `name1, `name2, ... ]
  139. */
  140. /*protected static final PrimitiveMethod _PRIM_IMPORT_ALIAS_EXCLUDE_ = new PrimitiveMethod(_IMPORT_ALIAS_EXCLUDE_NAME_,
  141. NATTable.atValue(new ATObject[] { _SRC_PARAM_, _ALIAS_PARAM_, _EXCLUDE_PARAM_ })) {
  142. public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
  143. ATObject sourceObject = arguments.base_at(NATNumber.ONE);
  144. ATObject aliases = arguments.base_at(NATNumber.atValue(2));
  145. ATObject exclusions = arguments.base_at(NATNumber.atValue(3));
  146. return performImport(sourceObject, ctx, preprocessAliases(aliases.base_asTable()), preprocessExcludes(exclusions.base_asTable()));
  147. }
  148. };*/
  149. /**
  150. * Invoked whenever a new true AmbientTalk object is created that should
  151. * represent the root. This gives the lexical root a chance to install its
  152. * primitive methods.
  153. */
  154. /*public static void initializeRoot(NATObject root) {
  155. try {
  156. // add import: native
  157. root.meta_addMethod(_PRIM_IMPORT_);
  158. // add import:alias: native
  159. root.meta_addMethod(_PRIM_IMPORT_ALIAS_);
  160. // add import:exclude: native
  161. root.meta_addMethod(_PRIM_IMPORT_EXCLUDE_);
  162. // add import:alias:exclude: native
  163. root.meta_addMethod(_PRIM_IMPORT_ALIAS_EXCLUDE_);
  164. } catch (InterpreterException e) {
  165. Logging.Init_LOG.fatal("Failed to initialize the root!", e);
  166. }
  167. }*/
  168. /* ----------------------
  169. * -- Global variables --
  170. * ---------------------- */
  171. /**
  172. * <tt>nil</tt> evaluates to the nil object, which is
  173. * the empty, dynamic parent of all AmbientTalk objects.
  174. */
  175. public ATNil base_getNil() {
  176. return NATNil._INSTANCE_;
  177. }
  178. /**
  179. * <tt>true</tt> evaluates to the unique boolean true object.
  180. */
  181. public ATBoolean base_getTrue() {
  182. return NATBoolean._TRUE_;
  183. }
  184. /**
  185. * <tt>false</tt> evaluates to the unique boolean false object.
  186. */
  187. public ATBoolean base_getFalse() {
  188. return NATBoolean._FALSE_;
  189. }
  190. /**
  191. * <tt>/</tt> evaluates to the global namespace. It is
  192. * simply an alias for <tt>lobby</tt>.
  193. * @see #base_getLobby()
  194. */
  195. public ATObject base_get_opdiv_() {
  196. return base_getLobby();
  197. }
  198. /**
  199. * <tt>lobby</tt> evaluates to the global namespace object.
  200. * For each <tt>name=path</tt> entry on AmbientTalk's
  201. * <i>object path</i>, the lobby object contains a slot
  202. * <tt>name</tt> bound to a namespace object bound to
  203. * the directory referred to by <tt>path</tt>.
  204. * <p>
  205. * Accessing the lobby allows loading in AmbientTalk source code
  206. * from external files.
  207. */
  208. public ATObject base_getLobby() {
  209. return Evaluator.getLobbyNamespace();
  210. }
  211. /**
  212. * <tt>root</tt> evaluates to the global lexical scope object.
  213. * This is the top-level object in which the definitions of
  214. * the file <tt>at/init/init.at</tt> are evaluated. All code
  215. * is assumed to be "nested" in the lexical root, so all definitions
  216. * of this object are lexically accessible.
  217. */
  218. public ATObject base_getRoot() {
  219. return Evaluator.getGlobalLexicalScope();
  220. }
  221. /**
  222. * <tt>jlobby</tt> evaluates to the Java namespace root. It is a
  223. * special object which is part of the symbiosis infrastructure of
  224. * AmbientTalk. <tt>jlobby</tt> acts like an object that has field
  225. * names that correspond to Java package names. By selecting fields
  226. * from this object, an appropriate Java package can be created
  227. * from which a Java class can be accessed. Only the Java classes
  228. * accessible in the Java classpath are accessible.
  229. *
  230. * Example:
  231. * <code>jlobby.java.util.Vector</code> evaluates to a reference to
  232. * the Java <tt>Vector</tt> class.
  233. */
  234. public ATObject base_getJlobby() {
  235. return Evaluator.getJLobbyRoot();
  236. }
  237. /**
  238. * <tt>network</tt> evaluates to the unique network control object.
  239. * It is a simple native object with two methods:
  240. * <ul>
  241. * <li><tt>network.online()</tt> makes the interpreter go online. This allows
  242. * publications of local actors to be discovered by remote objects and vice versa.
  243. * <li><tt>network.offline()</tt> makes the interpreter go offline. All
  244. * remote references to remote objects will become disconnected.
  245. * </ul>
  246. */
  247. public ATObject base_getNetwork() {
  248. return OBJNetwork._INSTANCE_;
  249. }
  250. /**
  251. * <tt>defaultMirror</tt> evaluates to the default mirror on objects. This
  252. * is the mirror encapsulating the standard AmbientTalk object semantics.
  253. * That is, it is a mirror with similar behaviour as the mirror created by
  254. * executing: <code>reflect: (object: { ... })</code>.
  255. *
  256. * The default mirror is an object with a read-only <tt>base</tt> field
  257. * that signifies the base-level object of this mirror. The main purpose
  258. * of this object is to serve as a prototype whose methods can be overridden
  259. * by custom mirrors. The syntax:
  260. * <pre>
  261. * mirror: { ... }
  262. * </pre>
  263. * is syntactic sugar for:
  264. * <pre>
  265. * extend: defaultMirror with: { ... }
  266. * </pre>
  267. *
  268. * Note that the default mirror is typed with the <tt>/.at.types.Mirror</tt> type.
  269. */
  270. public ATObject base_getDefaultMirror() {
  271. return Evaluator.getMirrorRoot();
  272. }
  273. /* ------------------------
  274. * -- Control Structures --
  275. * ------------------------ */
  276. /**
  277. * The <tt>if:then:</tt> control structure. Usage:
  278. * <pre>if: cond then: consequent</pre>
  279. *
  280. * pseudo-implementation:
  281. * <pre>cond.ifTrue: consequent</pre>
  282. *
  283. * Note that the consequent parameter should be a <i>closure</i>, i.e.
  284. * the caller is responsible for delaying the evaluation of the consequent!
  285. *
  286. * @param cond a boolean object
  287. * @param consequent a closure containing the code to execute if the boolean is true
  288. * @return if <tt>cond</tt> is true, the value of applying the consequent, <tt>nil</tt> otherwise
  289. */
  290. public ATObject base_if_then_(ATBoolean cond, ATClosure consequent) throws InterpreterException {
  291. return cond.base_ifTrue_(consequent);
  292. }
  293. /**
  294. * The <tt>if:then:else:</tt> control structure. Usage:
  295. * <pre>if: cond then: consequent else: alternative</pre>
  296. *
  297. * pseudo-implementation:
  298. * <pre>cond.ifTrue: consequent ifFalse: alternative</pre>
  299. *
  300. * Note that the consequent and alternative parameters should be <i>closures</i>, i.e.
  301. * the caller is responsible for delaying the evaluation of these arguments!
  302. *
  303. * @param cond a boolean object
  304. * @param consequent a closure containing the code to execute if the boolean is true
  305. * @param alternative a closure containing the code to execute if the boolean is false
  306. * @return the value of consequent if the boolean is true, the value of the alternative otherwise.
  307. */
  308. public ATObject base_if_then_else_(ATBoolean cond, ATClosure consequent, ATClosure alternative) throws InterpreterException {
  309. return cond.base_ifTrue_ifFalse_(consequent, alternative);
  310. }
  311. /**
  312. * The <tt>while:do:</tt> control structure. Usage:
  313. * <pre>while: condition do: body</pre>
  314. *
  315. * pseudo-implementation:
  316. * <pre>condition.whileTrue: body</pre>
  317. *
  318. * Note that <i>both</i> the condition and the body should be <i>closures</i>, because
  319. * they represent pieces of code that have to be executed repeatedly. Because of traditional
  320. * syntax, novice programmers are inclined to make the mistake of writing, e.g.:
  321. * <pre>while: (i < 10) do: { i := i + 1 }</pre>
  322. * Which is wrong because the first parameter should evaluate to a closure that itself
  323. * returns a boolean value, not to a boolean value directly.
  324. *
  325. * @param condition a closure expected to return a boolean object
  326. * @param body a closure containing the code to execute as long as the condition closure returns true
  327. * @return if conditions is true at least once, the last value of body, <tt>nil</tt> otherwise.
  328. */
  329. public ATObject base_while_do_(ATClosure condition, ATClosure body) throws InterpreterException {
  330. return condition.base_whileTrue_(body);
  331. }
  332. /**
  333. * The <tt>foreach:in:</tt> control structure. Usage:
  334. *
  335. * <pre>foreach: body in: table</pre>
  336. *
  337. * pseudo-implementation:
  338. * <pre>table.each: body</pre>
  339. *
  340. * Example: <code>[1,2,3].each: { |i| system.println(i) }</code>
  341. *
  342. * @param body a one-arity closure that is to be applied to each element of the table
  343. * @param tab a table to apply the body closure to
  344. * @return <tt>nil</tt>, by default
  345. */
  346. public ATObject base_foreach_in_(ATClosure body, ATTable tab) throws InterpreterException {
  347. return tab.base_each_(body);
  348. }
  349. /**
  350. * The <tt>do:if:</tt> control structure. Usage:
  351. * <pre>do: body if: condition</pre>
  352. *
  353. * pseudo-implementation:
  354. * <pre>condition.ifTrue: body</pre>
  355. *
  356. * In Ruby, this kind of control structure is called a <i>statement modifier</i>.
  357. *
  358. * @param body a zero-argument closure to execute if the condition is true
  359. * @param condition a boolean value
  360. * @return the result of invoking body if the condition is true or nil if the
  361. * condition is false
  362. */
  363. public ATObject base_do_if_(ATClosure body, ATBoolean condition) throws InterpreterException {
  364. return condition.base_ifTrue_(body);
  365. }
  366. /**
  367. * The <tt>do:unless:</tt> control structure. Usage:
  368. * <pre>do: body unless: condition</pre>
  369. *
  370. * pseudo-implementation:
  371. * <pre>condition.ifFalse: body</pre>
  372. *
  373. * In Ruby, this kind of control structure is called a <i>statement modifier</i>.
  374. * Example: <code>do: { file.close() } unless: (nil == file)</code>
  375. *
  376. * @param body a zero-argument closure to execute only if the condition is false
  377. * @param condition a boolean value
  378. * @return the result of invoking body if the condition is false, nil otherwise
  379. */
  380. public ATObject base_do_unless_(ATClosure body, ATBoolean condition) throws InterpreterException {
  381. return condition.base_ifFalse_(body);
  382. }
  383. /**
  384. * The <tt>let:</tt> construct. Usage:
  385. * <pre>let: { |var := value| body }</pre>
  386. *
  387. * pseudo-implementation:
  388. * <pre>closure()</pre>
  389. *
  390. * <tt>let:</tt> allows for the easy creation of temporary local variables.
  391. * This construct should be used in conjunction with a closure that declares optional
  392. * parameters. Because the closure will be invoked with zero arguments, all of the
  393. * parameters will be given their corresponding default initial value. The parameters
  394. * are defined local to the closure's body.
  395. *
  396. * AmbientTalk's <tt>let:</tt> behaves like Scheme's <tt>let*</tt> and <tt>letrec</tt>,
  397. * i.e. the following is legal:
  398. * <pre>let: {
  399. * |var1 := value1,
  400. * var2 := var1,
  401. * var3 := { ... var3() ... }|
  402. * ...
  403. *}</pre>
  404. *
  405. * @param body a closure which is supposed to declare some optional parameters
  406. * @return the result of invoking the body closure
  407. */
  408. public ATObject base_let_(ATClosure body) throws InterpreterException {
  409. return body.base_apply(NATTable.EMPTY);
  410. }
  411. /* ------------------------------------------
  412. * -- Actor Creation and accessing Methods --
  413. * ------------------------------------------ */
  414. /**
  415. * The <tt>actor: closure</tt> construct.
  416. *
  417. * The semantics of actor creation is as follows:
  418. * <ul>
  419. * <li> Mandatory parameters to the block of initialization code are treated as lexically visible
  420. * variables that have to remain available in the new actor behaviour. Hence, these variables
  421. * are evaluated to values immediately at creation-time and parameter-passed to the new actor.
  422. * <li> The closure containing the initialization code is unpacked, its lexical scope is disregarded
  423. * and the unwrapped method is serialized and sent to the new actor, which can use it to
  424. * initialize his behaviour object.
  425. * <li>The creating actor waits for the created actor to spawn a new behaviour and to return a far
  426. * reference to this behaviour. From that point on, the creating actor can run in parallel with
  427. * the created actor, which only then evaluates the initialization code to initialize its behaviour.
  428. * </ul>
  429. *
  430. * @param closure the closure whose parameters define lexical fields to be copied and whose
  431. * method specifies the code of the new actor's behaviour object
  432. * @return a far reference to the behaviour of the new actor
  433. */
  434. public ATObject base_actor_(ATClosure closure) throws InterpreterException {
  435. ATMethod method = closure.base_getMethod();
  436. NATTable copiedBindings = Evaluator.evalMandatoryPars(
  437. method.base_getParameters(),
  438. closure.base_getContext());
  439. Packet serializedBindings = new Packet("actor-bindings", copiedBindings);
  440. Packet serializedInitCode = new Packet("actor-initcode", method);
  441. ELVirtualMachine host = ELVirtualMachine.currentVM();
  442. return NATActorMirror.createActor(host, serializedBindings, serializedInitCode, new NATActorMirror(host));
  443. }
  444. /**
  445. * <tt>actor</tt> evaluates to the mirror on the actor executing this code.
  446. * The actor mirror is an object whose behaviour is consulted for operations
  447. * such as creating and sending asynchronous messages or creating mirrors on
  448. * other objects. It can be replaced by a custom mirror by means of the actor
  449. * mirror's <tt>install:</tt> primitive.
  450. */
  451. public ATActorMirror base_getActor() throws InterpreterException {
  452. return ELActor.currentActor().getActorMirror();
  453. }
  454. /**
  455. * The <tt>export: object as: topic</tt> construct. Pseudo-implementation:
  456. * <pre>actor.provide(topic, object)</pre>
  457. *
  458. * This construct enables the given object to become discoverable by objects
  459. * in other actors by means of the topic type.
  460. *
  461. * @param object the object to export to remote actors' objects
  462. * @param topic a type denoting the abstract 'publication topic' for this object's publication
  463. * @return a publication object whose <tt>cancel</tt> method can be used to cancel the publication.
  464. */
  465. public ATObject base_export_as_(ATObject object, ATTypeTag topic) throws InterpreterException {
  466. return ELActor.currentActor().getActorMirror().base_provide(topic, object);
  467. }
  468. /**
  469. * The <tt>when: topic discovered: handler</tt> construct. Pseudo-implementation:
  470. * <pre>actor.require(topic, handler, false)</pre>
  471. *
  472. * When an object is exported by <i>another</i> actor under topic, this construct triggers
  473. * the given code, passing a reference to the exported object as argument to the closure.
  474. *
  475. * Once the code block has run once, it will not be triggered again.
  476. *
  477. * @param topic the abstract 'subscription topic' used to find an exported object
  478. * @param handler a one-argument closure to apply to a discovered exported object
  479. * @return a subscription object whose <tt>cancel</tt> method can be used to cancel the subscription,
  480. * such that the handler will no longer be invoked. Beware, however, that at the time the
  481. * subscription is cancelled, a request to apply the closure may already have been scheduled
  482. * for execution by the current actor. This request is not cancelled by invoking the <tt>cancel</tt> method.
  483. */
  484. public ATObject base_when_discovered_(ATTypeTag topic, ATClosure handler) throws InterpreterException {
  485. return ELActor.currentActor().getActorMirror().base_require(topic, handler, NATBoolean._FALSE_);
  486. }
  487. /**
  488. * The <tt>whenever: topic discovered: handler</tt> construct. Pseudo-implementation:
  489. * <pre>actor.require(topic, handler, true)</pre>
  490. *
  491. * When an object is exported by <i>another</i> actor under topic, this construct triggers
  492. * the given code, passing a reference to the exported object as argument to the closure.
  493. *
  494. * The code block can be fired multiple times upon discovering multiple exported objects.
  495. * To stop the block from triggering upon new publications, it must be explicitly cancelled
  496. *
  497. * @param topic the abstract 'subscription topic' used to find an exported object
  498. * @param handler a one-argument closure to apply to any discovered exported object
  499. * @return a subscription object whose <tt>cancel</tt> method can be used to cancel the subscription,
  500. * such that the handler will no longer be invoked. Beware, however, that at the time the
  501. * subscription is cancelled, a request to apply the closure may already have been scheduled
  502. * for execution by the current actor. This request is not cancelled by invoking the <tt>cancel</tt> method.
  503. */
  504. public ATObject base_whenever_discovered_(ATTypeTag topic, ATClosure handler) throws InterpreterException {
  505. return ELActor.currentActor().getActorMirror().base_require(topic, handler, NATBoolean._TRUE_);
  506. }
  507. /**
  508. * The <tt>when: farReference disconnected: listener</tt> construct.
  509. * When the far reference is broken due to network disconnections, triggers the zero-arity listener
  510. * closure. It is possible to register listeners on local far references. These may trigger if the
  511. * local actor takes its object offline. In this case, these listeners will trigger as well.
  512. *
  513. * @param farReference a native far reference
  514. * @param listener a zero-arity closure to invoke if the far reference becomes disconnected
  515. * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
  516. * notifications of the listener.
  517. */
  518. public ATObject base_when_disconnected_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
  519. farReference.asNativeFarReference().addDisconnectionListener(listener);
  520. return new NATFarReference.NATDisconnectionSubscription(farReference.asNativeFarReference(), listener);
  521. }
  522. /**
  523. * The <tt>when: farReference reconnected: listener</tt> construct.
  524. * When the remote reference is reinstated after a network disconnection, trigger the zero-arity
  525. * listener. Although it is allowed to register these listeners on local far references,
  526. * these are normally not invoked because the only possibility for a local far ref to become
  527. * disconnected is because the object was taken offline, and this is a permanent disconnect.
  528. *
  529. * @param farReference a native far reference
  530. * @param listener a zero-arity closure to invoke if the far reference becomes reconnected
  531. * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
  532. * notifications of the listener.
  533. */
  534. public ATObject base_when_reconnected_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
  535. farReference.asNativeFarReference().addReconnectionListener(listener);
  536. return new NATFarReference.NATReconnectionSubscription(farReference.asNativeFarReference(), listener);
  537. }
  538. /**
  539. * The <tt>when: farReference takenOffline:</tt> construct.
  540. * When the (remote/local) far reference is broken because the object referenced was
  541. * taken offline, trigger the code.
  542. *
  543. * @param farReference a native far reference
  544. * @param listener a zero-arity closure to invoke if the referenced object has been taken offline.
  545. * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
  546. * notifications of the listener.
  547. */
  548. public ATObject base_when_takenOffline_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
  549. farReference.asNativeFarReference().addTakenOfflineListener(listener);
  550. return new NATFarReference.NATExpiredSubscription(farReference.asNativeFarReference(), listener);
  551. }
  552. /**
  553. * The <tt>retract: farReference</tt> construct.
  554. * Retracts all currently unsent messages from the far reference's outbox.
  555. * This has the side effect that the returned messages will <b>not</b> be sent
  556. * automatically anymore, the programmer is responsible to explicitly resend
  557. * all messages that were retracted but still need to be sent.
  558. *
  559. * Note that the returned messages are copies of the original.
  560. * @param farReference the far reference of which to retract outgoing message sends
  561. * @return a table containing copies of all messages that were sent to this far reference, but
  562. * not yet transmitted by the far reference to its referent.
  563. */
  564. public ATTable base_retract_(ATFarReference farReference) throws InterpreterException {
  565. return farReference.meta_retractUnsentMessages();
  566. }
  567. /* -----------------------------
  568. * -- Object Creation Methods --
  569. * ----------------------------- */
  570. /**
  571. * The <tt>object:</tt> object creation primitive.
  572. * This construct creates a new AmbientTalk object where:
  573. * <ul>
  574. * <li>The object is initialized with the <i>code</i> of the argument closure.
  575. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  576. * <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
  577. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  578. * <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
  579. * <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
  580. * with a 'native' metaobject protocol).
  581. * </ul>
  582. *
  583. * Example: <code>object: { def x := 1; }</code>
  584. * <p>
  585. * Pseudo-implementation:
  586. * <pre>object: code childOf: nil extends: false typedWith: [] mirroredBy: defaultMirror</pre>
  587. *
  588. * The closure used to initialize the object may contain formal parameters. The closure
  589. * will always be invoked with <i>its own mandatory formal parameters</i>. E.g., a closure
  590. * <code>{ |x| nil }</code> is invoked as <code>{ |x| nil }(x)</code>. The net effect of this
  591. * mechanic is that if <tt>x</tt> is a lexically visible variable at the object-creation
  592. * site, the value of the variable will be copied into a copy with the same name which
  593. * resides in the newly created object. This mechanic is primarily useful for copying surrounding
  594. * variables within the object, e.g. for isolates which lose access to their surrounding scope.
  595. * <p>
  596. * Also, if the closure has optional parameters, they will always be triggered.
  597. * The expressions to initialize the formal parameters are <i>evaluated</i>
  598. * in the context of the closure's lexical scope but are <i>added</i> to the newly created object.
  599. *
  600. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
  601. * @return a new AmbientTalk object with the properties defined above.
  602. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  603. */
  604. public ATObject base_object_(ATClosure code) throws InterpreterException {
  605. return base_object_childOf_extends_taggedAs_mirroredBy_(
  606. code,
  607. NATNil._INSTANCE_,
  608. NATBoolean._FALSE_ /* SHARES-A link */,
  609. NATTable.EMPTY,
  610. base_getDefaultMirror());
  611. }
  612. /**
  613. * The <tt>extend:with:</tt> object creation primitive.
  614. * This construct creates a new AmbientTalk object where:
  615. * <ul>
  616. * <li>The object is initialized with the <i>code</i> of the argument closure.
  617. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  618. * <li>The object's <b>dynamic parent</b> is the argument object.
  619. * <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
  620. * <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
  621. * <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
  622. * with a 'native' metaobject protocol).
  623. * </ul>
  624. *
  625. * Example: <code>extend: parent with: { def x := 1; }</code>
  626. * <p>
  627. * Pseudo-implementation:
  628. * <pre>object: code childOf: parent extends: true typedWith: [] mirroredBy: defaultMirror</pre>
  629. *
  630. * @param parent the dynamic parent object of the newly created object.
  631. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
  632. * @return a new AmbientTalk object with the properties defined above.
  633. * @see #base_object_(ATClosure)
  634. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  635. */
  636. public ATObject base_extend_with_(ATObject parent, ATClosure code) throws InterpreterException {
  637. return base_object_childOf_extends_taggedAs_mirroredBy_(
  638. code,
  639. parent,
  640. NATBoolean._TRUE_ /* IS-A link */,
  641. NATTable.EMPTY,
  642. base_getDefaultMirror());
  643. }
  644. /**
  645. * The <tt>extend:with:typedWith:</tt> object creation primitive.
  646. * This construct creates a new AmbientTalk object where:
  647. * <ul>
  648. * <li>The object is initialized with the <i>code</i> of the argument closure.
  649. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  650. * <li>The object's <b>dynamic parent</b> is the argument object.
  651. * <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
  652. * <li>The object's <b>types</b> are initialized to the argument types table.
  653. * <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
  654. * with a 'native' metaobject protocol).
  655. * </ul>
  656. *
  657. * Example: <code>extend: parent with: { def x := 1; } typedWith: [foo,bar]</code>
  658. * <p>
  659. * Pseudo-implementation:
  660. * <pre>object: code childOf: parent extends: true typedWith: types mirroredBy: defaultMirror</pre>
  661. *
  662. * @param parent the dynamic parent object of the newly created object.
  663. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  664. * @param types a table of types with which to type the newly created object.
  665. * @return a new AmbientTalk object with the properties defined above.
  666. * @see #base_object_(ATClosure)
  667. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  668. */
  669. public ATObject base_extend_with_taggedAs_(ATObject parent, ATClosure code, ATTable types) throws InterpreterException {
  670. return base_object_childOf_extends_taggedAs_mirroredBy_(
  671. code,
  672. parent,
  673. NATBoolean._TRUE_ /* IS-A link */,
  674. types,
  675. base_getDefaultMirror());
  676. }
  677. /**
  678. * The <tt>extend:with:mirroredBy:</tt> object creation primitive.
  679. * This construct creates a new AmbientTalk object where:
  680. * <ul>
  681. * <li>The object is initialized with the <i>code</i> of the argument closure.
  682. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  683. * <li>The object's <b>dynamic parent</b> is the argument object.
  684. * <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
  685. * <li>The object's <b>types</b> are set to <tt>[]</tt> (i.e. the object has no types).
  686. * <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
  687. * whose metaobject protocol is entirely dictated by the given mirror.
  688. * </ul>
  689. *
  690. * Example: <code>extend: parent with: { def x := 1; } mirroredBy: (mirror: {...})</code>
  691. * <p>
  692. * Pseudo-implementation:
  693. * <pre>object: code childOf: parent extends: true typedWith: [] mirroredBy: mirror</pre>
  694. *
  695. * @param parent the dynamic parent object of the newly created object.
  696. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  697. * @param mirror the mirror of the newly created mirage object.
  698. * @return a new AmbientTalk object with the properties defined above.
  699. * @see #base_object_(ATClosure)
  700. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  701. */
  702. public ATObject base_extend_with_mirroredBy_(ATObject parent, ATClosure code, ATObject mirror) throws InterpreterException {
  703. return base_object_childOf_extends_taggedAs_mirroredBy_(
  704. code,
  705. parent,
  706. NATBoolean._TRUE_ /* IS-A link */,
  707. NATTable.EMPTY,
  708. mirror);
  709. }
  710. /**
  711. * The <tt>extend:with:typedWith:mirroredBy:</tt> object creation primitive.
  712. * This construct creates a new AmbientTalk object where:
  713. * <ul>
  714. * <li>The object is initialized with the <i>code</i> of the argument closure.
  715. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  716. * <li>The object's <b>dynamic parent</b> is the argument object.
  717. * <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
  718. * <li>The object's <b>types</b> are initialized to the argument types table.
  719. * <li>The object's <b>mirror</b> is the given argument mirror. This means that the newly
  720. * created object is a <i>mirage</i> whose metaobject protocol is dictated by the given mirror.
  721. * </ul>
  722. *
  723. * Example: <code>extend: parent with: { def x := 1; } typedWith: [foo,bar] mirroredBy: mirror</code>
  724. * <p>
  725. * Pseudo-implementation:
  726. * <pre>object: code childOf: parent extends: true typedWith: types mirroredBy: mirror</pre>
  727. *
  728. * @param parent the dynamic parent object of the newly created object.
  729. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  730. * @param types a table of types with which to type the newly created object.
  731. * @param the mirror object of the newly created mirage object.
  732. * @return a new AmbientTalk object with the properties defined above.
  733. * @see #base_object_(ATClosure)
  734. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  735. */
  736. public ATObject base_extend_with_taggedAs_mirroredBy_(ATObject parent, ATClosure code, ATTable types, ATObject mirror) throws InterpreterException {
  737. return base_object_childOf_extends_taggedAs_mirroredBy_(
  738. code,
  739. parent,
  740. NATBoolean._TRUE_ /* IS-A link */,
  741. types,
  742. mirror);
  743. }
  744. /**
  745. * The <tt>share:with:</tt> object creation primitive.
  746. * This construct creates a new AmbientTalk object where:
  747. * <ul>
  748. * <li>The object is initialized with the <i>code</i> of the argument closure.
  749. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  750. * <li>The object's <b>dynamic parent</b> is the argument object.
  751. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  752. * <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
  753. * <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
  754. * with a 'native' metaobject protocol).
  755. * </ul>
  756. *
  757. * Example: <code>share: parent with: { def x := 1; }</code>
  758. * <p>
  759. * Pseudo-implementation:
  760. * <pre>object: code childOf: parent extends: false typedWith: [] mirroredBy: defaultMirror</pre>
  761. *
  762. * @param parent the dynamic parent object of the newly created object.
  763. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
  764. * @return a new AmbientTalk object with the properties defined above.
  765. * @see #base_object_(ATClosure)
  766. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  767. */
  768. public ATObject base_share_with_(ATObject parent, ATClosure code) throws InterpreterException {
  769. return base_object_childOf_extends_taggedAs_mirroredBy_(
  770. code,
  771. parent,
  772. NATBoolean._FALSE_ /* SHARES-A link */,
  773. NATTable.EMPTY,
  774. base_getDefaultMirror());
  775. }
  776. /**
  777. * The <tt>share:with:typedWith:</tt> object creation primitive.
  778. * This construct creates a new AmbientTalk object where:
  779. * <ul>
  780. * <li>The object is initialized with the <i>code</i> of the argument closure.
  781. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  782. * <li>The object's <b>dynamic parent</b> is the argument object.
  783. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  784. * <li>The object's <b>types</b> are initialized to the argument types table.
  785. * <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
  786. * with a 'native' metaobject protocol).
  787. * </ul>
  788. *
  789. * Example: <code>share: parent with: { def x := 1; } typedWith: [foo,bar]</code>
  790. * <p>
  791. * Pseudo-implementation:
  792. * <pre>object: code childOf: parent extends: false typedWith: types mirroredBy: defaultMirror</pre>
  793. *
  794. * @param parent the dynamic parent object of the newly created object.
  795. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  796. * @param types a table of types with which to type the newly created object.
  797. * @return a new AmbientTalk object with the properties defined above.
  798. * @see #base_object_(ATClosure)
  799. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  800. */
  801. public ATObject base_share_with_taggedAs_(ATObject parent, ATClosure code, ATTable types) throws InterpreterException {
  802. return base_object_childOf_extends_taggedAs_mirroredBy_(
  803. code,
  804. parent,
  805. NATBoolean._FALSE_ /* SHARES-A link */,
  806. types,
  807. base_getDefaultMirror());
  808. }
  809. /**
  810. * The <tt>share:with:mirroredBy:</tt> object creation primitive.
  811. * This construct creates a new AmbientTalk object where:
  812. * <ul>
  813. * <li>The object is initialized with the <i>code</i> of the argument closure.
  814. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  815. * <li>The object's <b>dynamic parent</b> is the argument object.
  816. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  817. * <li>The object's <b>types</b> are set to <tt>[]</tt> (i.e. the object has no types).
  818. * <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
  819. * whose metaobject protocol is entirely dictated by the given mirror.
  820. * </ul>
  821. *
  822. * Example: <code>share: parent with: { def x := 1; } mirroredBy: (mirror: {...})</code>
  823. * <p>
  824. * Pseudo-implementation:
  825. * <pre>object: code childOf: parent extends: false typedWith: [] mirroredBy: mirror</pre>
  826. *
  827. * @param parent the dynamic parent object of the newly created object.
  828. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  829. * @param mirror the mirror of the newly created mirage object.
  830. * @return a new AmbientTalk object with the properties defined above.
  831. * @see #base_object_(ATClosure)
  832. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  833. */
  834. public ATObject base_share_with_mirroredBy_(ATObject parent, ATClosure code, ATObject mirror) throws InterpreterException {
  835. return base_object_childOf_extends_taggedAs_mirroredBy_(
  836. code,
  837. parent,
  838. NATBoolean._FALSE_ /* SHARES-A link */,
  839. NATTable.EMPTY,
  840. mirror);
  841. }
  842. /**
  843. * The <tt>share:with:typedWith:mirroredBy:</tt> object creation primitive.
  844. * This construct creates a new AmbientTalk object where:
  845. * <ul>
  846. * <li>The object is initialized with the <i>code</i> of the argument closure.
  847. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  848. * <li>The object's <b>dynamic parent</b> is the argument object.
  849. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  850. * <li>The object's <b>types</b> are initialized to the argument types table.
  851. * <li>The object's <b>mirror</b> is the given argument mirror. This means that the newly
  852. * created object is a <i>mirage</i> whose metaobject protocol is dictated by the given mirror.
  853. * </ul>
  854. *
  855. * Example: <code>share: parent with: { def x := 1; } typedWith: [foo,bar] mirroredBy: mirror</code>
  856. * <p>
  857. * Pseudo-implementation:
  858. * <pre>object: code childOf: parent extends: false typedWith: types mirroredBy: mirror</pre>
  859. *
  860. * @param parent the dynamic parent object of the newly created object.
  861. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  862. * @param types a table of types with which to type the newly created object.
  863. * @param the mirror object of the newly created mirage object.
  864. * @return a new AmbientTalk object with the properties defined above.
  865. * @see #base_object_(ATClosure)
  866. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  867. */
  868. public ATObject base_share_with_taggedAs_mirroredBy_(ATObject parent, ATClosure code, ATTable types, ATObject mirror) throws InterpreterException {
  869. return base_object_childOf_extends_taggedAs_mirroredBy_(
  870. code,
  871. parent,
  872. NATBoolean._FALSE_ /* SHARES-A link */,
  873. types,
  874. mirror);
  875. }
  876. /**
  877. * The <tt>object:typedWith:</tt> object creation primitive.
  878. * This construct creates a new AmbientTalk object where:
  879. * <ul>
  880. * <li>The object is initialized with the <i>code</i> of the argument closure.
  881. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  882. * <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
  883. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  884. * <li>The object's <b>types</b> are initialized to the argument types table.
  885. * <li>The object's <b>mirror</b> is <tt>defaultMirror</tt> (i.e. the object has the
  886. * default metaobject protocol).
  887. * </ul>
  888. *
  889. * Example: <code>object: { def x := 1; } typedWith: [foo,bar]</code>
  890. * <p>
  891. * Pseudo-implementation:
  892. * <pre>object: code childOf: nil extends: false typedWith: types mirroredBy: defaultMirror</pre>
  893. *
  894. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  895. * @param types a table of types with which to type the newly created object.
  896. * @return a new AmbientTalk object with the properties defined above.
  897. * @see #base_object_(ATClosure)
  898. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  899. */
  900. public ATObject base_object_taggedAs_(ATClosure code, ATTable types) throws InterpreterException {
  901. return base_object_childOf_extends_taggedAs_mirroredBy_(
  902. code,
  903. NATNil._INSTANCE_,
  904. NATBoolean._FALSE_ /* SHARES-A link */,
  905. types,
  906. base_getDefaultMirror());
  907. }
  908. /**
  909. * The <tt>isolate:</tt> object creation primitive.
  910. * This construct creates a new AmbientTalk object where:
  911. * <ul>
  912. * <li>The object is initialized with the <i>code</i> of the argument closure.
  913. * <li>The object's <b>lexical parent</b> is initialized to the lexical scope of the argument closure,
  914. * but because it is typed as an isolate, the parent link is replaced by a link to the lexical <tt>root</tt>.
  915. * <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
  916. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  917. * <li>The object's <b>types</b> are initialized to <tt>[/.at.types.Isolate]</tt>, i.e.
  918. * the object is typed as an isolate.
  919. * <li>The object's <b>mirror</b> is <tt>defaultMirror</tt> (i.e. the object has the
  920. * default metaobject protocol).
  921. * </ul>
  922. *
  923. * Example: <code>isolate: { def x := 1; }</code>
  924. * <p>
  925. * Pseudo-implementation:
  926. * <pre>object: code childOf: nil extends: false taggedAs: [/.at.types.Isolate] mirroredBy: defaultMirror</pre>
  927. *
  928. * An isolate is an object without a proper lexical parent. It is as if the isolate is always
  929. * defined at top-level. However, lexically visible variables can be retained by copying them into the isolate
  930. * by means of formal parameters to the argument closure. Isolate objects are passed by-copy during
  931. * inter-actor parameter and result passing.
  932. *
  933. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  934. * @return a new AmbientTalk object with the properties defined above.
  935. * @see #base_object_(ATClosure)
  936. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  937. */
  938. public ATObject base_isolate_(ATClosure code) throws InterpreterException {
  939. return base_object_taggedAs_(code, NATTable.of(NativeTypeTags._ISOLATE_));
  940. }
  941. /**
  942. * The <tt>mirror:</tt> object creation primitive.
  943. * This construct creates a new AmbientTalk object where:
  944. * <ul>
  945. * <li>The object is initialized with the <i>code</i> of the argument closure.
  946. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  947. * <li>The object's <b>dynamic parent</b> is <tt>defaultMirror</tt>.
  948. * <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
  949. * <li>The object's <b>types</b> are initialized to <tt>[]</tt>.
  950. * <li>The object's <b>mirror</b> is <tt>defaultMirror</tt> (i.e. the object has the
  951. * default metaobject protocol).
  952. * </ul>
  953. *
  954. * Example: <code>mirror: { def x := 1; }</code>
  955. * <p>
  956. * Pseudo-implementation:
  957. * <pre>object: code childOf: defaultMirror extends: true taggedAs: [] mirroredBy: defaultMirror</pre>
  958. *
  959. * This construct is mere syntactic sugar for creating an extension of the default mirror root.
  960. * It follows that AmbientTalk mirrors are plain AmbientTalk objects. They simply need to implement
  961. * the entire metaobject protocol, and the easiest means to achieve this is by extending the default mirror.
  962. * Also keep in mind that the mirror is an extension object. This is important because the default
  963. * mirror has <i>state</i>, being the <tt>base</tt> field that points to the base-level object
  964. * being mirrorred. Hence, always make sure that, if overriding <tt>init</tt>, the parent's
  965. * <tt>init</tt> method is invoked with the appropriate <tt>base</tt> value.
  966. *
  967. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  968. * @return a new AmbientTalk object with the properties defined above.
  969. * @see #base_object_(ATClosure)
  970. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  971. */
  972. public ATObject base_mirror_(ATClosure code) throws InterpreterException {
  973. return base_object_childOf_extends_taggedAs_mirroredBy_(
  974. code,
  975. base_getDefaultMirror(),
  976. NATBoolean._TRUE_ /* IS-A link */,
  977. NATTable.EMPTY,
  978. base_getDefaultMirror());
  979. }
  980. /**
  981. * The <tt>object:mirroredBy:</tt> object creation primitive.
  982. * This construct creates a new AmbientTalk object where:
  983. * <ul>
  984. * <li>The object is initialized with the <i>code</i> of the argument closure.
  985. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  986. * <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
  987. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  988. * <li>The object's <b>types</b> are set to <tt>[]</tt> (i.e. the object has no types).
  989. * <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
  990. * whose metaobject protocol is entirely dictated by the given mirror.
  991. * </ul>
  992. *
  993. * Example: <code>object: { def x := 1; } mirroredBy: (mirror: {...})</code>
  994. * <p>
  995. * Pseudo-implementation:
  996. * <pre>object: code childOf: nil extends: false taggedAs: [] mirroredBy: mirror</pre>
  997. *
  998. * This primitive allows the construction of so-called <i>mirage</i> objects which are
  999. * AmbientTalk objects whose metaobject protocol behaviour is dictated by a custom mirror
  1000. * object.
  1001. *
  1002. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  1003. * @param mirror the mirror of the newly created mirage object.
  1004. * @return a new AmbientTalk object with the properties defined above.
  1005. * @see #base_object_(ATClosure)
  1006. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  1007. */
  1008. public ATObject base_object_mirroredBy_(ATClosure code, ATObject mirror) throws InterpreterException {
  1009. return base_object_childOf_extends_taggedAs_mirroredBy_(
  1010. code,
  1011. NATNil._INSTANCE_,
  1012. NATBoolean._FALSE_ /* SHARES-A link */,
  1013. NATTable.EMPTY,
  1014. mirror);
  1015. }
  1016. /**
  1017. * The <tt>object:taggedAs:mirroredBy:</tt> object creation primitive.
  1018. * This construct creates a new AmbientTalk object where:
  1019. * <ul>
  1020. * <li>The object is initialized with the <i>code</i> of the argument closure.
  1021. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  1022. * <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
  1023. * <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
  1024. * <li>The object's <b>types</b> are set to the argument types.
  1025. * <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
  1026. * whose metaobject protocol is entirely dictated by the given mirror.
  1027. * </ul>
  1028. *
  1029. * Example: <code>object: { def x := 1; } taggedAs: [foo,bar] mirroredBy: (mirror: {...})</code>
  1030. * <p>
  1031. * Pseudo-implementation:
  1032. * <pre>object: code childOf: nil extends: false taggedAs: types mirroredBy: mirror</pre>
  1033. *
  1034. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  1035. * @param types a table of types with which to type the newly created object.
  1036. * @param mirror the mirror of the newly created mirage object.
  1037. * @return a new AmbientTalk object with the properties defined above.
  1038. * @see #base_object_(ATClosure)
  1039. * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
  1040. */
  1041. public ATObject base_object_taggedAs_mirroredBy_(ATClosure code, ATTable types, ATObject mirror) throws InterpreterException {
  1042. return base_object_childOf_extends_taggedAs_mirroredBy_(
  1043. code,
  1044. NATNil._INSTANCE_,
  1045. NATBoolean._FALSE_ /* SHARES-A link */,
  1046. types,
  1047. mirror);
  1048. }
  1049. /**
  1050. * The <tt>object:childOf:extends:taggedAs:mirroredBy:</tt> object creation primitive.
  1051. * This construct creates a new AmbientTalk object where:
  1052. * <ul>
  1053. * <li>The object is initialized with the <i>code</i> of the argument closure.
  1054. * <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure.
  1055. * <li>The object's <b>dynamic parent</b> is the argument parent object.
  1056. * <li>The object's <b>parent type</b> is the argument parent type, true being <tt>IS-A</tt>, false being <tt>SHARES-A</tt>.
  1057. * <li>The object's <b>types</b> are set to the argument types table.
  1058. * <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
  1059. * whose metaobject protocol is entirely dictated by the given mirror, if the mirror is not <tt>defaultMirror</tt>.
  1060. * </ul>
  1061. *
  1062. * Example: <code>object: { def x := 1; } childOf: parent extends: true taggedAs: [foo,bar] mirroredBy: mirror</code>
  1063. * <p>
  1064. * Pseudo-implementation:
  1065. * <pre>let o = OBJECT(parent,code.lexicalParent,parentType,types);
  1066. * code.applyInScope(o, code.mandatoryPars);
  1067. * o
  1068. * </pre>
  1069. *
  1070. * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
  1071. * @param parent the dynamic parent object of the newly created object.
  1072. * @param parentType a boolean denoting whether or not the object is an extension of its dynamic parent.
  1073. * @param types a table of types with which the newly created object should be typed.
  1074. * @param mirror the mirror of the newly created object.
  1075. * @return a new AmbientTalk object with the properties defined above.
  1076. * @see #base_object_(ATClosure) for more information about the properties of the passed closure.
  1077. */
  1078. public ATObject base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure code, ATObject parent, ATBoolean parentType, ATTable types, ATObject mirror) throws InterpreterException {
  1079. ATTypeTag[] typeArray = NATTypeTag.toTypeTagArray(types);
  1080. boolean parentRelation = parentType.asNativeBoolean().javaValue;
  1081. NATObject newObject;
  1082. // if the mirror is a 'default' mirror...
  1083. if (mirror instanceof OBJMirrorRoot) {
  1084. // then create a native object
  1085. newObject = new NATObject(parent, // dynamic parent
  1086. code.base_getContext().base_getLexicalScope(), // lexical parent
  1087. parentRelation, // IS-A or SHARES-A
  1088. typeArray); // initial types
  1089. } else {
  1090. // else create a mirage mirrored by the custom mirror
  1091. newObject = NATMirage.createMirage(code, parent, parentRelation, typeArray, mirror);
  1092. }
  1093. newObject.initializeWithCode(code);
  1094. return newObject;
  1095. }
  1096. /**
  1097. * The <tt>reflect:</tt> construct. This construct returns a mirror on an object.
  1098. *
  1099. * pseudo-implementation:
  1100. * <pre>actor.createMirror(reflectee)</pre>
  1101. *
  1102. * An actor can change its default mirror creation policy by installing a new
  1103. * actor protocol that overrides <tt>createMirror</tt>.
  1104. *
  1105. * @param reflectee the object to reflect upon
  1106. * @return a mirror reflecting on the given object
  1107. * @see ATActorMirror#base_createMirror(ATObject) for the details about mirror creation on objects.
  1108. */
  1109. public ATObject base_reflect_(ATObject reflectee) throws InterpreterException {
  1110. return base_getActor().base_createMirror(reflectee);
  1111. }
  1112. /**
  1113. * The <tt>clone:</tt> language construct. Returns a clone of an object.
  1114. *
  1115. * Care must be taken when cloning a mirror. If a mirror would simply be cloned
  1116. * using the regular cloning semantics, its base field would be <b>shared</b>
  1117. * between the clone and the original mirror (because of shallow copy semantics).
  1118. * However, the base object will still be tied to the original mirror, not the clone.
  1119. * Therefore, the clone: operator is implemented as follows:
  1120. *
  1121. * <pre>def clone: obj {
  1122. * if: (is: obj taggedAs: Mirror) then: {
  1123. * reflect: (clone: obj.base)
  1124. * } else: {
  1125. * (reflect: obj).clone()
  1126. * }
  1127. * }</pre>
  1128. *
  1129. * The default cloning semantics ensures that all fields of the object are shallow-copied.
  1130. * Because methods are immutable, a clone and its original object share their method dictionary,
  1131. * but whenever a change is made to the dictionary, the changer creates a local copy of the
  1132. * dictionary as to not modify any clones. Hence, each object is truly stand-alone and independent
  1133. * of its clone.
  1134. *
  1135. * @param original the object to copy
  1136. * @return a clone of the given object (default semantics results in a shallow copy)
  1137. */
  1138. public ATObject base_clone_(ATObject original) throws InterpreterException {
  1139. if (original.meta_isTaggedAs(NativeTypeTags._MIRROR_).asNativeBoolean().javaValue) {
  1140. return base_reflect_(base_clone_(original.meta_select(original, OBJMirrorRoot._BASE_NAME_)));
  1141. } else {
  1142. return original.meta_clone();
  1143. }
  1144. }
  1145. /**
  1146. * The <tt>takeOffline:</tt> construct.
  1147. * Removes an object from the export table of an actor. This ensures that the object
  1148. * is no longer remotely accessible. This method is the cornerstone of distributed
  1149. * garbage collection in AmbientTalk. When an object is taken offline, remote clients
  1150. * that would still access it perceive this as if the object had become permanently
  1151. * disconnected.
  1152. *
  1153. * @return <tt>nil</tt>.
  1154. */
  1155. public ATNil base_takeOffline_ (ATObject object) throws InterpreterException{
  1156. ELActor.currentActor().takeOffline(object);
  1157. return NATNil._INSTANCE_;
  1158. }
  1159. /* -------------------
  1160. * -- Type Support -
  1161. * ------------------- */
  1162. /**
  1163. * The <tt>is: object taggedAs: type</tt> construct.
  1164. * @return true if the given object is typed with the given type, false otherwise
  1165. */
  1166. public ATBoolean base_is_taggedAs_(ATObject object, ATTypeTag type) throws InterpreterException {
  1167. return object.meta_isTaggedAs(type);
  1168. }
  1169. /**
  1170. * The <tt>tagsOf: object</tt>
  1171. * @return a table of all of the <i>local</i> types of an object.
  1172. */
  1173. public ATTable base_tagsOf_(ATObject object) throws InterpreterException {
  1174. return object.meta_getTypeTags();
  1175. }
  1176. /* -------------------------------
  1177. * -- Exception Handling Support -
  1178. * ------------------------------- */
  1179. /**
  1180. * The <tt>try: { tryBlock } usingHandlers: [ handler1, handler2, ... ]</tt> construct.
  1181. *
  1182. * Applies the given closure (to <tt>[]</tt>) and handles exceptions using the given exception handlers.
  1183. * This is the most general means of doing exception handling in AmbientTalk.
  1184. *
  1185. * The handlers given in the handler table represent first-class handler objects,
  1186. * which should respond to the <tt>canHandle</tt> message.
  1187. * @see ATHandler for the interface to which a handler object has to adhere
  1188. */
  1189. public ATObject base_try_usingHandlers_(ATClosure tryBlock, ATTable exceptionHandlers) throws InterpreterException {
  1190. try {
  1191. return tryBlock.base_apply(NATTable.EMPTY);
  1192. } catch(InterpreterException e) {
  1193. ATObject[] handlers = exceptionHandlers.asNativeTable().elements_;
  1194. // find the appropriate handler
  1195. for (int i = 0; i < handlers.length; i++) {
  1196. ATHandler handler = handlers[i].asHandler();
  1197. ATObject exc = e.getAmbientTalkRepresentation();
  1198. if (handler.base_canHandle(exc).asNativeBoolean().javaValue) {
  1199. return handler.base_handle(exc);
  1200. };
  1201. }
  1202. // no handler found, re-throw the exception
  1203. throw e;
  1204. }
  1205. }
  1206. /**
  1207. * The <tt>try: { tryBlock} using: handler</tt> construct.
  1208. *
  1209. * Ad-hoc code for one exception handler.
  1210. *
  1211. * @see #base_try_usingHandlers_(ATClosure, ATTable)
  1212. */
  1213. public ATObject base_try_using_(ATClosure tryBlock, ATHandler handler) throws InterpreterException {
  1214. try {
  1215. return tryBlock.base_apply(NATTable.EMPTY);
  1216. } catch(InterpreterException e) {
  1217. ATObject exc = e.getAmbientTalkRepresentation();
  1218. if (handler.base_canHandle(exc).asNativeBoolean().javaValue) {
  1219. return handler.base_handle(exc);
  1220. } else {
  1221. throw e;
  1222. }
  1223. }
  1224. }
  1225. /**
  1226. * The <tt>try: { tryBlock} using: handler1 using: handler2</tt> construct.
  1227. *
  1228. * Ad-hoc code for two exception handlers.
  1229. * @see #base_try_usingHandlers_(ATClosure, ATTable)
  1230. */
  1231. public ATObject base_try_using_using_(ATClosure tryBlock, ATHandler hdl1, ATHandler hdl2) throws InterpreterException {
  1232. return base_try_usingHandlers_(tryBlock, NATTable.atValue(new ATObject[] { hdl1, hdl2 }));
  1233. }
  1234. /**
  1235. * The <tt>try: { tryBlock} using: hdl1 using: hdl2 using: hdl3</tt> construct.
  1236. *
  1237. * Ad-hoc code for three exception handlers
  1238. * @see #base_try_usingHandlers_(ATClosure, ATTable)
  1239. */
  1240. public ATObject base_try_using_using_using_(ATClosure tryBlock, ATHandler hdl1, ATHandler hdl2, ATHandler hdl3) throws InterpreterException {
  1241. return base_try_usingHandlers_(tryBlock, NATTable.atValue(new ATObject[] { hdl1, hdl2, hdl3 }));
  1242. }
  1243. /**
  1244. * The <tt>try: { tryBlock} catch: type using: { |e| replacementCode }</tt>
  1245. *
  1246. * 'Syntactic sugar' for one "in-line", native handler.
  1247. * @see #base_try_usingHandlers_(ATClosure, ATTable)
  1248. */
  1249. public ATObject base_try_catch_using_(ATClosure tryBlock, ATTypeTag filter, ATClosure replacementCode) throws InterpreterException {
  1250. return base_try_using_(tryBlock, new NATHandler(filter, replacementCode));
  1251. }
  1252. /**
  1253. * The <tt>try:catch:using:catch:using:</tt> construct.
  1254. *
  1255. * <pre>try: {
  1256. * tryBlock
  1257. * } catch: type using: { |e|
  1258. * replacementCode
  1259. * } catch: type2 using: { |e|
  1260. * replacementCode2
  1261. * }</pre>
  1262. *
  1263. * 'Syntactic sugar' for two in-line handlers
  1264. * @see #base_try_usingHandlers_(ATClosure, ATTable)
  1265. */
  1266. public ATObject base_try_catch_using_catch_using_( ATClosure tryBlock,
  1267. ATTypeTag filter1, ATClosure hdl1,
  1268. ATTypeTag filter2, ATClosure hdl2) throws InterpreterException {
  1269. return base_try_using_using_(tryBlock, new NATHandler(filter1, hdl1), new NATHandler(filter2, hdl2));
  1270. }
  1271. /**
  1272. * The <tt>try:catch:using:catch:using:catch:using:</tt> construct.
  1273. *
  1274. * <pre>try: {
  1275. * tryBlock
  1276. * } catch: type using: { |e|
  1277. * replacementCode
  1278. * } catch: type2 using: { |e|
  1279. * replacementCode2
  1280. * } catch: type3 using: { |e|
  1281. * replacementCode3
  1282. * }</pre>
  1283. *
  1284. * 'Syntactic sugar' for three in-line handlers
  1285. * @see #base_try_usingHandlers_(ATClosure, ATTable)
  1286. */
  1287. public ATObject base_try_catch_using_catch_using_catch_using_(ATClosure tryBlock,
  1288. ATTypeTag filter1, ATClosure hdl1,
  1289. ATTypeTag filter2, ATClosure hdl2,
  1290. ATTypeTag filter3, ATClosure hdl3) throws InterpreterException {
  1291. return base_try_using_using_using_(tryBlock, new NATHandler(filter1, hdl1), new NATHandler(filter2, hdl2), new NATHandler(filter3, hdl3));
  1292. }
  1293. /**
  1294. * The <tt>handle: type with: { |e| replacementCode }</tt> construct.
  1295. *
  1296. * @return a first-class handler from a filter prototype and some handler code.
  1297. * @see ATHandler for the interface to which a handler object responds.
  1298. */
  1299. public ATObject base_handle_with_(ATTypeTag filter, ATClosure replacementCode) {
  1300. return new NATHandler(filter, replacementCode);
  1301. }
  1302. /**
  1303. * The <tt>raise: exception</tt> construct.
  1304. *
  1305. * Raises an exception which can be caught by dynamically installed try-catch-using blocks.
  1306. * @see #base_try_usingHandlers_(ATClosure, ATTable)
  1307. */
  1308. public ATNil base_raise_(ATObject anExceptionObject) throws InterpreterException {
  1309. throw Evaluator.asNativeException(anExceptionObject);
  1310. }
  1311. /* --------------------
  1312. * -- Unary Operators -
  1313. * -------------------- */
  1314. /**
  1315. * The unary <tt>!</tt> primitive.
  1316. * <pre>!b == b.not()</pre>
  1317. * @param b the boolean to negate.
  1318. * @return the negation of the boolean.
  1319. */
  1320. public ATBoolean base__opnot_(ATBoolean b) throws InterpreterException {
  1321. return b.base_not();
  1322. }
  1323. /**
  1324. * The unary <tt>-</tt> primitive.
  1325. * <pre>-NUM(n) == 0 - n</pre>
  1326. *
  1327. * @param n a number or a fraction to negate.
  1328. */
  1329. public ATNumeric base__opmns_(ATNumeric n) throws InterpreterException {
  1330. return NATNumber.ZERO.base__opmns_(n);
  1331. }
  1332. /**
  1333. * The unary <tt>+</tt> primitive.
  1334. * <pre>+NBR(n) == NBR(n)</pre>
  1335. */
  1336. public ATNumber base__oppls_(ATNumber n) throws InterpreterException {
  1337. return n;
  1338. }
  1339. /* -------------------
  1340. * -- Miscellaneous --
  1341. * ------------------- */
  1342. /**
  1343. * The <tt>read:</tt> metaprogramming construct. Parses the given text string into an
  1344. * abstract syntax tree.
  1345. *
  1346. * Example: <code>read: "x" => `x</code>
  1347. */
  1348. public ATAbstractGrammar base_read_(ATText source) throws InterpreterException {
  1349. return NATParser._INSTANCE_.base_parse(source);
  1350. }
  1351. /**
  1352. * The <tt>eval:in:</tt> metaprogramming construct.
  1353. * Evaluates the given AST in the context of the given object, returning its value.
  1354. *
  1355. * Example: <code>eval: `x in: object: { def x := 1 } => 1</code>
  1356. *
  1357. * This is a "dangerous" operation in the sense that lexical encapsulation of the given
  1358. * object can be violated.
  1359. */
  1360. public ATObject base_eval_in_(ATAbstractGrammar ast, ATObject obj) throws InterpreterException {
  1361. return ast.meta_eval(new NATContext(obj, obj));
  1362. }
  1363. /**
  1364. * The <tt>print:</tt> metaprogramming construct.
  1365. * This construct invokes the object mirror's <tt>print</tt> method.
  1366. *
  1367. * @return a text string being a human-readable representation of the given object.
  1368. */
  1369. public ATText base_print_(ATObject obj) throws InterpreterException {
  1370. return obj.meta_print();
  1371. }
  1372. /**
  1373. * Compare the receiver object to the <tt>root</tt> object.
  1374. * the reason for this custom implementation: during the execution
  1375. * of this method, 'this' should refer to the global lexical scope object (the root),
  1376. * not to the OBJLexicalRoot instance.
  1377. *
  1378. * When invoking one of these methods lexically, the receiver is always 'root'
  1379. * For example, <code>==(obj)</code> is equivalent to <code>root == obj</code> (or "root.==(obj)")
  1380. */
  1381. public ATBoolean base__opeql__opeql_(ATObject comparand) throws InterpreterException {
  1382. return Evaluator.getGlobalLexicalScope().base__opeql__opeql_(comparand);
  1383. }
  1384. /**
  1385. * Instantiate the <tt>root</tt> object. I.e. <code>new()</code> is equivalent
  1386. * to <tt>root.new()</tt>.
  1387. */
  1388. public ATObject base_new(ATObject[] initargs) throws InterpreterException {
  1389. // root.new(@initargs)
  1390. return Evaluator.getGlobalLexicalScope().base_new(initargs);
  1391. }
  1392. /**
  1393. * After deserialization, ensure that the lexical root remains unique.
  1394. */
  1395. public ATObject meta_resolve() throws InterpreterException {
  1396. return OBJLexicalRoot._INSTANCE_;
  1397. }
  1398. }