StackFrameClass.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.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 Kernel */
40 /* */
41 /* Primitive Rexx execution context */
42 /* */
43 /******************************************************************************/
44 #include "RexxCore.h"
45 #include "StackFrameClass.hpp"
46 #include "ProtectedObject.hpp"
47 
48 RexxClass *StackFrameClass::classInstance = OREF_NULL; // singleton class instance
49 
50 /**
51  * Create initial bootstrap objects
52  */
54 {
55  CLASS_CREATE(StackFrame, "StackFrame", RexxClass);
56 }
57 
58 
59 /**
60  * Allocate a new StackFrame object
61  *
62  * @param size The size of the object.
63  *
64  * @return The newly allocated object.
65  */
66 void *StackFrameClass::operator new(size_t size)
67 {
68  /* Get new object */
69  return new_object(size, T_StackFrame);
70 }
71 
72 
73 /**
74  * Allocate a new GC-protected StackFrame object
75  *
76  * @param size The size of the object.
77  * @param p The protected object
78  *
79  * @return The newly allocated object.
80  */
81 void *StackFrameClass::operator new(size_t size, ProtectedObject &p)
82 {
83  /* Get new object */
84  p = new_object(size, T_StackFrame);
85  return p;
86 }
87 
88 
89 /**
90  * Constructor for a StackFrame object.
91  *
92  * @param a The activation we're attached to.
93  */
95 {
96  type = ty;
97  name = n;
98  // interpret stack frames don't have a name, but we need to have a valid
99  // return value if requested, so make this a nullstring.
100  if (name == OREF_NULL)
101  {
102  name = OREF_NULLSTRING;
103  }
104  executable = e;
105  target = tg;
106  arguments = a;
107  traceLine = t;
108  line = l;
109 }
110 
111 
112 /**
113  * The Rexx accessible class NEW method. This raises an
114  * error because StackFrame objects can only be created by the
115  * internal interpreter.
116  *
117  * @param args The NEW args
118  * @param argc The count of arguments
119  *
120  * @return Never returns.
121  */
122 RexxObject *StackFrameClass::newRexx(RexxObject **args, size_t argc, size_t named_argc)
123 {
124  // we do not allow these to be allocated from Rexx code...
126  return TheNilObject;
127 }
128 
129 
130 void StackFrameClass::live(size_t liveMark)
131 /******************************************************************************/
132 /* Function: Normal garbage collection live marking */
133 /******************************************************************************/
134 {
135  memory_mark(this->name);
136  memory_mark(this->executable);
137  memory_mark(this->traceLine);
138  memory_mark(this->arguments);
139  memory_mark(this->target);
140  memory_mark(this->objectVariables);
141 }
142 
144 /******************************************************************************/
145 /* Function: Generalized object marking */
146 /******************************************************************************/
147 {
148  memory_mark_general(this->name);
153  memory_mark_general(this->objectVariables);
154 }
155 
157 /******************************************************************************/
158 /* Function: Flatten an object */
159 /******************************************************************************/
160 {
162 
163  newThis->name = OREF_NULL; // this never should be getting flattened, so sever the connection
164  newThis->executable = OREF_NULL;
165  newThis->traceLine = OREF_NULL;
166  newThis->arguments = OREF_NULL;
167  newThis->target = OREF_NULL;
168  newThis->objectVariables = OREF_NULL;
169 
171 }
172 
173 
174 /**
175  * Return the frame type used to invoke the executable
176  *
177  * @return The string name of the frame type.
178  */
180 {
181  return new_string(type);
182 }
183 
184 
185 /**
186  * Return the name used to invoke the executable
187  *
188  * @return The message or routine name (or program name, for a
189  * top-level invocation
190  */
192 {
193  return name;
194 }
195 
196 
197 /**
198  * Return a trace line for this stack frame
199  *
200  * @return The message or routine name (or program name, for a
201  * top-level invocation
202  */
204 {
205  return traceLine;
206 }
207 
208 
209 /**
210  * Return the stack frame current line position.
211  *
212  * @return The current line number of the context.
213  */
215 {
216  if (executable == OREF_NULL)
217  {
218  return TheNilObject;
219  }
220  return executable;
221 }
222 
223 /**
224  * Return the execution context current line position.
225  *
226  * @return The current line number of the context.
227  */
229 {
230  if (line == SIZE_MAX)
231  {
232  return TheNilObject;
233  }
234  else
235  {
236  return new_integer(line);
237  }
238 }
239 
240 /**
241  * Return an array of arguments to the current activation.
242  *
243  * @return An array of arguments. Returns an empty array if no
244  * arguments.
245  */
247 {
248  if (arguments == OREF_NULL)
249  {
250  return new_array((size_t)0);
251  }
252  else
253  {
254  return arguments;
255  }
256 }
257 
258 
259 /**
260  * Get the source object associated with the stack frame.
261  *
262  * @return The Source object instance for the stack frame.
263  */
265 {
266  if (executable == OREF_NULL)
267  {
268  return OREF_NULL;
269  }
270 
271  return executable->getSourceObject();
272 }
273 
274 
275 /**
276  * Get the message target if this is a method call.
277  *
278  * @return The target object, or .nil if this stack frame is not for a method call.
279  */
281 {
282  if (target == OREF_NULL)
283  {
284  return TheNilObject;
285  }
286  return target;
287 }
288 
289 /**
290  * Default string method override
291  *
292  * @return The trace line
293  */
295 {
296  return getTraceLine();
297 }
298 
299 /**
300  * Default makestring method override
301  *
302  * @return The trace line
303  */
305 {
306  return getTraceLine();
307 }
void reportException(wholenumber_t error)
RexxArray * new_array(size_t s)
Definition: ArrayClass.hpp:259
@ T_StackFrame
RexxInteger * new_integer(wholenumber_t v)
#define OREF_NULL
Definition: RexxCore.h:60
#define TheNilObject
Definition: RexxCore.h:181
#define Error_Unsupported_new_method
#define memory_mark(oref)
Definition: RexxMemory.hpp:445
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:431
#define CLASS_CREATE(name, id, className)
Definition: RexxMemory.hpp:498
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:446
#define cleanUpFlatten
Definition: RexxMemory.hpp:479
#define setUpFlatten(type)
Definition: RexxMemory.hpp:473
RexxString * new_string(const char *s, stringsizeB_t bl, sizeC_t cl=-1)
RexxSource * getSourceObject()
Definition: MethodClass.hpp:85
RexxString * getType()
static RexxClass * classInstance
const char * type
RexxSource * getSourceObject()
RexxObject * target
RexxObject * newRexx(RexxObject **args, size_t argc, size_t named_argc)
virtual RexxString * stringValue()
RexxString * getTraceLine()
RexxArray * arguments
void flatten(RexxEnvelope *)
RexxArray * getArguments()
RexxString * name
static void createInstance()
RexxObject * getLine()
StackFrameClass(const char *type, RexxString *name, BaseExecutable *p, RexxObject *target, RexxArray *arguments, RexxString *t, size_t l)
virtual RexxString * makeString()
RexxString * getName()
RexxObject * getTarget()
BaseExecutable * executable
RexxString * traceLine
void liveGeneral(int reason)
RexxObject * getExecutable()
#define SIZE_MAX