PageRenderTime 124ms CodeModel.GetById 57ms app.highlight 55ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at2dist041108/src/edu/vub/at/objects/natives/OBJLexicalRoot.java

http://ambienttalk.googlecode.com/
Java | 1731 lines | 451 code | 117 blank | 1163 comment | 18 complexity | d4dd4621ac4e2c35ee1f1798eba9b62e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   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 */
  28package edu.vub.at.objects.natives;
  29
  30import edu.vub.at.actors.ATActorMirror;
  31import edu.vub.at.actors.ATFarReference;
  32import edu.vub.at.actors.natives.ELActor;
  33import edu.vub.at.actors.natives.ELVirtualMachine;
  34import edu.vub.at.actors.natives.NATFarReference;
  35import edu.vub.at.actors.natives.Packet;
  36import edu.vub.at.actors.net.OBJNetwork;
  37import edu.vub.at.eval.Evaluator;
  38import edu.vub.at.exceptions.InterpreterException;
  39import edu.vub.at.exceptions.XIllegalOperation;
  40import edu.vub.at.exceptions.XUnassignableField;
  41import edu.vub.at.exceptions.XUndefinedSlot;
  42import edu.vub.at.objects.ATAbstractGrammar;
  43import edu.vub.at.objects.ATBoolean;
  44import edu.vub.at.objects.ATClosure;
  45import edu.vub.at.objects.ATHandler;
  46import edu.vub.at.objects.ATMethod;
  47import edu.vub.at.objects.ATNil;
  48import edu.vub.at.objects.ATNumber;
  49import edu.vub.at.objects.ATNumeric;
  50import edu.vub.at.objects.ATObject;
  51import edu.vub.at.objects.ATTable;
  52import edu.vub.at.objects.ATText;
  53import edu.vub.at.objects.ATTypeTag;
  54import edu.vub.at.objects.coercion.NativeTypeTags;
  55import edu.vub.at.objects.grammar.ATAssignmentSymbol;
  56import edu.vub.at.objects.grammar.ATSymbol;
  57import edu.vub.at.objects.mirrors.NATMirage;
  58import edu.vub.at.objects.mirrors.NATMirrorRoot;
  59import edu.vub.at.objects.mirrors.NativeClosure;
  60import edu.vub.at.parser.NATParser;
  61import edu.vub.at.util.logging.Logging;
  62
  63import java.util.Iterator;
  64import java.util.LinkedList;
  65import java.util.List;
  66import java.util.Set;
  67
  68/**
  69 * The singleton instance of this class represents the lexical root of an actor.
  70 * Since this lexical root is constant (it cannot be modified) and contains no mutable fields,
  71 * it is possible to share a singleton instance of this class among all actors.
  72 * <p>
  73 * The lexical root is an object containing globally visible AmbientTalk native methods.
  74 * Such methods include control structures such as <tt>if:then:else:</tt>
  75 * but also object creation methods like <tt>object:</tt> and reflective constructs
  76 * like <tt>reflect:</tt>.
  77 * 
  78 * Furthermore, the lexical root is also the root of the lexical parent hierarchy for objects.
  79 * This means that this object's mirror is responsible for ending recursive meta-level methods
  80 * such as <tt>lookup</tt> and <tt>assignField</tt>.
  81 * <p>
  82 * Like any class whose instances represent native AmbientTalk objects, this class is a subclass
  83 * of {@link NativeATObject}. This means that this class can use the typical protocol of native objects
  84 * to implement base-level AmbientTalk methods as Java methods whose name is prefixed with
  85 * <tt>base_</tt>.
  86 * <p>
  87 * Note that OBJLexicalRoot is a <i>sentinel</i> class. The actual object bound to the
  88 * lexical root of an actor (accessible via the field <tt>root</tt> will be a normal
  89 * AmbientTalk object whose lexical parent is this object.
  90 * The real, empty, root object is local to each actor and is mutable. The definitions
  91 * from the <tt>init.at</tt> file are added to that object.
  92 * 
  93 * @author smostinc
  94 * @author tvcutsem
  95 */
  96public final class OBJLexicalRoot extends NATByCopy {
  97	
  98	/**
  99	 * The singleton instance of the sentinel lexical root
 100	 */
 101	static public final OBJLexicalRoot _INSTANCE_ = new OBJLexicalRoot();
 102	
 103	/**
 104	 * Constructor made private for singleton design pattern
 105	 */
 106	private OBJLexicalRoot() { }
 107	
 108	/**
 109	 * The lexical root has a special lexical parent object which ends the recursion
 110	 * along the lexical lookup chain. These methods cannot be implemented
 111	 * directly in this class because this class still implements useful
 112	 * <tt>base_</tt> Java methods which have to be invoked by means of the
 113	 * implementations defined in {@link NativeATObject}.
 114	 */
 115	private final NativeATObject lexicalSentinel_ = new NATByCopy() {
 116		// METHODS THAT END THE LEXICAL LOOKUP CHAIN
 117		
 118		public ATObject impl_callAccessor(ATSymbol selector, ATTable arguments) throws InterpreterException {
 119			throw new XUndefinedSlot("variable access", selector.toString());
 120		}
 121
 122		public ATObject impl_callMutator(ATAssignmentSymbol selector, ATTable arguments) throws InterpreterException {
 123			throw new XUnassignableField(selector.toString());
 124		}	
 125		
 126		public ATObject impl_callField(ATSymbol selector) throws InterpreterException {
 127			throw new XUndefinedSlot("variable access", selector.toString());
 128		}
 129		
 130		public ATClosure impl_lookupAccessor(final ATSymbol selector) throws InterpreterException {
 131			throw new XUndefinedSlot("accessor", selector.toString());
 132		}
 133
 134		public ATClosure impl_lookupMutator(ATAssignmentSymbol selector) throws InterpreterException {
 135			throw new XUnassignableField(selector.toString());
 136		}
 137
 138		public NATText meta_print() throws InterpreterException {
 139			return NATText.atValue("lexicalrootsentinel");
 140		}
 141	};
 142	
 143	public ATObject impl_lexicalParent() {
 144		return lexicalSentinel_;
 145	}
 146	
 147	/* -----------------------
 148	 * -- Primitive Methods --
 149	 * ----------------------- */
 150	
 151	/* ===============================================================================
 152	 * NOTE: the code below has been replaced by dedicated syntax and AST elements.
 153	 * However, the skeleton of this code may still prove useful in the future, if
 154	 * we ever plan to implement all base_ native methods as true AmbientTalk methods
 155	 * (i.e. as PrimitiveMethod instances).
 156	 * ===============================================================================
 157	 */
 158	
 159	
 160	/*
 161	private static final AGSymbol _IMPORT_NAME_ = AGSymbol.jAlloc("import:");
 162	private static final AGSymbol _IMPORT_ALIAS_NAME_ = AGSymbol.jAlloc("import:alias:");
 163	private static final AGSymbol _IMPORT_EXCLUDE_NAME_ = AGSymbol.jAlloc("import:exclude:");
 164	private static final AGSymbol _IMPORT_ALIAS_EXCLUDE_NAME_ = AGSymbol.jAlloc("import:alias:exclude:");
 165	
 166	private static final AGSymbol _SRC_PARAM_ = AGSymbol.jAlloc("sourceObject");
 167	private static final AGSymbol _ALIAS_PARAM_ = AGSymbol.jAlloc("aliases");
 168	private static final AGSymbol _EXCLUDE_PARAM_ = AGSymbol.jAlloc("exclude");
 169	*/
 170	
 171	
 172	/*protected static final PrimitiveMethod _PRIM_IMPORT_ = new PrimitiveMethod(_IMPORT_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_ })) {
 173		public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
 174			  ATObject sourceObject = arguments.base_at(NATNumber.ONE);
 175			  return performImport(sourceObject, ctx, new Hashtable(), OBJLexicalRoot.getDefaultExcludedSlots());
 176		}
 177	};*/
 178	
 179	/**
 180	 * def import: sourceObject alias: [ `oldname -> `newname , ... ]
 181	 */
 182	/*protected static final PrimitiveMethod _PRIM_IMPORT_ALIAS_ = new PrimitiveMethod(_IMPORT_ALIAS_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_, _ALIAS_PARAM_ })) {
 183		public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
 184			  ATObject sourceObject = arguments.base_at(NATNumber.ONE);
 185			  ATObject aliases = arguments.base_at(NATNumber.atValue(2));
 186			  return performImport(sourceObject, ctx, preprocessAliases(aliases.base_asTable()), OBJLexicalRoot.getDefaultExcludedSlots());
 187		}
 188	};*/
 189	
 190	/**
 191	 * def import: sourceObject excludes: [ `name1, `name2, ... ]
 192	 */
 193	/*protected static final PrimitiveMethod _PRIM_IMPORT_EXCLUDE_ = new PrimitiveMethod(_IMPORT_EXCLUDE_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_, _EXCLUDE_PARAM_ })) {
 194		public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
 195			  ATObject sourceObject = arguments.base_at(NATNumber.ONE);
 196			  ATObject exclusions = arguments.base_at(NATNumber.atValue(2));
 197			  return performImport(sourceObject, ctx, new Hashtable(), preprocessExcludes(exclusions.base_asTable()));
 198		}
 199	};*/
 200	
 201	/**
 202	 * def import: sourceObject alias: [ `oldname -> `newname, ... ] excludes: [ `name1, `name2, ... ]
 203	 */
 204	/*protected static final PrimitiveMethod _PRIM_IMPORT_ALIAS_EXCLUDE_ = new PrimitiveMethod(_IMPORT_ALIAS_EXCLUDE_NAME_,
 205			                                                                                 NATTable.atValue(new ATObject[] { _SRC_PARAM_, _ALIAS_PARAM_, _EXCLUDE_PARAM_ })) {
 206		public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
 207			  ATObject sourceObject = arguments.base_at(NATNumber.ONE);
 208			  ATObject aliases = arguments.base_at(NATNumber.atValue(2));
 209			  ATObject exclusions = arguments.base_at(NATNumber.atValue(3));
 210			  return performImport(sourceObject, ctx, preprocessAliases(aliases.base_asTable()), preprocessExcludes(exclusions.base_asTable()));
 211		}
 212	};*/
 213	
 214	/**
 215	 * Invoked whenever a new true AmbientTalk object is created that should
 216	 * represent the root. This gives the lexical root a chance to install its
 217	 * primitive methods.
 218	 */
 219	/*public static void initializeRoot(NATObject root) {
 220		try {
 221			// add import: native
 222			root.meta_addMethod(_PRIM_IMPORT_);
 223			// add import:alias: native
 224			root.meta_addMethod(_PRIM_IMPORT_ALIAS_);
 225			// add import:exclude: native
 226			root.meta_addMethod(_PRIM_IMPORT_EXCLUDE_);
 227			// add import:alias:exclude: native
 228			root.meta_addMethod(_PRIM_IMPORT_ALIAS_EXCLUDE_);
 229		} catch (InterpreterException e) {
 230			Logging.Init_LOG.fatal("Failed to initialize the root!", e);
 231		}
 232	}*/
 233	
 234	/* ----------------------
 235	 * -- Global variables --
 236	 * ---------------------- */
 237	
 238	/**
 239	 * <tt>nil</tt> evaluates to the nil object, which is
 240	 * the empty, dynamic parent of all AmbientTalk objects. 
 241	 */
 242	public ATNil base_nil() {
 243		return Evaluator.getNil();
 244	}
 245	
 246	/**
 247	 * <tt>true</tt> evaluates to the unique boolean true object.
 248	 */
 249	public ATBoolean base_true() {
 250		return NATBoolean._TRUE_;
 251	}
 252	
 253	/**
 254	 * <tt>false</tt> evaluates to the unique boolean false object.
 255	 */
 256	public ATBoolean base_false() {
 257		return NATBoolean._FALSE_;
 258	}
 259	
 260	/**
 261	 * <tt>/</tt> evaluates to the global namespace. It is
 262	 * simply an alias for <tt>lobby</tt>.
 263	 * @see #base_lobby()
 264	 */
 265	public ATObject base__opdiv_() {
 266		return base_lobby();
 267	}
 268	
 269	/**
 270	 * <tt>lobby</tt> evaluates to the global namespace object.
 271	 * For each <tt>name=path</tt> entry on AmbientTalk's
 272	 * <i>object path</i>, the lobby object contains a slot
 273	 * <tt>name</tt> bound to a namespace object bound to
 274	 * the directory referred to by <tt>path</tt>.
 275	 * <p>
 276	 * Accessing the lobby allows loading in AmbientTalk source code
 277	 * from external files.
 278	 */
 279	public ATObject base_lobby() {
 280		return Evaluator.getLobbyNamespace();
 281	}
 282	
 283	/**
 284	 * <tt>root</tt> evaluates to the global lexical scope object.
 285	 * This is the top-level object in which the definitions of
 286	 * the file <tt>at/init/init.at</tt> are evaluated. All code
 287	 * is assumed to be "nested" in the lexical root, so all definitions
 288	 * of this object are lexically accessible.
 289	 */
 290	public ATObject base_root() {
 291		return Evaluator.getGlobalLexicalScope();
 292	}
 293	
 294	/**
 295	 * <tt>jlobby</tt> evaluates to the Java namespace root. It is a
 296	 * special object which is part of the symbiosis infrastructure of
 297	 * AmbientTalk. <tt>jlobby</tt> acts like an object that has field
 298	 * names that correspond to Java package names. By selecting fields
 299	 * from this object, an appropriate Java package can be created
 300	 * from which a Java class can be accessed. Only the Java classes
 301	 * accessible in the Java classpath are accessible.
 302	 * 
 303	 * Example:
 304	 * <code>jlobby.java.util.Vector</code> evaluates to a reference to
 305	 * the Java <tt>Vector</tt> class.
 306	 */
 307	public ATObject base_jlobby() {
 308		return Evaluator.getJLobbyRoot();
 309	}
 310
 311	/**
 312	 * <tt>network</tt> evaluates to the unique network control object.
 313	 * It is a simple native object with two methods:
 314	 * <ul>
 315	 *  <li><tt>network.online()</tt> makes the interpreter go online. This allows
 316	 *  publications of local actors to be discovered by remote objects and vice versa.
 317	 *  <li><tt>network.offline()</tt> makes the interpreter go offline. All
 318	 *  remote references to remote objects will become disconnected.
 319	 * </ul>
 320	 */
 321	public ATObject base_network() {
 322		return OBJNetwork._INSTANCE_;
 323	}
 324	
 325	/**
 326	 * <tt>defaultMirror</tt> evaluates to the default mirror on objects. This
 327	 * is the mirror encapsulating the standard AmbientTalk object semantics.
 328	 * That is, it is a mirror with similar behaviour as the mirror created by
 329	 * executing: <code>reflect: (object: { ... })</code>.
 330	 * 
 331	 * The default mirror is an object with a read-only <tt>base</tt> field
 332	 * that signifies the base-level object of this mirror. The main purpose
 333	 * of this object is to serve as a prototype whose methods can be overridden
 334	 * by custom mirrors. The syntax:
 335	 * <pre>
 336	 * mirror: { ... }
 337	 * </pre>
 338	 * is syntactic sugar for:
 339	 * <pre>
 340	 * extend: defaultMirror with: { ... }
 341	 * </pre>
 342	 * 
 343	 * Note that the default mirror is typed with the <tt>/.at.types.Mirror</tt> type.
 344	 */
 345	public ATObject base_defaultMirror() {
 346		return Evaluator.getMirrorRoot();
 347	}
 348	
 349	/* ------------------------
 350	 * -- Control Structures --
 351	 * ------------------------ */
 352	
 353	/**
 354	 * The <tt>if:then:</tt> control structure. Usage:
 355	 *  <pre>if: cond then: consequent</pre>
 356	 * 
 357	 * pseudo-implementation:
 358	 * <pre>cond.ifTrue: consequent</pre>
 359	 * 
 360	 * Note that the consequent parameter should be a <i>closure</i>, i.e.
 361	 * the caller is responsible for delaying the evaluation of the consequent!
 362	 * 
 363	 * @param cond a boolean object
 364	 * @param consequent a closure containing the code to execute if the boolean is true
 365	 * @return if <tt>cond</tt> is true, the value of applying the consequent, <tt>nil</tt> otherwise
 366	 */
 367	public ATObject base_if_then_(ATBoolean cond, ATClosure consequent) throws InterpreterException {
 368		return cond.base_ifTrue_(consequent);
 369	}
 370	
 371	/**
 372	 * The <tt>if:then:else:</tt> control structure. Usage:
 373	 *  <pre>if: cond then: consequent else: alternative</pre>
 374	 * 
 375	 * pseudo-implementation:
 376	 * <pre>cond.ifTrue: consequent ifFalse: alternative</pre>
 377	 * 
 378	 * Note that the consequent and alternative parameters should be <i>closures</i>, i.e.
 379	 * the caller is responsible for delaying the evaluation of these arguments!
 380	 * 
 381	 * @param cond a boolean object
 382	 * @param consequent a closure containing the code to execute if the boolean is true
 383	 * @param alternative a closure containing the code to execute if the boolean is false
 384	 * @return the value of consequent if the boolean is true, the value of the alternative otherwise.
 385	 */
 386	public ATObject base_if_then_else_(ATBoolean cond, ATClosure consequent, ATClosure alternative) throws InterpreterException {
 387		return cond.base_ifTrue_ifFalse_(consequent, alternative);
 388	}
 389	
 390	/**
 391	 * The <tt>while:do:</tt> control structure. Usage:
 392	 * <pre>while: condition do: body</pre>
 393	 * 
 394	 * pseudo-implementation:
 395	 * <pre>condition.whileTrue: body</pre>
 396	 * 
 397	 * Note that <i>both</i> the condition and the body should be <i>closures</i>, because
 398	 * they represent pieces of code that have to be executed repeatedly. Because of traditional
 399	 * syntax, novice programmers are inclined to make the mistake of writing, e.g.:
 400	 * <pre>while: (i < 10) do: { i := i + 1 }</pre>
 401	 * Which is wrong because the first parameter should evaluate to a closure that itself
 402	 * returns a boolean value, not to a boolean value directly.
 403	 * 
 404	 * @param condition a closure expected to return a boolean object
 405	 * @param body a closure containing the code to execute as long as the condition closure returns true
 406	 * @return if conditions is true at least once, the last value of body, <tt>nil</tt> otherwise.
 407	 */
 408	public ATObject base_while_do_(ATClosure condition, ATClosure body) throws InterpreterException {
 409		return condition.base_whileTrue_(body);
 410	}
 411	
 412	/**
 413	 * The <tt>foreach:in:</tt> control structure. Usage:
 414	 * 
 415	 * <pre>foreach: body in: table</pre>
 416	 * 
 417	 * pseudo-implementation:
 418	 * <pre>table.each: body</pre>
 419	 * 
 420	 * Example: <code>[1,2,3].each: { |i| system.println(i) }</code>
 421	 * 
 422	 * @param body a one-arity closure that is to be applied to each element of the table
 423	 * @param tab a table to apply the body closure to
 424	 * @return <tt>nil</tt>, by default
 425	 */
 426	public ATObject base_foreach_in_(ATClosure body, ATTable tab) throws InterpreterException {
 427		return tab.base_each_(body);
 428	}
 429
 430	/**
 431	 * The <tt>do:if:</tt> control structure. Usage:
 432	 * <pre>do: body if: condition</pre>
 433	 * 
 434	 * pseudo-implementation:
 435	 * <pre>condition.ifTrue: body</pre>
 436	 *
 437	 * In Ruby, this kind of control structure is called a <i>statement modifier</i>.
 438	 * 
 439	 * @param body a zero-argument closure to execute if the condition is true
 440	 * @param condition a boolean value
 441	 * @return the result of invoking body if the condition is true or nil if the
 442	 * condition is false
 443	 */
 444	public ATObject base_do_if_(ATClosure body, ATBoolean condition) throws InterpreterException {
 445		return condition.base_ifTrue_(body);
 446	}
 447	
 448	/**
 449	 * The <tt>do:unless:</tt> control structure. Usage:
 450	 * <pre>do: body unless: condition</pre>
 451	 * 
 452	 * pseudo-implementation:
 453	 * <pre>condition.ifFalse: body</pre>
 454	 *
 455	 * In Ruby, this kind of control structure is called a <i>statement modifier</i>.
 456	 * Example: <code>do: { file.close() } unless: (nil == file)</code>
 457	 * 
 458	 * @param body a zero-argument closure to execute only if the condition is false
 459	 * @param condition a boolean value
 460	 * @return the result of invoking body if the condition is false, nil otherwise
 461	 */
 462	public ATObject base_do_unless_(ATClosure body, ATBoolean condition) throws InterpreterException {
 463		return condition.base_ifFalse_(body);
 464	}
 465	
 466	/**
 467	 * The <tt>let:</tt> construct. Usage:
 468	 * <pre>let: { |var := value| body }</pre>
 469	 * 
 470	 * pseudo-implementation:
 471	 * <pre>closure()</pre>
 472	 * 
 473	 * <tt>let:</tt> allows for the easy creation of temporary local variables.
 474	 * This construct should be used in conjunction with a closure that declares optional
 475	 * parameters. Because the closure will be invoked with zero arguments, all of the
 476	 * parameters will be given their corresponding default initial value. The parameters
 477	 * are defined local to the closure's body.
 478	 * 
 479	 * AmbientTalk's <tt>let:</tt> behaves like Scheme's <tt>let*</tt> and <tt>letrec</tt>,
 480	 * i.e. the following is legal:
 481	 * <pre>let: {
 482	 *  |var1 := value1,
 483	 *   var2 := var1,
 484	 *   var3 := { ... var3() ... }|
 485	 *  ...
 486	 *}</pre>
 487	 * 
 488	 * @param body a closure which is supposed to declare some optional parameters
 489	 * @return the result of invoking the body closure
 490	 */
 491	public ATObject base_let_(ATClosure body) throws InterpreterException {
 492		return body.base_apply(NATTable.EMPTY);
 493	}
 494	
 495	/* ------------------------------------------
 496	 * -- Actor Creation and accessing Methods --
 497	 * ------------------------------------------ */
 498	
 499	/**
 500	 * The <tt>actor: closure</tt> construct.
 501	 *  
 502	 * The semantics of actor creation is as follows:
 503	 * <ul>
 504	 *  <li> Mandatory parameters to the block of initialization code are treated as lexically visible
 505	 *   variables that have to remain available in the new actor behaviour. Hence, these variables
 506	 *   are evaluated to values immediately at creation-time and parameter-passed to the new actor.
 507	 *  <li> The closure containing the initialization code is unpacked, its lexical scope is disregarded
 508	 *   and the unwrapped method is serialized and sent to the new actor, which can use it to
 509	 *   initialize his behaviour object.
 510	 *  <li>The creating actor waits for the created actor to spawn a new behaviour and to return a far
 511	 *   reference to this behaviour. From that point on, the creating actor can run in parallel with
 512	 *   the created actor, which only then evaluates the initialization code to initialize its behaviour.
 513	 * </ul>
 514	 * 
 515	 * @param closure the closure whose parameters define lexical fields to be copied and whose
 516	 * method specifies the code of the new actor's behaviour object
 517	 * @return a far reference to the behaviour of the new actor
 518	 */
 519	public ATObject base_actor_(ATClosure closure) throws InterpreterException {
 520		ATMethod method = closure.base_method();
 521		ATObject copiedBindings;
 522
 523		// if no variables were specified to pass along to the new actor, calculate the
 524		// set of free variables for the actor
 525		if (method.base_parameters().base_isEmpty().asNativeBoolean().javaValue) {
 526			// introduce a private scope object that will hold copies
 527			// of the lexically free variables of the actor
 528			copiedBindings = new NATObject(OBJLexicalRoot._INSTANCE_, new ATTypeTag[] { NativeTypeTags._ISOLATE_ });
 529			
 530			// calculate the set of free variables of the initialization expression
 531			Set freeVars = method.base_bodyExpression().impl_freeVariables();
 532			// add all these free variables manually as fields to a custom 
 533			Iterator it = freeVars.iterator();
 534			while (it.hasNext()) {
 535				ATSymbol freeVar = (ATSymbol) it.next();
 536				
 537				// extra check to weed out special variables like "super" and variables available in the lexical root
 538				if (! (Evaluator.getGlobalLexicalScope().meta_respondsTo(freeVar).asNativeBoolean().javaValue
 539				      || OBJLexicalRoot._INSTANCE_.meta_respondsTo(freeVar).asNativeBoolean().javaValue)) {
 540
 541					// lookup the variable in the lexical scope
 542					try {
 543						ATClosure accessor = closure.base_context().base_lexicalScope().impl_lookup(freeVar);
 544						// only add the variable if it refers to a field, rather than to a method
 545						if (accessor instanceof NativeClosure.Accessor) {
 546							copiedBindings.meta_defineField(freeVar, accessor.base_apply(NATTable.EMPTY));
 547						}
 548					} catch(XUndefinedSlot exc) {
 549						// silently ignore lexically free variables which cannot be found
 550						// the assumption is that these variables will be bound by means of
 551						// import statements
 552						Logging.Actor_LOG.warn("Undefined lexically free var while constructing actor: "+exc.getFieldName());
 553					}
 554				}
 555			}
 556		} else {
 557			copiedBindings = Evaluator.evalMandatoryPars(
 558					method.base_parameters(),
 559					closure.base_context());
 560		}
 561		
 562		Packet serializedBindings = new Packet("actor-bindings", copiedBindings);
 563		Packet serializedInitCode = new Packet("actor-initcode", method);
 564		return ELVirtualMachine.currentVM().createActor(serializedBindings, serializedInitCode);
 565	}
 566	
 567	/**
 568	 * <tt>reflectOnActor</tt> evaluates to the mirror on the actor executing this code.
 569	 * The actor mirror is an object whose behaviour is consulted for operations
 570	 * such as creating and sending asynchronous messages or creating mirrors on
 571	 * other objects. It can be replaced by a custom mirror by means of the actor
 572	 * mirror's <tt>getExplicitActorMirror</tt> method.
 573	 */
 574	public ATActorMirror base_reflectOnActor() throws InterpreterException {
 575		return ELActor.currentActor().getImplicitActorMirror().base_getExplicitActorMirror();
 576	}
 577	
 578	/**
 579	 * The <tt>export: object as: topic</tt> construct. Pseudo-implementation:
 580	 * <pre>actor.provide(topic, object)</pre>
 581	 * 
 582	 * This construct enables the given object to become discoverable by objects
 583	 * in other actors by means of the topic type.
 584	 * 
 585	 * @param object the object to export to remote actors' objects
 586	 * @param topic a type denoting the abstract 'publication topic' for this object's publication
 587	 * @return a publication object whose <tt>cancel</tt> method can be used to cancel the publication.
 588	 */
 589	public ATObject base_export_as_(ATObject object, ATTypeTag topic) throws InterpreterException {
 590		return ELActor.currentActor().getImplicitActorMirror().base_provide(topic, object);
 591	}
 592	
 593	/**
 594	 * The <tt>when: topic discovered: handler</tt> construct. Pseudo-implementation:
 595	 * <pre>actor.require(topic, handler, false)</pre>
 596	 * 
 597	 * When an object is exported by <i>another</i> actor under topic, this construct triggers
 598	 * the given code, passing a reference to the exported object as argument to the closure.
 599	 * 
 600	 * Once the code block has run once, it will not be triggered again.
 601	 * 
 602	 * @param topic the abstract 'subscription topic' used to find an exported object
 603	 * @param handler a one-argument closure to apply to a discovered exported object
 604	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel the subscription,
 605	 * such that the handler will no longer be invoked. Beware, however, that at the time the
 606	 * subscription is cancelled, a request to apply the closure may already have been scheduled
 607	 * for execution by the current actor. This request is not cancelled by invoking the <tt>cancel</tt> method.
 608	 */
 609	public ATObject base_when_discovered_(ATTypeTag topic, ATClosure handler) throws InterpreterException {
 610		return ELActor.currentActor().getImplicitActorMirror().base_require(topic, handler, NATBoolean._FALSE_);
 611	}
 612	
 613	/**
 614	 * The <tt>whenever: topic discovered: handler</tt> construct. Pseudo-implementation:
 615	 * <pre>actor.require(topic, handler, true)</pre>
 616	 * 
 617	 * When an object is exported by <i>another</i> actor under topic, this construct triggers
 618	 * the given code, passing a reference to the exported object as argument to the closure.
 619	 * 
 620	 * The code block can be fired multiple times upon discovering multiple exported objects.
 621	 * To stop the block from triggering upon new publications, it must be explicitly cancelled
 622	 * 
 623	 * @param topic the abstract 'subscription topic' used to find an exported object
 624	 * @param handler a one-argument closure to apply to any discovered exported object
 625	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel the subscription,
 626	 * such that the handler will no longer be invoked. Beware, however, that at the time the
 627	 * subscription is cancelled, a request to apply the closure may already have been scheduled
 628	 * for execution by the current actor. This request is not cancelled by invoking the <tt>cancel</tt> method.
 629	 */
 630	public ATObject base_whenever_discovered_(ATTypeTag topic, ATClosure handler) throws InterpreterException {
 631		return ELActor.currentActor().getImplicitActorMirror().base_require(topic, handler, NATBoolean._TRUE_);
 632	}
 633	
 634	/**
 635	 * The <tt>whenever: farReference disconnected: listener</tt> construct.
 636	 * When the far reference is broken due to network disconnections, triggers the zero-arity listener
 637	 * closure. It is possible to register listeners on local far references. These may trigger if the
 638	 * local actor takes its object offline. In this case, these listeners will trigger as well.
 639	 * 
 640	 * @param farReference a native far reference
 641	 * @param listener a zero-arity closure to invoke if the far reference becomes disconnected
 642	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
 643	 * notifications of the listener.
 644	 */
 645	public ATObject base_whenever_disconnected_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
 646		farReference.asNativeFarReference().addDisconnectionListener(listener);
 647		return new NATFarReference.NATDisconnectionSubscription(farReference.asNativeFarReference(), listener);
 648	}
 649	
 650	/**
 651	 * The <tt>whenever: farReference reconnected: listener</tt> construct.
 652	 * When the remote reference is reinstated after a network disconnection, trigger the zero-arity
 653	 * listener. Although it is allowed to register these listeners on local far references,
 654	 * these are normally not invoked because the only possibility for a local far ref to become
 655	 * disconnected is because the object was taken offline, and this is a permanent disconnect.
 656	 * 
 657	 * @param farReference a native far reference
 658	 * @param listener a zero-arity closure to invoke if the far reference becomes reconnected
 659	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
 660	 * notifications of the listener.
 661	 */
 662	public ATObject base_whenever_reconnected_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
 663		farReference.asNativeFarReference().addReconnectionListener(listener);
 664		return new NATFarReference.NATReconnectionSubscription(farReference.asNativeFarReference(), listener);
 665	}
 666	
 667	/**
 668	 * The <tt>when: farReference takenOffline:</tt> construct.
 669	 *  When the (remote/local) far reference is broken because the object referenced was 
 670	 *  taken offline, trigger the code.
 671	 *  
 672	 * @param farReference a native far reference
 673	 * @param listener a zero-arity closure to invoke if the referenced object has been taken offline.
 674	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
 675	 * notifications of the listener.
 676	 */
 677	public ATObject base_when_takenOffline_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
 678		farReference.asNativeFarReference().addTakenOfflineListener(listener);
 679		return new NATFarReference.NATExpiredSubscription(farReference.asNativeFarReference(), listener);
 680	}
 681	
 682
 683	/**
 684	 * The <tt>retract: farReference</tt> construct. 
 685	 * Retracts all currently unsent messages from the far reference's outbox.
 686	 * This has the side effect that the returned messages will <b>not</b> be sent
 687	 * automatically anymore, the programmer is responsible to explicitly resend
 688	 * all messages that were retracted but still need to be sent.
 689	 *  
 690	 * Note that the returned messages are copies of the original.
 691	 * @param farReference the far reference of which to retract outgoing message sends
 692	 * @return a table containing copies of all messages that were sent to this far reference, but
 693	 * not yet transmitted by the far reference to its referent.
 694	 */
 695	public ATTable base_retract_(ATFarReference farReference) throws InterpreterException {
 696		return farReference.meta_retractUnsentMessages();
 697	}
 698	
 699	/* -----------------------------
 700	 * -- Object Creation Methods --
 701	 * ----------------------------- */
 702	
 703	/**
 704	 * The <tt>object:</tt> object creation primitive.
 705	 * This construct creates a new AmbientTalk object where:
 706	 * <ul>
 707	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 708	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 709	 *  <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
 710	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 711	 *  <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
 712	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 713	 *  with a 'native' metaobject protocol).
 714	 * </ul>
 715	 * 
 716	 * Example: <code>object: { def x := 1; }</code>
 717	 * <p>
 718	 * Pseudo-implementation:
 719	 * <pre>object: code childOf: nil extends: false taggedAs: [] mirroredBy: defaultMirror</pre>
 720	 * 
 721	 * The closure used to initialize the object may contain formal parameters. The closure
 722	 * will always be invoked with <i>its own mandatory formal parameters</i>. E.g., a closure
 723	 * <code>{ |x| nil }</code> is invoked as <code>{ |x| nil }(x)</code>. The net effect of this
 724	 * mechanic is that if <tt>x</tt> is a lexically visible variable at the object-creation
 725	 * site, the value of the variable will be copied into a copy with the same name which
 726	 * resides in the newly created object. This mechanic is primarily useful for copying surrounding
 727	 * variables within the object, e.g. for isolates which lose access to their surrounding scope.
 728	 * <p>
 729	 * Also, if the closure has optional parameters, they will always be triggered.
 730	 * The expressions to initialize the formal parameters are <i>evaluated</i>
 731	 * in the context of the closure's lexical scope but are <i>added</i> to the newly created object.
 732	 * 
 733	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
 734	 * @return a new AmbientTalk object with the properties defined above.
 735	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 736	 */
 737	public ATObject base_object_(ATClosure code) throws InterpreterException {
 738		return base_object_childOf_extends_taggedAs_mirroredBy_(
 739				code,
 740				Evaluator.getNil(),
 741				NATBoolean._FALSE_ /* SHARES-A link */,
 742				NATTable.EMPTY,
 743				base_defaultMirror());
 744	}
 745	
 746	/**
 747	 * The <tt>extend:with:</tt> object creation primitive.
 748	 * This construct creates a new AmbientTalk object where:
 749	 * <ul>
 750	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 751	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 752	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 753	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
 754	 *  <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
 755	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 756	 *  with a 'native' metaobject protocol).
 757	 * </ul>
 758	 * 
 759	 * Example: <code>extend: parent with: { def x := 1; }</code>
 760	 * <p>
 761	 * Pseudo-implementation:
 762	 * <pre>object: code childOf: parent extends: true taggedAs: [] mirroredBy: defaultMirror</pre>
 763	 * 
 764	 * @param parent the dynamic parent object of the newly created object.
 765	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
 766	 * @return a new AmbientTalk object with the properties defined above.
 767	 * @see #base_object_(ATClosure)
 768	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 769	 */
 770	public ATObject base_extend_with_(ATObject parent, ATClosure code) throws InterpreterException {
 771		return base_object_childOf_extends_taggedAs_mirroredBy_(
 772				code,
 773				parent,
 774				NATBoolean._TRUE_ /* IS-A link */,
 775				NATTable.EMPTY,
 776				base_defaultMirror());
 777	}
 778	
 779    /**
 780     * The <tt>extend:with:taggedAs:</tt> object creation primitive.
 781	 * This construct creates a new AmbientTalk object where:
 782	 * <ul>
 783	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 784	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 785	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 786	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
 787	 *  <li>The object's <b>types</b> are initialized to the argument types table.
 788	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 789	 *  with a 'native' metaobject protocol).
 790	 * </ul>
 791	 * 
 792	 * Example: <code>extend: parent with: { def x := 1; } taggedAs: [foo,bar]</code>
 793	 * <p>
 794	 * Pseudo-implementation:
 795	 * <pre>object: code childOf: parent extends: true taggedAs: types mirroredBy: defaultMirror</pre>
 796	 * 
 797	 * @param parent the dynamic parent object of the newly created object.
 798	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 799	 * @param types a table of types with which to type the newly created object.
 800	 * @return a new AmbientTalk object with the properties defined above.
 801	 * @see #base_object_(ATClosure)
 802	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 803	 */
 804	public ATObject base_extend_with_taggedAs_(ATObject parent, ATClosure code, ATTable types) throws InterpreterException {
 805		return base_object_childOf_extends_taggedAs_mirroredBy_(
 806				code,
 807				parent,
 808				NATBoolean._TRUE_ /* IS-A link */,
 809				types,
 810				base_defaultMirror());
 811	}
 812	
 813    /**
 814     * The <tt>extend:with:mirroredBy:</tt> object creation primitive.
 815	 * This construct creates a new AmbientTalk object where:
 816	 * <ul>
 817	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 818	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 819	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 820	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
 821	 *  <li>The object's <b>types</b> are set to <tt>[]</tt> (i.e. the object has no types).
 822	 *  <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
 823	 *  whose metaobject protocol is entirely dictated by the given mirror.
 824	 * </ul>
 825	 * 
 826	 * Example: <code>extend: parent with: { def x := 1; } mirroredBy: (mirror: {...})</code>
 827	 * <p>
 828	 * Pseudo-implementation:
 829	 * <pre>object: code childOf: parent extends: true taggedAs: [] mirroredBy: mirror</pre>
 830	 * 
 831	 * @param parent the dynamic parent object of the newly created object.
 832	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 833	 * @param mirror the mirror of the newly created mirage object.
 834	 * @return a new AmbientTalk object with the properties defined above.
 835	 * @see #base_object_(ATClosure)
 836	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 837	 */
 838	public ATObject base_extend_with_mirroredBy_(ATObject parent, ATClosure code, ATObject mirror) throws InterpreterException {
 839		return base_object_childOf_extends_taggedAs_mirroredBy_(
 840				code,
 841				parent,
 842				NATBoolean._TRUE_ /* IS-A link */,
 843				NATTable.EMPTY,
 844				mirror);
 845	}
 846	
 847    /**
 848     * The <tt>extend:with:taggedAs:mirroredBy:</tt> object creation primitive.
 849	 * This construct creates a new AmbientTalk object where:
 850	 * <ul>
 851	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 852	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 853	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 854	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
 855	 *  <li>The object's <b>types</b> are initialized to the argument types table.
 856	 *  <li>The object's <b>mirror</b> is the given argument mirror. This means that the newly
 857	 *  created object is a <i>mirage</i> whose metaobject protocol is dictated by the given mirror.
 858	 * </ul>
 859	 * 
 860	 * Example: <code>extend: parent with: { def x := 1; } taggedAs: [foo,bar] mirroredBy: mirror</code>
 861	 * <p>
 862	 * Pseudo-implementation:
 863	 * <pre>object: code childOf: parent extends: true taggedAs: types mirroredBy: mirror</pre>
 864	 * 
 865	 * @param parent the dynamic parent object of the newly created object.
 866	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 867	 * @param types a table of types with which to type the newly created object.
 868	 * @param the mirror object of the newly created mirage object.
 869	 * @return a new AmbientTalk object with the properties defined above.
 870	 * @see #base_object_(ATClosure)
 871	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 872	 */
 873	public ATObject base_extend_with_taggedAs_mirroredBy_(ATObject parent, ATClosure code, ATTable types, ATObject mirror) throws InterpreterException {
 874		return base_object_childOf_extends_taggedAs_mirroredBy_(
 875				code,
 876				parent,
 877				NATBoolean._TRUE_ /* IS-A link */,
 878				types,
 879				mirror);
 880	}
 881	
 882	/**
 883	 * The <tt>share:with:</tt> object creation primitive.
 884	 * This construct creates a new AmbientTalk object where:
 885	 * <ul>
 886	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 887	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 888	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 889	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 890	 *  <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
 891	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 892	 *  with a 'native' metaobject protocol).
 893	 * </ul>
 894	 * 
 895	 * Example: <code>share: parent with: { def x := 1; }</code>
 896	 * <p>
 897	 * Pseudo-implementation:
 898	 * <pre>object: code childOf: parent extends: false taggedAs: [] mirroredBy: defaultMirror</pre>
 899	 * 
 900	 * @param parent the dynamic parent object of the newly created object.
 901	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
 902	 * @return a new AmbientTalk object with the properties defined above.
 903	 * @see #base_object_(ATClosure)
 904	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 905	 */
 906	public ATObject base_share_with_(ATObject parent, ATClosure code) throws InterpreterException {
 907		return base_object_childOf_extends_taggedAs_mirroredBy_(
 908				code,
 909				parent,
 910				NATBoolean._FALSE_ /* SHARES-A link */,
 911				NATTable.EMPTY,
 912				base_defaultMirror());
 913	}
 914
 915    /**
 916     * The <tt>share:with:taggedAs:</tt> object creation primitive.
 917	 * This construct creates a new AmbientTalk object where:
 918	 * <ul>
 919	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 920	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 921	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 922	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 923	 *  <li>The object's <b>types</b> are initialized to the argument types table.
 924	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 925	 *  with a 'native' metaobject protocol).
 926	 * </ul>
 927	 * 
 928	 * Example: <code>share: parent with: { def x := 1; } taggedAs: [foo,bar]</code>
 929	 * <p>
 930	 * Pseudo-implementation:
 931	 * <pre>object: code childOf: parent extends: false taggedAs: types mirroredBy: defaultMirror</pre>
 932	 * 
 933	 * @param parent the dynamic parent object of the newly created object.
 934	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 935	 * @param types a table of types with which to type the newly created object.
 936	 * @return a new AmbientTalk object with the properties defined above.
 937	 * @see #base_object_(ATClosure)
 938	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 939	 */
 940	public ATObject base_share_with_taggedAs_(ATObject parent, ATClosure code, ATTable types) throws InterpreterException {
 941		return base_object_childOf_extends_taggedAs_mirroredBy_(
 942				code,
 943				parent,
 944				NATBoolean._FALSE_ /* SHARES-A link */,
 945				types,
 946				base_defaultMirror());
 947	}
 948	
 949    /**
 950     * The <tt>share:with:mirroredBy:</tt> object creation primitive.
 951	 * This construct creates a new AmbientTalk object where:
 952	 * <ul>
 953	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 954	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 955	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 956	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 957	 *  <li>The object's <b>types</b> are set to <tt>[]</tt> (i.e. the object has no types).
 958	 *  <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
 959	 *  whose metaobject protocol is entirely dictated by the given mirror.
 960	 * </ul>
 961	 * 
 962	 * Example: <code>share: parent with: { def x := 1; } mirroredBy: (mirror: {...})</code>
 963	 * <p>
 964	 * Pseudo-implementation:
 965	 * <pre>object: code childOf: parent extends: false taggedAs: [] mirroredBy: mirror</pre>
 966	 * 
 967	 * @param parent the dynamic parent object of the newly created object.
 968	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 969	 * @param mirror the mirror of the newly created mirage object.
 970	 * @return a new AmbientTalk object with the properties defined above.
 971	 * @see #base_object_(ATClosure)
 972	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 973	 */
 974	public ATObject base_share_with_mirroredBy_(ATObject parent, ATClosure code, ATObject mirror) throws InterpreterException {
 975		return base_object_childOf_extends_taggedAs_mirroredBy_(
 976				code,
 977				parent,
 978				NATBoolean._FALSE_ /* SHARES-A link */,
 979				NATTable.EMPTY,
 980				mirror);
 981	}
 982	
 983    /**
 984     * The <tt>share:with:taggedAs:mirroredBy:</tt> object creation primitive.
 985	 * This construct creates a new AmbientTalk object where:
 986	 * <ul>
 987	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 988	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 989	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 990	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 991	 *  <li>The object's <b>types</b> are initialized to the argument types table.
 992	 *  <li>The object's <b>mirror</b> is the given argument mirror. This means that the newly
 993	 *  created object is a <i>mirage</i> whose metaobject protocol is dictated by the given mirror.
 994	 * </ul>
 995	 * 
 996	 * Example: <code>share: parent with: { def x := 1; } taggedAs: [foo,bar] mirroredBy: mirror</code>
 997	 * <p>
 998	 * Pseudo-implementation:
 999	 * <pre>object: code childOf: parent extends: false taggedAs: types mirroredBy: mirror</pre>
1000	 * 
1001	 * @param parent the dynamic parent object of the newly created object.
1002	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1003	 * @param types a table of types with which to type the newly created object.
1004	 * @param mirror the mirror object of the newly created mirage object.
1005	 * @return a new AmbientTalk object with the properties defined above.
1006	 * @see #base_object_(ATClosure)
1007	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
1008	 */
1009	public ATObject base_share_with_taggedAs_mirroredBy_(ATObject parent, ATClosure code, ATTable types, ATObject mirror) throws InterpreterException {
1010		return base_object_childOf_extends_taggedAs_mirroredBy_(
1011				code,
1012				parent,
1013				NATBoolean._FALSE_ /* SHARES-A link */,
1014				types,
1015				mirror);
1016	}
1017	
1018    /**
1019     * The <tt>object:taggedAs:</tt> object creation primitive.
1020	 * This construct creates a new AmbientTalk object where:
1021	 * <ul>
1022	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
1023	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
1024	 *  <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
1025	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
1026	 *  <li>The object's <b>types</b> are initialized to the argument types table.
1027	 *  <li>The object's <b>mirror</b> is <tt>defaultMirror</tt> (i.e. the object has the
1028	 *  default metaobject protocol).
1029	 * </ul>
1030	 * 
1031	 * Example: <code>object: { def x := 1; } taggedAs: [foo,bar]</code>
1032	 * <p>
1033	 * Pseudo-implementation:
1034	 * <pre>object: code childOf: nil extends: false taggedAs: types mirroredBy: defaultMirror</pre>
1035	 * 
1036	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1037	 * @param types a table of type tags with which to type the newly created object.
1038	 * @return a new AmbientTalk object with the properties defined above.
1039	 * @see #base_object_(ATClosure)
1040	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
1041	 */
1042	public ATObject base_object_taggedAs_(ATClosure code, ATTable types) throws InterpreterException {
1043		return base_object_childOf_extends_taggedAs_mirroredBy_(
1044				code,
1045				Evaluator.getNil(),
1046				NATBoolean._FALSE_ /* SHARES-A link */,
1047				types,
1048				base_defaultMirror());
1049	}
1050	
1051    /**
1052     * The <tt>isolate:</tt> object creation primitive.
1053	 * This construct creates a new AmbientTalk object where:
1054	 * <ul>
1055	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
1056	 *  <li>The object's <b>lexical parent</b> is initialized to the lexical scope of the argument closure,
1057	 *  but because it is typed as an isolate, the parent link is replaced by a link to the lexical <tt>root</tt>.
1058	 *  <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
1059	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
1060	 *  <li>The object's <b>types</b> are initialized to <tt>[/.at.types.Isolate]</tt>, i.e.
1061	 *  the object is typed as an isolate.
1062	 *  <li>The object's <b>mirror</b> is <tt>defaultMirror</tt> (i.e. the object has the
1063	 *  default metaobject protocol).
1064	 * </ul>
1065	 * 
1066	 * Example: <code>isolate: { def x := 1; }</code>
1067	 * <p>
1068	 * Pseudo-implementation:
1069	 * <pre>object: code childOf: nil extends: false taggedAs: [/.at.types.Isolate] mirroredBy: defaultMirror</pre>
1070	 * 
1071	 * An isolate is an object without a proper lexical parent. It is as if the isolate is always
1072	 * defined at top-level. However, lexically visible variables can be retained by copying them into the isolate
1073	 * by means of formal parameters to the argument closure. Isolate objects are passed b

Large files files are truncated, but you can click here to view the full file