[r7647]: sandbox / jlf / internals / notes / expose.txt  Maximize  Restore  History

Download this file

302 lines (240 with data), 13.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
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