edu.vub.at.objects.natives
Class NATClosure

java.lang.Object
  extended byedu.vub.at.objects.natives.NATNil
      extended byedu.vub.at.objects.natives.NATByRef
          extended byedu.vub.at.objects.natives.NATClosure
All Implemented Interfaces:
ATAbstractGrammar, ATClosure, ATConversions, ATExpression, ATNil, ATObject, ATStatement, java.io.Serializable
Direct Known Subclasses:
JavaClosure, NativeClosure

public class NATClosure
extends NATByRef
implements ATClosure

A NATClosure instance represents a first-class AmbientTalk closure. A closure is modelled as a pair (method, context), where the method contains the pure function (function name, arguments and body). The single most important operation to be performed on a closure is applying it. This will give rise to the application of its underlying method within the context wrapped by the closure.

Author:
smostinc
See Also:
Serialized Form

Nested Class Summary
private static class NATClosure.QuitClosureFrame
           
 
Field Summary
protected  ATContext context_
           
protected  ATMethod method_
           
 
Fields inherited from class edu.vub.at.objects.natives.NATNil
_INSTANCE_
 
Constructor Summary
NATClosure(ATMethod method, ATContext context)
           
NATClosure(ATMethod method, ATObject implementor, ATObject receiver)
          This constructor creates a closure with a bound dynamic receiver, and it is called after the succesful lookup of a receiverful message.
 
Method Summary
 ATObject base_apply(ATTable arguments)
          To apply a closure, apply its underlying method with the context of the closure, rather than the runtime context of the invoker.
 ATObject base_applyInScope(ATTable args, ATObject scope)
          To apply a closure in a given scope, apply its underlying method with a new context constructed from the scope object.
 ATClosure base_asClosure()
           
 ATObject base_escape()
          The following is a pseudo-code implementation of escape.
 ATContext base_getContext()
          Structural access to the scope of the closure.
 ATMethod base_getMethod()
          Structural access to the encapsulated method.
 boolean base_isClosure()
           
 ATObject base_whileTrue_(ATClosure body)
          receiver is a zero-argument block closure returning a boolean
 ATTable meta_getStripes()
          Returns the stripes of this object.
 NATText meta_print()
          Prints out the object in a human-readable way.
 
Methods inherited from class edu.vub.at.objects.natives.NATByRef
meta_pass, meta_resolve
 
Methods inherited from class edu.vub.at.objects.natives.NATNil
asAmbientTalkObject, asJavaClassUnderSymbiosis, asJavaObjectUnderSymbiosis, asNativeBoolean, asNativeException, asNativeFarReference, asNativeFraction, asNativeNumber, asNativeNumeric, asNativeTable, asNativeText, base__opeql__opeql_, base_asActorMirror, base_asAsyncMessage, base_asBegin, base_asBoolean, base_asDefinition, base_asExpression, base_asFarReference, base_asField, base_asHandler, base_asMessage, base_asMessageCreation, base_asMethod, base_asMirror, base_asNumber, base_asSplice, base_asStatement, base_asStripe, base_asSymbol, base_asTable, base_asUnquoteSplice, base_asVariableAssignment, base_init, base_isBoolean, base_isCallFrame, base_isFarReference, base_isMessageCreation, base_isMethod, base_isMirror, base_isSplice, base_isStripe, base_isSymbol, base_isTable, base_isUnquoteSplice, base_isVariableAssignment, base_new, createChild, equals, isAmbientTalkObject, isJavaObjectUnderSymbiosis, isNativeBoolean, isNativeField, isNativeText, meta_addField, meta_addMethod, meta_assignField, meta_assignVariable, meta_clone, meta_defineField, meta_doesNotUnderstand, meta_eval, meta_extend, meta_getDynamicParent, meta_getLexicalParent, meta_grabField, meta_grabMethod, meta_invoke, meta_isCloneOf, meta_isRelatedTo, meta_isStripedWith, meta_listFields, meta_listMethods, meta_lookup, meta_newInstance, meta_quote, meta_receive, meta_respondsTo, meta_select, meta_send, meta_share, readResolve, toString, writeReplace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.vub.at.objects.ATObject
base__opeql__opeql_, base_init, base_new, meta_addField, meta_addMethod, meta_assignField, meta_assignVariable, meta_clone, meta_defineField, meta_doesNotUnderstand, meta_eval, meta_extend, meta_getDynamicParent, meta_getLexicalParent, meta_grabField, meta_grabMethod, meta_invoke, meta_isCloneOf, meta_isRelatedTo, meta_isStripedWith, meta_listFields, meta_listMethods, meta_lookup, meta_newInstance, meta_pass, meta_quote, meta_receive, meta_resolve, meta_respondsTo, meta_select, meta_send, meta_share
 
