Some notes taken while thinking about closures.


=====================================================================================
Abandoned : add support for expose in routines (now using a method)
=====================================================================================

RexxActivation.hpp
(after procedureExpose)
   void              routineExpose(RexxVariableBase **variables, size_t count);


RexxActivation.cpp
void RexxActivation::routineExpose(
    RexxVariableBase **variables, size_t count)
/******************************************************************************/
/* Function:  Expose variables for a routine                                  */
/******************************************************************************/
{
    /* get a new  */
    activity->allocateLocalVariableFrame(&settings.local_variables);
    /* make sure we clear out the dictionary, otherwise we'll see the */
    /* dynamic entries from the previous level. */
    settings.local_variables.procedure(this);

    for (size_t i = 0; i < count; i++)
    {
        variables[i]->procedureExpose(this, parent, &stack);
    }
}


=====================================================================================
Variables
=====================================================================================

RexxLocalVariables.hpp
    #define VARIABLE_SELF    1             /* variable lookaside indices        */
    #define VARIABLE_SUPER   2
    #define VARIABLE_RESULT  3
    #define VARIABLE_RC      4
    #define VARIABLE_SIGL    5
    #define FIRST_VARIABLE_INDEX 5         /* variable index list first slot    */


----------
Data model
----------

RexxLocalVariables
    size_t flags;                        /* dictionary control flags          */
    size_t size;                         /* size of the expstack              */
    RexxActivation *owner;               /* the owning activation             */
    RexxVariable **locals;               /* the frame of local variables      */    <-- locals->setFrame(frameStack.allocateFrame(locals->size));    <-- frameStack is an attribute of RexxActivity (type RexxActivationStack)
    RexxVariableDictionary *dictionary;  /* dictionary used for dynamic lookups */


RexxActivation : public RexxActivationBase 
   ActivationSettings   settings;      /* inherited REXX settings           */


ActivationSettings
    RexxLocalVariables local_variables;  /* the local variables for this activation */


=====================================================================================
Code review for method expose
=====================================================================================

ExposeInstruction.cpp
class RexxInstructionExpose : public RexxInstruction {
  size_t            variableCount;     // number of variables to expose
  RexxVariableBase *variables[1];      // list of variables for EXPOSE


void RexxInstructionExpose::execute(
            RexxActivation      *context,      /* current activation context        */
            RexxExpressionStack *stack)        /* evaluation stack                  */
    context->expose(variables, variableCount);


void RexxActivation::expose(RexxVariableBase **variables, size_t count)
{
    /* get the variable set for this object */
    RexxVariableDictionary * object_variables = getObjectVariables();

    /* now expose each individual variable */
    for (size_t i = 0; i < count; i++)
    {
        variables[i]->expose(this, &stack, object_variables);
    }
}


ExpressionBaseVariable.hpp
class RexxVariableBase : public RexxInternalObject {
  virtual void expose(RexxActivation *, RexxExpressionStack *, RexxVariableDictionary *) {;}

Subclasses of RexxVariableVase :
    RexxCompoundVariable (ExpressionCompoundVariable)
    RexxDotVariable (ExpressionDotVariable.hpp) --> no expose
    RexxExpressionMessage (ExpressionMessage.hpp) --> no expose
    RexxStemVariable (ExpressionStem.hpp)
    RexxParseVariable (ExpressionVariable.hpp)
    RexxVariableReference (IndirectVariableReference.hpp)
    

ExpressionVariable.cpp
void RexxParseVariable::expose(
  RexxActivation      *context,        /* current activation context        */
  RexxExpressionStack *stack,          /* current evaluation stack          */
                                       /* variable scope we're exposing from*/
  RexxVariableDictionary *object_dictionary)
{
    /* get the old variable entry        */
    RexxVariable *old_variable = object_dictionary->getVariable(variableName);
    /* set the entry in the new table    */
    context->putLocalVariable(old_variable, index);
}


ExpressionCompoundVariable.cpp
void RexxCompoundVariable::expose(
  RexxActivation      *context,        /* current activation context        */
  RexxExpressionStack *stack,          /* current evaluation stack          */
                                       /* variable scope we're exposing from*/
  RexxVariableDictionary *object_dictionary)
{
    /* get the stem in the source dictionary */
    RexxStem *source_stem = object_dictionary->getStem(stemName);
                                          /* new tail for compound             */
    RexxCompoundTail resolved_tail(context, &tails[0], tailCount);
    /* first get (and possible create) the compound variable in the */
    /* object context. */
    RexxCompoundElement *variable = source_stem->exposeCompoundVariable(&resolved_tail);
    /* get the stem index from the current level.  This may end up */
    /* creating the stem that holds the exposed value. */
    RexxStem *stem_table = context->getLocalStem(stemName, index);
    /* have the stem expose this */
    stem_table->expose(variable);
    /* tracing intermediate values?      */
    if (context->tracingIntermediates()) {
        /* trace resolved compound name */
        context->traceCompoundName(stemName, (RexxObject **)&tails[0], tailCount, variable->getName());
    }
}


StemClass.cpp
void RexxStem::expose( RexxCompoundElement *old_variable) /* the parent compound variable     */
{
    /* create the equivalent in this stem */
    RexxCompoundElement *new_variable = tails.findEntry(old_variable->getName(), true);
    new_variable->expose(old_variable);  /* make the association between the two */
}


InstructionParser.cpp
RexxInstruction *RexxSource::exposeNew()
{
    this->isExposeValid();               /* validate the placement            */
                                         /* go process the list               */
    size_t variableCount = this->processVariableList(KEYWORD_EXPOSE);
    /* Get new object                    */
    RexxInstruction *newObject = new_variable_instruction(EXPOSE, Expose, sizeof(RexxInstructionExpose) + (variableCount - 1) * sizeof(RexxObject *));
    /* Initialize this new method        */
    new ((void *)newObject) RexxInstructionExpose(variableCount, this->subTerms);
    return newObject; /* done, return this                 */
}


SourceFile.cpp
size_t RexxSource::processVariableList(
    Iterator over the tokens :
       if the token is a variable name
            retriever = this->addText(token);/* get a retriever for this          */
            this->subTerms->push(retriever); /* add to the variable list          */
            if (type == KEYWORD_EXPOSE)      /* this an expose operation?         */
            {
                this->expose(token->value);    /* add to the expose list too        */
            }
            list_count++;                    /* record the variable               */
       else if the token is a variable reference
            retriever = this->addText(token);/* get a retriever for this          */
                                             /* make this an indirect reference   */
            retriever = (RexxObject *)new RexxVariableReference((RexxVariableBase *)retriever);
            this->subTerms->queue(retriever);/* add to the variable list          */
            this->currentstack++;            /* account for the varlists          */
       else error


SourceFile.cpp
RexxInstruction *RexxSource::instruction()
                case KEYWORD_EXPOSE:       /* EXPOSE instruction                */
                    refineSubclass(_first, IS_KEYWORD);
                    /* interpreted?                      */
                    if (this->flags&_interpret)
                        syntaxError(Error_Translation_expose_interpret);
                    /* add the instruction to the parse  */
                    _instruction = this->exposeNew();
                    break;


=====================================================================================
Code review for procedure expose
=====================================================================================

---------------
procedureExpose
---------------
    ProcedureInstruction.cpp
        void RexxInstructionProcedure::execute(
            RexxActivation      *context,      /* current activation context        */
            RexxExpressionStack *stack)        /* evaluation stack                  */
            ...
            context->procedureExpose(variables, variableCount);
            ...
    RexxActivation.hpp
        void              procedureExpose(RexxVariableBase **variables, size_t count);

    RexxActivation.cpp
        void RexxActivation::procedureExpose(RexxVariableBase **variables, size_t count)
            activity->allocateLocalVariableFrame(&settings.local_variables);

    ExpressionBaseVariable.hpp
        class RexxVariableBase
            virtual void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *) {;}

