PageRenderTime 13ms CodeModel.GetById 4ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at_build150307/src/edu/vub/at/objects/ATClosure.java

http://ambienttalk.googlecode.com/
Java | 111 lines | 10 code | 10 blank | 91 comment | 0 complexity | 5eed3be0dc058d72b6360f472e55816b MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * ATClosure.java created on Jul 23, 2006 at 11:52:10 AM
  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;
 29
 30import edu.vub.at.exceptions.InterpreterException;
 31
 32
 33/**
 34 * The public interface to a native AmbientTalk closure (a method + enclosing environment).
 35 * 
 36 * Since ATMethods are always wrapped either at creation time (blocks) or during 
 37 * lookup (methods), ATClosures are by definition the only way methods and blocks 
 38 * can be encountered at the ambienttalk base level. Closures should respond to the
 39 * base_apply method, which should trigger the invocation of their encapsulating method in the
 40 * enclosed closure context.
 41 * 
 42 * Closures are sometimes also 'abused' to simply represent blocks of source code whose
 43 * body has to be evaluated not in the enclosed lexical context, but within the context
 44 * of another object. To facilitate such use, a closure provides the method 'base_applyInScope'
 45 * which will execute the enclosed method in the scope of the given object, rather than
 46 * in the enclosed lexical context.
 47 * 
 48 * @author smostinc
 49 * @author tvcutsem
 50 */
 51public interface ATClosure extends ATObject {
 52	
 53	/**
 54	 * Structural access to the encapsulated method. 
 55	 */
 56	public ATMethod base_getMethod() throws InterpreterException;
 57
 58	/**
 59	 * Structural access to the scope of the closure.
 60	 */
 61	public ATContext base_getContext() throws InterpreterException;
 62	
 63	/**
 64	 * Applies the closure to the given arguments, already wrapped in a table.
 65	 * The enclosed method is executed in the context provided by the closure.
 66	 * 
 67	 * @param args the already evaluated arguments, wrapped in a table
 68	 * @return the value of evaluating the method body in the context of the closure
 69	 */
 70	public ATObject base_apply(ATTable args) throws InterpreterException;
 71	
 72	/**
 73	 * Applies the closure to the given arguments, already wrapped in a table.
 74	 * The enclodes method is executed in the context of the given object. The
 75	 * enclosed closure context is disregarded.
 76	 * 
 77	 * The context provided by an object is always equal to:
 78	 * <tt>ctx(cur=object,self=object,super=object.dynamicParent)</tt>
 79	 * 
 80	 * @param args the already evaluated arguments, wrapped in a table
 81	 * @param scope the object that will act as self and as lexically enclosing scope.
 82	 * @return the value of evaluating the method body in the context of the given object scope
 83	 */
 84	public ATObject base_applyInScope(ATTable args, ATObject scope) throws InterpreterException;
 85	
 86	/**
 87	 * Allows AmbientTalk programmers to write
 88	 * { booleanCondition }.whileTrue: { body }
 89	 * which will execute body as long as the boolean condition evaluates to true.
 90	 */
 91	public ATObject base_whileTrue_(ATClosure body) throws InterpreterException;
 92	
 93	/**
 94	 * { |quit| ... quit(val) ... }.escape()
 95	 * 
 96	 * The escape control construct passes to its receiver block a function which
 97	 * when invoked, immediately transfers control back to the caller of escape,
 98	 * returning the value passed to quit.
 99	 * 
100	 * If no value is passed to quit, nil is returned instead.
101	 * 
102	 * If quit is not invoked during the execution of the receiver block,
103	 * the block terminates normally, with its normal return value.
104	 *   
105	 * If quit is invoked at the point where the call to escape has already returned,
106	 * either normally or via an exception or another escape call,
107	 * invoking quit will raise an XIllegalOperation exception.
108	 */
109	public ATObject base_escape() throws InterpreterException;
110	
111}