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
#define OREF_NULL
Definition: RexxCore.h:60
#define NESTED_INTERNAL
#define VDICT_NOVALUE
RexxVariable * get(size_t index)
void procedure(RexxActivation *activation)
RexxActivation * owner
RexxVariableDictionary * getDictionary()
void migrate(RexxActivity *)
void updateVariable(RexxVariable *)
void setFrame(RexxObject **frame)
void putVariable(RexxVariable *variable, size_t index)
RexxVariable * findVariable(RexxString *name, size_t index)
void setDictionary(RexxVariableDictionary *dict)
RexxVariable * lookupVariable(RexxString *name, size_t index)
void liveGeneral(int reason)
RexxVariableDictionary * dictionary
RexxVariable * find(RexxString *name, size_t index)
void init(RexxActivation *creator, size_t poolSize)
RexxVariable * lookupStemVariable(RexxString *name, size_t index)
RexxVariableDictionary * getNestedDictionary()
RexxLocalVariables(RexxObject **frames, size_t items)
void put(RexxVariable *, RexxString *)
RexxString * getName()