# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

opcode_call_method.cpp

Go to the documentation of this file.
00001 
00006 /* Copyright, 2000 Nevrax Ltd.
00007  *
00008  * This file is part of NEVRAX NEL.
00009  * NEVRAX NEL is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013 
00014  * NEVRAX NEL is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * General Public License for more details.
00018 
00019  * You should have received a copy of the GNU General Public License
00020  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00022  * MA 02111-1307, USA.
00023  */
00024 
00025 #include "nel/ai/script/compilateur.h"
00026 #include "nel/ai/agent/agent_script.h"
00027 #include "nel/ai/script/interpret_object_agent.h"
00028 #include "nel/ai/script/interpret_object_message.h"
00029 
00030 namespace NLAISCRIPT
00031 {
00032         //*************************************
00033         // CMethodContext
00034         //*************************************
00035         const IMethodContext *CMethodContext::clone() const
00036         {
00037                 return new CMethodContext();
00038         }
00039         
00040         void CMethodContext::saveConstext(CCodeContext &context)
00041         {
00042                 NLAIAGENT::IBaseGroupType *param = (NLAIAGENT::IBaseGroupType *)context.Stack[(int)context.Stack];
00043                 NLAIAGENT::CIteratorContener It = param->getIterator();
00044                 uint z = 0;
00045                 while(!It.isInEnd())
00046                 {                       
00047                         NLAIAGENT::IObjectIA *o = (NLAIAGENT::IObjectIA *)It++;
00048                         o->incRef();
00049                         context.Heap[(int)context.Heap] = o;
00050                         context.Heap ++;
00051                         z ++;
00052                 }                               
00053                 int bp = (int)context.Heap;
00054                 CVarPStackParam::_Shift += bp;
00055                 context.Heap.addStack(z);
00056                 context.Heap.setShift((int)context.Heap);
00057                 context.Param.push_back(param);
00058                 param->incRef();
00059                 context.Stack --;
00060                 
00061         }
00062 
00063         void CMethodContext::loadConstext(CCodeContext &context)
00064         {
00065                 context.Heap.restoreShift();
00066                 context.Heap.restoreStack();
00067                 context.Param.back()->release();
00068                 context.Param.pop_back();
00069         }
00070 
00071         //*************************************
00072         // CMethodContextDebug
00073         //*************************************
00074         const IMethodContext *CMethodContextDebug::clone() const
00075         {
00076                 return new CMethodContextDebug();
00077         }
00078         
00079         void CMethodContextDebug::saveConstext(CCodeContext &context)
00080         {
00081                 NLAIAGENT::IBaseGroupType *param = (NLAIAGENT::IBaseGroupType *)context.Stack[(int)context.Stack];              
00082                 NLAIAGENT::CIteratorContener It = param->getIterator();
00083                 
00084                 while(!It.isInEnd())
00085                 {                       
00086                         NLAIAGENT::IObjectIA *o = (NLAIAGENT::IObjectIA *)It++;
00087                         o->incRef();
00088                         context.Heap[(int)context.Heap] = o;
00089                         context.Heap ++;
00090                 }                               
00091                 int bp = (int)context.Heap;
00092                 CVarPStackParam::_Shift += bp;
00093                 context.Heap.addStack(param->size());
00094                 int sh = (int)context.Heap;
00095                 context.Heap.setShift(sh);
00096                 context.ContextDebug.HeapDebug.setShift(sh);
00097                 context.Param.push_back(param);
00098                 param->incRef();
00099                 context.Stack --;
00100         }
00101 
00102         void CMethodContextDebug::loadConstext(CCodeContext &context)
00103         {
00104                 context.Heap.restoreShift();
00105                 context.Heap.restoreStack();
00106                 context.ContextDebug.HeapDebug.restoreShift();
00107                 NLAIAGENT::IObjectIA *obj = context.Param.back();
00108                 obj->release();
00109                 context.Param.pop_back();               
00110         }
00111 
00112         //*************************************
00113         // CCallMethod
00114         //*************************************
00115 
00116         void CCallMethod::getDebugResult(std::string &str,CCodeContext &context) const
00117         {               
00118                 const NLAIAGENT::IObjectIA *r = (context.Self);
00119                 std::string name = "????";
00120                 if(((const NLAIC::CTypeOfObject &)r->getType()) & NLAIC::CTypeOfObject::tInterpret)
00121                 {
00122                         if(((const NLAIC::CTypeOfObject &)r->getType()) & NLAIC::CTypeOfObject::tAgent)
00123                         {
00124                                 name = r->getMethodeMemberDebugString(_Inheritance,_I);
00125                         }
00126                         else
00127                         if(((const NLAIC::CTypeOfObject &)r->getType()) & NLAIC::CTypeOfObject::tMessage)
00128                         {               
00129                                 if(((NLAIAGENT::CMessageScript *)r)->getCreatorClass() != NULL)
00130                                 {
00131                                         ((NLAIAGENT::CMessageScript *)r)->getCreatorClass()->getBrancheCode(_Inheritance,_I).getName().getDebugString(name);
00132                                         ((NLAIAGENT::CMessageScript *)r)->getCreatorClass()->getBrancheCode(_Inheritance,_I).getParam().getDebugString(name);
00133                                 }
00134                         }
00135                 }
00136                 str = NLAIC::stringGetBuild("Method: '%s.%s'", (const char *)(context.Self)->getType(),name.c_str());
00137         }
00138 
00139         NLAIAGENT::TProcessStatement CCallMethod::runOpCode(CCodeContext &context)
00140         {                               
00141                 int sp = CVarPStackParam::_Shift;
00142                 saveConstext(context);
00143 
00144                 NLAIAGENT::IObjectIA::CProcessResult i;
00145 
00146                 if(_Inheritance) i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_Inheritance,_I,&context);
00147                 else i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_I,&context);
00148                 
00149                 loadConstext(context);
00150                 CVarPStackParam::_Shift = sp;
00151                 return NLAIAGENT::processIdle;
00152         }       
00153 
00154         void CCallMethodi::getDebugResult(std::string &str,CCodeContext &context) const
00155         {
00156                 NLAIAGENT::IObjectIA *obj = (NLAIAGENT::IObjectIA *)context.Self;
00157                 std::list<sint32>::const_iterator it = _N.begin();
00158                 std::string name = "????";
00159 
00160                 while(it != _N.end())
00161                 {
00162                         obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00163                 }
00164 
00165                 //str = NLAIC::stringGetBuild("CallMethodi %d de la class '%s'",_I, (const char *)obj->getType());
00166                 if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tInterpret)
00167                 {
00168                         if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tAgent)
00169                         {
00170                                 /*sint i = _I - ((NLAIAGENT::CAgentScript *)obj)->getBaseMethodCount();
00171                                 if(i >= 0)
00172                                 {
00173                                         ((NLAIAGENT::CAgentScript *)obj)->getClass()->getBrancheCode(_Inheritance, i).getName().getDebugString(name);
00174                                         ((NLAIAGENT::CAgentScript *)obj)->getClass()->getBrancheCode(_Inheritance,i).getParam().getDebugString(name);
00175                                 }*/
00176                                 name = obj->getMethodeMemberDebugString(_Inheritance,_I);
00177                         }
00178                         else
00179                         if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tMessage)
00180                         {                               
00181                                 ((NLAIAGENT::CMessageScript *)obj)->getCreatorClass()->getBrancheCode(_Inheritance,_I).getName().getDebugString(name);
00182                                 ((NLAIAGENT::CMessageScript *)obj)->getCreatorClass()->getBrancheCode(_Inheritance,_I).getParam().getDebugString(name);
00183                         }
00184                 }
00185                 str = NLAIC::stringGetBuild("Method: '%s.%s'", (const char *)(context.Self)->getType(),name.c_str());
00186         }
00187 
00188         NLAIAGENT::TProcessStatement CCallMethodi::runOpCode(CCodeContext &context)
00189         {                               
00190                 int sp = CVarPStackParam::_Shift;
00191                 NLAIAGENT::IObjectIA *obj = (NLAIAGENT::IObjectIA *)context.Self;
00192 
00193                 std::list<sint32>::iterator it = _N.begin();                    
00194                 while(it != _N.end())
00195                 {
00196                         obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00197                 }
00198 
00199                 NLAIAGENT::IObjectIA *selfTmp = (NLAIAGENT::IObjectIA *)context.Self;
00200                 context.Self = obj;
00201                 saveConstext(context);
00202 
00203                 NLAIAGENT::IObjectIA::CProcessResult i;
00204                 if(_Inheritance) i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_Inheritance,_I,&context);
00205                 else i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_I,&context);
00206 
00207                 context.Self = selfTmp;
00208                 loadConstext(context);
00209                 CVarPStackParam::_Shift = sp;
00210                 return NLAIAGENT::processIdle;
00211         }       
00212 
00213         NLAIAGENT::TProcessStatement CCallStackNewMethodi::runOpCode(CCodeContext &context)
00214         {                               
00215                 int sp = CVarPStackParam::_Shift;
00216                 NLAIAGENT::IObjectIA *o = (NLAIAGENT::IObjectIA *)context.Stack[(int)context.Stack];
00217                 o->incRef();            
00218                 context.Stack --;               
00219 
00220                 std::list<sint32>::iterator it = _N.begin();
00221                 NLAIAGENT::IObjectIA *obj = o;
00222                 while(it != _N.end())
00223                 {
00224                         obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00225                 }
00226 
00227                 NLAIAGENT::IObjectIA *selfTmp = (NLAIAGENT::IObjectIA *)context.Self;
00228                 context.Self = obj;
00229                 saveConstext(context);
00230                 
00231                 NLAIAGENT::IObjectIA::CProcessResult i;
00232                 if ( _Inheritance ) 
00233                         i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_Inheritance,_I,&context);
00234                 else 
00235                         i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_I,&context);
00236 
00237                 context.Self = selfTmp;
00238                 loadConstext(context);
00239                 CVarPStackParam::_Shift = sp;           
00240                 context.Stack ++;
00241                 context.Stack[(int)context.Stack] = o;
00242                 return NLAIAGENT::processIdle;
00243         }
00244 
00245         void CCallStackMethodi::getDebugResult(std::string &str,CCodeContext &context) const
00246         {               
00247                 NLAIAGENT::IObjectIA *obj = (NLAIAGENT::IObjectIA *)context.Stack[(int)context.Stack - 1];
00248                 std::list<sint32>::const_iterator it = _N.begin();
00249                 std::string name = "????";
00250 
00251                 while(it != _N.end())
00252                 {
00253                         obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00254                 }               
00255                 if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tInterpret)
00256                 {
00257                         if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tAgent)
00258                         {
00259                                 /*sint i = _I - ((NLAIAGENT::CAgentScript *)obj)->getBaseMethodCount();
00260                                 if(i >= 0)
00261                                 {
00262                                         ((NLAIAGENT::CAgentScript *)obj)->getClass()->getBrancheCode(_Inheritance, i).getName().getDebugString(name);
00263                                         ((NLAIAGENT::CAgentScript *)obj)->getClass()->getBrancheCode(_Inheritance,i).getParam().getDebugString(name);
00264                                 }*/
00265                                 name = obj->getMethodeMemberDebugString(_Inheritance,_I);
00266                         }
00267                         else
00268                         if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tMessage)
00269                         {                               
00270                                 ((NLAIAGENT::CMessageScript *)obj)->getCreatorClass()->getBrancheCode(_Inheritance,_I).getName().getDebugString(name);
00271                                 ((NLAIAGENT::CMessageScript *)obj)->getCreatorClass()->getBrancheCode(_Inheritance,_I).getParam().getDebugString(name);
00272                         }
00273                 }
00274                 str = NLAIC::stringGetBuild("Method: '%s.%s'", (const char *)(context.Self)->getType(),name.c_str());
00275         }
00276 
00277         NLAIAGENT::TProcessStatement CCallStackMethodi::runOpCode(CCodeContext &context)
00278         {                               
00279                 int sp = CVarPStackParam::_Shift;
00280                 NLAIAGENT::IObjectIA *o = (NLAIAGENT::IObjectIA *)context.Stack[(int)context.Stack - 1];
00281                 o->incRef();
00282                 NLAIAGENT::IObjectIA *os = (NLAIAGENT::IObjectIA *)context.Stack; 
00283                 os->incRef();
00284                 
00285                 context.Stack --;
00286                 context.Stack --;
00287                 context.Stack ++;
00288                 context.Stack[(int)context.Stack] = os;
00289 
00290                 std::list<sint32>::iterator it = _N.begin();
00291                 NLAIAGENT::IObjectIA *obj = o;
00292                 while(it != _N.end())
00293                 {
00294                         obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00295                 }
00296 
00297                 NLAIAGENT::IObjectIA *selfTmp = (NLAIAGENT::IObjectIA *)context.Self;
00298                 context.Self = obj;
00299                 saveConstext(context);
00300                 
00301                 NLAIAGENT::IObjectIA::CProcessResult i;
00302                 if(_Inheritance) i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_Inheritance,_I,&context);
00303                 else i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_I,&context);
00304 
00305                 context.Self = selfTmp;
00306                 loadConstext(context);
00307                 CVarPStackParam::_Shift = sp;
00308                 o->release();
00309                 return NLAIAGENT::processIdle;
00310         }                       
00311 
00312 
00313         void CCallHeapMethodi::getDebugResult(std::string &str,CCodeContext &context) const
00314         {               
00315                 NLAIAGENT::IObjectIA *obj = (NLAIAGENT::IObjectIA *)context.Heap[(int)_HeapPos];
00316                 std::list<sint32>::const_iterator it = _N.begin();
00317                 std::string name = "????";
00318 
00319                 while(it != _N.end())
00320                 {
00321                         obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00322                 }
00323                 if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tInterpret)
00324                 {
00325                         if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tAgent)
00326                         {
00327                                 /*sint i = _I - ((NLAIAGENT::CAgentScript *)obj)->getBaseMethodCount();
00328                                 if(i >= 0)
00329                                 {
00330                                         ((NLAIAGENT::CAgentScript *)obj)->getClass()->getBrancheCode(_Inheritance, i).getName().getDebugString(name);
00331                                         ((NLAIAGENT::CAgentScript *)obj)->getClass()->getBrancheCode(_Inheritance,i).getParam().getDebugString(name);
00332                                 }*/
00333                                 name = obj->getMethodeMemberDebugString(_Inheritance,_I);
00334                         }
00335                         else
00336                         if(((const NLAIC::CTypeOfObject &)obj->getType()) & NLAIC::CTypeOfObject::tMessage)
00337                         {                               
00338                                 ((NLAIAGENT::CMessageScript *)obj)->getCreatorClass()->getBrancheCode(_Inheritance,_I).getName().getDebugString(name);
00339                                 ((NLAIAGENT::CMessageScript *)obj)->getCreatorClass()->getBrancheCode(_Inheritance,_I).getParam().getDebugString(name);
00340                         }
00341                 }
00342                 str = NLAIC::stringGetBuild("Method: '%s.%s'", (const char *)(context.Self)->getType(),name.c_str());
00343         }
00344 
00345 
00346         NLAIAGENT::TProcessStatement CCallHeapMethodi::runOpCode(CCodeContext &context)
00347         {                               
00348                 int sp = CVarPStackParam::_Shift;
00349                 NLAIAGENT::IObjectIA *obj = (NLAIAGENT::IObjectIA *)context.Heap[(int)_HeapPos];
00350                 NLAIAGENT::IObjectIA *selfTmp = (NLAIAGENT::IObjectIA *)context.Self;
00351 
00352                 std::list<sint32>::iterator it = _N.begin();                    
00353                 while(it != _N.end())
00354                 {
00355                         obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00356                 }
00357                 
00358                 context.Self = obj;
00359                 saveConstext(context);
00360 
00361                 NLAIAGENT::IObjectIA::CProcessResult i;
00362                 if(_Inheritance) i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_Inheritance,_I,&context);
00363                 else i = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_I,&context);
00364 
00365                 context.Self = selfTmp;
00366                 loadConstext(context);
00367                 CVarPStackParam::_Shift = sp;
00368                 return NLAIAGENT::processIdle;
00369         }
00370 }