Methods inherited from interface edu.vub.at.objects.coercion.ATConversions
asAmbientTalkObject, asJavaClassUnderSymbiosis, asJavaObjectUnderSymbiosis, asNativeBoolean, asNativeException, asNativeFarReference, asNativeFraction, asNativeNumber, asNativeNumeric, asNativeTable, asNativeText, base_asActorMirror, base_asAsyncMessage, base_asBegin, base_asBoolean, base_asDefinition, base_asExpression, base_asFarReference, base_asField, base_asHandler, base_asMessage, base_asMessageCreation, base_asMethod, base_asMirror, base_asNumber, base_asSplice, base_asStatement, base_asStripe, base_asSymbol, base_asTable, base_asUnquoteSplice, base_asVariableAssignment, base_isBoolean, base_isCallFrame, base_isFarReference, base_isMessageCreation, base_isMethod, base_isMirror, base_isSplice, base_isStripe, base_isSymbol, base_isTable, base_isUnquoteSplice, base_isVariableAssignment, isAmbientTalkObject, isJavaObjectUnderSymbiosis, isNativeBoolean, isNativeField, isNativeText
 

Field Detail

method_

protected ATMethod method_

context_

protected ATContext context_
Constructor Detail

NATClosure

public NATClosure(ATMethod method,
                  ATObject implementor,
                  ATObject receiver)
           throws InterpreterException
This constructor creates a closure with a bound dynamic receiver, and it is called after the succesful lookup of a receiverful message.

Parameters:
method - the method being wrapped into a closure.
implementor - the object in which the definition is nested.
receiver - the object where the lookup was initiated.

NATClosure

public NATClosure(ATMethod method,
                  ATContext context)
Method Detail

base_apply

public ATObject base_apply(ATTable arguments)
                    throws InterpreterException
To apply a closure, apply its underlying method with the context of the closure, rather than the runtime context of the invoker.

Specified by:
base_apply in interface ATClosure
Parameters:
arguments - the already evaluated arguments, wrapped in a table
Returns:
the value of evaluating the method body in the context of the closure
Throws:
InterpreterException

base_applyInScope

public ATObject base_applyInScope(ATTable args,
                                  ATObject scope)
                           throws InterpreterException
To apply a closure in a given scope, apply its underlying method with a new context constructed from the scope object.

Specified by:
base_applyInScope in interface ATClosure
Parameters:
args - the already evaluated arguments, wrapped in a table
scope - the object that will act as self and as lexically enclosing scope.
Returns:
the value of evaluating the method body in the context of the given object scope
Throws:
InterpreterException

base_whileTrue_

public ATObject base_whileTrue_(ATClosure body)
                         throws InterpreterException
receiver is a zero-argument block closure returning a boolean

Specified by:
base_whileTrue_ in interface ATClosure
Parameters:
body - a zero-argument block closure def whileTrue: body { self.apply().ifTrue: { body(); self.whileTrue: body } }
Throws:
InterpreterException

base_escape

public ATObject base_escape()
                     throws InterpreterException
The following is a pseudo-code implementation of escape. The important difference between the native implementation and this pseudo-code is that the 'escaping exception' can *not* be caught at the AmbientTalk level. The SignalEscape is a truly native exception. def block.escape() { def returned := false; def quit(@args) { if: (returned) then: { raise: XIllegalOperation.new("Cannot quit, escape activation already returned") } else: { raise: SignalEscape.new(block, if: (args.isEmpty()) then: nil else: args[1]) } }; try: { block(quit); } catch: SignalEscape using: {|e| if: (e.block == block) then: { e.val } else: { raise: e } } finally: { // doesn't yet exist in AT/2 returned := true; } }

Specified by:
base_escape in interface ATClosure
Throws:
InterpreterException

base_getContext

public ATContext base_getContext()
                          throws InterpreterException
Description copied from interface: ATClosure
Structural access to the scope of the closure.

Specified by:
base_getContext in interface ATClosure
Throws:
InterpreterException

base_getMethod

public ATMethod base_getMethod()
Description copied from interface: ATClosure
Structural access to the encapsulated method.

Specified by:
base_getMethod in interface ATClosure

base_isClosure

public boolean base_isClosure()
Specified by:
base_isClosure in interface ATConversions
Overrides:
base_isClosure in class NATNil

base_asClosure

public ATClosure base_asClosure()
Specified by:
base_asClosure in interface ATConversions
Overrides:
base_asClosure in class NATNil

meta_print

public NATText meta_print()
                   throws InterpreterException
Description copied from interface: ATObject
Prints out the object in a human-readable way.

Specified by:
meta_print in interface ATObject
Overrides:
meta_print in class NATNil
Throws:
InterpreterException

meta_getStripes

public ATTable meta_getStripes()
                        throws InterpreterException
Description copied from interface: ATObject
Returns the stripes of this object. Note that only the stripes that were attached directly to this object are returned, not all of the parent's stripes as well.

Specified by:
meta_getStripes in interface ATObject
Overrides:
meta_getStripes in class NATNil
Throws:
InterpreterException