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)  

RexxVariable.cpp
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 RexxVariable.c */
40 /* */
41 /* Primitive Variable Class */
42 /* */
43 /****************************************************************************/
44 #include "RexxCore.h"
45 #include "RexxVariable.hpp"
46 #include "RexxActivity.hpp"
47 #include "ActivityManager.hpp"
48 
49 void RexxVariable::live(size_t liveMark)
50 /******************************************************************************/
51 /* Function: Normal garbage collection live marking */
52 /******************************************************************************/
53 {
56  memory_mark(this->dependents);
57 }
58 
59 void RexxVariable::liveGeneral(int reason)
60 /******************************************************************************/
61 /* Function: Normal garbage collection live marking */
62 /******************************************************************************/
63 {
67 }
68 
70 /******************************************************************************/
71 /* Function: Flatten an object */
72 /******************************************************************************/
73 {
75 
76  flatten_reference(newThis->variableValue, envelope);
77  flatten_reference(newThis->variable_name, envelope);
78  flatten_reference(newThis->dependents, envelope);
79 
81 }
82 
84  RexxActivity *informee) /* activity to inform of changes */
85 /****************************************************************************/
86 /* Function: Set up an activity notification for a variable change */
87 /****************************************************************************/
88 {
89  if (this->dependents == OREF_NULL) /* no dependents yet? */
90  {
91  /* set this up as an object table */
92  OrefSet(this, this->dependents, new_identity_table());
93  }
94  /* add this to the table */
95  this->dependents->put(TheNilObject, (RexxObject *)informee);
96 }
97 
99  RexxActivity *informee) /* activity to inform of changes */
100 /****************************************************************************/
101 /* Function: Remove a dependent from the notification list */
102 /****************************************************************************/
103 {
104  /* remove the entry */
105  this->dependents->remove((RexxObject *)informee);
106  if (this->dependents->items() == 0) /* last one? */
107  {
108  /* drop the dependents list */
109  OrefSet(this, this->dependents, OREF_NULL);
110  }
111 }
112 
114 /****************************************************************************/
115 /* Function: Drop a variable */
116 /****************************************************************************/
117 {
118  /* clear out the value */
119  OrefSet(this, this->variableValue, OREF_NULL);
120  if (this->dependents != OREF_NULL) /* have notifications to process? */
121  {
122  this->notify(); /* notify any dependents */
123  }
124 }
125 
127 /****************************************************************************/
128 /* Function: Process all variable notifications */
129 /****************************************************************************/
130 {
131  if (this->dependents != OREF_NULL)
132  { /* any dependents? */
133  /* loop through the table */
134  for (HashLink i = this->dependents->first(); this->dependents->available(i); i = this->dependents->next(i))
135  {
136  /* post the event to the dependent */
137  ((RexxActivity *)this->dependents->index(i))->guardPost();
138  }
139  /* yield control and allow the */
140  /* waiting guard to run too */
141  /* get the current activity */
143  activity->releaseAccess(); /* release the lock */
144  activity->requestAccess(); /* get it back again */
145  }
146 }
147 
148 
150  RexxString *name) /* the name of the variable */
151 /****************************************************************************/
152 /* Function: Create a new REXX variable object */
153 /****************************************************************************/
154 {
155  /* Get new object */
157  newObj->variableValue = OREF_NULL; /* clear out the hash value */
158  newObj->creator = OREF_NULL; /* clear out creator field */
159  newObj->variable_name = name; /* fill in the name */
160  newObj->dependents = OREF_NULL; /* and the dependents */
161  return newObj; /* return the new object */
162 }
163 
RexxHashTableCollection::index
RexxObject * index(HashLink pos)
Definition: RexxCollection.hpp:90
RexxHashTableCollection::next
HashLink next(HashLink pos)
Definition: RexxCollection.hpp:88
RexxVariable.hpp
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
RexxVariable::live
void live(size_t)
Definition: RexxVariable.cpp:49
ActivityManager.hpp
RexxIdentityTable::put
virtual RexxObject * put(RexxObject *, RexxObject *)
Definition: IdentityTableClass.cpp:139
RexxVariable::flatten
void flatten(RexxEnvelope *)
Definition: RexxVariable.cpp:69
RexxVariable::variable_name
RexxString * variable_name
Definition: RexxVariable.hpp:97
RexxHashTableCollection::items
HashLink items()
Definition: RexxCollection.hpp:86
RexxActivity::requestAccess
void requestAccess()
Definition: RexxActivity.cpp:1945
RexxActivity::releaseAccess
void releaseAccess()
Definition: RexxActivity.cpp:1931
RexxEnvelope
Definition: RexxEnvelope.hpp:53
new_identity_table
RexxIdentityTable * new_identity_table()
Definition: IdentityTableClass.hpp:74
RexxHashTableCollection::first
HashLink first()
Definition: RexxCollection.hpp:87
RexxVariable::creator
RexxActivation * creator
Definition: RexxVariable.hpp:99
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
RexxActivity
Definition: RexxActivity.hpp:127
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
RexxVariable::variableValue
RexxObject * variableValue
Definition: RexxVariable.hpp:98
RexxIdentityTable::remove
virtual RexxObject * remove(RexxObject *key)
Definition: IdentityTableClass.cpp:95
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
HashLink
size_t HashLink
Definition: RexxHashTable.hpp:49
RexxVariable::liveGeneral
void liveGeneral(int reason)
Definition: RexxVariable.cpp:59
RexxVariable::dependents
RexxIdentityTable * dependents
Definition: RexxVariable.hpp:100
RexxVariable::notify
void notify()
Definition: RexxVariable.cpp:126
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
TheNilObject
#define TheNilObject
Definition: RexxCore.h:180
ActivityManager::currentActivity
static RexxActivity *volatile currentActivity
Definition: ActivityManager.hpp:95
RexxHashTableCollection::available
bool available(HashLink pos)
Definition: RexxCollection.hpp:91
RexxActivity.hpp
RexxVariable::newInstance
static RexxVariable * newInstance(RexxString *name)
Definition: RexxVariable.cpp:149
RexxCore.h
RexxVariable::uninform
void uninform(RexxActivity *)
Definition: RexxVariable.cpp:98
new_object
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:422
RexxVariable::inform
void inform(RexxActivity *)
Definition: RexxVariable.cpp:83
T_Variable
Definition: ClassTypeCodes.h:126
RexxObject
Definition: ObjectClass.hpp:311
RexxVariable::drop
void drop()
Definition: RexxVariable.cpp:113
RexxString
Definition: StringClass.hpp:119
RexxVariable
Definition: RexxVariable.hpp:49