ooRexx  4.2.0-source
About: ooRexx (Open Object Rexx) is a free implementation of Object Rexx. Object Rexx is an enhancement of the classic Rexx interpreter; a full-featured programming language with a human-oriented syntax.
  Fossies Dox: ooRexx-4.2.0-source.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

RexxLocalVariables.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Kernel otplocalvariables.hpp*/
40 /* */
41 /* Primitive Run time local variable cache */
42 /* */
43 /******************************************************************************/
44 
45 #ifndef Included_RexxLocalVariables
46 #define Included_RexxLocalVariables
47 
49 
50 #define VDICT_NOVALUE 0x0001u /* novalue traps enabled */
51 #define NESTED_INTERNAL 0x0002u /* this is an internal call without procedure */
52 #define METHOD_CONTEXT 0x0004u /* this is a method context */
53 
54 #define VARIABLE_SELF 1 /* variable lookaside indices */
55 #define VARIABLE_SUPER 2
56 #define VARIABLE_RESULT 3
57 #define VARIABLE_RC 4
58 #define VARIABLE_SIGL 5
59 #define FIRST_VARIABLE_INDEX 5 /* variable index list first slot */
60 
62  public:
63  inline void *operator new(size_t size, void *ptr) { return ptr;};
64  RexxLocalVariables(RexxObject **frames, size_t items) { locals = (RexxVariable **)frames; size = items; }
66 
67  void live(size_t);
68  void liveGeneral(int reason);
69  void migrate(RexxActivity *);
70 
71  /* NOTE: we add one because the size is actually the index */
72  /* number of the last variable in the cache. The zero-th */
73  /* element is used to trigger cache lookup failures. */
74  inline void init(RexxActivation *creator, size_t poolSize) { this->owner = creator; this->size = poolSize + 1; dictionary = OREF_NULL; flags = 0; }
75  inline void setFrame(RexxObject **frame)
76  {
77  locals = (RexxVariable **)frame;
78  memset(locals, 0, sizeof(RexxVariable *) * size);
79  // NOTE: We do NOT reset the variable dictionary. For a new activation,
80  // init() has already reset this. If we're migrating to a new frame after a reply,
81  // then we need to keep the old set of variables active.
82  }
83 
84  RexxVariable *lookupVariable(RexxString *name, size_t index);
85 
86  RexxVariable *findVariable(RexxString *name, size_t index);
87  RexxVariable *lookupStemVariable(RexxString *name, size_t index);
88 
89  void createDictionary();
90 
92  {
93  if (dictionary == OREF_NULL) {
95  }
96  return dictionary;
97  }
98 
99  inline void putVariable(RexxVariable *variable, size_t index)
100  {
101  /* this may be a dynamic addition, so we might not know the */
102  /* index. */
103  if (index != 0) {
104  locals[index] = variable;
105  if (dictionary != OREF_NULL) {
106  dictionary->put(variable, variable->getName());
107  }
108  }
109  else {
110  if (dictionary == OREF_NULL) {
112  }
113  dictionary->put(variable, variable->getName());
114  }
115  }
116 
118 
119  inline RexxVariable *get(size_t index) { return locals[index]; }
120  inline RexxVariable *find(RexxString *name, size_t index)
121  {
122  RexxVariable *variable = get(index);
123  if (variable == OREF_NULL) {
124  variable = findVariable(name, index);
125  }
126  return variable;
127  }
128 
129  inline void setNovalueOn() { this->flags |= VDICT_NOVALUE; };
130  inline void setNovalueOff() { this->flags &= ~VDICT_NOVALUE; };
131  inline bool getNovalue() {return (this->flags & VDICT_NOVALUE) != 0; };
132  inline void setNested() { flags |= NESTED_INTERNAL; }
133  inline void clearNested() { flags &= ~NESTED_INTERNAL; }
134  inline bool isNested() { return (flags&NESTED_INTERNAL) != 0; }
135 
136  inline void procedure(RexxActivation *activation) { this->owner = activation; dictionary = OREF_NULL; flags &= ~NESTED_INTERNAL; }
137  inline void setDictionary(RexxVariableDictionary *dict) { dictionary = dict; }
139 
140  size_t flags; /* dictionary control flags */
141  size_t size; /* size of the expstack */
142  RexxActivation *owner; /* the owning activation */
143  RexxVariable **locals; /* the frame of local variables */
144  RexxVariableDictionary *dictionary; /* dictionary used for dynamic lookups */
145 };
146 #endif
RexxLocalVariables::migrate
void migrate(RexxActivity *)
Definition: RexxLocalVariables.cpp:91
RexxLocalVariables::getNovalue
bool getNovalue()
Definition: RexxLocalVariables.hpp:131
RexxLocalVariables::findVariable
RexxVariable * findVariable(RexxString *name, size_t index)
Definition: RexxLocalVariables.cpp:104
RexxLocalVariables::updateVariable
void updateVariable(RexxVariable *)
Definition: RexxLocalVariables.cpp:289
RexxLocalVariables::clearNested
void clearNested()
Definition: RexxLocalVariables.hpp:133
RexxLocalVariables::putVariable
void putVariable(RexxVariable *variable, size_t index)
Definition: RexxLocalVariables.hpp:99
RexxLocalVariables::setDictionary
void setDictionary(RexxVariableDictionary *dict)
Definition: RexxLocalVariables.hpp:137
RexxLocalVariables::flags
size_t flags
Definition: RexxLocalVariables.hpp:140
RexxLocalVariables::dictionary
RexxVariableDictionary * dictionary
Definition: RexxLocalVariables.hpp:144
RexxLocalVariables::init
void init(RexxActivation *creator, size_t poolSize)
Definition: RexxLocalVariables.hpp:74
RexxVariableDictionary
Definition: RexxVariableDictionary.hpp:55
RexxVariable::getName
RexxString * getName()
Definition: RexxVariable.hpp:74
RexxLocalVariables::RexxLocalVariables
RexxLocalVariables()
Definition: RexxLocalVariables.hpp:65
RexxLocalVariables::liveGeneral
void liveGeneral(int reason)
Definition: RexxLocalVariables.cpp:70
RexxLocalVariables::owner
RexxActivation * owner
Definition: RexxLocalVariables.hpp:142
RexxLocalVariables::RexxLocalVariables
RexxLocalVariables(RexxObject **frames, size_t items)
Definition: RexxLocalVariables.hpp:64
RexxLocalVariables::getDictionary
RexxVariableDictionary * getDictionary()
Definition: RexxLocalVariables.hpp:91
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
RexxLocalVariables::procedure
void procedure(RexxActivation *activation)
Definition: RexxLocalVariables.hpp:136
RexxLocalVariables::setNovalueOff
void setNovalueOff()
Definition: RexxLocalVariables.hpp:130
NESTED_INTERNAL
#define NESTED_INTERNAL
Definition: RexxLocalVariables.hpp:51
RexxActivity
Definition: RexxActivity.hpp:127
RexxLocalVariables::lookupStemVariable
RexxVariable * lookupStemVariable(RexxString *name, size_t index)
Definition: RexxLocalVariables.cpp:219
RexxLocalVariables::find
RexxVariable * find(RexxString *name, size_t index)
Definition: RexxLocalVariables.hpp:120
RexxLocalVariables::size
size_t size
Definition: RexxLocalVariables.hpp:141
RexxLocalVariables::locals
RexxVariable ** locals
Definition: RexxLocalVariables.hpp:143
RexxLocalVariables::live
void live(size_t)
Definition: RexxLocalVariables.cpp:50
RexxLocalVariables
Definition: RexxLocalVariables.hpp:61
RexxLocalVariables::createDictionary
void createDictionary()
Definition: RexxLocalVariables.cpp:337
RexxActivation
Definition: RexxActivation.hpp:156
RexxVariableDictionary::put
void put(RexxVariable *, RexxString *)
Definition: RexxVariableDictionary.cpp:239
RexxLocalVariables::setFrame
void setFrame(RexxObject **frame)
Definition: RexxLocalVariables.hpp:75
RexxLocalVariables::isNested
bool isNested()
Definition: RexxLocalVariables.hpp:134
RexxLocalVariables::getNestedDictionary
RexxVariableDictionary * getNestedDictionary()
Definition: RexxLocalVariables.hpp:138
VDICT_NOVALUE
#define VDICT_NOVALUE
Definition: RexxLocalVariables.hpp:50
RexxLocalVariables::setNested
void setNested()
Definition: RexxLocalVariables.hpp:132
RexxLocalVariables::setNovalueOn
void setNovalueOn()
Definition: RexxLocalVariables.hpp:129
RexxLocalVariables::lookupVariable
RexxVariable * lookupVariable(RexxString *name, size_t index)
Definition: RexxLocalVariables.cpp:155
RexxVariableDictionary.hpp
RexxObject
Definition: ObjectClass.hpp:311
RexxString
Definition: StringClass.hpp:119
RexxLocalVariables::get
RexxVariable * get(size_t index)
Definition: RexxLocalVariables.hpp:119
RexxVariable
Definition: RexxVariable.hpp:49