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(const char *ds, int di) { resourceLock.request(ds, di); }
77  static inline void releaseResourceLock(const char *ds, int di) { resourceLock.release(ds, di); }
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, const char *imageTarget);
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 
151 /**
152  * Block control for access to the resource lock.
153  */
155 {
156 public:
157  inline ResourceSection(const char *ds, int di) : dbgds(ds), dbgdi(di)
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  const char *dbgds;
194  int dbgdi;
195 };
196 
197 
198 
200 {
201 public:
202  InstanceBlock();
203  InstanceBlock(RexxOption *options);
204  InstanceBlock(PRXSYSEXIT exits, const char *env);
205  ~InstanceBlock();
206 
207  RexxActivity *activity; // our current activity
208  InterpreterInstance *instance; // potential interpreter instance
209 };
210 
211 
212 #endif
#define LITEND
RexxActivity * activity
InterpreterInstance * instance
static size_t getInterpreterVersion()
Definition: Version.cpp:92
static RexxObject * localServer
static bool lastInstance()
static void clearTimeSliceElapsed()
static void live(size_t)
Definition: Interpreter.cpp:83
static void getResourceLock(const char *ds, int di)
Definition: Interpreter.hpp:76
static bool timeSliceElapsed
static void logicError(const char *desc)
static bool hasTimeSliceElapsed()
static void decodeConditionData(RexxDirectory *conditionObj, RexxCondition *condData)
static void releaseResourceLock(const char *ds, int di)
Definition: Interpreter.hpp:77
static void init()
Definition: Interpreter.cpp:77
static wholenumber_t messageNumber(RexxString *)
static RexxString * getVersionNumber()
Definition: Version.cpp:52
static void startInterpreter(InterpreterStartupMode mode, const char *imageTarget)
static void initLocal()
static bool terminateInterpreter()
static bool isActive()
Definition: Interpreter.hpp:92
static bool terminateInterpreterInstance(InterpreterInstance *instance)
static void createLocks()
Definition: Interpreter.hpp:78
static void closeLocks()
Definition: Interpreter.hpp:83
static bool isBigEndian()
static RexxString * versionNumber
static RexxList * interpreterInstances
static void liveGeneral(int reason)
Definition: Interpreter.cpp:90
static RexxClass * findClass(RexxString *className)
static RexxString * getCurrentQueue()
static int createInstance(RexxInstance *&instance, RexxThreadContext *&threadContext, RexxOption *options)
static void processStartup()
static int getWordSize()
static InterpreterInstance * createInterpreterInstance()
Definition: Interpreter.hpp:95
static int initializations
static void setTimeSliceElapsed()
static bool haltAllActivities(RexxString *)
static void processShutdown()
static bool isTerminated()
Definition: Interpreter.hpp:91
static bool active
static size_t getLanguageLevel()
Definition: Version.cpp:103
static SysMutex resourceLock
const char * dbgds
ResourceSection(const char *ds, int di)
void release(const char *ds, int di)
void request(const char *ds, int di)
ssize_t wholenumber_t
Definition: rexx.h:230