RexxActivationStack.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 RexxActivationStack.c */
40 /* */
41 /* Primitive Activation Frame Stack support classes */
42 /* */
43 /* NOTE: activations are an execution time only object. They are never */
44 /* flattened or saved in the image, and hence will never be in old */
45 /* space. Because of this, activations "cheat" and do not use */
46 /* OrefSet to assign values to get better performance. Care must be */
47 /* used to maintain this situation. */
48 /* */
49 /******************************************************************************/
50 #include <ctype.h>
51 #include <string.h>
52 #include "RexxCore.h"
53 #include "RexxActivationStack.hpp"
54 
55 
56 void RexxActivationFrameBuffer::live(size_t liveMark)
57 /******************************************************************************/
58 /* Function: Normal garbage collection live marking */
59 /******************************************************************************/
60 {
61  /* we only mark housekeeping type fields. The main buffer */
62  /* entries are marked by the owning activations. */
63  memory_mark(this->previous);
64 }
65 
67 /******************************************************************************/
68 /* Function: Normal garbage collection live marking */
69 /******************************************************************************/
70 {
72 }
73 
75 /******************************************************************************/
76 /* Function: Flatten an object */
77 /******************************************************************************/
78 {
80  /* we only mark housekeeping type fields. The main buffer */
81  /* entries are marked by the owning activations. */
82 
83  flatten_reference(newThis->previous, envelope);
84 
86 }
87 
88 
89 void RexxActivationStack::live(size_t liveMark)
90 /******************************************************************************/
91 /* Function: Normal garbage collection live marking */
92 /******************************************************************************/
93 {
94  memory_mark(this->current);
95  memory_mark(this->unused);
96 }
97 
99 /******************************************************************************/
100 /* Function: Normal garbage collection live marking */
101 /******************************************************************************/
102 {
105 }
106 
108 /******************************************************************************/
109 /* Function: Initialize a frame stack for a new activity. */
110 /******************************************************************************/
111 {
112  /* create a new frame buffer with the default size. */
114  unused = OREF_NULL;
115 }
116 
118 /******************************************************************************/
119 /* Function: Expand the capacity of the stack to add at least entries */
120 /* additional values on the stack. */
121 /******************************************************************************/
122 {
125  /* do we have an unused one we're holding ready that has enough */
126  /* room? */
127  if (unused != OREF_NULL && unused->hasCapacity(entries))
128  {
129  /* just activate this one for use */
130  next = unused;
131  unused = OREF_NULL;
132  }
133  else
134  {
135  /* create a new frame buffer */
136  next = new_activationFrameBuffer(entries);
137  }
138  /* chain the existing buffer off of the new one */
139  next->push(current);
140  /* set this up as the new current stack */
141  current = next;
142 }
143 
144 
146  size_t entries) /* space for entries in the fame */
147 /******************************************************************************/
148 /* Function: Create a new expression stack */
149 /******************************************************************************/
150 {
151  RexxActivationFrameBuffer *newObj; /* newly created buffer */
152 
153  /* Get new object */
155  newObj->size = entries; /* set the size */
156  newObj->next = 0; /* set the top element */
157  newObj->previous = OREF_NULL; /* no previous element yet */
158  return newObj; /* return the new stack item */
159 }
@ T_ActivationFrameBuffer
RexxActivationFrameBuffer * new_activationFrameBuffer(size_t s)
#define OREF_NULL
Definition: RexxCore.h:60
#define memory_mark(oref)
Definition: RexxMemory.hpp:445
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:431
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:493
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:446
#define cleanUpFlatten
Definition: RexxMemory.hpp:479
#define setUpFlatten(type)
Definition: RexxMemory.hpp:473
static wholenumber_t maxVal(wholenumber_t n1, wholenumber_t n2)
Definition: Numerics.hpp:122
RexxActivationFrameBuffer * previous
void push(RexxActivationFrameBuffer *p)
static RexxActivationFrameBuffer * newInstance(size_t)
void flatten(RexxEnvelope *)
bool hasCapacity(size_t entries)
void expandCapacity(size_t entries)
void liveGeneral(int reason)
RexxActivationFrameBuffer * current
RexxActivationFrameBuffer * unused
size_t stringsize_t
Definition: rexx.h:228