2014-10-14 13:11:37 +00:00
/*
* This file is part of the Colobot : Gold Edition source code
2015-08-22 14:40:02 +00:00
* Copyright ( C ) 2001 - 2015 , Daniel Roux , EPSITEC SA & TerranovaTeam
* http : //epsitec.ch; http://colobot.info; http://github.com/colobot
2014-10-14 13:11:37 +00:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
* See the GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see http : //gnu.org/licenses
*/
2012-08-02 22:50:25 +00:00
2015-11-15 17:05:35 +00:00
// Modules inlcude
2015-11-23 20:59:56 +00:00
# include "CBot/CBotVar/CBotVar.h"
2015-11-22 16:25:46 +00:00
2015-11-23 20:59:56 +00:00
# include "CBot/CBotCall.h"
# include "CBot/CBotStack.h"
# include "CBot/CBotCStack.h"
# include "CBot/CBotClass.h"
# include "CBot/CBotUtils.h"
# include "CBot/CBotFileUtils.h"
2015-11-15 15:49:06 +00:00
2015-11-23 20:59:56 +00:00
# include "CBot/CBotInstr/CBotFunction.h"
2015-11-15 17:31:57 +00:00
2015-11-22 16:25:46 +00:00
# include "StringFunctions.h"
2015-11-15 17:05:35 +00:00
// Local include
// Global include
2012-08-02 22:50:25 +00:00
# include <stdio.h>
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
CBotProgram : : CBotProgram ( )
{
2015-08-16 10:43:42 +00:00
m_Prog = nullptr ;
m_pRun = nullptr ;
m_pClass = nullptr ;
m_pStack = nullptr ;
m_pInstance = nullptr ;
2012-08-08 20:35:17 +00:00
m_ErrorCode = 0 ;
m_Ident = 0 ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
CBotProgram : : CBotProgram ( CBotVar * pInstance )
{
2015-08-16 10:43:42 +00:00
m_Prog = nullptr ;
m_pRun = nullptr ;
m_pClass = nullptr ;
m_pStack = nullptr ;
2012-08-08 20:35:17 +00:00
m_pInstance = pInstance ;
m_ErrorCode = 0 ;
m_Ident = 0 ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
CBotProgram : : ~ CBotProgram ( )
{
2012-08-08 20:35:17 +00:00
// delete m_pClass;
m_pClass - > Purge ( ) ;
2015-08-16 10:43:42 +00:00
m_pClass = nullptr ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
CBotClass : : FreeLock ( this ) ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
delete m_Prog ;
# if STACKMEM
m_pStack - > Delete ( ) ;
2012-08-02 22:50:25 +00:00
# else
2012-08-08 20:35:17 +00:00
delete m_pStack ;
2012-08-02 22:50:25 +00:00
# endif
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : Compile ( const char * program , CBotStringArray & ListFonctions , void * pUser )
{
2012-08-08 20:35:17 +00:00
int error = 0 ;
Stop ( ) ;
// delete m_pClass;
m_pClass - > Purge ( ) ; // purge the old definitions of classes
// but without destroying the object
2015-08-16 10:43:42 +00:00
m_pClass = nullptr ;
delete m_Prog ; m_Prog = nullptr ;
2012-08-08 20:35:17 +00:00
ListFonctions . SetSize ( 0 ) ;
m_ErrorCode = 0 ;
// transforms the program in Tokens
CBotToken * pBaseToken = CBotToken : : CompileTokens ( program , error ) ;
2015-08-16 10:43:42 +00:00
if ( pBaseToken = = nullptr ) return false ;
2012-08-08 20:35:17 +00:00
2015-08-16 10:43:42 +00:00
CBotCStack * pStack = new CBotCStack ( nullptr ) ;
2012-08-11 18:59:35 +00:00
CBotToken * p = pBaseToken - > GetNext ( ) ; // skips the first token (separator)
2012-08-08 20:35:17 +00:00
pStack - > SetBotCall ( this ) ; // defined used routines
CBotCall : : SetPUser ( pUser ) ;
// first made a quick pass just to take the headers of routines and classes
2015-08-16 10:43:42 +00:00
while ( pStack - > IsOk ( ) & & p ! = nullptr & & p - > GetType ( ) ! = 0 )
2012-08-08 20:35:17 +00:00
{
if ( IsOfType ( p , ID_SEP ) ) continue ; // semicolons lurking
2013-05-26 15:47:54 +00:00
if ( p - > GetType ( ) = = ID_CLASS | |
2012-08-11 18:59:35 +00:00
( p - > GetType ( ) = = ID_PUBLIC & & p - > GetNext ( ) - > GetType ( ) = = ID_CLASS ) )
2012-08-08 20:35:17 +00:00
{
CBotClass * nxt = CBotClass : : Compile1 ( p , pStack ) ;
2015-08-16 10:43:42 +00:00
if ( m_pClass = = nullptr ) m_pClass = nxt ;
2012-08-08 20:35:17 +00:00
else m_pClass - > AddNext ( nxt ) ;
}
else
{
2015-08-16 10:43:42 +00:00
CBotFunction * next = CBotFunction : : Compile1 ( p , pStack , nullptr ) ;
if ( m_Prog = = nullptr ) m_Prog = next ;
2012-08-08 20:35:17 +00:00
else m_Prog - > AddNext ( next ) ;
}
}
if ( ! pStack - > IsOk ( ) )
{
2013-05-26 15:47:54 +00:00
m_ErrorCode = pStack - > GetError ( m_ErrorStart , m_ErrorEnd ) ;
2012-08-08 20:35:17 +00:00
delete m_Prog ;
2015-08-16 10:43:42 +00:00
m_Prog = nullptr ;
2012-08-08 20:35:17 +00:00
delete pBaseToken ;
return false ;
}
2015-08-16 10:43:42 +00:00
// CBotFunction* temp = nullptr;
2012-08-08 20:35:17 +00:00
CBotFunction * next = m_Prog ; // rewind the list
2012-08-11 18:59:35 +00:00
p = pBaseToken - > GetNext ( ) ; // returns to the beginning
2012-08-08 20:35:17 +00:00
2015-08-16 10:43:42 +00:00
while ( pStack - > IsOk ( ) & & p ! = nullptr & & p - > GetType ( ) ! = 0 )
2012-08-08 20:35:17 +00:00
{
if ( IsOfType ( p , ID_SEP ) ) continue ; // semicolons lurking
2013-05-26 15:47:54 +00:00
if ( p - > GetType ( ) = = ID_CLASS | |
2012-08-11 18:59:35 +00:00
( p - > GetType ( ) = = ID_PUBLIC & & p - > GetNext ( ) - > GetType ( ) = = ID_CLASS ) )
2012-08-08 20:35:17 +00:00
{
m_bCompileClass = true ;
CBotClass : : Compile ( p , pStack ) ; // completes the definition of the class
}
else
{
m_bCompileClass = false ;
CBotFunction : : Compile ( p , pStack , next ) ;
2012-08-11 18:59:35 +00:00
if ( next - > IsExtern ( ) ) ListFonctions . Add ( next - > GetName ( ) /* + next->GetParams()*/ ) ;
2012-08-08 20:35:17 +00:00
next - > m_pProg = this ; // keeps pointers to the module
next = next - > Next ( ) ;
}
}
// delete m_Prog; // the list of first pass
// m_Prog = temp; // list of the second pass
if ( ! pStack - > IsOk ( ) )
{
2013-05-26 15:47:54 +00:00
m_ErrorCode = pStack - > GetError ( m_ErrorStart , m_ErrorEnd ) ;
2012-08-08 20:35:17 +00:00
delete m_Prog ;
2015-08-16 10:43:42 +00:00
m_Prog = nullptr ;
2012-08-08 20:35:17 +00:00
}
delete pBaseToken ;
delete pStack ;
2015-08-16 10:43:42 +00:00
return ( m_Prog ! = nullptr ) ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : Start ( const char * name )
{
2012-08-08 20:35:17 +00:00
# if STACKMEM
m_pStack - > Delete ( ) ;
2012-08-02 22:50:25 +00:00
# else
2012-08-08 20:35:17 +00:00
delete m_pStack ;
2012-08-02 22:50:25 +00:00
# endif
2015-08-16 10:43:42 +00:00
m_pStack = nullptr ;
2012-08-08 20:35:17 +00:00
m_pRun = m_Prog ;
2015-08-16 10:43:42 +00:00
while ( m_pRun ! = nullptr )
2012-08-08 20:35:17 +00:00
{
2012-08-11 18:59:35 +00:00
if ( m_pRun - > GetName ( ) = = name ) break ;
2012-08-08 20:35:17 +00:00
m_pRun = m_pRun - > m_next ;
}
2015-08-16 10:43:42 +00:00
if ( m_pRun = = nullptr )
2012-08-08 20:35:17 +00:00
{
m_ErrorCode = TX_NORUN ;
return false ;
}
# if STACKMEM
m_pStack = CBotStack : : FirstStack ( ) ;
2012-08-02 22:50:25 +00:00
# else
2015-08-16 10:43:42 +00:00
m_pStack = new CBotStack ( nullptr ) ; // creates an execution stack
2012-08-02 22:50:25 +00:00
# endif
2012-08-08 20:35:17 +00:00
m_pStack - > SetBotCall ( this ) ; // bases for routines
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
return true ; // we are ready for Run ()
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : GetPosition ( const char * name , int & start , int & stop , CBotGet modestart , CBotGet modestop )
{
2012-08-08 20:35:17 +00:00
CBotFunction * p = m_Prog ;
2015-08-16 10:43:42 +00:00
while ( p ! = nullptr )
2012-08-08 20:35:17 +00:00
{
2012-08-11 18:59:35 +00:00
if ( p - > GetName ( ) = = name ) break ;
2012-08-08 20:35:17 +00:00
p = p - > m_next ;
}
2012-08-02 22:50:25 +00:00
2015-08-16 10:43:42 +00:00
if ( p = = nullptr ) return false ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
p - > GetPosition ( start , stop , modestart , modestop ) ;
return true ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : Run ( void * pUser , int timer )
{
2012-08-08 20:35:17 +00:00
bool ok ;
2015-08-16 10:43:42 +00:00
if ( m_pStack = = nullptr | | m_pRun = = nullptr ) goto error ;
2012-08-08 20:35:17 +00:00
m_ErrorCode = 0 ;
m_pStack - > Reset ( pUser ) ; // empty the possible previous error, and resets the timer
if ( timer > = 0 ) m_pStack - > SetTimer ( timer ) ;
m_pStack - > SetBotCall ( this ) ; // bases for routines
# if STACKRUN
// resumes execution on the top of the stack
ok = m_pStack - > Execute ( ) ;
2013-05-26 15:47:54 +00:00
if ( ok )
2012-08-08 20:35:17 +00:00
{
# ifdef _DEBUG
CBotVar * ppVar [ 3 ] ;
ppVar [ 0 ] = CBotVar : : Create ( " aa " , CBotTypInt ) ;
ppVar [ 1 ] = CBotVar : : Create ( " bb " , CBotTypInt ) ;
2015-08-16 10:43:42 +00:00
ppVar [ 2 ] = nullptr ;
2012-08-08 20:35:17 +00:00
ok = m_pRun - > Execute ( ppVar , m_pStack , m_pInstance ) ;
2012-08-02 22:50:25 +00:00
# else
2012-08-08 20:35:17 +00:00
// returns to normal execution
2015-08-16 10:43:42 +00:00
ok = m_pRun - > Execute ( nullptr , m_pStack , m_pInstance ) ;
2012-08-02 22:50:25 +00:00
# endif
2012-08-08 20:35:17 +00:00
}
2012-08-02 22:50:25 +00:00
# else
2015-08-16 10:43:42 +00:00
ok = m_pRun - > Execute ( nullptr , m_pStack , m_pInstance ) ;
2012-08-02 22:50:25 +00:00
# endif
2012-08-08 20:35:17 +00:00
// completed on a mistake?
if ( ! ok & & ! m_pStack - > IsOk ( ) )
{
2012-08-11 18:59:35 +00:00
m_ErrorCode = m_pStack - > GetError ( m_ErrorStart , m_ErrorEnd ) ;
2012-08-08 20:35:17 +00:00
# if STACKMEM
m_pStack - > Delete ( ) ;
2012-08-02 22:50:25 +00:00
# else
2012-08-08 20:35:17 +00:00
delete m_pStack ;
2012-08-02 22:50:25 +00:00
# endif
2015-08-16 10:43:42 +00:00
m_pStack = nullptr ;
2012-08-08 20:35:17 +00:00
return true ; // execution is finished!
}
2012-08-02 22:50:25 +00:00
2015-08-16 10:43:42 +00:00
if ( ok ) m_pRun = nullptr ; // more function in execution
2012-08-08 20:35:17 +00:00
return ok ;
2012-08-02 22:50:25 +00:00
error :
2012-08-08 20:35:17 +00:00
m_ErrorCode = TX_NORUN ;
return true ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
void CBotProgram : : Stop ( )
{
2012-08-08 20:35:17 +00:00
# if STACKMEM
m_pStack - > Delete ( ) ;
2012-08-02 22:50:25 +00:00
# else
2012-08-08 20:35:17 +00:00
delete m_pStack ;
2012-08-02 22:50:25 +00:00
# endif
2015-08-16 10:43:42 +00:00
m_pStack = nullptr ;
m_pRun = nullptr ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : GetRunPos ( const char * & FunctionName , int & start , int & end )
{
2015-08-16 10:43:42 +00:00
FunctionName = nullptr ;
2012-08-08 20:35:17 +00:00
start = end = 0 ;
2015-08-16 10:43:42 +00:00
if ( m_pStack = = nullptr ) return false ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
m_pStack - > GetRunPos ( FunctionName , start , end ) ;
return true ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-11 18:59:35 +00:00
CBotVar * CBotProgram : : GetStackVars ( const char * & FunctionName , int level )
2012-08-02 22:50:25 +00:00
{
2015-08-16 10:43:42 +00:00
FunctionName = nullptr ;
if ( m_pStack = = nullptr ) return nullptr ;
2012-08-02 22:50:25 +00:00
2012-08-11 18:59:35 +00:00
return m_pStack - > GetStackVars ( FunctionName , level ) ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
void CBotProgram : : SetTimer ( int n )
{
2012-08-08 20:35:17 +00:00
CBotStack : : SetTimer ( n ) ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-11 18:59:35 +00:00
int CBotProgram : : GetError ( )
2012-08-02 22:50:25 +00:00
{
2012-08-08 20:35:17 +00:00
return m_ErrorCode ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
void CBotProgram : : SetIdent ( long n )
{
2012-08-08 20:35:17 +00:00
m_Ident = n ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-11 18:59:35 +00:00
long CBotProgram : : GetIdent ( )
2012-08-02 22:50:25 +00:00
{
2012-08-08 20:35:17 +00:00
return m_Ident ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : GetError ( int & code , int & start , int & end )
{
2012-08-08 20:35:17 +00:00
code = m_ErrorCode ;
start = m_ErrorStart ;
end = m_ErrorEnd ;
return code > 0 ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : GetError ( int & code , int & start , int & end , CBotProgram * & pProg )
{
2012-08-08 20:35:17 +00:00
code = m_ErrorCode ;
start = m_ErrorStart ;
end = m_ErrorEnd ;
pProg = this ;
return code > 0 ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-11 18:59:35 +00:00
CBotString CBotProgram : : GetErrorText ( int code )
2012-08-02 22:50:25 +00:00
{
2012-08-08 20:35:17 +00:00
CBotString TextError ;
TextError . LoadString ( code ) ;
if ( TextError . IsEmpty ( ) )
{
char buf [ 100 ] ;
sprintf ( buf , " Exception numéro %d. " , code ) ;
TextError = buf ;
}
return TextError ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-11 18:59:35 +00:00
CBotFunction * CBotProgram : : GetFunctions ( )
2012-08-02 22:50:25 +00:00
{
2012-08-08 20:35:17 +00:00
return m_Prog ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2013-05-26 15:47:54 +00:00
bool CBotProgram : : AddFunction ( const char * name ,
bool rExec ( CBotVar * pVar , CBotVar * pResult , int & Exception , void * pUser ) ,
2012-08-08 20:35:17 +00:00
CBotTypResult rCompile ( CBotVar * & pVar , void * pUser ) )
2012-08-02 22:50:25 +00:00
{
2012-08-08 20:35:17 +00:00
// stores pointers to the two functions
return CBotCall : : AddFunction ( name , rExec , rCompile ) ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
bool rSizeOf ( CBotVar * pVar , CBotVar * pResult , int & ex , void * pUser )
{
if ( pVar = = nullptr ) return TX_LOWPARAM ;
2012-08-02 22:50:25 +00:00
2015-11-15 17:05:35 +00:00
int i = 0 ;
pVar = pVar - > GetItemList ( ) ;
while ( pVar ! = nullptr )
{
i + + ;
pVar = pVar - > GetNext ( ) ;
}
pResult - > SetValInt ( i ) ;
return true ;
}
////////////////////////////////////////////////////////////////////////////////
CBotTypResult cSizeOf ( CBotVar * & pVar , void * pUser )
{
if ( pVar = = nullptr ) return CBotTypResult ( TX_LOWPARAM ) ;
if ( pVar - > GetType ( ) ! = CBotTypArrayPointer )
return CBotTypResult ( TX_BADPARAM ) ;
return CBotTypResult ( CBotTypInt ) ;
}
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : DefineNum ( const char * name , long val )
{
2012-08-08 20:35:17 +00:00
return CBotToken : : DefineNum ( name , val ) ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : SaveState ( FILE * pf )
{
2012-08-08 20:35:17 +00:00
if ( ! WriteWord ( pf , CBOTVERSION ) ) return false ;
2015-08-16 10:43:42 +00:00
if ( m_pStack ! = nullptr )
2012-08-08 20:35:17 +00:00
{
if ( ! WriteWord ( pf , 1 ) ) return false ;
2012-08-11 18:59:35 +00:00
if ( ! WriteString ( pf , m_pRun - > GetName ( ) ) ) return false ;
2012-08-08 20:35:17 +00:00
if ( ! m_pStack - > SaveState ( pf ) ) return false ;
}
2013-05-26 15:47:54 +00:00
else
2012-08-08 20:35:17 +00:00
{
if ( ! WriteWord ( pf , 0 ) ) return false ;
}
return true ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-02 22:50:25 +00:00
bool CBotProgram : : RestoreState ( FILE * pf )
{
2012-08-08 20:35:17 +00:00
unsigned short w ;
CBotString s ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
Stop ( ) ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
if ( ! ReadWord ( pf , w ) ) return false ;
if ( w ! = CBOTVERSION ) return false ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
if ( ! ReadWord ( pf , w ) ) return false ;
if ( w = = 0 ) return true ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
if ( ! ReadString ( pf , s ) ) return false ;
Start ( s ) ; // point de reprise
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
# if STACKMEM
m_pStack - > Delete ( ) ;
2012-08-02 22:50:25 +00:00
# else
2012-08-08 20:35:17 +00:00
delete m_pStack ;
2012-08-02 22:50:25 +00:00
# endif
2015-08-16 10:43:42 +00:00
m_pStack = nullptr ;
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
// retrieves the stack from the memory
2015-08-16 10:43:42 +00:00
// uses a nullptr pointer (m_pStack) but it's ok like that
2012-08-08 20:35:17 +00:00
if ( ! m_pStack - > RestoreState ( pf , m_pStack ) ) return false ;
m_pStack - > SetBotCall ( this ) ; // bases for routines
2012-08-02 22:50:25 +00:00
2012-08-08 20:35:17 +00:00
// restored some states in the stack according to the structure
2015-08-16 10:43:42 +00:00
m_pRun - > RestoreState ( nullptr , m_pStack , m_pInstance ) ;
2012-08-08 20:35:17 +00:00
return true ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
2012-08-11 18:59:35 +00:00
int CBotProgram : : GetVersion ( )
2012-08-02 22:50:25 +00:00
{
2012-08-08 20:35:17 +00:00
return CBOTVERSION ;
2012-08-02 22:50:25 +00:00
}
2015-11-15 17:05:35 +00:00
////////////////////////////////////////////////////////////////////////////////
void CBotProgram : : Init ( )
{
CBotToken : : DefineNum ( " CBotErrZeroDiv " , TX_DIVZERO ) ; // division by zero
CBotToken : : DefineNum ( " CBotErrNotInit " , TX_NOTINIT ) ; // uninitialized variable
CBotToken : : DefineNum ( " CBotErrBadThrow " , TX_BADTHROW ) ; // throw a negative value
//CBotToken::DefineNum("CBotErrNoRetVal", 6003); // function did not return results // TODO: Not used. I'm pretty sure not returning a value crashes the game :P
CBotToken : : DefineNum ( " CBotErrNoRun " , TX_NORUN ) ; // active Run () without a function // TODO: Is this actually a runtime error?
CBotToken : : DefineNum ( " CBotErrUndefFunc " , TX_NOCALL ) ; // Calling a function that no longer exists
CBotToken : : DefineNum ( " CBotErrUndefClass " , TX_NOCLASS ) ; // Class no longer exists
CBotToken : : DefineNum ( " CBotErrNullPointer " , TX_NULLPT ) ; // Attempted to use a null pointer
CBotToken : : DefineNum ( " CBotErrNan " , TX_OPNAN ) ; // Can't do operations on nan
CBotToken : : DefineNum ( " CBotErrOutOfBounds " , TX_OUTARRAY ) ; // Attempted access out of bounds of an array
CBotToken : : DefineNum ( " CBotErrStackOverflow " , TX_STACKOVER ) ; // Stack overflow
CBotToken : : DefineNum ( " CBotErrDeletedObject " , TX_DELETEDPT ) ; // Attempted to use deleted object
CBotProgram : : AddFunction ( " sizeof " , rSizeOf , cSizeOf ) ;
InitStringFunctions ( ) ;
}
////////////////////////////////////////////////////////////////////////////////
void CBotProgram : : Free ( )
{
CBotToken : : Free ( ) ;
CBotCall : : Free ( ) ;
CBotClass : : Free ( ) ;
}