PageRenderTime 125ms CodeModel.GetById 16ms app.highlight 91ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://ambienttalk.googlecode.com/
Java | 2542 lines | 1226 code | 123 blank | 1193 comment | 158 complexity | 9bfdd6fde26521118313086642bb7591 MD5 | raw 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.ATContext;
  46import edu.vub.at.objects.ATHandler;
  47import edu.vub.at.objects.ATMethod;
  48import edu.vub.at.objects.ATNil;
  49import edu.vub.at.objects.ATNumber;
  50import edu.vub.at.objects.ATNumeric;
  51import edu.vub.at.objects.ATObject;
  52import edu.vub.at.objects.ATTable;
  53import edu.vub.at.objects.ATText;
  54import edu.vub.at.objects.ATTypeTag;
  55import edu.vub.at.objects.coercion.NativeTypeTags;
  56import edu.vub.at.objects.grammar.ATAssignmentSymbol;
  57import edu.vub.at.objects.grammar.ATSymbol;
  58import edu.vub.at.objects.mirrors.DirectNativeMethod;
  59import edu.vub.at.objects.mirrors.JavaInterfaceAdaptor;
  60import edu.vub.at.objects.mirrors.NATMirage;
  61import edu.vub.at.objects.mirrors.NATMirrorRoot;
  62import edu.vub.at.objects.mirrors.NativeClosure;
  63import edu.vub.at.parser.NATParser;
  64import edu.vub.at.util.logging.Logging;
  65
  66import java.lang.reflect.Method;
  67import java.util.HashMap;
  68import java.util.Iterator;
  69import java.util.LinkedList;
  70import java.util.List;
  71import java.util.Set;
  72import java.util.Map.Entry;
  73import java.util.concurrent.atomic.AtomicInteger;
  74
  75/**
  76 * The singleton instance of this class represents the lexical root of an actor.
  77 * Since this lexical root is constant (it cannot be modified) and contains no mutable fields,
  78 * it is possible to share a singleton instance of this class among all actors.
  79 * <p>
  80 * The lexical root is an object containing globally visible AmbientTalk native methods.
  81 * Such methods include control structures such as <tt>if:then:else:</tt>
  82 * but also object creation methods like <tt>object:</tt> and reflective constructs
  83 * like <tt>reflect:</tt>.
  84 * 
  85 * Furthermore, the lexical root is also the root of the lexical parent hierarchy for objects.
  86 * This means that this object's mirror is responsible for ending recursive meta-level methods
  87 * such as <tt>lookup</tt> and <tt>assignField</tt>.
  88 * <p>
  89 * Like any class whose instances represent native AmbientTalk objects, this class is a subclass
  90 * of {@link NativeATObject}. This means that this class can use the typical protocol of native objects
  91 * to implement base-level AmbientTalk methods as Java methods whose name is prefixed with
  92 * <tt>base_</tt>.
  93 * <p>
  94 * Note that OBJLexicalRoot is a <i>sentinel</i> class. The actual object bound to the
  95 * lexical root of an actor (accessible via the field <tt>root</tt> will be a normal
  96 * AmbientTalk object whose lexical parent is this object.
  97 * The real, empty, root object is local to each actor and is mutable. The definitions
  98 * from the <tt>init.at</tt> file are added to that object.
  99 * 
 100 * @author smostinc
 101 * @author tvcutsem
 102 */
 103public final class OBJLexicalRoot extends NATByCopy {
 104	
 105	/**
 106	 * The singleton instance of the sentinel lexical root
 107	 */
 108	static public final OBJLexicalRoot _INSTANCE_ = new OBJLexicalRoot();
 109	
 110	/**
 111	 * Constructor made private for singleton design pattern
 112	 */
 113	private OBJLexicalRoot() { }
 114	
 115	/**
 116	 * The lexical root has a special lexical parent object which ends the recursion
 117	 * along the lexical lookup chain. These methods cannot be implemented
 118	 * directly in this class because this class still implements useful
 119	 * <tt>base_</tt> Java methods which have to be invoked by means of the
 120	 * implementations defined in {@link NativeATObject}.
 121	 */
 122	private final NativeATObject lexicalSentinel_ = new NATByCopy() {
 123		// METHODS THAT END THE LEXICAL LOOKUP CHAIN
 124		
 125		public ATObject impl_callAccessor(ATSymbol selector, ATTable arguments) throws InterpreterException {
 126			throw new XUndefinedSlot("variable access", selector.toString());
 127		}
 128
 129		public ATObject impl_callMutator(ATAssignmentSymbol selector, ATTable arguments) throws InterpreterException {
 130			throw new XUnassignableField(selector.toString());
 131		}	
 132		
 133		public ATObject impl_callField(ATSymbol selector) throws InterpreterException {
 134			throw new XUndefinedSlot("variable access", selector.toString());
 135		}
 136		
 137		public ATClosure impl_lookupAccessor(final ATSymbol selector) throws InterpreterException {
 138			throw new XUndefinedSlot("accessor", selector.toString());
 139		}
 140
 141		public ATClosure impl_lookupMutator(ATAssignmentSymbol selector) throws InterpreterException {
 142			throw new XUnassignableField(selector.toString());
 143		}
 144
 145		public NATText meta_print() throws InterpreterException {
 146			return NATText.atValue("lexicalrootsentinel");
 147		}
 148	};
 149	
 150	public ATObject impl_lexicalParent() {
 151		return lexicalSentinel_;
 152	}
 153	
 154	/* -----------------------
 155	 * -- Primitive Methods --
 156	 * ----------------------- */
 157	
 158	/* ===============================================================================
 159	 * NOTE: the code below has been replaced by dedicated syntax and AST elements.
 160	 * However, the skeleton of this code may still prove useful in the future, if
 161	 * we ever plan to implement all base_ native methods as true AmbientTalk methods
 162	 * (i.e. as PrimitiveMethod instances).
 163	 * ===============================================================================
 164	 */
 165	
 166	
 167	/*
 168	private static final AGSymbol _IMPORT_NAME_ = AGSymbol.jAlloc("import:");
 169	private static final AGSymbol _IMPORT_ALIAS_NAME_ = AGSymbol.jAlloc("import:alias:");
 170	private static final AGSymbol _IMPORT_EXCLUDE_NAME_ = AGSymbol.jAlloc("import:exclude:");
 171	private static final AGSymbol _IMPORT_ALIAS_EXCLUDE_NAME_ = AGSymbol.jAlloc("import:alias:exclude:");
 172	
 173	private static final AGSymbol _SRC_PARAM_ = AGSymbol.jAlloc("sourceObject");
 174	private static final AGSymbol _ALIAS_PARAM_ = AGSymbol.jAlloc("aliases");
 175	private static final AGSymbol _EXCLUDE_PARAM_ = AGSymbol.jAlloc("exclude");
 176	*/
 177	
 178	
 179	/*protected static final PrimitiveMethod _PRIM_IMPORT_ = new PrimitiveMethod(_IMPORT_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_ })) {
 180		public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
 181			  ATObject sourceObject = arguments.base_at(NATNumber.ONE);
 182			  return performImport(sourceObject, ctx, new Hashtable(), OBJLexicalRoot.getDefaultExcludedSlots());
 183		}
 184	};*/
 185	
 186	/**
 187	 * def import: sourceObject alias: [ `oldname -> `newname , ... ]
 188	 */
 189	/*protected static final PrimitiveMethod _PRIM_IMPORT_ALIAS_ = new PrimitiveMethod(_IMPORT_ALIAS_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_, _ALIAS_PARAM_ })) {
 190		public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
 191			  ATObject sourceObject = arguments.base_at(NATNumber.ONE);
 192			  ATObject aliases = arguments.base_at(NATNumber.atValue(2));
 193			  return performImport(sourceObject, ctx, preprocessAliases(aliases.base_asTable()), OBJLexicalRoot.getDefaultExcludedSlots());
 194		}
 195	};*/
 196	
 197	/**
 198	 * def import: sourceObject excludes: [ `name1, `name2, ... ]
 199	 */
 200	/*protected static final PrimitiveMethod _PRIM_IMPORT_EXCLUDE_ = new PrimitiveMethod(_IMPORT_EXCLUDE_NAME_, NATTable.atValue(new ATObject[] { _SRC_PARAM_, _EXCLUDE_PARAM_ })) {
 201		public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
 202			  ATObject sourceObject = arguments.base_at(NATNumber.ONE);
 203			  ATObject exclusions = arguments.base_at(NATNumber.atValue(2));
 204			  return performImport(sourceObject, ctx, new Hashtable(), preprocessExcludes(exclusions.base_asTable()));
 205		}
 206	};*/
 207	
 208	/**
 209	 * def import: sourceObject alias: [ `oldname -> `newname, ... ] excludes: [ `name1, `name2, ... ]
 210	 */
 211	/*protected static final PrimitiveMethod _PRIM_IMPORT_ALIAS_EXCLUDE_ = new PrimitiveMethod(_IMPORT_ALIAS_EXCLUDE_NAME_,
 212			                                                                                 NATTable.atValue(new ATObject[] { _SRC_PARAM_, _ALIAS_PARAM_, _EXCLUDE_PARAM_ })) {
 213		public ATObject base_apply(ATTable arguments, ATContext ctx) throws InterpreterException {
 214			  ATObject sourceObject = arguments.base_at(NATNumber.ONE);
 215			  ATObject aliases = arguments.base_at(NATNumber.atValue(2));
 216			  ATObject exclusions = arguments.base_at(NATNumber.atValue(3));
 217			  return performImport(sourceObject, ctx, preprocessAliases(aliases.base_asTable()), preprocessExcludes(exclusions.base_asTable()));
 218		}
 219	};*/
 220	
 221	/**
 222	 * Invoked whenever a new true AmbientTalk object is created that should
 223	 * represent the root. This gives the lexical root a chance to install its
 224	 * primitive methods.
 225	 */
 226	/*public static void initializeRoot(NATObject root) {
 227		try {
 228			// add import: native
 229			root.meta_addMethod(_PRIM_IMPORT_);
 230			// add import:alias: native
 231			root.meta_addMethod(_PRIM_IMPORT_ALIAS_);
 232			// add import:exclude: native
 233			root.meta_addMethod(_PRIM_IMPORT_EXCLUDE_);
 234			// add import:alias:exclude: native
 235			root.meta_addMethod(_PRIM_IMPORT_ALIAS_EXCLUDE_);
 236		} catch (InterpreterException e) {
 237			Logging.Init_LOG.fatal("Failed to initialize the root!", e);
 238		}
 239	}*/
 240	
 241	/* ----------------------
 242	 * -- Global variables --
 243	 * ---------------------- */
 244	
 245	/**
 246	 * <tt>nil</tt> evaluates to the nil object, which is
 247	 * the empty, dynamic parent of all AmbientTalk objects. 
 248	 */
 249	public ATNil base_nil() {
 250		return Evaluator.getNil();
 251	}
 252	
 253	/**
 254	 * <tt>true</tt> evaluates to the unique boolean true object.
 255	 */
 256	public ATBoolean base_true() {
 257		return NATBoolean._TRUE_;
 258	}
 259	
 260	/**
 261	 * <tt>false</tt> evaluates to the unique boolean false object.
 262	 */
 263	public ATBoolean base_false() {
 264		return NATBoolean._FALSE_;
 265	}
 266	
 267	/**
 268	 * <tt>/</tt> evaluates to the global namespace. It is
 269	 * simply an alias for <tt>lobby</tt>.
 270	 * @see #base_lobby()
 271	 */
 272	public ATObject base__opdiv_() {
 273		return base_lobby();
 274	}
 275	
 276	/**
 277	 * <tt>lobby</tt> evaluates to the global namespace object.
 278	 * For each <tt>name=path</tt> entry on AmbientTalk's
 279	 * <i>object path</i>, the lobby object contains a slot
 280	 * <tt>name</tt> bound to a namespace object bound to
 281	 * the directory referred to by <tt>path</tt>.
 282	 * <p>
 283	 * Accessing the lobby allows loading in AmbientTalk source code
 284	 * from external files.
 285	 */
 286	public ATObject base_lobby() {
 287		return Evaluator.getLobbyNamespace();
 288	}
 289	
 290	/**
 291	 * <tt>root</tt> evaluates to the global lexical scope object.
 292	 * This is the top-level object in which the definitions of
 293	 * the file <tt>at/init/init.at</tt> are evaluated. All code
 294	 * is assumed to be "nested" in the lexical root, so all definitions
 295	 * of this object are lexically accessible.
 296	 */
 297	public ATObject base_root() {
 298		return Evaluator.getGlobalLexicalScope();
 299	}
 300	
 301	/**
 302	 * <tt>jlobby</tt> evaluates to the Java namespace root. It is a
 303	 * special object which is part of the symbiosis infrastructure of
 304	 * AmbientTalk. <tt>jlobby</tt> acts like an object that has field
 305	 * names that correspond to Java package names. By selecting fields
 306	 * from this object, an appropriate Java package can be created
 307	 * from which a Java class can be accessed. Only the Java classes
 308	 * accessible in the Java classpath are accessible.
 309	 * 
 310	 * Example:
 311	 * <code>jlobby.java.util.Vector</code> evaluates to a reference to
 312	 * the Java <tt>Vector</tt> class.
 313	 */
 314	public ATObject base_jlobby() {
 315		return Evaluator.getJLobbyRoot();
 316	}
 317
 318	/**
 319	 * <tt>network</tt> evaluates to the unique network control object.
 320	 * It is a simple native object with two methods:
 321	 * <ul>
 322	 *  <li><tt>network.online()</tt> makes the interpreter go online. This allows
 323	 *  publications of local actors to be discovered by remote objects and vice versa.
 324	 *  <li><tt>network.offline()</tt> makes the interpreter go offline. All
 325	 *  remote references to remote objects will become disconnected.
 326	 * </ul>
 327	 */
 328	public ATObject base_network() {
 329		return OBJNetwork._INSTANCE_;
 330	}
 331	
 332	/**
 333	 * <tt>defaultMirror</tt> evaluates to the default mirror on objects. This
 334	 * is the mirror encapsulating the standard AmbientTalk object semantics.
 335	 * That is, it is a mirror with similar behaviour as the mirror created by
 336	 * executing: <code>reflect: (object: { ... })</code>.
 337	 * 
 338	 * The default mirror is an object with a read-only <tt>base</tt> field
 339	 * that signifies the base-level object of this mirror. The main purpose
 340	 * of this object is to serve as a prototype whose methods can be overridden
 341	 * by custom mirrors. The syntax:
 342	 * <pre>
 343	 * mirror: { ... }
 344	 * </pre>
 345	 * is syntactic sugar for:
 346	 * <pre>
 347	 * extend: defaultMirror with: { ... }
 348	 * </pre>
 349	 * 
 350	 * Note that the default mirror is typed with the <tt>/.at.types.Mirror</tt> type.
 351	 */
 352	public ATObject base_defaultMirror() {
 353		return Evaluator.getMirrorRoot();
 354	}
 355	
 356	/* ------------------------
 357	 * -- Control Structures --
 358	 * ------------------------ */
 359	
 360	/**
 361	 * The <tt>if:then:</tt> control structure. Usage:
 362	 *  <pre>if: cond then: consequent</pre>
 363	 * 
 364	 * pseudo-implementation:
 365	 * <pre>cond.ifTrue: consequent</pre>
 366	 * 
 367	 * Note that the consequent parameter should be a <i>closure</i>, i.e.
 368	 * the caller is responsible for delaying the evaluation of the consequent!
 369	 * 
 370	 * @param cond a boolean object
 371	 * @param consequent a closure containing the code to execute if the boolean is true
 372	 * @return if <tt>cond</tt> is true, the value of applying the consequent, <tt>nil</tt> otherwise
 373	 */
 374	public ATObject base_if_then_(ATBoolean cond, ATClosure consequent) throws InterpreterException {
 375		return cond.base_ifTrue_(consequent);
 376	}
 377	
 378	/**
 379	 * The <tt>if:then:else:</tt> control structure. Usage:
 380	 *  <pre>if: cond then: consequent else: alternative</pre>
 381	 * 
 382	 * pseudo-implementation:
 383	 * <pre>cond.ifTrue: consequent ifFalse: alternative</pre>
 384	 * 
 385	 * Note that the consequent and alternative parameters should be <i>closures</i>, i.e.
 386	 * the caller is responsible for delaying the evaluation of these arguments!
 387	 * 
 388	 * @param cond a boolean object
 389	 * @param consequent a closure containing the code to execute if the boolean is true
 390	 * @param alternative a closure containing the code to execute if the boolean is false
 391	 * @return the value of consequent if the boolean is true, the value of the alternative otherwise.
 392	 */
 393	public ATObject base_if_then_else_(ATBoolean cond, ATClosure consequent, ATClosure alternative) throws InterpreterException {
 394		return cond.base_ifTrue_ifFalse_(consequent, alternative);
 395	}
 396	
 397	/**
 398	 * The <tt>while:do:</tt> control structure. Usage:
 399	 * <pre>while: condition do: body</pre>
 400	 * 
 401	 * pseudo-implementation:
 402	 * <pre>condition.whileTrue: body</pre>
 403	 * 
 404	 * Note that <i>both</i> the condition and the body should be <i>closures</i>, because
 405	 * they represent pieces of code that have to be executed repeatedly. Because of traditional
 406	 * syntax, novice programmers are inclined to make the mistake of writing, e.g.:
 407	 * <pre>while: (i < 10) do: { i := i + 1 }</pre>
 408	 * Which is wrong because the first parameter should evaluate to a closure that itself
 409	 * returns a boolean value, not to a boolean value directly.
 410	 * 
 411	 * @param condition a closure expected to return a boolean object
 412	 * @param body a closure containing the code to execute as long as the condition closure returns true
 413	 * @return if conditions is true at least once, the last value of body, <tt>nil</tt> otherwise.
 414	 */
 415	public ATObject base_while_do_(ATClosure condition, ATClosure body) throws InterpreterException {
 416		return condition.base_whileTrue_(body);
 417	}
 418	
 419	/**
 420	 * The <tt>foreach:in:</tt> control structure. Usage:
 421	 * 
 422	 * <pre>foreach: body in: table</pre>
 423	 * 
 424	 * pseudo-implementation:
 425	 * <pre>table.each: body</pre>
 426	 * 
 427	 * Example: <code>[1,2,3].each: { |i| system.println(i) }</code>
 428	 * 
 429	 * @param body a one-arity closure that is to be applied to each element of the table
 430	 * @param tab a table to apply the body closure to
 431	 * @return <tt>nil</tt>, by default
 432	 */
 433	public ATObject base_foreach_in_(ATClosure body, ATTable tab) throws InterpreterException {
 434		return tab.base_each_(body);
 435	}
 436
 437	/**
 438	 * The <tt>do:if:</tt> control structure. Usage:
 439	 * <pre>do: body if: condition</pre>
 440	 * 
 441	 * pseudo-implementation:
 442	 * <pre>condition.ifTrue: body</pre>
 443	 *
 444	 * In Ruby, this kind of control structure is called a <i>statement modifier</i>.
 445	 * 
 446	 * @param body a zero-argument closure to execute if the condition is true
 447	 * @param condition a boolean value
 448	 * @return the result of invoking body if the condition is true or nil if the
 449	 * condition is false
 450	 */
 451	public ATObject base_do_if_(ATClosure body, ATBoolean condition) throws InterpreterException {
 452		return condition.base_ifTrue_(body);
 453	}
 454	
 455	/**
 456	 * The <tt>do:unless:</tt> control structure. Usage:
 457	 * <pre>do: body unless: condition</pre>
 458	 * 
 459	 * pseudo-implementation:
 460	 * <pre>condition.ifFalse: body</pre>
 461	 *
 462	 * In Ruby, this kind of control structure is called a <i>statement modifier</i>.
 463	 * Example: <code>do: { file.close() } unless: (nil == file)</code>
 464	 * 
 465	 * @param body a zero-argument closure to execute only if the condition is false
 466	 * @param condition a boolean value
 467	 * @return the result of invoking body if the condition is false, nil otherwise
 468	 */
 469	public ATObject base_do_unless_(ATClosure body, ATBoolean condition) throws InterpreterException {
 470		return condition.base_ifFalse_(body);
 471	}
 472	
 473	/**
 474	 * The <tt>let:</tt> construct. Usage:
 475	 * <pre>let: { |var := value| body }</pre>
 476	 * 
 477	 * pseudo-implementation:
 478	 * <pre>closure()</pre>
 479	 * 
 480	 * <tt>let:</tt> allows for the easy creation of temporary local variables.
 481	 * This construct should be used in conjunction with a closure that declares optional
 482	 * parameters. Because the closure will be invoked with zero arguments, all of the
 483	 * parameters will be given their corresponding default initial value. The parameters
 484	 * are defined local to the closure's body.
 485	 * 
 486	 * AmbientTalk's <tt>let:</tt> behaves like Scheme's <tt>let*</tt> and <tt>letrec</tt>,
 487	 * i.e. the following is legal:
 488	 * <pre>let: {
 489	 *  |var1 := value1,
 490	 *   var2 := var1,
 491	 *   var3 := { ... var3() ... }|
 492	 *  ...
 493	 *}</pre>
 494	 * 
 495	 * @param body a closure which is supposed to declare some optional parameters
 496	 * @return the result of invoking the body closure
 497	 */
 498	public ATObject base_let_(ATClosure body) throws InterpreterException {
 499		return body.base_apply(NATTable.EMPTY);
 500	}
 501	
 502	/* ------------------------------------------
 503	 * -- Actor Creation and accessing Methods --
 504	 * ------------------------------------------ */
 505	
 506	/**
 507	 * The <tt>actor: closure</tt> construct.
 508	 *  
 509	 * The semantics of actor creation is as follows:
 510	 * <ul>
 511	 *  <li> Mandatory parameters to the block of initialization code are treated as lexically visible
 512	 *   variables that have to remain available in the new actor behaviour. Hence, these variables
 513	 *   are evaluated to values immediately at creation-time and parameter-passed to the new actor.
 514	 *  <li> The closure containing the initialization code is unpacked, its lexical scope is disregarded
 515	 *   and the unwrapped method is serialized and sent to the new actor, which can use it to
 516	 *   initialize his behaviour object.
 517	 *  <li>The creating actor waits for the created actor to spawn a new behaviour and to return a far
 518	 *   reference to this behaviour. From that point on, the creating actor can run in parallel with
 519	 *   the created actor, which only then evaluates the initialization code to initialize its behaviour.
 520	 * </ul>
 521	 * 
 522	 * @param closure the closure whose parameters define lexical fields to be copied and whose
 523	 * method specifies the code of the new actor's behaviour object
 524	 * @return a far reference to the behaviour of the new actor
 525	 */
 526	public ATObject base_actor_(ATClosure closure) throws InterpreterException {
 527		ATMethod method = closure.base_method();
 528		ATObject copiedBindings;
 529
 530		// if no variables were specified to pass along to the new actor, calculate the
 531		// set of free variables for the actor
 532		if (method.base_parameters().base_isEmpty().asNativeBoolean().javaValue) {
 533			// introduce a private scope object that will hold copies
 534			// of the lexically free variables of the actor
 535			copiedBindings = new NATObject(OBJLexicalRoot._INSTANCE_, new ATTypeTag[] { NativeTypeTags._ISOLATE_ });
 536			
 537			// calculate the set of free variables of the initialization expression
 538			Set freeVars = method.base_bodyExpression().impl_freeVariables();
 539			// add all these free variables manually as fields to a custom 
 540			Iterator it = freeVars.iterator();
 541			while (it.hasNext()) {
 542				ATSymbol freeVar = (ATSymbol) it.next();
 543				
 544				// extra check to weed out special variables like "super" and variables available in the lexical root
 545				if (! (Evaluator.getGlobalLexicalScope().meta_respondsTo(freeVar).asNativeBoolean().javaValue
 546				      || OBJLexicalRoot._INSTANCE_.meta_respondsTo(freeVar).asNativeBoolean().javaValue)) {
 547
 548					// lookup the variable in the lexical scope
 549					try {
 550						ATClosure accessor = closure.base_context().base_lexicalScope().impl_lookup(freeVar);
 551						// only add the variable if it refers to a field, rather than to a method
 552						if (accessor instanceof NativeClosure.Accessor) {
 553							copiedBindings.meta_defineField(freeVar, accessor.base_apply(NATTable.EMPTY));
 554						}
 555					} catch(XUndefinedSlot exc) {
 556						// silently ignore lexically free variables which cannot be found
 557						// the assumption is that these variables will be bound by means of
 558						// import statements
 559						Logging.Actor_LOG.warn("Undefined lexically free var while constructing actor: "+exc.getFieldName());
 560					}
 561				}
 562			}
 563		} else {
 564			copiedBindings = Evaluator.evalMandatoryPars(
 565					method.base_parameters(),
 566					closure.base_context());
 567		}
 568		
 569		Packet serializedBindings = new Packet("actor-bindings", copiedBindings);
 570		Packet serializedInitCode = new Packet("actor-initcode", method);
 571		return ELVirtualMachine.currentVM().createActor(serializedBindings, serializedInitCode);
 572	}
 573	
 574	/**
 575	 * <tt>reflectOnActor</tt> evaluates to the mirror on the actor executing this code.
 576	 * The actor mirror is an object whose behaviour is consulted for operations
 577	 * such as creating and sending asynchronous messages or creating mirrors on
 578	 * other objects. It can be replaced by a custom mirror by means of the actor
 579	 * mirror's <tt>getExplicitActorMirror</tt> method.
 580	 */
 581	public ATActorMirror base_reflectOnActor() throws InterpreterException {
 582		return ELActor.currentActor().getImplicitActorMirror().base_getExplicitActorMirror();
 583	}
 584	
 585	/**
 586	 * The <tt>export: object as: topic</tt> construct. Pseudo-implementation:
 587	 * <pre>actor.provide(topic, object)</pre>
 588	 * 
 589	 * This construct enables the given object to become discoverable by objects
 590	 * in other actors by means of the topic type.
 591	 * 
 592	 * @param object the object to export to remote actors' objects
 593	 * @param topic a type denoting the abstract 'publication topic' for this object's publication
 594	 * @return a publication object whose <tt>cancel</tt> method can be used to cancel the publication.
 595	 */
 596	public ATObject base_export_as_(ATObject object, ATTypeTag topic) throws InterpreterException {
 597		return ELActor.currentActor().getImplicitActorMirror().base_provide(topic, object);
 598	}
 599	
 600	/**
 601	 * The <tt>when: topic discovered: handler</tt> construct. Pseudo-implementation:
 602	 * <pre>actor.require(topic, handler, false)</pre>
 603	 * 
 604	 * When an object is exported by <i>another</i> actor under topic, this construct triggers
 605	 * the given code, passing a reference to the exported object as argument to the closure.
 606	 * 
 607	 * Once the code block has run once, it will not be triggered again.
 608	 * 
 609	 * @param topic the abstract 'subscription topic' used to find an exported object
 610	 * @param handler a one-argument closure to apply to a discovered exported object
 611	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel the subscription,
 612	 * such that the handler will no longer be invoked. Beware, however, that at the time the
 613	 * subscription is cancelled, a request to apply the closure may already have been scheduled
 614	 * for execution by the current actor. This request is not cancelled by invoking the <tt>cancel</tt> method.
 615	 */
 616	public ATObject base_when_discovered_(ATTypeTag topic, ATClosure handler) throws InterpreterException {
 617		return ELActor.currentActor().getImplicitActorMirror().base_require(topic, handler, NATBoolean._FALSE_);
 618	}
 619	
 620	/**
 621	 * The <tt>whenever: topic discovered: handler</tt> construct. Pseudo-implementation:
 622	 * <pre>actor.require(topic, handler, true)</pre>
 623	 * 
 624	 * When an object is exported by <i>another</i> actor under topic, this construct triggers
 625	 * the given code, passing a reference to the exported object as argument to the closure.
 626	 * 
 627	 * The code block can be fired multiple times upon discovering multiple exported objects.
 628	 * To stop the block from triggering upon new publications, it must be explicitly cancelled
 629	 * 
 630	 * @param topic the abstract 'subscription topic' used to find an exported object
 631	 * @param handler a one-argument closure to apply to any discovered exported object
 632	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel the subscription,
 633	 * such that the handler will no longer be invoked. Beware, however, that at the time the
 634	 * subscription is cancelled, a request to apply the closure may already have been scheduled
 635	 * for execution by the current actor. This request is not cancelled by invoking the <tt>cancel</tt> method.
 636	 */
 637	public ATObject base_whenever_discovered_(ATTypeTag topic, ATClosure handler) throws InterpreterException {
 638		return ELActor.currentActor().getImplicitActorMirror().base_require(topic, handler, NATBoolean._TRUE_);
 639	}
 640	
 641	/**
 642	 * The <tt>whenever: farReference disconnected: listener</tt> construct.
 643	 * When the far reference is broken due to network disconnections, triggers the zero-arity listener
 644	 * closure. It is possible to register listeners on local far references. These may trigger if the
 645	 * local actor takes its object offline. In this case, these listeners will trigger as well.
 646	 * 
 647	 * @param farReference a native far reference
 648	 * @param listener a zero-arity closure to invoke if the far reference becomes disconnected
 649	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
 650	 * notifications of the listener.
 651	 */
 652	public ATObject base_whenever_disconnected_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
 653		farReference.asNativeFarReference().addDisconnectionListener(listener);
 654		return new NATFarReference.NATDisconnectionSubscription(farReference.asNativeFarReference(), listener);
 655	}
 656	
 657	/**
 658	 * The <tt>whenever: farReference reconnected: listener</tt> construct.
 659	 * When the remote reference is reinstated after a network disconnection, trigger the zero-arity
 660	 * listener. Although it is allowed to register these listeners on local far references,
 661	 * these are normally not invoked because the only possibility for a local far ref to become
 662	 * disconnected is because the object was taken offline, and this is a permanent disconnect.
 663	 * 
 664	 * @param farReference a native far reference
 665	 * @param listener a zero-arity closure to invoke if the far reference becomes reconnected
 666	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
 667	 * notifications of the listener.
 668	 */
 669	public ATObject base_whenever_reconnected_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
 670		farReference.asNativeFarReference().addReconnectionListener(listener);
 671		return new NATFarReference.NATReconnectionSubscription(farReference.asNativeFarReference(), listener);
 672	}
 673	
 674	/**
 675	 * The <tt>when: farReference takenOffline:</tt> construct.
 676	 *  When the (remote/local) far reference is broken because the object referenced was 
 677	 *  taken offline, trigger the code.
 678	 *  
 679	 * @param farReference a native far reference
 680	 * @param listener a zero-arity closure to invoke if the referenced object has been taken offline.
 681	 * @return a subscription object whose <tt>cancel</tt> method can be used to cancel future
 682	 * notifications of the listener.
 683	 */
 684	public ATObject base_when_takenOffline_(ATFarReference farReference, ATClosure listener) throws InterpreterException {
 685		farReference.asNativeFarReference().addTakenOfflineListener(listener);
 686		return new NATFarReference.NATExpiredSubscription(farReference.asNativeFarReference(), listener);
 687	}
 688	
 689
 690	/**
 691	 * The <tt>retract: farReference</tt> construct. 
 692	 * Retracts all currently unsent messages from the far reference's outbox.
 693	 * This has the side effect that the returned messages will <b>not</b> be sent
 694	 * automatically anymore, the programmer is responsible to explicitly resend
 695	 * all messages that were retracted but still need to be sent.
 696	 *  
 697	 * Note that the returned messages are copies of the original.
 698	 * @param farReference the far reference of which to retract outgoing message sends
 699	 * @return a table containing copies of all messages that were sent to this far reference, but
 700	 * not yet transmitted by the far reference to its referent.
 701	 */
 702	public ATTable base_retract_(ATFarReference farReference) throws InterpreterException {
 703		return farReference.meta_retractUnsentMessages();
 704	}
 705	
 706	/* -----------------------------
 707	 * -- Object Creation Methods --
 708	 * ----------------------------- */
 709	
 710	/**
 711	 * The <tt>object:</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 <tt>nil</tt>.
 717	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 718	 *  <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
 719	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 720	 *  with a 'native' metaobject protocol).
 721	 * </ul>
 722	 * 
 723	 * Example: <code>object: { def x := 1; }</code>
 724	 * <p>
 725	 * Pseudo-implementation:
 726	 * <pre>object: code childOf: nil extends: false taggedAs: [] mirroredBy: defaultMirror</pre>
 727	 * 
 728	 * The closure used to initialize the object may contain formal parameters. The closure
 729	 * will always be invoked with <i>its own mandatory formal parameters</i>. E.g., a closure
 730	 * <code>{ |x| nil }</code> is invoked as <code>{ |x| nil }(x)</code>. The net effect of this
 731	 * mechanic is that if <tt>x</tt> is a lexically visible variable at the object-creation
 732	 * site, the value of the variable will be copied into a copy with the same name which
 733	 * resides in the newly created object. This mechanic is primarily useful for copying surrounding
 734	 * variables within the object, e.g. for isolates which lose access to their surrounding scope.
 735	 * <p>
 736	 * Also, if the closure has optional parameters, they will always be triggered.
 737	 * The expressions to initialize the formal parameters are <i>evaluated</i>
 738	 * in the context of the closure's lexical scope but are <i>added</i> to the newly created object.
 739	 * 
 740	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
 741	 * @return a new AmbientTalk object with the properties defined above.
 742	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 743	 */
 744	public ATObject base_object_(ATClosure code) throws InterpreterException {
 745		return base_object_childOf_extends_taggedAs_mirroredBy_(
 746				code,
 747				Evaluator.getNil(),
 748				NATBoolean._FALSE_ /* SHARES-A link */,
 749				NATTable.EMPTY,
 750				base_defaultMirror());
 751	}
 752	
 753	/**
 754	 * The <tt>extend:with:</tt> object creation primitive.
 755	 * This construct creates a new AmbientTalk object where:
 756	 * <ul>
 757	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 758	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 759	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 760	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
 761	 *  <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
 762	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 763	 *  with a 'native' metaobject protocol).
 764	 * </ul>
 765	 * 
 766	 * Example: <code>extend: parent with: { def x := 1; }</code>
 767	 * <p>
 768	 * Pseudo-implementation:
 769	 * <pre>object: code childOf: parent extends: true taggedAs: [] mirroredBy: defaultMirror</pre>
 770	 * 
 771	 * @param parent the dynamic parent object of the newly created object.
 772	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
 773	 * @return a new AmbientTalk object with the properties defined above.
 774	 * @see #base_object_(ATClosure)
 775	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 776	 */
 777	public ATObject base_extend_with_(ATObject parent, ATClosure code) throws InterpreterException {
 778		return base_object_childOf_extends_taggedAs_mirroredBy_(
 779				code,
 780				parent,
 781				NATBoolean._TRUE_ /* IS-A link */,
 782				NATTable.EMPTY,
 783				base_defaultMirror());
 784	}
 785	
 786    /**
 787     * The <tt>extend:with:taggedAs:</tt> object creation primitive.
 788	 * This construct creates a new AmbientTalk object where:
 789	 * <ul>
 790	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 791	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 792	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 793	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
 794	 *  <li>The object's <b>types</b> are initialized to the argument types table.
 795	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 796	 *  with a 'native' metaobject protocol).
 797	 * </ul>
 798	 * 
 799	 * Example: <code>extend: parent with: { def x := 1; } taggedAs: [foo,bar]</code>
 800	 * <p>
 801	 * Pseudo-implementation:
 802	 * <pre>object: code childOf: parent extends: true taggedAs: types mirroredBy: defaultMirror</pre>
 803	 * 
 804	 * @param parent the dynamic parent object of the newly created object.
 805	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 806	 * @param types a table of types with which to type the newly created object.
 807	 * @return a new AmbientTalk object with the properties defined above.
 808	 * @see #base_object_(ATClosure)
 809	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 810	 */
 811	public ATObject base_extend_with_taggedAs_(ATObject parent, ATClosure code, ATTable types) throws InterpreterException {
 812		return base_object_childOf_extends_taggedAs_mirroredBy_(
 813				code,
 814				parent,
 815				NATBoolean._TRUE_ /* IS-A link */,
 816				types,
 817				base_defaultMirror());
 818	}
 819	
 820    /**
 821     * The <tt>extend:with:mirroredBy:</tt> object creation primitive.
 822	 * This construct creates a new AmbientTalk object where:
 823	 * <ul>
 824	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 825	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 826	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 827	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
 828	 *  <li>The object's <b>types</b> are set to <tt>[]</tt> (i.e. the object has no types).
 829	 *  <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
 830	 *  whose metaobject protocol is entirely dictated by the given mirror.
 831	 * </ul>
 832	 * 
 833	 * Example: <code>extend: parent with: { def x := 1; } mirroredBy: (mirror: {...})</code>
 834	 * <p>
 835	 * Pseudo-implementation:
 836	 * <pre>object: code childOf: parent extends: true taggedAs: [] mirroredBy: mirror</pre>
 837	 * 
 838	 * @param parent the dynamic parent object of the newly created object.
 839	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 840	 * @param mirror the mirror of the newly created mirage object.
 841	 * @return a new AmbientTalk object with the properties defined above.
 842	 * @see #base_object_(ATClosure)
 843	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 844	 */
 845	public ATObject base_extend_with_mirroredBy_(ATObject parent, ATClosure code, ATObject mirror) throws InterpreterException {
 846		return base_object_childOf_extends_taggedAs_mirroredBy_(
 847				code,
 848				parent,
 849				NATBoolean._TRUE_ /* IS-A link */,
 850				NATTable.EMPTY,
 851				mirror);
 852	}
 853	
 854    /**
 855     * The <tt>extend:with:taggedAs:mirroredBy:</tt> object creation primitive.
 856	 * This construct creates a new AmbientTalk object where:
 857	 * <ul>
 858	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 859	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 860	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 861	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
 862	 *  <li>The object's <b>types</b> are initialized to the argument types table.
 863	 *  <li>The object's <b>mirror</b> is the given argument mirror. This means that the newly
 864	 *  created object is a <i>mirage</i> whose metaobject protocol is dictated by the given mirror.
 865	 * </ul>
 866	 * 
 867	 * Example: <code>extend: parent with: { def x := 1; } taggedAs: [foo,bar] mirroredBy: mirror</code>
 868	 * <p>
 869	 * Pseudo-implementation:
 870	 * <pre>object: code childOf: parent extends: true taggedAs: types mirroredBy: mirror</pre>
 871	 * 
 872	 * @param parent the dynamic parent object of the newly created object.
 873	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 874	 * @param types a table of types with which to type the newly created object.
 875	 * @param the mirror object of the newly created mirage object.
 876	 * @return a new AmbientTalk object with the properties defined above.
 877	 * @see #base_object_(ATClosure)
 878	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 879	 */
 880	public ATObject base_extend_with_taggedAs_mirroredBy_(ATObject parent, ATClosure code, ATTable types, ATObject mirror) throws InterpreterException {
 881		return base_object_childOf_extends_taggedAs_mirroredBy_(
 882				code,
 883				parent,
 884				NATBoolean._TRUE_ /* IS-A link */,
 885				types,
 886				mirror);
 887	}
 888	
 889	/**
 890	 * The <tt>share:with:</tt> object creation primitive.
 891	 * This construct creates a new AmbientTalk object where:
 892	 * <ul>
 893	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 894	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 895	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 896	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 897	 *  <li>The object's <b>types</b> is <tt>[]</tt> (i.e. it has no types).
 898	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 899	 *  with a 'native' metaobject protocol).
 900	 * </ul>
 901	 * 
 902	 * Example: <code>share: parent with: { def x := 1; }</code>
 903	 * <p>
 904	 * Pseudo-implementation:
 905	 * <pre>object: code childOf: parent extends: false taggedAs: [] mirroredBy: defaultMirror</pre>
 906	 * 
 907	 * @param parent the dynamic parent object of the newly created object.
 908	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent
 909	 * @return a new AmbientTalk object with the properties defined above.
 910	 * @see #base_object_(ATClosure)
 911	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 912	 */
 913	public ATObject base_share_with_(ATObject parent, ATClosure code) throws InterpreterException {
 914		return base_object_childOf_extends_taggedAs_mirroredBy_(
 915				code,
 916				parent,
 917				NATBoolean._FALSE_ /* SHARES-A link */,
 918				NATTable.EMPTY,
 919				base_defaultMirror());
 920	}
 921
 922    /**
 923     * The <tt>share:with:taggedAs:</tt> object creation primitive.
 924	 * This construct creates a new AmbientTalk object where:
 925	 * <ul>
 926	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 927	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 928	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 929	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 930	 *  <li>The object's <b>types</b> are initialized to the argument types table.
 931	 *  <li>The object's <b>mirror</b> is the <tt>defaultMirror</tt> on objects (i.e. it is an object
 932	 *  with a 'native' metaobject protocol).
 933	 * </ul>
 934	 * 
 935	 * Example: <code>share: parent with: { def x := 1; } taggedAs: [foo,bar]</code>
 936	 * <p>
 937	 * Pseudo-implementation:
 938	 * <pre>object: code childOf: parent extends: false taggedAs: types mirroredBy: defaultMirror</pre>
 939	 * 
 940	 * @param parent the dynamic parent object of the newly created object.
 941	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 942	 * @param types a table of types with which to type the newly created object.
 943	 * @return a new AmbientTalk object with the properties defined above.
 944	 * @see #base_object_(ATClosure)
 945	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 946	 */
 947	public ATObject base_share_with_taggedAs_(ATObject parent, ATClosure code, ATTable types) throws InterpreterException {
 948		return base_object_childOf_extends_taggedAs_mirroredBy_(
 949				code,
 950				parent,
 951				NATBoolean._FALSE_ /* SHARES-A link */,
 952				types,
 953				base_defaultMirror());
 954	}
 955	
 956    /**
 957     * The <tt>share:with:mirroredBy:</tt> object creation primitive.
 958	 * This construct creates a new AmbientTalk object where:
 959	 * <ul>
 960	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 961	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 962	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 963	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 964	 *  <li>The object's <b>types</b> are set to <tt>[]</tt> (i.e. the object has no types).
 965	 *  <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
 966	 *  whose metaobject protocol is entirely dictated by the given mirror.
 967	 * </ul>
 968	 * 
 969	 * Example: <code>share: parent with: { def x := 1; } mirroredBy: (mirror: {...})</code>
 970	 * <p>
 971	 * Pseudo-implementation:
 972	 * <pre>object: code childOf: parent extends: false taggedAs: [] mirroredBy: mirror</pre>
 973	 * 
 974	 * @param parent the dynamic parent object of the newly created object.
 975	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
 976	 * @param mirror the mirror of the newly created mirage object.
 977	 * @return a new AmbientTalk object with the properties defined above.
 978	 * @see #base_object_(ATClosure)
 979	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
 980	 */
 981	public ATObject base_share_with_mirroredBy_(ATObject parent, ATClosure code, ATObject mirror) throws InterpreterException {
 982		return base_object_childOf_extends_taggedAs_mirroredBy_(
 983				code,
 984				parent,
 985				NATBoolean._FALSE_ /* SHARES-A link */,
 986				NATTable.EMPTY,
 987				mirror);
 988	}
 989	
 990    /**
 991     * The <tt>share:with:taggedAs:mirroredBy:</tt> object creation primitive.
 992	 * This construct creates a new AmbientTalk object where:
 993	 * <ul>
 994	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
 995	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
 996	 *  <li>The object's <b>dynamic parent</b> is the argument object.
 997	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
 998	 *  <li>The object's <b>types</b> are initialized to the argument types table.
 999	 *  <li>The object's <b>mirror</b> is the given argument mirror. This means that the newly
1000	 *  created object is a <i>mirage</i> whose metaobject protocol is dictated by the given mirror.
1001	 * </ul>
1002	 * 
1003	 * Example: <code>share: parent with: { def x := 1; } taggedAs: [foo,bar] mirroredBy: mirror</code>
1004	 * <p>
1005	 * Pseudo-implementation:
1006	 * <pre>object: code childOf: parent extends: false taggedAs: types mirroredBy: mirror</pre>
1007	 * 
1008	 * @param parent the dynamic parent object of the newly created object.
1009	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1010	 * @param types a table of types with which to type the newly created object.
1011	 * @param mirror the mirror object of the newly created mirage object.
1012	 * @return a new AmbientTalk object with the properties defined above.
1013	 * @see #base_object_(ATClosure)
1014	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
1015	 */
1016	public ATObject base_share_with_taggedAs_mirroredBy_(ATObject parent, ATClosure code, ATTable types, ATObject mirror) throws InterpreterException {
1017		return base_object_childOf_extends_taggedAs_mirroredBy_(
1018				code,
1019				parent,
1020				NATBoolean._FALSE_ /* SHARES-A link */,
1021				types,
1022				mirror);
1023	}
1024	
1025    /**
1026     * The <tt>object:taggedAs:</tt> object creation primitive.
1027	 * This construct creates a new AmbientTalk object where:
1028	 * <ul>
1029	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
1030	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
1031	 *  <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
1032	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
1033	 *  <li>The object's <b>types</b> are initialized to the argument types table.
1034	 *  <li>The object's <b>mirror</b> is <tt>defaultMirror</tt> (i.e. the object has the
1035	 *  default metaobject protocol).
1036	 * </ul>
1037	 * 
1038	 * Example: <code>object: { def x := 1; } taggedAs: [foo,bar]</code>
1039	 * <p>
1040	 * Pseudo-implementation:
1041	 * <pre>object: code childOf: nil extends: false taggedAs: types mirroredBy: defaultMirror</pre>
1042	 * 
1043	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1044	 * @param types a table of type tags with which to type the newly created object.
1045	 * @return a new AmbientTalk object with the properties defined above.
1046	 * @see #base_object_(ATClosure)
1047	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
1048	 */
1049	public ATObject base_object_taggedAs_(ATClosure code, ATTable types) throws InterpreterException {
1050		return base_object_childOf_extends_taggedAs_mirroredBy_(
1051				code,
1052				Evaluator.getNil(),
1053				NATBoolean._FALSE_ /* SHARES-A link */,
1054				types,
1055				base_defaultMirror());
1056	}
1057	
1058    /**
1059     * The <tt>isolate:</tt> object creation primitive.
1060	 * This construct creates a new AmbientTalk object where:
1061	 * <ul>
1062	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
1063	 *  <li>The object's <b>lexical parent</b> is initialized to the lexical scope of the argument closure,
1064	 *  but because it is typed as an isolate, the parent link is replaced by a link to the lexical <tt>root</tt>.
1065	 *  <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
1066	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
1067	 *  <li>The object's <b>types</b> are initialized to <tt>[/.at.types.Isolate]</tt>, i.e.
1068	 *  the object is typed as an isolate.
1069	 *  <li>The object's <b>mirror</b> is <tt>defaultMirror</tt> (i.e. the object has the
1070	 *  default metaobject protocol).
1071	 * </ul>
1072	 * 
1073	 * Example: <code>isolate: { def x := 1; }</code>
1074	 * <p>
1075	 * Pseudo-implementation:
1076	 * <pre>object: code childOf: nil extends: false taggedAs: [/.at.types.Isolate] mirroredBy: defaultMirror</pre>
1077	 * 
1078	 * An isolate is an object without a proper lexical parent. It is as if the isolate is always
1079	 * defined at top-level. However, lexically visible variables can be retained by copying them into the isolate
1080	 * by means of formal parameters to the argument closure. Isolate objects are passed by-copy during
1081	 * inter-actor parameter and result passing.
1082	 * 
1083	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1084	 * @return a new AmbientTalk object with the properties defined above.
1085	 * @see #base_object_(ATClosure)
1086	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
1087	 */
1088	public ATObject base_isolate_(ATClosure code) throws InterpreterException {
1089		return base_object_taggedAs_(code, NATTable.of(NativeTypeTags._ISOLATE_));
1090	}
1091	
1092    /**
1093     * The <tt>mirror:</tt> object creation primitive.
1094	 * This construct creates a new AmbientTalk object where:
1095	 * <ul>
1096	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
1097	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
1098	 *  <li>The object's <b>dynamic parent</b> is <tt>defaultMirror</tt>.
1099	 *  <li>The object's <b>parent type</b> is <b>IS-A</b> (i.e. it is an extension of its parent).
1100	 *  <li>The object's <b>types</b> are initialized to <tt>[]</tt>.
1101	 *  <li>The object's <b>mirror</b> is <tt>defaultMirror</tt> (i.e. the object has the
1102	 *  default metaobject protocol).
1103	 * </ul>
1104	 * 
1105	 * Example: <code>mirror: { def x := 1; }</code>
1106	 * <p>
1107	 * Pseudo-implementation:
1108	 * <pre>object: code childOf: defaultMirror extends: true taggedAs: [] mirroredBy: defaultMirror</pre>
1109	 * 
1110	 * This construct is mere syntactic sugar for creating an extension of the default mirror root.
1111	 * It follows that AmbientTalk mirrors are plain AmbientTalk objects. They simply need to implement
1112	 * the entire metaobject protocol, and the easiest means to achieve this is by extending the default mirror.
1113	 * Also keep in mind that the mirror is an extension object. This is important because the default
1114	 * mirror has <i>state</i>, being the <tt>base</tt> field that points to the base-level object
1115	 * being mirrorred. Hence, always make sure that, if overriding <tt>init</tt>, the parent's
1116	 * <tt>init</tt> method is invoked with the appropriate <tt>base</tt> value.
1117	 * 
1118	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1119	 * @return a new AmbientTalk object with the properties defined above.
1120	 * @see #base_object_(ATClosure)
1121	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
1122	 */
1123	public ATObject base_mirror_(ATClosure code) throws InterpreterException {
1124		return base_object_childOf_extends_taggedAs_mirroredBy_(
1125				code,
1126				base_defaultMirror(),
1127				NATBoolean._TRUE_ /* IS-A link */, 
1128			    NATTable.EMPTY,
1129			    base_defaultMirror());
1130	}
1131	
1132    /**
1133     * The <tt>object:mirroredBy:</tt> object creation primitive.
1134	 * This construct creates a new AmbientTalk object where:
1135	 * <ul>
1136	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
1137	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
1138	 *  <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
1139	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
1140	 *  <li>The object's <b>types</b> are set to <tt>[]</tt> (i.e. the object has no types).
1141	 *  <li>The object's <b>mirror</b> is the given mirror. This means that this object is a <i>mirage</i>
1142	 *  whose metaobject protocol is entirely dictated by the given mirror.
1143	 * </ul>
1144	 * 
1145	 * Example: <code>object: { def x := 1; } mirroredBy: (mirror: {...})</code>
1146	 * <p>
1147	 * Pseudo-implementation:
1148	 * <pre>object: code childOf: nil extends: false taggedAs: [] mirroredBy: mirror</pre>
1149	 * 
1150	 * This primitive allows the construction of so-called <i>mirage</i> objects which are
1151	 * AmbientTalk objects whose metaobject protocol behaviour is dictated by a custom mirror
1152	 * object.
1153	 * 
1154	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1155	 * @param mirror the mirror prototype of the newly created mirage object, or a constructor closure.
1156	 * @return a new AmbientTalk object with the properties defined above.
1157	 * @see #base_object_(ATClosure)
1158	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
1159	 */
1160	public ATObject base_object_mirroredBy_(ATClosure code, ATObject mirror) throws InterpreterException {
1161		return base_object_childOf_extends_taggedAs_mirroredBy_(
1162				code,
1163				Evaluator.getNil(),
1164				NATBoolean._FALSE_ /* SHARES-A link */,
1165				NATTable.EMPTY,
1166				mirror);
1167	}
1168	
1169    /**
1170     * The <tt>object:taggedAs:mirroredBy:</tt> object creation primitive.
1171	 * This construct creates a new AmbientTalk object where:
1172	 * <ul>
1173	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
1174	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
1175	 *  <li>The object's <b>dynamic parent</b> is <tt>nil</tt>.
1176	 *  <li>The object's <b>parent type</b> is <b>SHARES-A</b> (i.e. it is not an extension of its parent).
1177	 *  <li>The object's <b>types</b> are set to the argument types.
1178	 *  <li>The object's <b>mirror</b> is a clone of given mirror, or the return value of a constructor closure. This means that this object is a <i>mirage</i>
1179	 *  whose metaobject protocol is entirely dictated by the given mirror.
1180	 * </ul>
1181	 * 
1182	 * Example: <code>object: { def x := 1; } taggedAs: [foo,bar] mirroredBy: (mirror: {...})</code>
1183	 * <p>
1184	 * Pseudo-implementation:
1185	 * <pre>object: code childOf: nil extends: false taggedAs: types mirroredBy: mirror</pre>
1186	 * 
1187	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1188	 * @param types a table of types with which to type the newly created object.
1189	 * @param mirror the mirror of the newly created mirage object.
1190	 * @return a new AmbientTalk object with the properties defined above.
1191	 * @see #base_object_(ATClosure)
1192	 * @see #base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure, ATObject, ATBoolean, ATTable, ATObject)
1193	 */
1194	public ATObject base_object_taggedAs_mirroredBy_(ATClosure code, ATTable types, ATObject mirror) throws InterpreterException {
1195		return base_object_childOf_extends_taggedAs_mirroredBy_(
1196				code,
1197				Evaluator.getNil(),
1198				NATBoolean._FALSE_ /* SHARES-A link */,
1199				types,
1200				mirror);
1201	}
1202	
1203    /**
1204     * The <tt>object:childOf:extends:taggedAs:mirroredBy:</tt> object creation primitive.
1205	 * This construct creates a new AmbientTalk object where:
1206	 * <ul>
1207	 *  <li>The object is initialized with the <i>code</i> of the argument closure.
1208	 *  <li>The object's <b>lexical parent</b> is the lexical scope of the argument closure. 
1209	 *  <li>The object's <b>dynamic parent</b> is the argument parent object.
1210	 *  <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>.
1211	 *  <li>The object's <b>types</b> are set to the argument types table.
1212	 *  <li>The object's <b>mirror</b> is a clone of the given mirror prototype,
1213	 *  or the return value of the given constructor closure. This means that this object is a <i>mirage</i>
1214	 *  whose metaobject protocol is entirely dictated by the given mirror, if the mirror is not <tt>defaultMirror</tt>.
1215	 * </ul>
1216	 * 
1217	 * Example: <code>object: { def x := 1; } childOf: parent extends: true taggedAs: [foo,bar] mirroredBy: mirror</code>
1218	 * <p>
1219	 * Pseudo-implementation:
1220	 * <pre>let o = OBJECT(parent,code.lexicalParent,parentType,types);
1221	 *  code.applyInScope(o, code.mandatoryPars);
1222	 *  o
1223	 * </pre>
1224	 * 
1225	 * @param code a closure containing both the code with which to initialize the object and the new object's lexical parent.
1226	 * @param parent the dynamic parent object of the newly created object.
1227	 * @param parentType a boolean denoting whether or not the object is an extension of its dynamic parent.
1228	 * @param types a table of types with which the newly created object should be typed.
1229	 * @param mirror the mirror of the newly created object.
1230	 * @return a new AmbientTalk object with the properties defined above.
1231	 * @see #base_object_(ATClosure) for more information about the properties of the passed closure.
1232	 */
1233	public ATObject base_object_childOf_extends_taggedAs_mirroredBy_(ATClosure code, ATObject parent, ATBoolean parentType, ATTable types, ATObject mirror) throws InterpreterException {
1234		ATTypeTag[] typeArray = NATTypeTag.toTypeTagArray(types);
1235		boolean parentRelation = parentType.asNativeBoolean().javaValue;
1236		NATObject newObject;
1237		// if the mirror is a 'default' mirror...
1238		if (mirror instanceof NATMirrorRoot) {
1239			// then create a native object
1240			newObject = new NATObject(parent, // dynamic parent
1241					                  code.base_context().base_lexicalScope(), // lexical parent
1242					                  parentRelation, // IS-A or SHARES-A
1243					                  typeArray); // initial types
1244		} else {
1245			// else create a mirage mirrored by the custom mirror
1246			newObject = NATMirage.createMirage(code, parent, parentRelation, typeArray, mirror);
1247		}
1248		
1249		newObject.initializeWithCode(code);
1250		return newObject;
1251	}
1252	
1253	/**
1254	 * The <tt>reflect:</tt> construct. This construct returns a mirror on an object.
1255	 * 
1256	 * pseudo-implementation:
1257	 * <pre>actor.createMirror(reflectee)</pre>
1258	 * 
1259	 * An actor can change its default mirror creation policy by installing a new
1260	 * actor protocol that overrides <tt>createMirror</tt>.
1261	 * 
1262	 * @param reflectee the object to reflect upon
1263	 * @return a mirror reflecting on the given object
1264	 * @see ATActorMirror#base_createMirror(ATObject) for the details about mirror creation on objects.
1265	 */
1266	public ATObject base_reflect_(ATObject reflectee) throws InterpreterException {
1267		return base_reflectOnActor().base_createMirror(reflectee);
1268	}
1269	
1270	/**
1271	 * The <tt>clone:</tt> language construct. Returns a clone of an object.
1272	 * 
1273	 * Care must be taken when cloning a mirror. If a mirror would simply be cloned
1274	 * using the regular cloning semantics, its base field would be <b>shared</b>
1275	 * between the clone and the original mirror (because of shallow copy semantics).
1276	 * However, the base object will still be tied to the original mirror, not the clone.
1277	 * Therefore, the clone: operator is implemented as follows:
1278	 * 
1279     * <pre>def clone: obj {
1280     *   if: (is: obj taggedAs: Mirror) then: {
1281     *     reflect: (clone: obj.base)
1282     *   } else: {
1283     *     (reflect: obj).clone()
1284     *   }
1285     * }</pre>
1286	 * 
1287	 * The default cloning semantics ensures that all fields of the object are shallow-copied.
1288	 * Because methods are immutable, a clone and its original object share their method dictionary,
1289	 * but whenever a change is made to the dictionary, the changer creates a local copy of the
1290	 * dictionary as to not modify any clones. Hence, each object is truly stand-alone and independent
1291	 * of its clone.
1292	 * 
1293	 * @param original the object to copy
1294	 * @return a clone of the given object (default semantics results in a shallow copy)
1295	 */
1296	public ATObject base_clone_(ATObject original) throws InterpreterException {
1297		if (original.meta_isTaggedAs(NativeTypeTags._MIRROR_).asNativeBoolean().javaValue) {
1298		    return base_reflect_(base_clone_(original.impl_invokeAccessor(original, NATMirrorRoot._BASE_NAME_, NATTable.EMPTY)));
1299		} else {
1300			return original.meta_clone();
1301		}
1302	}
1303	
1304	/**
1305	 * The <tt>takeOffline:</tt> construct. 
1306	 * Removes an object from the export table of an actor. This ensures that the object
1307	 * is no longer remotely accessible. This method is the cornerstone of distributed
1308	 * garbage collection in AmbientTalk. When an object is taken offline, remote clients
1309	 * that would still access it perceive this as if the object had become permanently
1310	 * disconnected.
1311	 * 
1312	 * @return <tt>nil</tt>.
1313	 */
1314	 public ATNil base_takeOffline_ (ATObject object) throws InterpreterException{
1315		ELActor.currentActor().takeOffline(object);
1316		return Evaluator.getNil();
1317	 }
1318
1319	/**
1320	 * The <tt>disconnect:</tt> construct. 
1321	 * When an object is manually disconnected, remote clients
1322	 * will percieve this as if the object was physically disconnected.
1323	 * This allows per-object disconnects rather than per-actor disconnects.
1324	 * 
1325	 * @return a disconnected object whose <tt>reconnect</tt> method can be used to reconnect (and re-publish) the disconnected object.
1326	 */
1327	 public ATObject base_disconnect_ (ATObject object) throws InterpreterException{
1328		 return ELActor.currentActor().disconnect(object);
1329	 }
1330	
1331	/* -------------------
1332	 * -- Type Support -
1333	 * ------------------- */
1334	
1335	/**
1336	 * The <tt>is: object taggedAs: type</tt> construct.
1337	 * @return true if the given object is typed with the given type, false otherwise
1338	 */
1339	public ATBoolean base_is_taggedAs_(ATObject object, ATTypeTag type) throws InterpreterException {
1340		return object.meta_isTaggedAs(type);
1341	}
1342	
1343	/**
1344	 * The <tt>tagsOf: object</tt> construct.
1345	 * @return a table of all of the <i>local</i> types of an object.
1346	 */
1347	public ATTable base_tagsOf_(ATObject object) throws InterpreterException {
1348		return object.meta_typeTags();
1349	}
1350	
1351	/* -------------------------------
1352	 * -- Exception Handling Support -
1353	 * ------------------------------- */
1354	
1355	/**
1356	 * The <tt>try: { tryBlock } finally: { finallyBlock }</tt> construct.
1357	 * 
1358	 * Applies the tryBlock closure (to <tt>[]</tt>).
1359	 * Whether the tryBlock raises an exception or not, the finallyBlock closure is guaranteed to be applied either 
1360	 * after normal termination of the tryBlock or when an exception is propagated from the tryBlock.
1361	 */
1362	public ATObject base_try_finally_(ATClosure tryBlock, ATClosure finallyBlock) throws InterpreterException {
1363		try {
1364			return tryBlock.base_apply(NATTable.EMPTY);
1365		} finally {
1366		    finallyBlock.base_apply(NATTable.EMPTY);
1367		}
1368	}
1369	
1370	/**
1371	 * The <tt>try: { tryBlock } usingHandlers: [ handler1, handler2, ... ] finally: { finallyBlock }</tt> construct.
1372	 * 
1373	 * Applies the tryBlock closure (to <tt>[]</tt>) and handles exceptions using the given exception handlers.
1374	 * Whether the tryBlock raises an exception or not, the finallyBlock closure is guaranteed to be applied either 
1375	 * after the termination of the tryBlock or the execution of a fitting handler either before the exception is 
1376	 * propagated if no matching handler is provided. This construct is the most general means of doing exception
1377	 * handling in AmbientTalk.
1378	 * 
1379	 * The handlers given in the handler table represent first-class handler objects,
1380	 * which should respond to the <tt>canHandle</tt> message.
1381	 * @see ATHandler for the interface to which a handler object has to adhere
1382	 */
1383	public ATObject base_try_usingHandlers_finally_(ATClosure tryBlock, ATTable exceptionHandlers, ATClosure finallyBlock) throws InterpreterException {
1384		try {
1385			return tryBlock.base_apply(NATTable.EMPTY);
1386		} catch(InterpreterException e) {
1387			ATObject[] handlers = exceptionHandlers.asNativeTable().elements_;
1388			
1389			// find the appropriate handler
1390			for (int i = 0; i < handlers.length; i++) {
1391				ATHandler handler = handlers[i].asHandler();
1392				ATObject exc = e.getAmbientTalkRepresentation();
1393				if (handler.base_canHandle(exc).asNativeBoolean().javaValue) {
1394					return handler.base_handle(exc);
1395				};	
1396			}
1397			
1398			// no handler found, re-throw the exception
1399			throw e;
1400		} finally {
1401			finallyBlock.base_apply(NATTable.EMPTY);
1402		}
1403	}
1404	
1405	/**
1406	 * The <tt>try: { tryBlock } usingHandlers: [ handler1, handler2, ... ]</tt> construct.
1407	 * 
1408	 * Ad hoc code for tryBlocks which have an empty finally block
1409	 * @see OBJLexicalRoot#base_try_usingHandlers_finally_(ATClosure, ATTable, ATClosure)
1410	 */
1411	public ATObject base_try_usingHandlers_(ATClosure tryBlock, ATTable exceptionHandlers) throws InterpreterException {
1412		// An ad hoc version is provided since not using a finally block is a lot cheaper 
1413		// when we know for sure we won't be needing one.
1414		try {
1415			return tryBlock.base_apply(NATTable.EMPTY);
1416		} catch(InterpreterException e) {
1417			ATObject[] handlers = exceptionHandlers.asNativeTable().elements_;
1418			
1419			// find the appropriate handler
1420			for (int i = 0; i < handlers.length; i++) {
1421				ATHandler handler = handlers[i].asHandler();
1422				ATObject exc = e.getAmbientTalkRepresentation();
1423				if (handler.base_canHandle(exc).asNativeBoolean().javaValue) {
1424					return handler.base_handle(exc);
1425				};	
1426			}
1427			
1428			// no handler found, re-throw the exception
1429			throw e;
1430		}
1431	}
1432	
1433	/**
1434	 * The <tt>try: { tryBlock} using: handler</tt> construct.
1435	 * 
1436	 * Ad-hoc code for one exception handler.
1437	 * 
1438	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1439	 */
1440	public ATObject base_try_using_(ATClosure tryBlock, ATHandler handler) throws InterpreterException {
1441		try {
1442			return tryBlock.base_apply(NATTable.EMPTY);
1443		} catch(InterpreterException e) {
1444			ATObject exc = e.getAmbientTalkRepresentation();
1445			if (handler.base_canHandle(exc).asNativeBoolean().javaValue) {
1446				return handler.base_handle(exc);
1447			} else {
1448				throw e;
1449			}
1450		}
1451	}
1452	
1453	/**
1454	 * The <tt>try: { tryBlock} using: handler finally: { finallyBlock }</tt> construct.
1455	 * 
1456	 * Ad-hoc code for one exception handler.
1457	 * 
1458	 * @see #base_try_usingHandlers_finally_(ATClosure, ATTable, ATClosure)
1459	 */
1460	public ATObject base_try_using_finally_(ATClosure tryBlock, ATHandler handler, ATClosure finallyBlock) throws InterpreterException {
1461		try {
1462			return tryBlock.base_apply(NATTable.EMPTY);
1463		} catch(InterpreterException e) {
1464			ATObject exc = e.getAmbientTalkRepresentation();
1465			if (handler.base_canHandle(exc).asNativeBoolean().javaValue) {
1466				return handler.base_handle(exc);
1467			} else {
1468				throw e;
1469			}
1470		} finally {
1471			finallyBlock.base_apply(NATTable.EMPTY);
1472		}
1473	}
1474	
1475	/**
1476	 * The <tt>try: { tryBlock} using: handler1 using: handler2</tt> construct.
1477	 * 
1478	 * Ad-hoc code for two exception handlers.
1479	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1480	 */
1481	public ATObject base_try_using_using_(ATClosure tryBlock, ATHandler hdl1, ATHandler hdl2) throws InterpreterException {
1482		return base_try_usingHandlers_(tryBlock, NATTable.atValue(new ATObject[] { hdl1, hdl2 }));
1483	}
1484	
1485	/**
1486	 * The <tt>try: { tryBlock} using: handler1 using: handler2 finally: { finallyBlock }</tt> construct.
1487	 * 
1488	 * Ad-hoc code for two exception handlers.
1489	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1490	 */
1491	public ATObject base_try_using_using_finally_(ATClosure tryBlock, ATHandler hdl1, ATHandler hdl2, ATClosure finallyBlock) throws InterpreterException {
1492		return base_try_usingHandlers_finally_(tryBlock, NATTable.atValue(new ATObject[] { hdl1, hdl2 }), finallyBlock);
1493	}
1494
1495	
1496	/**
1497	 * The <tt>try: { tryBlock} using: hdl1 using: hdl2 using: hdl3</tt> construct.
1498	 * 
1499	 * Ad-hoc code for three exception handlers
1500	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1501	 */
1502	public ATObject base_try_using_using_using_(ATClosure tryBlock, ATHandler hdl1, ATHandler hdl2, ATHandler hdl3) throws InterpreterException {
1503		return base_try_usingHandlers_(tryBlock, NATTable.atValue(new ATObject[] { hdl1, hdl2, hdl3 }));
1504	}
1505	
1506	/**
1507	 * The <tt>try: { tryBlock} using: hdl1 using: hdl2 using: hdl3 finally: { finallyBlock }</tt> construct.
1508	 * 
1509	 * Ad-hoc code for three exception handlers.
1510	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1511	 */
1512	public ATObject base_try_using_using_using_finally_(ATClosure tryBlock, ATHandler hdl1, ATHandler hdl2, ATHandler hdl3, ATClosure finallyBlock) throws InterpreterException {
1513		return base_try_usingHandlers_finally_(tryBlock, NATTable.atValue(new ATObject[] { hdl1, hdl2, hdl3 }), finallyBlock);
1514	}
1515	
1516	/**
1517	 * The <tt>try: { tryBlock} catch: type using: { |e| replacementCode }</tt>
1518	 * 
1519	 * 'Syntactic sugar' for one "in-line", native handler.
1520	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1521	 */
1522	public ATObject base_try_catch_using_(ATClosure tryBlock, ATTypeTag filter, ATClosure replacementCode) throws InterpreterException {
1523		return base_try_using_(tryBlock, new NATHandler(filter, replacementCode));
1524	}
1525	
1526	/**
1527	 * The <tt>try: { tryBlock} catch: type using: { |e| replacementCode } finally: { finallyBlock }</tt>
1528	 * 
1529	 * 'Syntactic sugar' for one "in-line", native handler.
1530	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1531	 */
1532	public ATObject base_try_catch_using_finally_(ATClosure tryBlock, ATTypeTag filter, ATClosure replacementCode, ATClosure finallyBlock) throws InterpreterException {
1533		return base_try_using_finally_(tryBlock, new NATHandler(filter, replacementCode), finallyBlock);
1534	}
1535	
1536	/**
1537	 * The <tt>try:catch:using:catch:using:</tt> construct.
1538	 * 
1539	 * <pre>try: {
1540	 *   tryBlock
1541	 * } catch: type using: { |e|
1542	 *   replacementCode
1543	 * } catch: type2 using: { |e|
1544	 *   replacementCode2
1545	 * }</pre>
1546	 * 
1547	 * 'Syntactic sugar' for two in-line handlers
1548	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1549	 */
1550	public ATObject base_try_catch_using_catch_using_(	ATClosure tryBlock,
1551														ATTypeTag filter1, ATClosure hdl1,
1552			                						   	ATTypeTag filter2, ATClosure hdl2) throws InterpreterException {
1553		return base_try_using_using_(tryBlock, new NATHandler(filter1, hdl1), new NATHandler(filter2, hdl2));
1554	}
1555	
1556	
1557	/**
1558	 * The <tt>try:catch:using:catch:using:finally:</tt> construct.
1559	 * 
1560	 * <pre>try: {
1561	 *   tryBlock
1562	 * } catch: type using: { |e|
1563	 *   replacementCode
1564	 * } catch: type2 using: { |e|
1565	 *   replacementCode2
1566	 * } finally: {
1567	 *   finalizationCode
1568	 * }</pre>
1569	 * 
1570	 * 'Syntactic sugar' for two in-line handlers
1571	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1572	 */
1573	public ATObject base_try_catch_using_catch_using_finally_(	ATClosure tryBlock,
1574														ATTypeTag filter1, ATClosure hdl1,
1575			                						   	ATTypeTag filter2, ATClosure hdl2, 
1576			                						   	ATClosure finallyBlock) throws InterpreterException {
1577		return base_try_using_using_finally_(tryBlock, new NATHandler(filter1, hdl1), new NATHandler(filter2, hdl2), finallyBlock);
1578	}
1579	
1580	/**
1581	 * The <tt>try:catch:using:catch:using:catch:using:</tt> construct.
1582	 * 
1583	 * <pre>try: {
1584	 *   tryBlock
1585	 * } catch: type using: { |e|
1586	 *   replacementCode
1587	 * } catch: type2 using: { |e|
1588	 *   replacementCode2
1589	 * } catch: type3 using: { |e|
1590	 *   replacementCode3
1591	 * }</pre>
1592	 * 
1593	 * 'Syntactic sugar' for three in-line handlers
1594	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1595	 */
1596	public ATObject base_try_catch_using_catch_using_catch_using_(ATClosure tryBlock,
1597															   ATTypeTag filter1, ATClosure hdl1,
1598															   ATTypeTag filter2, ATClosure hdl2,
1599															   ATTypeTag filter3, ATClosure hdl3) throws InterpreterException {
1600		return base_try_using_using_using_(tryBlock, new NATHandler(filter1, hdl1), new NATHandler(filter2, hdl2), new NATHandler(filter3, hdl3));
1601	}
1602	
1603	/**
1604	 * The <tt>try:catch:using:catch:using:catch:using:finally:</tt> construct.
1605	 * 
1606	 * <pre>try: {
1607	 *   tryBlock
1608	 * } catch: type using: { |e|
1609	 *   replacementCode
1610	 * } catch: type2 using: { |e|
1611	 *   replacementCode2
1612	 * } catch: type3 using: { |e|
1613	 *   replacementCode3
1614	 * }</pre>
1615	 * 
1616	 * 'Syntactic sugar' for three in-line handlers
1617	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1618	 */
1619	public ATObject base_try_catch_using_catch_using_catch_using_finally_(ATClosure tryBlock,
1620															   ATTypeTag filter1, ATClosure hdl1,
1621															   ATTypeTag filter2, ATClosure hdl2,
1622															   ATTypeTag filter3, ATClosure hdl3,
1623															   ATClosure finallyBlock) throws InterpreterException {
1624		return base_try_using_using_using_finally_(tryBlock, new NATHandler(filter1, hdl1), new NATHandler(filter2, hdl2), new NATHandler(filter3, hdl3), finallyBlock);
1625	}
1626
1627	/**
1628	 * The <tt>handle: type with: { |e| replacementCode }</tt> construct.
1629	 * 
1630	 * @return a first-class handler from a filter prototype and some handler code.
1631	 * @see ATHandler for the interface to which a handler object responds.
1632	 */
1633	public ATObject base_handle_with_(ATTypeTag filter, ATClosure replacementCode) {
1634		return new NATHandler(filter, replacementCode);
1635	}
1636	
1637	/**
1638	 * The <tt>raise: exception</tt> construct.
1639	 * 
1640	 * Raises an exception which can be caught by dynamically installed try-catch-using blocks.
1641	 * @see #base_try_usingHandlers_(ATClosure, ATTable)
1642	 */
1643	public ATNil base_raise_(ATObject anExceptionObject) throws InterpreterException {
1644		throw Evaluator.asNativeException(anExceptionObject);
1645	}
1646	
1647	/* --------------------
1648	 * -- Unary Operators -
1649	 * -------------------- */
1650	
1651	/**
1652	 * The unary <tt>!</tt> primitive.
1653	 * <pre>!b == b.not()</pre>
1654	 * @param b the boolean to negate.
1655	 * @return the negation of the boolean.
1656	 */
1657	public ATBoolean base__opnot_(ATBoolean b) throws InterpreterException {
1658		return b.base_not();
1659	}
1660	
1661	/**
1662	 * The unary <tt>-</tt> primitive.
1663	 * <pre>-NUM(n) == 0 - n</pre>
1664	 * 
1665	 * @param n a number or a fraction to negate.
1666	 */
1667	public ATNumeric base__opmns_(ATNumeric n) throws InterpreterException {
1668		return NATNumber.ZERO.base__opmns_(n);
1669	}
1670	
1671	/**
1672	 * The unary <tt>+</tt> primitive.
1673	 * <pre>+NBR(n) == NBR(n)</pre>
1674	 */
1675	public ATNumber base__oppls_(ATNumber n) throws InterpreterException {
1676		return n;
1677	}
1678	
1679	/* -------------------
1680	 * -- Miscellaneous --
1681	 * ------------------- */
1682	
1683	/**
1684	 * The <tt>read:</tt> metaprogramming construct. Parses the given text string into an
1685	 * abstract syntax tree.
1686	 * 
1687	 * Example: <code>read: "x" => `x</code>
1688	 */
1689	public ATAbstractGrammar base_read_(ATText source) throws InterpreterException {
1690		return NATParser._INSTANCE_.base_parse(source);
1691	}
1692	
1693	/**
1694	 * The <tt>eval:in:</tt> metaprogramming construct.
1695	 * Evaluates the given AST in the context of the given object, returning its value.
1696	 * 
1697	 * Example: <code>eval: `x in: object: { def x := 1 } => 1</code>
1698	 * 
1699	 * This is a "dangerous" operation in the sense that lexical encapsulation of the given
1700	 * object can be violated.
1701	 */
1702	public ATObject base_eval_in_(ATAbstractGrammar ast, ATObject obj) throws InterpreterException {
1703		return ast.meta_eval(new NATContext(obj, obj));
1704	}
1705
1706	/**
1707	 * The <tt>print:</tt> metaprogramming construct.
1708	 * This construct invokes the object mirror's <tt>print</tt> method.
1709	 * 
1710	 * @return a text string being a human-readable representation of the given object.
1711	 */
1712	public ATText base_print_(ATObject obj) throws InterpreterException {
1713		return obj.meta_print();
1714	}
1715	
1716	/**
1717	 * The <tt>asCode:</tt> metaprogramming construct.
1718	 * This construct invokes the object mirror's <tt>asCode</tt> method.
1719	 * 
1720	 * @return a text string being the source code representation of the given object.
1721	 */
1722	public ATText base_asCode_(ATObject obj) throws InterpreterException {
1723		return obj.meta_asCode();
1724	}
1725	
1726	/**
1727	 * Compare the receiver object to the <tt>root</tt> object.
1728	 * the reason for this custom implementation: during the execution
1729	 * of this method, 'this' should refer to the global lexical scope object (the root),
1730	 * not to the OBJLexicalRoot instance.
1731	 * 
1732	 * When invoking one of these methods lexically, the receiver is always 'root'
1733	 * For example, <code>==(obj)</code> is equivalent to <code>root == obj</code> (or "root.==(obj)")
1734	 */
1735    public ATBoolean base__opeql__opeql_(ATObject comparand) throws InterpreterException {
1736        return Evaluator.getGlobalLexicalScope().base__opeql__opeql_(comparand);
1737    }
1738	
1739    /**
1740     * Instantiate the <tt>root</tt> object. I.e. <code>new()</code> is equivalent
1741     * to <tt>root.new()</tt>.
1742     */
1743    /*public ATObject base_new(ATObject[] initargs) throws InterpreterException {
1744    	// root.new(@initargs)
1745    	ATObject root = Evaluator.getGlobalLexicalScope();
1746	    return root.meta_invoke(root,NATNil._NEW_NAME_,NATTable.atValue(initargs));
1747    }*/
1748    
1749	/**
1750	 * After deserialization, ensure that the lexical root remains unique.
1751	 */
1752	public ATObject meta_resolve() throws InterpreterException {
1753		return OBJLexicalRoot._INSTANCE_;
1754	}
1755
1756	public NATText meta_print() throws InterpreterException {
1757		return NATText.atValue("lexroot");
1758	}
1759	
1760	/**
1761	 * This hashmap stores all native top-level lexical methods.
1762	 * It is populated when this class is loaded, and shared between all
1763	 * AmbientTalk actors on this VM. This is safe, since {@link DirectNativeMethod}
1764	 * instances are all immutable.
1765	 */
1766	private static final HashMap<String, ATMethod> _meths = new HashMap<String, ATMethod>();
1767
1768	static {
1769		_meths.put("nil", new DirectNativeMethod("nil") {
1770			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1771				if (ctx.base_receiver() != _INSTANCE_) {
1772					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1773				}
1774				checkArity(args, 0);
1775				return _INSTANCE_.base_nil();
1776			}
1777		});
1778		_meths.put("true", new DirectNativeMethod("true") {
1779			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1780				if (ctx.base_receiver() != _INSTANCE_) {
1781					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1782				}
1783				checkArity(args, 0);
1784				return _INSTANCE_.base_true();
1785			}
1786		});
1787		_meths.put("false", new DirectNativeMethod("false") {
1788			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1789				if (ctx.base_receiver() != _INSTANCE_) {
1790					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1791				}
1792				checkArity(args, 0);
1793				return _INSTANCE_.base_false();
1794			}
1795		});
1796		_meths.put("lobby", new DirectNativeMethod("lobby") {
1797			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1798				if (ctx.base_receiver() != _INSTANCE_) {
1799					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1800				}
1801				checkArity(args, 0);
1802				return _INSTANCE_.base_lobby();
1803			}
1804		});
1805		_meths.put("/", _meths.get("lobby"));
1806		_meths.put("root", new DirectNativeMethod("root") {
1807			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1808				if (ctx.base_receiver() != _INSTANCE_) {
1809					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1810				}
1811				checkArity(args, 0);
1812				return _INSTANCE_.base_root();
1813			}
1814		});
1815		_meths.put("jlobby", new DirectNativeMethod("jlobby") {
1816			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1817				if (ctx.base_receiver() != _INSTANCE_) {
1818					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1819				}
1820				checkArity(args, 0);
1821				return _INSTANCE_.base_jlobby();
1822			}
1823		});
1824		_meths.put("network", new DirectNativeMethod("network") {
1825			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1826				if (ctx.base_receiver() != _INSTANCE_) {
1827					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1828				}
1829				checkArity(args, 0);
1830				return _INSTANCE_.base_network();
1831			}
1832		});
1833		_meths.put("defaultMirror", new DirectNativeMethod("defaultMirror") {
1834			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1835				if (ctx.base_receiver() != _INSTANCE_) {
1836					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1837				}
1838				checkArity(args, 0);
1839				return _INSTANCE_.base_defaultMirror();
1840			}
1841		});
1842		_meths.put("if:then:", new DirectNativeMethod("if:then:") {
1843			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1844				if (ctx.base_receiver() != _INSTANCE_) {
1845					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1846				}
1847				checkArity(args, 2);
1848				ATBoolean cond = get(args, 1).asBoolean();
1849				ATClosure consequent = get(args, 2).asClosure();
1850				return _INSTANCE_.base_if_then_(cond, consequent);
1851			}
1852		});
1853		_meths.put("if:then:else:", new DirectNativeMethod("if:then:else:") {
1854			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1855				if (ctx.base_receiver() != _INSTANCE_) {
1856					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1857				}
1858				checkArity(args, 3);
1859				ATBoolean cond = get(args, 1).asBoolean();
1860				ATClosure consequent = get(args, 2).asClosure();
1861				ATClosure alternative = get(args, 3).asClosure();
1862				return _INSTANCE_.base_if_then_else_(cond, consequent, alternative);
1863			}
1864		});
1865		_meths.put("while:do:", new DirectNativeMethod("while:do:") {
1866			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1867				if (ctx.base_receiver() != _INSTANCE_) {
1868					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1869				}
1870				checkArity(args, 2);
1871				ATClosure condition = get(args, 1).asClosure();
1872				ATClosure body = get(args, 2).asClosure();
1873				return _INSTANCE_.base_while_do_(condition, body);
1874			}
1875		});
1876		_meths.put("foreach:in:", new DirectNativeMethod("foreach:in:") {
1877			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1878				if (ctx.base_receiver() != _INSTANCE_) {
1879					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1880				}
1881				checkArity(args, 2);
1882				ATClosure body = get(args, 1).asClosure();
1883				ATTable tab = get(args, 2).asTable();
1884				return _INSTANCE_.base_foreach_in_(body, tab);
1885			}
1886		});
1887		_meths.put("do:if:", new DirectNativeMethod("do:if:") {
1888			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1889				if (ctx.base_receiver() != _INSTANCE_) {
1890					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1891				}
1892				checkArity(args, 2);
1893				ATClosure body = get(args, 1).asClosure();
1894				ATBoolean condition = get(args, 2).asBoolean();
1895				return _INSTANCE_.base_do_if_(body, condition);
1896			}
1897		});
1898		_meths.put("do:unless:", new DirectNativeMethod("do:unless:") {
1899			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1900				if (ctx.base_receiver() != _INSTANCE_) {
1901					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1902				}
1903				checkArity(args, 2);
1904				ATClosure body = get(args, 1).asClosure();
1905				ATBoolean condition = get(args, 2).asBoolean();
1906				return _INSTANCE_.base_do_unless_(body, condition);
1907			}
1908		});
1909		_meths.put("let:", new DirectNativeMethod("let:") {
1910			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1911				if (ctx.base_receiver() != _INSTANCE_) {
1912					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1913				}
1914				checkArity(args, 1);
1915				ATClosure body = get(args, 1).asClosure();
1916				return _INSTANCE_.base_let_(body);
1917			}
1918		});
1919		_meths.put("actor:", new DirectNativeMethod("actor:") {
1920			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1921				if (ctx.base_receiver() != _INSTANCE_) {
1922					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1923				}
1924				checkArity(args, 1);
1925				ATClosure closure = get(args, 1).asClosure();
1926				return _INSTANCE_.base_actor_(closure);
1927			}
1928		});
1929		_meths.put("reflectOnActor", new DirectNativeMethod("reflectOnActor") {
1930			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1931				if (ctx.base_receiver() != _INSTANCE_) {
1932					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1933				}
1934				checkArity(args, 0);
1935				return _INSTANCE_.base_reflectOnActor();
1936			}
1937		});
1938		_meths.put("export:as:", new DirectNativeMethod("export:as:") {
1939			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1940				if (ctx.base_receiver() != _INSTANCE_) {
1941					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1942				}
1943				checkArity(args, 2);
1944				ATObject object = get(args, 1);
1945				ATTypeTag topic = get(args, 2).asTypeTag();
1946				return _INSTANCE_.base_export_as_(object, topic);
1947			}
1948		});
1949		_meths.put("when:discovered:", new DirectNativeMethod("when:discovered:") {
1950			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1951				if (ctx.base_receiver() != _INSTANCE_) {
1952					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1953				}
1954				checkArity(args, 2);
1955				ATTypeTag topic = get(args, 1).asTypeTag();
1956				ATClosure handler = get(args, 2).asClosure();
1957				return _INSTANCE_.base_when_discovered_(topic, handler);
1958			}
1959		});
1960		_meths.put("whenever:discovered:", new DirectNativeMethod("whenever:discovered:") {
1961			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1962				if (ctx.base_receiver() != _INSTANCE_) {
1963					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1964				}
1965				checkArity(args, 2);
1966				ATTypeTag topic = get(args, 1).asTypeTag();
1967				ATClosure handler = get(args, 2).asClosure();
1968				return _INSTANCE_.base_whenever_discovered_(topic, handler);
1969			}
1970		});
1971		_meths.put("whenever:disconnected:", new DirectNativeMethod("whenever:disconnected:") {
1972			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1973				if (ctx.base_receiver() != _INSTANCE_) {
1974					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1975				}
1976				checkArity(args, 2);
1977				ATFarReference farReference = get(args, 1).asFarReference();
1978				ATClosure listener = get(args, 2).asClosure();
1979				return _INSTANCE_.base_whenever_disconnected_(farReference, listener);
1980			}
1981		});
1982		_meths.put("whenever:reconnected:", new DirectNativeMethod("whenever:reconnected:") {
1983			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1984				if (ctx.base_receiver() != _INSTANCE_) {
1985					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1986				}
1987				checkArity(args, 2);
1988				ATFarReference farReference = get(args, 1).asFarReference();
1989				ATClosure listener = get(args, 2).asClosure();
1990				return _INSTANCE_.base_whenever_reconnected_(farReference, listener);
1991			}
1992		});
1993		_meths.put("when:takenOffline:", new DirectNativeMethod("when:takenOffline:") {
1994			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
1995				if (ctx.base_receiver() != _INSTANCE_) {
1996					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
1997				}
1998				checkArity(args, 2);
1999				ATFarReference farReference = get(args, 1).asFarReference();
2000				ATClosure listener = get(args, 2).asClosure();
2001				return _INSTANCE_.base_when_takenOffline_(farReference, listener);
2002			}
2003		});
2004		_meths.put("retract:", new DirectNativeMethod("retract:") {
2005			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2006				if (ctx.base_receiver() != _INSTANCE_) {
2007					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2008				}
2009				checkArity(args, 1);
2010				ATFarReference farReference = get(args, 1).asFarReference();
2011				return _INSTANCE_.base_retract_(farReference);
2012			}
2013		});
2014		_meths.put("object:", new DirectNativeMethod("object:") {
2015			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2016				if (ctx.base_receiver() != _INSTANCE_) {
2017					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2018				}
2019				checkArity(args, 1);
2020				ATClosure code = get(args, 1).asClosure();
2021				return _INSTANCE_.base_object_(code);
2022			}
2023		});
2024		_meths.put("extend:with:", new DirectNativeMethod("extend:with:") {
2025			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2026				if (ctx.base_receiver() != _INSTANCE_) {
2027					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2028				}
2029				checkArity(args, 2);
2030				ATObject parent = get(args, 1);
2031				ATClosure code = get(args, 2).asClosure();
2032				return _INSTANCE_.base_extend_with_(parent, code);
2033			}
2034		});
2035		_meths.put("extend:with:taggedAs:", new DirectNativeMethod("extend:with:taggedAs:") {
2036			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2037				if (ctx.base_receiver() != _INSTANCE_) {
2038					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2039				}
2040				checkArity(args, 3);
2041				ATObject parent = get(args, 1);
2042				ATClosure code = get(args, 2).asClosure();
2043				ATTable types = get(args, 3).asTable();
2044				return _INSTANCE_.base_extend_with_taggedAs_(parent, code, types);
2045			}
2046		});
2047		_meths.put("extend:with:mirroredBy:", new DirectNativeMethod("extend:with:mirroredBy:") {
2048			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2049				if (ctx.base_receiver() != _INSTANCE_) {
2050					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2051				}
2052				checkArity(args, 3);
2053				ATObject parent = get(args, 1);
2054				ATClosure code = get(args, 2).asClosure();
2055				ATObject mirror = get(args, 3);
2056				return _INSTANCE_.base_extend_with_mirroredBy_(parent, code, mirror);
2057			}
2058		});
2059		_meths.put("extend:with:taggedAs:mirroredBy:", new DirectNativeMethod("extend:with:taggedAs:mirroredBy:") {
2060			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2061				if (ctx.base_receiver() != _INSTANCE_) {
2062					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2063				}
2064				checkArity(args, 4);
2065				ATObject parent = get(args, 1);
2066				ATClosure code = get(args, 2).asClosure();
2067				ATTable types = get(args, 3).asTable();
2068				ATObject mirror = get(args, 4);
2069				return _INSTANCE_.base_extend_with_taggedAs_mirroredBy_(parent, code, types, mirror);
2070			}
2071		});
2072		_meths.put("share:with:", new DirectNativeMethod("share:with:") {
2073			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2074				if (ctx.base_receiver() != _INSTANCE_) {
2075					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2076				}
2077				checkArity(args, 2);
2078				ATObject parent = get(args, 1);
2079				ATClosure code = get(args, 2).asClosure();
2080				return _INSTANCE_.base_share_with_(parent, code);
2081			}
2082		});
2083		_meths.put("share:with:taggedAs:", new DirectNativeMethod("share:with:taggedAs:") {
2084			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2085				if (ctx.base_receiver() != _INSTANCE_) {
2086					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2087				}
2088				checkArity(args, 3);
2089				ATObject parent = get(args, 1);
2090				ATClosure code = get(args, 2).asClosure();
2091				ATTable types = get(args, 3).asTable();
2092				return _INSTANCE_.base_share_with_taggedAs_(parent, code, types);
2093			}
2094		});
2095		_meths.put("share:with:mirroredBy:", new DirectNativeMethod("share:with:mirroredBy:") {
2096			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2097				if (ctx.base_receiver() != _INSTANCE_) {
2098					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2099				}
2100				checkArity(args, 3);
2101				ATObject parent = get(args, 1);
2102				ATClosure code = get(args, 2).asClosure();
2103				ATObject mirror = get(args, 3);
2104				return _INSTANCE_.base_share_with_mirroredBy_(parent, code, mirror);
2105			}
2106		});
2107		_meths.put("share:with:taggedAs:mirroredBy:", new DirectNativeMethod("share:with:taggedAs:mirroredBy:") {
2108			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2109				if (ctx.base_receiver() != _INSTANCE_) {
2110					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2111				}
2112				checkArity(args, 4);
2113				ATObject parent = get(args, 1);
2114				ATClosure code = get(args, 2).asClosure();
2115				ATTable types = get(args, 3).asTable();
2116				ATObject mirror = get(args, 4);
2117				return _INSTANCE_.base_share_with_taggedAs_mirroredBy_(parent, code, types, mirror);
2118			}
2119		});
2120		_meths.put("object:taggedAs:", new DirectNativeMethod("object:taggedAs:") {
2121			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2122				if (ctx.base_receiver() != _INSTANCE_) {
2123					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2124				}
2125				checkArity(args, 2);
2126				ATClosure code = get(args, 1).asClosure();
2127				ATTable types = get(args, 2).asTable();
2128				return _INSTANCE_.base_object_taggedAs_(code, types);
2129			}
2130		});
2131		_meths.put("isolate:", new DirectNativeMethod("isolate:") {
2132			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2133				if (ctx.base_receiver() != _INSTANCE_) {
2134					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2135				}
2136				checkArity(args, 1);
2137				ATClosure code = get(args, 1).asClosure();
2138				return _INSTANCE_.base_isolate_(code);
2139			}
2140		});
2141		_meths.put("mirror:", new DirectNativeMethod("mirror:") {
2142			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2143				if (ctx.base_receiver() != _INSTANCE_) {
2144					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2145				}
2146				checkArity(args, 1);
2147				ATClosure code = get(args, 1).asClosure();
2148				return _INSTANCE_.base_mirror_(code);
2149			}
2150		});
2151		_meths.put("object:mirroredBy:", new DirectNativeMethod("object:mirroredBy:") {
2152			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2153				if (ctx.base_receiver() != _INSTANCE_) {
2154					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2155				}
2156				checkArity(args, 2);
2157				ATClosure code = get(args, 1).asClosure();
2158				ATObject mirror = get(args, 2);
2159				return _INSTANCE_.base_object_mirroredBy_(code, mirror);
2160			}
2161		});
2162		_meths.put("object:taggedAs:mirroredBy:", new DirectNativeMethod("object:taggedAs:mirroredBy:") {
2163			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2164				if (ctx.base_receiver() != _INSTANCE_) {
2165					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2166				}
2167				checkArity(args, 3);
2168				ATClosure code = get(args, 1).asClosure();
2169				ATTable types = get(args, 2).asTable();
2170				ATObject mirror = get(args, 3);
2171				return _INSTANCE_.base_object_taggedAs_mirroredBy_(code, types, mirror);
2172			}
2173		});
2174		_meths.put("object:childOf:extends:taggedAs:mirroredBy:", new DirectNativeMethod("object:childOf:extends:taggedAs:mirroredBy:") {
2175			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2176				if (ctx.base_receiver() != _INSTANCE_) {
2177					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2178				}
2179				checkArity(args, 5);
2180				ATClosure code = get(args, 1).asClosure();
2181				ATObject parent = get(args, 2);
2182				ATBoolean parentType = get(args, 3).asBoolean();
2183				ATTable types = get(args, 4).asTable();
2184				ATObject mirror = get(args, 5);
2185				return _INSTANCE_.base_object_childOf_extends_taggedAs_mirroredBy_(code, parent, parentType, types, mirror);
2186			}
2187		});
2188		_meths.put("reflect:", new DirectNativeMethod("reflect:") {
2189			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2190				if (ctx.base_receiver() != _INSTANCE_) {
2191					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2192				}
2193				checkArity(args, 1);
2194				ATObject reflectee = get(args, 1);
2195				return _INSTANCE_.base_reflect_(reflectee);
2196			}
2197		});
2198		_meths.put("clone:", new DirectNativeMethod("clone:") {
2199			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2200				if (ctx.base_receiver() != _INSTANCE_) {
2201					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2202				}
2203				checkArity(args, 1);
2204				ATObject original = get(args, 1);
2205				return _INSTANCE_.base_clone_(original);
2206			}
2207		});
2208		_meths.put("takeOffline:", new DirectNativeMethod("takeOffline:") {
2209			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2210				if (ctx.base_receiver() != _INSTANCE_) {
2211					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2212				}
2213				checkArity(args, 1);
2214				ATObject object = get(args, 1);
2215				return _INSTANCE_.base_takeOffline_(object);
2216			}
2217		});
2218		_meths.put("disconnect:", new DirectNativeMethod("disconnect:") {
2219			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2220				if (ctx.base_receiver() != _INSTANCE_) {
2221					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2222				}
2223				checkArity(args, 1);
2224				ATObject object = get(args, 1);
2225				return _INSTANCE_.base_disconnect_(object);
2226			}
2227		});
2228		_meths.put("is:taggedAs:", new DirectNativeMethod("is:taggedAs:") {
2229			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2230				if (ctx.base_receiver() != _INSTANCE_) {
2231					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2232				}
2233				checkArity(args, 2);
2234				ATObject object = get(args, 1);
2235				ATTypeTag type = get(args, 2).asTypeTag();
2236				return _INSTANCE_.base_is_taggedAs_(object, type);
2237			}
2238		});
2239		_meths.put("tagsOf:", new DirectNativeMethod("tagsOf:") {
2240			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2241				if (ctx.base_receiver() != _INSTANCE_) {
2242					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2243				}
2244				checkArity(args, 1);
2245				ATObject object = get(args, 1);
2246				return _INSTANCE_.base_tagsOf_(object);
2247			}
2248		});
2249		_meths.put("try:finally:", new DirectNativeMethod("try:finally:") {
2250			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2251				if (ctx.base_receiver() != _INSTANCE_) {
2252					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2253				}
2254				checkArity(args, 2);
2255				ATClosure tryBlock = get(args, 1).asClosure();
2256				ATClosure finallyBlock = get(args, 2).asClosure();
2257				return _INSTANCE_.base_try_finally_(tryBlock, finallyBlock);
2258			}
2259		});
2260		_meths.put("try:usingHandlers:finally:", new DirectNativeMethod("try:usingHandlers:finally:") {
2261			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2262				if (ctx.base_receiver() != _INSTANCE_) {
2263					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2264				}
2265				checkArity(args, 3);
2266				ATClosure tryBlock = get(args, 1).asClosure();
2267				ATTable exceptionHandlers = get(args, 2).asTable();
2268				ATClosure finallyBlock = get(args, 3).asClosure();
2269				return _INSTANCE_.base_try_usingHandlers_finally_(tryBlock, exceptionHandlers, finallyBlock);
2270			}
2271		});
2272		_meths.put("try:usingHandlers:", new DirectNativeMethod("try:usingHandlers:") {
2273			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2274				if (ctx.base_receiver() != _INSTANCE_) {
2275					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2276				}
2277				checkArity(args, 2);
2278				ATClosure tryBlock = get(args, 1).asClosure();
2279				ATTable exceptionHandlers = get(args, 2).asTable();
2280				return _INSTANCE_.base_try_usingHandlers_(tryBlock, exceptionHandlers);
2281			}
2282		});
2283		_meths.put("try:using:", new DirectNativeMethod("try:using:") {
2284			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2285				if (ctx.base_receiver() != _INSTANCE_) {
2286					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2287				}
2288				checkArity(args, 2);
2289				ATClosure tryBlock = get(args, 1).asClosure();
2290				ATHandler handler = get(args, 2).asHandler();
2291				return _INSTANCE_.base_try_using_(tryBlock, handler);
2292			}
2293		});
2294		_meths.put("try:using:finally:", new DirectNativeMethod("try:using:finally:") {
2295			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2296				if (ctx.base_receiver() != _INSTANCE_) {
2297					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2298				}
2299				checkArity(args, 3);
2300				ATClosure tryBlock = get(args, 1).asClosure();
2301				ATHandler handler = get(args, 2).asHandler();
2302				ATClosure finallyBlock = get(args, 3).asClosure();
2303				return _INSTANCE_.base_try_using_finally_(tryBlock, handler, finallyBlock);
2304			}
2305		});
2306		_meths.put("try:using:using:", new DirectNativeMethod("try:using:using:") {
2307			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2308				if (ctx.base_receiver() != _INSTANCE_) {
2309					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2310				}
2311				checkArity(args, 3);
2312				ATClosure tryBlock = get(args, 1).asClosure();
2313				ATHandler hdl1 = get(args, 2).asHandler();
2314				ATHandler hdl2 = get(args, 3).asHandler();
2315				return _INSTANCE_.base_try_using_using_(tryBlock, hdl1, hdl2);
2316			}
2317		});
2318		_meths.put("try:using:using:finally:", new DirectNativeMethod("try:using:using:finally:") {
2319			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2320				if (ctx.base_receiver() != _INSTANCE_) {
2321					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2322				}
2323				checkArity(args, 4);
2324				ATClosure tryBlock = get(args, 1).asClosure();
2325				ATHandler hdl1 = get(args, 2).asHandler();
2326				ATHandler hdl2 = get(args, 3).asHandler();
2327				ATClosure finallyBlock = get(args, 4).asClosure();
2328				return _INSTANCE_.base_try_using_using_finally_(tryBlock, hdl1, hdl2, finallyBlock);
2329			}
2330		});
2331		_meths.put("try:using:using:using:", new DirectNativeMethod("try:using:using:using:") {
2332			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2333				if (ctx.base_receiver() != _INSTANCE_) {
2334					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2335				}
2336				checkArity(args, 4);
2337				ATClosure tryBlock = get(args, 1).asClosure();
2338				ATHandler hdl1 = get(args, 2).asHandler();
2339				ATHandler hdl2 = get(args, 3).asHandler();
2340				ATHandler hdl3 = get(args, 4).asHandler();
2341				return _INSTANCE_.base_try_using_using_using_(tryBlock, hdl1, hdl2, hdl3);
2342			}
2343		});
2344		_meths.put("try:using:using:using:finally:", new DirectNativeMethod("try:using:using:using:finally:") {
2345			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2346				if (ctx.base_receiver() != _INSTANCE_) {
2347					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2348				}
2349				checkArity(args, 5);
2350				ATClosure tryBlock = get(args, 1).asClosure();
2351				ATHandler hdl1 = get(args, 2).asHandler();
2352				ATHandler hdl2 = get(args, 3).asHandler();
2353				ATHandler hdl3 = get(args, 4).asHandler();
2354				ATClosure finallyBlock = get(args, 5).asClosure();
2355				return _INSTANCE_.base_try_using_using_using_finally_(tryBlock, hdl1, hdl2, hdl3, finallyBlock);
2356			}
2357		});
2358		_meths.put("try:catch:using:", new DirectNativeMethod("try:catch:using:") {
2359			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2360				if (ctx.base_receiver() != _INSTANCE_) {
2361					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2362				}
2363				checkArity(args, 3);
2364				ATClosure tryBlock = get(args, 1).asClosure();
2365				ATTypeTag filter = get(args, 2).asTypeTag();
2366				ATClosure replacementCode = get(args, 3).asClosure();
2367				return _INSTANCE_.base_try_catch_using_(tryBlock, filter, replacementCode);
2368			}
2369		});
2370		_meths.put("try:catch:using:finally:", new DirectNativeMethod("try:catch:using:finally:") {
2371			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2372				if (ctx.base_receiver() != _INSTANCE_) {
2373					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2374				}
2375				checkArity(args, 4);
2376				ATClosure tryBlock = get(args, 1).asClosure();
2377				ATTypeTag filter = get(args, 2).asTypeTag();
2378				ATClosure replacementCode = get(args, 3).asClosure();
2379				ATClosure finallyBlock = get(args, 4).asClosure();
2380				return _INSTANCE_.base_try_catch_using_finally_(tryBlock, filter, replacementCode, finallyBlock);
2381			}
2382		});
2383		_meths.put("try:catch:using:catch:using:", new DirectNativeMethod("try:catch:using:catch:using:") {
2384			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2385				if (ctx.base_receiver() != _INSTANCE_) {
2386					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2387				}
2388				checkArity(args, 5);
2389				ATClosure tryBlock = get(args, 1).asClosure();
2390				ATTypeTag filter1 = get(args, 2).asTypeTag();
2391				ATClosure hdl1 = get(args, 3).asClosure();
2392				ATTypeTag filter2 = get(args, 4).asTypeTag();
2393				ATClosure hdl2 = get(args, 5).asClosure();
2394				return _INSTANCE_.base_try_catch_using_catch_using_(tryBlock, filter1, hdl1, filter2, hdl2);
2395			}
2396		});
2397		_meths.put("try:catch:using:catch:using:finally:", new DirectNativeMethod("try:catch:using:catch:using:finally:") {
2398			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2399				if (ctx.base_receiver() != _INSTANCE_) {
2400					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2401				}
2402				checkArity(args, 6);
2403				ATClosure tryBlock = get(args, 1).asClosure();
2404				ATTypeTag filter1 = get(args, 2).asTypeTag();
2405				ATClosure hdl1 = get(args, 3).asClosure();
2406				ATTypeTag filter2 = get(args, 4).asTypeTag();
2407				ATClosure hdl2 = get(args, 5).asClosure();
2408				ATClosure finallyBlock = get(args, 6).asClosure();
2409				return _INSTANCE_.base_try_catch_using_catch_using_finally_(tryBlock, filter1, hdl1, filter2, hdl2, finallyBlock);
2410			}
2411		});
2412		_meths.put("handle:with:", new DirectNativeMethod("handle:with:") {
2413			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2414				if (ctx.base_receiver() != _INSTANCE_) {
2415					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2416				}
2417				checkArity(args, 2);
2418				ATTypeTag filter = get(args, 1).asTypeTag();
2419				ATClosure replacementCode = get(args, 2).asClosure();
2420				return _INSTANCE_.base_handle_with_(filter, replacementCode);
2421			}
2422		});
2423		_meths.put("raise:", new DirectNativeMethod("raise:") {
2424			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2425				if (ctx.base_receiver() != _INSTANCE_) {
2426					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2427				}
2428				checkArity(args, 1);
2429				ATObject anExceptionObject = get(args, 1);
2430				return _INSTANCE_.base_raise_(anExceptionObject);
2431			}
2432		});
2433		_meths.put("!", new DirectNativeMethod("!") {
2434			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2435				if (ctx.base_receiver() != _INSTANCE_) {
2436					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2437				}
2438				checkArity(args, 1);
2439				ATBoolean b = get(args, 1).asBoolean();
2440				return _INSTANCE_.base__opnot_(b);
2441			}
2442		});
2443		_meths.put("-", new DirectNativeMethod("-") {
2444			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2445				if (ctx.base_receiver() != _INSTANCE_) {
2446					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2447				}
2448				checkArity(args, 1);
2449				ATNumeric n = get(args, 1).asNativeNumeric();
2450				return _INSTANCE_.base__opmns_(n);
2451			}
2452		});
2453		_meths.put("+", new DirectNativeMethod("+") {
2454			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2455				if (ctx.base_receiver() != _INSTANCE_) {
2456					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2457				}
2458				checkArity(args, 1);
2459				ATNumber n = get(args, 1).asNumber();
2460				return _INSTANCE_.base__oppls_(n);
2461			}
2462		});
2463		_meths.put("read:", new DirectNativeMethod("read:") {
2464			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2465				if (ctx.base_receiver() != _INSTANCE_) {
2466					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2467				}
2468				checkArity(args, 1);
2469				ATText source = get(args, 1).asNativeText();
2470				return _INSTANCE_.base_read_(source);
2471			}
2472		});
2473		_meths.put("eval:in:", new DirectNativeMethod("eval:in:") {
2474			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2475				if (ctx.base_receiver() != _INSTANCE_) {
2476					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2477				}
2478				checkArity(args, 2);
2479				ATAbstractGrammar ast = get(args, 1).asAbstractGrammar();
2480				ATObject obj = get(args, 2);
2481				return _INSTANCE_.base_eval_in_(ast, obj);
2482			}
2483		});
2484		_meths.put("print:", new DirectNativeMethod("print:") {
2485			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2486				if (ctx.base_receiver() != _INSTANCE_) {
2487					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2488				}
2489				checkArity(args, 1);
2490				ATObject obj = get(args, 1);
2491				return _INSTANCE_.base_print_(obj);
2492			}
2493		});
2494		_meths.put("asCode:", new DirectNativeMethod("asCode:") {
2495			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2496				if (ctx.base_receiver() != _INSTANCE_) {
2497					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2498				}
2499				checkArity(args, 1);
2500				ATObject obj = get(args, 1);
2501				return _INSTANCE_.base_asCode_(obj);
2502			}
2503		});
2504		_meths.put("==", new DirectNativeMethod("==") {
2505			public ATObject base_apply(ATTable args, ATContext ctx) throws InterpreterException {
2506				if (ctx.base_receiver() != _INSTANCE_) {
2507					throw new XIllegalOperation("native top-level method invoked on illegal object: "+ctx.base_receiver());
2508				}
2509				checkArity(args, 1);
2510				ATObject comparand = get(args, 1);
2511				return _INSTANCE_.base__opeql__opeql_(comparand);
2512			}
2513		});
2514	}
2515	
2516	/**
2517	 * Overrides the default AmbientTalk native object behavior of extracting native
2518	 * methods based on the 'base_' naming convention. Instead, the lexical root uses
2519	 * an explicit hashmap of native methods. This is much faster than the default
2520	 * behavior, which requires reflection.
2521	 */
2522	protected boolean hasLocalMethod(ATSymbol atSelector) throws InterpreterException {
2523		if  (_meths.containsKey(atSelector.base_text().asNativeText().javaValue)) {
2524			return true;
2525		} else {
2526			return super.hasLocalMethod(atSelector);
2527		}
2528	}
2529
2530	/**
2531	 * @see OBJLexicalRoot#hasLocalMethod(ATSymbol)
2532	 */
2533	protected ATMethod getLocalMethod(ATSymbol selector) throws InterpreterException {
2534		ATMethod val = _meths.get(selector.base_text().asNativeText().javaValue);
2535		if (val == null) {
2536			return super.getLocalMethod(selector);
2537			//throw new XSelectorNotFound(selector, this);			
2538		}
2539		return val;
2540	}
2541    
2542}