PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://ambienttalk.googlecode.com/
Java | 123 lines | 46 code | 17 blank | 60 comment | 0 complexity | e82c8eeb22cc0bd2dfe04c3f7e833734 MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * NATNil.java created on 15 jul 2007 at 18:33:28
  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.exceptions.InterpreterException;
 31import edu.vub.at.objects.ATBoolean;
 32import edu.vub.at.objects.ATClosure;
 33import edu.vub.at.objects.ATNil;
 34import edu.vub.at.objects.ATObject;
 35import edu.vub.at.objects.ATTable;
 36import edu.vub.at.objects.grammar.ATAssignmentSymbol;
 37import edu.vub.at.objects.grammar.ATSymbol;
 38
 39/**
 40 * This class encapsulates the behaviour of the native
 41 * <tt>nil</tt> AmbientTalk object.
 42 * 
 43 * @author tvcutsem
 44 */
 45public class OBJNil extends NATByCopy implements ATNil {
 46
 47	/**
 48	 * This field holds the sole instance of this class. In AmbientTalk,
 49	 * this is the object that represents <tt>nil</tt>.
 50	 */
 51	public final static OBJNil _INSTANCE_ = new OBJNil();
 52	
 53	/**
 54	 * Constructor made private for singleton design pattern
 55	 */
 56	private OBJNil() { }
 57	
 58	/**
 59	 * Nil has a special parent object which ends the recursion
 60	 * along the dynamic delegation chain. These methods cannot be implemented
 61	 * directly in this class because this class still implements useful
 62	 * <tt>base_</tt> Java methods which have to be invoked by means of the
 63	 * implementations defined in {@link NativeATObject}.
 64	 */
 65	private final NativeATObject dynamicSentinel_ = new NATByCopy() {
 66
 67      private static final long serialVersionUID = -1307795172754062220L;
 68		// METHODS THAT END THE DYNAMIC DELEGATION CHAIN
 69		
 70		public ATBoolean meta_respondsTo(ATSymbol selector) throws InterpreterException {
 71			// no more delegation
 72			return NATBoolean._FALSE_;
 73		}
 74		
 75		/**
 76		 * When performing <tt>o.m()</tt> and <tt>m</tt> is not found, invoke
 77		 * <tt>doesNotUnderStand</tt> and apply the resulting closure to the given arguments.
 78		 */
 79		public ATObject impl_invokeAccessor(ATObject receiver, ATSymbol selector, ATTable arguments) throws InterpreterException {
 80			return receiver.meta_doesNotUnderstand(selector).base_apply(arguments);
 81		}
 82		
 83		public ATObject impl_invokeMutator(ATObject receiver, ATAssignmentSymbol selector, ATTable arguments) throws InterpreterException {
 84			return receiver.meta_doesNotUnderstand(selector).base_apply(arguments);
 85		}
 86
 87		/**
 88		 * When performing <tt>o.x</tt> and <tt>x</tt> is not found, invoke
 89		 * <tt>doesNotUnderStand</tt> and apply the corresponding closure with zero arguments.
 90		 */
 91		public ATObject meta_invokeField(ATObject receiver, ATSymbol selector) throws InterpreterException {
 92			return receiver.meta_doesNotUnderstand(selector).base_apply(NATTable.EMPTY);
 93		}
 94	    
 95	    public ATClosure impl_selectAccessor(ATObject receiver, final ATSymbol selector) throws InterpreterException {
 96	    	return receiver.meta_doesNotUnderstand(selector);
 97	    }
 98
 99		public ATClosure impl_selectMutator(ATObject receiver, final ATAssignmentSymbol selector) throws InterpreterException {
100			return receiver.meta_doesNotUnderstand(selector);
101		}
102
103		public NATText meta_print() throws InterpreterException {
104			return NATText.atValue("dynamicsentinel");
105		}
106	};
107	
108	public ATObject base_super() {
109		return dynamicSentinel_;
110	}
111	
112    /**
113     * After deserialization, ensure that nil remains unique.
114     */
115    public ATObject meta_resolve() throws InterpreterException {
116    	return OBJNil._INSTANCE_;
117    }
118
119	public NATText meta_print() throws InterpreterException {
120		return NATText.atValue("nil");
121	}
122	
123}