# 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_lib_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 #include "nel/ai/script/compilateur.h"
00025 #include "nel/ai/agent/agent_script.h"
00026 
00027 namespace NLAISCRIPT
00028 {
00029         void CLibMemberMethod::getDebugResult(std::string &str,CCodeContext &context) const
00030         {               
00031                 const NLAIAGENT::IObjectIA *obj = (context.Self);
00032                 str = NLAIC::stringGetBuild("methode %s",obj->getMethodeMemberDebugString(0,_Id).c_str());      
00033         }
00034 
00035         NLAIAGENT::TProcessStatement CLibMemberMethod::runOpCode(CCodeContext &context)
00036         {
00037                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack];
00038 
00039                 context.Param.push_back(param);
00040                 param->incRef();
00041 
00042                 NLAIAGENT::IObjectIA::CProcessResult r = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_Id,param);
00043 
00044                 if(r.Result != NULL)
00045                 {
00046                         param->release(); 
00047                         context.Stack[(int)context.Stack] = r.Result;
00048                 }
00049                 else
00050                 {
00051                         context.Stack --;
00052                 }
00053                 
00054                 context.Param.back()->release();
00055                 context.Param.pop_back();
00056                 return r.ResultState;
00057         }
00058 
00059         void CLibMemberInheritedMethod::getDebugResult(std::string &str,CCodeContext &context) const
00060         {               
00061                 const NLAIAGENT::IObjectIA *obj = (context.Self);
00062                 str = NLAIC::stringGetBuild("methode %s",obj->getMethodeMemberDebugString(_Inheritance,_Id).c_str());
00063         }
00064 
00065         NLAIAGENT::TProcessStatement CLibMemberInheritedMethod::runOpCode(CCodeContext &context)
00066         {
00067                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack];
00068                 NLAIAGENT::IObjectIA::CProcessResult r = ((NLAIAGENT::IObjectIA *)context.Self)->runMethodeMember(_Inheritance,_Id,param);
00069 
00070                 context.Param.push_back(param);
00071                 param->incRef();
00072                 
00073                 if(r.Result != NULL)
00074                 {
00075                         param->release();
00076                         context.Stack[(int)context.Stack] = r.Result;
00077                 }
00078                 else
00079                 {
00080                         context.Stack --;
00081                 }
00082                 context.Param.back()->release();
00083                 context.Param.pop_back();       
00084                 return r.ResultState;
00085         }
00086 
00087         void CLibMemberMethodi::getDebugResult(std::string &str,CCodeContext &context) const
00088         {               
00089                 const NLAIAGENT::IObjectIA *obj = (context.Self);
00090                 std::list<sint32>::const_iterator it = _I.begin();
00091                 while(it != _I.end())
00092                 {
00093                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00094                 }               
00095 
00096                 str = NLAIC::stringGetBuild("methode %s",obj->getMethodeMemberDebugString(_Inheritance,_Id).c_str());
00097         }
00098 
00099         NLAIAGENT::TProcessStatement CLibMemberMethodi::runOpCode(CCodeContext &context)
00100         {
00101                 std::list<sint32>::iterator it = _I.begin();
00102                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack];
00103                 NLAIAGENT::IObjectIA *obj = (NLAIAGENT::IObjectIA *)context.Self;
00104 
00105                 context.Param.push_back(param);
00106                 param->incRef();
00107                 
00108                 while(it != _I.end())
00109                 {
00110                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00111                 }
00112 
00113                 NLAIAGENT::IObjectIA::CProcessResult r;
00114 
00115                 if(_Inheritance )  r = obj->runMethodeMember(_Inheritance,_Id,param);
00116                 else r = obj->runMethodeMember(_Id,param);
00117                 
00118                 if(r.Result != NULL)
00119                 {
00120                         param->release();
00121                         context.Stack[(int)context.Stack] = r.Result;
00122                 }
00123                 else
00124                 {
00125                         context.Stack --;
00126                 }
00127                 context.Param.back()->release();
00128                 context.Param.pop_back();
00129                 return r.ResultState;
00130         }
00131 
00132         void CLibCallMethod::getDebugResult(std::string &str,CCodeContext &context) const
00133         {                               
00134                 str = NLAIC::stringGetBuild("methode %s",_Lib->getMethodeMemberDebugString(0,_Id).c_str());
00135         }
00136 
00137         NLAIAGENT::TProcessStatement CLibCallMethod::runOpCode(CCodeContext &context)
00138         {
00139                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack];
00140                 NLAIAGENT::IObjectIA::CProcessResult r = _Lib->runMethodeMember(_Id,param);
00141 
00142                 context.Param.push_back(param);
00143                 param->incRef();
00144 
00145                 if(r.Result != NULL)
00146                 {
00147                         param->release();
00148                         context.Stack[(int)context.Stack] = r.Result;
00149                 }
00150                 else
00151                 {
00152                         context.Stack --;
00153                 }
00154                 context.Param.back()->release();
00155                 context.Param.pop_back();
00156                 return r.ResultState;
00157         }
00158 
00159         void CLibCallInheritedMethod::getDebugResult(std::string &str,CCodeContext &context) const
00160         {                               
00161                 str = NLAIC::stringGetBuild("methode %s",_Lib->getMethodeMemberDebugString(_Inheritance,_Id).c_str());
00162         }
00163 
00164         NLAIAGENT::TProcessStatement CLibCallInheritedMethod::runOpCode(CCodeContext &context)
00165         {
00166                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack];
00167                 NLAIAGENT::IObjectIA::CProcessResult r = _Lib->runMethodeMember(_Inheritance,_Id,param);
00168 
00169                 context.Param.push_back(param);
00170                 param->incRef();
00171                 
00172                 if(r.Result != NULL)
00173                 {
00174                         param->release();
00175                         context.Stack[(int)context.Stack] = r.Result;
00176                 }
00177                 else
00178                 {
00179                         context.Stack --;
00180                 }
00181                 context.Param.back()->release();
00182                 context.Param.pop_back();
00183                 return r.ResultState;
00184         }
00185 
00186         void CLibCallMethodi::getDebugResult(std::string &str,CCodeContext &context) const
00187         {               
00188                 std::list<sint32>::const_iterator it = _I.begin();
00189                 const NLAIAGENT::IObjectIA *obj = _Lib;
00190                 while(it != _I.end())
00191                 {
00192                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00193                 }               
00194 
00195                 str = NLAIC::stringGetBuild("methode %s",obj->getMethodeMemberDebugString(_Inheritance,_Id).c_str());
00196         }
00197 
00198         NLAIAGENT::TProcessStatement CLibCallMethodi::runOpCode(CCodeContext &context)
00199         {
00200                 std::list<sint32>::iterator it = _I.begin();
00201                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack];
00202                 NLAIAGENT::IObjectIA *obj = _Lib;
00203                 while(it != _I.end())
00204                 {
00205                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00206                 }
00207 
00208                 NLAIAGENT::IObjectIA::CProcessResult r;
00209 
00210                 context.Param.push_back(param);
00211                 param->incRef();
00212 
00213                 if(_Inheritance )  r = obj->runMethodeMember(_Inheritance,_Id,param);
00214                 else r = obj->runMethodeMember(_Id,param);
00215                 
00216                 if(r.Result != NULL)
00217                 {
00218                         param->release();
00219                         context.Stack[(int)context.Stack] = r.Result;
00220                 }
00221                 else
00222                 {
00223                         context.Stack --;
00224                 }
00225                 context.Param.back()->release();
00226                 context.Param.pop_back();
00227                 return r.ResultState;
00228         }
00229 
00230         void CLibStackMemberMethod::getDebugResult(std::string &str,CCodeContext &context) const
00231         {
00232                 std::list<sint32>::const_iterator it = _I.begin();
00233                 const NLAIAGENT::IObjectIA *obj = context.Stack[(int)context.Stack - 1];
00234                 while(it != _I.end())
00235                 {
00236                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00237                 }               
00238 
00239                 str = NLAIC::stringGetBuild("methode %s",obj->getMethodeMemberDebugString(_H,_Id).c_str());
00240         }
00241 
00242         NLAIAGENT::TProcessStatement CLibStackMemberMethod::runOpCode(CCodeContext &context)
00243         {
00244                 NLAIAGENT::IObjectIA *obj = context.Stack[(int)context.Stack - 1];
00245                 obj->incRef();
00246                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack];
00247                 param->incRef();
00248                 context.Stack --;
00249                 context.Stack --;
00250                 std::list<sint32>::iterator it = _I.begin();
00251                 while(it != _I.end())
00252                 {
00253                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00254                 }
00255 
00256                 NLAIAGENT::IObjectIA::CProcessResult r;
00257 
00258                 context.Param.push_back(param);
00259                 param->incRef();
00260 
00261                 if(_H )  r = obj->runMethodeMember(_H,_Id,param);
00262                 else r = obj->runMethodeMember(_Id,param);
00263                 
00264                 param->release();
00265                 if(r.Result != NULL)
00266                 {                       
00267                         context.Stack ++;
00268                         context.Stack[(int)context.Stack] = r.Result;
00269                 }
00270 
00271                 context.Param.back()->release();
00272                 context.Param.pop_back();
00273                 return r.ResultState;
00274         }
00275 
00276         void CLibStackNewMemberMethod::getDebugResult(std::string &str,CCodeContext &context) const
00277         {
00278                 std::list<sint32>::const_iterator it = _I.begin();
00279                 const NLAIAGENT::IObjectIA *obj = context.Stack[(int)context.Stack];
00280                 while(it != _I.end())
00281                 {
00282                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00283                 }               
00284 
00285                 str = NLAIC::stringGetBuild("methode %s",obj->getMethodeMemberDebugString(_H,_Id).c_str());
00286         }
00287 
00288         NLAIAGENT::TProcessStatement CLibStackNewMemberMethod::runOpCode(CCodeContext &context)
00289         {
00290                 NLAIAGENT::IObjectIA *obj = context.Stack[(int)context.Stack];
00291                 obj->incRef();
00292                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack - 1];            
00293                 context.Stack --;
00294                 context.Stack[(int)context.Stack] = obj;
00295                 std::list<sint32>::iterator it = _I.begin();
00296                 while(it != _I.end())
00297                 {
00298                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00299                 }
00300 
00301                 NLAIAGENT::IObjectIA::CProcessResult r;
00302 
00303                 context.Param.push_back(param);
00304                 param->incRef();
00305 
00306                 if(_H )  r = obj->runMethodeMember(_H,_Id,param);
00307                 else r = obj->runMethodeMember(_Id,param);
00308                 param->release();
00309                 if(r.Result != NULL)
00310                 {                       
00311                         context.Stack ++;
00312                         context.Stack[(int)context.Stack] = r.Result;
00313                 }
00314 
00315                 context.Param.back()->release();
00316                 context.Param.pop_back();
00317                 
00318                 return r.ResultState;
00319         }
00320 
00321         void CLibHeapMemberMethod::getDebugResult(std::string &str,CCodeContext &context) const
00322         {
00323                 std::list<sint32>::const_iterator it = _I.begin();
00324                 const NLAIAGENT::IObjectIA *obj = context.Heap[(int)_Index];
00325                 while(it != _I.end())
00326                 {
00327                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00328                 }               
00329 
00330                 str = NLAIC::stringGetBuild("methode %s",obj->getMethodeMemberDebugString(_H,_Id).c_str());
00331         }
00332 
00333         NLAIAGENT::TProcessStatement CLibHeapMemberMethod::runOpCode(CCodeContext &context)
00334         {
00335                 NLAIAGENT::IObjectIA *obj = context.Heap[(int)_Index];          
00336                 NLAIAGENT::IObjectIA *param = context.Stack[(int)context.Stack];
00337 
00338                 context.Param.push_back(param);
00339                 param->incRef();
00340 
00341 #ifdef NL_DEBUG
00342                 int db_size = context.Param.size();
00343                 static sint kkkkk = 0;
00344                 
00345                 const char *txtDbg = (const char *)obj->getType();
00346 
00347                 kkkkk ++;
00348 #endif
00349                 
00350                 std::list<sint32>::iterator it = _I.begin();
00351                 while(it != _I.end())
00352                 {
00353                          obj = (NLAIAGENT::IObjectIA *)obj->getStaticMember(*it++);
00354                 }
00355 
00356 
00357                 NLAIAGENT::IObjectIA::CProcessResult r;
00358 
00359                 if (_H )  
00360                         r = obj->runMethodeMember(_H,_Id,param);
00361                 else 
00362                         r = obj->runMethodeMember(_Id,param);
00363                 
00364                 if(r.Result != NULL)
00365                 {
00366                         param->release();
00367                         context.Stack[(int)context.Stack] = r.Result;
00368                 }
00369                 else
00370                 {
00371                         context.Stack --;
00372                 }
00373 
00374 #ifdef NL_DEBUG
00375                 db_size = context.Param.size();
00376                 if(!db_size) throw;
00377 #endif
00378                 NLAIAGENT::IObjectIA *p = context.Param.back();
00379                 context.Param.pop_back();
00380                 p->release();
00381                 
00382                 return r.ResultState;           
00383         }       
00384 }