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)  

RexxCode.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 RexxCode.cpp */
40 /* */
41 /* Primitive Method Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include "RexxCore.h"
48 #include "RexxCode.hpp"
49 #include "ArrayClass.hpp"
50 #include "DirectoryClass.hpp"
51 #include "RexxInstruction.hpp"
52 #include "SourceFile.hpp"
53 #include "ActivityManager.hpp"
54 #include "RexxActivation.hpp"
55 #include <ctype.h>
56 
57 
58 
60  RexxSource * _source, /* source object */
61  RexxInstruction * _start, /* start of the code tree */
62  RexxDirectory * _labels, /* method labels */
63  size_t maxstack, /* max operator stack size */
64  size_t variable_index) /* save of the vdict */
65 /******************************************************************************/
66 /* Function: Initialize a rexxmethod code object */
67 /******************************************************************************/
68 {
69  OrefSet(this, this->source, _source); /* save the program source */
70  OrefSet(this, this->start, _start); /* the parse tree */
71  OrefSet(this, this->labels, _labels); /* the method's labels */
72  /* save the stack info */
73  this->maxStack = maxstack;
74  this->vdictSize = variable_index; /* save the initial vdict size */
75 }
76 
77 
88 void RexxCode::call(RexxActivity *activity, RoutineClass *routine, RexxString *msgname, RexxObject**argPtr, size_t argcount, ProtectedObject &result)
89 {
90  // just forward to the more general method
91  this->call(activity, routine, msgname, argPtr, argcount, OREF_SUBROUTINE, OREF_NULL, EXTERNALCALL, result);
92 }
93 
94 
96  RexxActivity *activity, /* activity running under */
97  RoutineClass *routine, // top level routine instance
98  RexxString *msgname, /* message to be run */
99  RexxObject**argPtr, /* arguments to the method */
100  size_t argcount, /* the count of arguments */
101  RexxString *calltype, /* COMMAND/ROUTINE/FUNCTION */
102  RexxString *environment, /* initial command environment */
103  int context, /* type of context */
104  ProtectedObject &result) // the method result
105 /******************************************************************************/
106 /* Function: Call a method as a top level program or external function call */
107 /******************************************************************************/
108 {
109  // check the stack space before proceeding
110  activity->checkStackSpace(); /* have enough stack space? */
111  /* add to the activity stack */
112  RexxActivation *newacta = ActivityManager::newActivation(activity, routine, this, calltype, environment, context);
113  activity->pushStackFrame(newacta);
114  /* run the method and return result */
115  newacta->run(OREF_NULL, msgname, argPtr, argcount, OREF_NULL, result);
116 }
117 
118 
120  RexxActivity *activity, /* activity running under */
121  RexxMethod *method, // the method object getting invoked
122  RexxObject *receiver, /* object receiving the message */
123  RexxString *msgname, /* message to be run */
124  RexxObject**argPtr, /* arguments to the method */
125  size_t argcount, /* the count of arguments */
126  ProtectedObject &result) // the method result
127 /******************************************************************************/
128 /* Function: Call a method as a top level program or external function call */
129 /******************************************************************************/
130 {
131  RexxActivation *newacta = ActivityManager::newActivation(activity, method, this);
132  /* add to the activity stack */
133  activity->pushStackFrame(newacta);
134  /* run the method and return result */
135  newacta->run(receiver, msgname, argPtr, argcount, OREF_NULL, result);
136  activity->relinquish(); /* yield control now */
137 }
138 
139 
140 void RexxCode::live(size_t liveMark)
141 /******************************************************************************/
142 /* Function: Normal garbage collection live marking */
143 /******************************************************************************/
144 {
145  memory_mark(this->source);
146  memory_mark(this->start);
147  memory_mark(this->labels);
148 }
149 
150 void RexxCode::liveGeneral(int reason)
151 /******************************************************************************/
152 /* Function: Generalized object marking */
153 /******************************************************************************/
154 {
156  memory_mark_general(this->start);
158 }
159 
161 /******************************************************************************/
162 /* Function: Flatten an object */
163 /******************************************************************************/
164 {
166 
167  flatten_reference(newThis->source, envelope);
168  flatten_reference(newThis->start, envelope);
169  flatten_reference(newThis->labels, envelope);
170 
172 }
173 
175 /******************************************************************************/
176 /* Function: Extract the source from a method from the source object as an */
177 /* array of strings. */
178 /******************************************************************************/
179 {
180  SourceLocation location; /* location information */
181  SourceLocation end_location; /* ending location */
182  RexxInstruction *current; /* current instruction */
183 
184  if (this->start == OREF_NULL) /* empty method? */
185  return new_array((size_t)0); /* just return an empty array */
186  location = start->getLocation(); /* get its location info */
187  current = this->start; /* point to the beginning */
188  /* while not at the last one */
189  while (current->nextInstruction != OREF_NULL) {
190  current = current->nextInstruction;/* step to the next one */
191  }
192 
193  end_location = current->getLocation(); /* get the end location */
194  /* copy over the ending position */
195  location.setEndLine(end_location.getEndLine());
196  location.setEndOffset(end_location.getEndOffset());
197  /* go extract the source array */
198  return this->source->extractSource(location);
199 }
200 
202 /******************************************************************************/
203 /* Function: Return the name of the program that contains this method. */
205 {
206  /* retrieve this from the source */
207  return this->source->getProgramName();
208 }
209 
210 
211 void * RexxCode::operator new(size_t size)
212 /******************************************************************************/
213 /* Function: Create a new rexx method code instance */
214 /******************************************************************************/
215 {
216  return new_object(size, T_RexxCode); /* Get new object */
217 }
218 
219 
221 /******************************************************************************/
222 /* Function: Associate a security manager with a method's source */
223 /******************************************************************************/
224 {
225  source->setSecurityManager(manager);
226  return TheTrueObject;
227 }
228 
ActivityManager::newActivation
static RexxActivation * newActivation(RexxActivity *activity, RoutineClass *routine, RexxCode *code, RexxString *calltype, RexxString *environment, int context)
Definition: ActivityManager.cpp:254
new_array
RexxArray * new_array(size_t s)
Definition: ArrayClass.hpp:250
RexxArray
Definition: ArrayClass.hpp:100
RexxInstruction::getLocation
const SourceLocation & getLocation()
Definition: RexxInstruction.hpp:68
RexxActivity::relinquish
void relinquish()
Definition: RexxActivity.cpp:1853
RexxCode::vdictSize
size_t vdictSize
Definition: RexxCode.hpp:104
memory_mark_general
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:437
RexxActivation.hpp
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
RoutineClass
Definition: RoutineClass.hpp:49
RexxCode::labels
RexxDirectory * labels
Definition: RexxCode.hpp:102
ActivityManager.hpp
RexxCode
Definition: RexxCode.hpp:58
RexxInstruction
Definition: RexxInstruction.hpp:54
RexxCode::maxStack
size_t maxStack
Definition: RexxCode.hpp:103
RexxActivity::checkStackSpace
void checkStackSpace()
Definition: RexxActivity.cpp:1964
SourceLocation
Definition: SourceLocation.hpp:48
RexxCode::flatten
void flatten(RexxEnvelope *)
Definition: RexxCode.cpp:160
RexxInstruction.hpp
RexxCode::live
void live(size_t)
Definition: RexxCode.cpp:140
TheTrueObject
#define TheTrueObject
Definition: RexxCore.h:185
RexxEnvelope
Definition: RexxEnvelope.hpp:53
SourceLocation::setEndLine
void setEndLine(size_t l)
Definition: SourceLocation.hpp:58
RexxActivity::pushStackFrame
void pushStackFrame(RexxActivationBase *new_activation)
Definition: RexxActivity.cpp:1462
T_RexxCode
Definition: ClassTypeCodes.h:114
RexxCode::liveGeneral
void liveGeneral(int reason)
Definition: RexxCode.cpp:150
RexxSource
Definition: SourceFile.hpp:131
RexxInstruction::nextInstruction
RexxInstruction * nextInstruction
Definition: RexxInstruction.hpp:85
RexxCode::start
RexxInstruction * start
Definition: RexxCode.hpp:101
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
ArrayClass.hpp
RexxCode::call
virtual void call(RexxActivity *, RoutineClass *, RexxString *, RexxObject **, size_t, RexxString *, RexxString *, int, ProtectedObject &)
Definition: RexxCode.cpp:95
RexxCode::getProgramName
RexxString * getProgramName()
Definition: RexxCode.cpp:201
RexxActivity
Definition: RexxActivity.hpp:127
RexxDirectory
Definition: DirectoryClass.hpp:49
RexxSource::extractSource
RexxArray * extractSource(SourceLocation &)
Definition: SourceFile.cpp:1079
RexxCode::getSource
RexxArray * getSource()
Definition: RexxCode.cpp:174
flatten_reference
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:440
cleanUpFlatten
#define cleanUpFlatten
Definition: RexxMemory.hpp:432
ProtectedObject
Definition: ProtectedObject.hpp:46
memory_mark
#define memory_mark(oref)
Definition: RexxMemory.hpp:436
RexxCode.hpp
SourceLocation::getEndOffset
size_t getEndOffset()
Definition: SourceLocation.hpp:54
RexxSource::getProgramName
RexxString * getProgramName()
Definition: SourceFile.hpp:290
RexxActivation
Definition: RexxActivation.hpp:156
RexxCode::RexxCode
RexxCode(RexxSource *, RexxInstruction *, RexxDirectory *, size_t, size_t)
Definition: RexxCode.cpp:59
RexxCode::run
virtual void run(RexxActivity *, RexxMethod *, RexxObject *, RexxString *, RexxObject **, size_t, ProtectedObject &)
Definition: RexxCode.cpp:119
RexxCode::setSecurityManager
RexxObject * setSecurityManager(RexxObject *)
Definition: RexxCode.cpp:220
setUpFlatten
#define setUpFlatten(type)
Definition: RexxMemory.hpp:427
SourceLocation::getEndLine
size_t getEndLine()
Definition: SourceLocation.hpp:53
RexxActivation::run
RexxObject * run(RexxObject *_receiver, RexxString *msgname, RexxObject **_arglist, size_t _argcount, RexxInstruction *start, ProtectedObject &resultObj)
Definition: RexxActivation.cpp:383
RexxCore.h
DirectoryClass.hpp
RexxMethod
Definition: MethodClass.hpp:101
new_object
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:422
RexxSource::setSecurityManager
void setSecurityManager(RexxObject *manager)
Definition: SourceFile.hpp:366
EXTERNALCALL
#define EXTERNALCALL
Definition: RexxActivation.hpp:141
SourceLocation::setEndOffset
void setEndOffset(size_t l)
Definition: SourceLocation.hpp:59
SourceFile.hpp
RexxObject
Definition: ObjectClass.hpp:311
RexxCode::source
RexxSource * source
Definition: RexxCode.hpp:100
RexxString
Definition: StringClass.hpp:119