    ExpressionCompoundVariable.hpp
        class RexxCompoundVariable : public RexxVariableBase {
            void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *);

    ExpressionCompoundVariable.cpp
        void RexxCompoundVariable::procedureExpose(
            RexxActivation      *context,        /* current activation context        */
            RexxActivation      *parent,         /* the parent activation context     */
            RexxExpressionStack *stack)          /* current evaluation stack          */

    ExpressionStem.hpp
        class RexxStemVariable : public RexxVariableBase {
            void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *);

    ExpressionStem.cpp
        void RexxStemVariable::procedureExpose(
            RexxActivation      *context,        /* current activation context        */
            RexxActivation      *parent,         /* the parent activation context     */
            RexxExpressionStack *stack)          /* current evaluation stack          */

    ExpressionVariable.hpp
        class RexxParseVariable : public RexxVariableBase {
            void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *);
    ExpressionVariable.cpp
        void RexxParseVariable::procedureExpose(
            RexxActivation      *context,        /* current activation context        */
            RexxActivation      *parent,         /* the parent activation context     */
            RexxExpressionStack *stack)          /* current evaluation stack          */

    IndirectVariableReference.hpp
        class RexxVariableReference : public RexxVariableBase {
            void procedureExpose(RexxActivation *, RexxActivation *, RexxExpressionStack *);

    IndirectVariableReference.cpp
        void RexxVariableReference::procedureExpose(
            RexxActivation      *context,        /* current activation context        */
            RexxActivation      *parent,         /* the parent activation context     */
            RexxExpressionStack *stack)          /* current evaluation stack          */


--------------------------
allocateLocalVariableFrame
--------------------------

    RexxActivity.hpp
       inline void allocateLocalVariableFrame(RexxLocalVariables *locals)   <-- locals = &aRexxActivation.settings.local_variables
       {
           locals->setFrame(frameStack.allocateFrame(locals->size));    <-- frameStack is an attribute of RexxActivity (type RexxActivationStack)
       }
       
    RexxActivation.cpp
    
        RexxActivation::RexxActivation(RexxActivity* _activity, RexxMethod * _method, RexxCode *_code)
            /* allocate a frame for the local variables from activity stack */
            settings.local_variables.init(this, code->getLocalVariableSize());
            this->activity->allocateLocalVariableFrame(&settings.local_variables);
            
        RexxActivation::RexxActivation(RexxActivity *_activity, RoutineClass *_routine, RexxCode *_code, RexxString *calltype, RexxString *env, int context)
            /* allocate a frame for the local variables from activity stack */
            settings.local_variables.init(this, code->getLocalVariableSize());
            this->activity->allocateLocalVariableFrame(&settings.local_variables);
            
        void RexxActivation::procedureExpose(
            /* get a new  */
            RexxVariableBase **variables, size_t count)
            activity->allocateLocalVariableFrame(&settings.local_variables);
            /* make sure we clear out the dictionary, otherwise we'll see the */
            /* dynamic entries from the previous level. */
            settings.local_variables.procedure(this);
            
    RexxLocalVariables.cpp
    

