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)  

Interpreter.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.ibm.com/developerworks/oss/CPLv1.0.htm */
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 Windows Support */
40 /* */
41 /* Main interpreter control. This is the preferred location for all */
42 /* platform independent global variables. */
43 /* The interpreter does not instantiate an instance of this */
44 /* class, so most variables and methods should be static. */
45 /* */
46 /* */
47 /*****************************************************************************/
48 
49 #ifndef RexxInterpreter_Included
50 #define RexxInterpreter_Included
51 
52 #include "RexxCore.h"
53 #include "SysSemaphore.hpp"
54 
56 class RexxList;
57 class RexxActivity;
58 
60 {
61 public:
62  typedef enum
63  {
64  SAVE_IMAGE_MODE = 0, // image creation
65  RUN_MODE = 1 // normal run mode
67 
68  static void init();
69 
70  static void live(size_t);
71  static void liveGeneral(int reason);
72 
73  static void processStartup();
74  static void processShutdown();
75 
76  static inline void getResourceLock() { resourceLock.request(); }
77  static inline void releaseResourceLock() { resourceLock.release(); }
78  static inline void createLocks()
79  {
81  }
82 
83  static inline void closeLocks()
84  {
86  }
87 
88  static int createInstance(RexxInstance *&instance, RexxThreadContext *&threadContext, RexxOption *options);
89  static bool terminateInterpreter();
90  static void startInterpreter(InterpreterStartupMode mode);
91  static inline bool isTerminated() { return !active; }
92  static inline bool isActive() { return active; }
93  static bool lastInstance();
97  static RexxString *getVersionNumber();
98  static void initLocal();
99  static size_t getInterpreterVersion();
100  static size_t getLanguageLevel();
101 
102  static inline bool hasTimeSliceElapsed()
103  {
104  // if we've had a time slice event, flip the event flag and return true
105  if (timeSliceElapsed)
106  {
107  timeSliceElapsed = false;
108  return true;
109  }
110  // not time to break
111  return false;
112  }
113 
114  static inline int getWordSize()
115  {
116  return sizeof(void *) * 8;
117  }
118 
119  static inline bool isBigEndian()
120  {
121  static const int mfcone=1; // constant 1
122  static const char *mfctop=(char *)&mfcone; // -> top byte
123  #define LITEND *mfctop // named flag; 1=little-endian
124 
125  return LITEND == 0;
126  }
127 
128 
129  static void logicError (const char *desc);
131  static inline void setTimeSliceElapsed() { timeSliceElapsed = true; }
132  static inline void clearTimeSliceElapsed() { timeSliceElapsed = false; }
133  static bool haltAllActivities(RexxString *);
134  static void decodeConditionData(RexxDirectory *conditionObj, RexxCondition *condData);
135  static RexxClass *findClass(RexxString *className);
136  static RexxString *getCurrentQueue();
137 
138  static RexxObject *localServer; // local environment initialization server
139 
140 
141 protected:
142  static SysMutex resourceLock; // use to lock resources accessed outside of kernel global lock
143  static int initializations; // indicates whether we're terminated or not
144  static bool timeSliceElapsed; // indicates we've had a timer interrupt
145  static RexxList *interpreterInstances; // the set of interpreter instances
146  static bool active; // indicates whether the interpreter is initialized
147  static RexxString *versionNumber; // our version number information
148 };
149 
150 
155 {
156 public:
158  {
160  terminated = false;
161  }
162 
164  {
165  if (!terminated)
166  {
168  }
169  }
170 
171  inline void release()
172  {
173  if (!terminated)
174  {
176  terminated = true;
177  }
178  }
179 
180 
181  inline void reacquire()
182  {
183  if (terminated)
184  {
186  terminated = false;
187  }
188  }
189 
190 private:
191 
192  bool terminated; // we can release these as needed
193 };
194 
195 
196 
198 {
199 public:
200  InstanceBlock();
201  InstanceBlock(RexxOption *options);
202  InstanceBlock(PRXSYSEXIT exits, const char *env);
203  ~InstanceBlock();
204 
205  RexxActivity *activity; // our current activity
206  InterpreterInstance *instance; // potential interpreter instance
207 };
208 
209 
210 #endif
SysMutex::create
void create()
Definition: SysSemaphore.cpp:238
Interpreter::startInterpreter
static void startInterpreter(InterpreterStartupMode mode)
Definition: Interpreter.cpp:124
InstanceBlock::activity
RexxActivity * activity
Definition: Interpreter.hpp:205
Interpreter::setTimeSliceElapsed
static void setTimeSliceElapsed()
Definition: Interpreter.hpp:131
Interpreter::haltAllActivities
static bool haltAllActivities(RexxString *)
Definition: Interpreter.cpp:349
Interpreter::getInterpreterVersion
static size_t getInterpreterVersion()
Definition: Version.cpp:92
Interpreter::findClass
static RexxClass * findClass(RexxString *className)
Definition: Interpreter.cpp:520
Interpreter::active
static bool active
Definition: Interpreter.hpp:146
Interpreter::live
static void live(size_t)
Definition: Interpreter.cpp:83
InstanceBlock::instance
InterpreterInstance * instance
Definition: Interpreter.hpp:206
Interpreter::InterpreterStartupMode
InterpreterStartupMode
Definition: Interpreter.hpp:62
Interpreter::localServer
static RexxObject * localServer
Definition: Interpreter.hpp:138
Interpreter::RUN_MODE
Definition: Interpreter.hpp:65
Interpreter::isBigEndian
static bool isBigEndian()
Definition: Interpreter.hpp:119
Interpreter::lastInstance
static bool lastInstance()
Definition: Interpreter.cpp:239
RexxThreadContext_
Definition: oorexxapi.h:710
Interpreter::versionNumber
static RexxString * versionNumber
Definition: Interpreter.hpp:147
Interpreter::decodeConditionData
static void decodeConditionData(RexxDirectory *conditionObj, RexxCondition *condData)
Definition: Interpreter.cpp:460
RexxCondition
Definition: oorexxapi.h:423
Interpreter::closeLocks
static void closeLocks()
Definition: Interpreter.hpp:83
SysSemaphore.hpp
ResourceSection::reacquire
void reacquire()
Definition: Interpreter.hpp:181
SysMutex::close
void close()
Definition: SysSemaphore.cpp:287
ResourceSection::ResourceSection
ResourceSection()
Definition: Interpreter.hpp:157
ResourceSection
Definition: Interpreter.hpp:154
Interpreter::messageNumber
static wholenumber_t messageNumber(RexxString *)
Definition: Interpreter.cpp:562
Interpreter::initLocal
static void initLocal()
Definition: Interpreter.cpp:167
Interpreter::releaseResourceLock
static void releaseResourceLock()
Definition: Interpreter.hpp:77
Interpreter::timeSliceElapsed
static bool timeSliceElapsed
Definition: Interpreter.hpp:144
Interpreter::createLocks
static void createLocks()
Definition: Interpreter.hpp:78
RexxActivity
Definition: RexxActivity.hpp:127
Interpreter::getWordSize
static int getWordSize()
Definition: Interpreter.hpp:114
ResourceSection::terminated
bool terminated
Definition: Interpreter.hpp:192
RexxDirectory
Definition: DirectoryClass.hpp:49
RexxClass
Definition: ClassClass.hpp:49
Interpreter::isActive
static bool isActive()
Definition: Interpreter.hpp:92
ResourceSection::~ResourceSection
~ResourceSection()
Definition: Interpreter.hpp:163
Interpreter::processShutdown
static void processShutdown()
Definition: Interpreter.cpp:109
_RXSYSEXIT
Definition: rexx.h:190
SysMutex
Definition: SysSemaphore.hpp:73
SysMutex::request
void request()
Definition: SysSemaphore.hpp:81
InstanceBlock
Definition: Interpreter.hpp:197
Interpreter::getResourceLock
static void getResourceLock()
Definition: Interpreter.hpp:76
RexxOption
Definition: oorexxapi.h:416
Interpreter::getVersionNumber
static RexxString * getVersionNumber()
Definition: Version.cpp:52
ResourceSection::release
void release()
Definition: Interpreter.hpp:171
Interpreter::SAVE_IMAGE_MODE
Definition: Interpreter.hpp:64
Interpreter::init
static void init()
Definition: Interpreter.cpp:77
Interpreter::liveGeneral
static void liveGeneral(int reason)
Definition: Interpreter.cpp:90
Interpreter::processStartup
static void processStartup()
Definition: Interpreter.cpp:100
LITEND
#define LITEND
Interpreter::clearTimeSliceElapsed
static void clearTimeSliceElapsed()
Definition: Interpreter.hpp:132
wholenumber_t
ssize_t wholenumber_t
Definition: rexx.h:229
InterpreterInstance
Definition: InterpreterInstance.hpp:55
Interpreter::getCurrentQueue
static RexxString * getCurrentQueue()
Definition: Interpreter.cpp:540
Interpreter::terminateInterpreter
static bool terminateInterpreter()
Definition: Interpreter.cpp:187
Interpreter::initializations
static int initializations
Definition: Interpreter.hpp:143
Interpreter::interpreterInstances
static RexxList * interpreterInstances
Definition: Interpreter.hpp:145
Interpreter::isTerminated
static bool isTerminated()
Definition: Interpreter.hpp:91
Interpreter::terminateInterpreterInstance
static bool terminateInterpreterInstance(InterpreterInstance *instance)
Definition: Interpreter.cpp:335
Interpreter::resourceLock
static SysMutex resourceLock
Definition: Interpreter.hpp:142
Interpreter::createInstance
static int createInstance(RexxInstance *&instance, RexxThreadContext *&threadContext, RexxOption *options)
Definition: Interpreter.cpp:256
Interpreter::getLanguageLevel
static size_t getLanguageLevel()
Definition: Version.cpp:103
Interpreter::createInterpreterInstance
static InterpreterInstance * createInterpreterInstance()
Definition: Interpreter.hpp:95
InstanceBlock::InstanceBlock
InstanceBlock()
Definition: Interpreter.cpp:374
RexxCore.h
RexxList
Definition: ListClass.hpp:63
Interpreter::logicError
static void logicError(const char *desc)
Definition: Interpreter.cpp:553
Interpreter
Definition: Interpreter.hpp:59
RexxInstance_
Definition: oorexxapi.h:677
InstanceBlock::~InstanceBlock
~InstanceBlock()
Definition: Interpreter.cpp:439
SysMutex::release
void release()
Definition: SysSemaphore.hpp:82
RexxObject
Definition: ObjectClass.hpp:311
RexxString
Definition: StringClass.hpp:119
Interpreter::hasTimeSliceElapsed
static bool hasTimeSliceElapsed()
Definition: Interpreter.hpp:102