Transation of comments complete
parent
0844a0f7bd
commit
0919796df7
|
@ -12,18 +12,20 @@
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
// expression du genre Opérande1 + Opérande2
|
|
||||||
// Opérande1 - Opérande2
|
///////////////////////////////////////////////////
|
||||||
|
// expressions of type Operand1 + Operand2
|
||||||
|
// Operand1 - Operand2
|
||||||
|
|
||||||
#include "CBot.h"
|
#include "CBot.h"
|
||||||
|
|
||||||
// divers constructeurs
|
// various constructors
|
||||||
|
|
||||||
CBotAddExpr::CBotAddExpr()
|
CBotAddExpr::CBotAddExpr()
|
||||||
{
|
{
|
||||||
m_leftop =
|
m_leftop =
|
||||||
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
|
m_rightop = NULL; // NULL to be able to delete without further
|
||||||
name = "CBotAddExpr"; // debug
|
name = "CBotAddExpr"; // debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,105 +40,105 @@ CBotAddExpr::~CBotAddExpr()
|
||||||
|
|
||||||
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
|
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
|
||||||
{
|
{
|
||||||
CBotStack* pStk = pStack->TokenStack(); // un bout de pile svp
|
CBotStack* pStk = pStack->TokenStack(); // one end of stack please
|
||||||
|
|
||||||
// cherche des instructions qui peuvent convenir à gauche de l'opération + ou -
|
// looking statements that may be suitable to the left of the operation + or -
|
||||||
|
|
||||||
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B à gauche
|
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B left
|
||||||
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
|
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
|
||||||
|
|
||||||
// est-ce qu'on a le token + ou - ensuite ?
|
// do we have the token + or - next?
|
||||||
|
|
||||||
if ( p->GetType() == ID_ADD ||
|
if ( p->GetType() == ID_ADD ||
|
||||||
p->GetType() == ID_SUB) // plus ou moins
|
p->GetType() == ID_SUB) // more or less
|
||||||
{
|
{
|
||||||
CBotAddExpr* inst = new CBotAddExpr(); // élément pour opération
|
CBotAddExpr* inst = new CBotAddExpr(); // element for operation
|
||||||
inst->SetToken(p); // mémorise l'opération
|
inst->SetToken(p); // stores the operation
|
||||||
|
|
||||||
int type1, type2;
|
int type1, type2;
|
||||||
type1 = pStack->GetType(); // de quel type le premier opérande ?
|
type1 = pStack->GetType(); // what kind of the first operand?
|
||||||
|
|
||||||
p = p->Next(); // saute le token de l'opération
|
p = p->Next(); // skip the token of the operation
|
||||||
|
|
||||||
// cherche des instructions qui peuvent convenir à droite
|
// looking statements that may be suitable for right
|
||||||
|
|
||||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) à droite
|
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) rigth
|
||||||
{
|
{
|
||||||
// il y a un second opérande acceptable
|
// there is an acceptable second operand
|
||||||
|
|
||||||
type2 = pStack->GetType(); // de quel type le résultat ?
|
type2 = pStack->GetType(); // what kind of results?
|
||||||
|
|
||||||
if ( type1 == type2 ) // les résultats sont-ils compatibles
|
if ( type1 == type2 ) // are the results consistent ?
|
||||||
{
|
{
|
||||||
// si ok, enregistre l'opérande dans l'objet
|
// ok so, saves the operand in the object
|
||||||
inst->m_leftop = left;
|
inst->m_leftop = left;
|
||||||
// et rend l'object à qui l'a demandé
|
// and makes the object on demand
|
||||||
return pStack->Return(inst, pStk);
|
return pStack->Return(inst, pStk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// en cas d'erreur, libère les éléments
|
// in case of error, free the elements
|
||||||
delete left;
|
delete left;
|
||||||
delete inst;
|
delete inst;
|
||||||
// et transmet l'erreur qui se trouve sur la pile
|
// and transmits the error that is on the stack
|
||||||
return pStack->Return(NULL, pStk);
|
return pStack->Return(NULL, pStk);
|
||||||
}
|
}
|
||||||
|
|
||||||
// si on n'a pas affaire à une opération + ou -
|
// if we are not dealing with an operation + or -
|
||||||
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
|
// goes to that requested, the operand (left) found
|
||||||
// à la place de l'objet "addition"
|
// place the object "addition"
|
||||||
return pStack->Return(left, pStk);
|
return pStack->Return(left, pStk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// fait l'opération d'addition ou de soustraction
|
// operation is addition or subtraction
|
||||||
|
|
||||||
bool CBotAddExpr::Execute(CBotStack* &pStack)
|
bool CBotAddExpr::Execute(CBotStack* &pStack)
|
||||||
{
|
{
|
||||||
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
|
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
|
||||||
// ou le retrouve en cas de reprise
|
// or is found in case of recovery
|
||||||
// if ( pSk1 == EOX ) return TRUE;
|
// if ( pSk1 == EOX ) return TRUE;
|
||||||
|
|
||||||
|
|
||||||
// selon la reprise, on peut être dans l'un des 2 états
|
// according to recovery, it may be in one of two states
|
||||||
|
|
||||||
if ( pStk1->GetState() == 0 && // 1er état, évalue l'opérande de gauche
|
if ( pStk1->GetState() == 0 && // first state, evaluates the left operand
|
||||||
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
!m_leftop->Execute(pStk1) ) return FALSE; // interrupted here?
|
||||||
|
|
||||||
// passe à l'étape suivante
|
// passes to the next step
|
||||||
pStk1->SetState(1); // prêt pour la suite
|
pStk1->SetState(1); // ready for further
|
||||||
|
|
||||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
// requires a little more stack to not touch the result of the left
|
||||||
// qui se trouve sur la pile, justement.
|
// which is on the stack, precisely.
|
||||||
|
|
||||||
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
|
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
|
||||||
// ou le retrouve en cas de reprise
|
// or is found in case of recovery
|
||||||
|
|
||||||
// 2e état, évalue l'opérande de droite
|
// Second state, evaluates the right operand
|
||||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here?
|
||||||
|
|
||||||
int type1 = pStk1->GetType(); // de quels types les résultats ?
|
int type1 = pStk1->GetType(); // what kind of results?
|
||||||
int type2 = pStk2->GetType();
|
int type2 = pStk2->GetType();
|
||||||
|
|
||||||
// crée une variable temporaire pour y mettre le résultat
|
// creates a temporary variable to put the result
|
||||||
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
|
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
|
||||||
|
|
||||||
// fait l'opération selon la demande
|
// is the operation as requested
|
||||||
switch (GetTokenType())
|
switch (GetTokenType())
|
||||||
{
|
{
|
||||||
case ID_ADD:
|
case ID_ADD:
|
||||||
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
|
result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition
|
||||||
break;
|
break;
|
||||||
case ID_SUB:
|
case ID_SUB:
|
||||||
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
|
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pStk2->SetVar(result); // met le résultat sur la pile
|
pStk2->SetVar(result); // puts the result on the stack
|
||||||
|
|
||||||
pStk1->Return(pStk2); // libère la pile
|
pStk1->Return(pStk2); // frees the stack
|
||||||
return pStack->Return(pStk1); // transmet le résultat
|
return pStack->Return(pStk1); // transmits the result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,16 @@
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
// expression du genre Opérande1 > Opérande2
|
|
||||||
// Opérande1 != Opérande2
|
///////////////////////////////////////////////////
|
||||||
|
// expression of type Opérande1 > Opérande2
|
||||||
|
// Opérande1 != Opérande2
|
||||||
// etc.
|
// etc.
|
||||||
|
|
||||||
#include "CBot.h"
|
#include "CBot.h"
|
||||||
|
|
||||||
// divers constructeurs
|
// various constructeurs
|
||||||
|
|
||||||
CBotCompExpr::CBotCompExpr()
|
CBotCompExpr::CBotCompExpr()
|
||||||
{
|
{
|
||||||
|
@ -36,38 +38,38 @@ CBotCompExpr::~CBotCompExpr()
|
||||||
|
|
||||||
fichier plus utilise;
|
fichier plus utilise;
|
||||||
|
|
||||||
// compile une instruction de type A < B
|
// compile instruction of type A < B
|
||||||
|
|
||||||
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
{
|
{
|
||||||
CBotCStack* pStk = pStack->AddStack();
|
CBotCStack* pStk = pStack->AddStack();
|
||||||
|
|
||||||
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B à gauche
|
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B left
|
||||||
if (left == NULL) return pStack->Return(NULL, pStk); // erreur
|
if (left == NULL) return pStack->Return(NULL, pStk); // error
|
||||||
|
|
||||||
if ( p->GetType() == ID_HI ||
|
if ( p->GetType() == ID_HI ||
|
||||||
p->GetType() == ID_LO ||
|
p->GetType() == ID_LO ||
|
||||||
p->GetType() == ID_HS ||
|
p->GetType() == ID_HS ||
|
||||||
p->GetType() == ID_LS ||
|
p->GetType() == ID_LS ||
|
||||||
p->GetType() == ID_EQ ||
|
p->GetType() == ID_EQ ||
|
||||||
p->GetType() == ID_NE) // les diverses comparaisons
|
p->GetType() == ID_NE) // the various comparisons
|
||||||
{
|
{
|
||||||
CBotCompExpr* inst = new CBotCompExpr(); // élément pour opération
|
CBotCompExpr* inst = new CBotCompExpr(); // element for operation
|
||||||
inst->SetToken(p); // mémorise l'opération
|
inst->SetToken(p); // stores the operation
|
||||||
|
|
||||||
int type1, type2;
|
int type1, type2;
|
||||||
type1 = pStack->GetType();
|
type1 = pStack->GetType();
|
||||||
|
|
||||||
p = p->Next();
|
p = p->Next();
|
||||||
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B à droite
|
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B right
|
||||||
{
|
{
|
||||||
type2 = pStack->GetType();
|
type2 = pStack->GetType();
|
||||||
// les résultats sont-ils compatibles
|
// are the results compatible
|
||||||
if ( type1 == type2 )
|
if ( type1 == type2 )
|
||||||
{
|
{
|
||||||
inst->m_leftop = left;
|
inst->m_leftop = left;
|
||||||
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
|
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
|
||||||
// le résultat est un boolean
|
// the result is a boolean
|
||||||
return pStack->Return(inst, pStk);
|
return pStack->Return(inst, pStk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,21 +83,21 @@ CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// fait l'opération
|
// perform the operation
|
||||||
|
|
||||||
bool CBotCompExpr::Execute(CBotStack* &pStack)
|
bool CBotCompExpr::Execute(CBotStack* &pStack)
|
||||||
{
|
{
|
||||||
CBotStack* pStk1 = pStack->AddStack(this);
|
CBotStack* pStk1 = pStack->AddStack(this);
|
||||||
// if ( pStk1 == EOX ) return TRUE;
|
// if ( pStk1 == EOX ) return TRUE;
|
||||||
|
|
||||||
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
|
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here ?
|
||||||
|
|
||||||
pStk1->SetState(1); // opération terminée
|
pStk1->SetState(1); // finished
|
||||||
|
|
||||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
// requires a little more stack to not touch the result of the left
|
||||||
CBotStack* pStk2 = pStk1->AddStack();
|
CBotStack* pStk2 = pStk1->AddStack();
|
||||||
|
|
||||||
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
|
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ?
|
||||||
|
|
||||||
int type1 = pStk1->GetType();
|
int type1 = pStk1->GetType();
|
||||||
int type2 = pStk2->GetType();
|
int type2 = pStk2->GetType();
|
||||||
|
@ -105,27 +107,27 @@ bool CBotCompExpr::Execute(CBotStack* &pStack)
|
||||||
switch (GetTokenType())
|
switch (GetTokenType())
|
||||||
{
|
{
|
||||||
case ID_LO:
|
case ID_LO:
|
||||||
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // inférieur
|
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower
|
||||||
break;
|
break;
|
||||||
case ID_HI:
|
case ID_HI:
|
||||||
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // supérieur
|
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher
|
||||||
break;
|
break;
|
||||||
case ID_LS:
|
case ID_LS:
|
||||||
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // inférieur ou égal
|
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal
|
||||||
break;
|
break;
|
||||||
case ID_HS:
|
case ID_HS:
|
||||||
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // supérieur ou égal
|
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal
|
||||||
break;
|
break;
|
||||||
case ID_EQ:
|
case ID_EQ:
|
||||||
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // égal
|
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal
|
||||||
break;
|
break;
|
||||||
case ID_NE:
|
case ID_NE:
|
||||||
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // différent
|
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pStk2->SetVar(result); // met le résultat sur la pile
|
pStk2->SetVar(result); // puts the result on the stack
|
||||||
|
|
||||||
pStk1->Return(pStk2); // libère la pile
|
pStk1->Return(pStk2); // frees the stack
|
||||||
return pStack->Return(pStk1); // transmet le résultat
|
return pStack->Return(pStk1); // transmit the result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -12,7 +12,7 @@
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.//////////////////////////////////////////////////////////////////////
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
|
|
||||||
//Management of the stack
|
//Management of the stack
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#define ITIMER 100
|
#define ITIMER 100
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// gestion de la pile d'exécution
|
// management of a execution of a stack
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int CBotStack::m_initimer = ITIMER;
|
int CBotStack::m_initimer = ITIMER;
|
||||||
|
@ -46,14 +46,14 @@ CBotStack* CBotStack::FirstStack()
|
||||||
long size = sizeof(CBotStack);
|
long size = sizeof(CBotStack);
|
||||||
size *= (MAXSTACK+10);
|
size *= (MAXSTACK+10);
|
||||||
|
|
||||||
// demande une tranche mémoire pour la pile
|
// request a slice of memory for the stack
|
||||||
p = (CBotStack*)malloc(size);
|
p = (CBotStack*)malloc(size);
|
||||||
|
|
||||||
// la vide totalement
|
// completely empty
|
||||||
memset(p, 0, size);
|
memset(p, 0, size);
|
||||||
|
|
||||||
p-> m_bBlock = true;
|
p-> m_bBlock = true;
|
||||||
m_timer = m_initimer; // met le timer au début
|
m_timer = m_initimer; // sets the timer at the beginning
|
||||||
|
|
||||||
CBotStack* pp = p;
|
CBotStack* pp = p;
|
||||||
pp += MAXSTACK;
|
pp += MAXSTACK;
|
||||||
|
@ -73,7 +73,7 @@ CBotStack* CBotStack::FirstStack()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_error = 0; // évite des blocages car m_error est static
|
m_error = 0; // avoids deadlocks because m_error is static
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ CBotStack::CBotStack(CBotStack* ppapa)
|
||||||
|
|
||||||
CBotStack::~CBotStack()
|
CBotStack::~CBotStack()
|
||||||
{
|
{
|
||||||
ASM_TRAP(); // utiliser Delete() à la place
|
ASM_TRAP(); // use Delete () instead
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBotStack::Delete()
|
void CBotStack::Delete()
|
||||||
|
@ -98,10 +98,10 @@ void CBotStack::Delete()
|
||||||
if (m_prev != NULL)
|
if (m_prev != NULL)
|
||||||
{
|
{
|
||||||
if ( m_prev->m_next == this )
|
if ( m_prev->m_next == this )
|
||||||
m_prev->m_next = NULL; // enlève de la chaîne
|
m_prev->m_next = NULL; // removes chain
|
||||||
|
|
||||||
if ( m_prev->m_next2 == this )
|
if ( m_prev->m_next2 == this )
|
||||||
m_prev->m_next2 = NULL; // enlève de la chaîne
|
m_prev->m_next2 = NULL; // removes chain
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_var;
|
delete m_var;
|
||||||
|
@ -113,7 +113,7 @@ void CBotStack::Delete()
|
||||||
int n = m_index;
|
int n = m_index;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// efface le bloc libéré
|
// clears the freed block
|
||||||
memset(this, 0, sizeof(CBotStack));
|
memset(this, 0, sizeof(CBotStack));
|
||||||
m_bOver = bOver;
|
m_bOver = bOver;
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -125,12 +125,12 @@ void CBotStack::Delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// routine optimisée
|
// routine improved
|
||||||
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
|
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
|
||||||
{
|
{
|
||||||
if (m_next != NULL)
|
if (m_next != NULL)
|
||||||
{
|
{
|
||||||
return m_next; // reprise dans une pile existante
|
return m_next; // included in an existing stack
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -146,7 +146,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
|
||||||
}
|
}
|
||||||
while ( p->m_prev != NULL );
|
while ( p->m_prev != NULL );
|
||||||
|
|
||||||
m_next = p; // chaîne l'élément
|
m_next = p; // chain an element
|
||||||
p->m_bBlock = bBlock;
|
p->m_bBlock = bBlock;
|
||||||
p->m_instr = instr;
|
p->m_instr = instr;
|
||||||
p->m_prog = m_prog;
|
p->m_prog = m_prog;
|
||||||
|
@ -167,11 +167,11 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
|
||||||
m_next = NULL;
|
m_next = NULL;
|
||||||
return EOX;
|
return EOX;
|
||||||
}
|
}
|
||||||
return m_next; // reprise dans une pile existante
|
return m_next; // included in an existing stack
|
||||||
}
|
}
|
||||||
CBotStack* p = AddStack(NULL, bBlock);
|
CBotStack* p = AddStack(NULL, bBlock);
|
||||||
p->m_call = instr;
|
p->m_call = instr;
|
||||||
p->m_bFunc = 2; // spécial
|
p->m_bFunc = 2; // special
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,8 +179,8 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
|
||||||
{
|
{
|
||||||
if (m_next2 != NULL)
|
if (m_next2 != NULL)
|
||||||
{
|
{
|
||||||
m_next2->m_prog = m_prog; // spécial évite un RestoreStack2
|
m_next2->m_prog = m_prog; // special avoids RestoreStack2
|
||||||
return m_next2; // reprise dans une pile existante
|
return m_next2; // included in an existing stack
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotStack* p = this;
|
CBotStack* p = this;
|
||||||
|
@ -190,7 +190,7 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
|
||||||
}
|
}
|
||||||
while ( p->m_prev != NULL );
|
while ( p->m_prev != NULL );
|
||||||
|
|
||||||
m_next2 = p; // chaîne l'élément
|
m_next2 = p; // chain an element
|
||||||
p->m_prev = this;
|
p->m_prev = this;
|
||||||
p->m_bBlock = bBlock;
|
p->m_bBlock = bBlock;
|
||||||
p->m_prog = m_prog;
|
p->m_prog = m_prog;
|
||||||
|
@ -205,27 +205,27 @@ bool CBotStack::GivBlock()
|
||||||
|
|
||||||
bool CBotStack::Return(CBotStack* pfils)
|
bool CBotStack::Return(CBotStack* pfils)
|
||||||
{
|
{
|
||||||
if ( pfils == this ) return true; // spécial
|
if ( pfils == this ) return true; // special
|
||||||
|
|
||||||
if (m_var != NULL) delete m_var; // valeur remplacée ?
|
if (m_var != NULL) delete m_var; // value replaced?
|
||||||
m_var = pfils->m_var; // résultat transmis
|
m_var = pfils->m_var; // result transmitted
|
||||||
pfils->m_var = NULL; // ne pas détruire la variable
|
pfils->m_var = NULL; // not to destroy the variable
|
||||||
|
|
||||||
m_next->Delete();m_next = NULL; // libère la pile au dessus
|
m_next->Delete();m_next = NULL; // releases the stack above
|
||||||
m_next2->Delete();m_next2 = NULL; // aussi la seconde pile (catch)
|
m_next2->Delete();m_next2 = NULL; // also the second stack (catch)
|
||||||
|
|
||||||
return (m_error == 0); // interrompu si erreur
|
return (m_error == 0); // interrupted if error
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotStack::ReturnKeep(CBotStack* pfils)
|
bool CBotStack::ReturnKeep(CBotStack* pfils)
|
||||||
{
|
{
|
||||||
if ( pfils == this ) return true; // spécial
|
if ( pfils == this ) return true; // special
|
||||||
|
|
||||||
if (m_var != NULL) delete m_var; // valeur remplacée ?
|
if (m_var != NULL) delete m_var; // value replaced?
|
||||||
m_var = pfils->m_var; // résultat transmis
|
m_var = pfils->m_var; // result transmitted
|
||||||
pfils->m_var = NULL; // ne pas détruire la variable
|
pfils->m_var = NULL; // not to destroy the variable
|
||||||
|
|
||||||
return (m_error == 0); // interrompu si erreur
|
return (m_error == 0); // interrupted if error
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotStack::StackOver()
|
bool CBotStack::StackOver()
|
||||||
|
@ -248,7 +248,7 @@ CBotStack::CBotStack(CBotStack* ppapa)
|
||||||
m_state = 0;
|
m_state = 0;
|
||||||
m_step = 1;
|
m_step = 1;
|
||||||
|
|
||||||
if (ppapa == NULL) m_timer = m_initimer; // met le timer au début
|
if (ppapa == NULL) m_timer = m_initimer; // sets the timer at the beginning
|
||||||
|
|
||||||
m_listVar = NULL;
|
m_listVar = NULL;
|
||||||
m_bDontDelete = false;
|
m_bDontDelete = false;
|
||||||
|
@ -260,27 +260,27 @@ CBotStack::CBotStack(CBotStack* ppapa)
|
||||||
m_bFunc = false;
|
m_bFunc = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructeur
|
// destructor
|
||||||
CBotStack::~CBotStack()
|
CBotStack::~CBotStack()
|
||||||
{
|
{
|
||||||
if ( m_next != EOX) delete m_next;
|
if ( m_next != EOX) delete m_next;
|
||||||
delete m_next2;
|
delete m_next2;
|
||||||
if (m_prev != NULL && m_prev->m_next == this )
|
if (m_prev != NULL && m_prev->m_next == this )
|
||||||
m_prev->m_next = NULL; // enlève de la chaîne
|
m_prev->m_next = NULL; // removes chain
|
||||||
|
|
||||||
delete m_var;
|
delete m_var;
|
||||||
if ( !m_bDontDelete ) delete m_listVar;
|
if ( !m_bDontDelete ) delete m_listVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
// routine à optimiser
|
// \TODO routine has/to optimize
|
||||||
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
|
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
|
||||||
{
|
{
|
||||||
if (m_next != NULL)
|
if (m_next != NULL)
|
||||||
{
|
{
|
||||||
return m_next; // reprise dans une pile existante
|
return m_next; // included in an existing stack
|
||||||
}
|
}
|
||||||
CBotStack* p = new CBotStack(this);
|
CBotStack* p = new CBotStack(this);
|
||||||
m_next = p; // chaîne l'élément
|
m_next = p; // chain an element
|
||||||
p->m_bBlock = bBlock;
|
p->m_bBlock = bBlock;
|
||||||
p->m_instr = instr;
|
p->m_instr = instr;
|
||||||
p->m_prog = m_prog;
|
p->m_prog = m_prog;
|
||||||
|
@ -297,15 +297,15 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
|
||||||
m_next = NULL;
|
m_next = NULL;
|
||||||
return EOX;
|
return EOX;
|
||||||
}
|
}
|
||||||
return m_next; // reprise dans une pile existante
|
return m_next; // included in an existing stack
|
||||||
}
|
}
|
||||||
CBotStack* p = new CBotStack(this);
|
CBotStack* p = new CBotStack(this);
|
||||||
m_next = p; // chaîne l'élément
|
m_next = p; // chain an element
|
||||||
p->m_bBlock = bBlock;
|
p->m_bBlock = bBlock;
|
||||||
p->m_call = instr;
|
p->m_call = instr;
|
||||||
p->m_prog = m_prog;
|
p->m_prog = m_prog;
|
||||||
p->m_step = 0;
|
p->m_step = 0;
|
||||||
p->m_bFunc = 2; // spécial
|
p->m_bFunc = 2; // special
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,12 +313,12 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
|
||||||
{
|
{
|
||||||
if (m_next2 != NULL)
|
if (m_next2 != NULL)
|
||||||
{
|
{
|
||||||
m_next2->m_prog = m_prog; // spécial évite un RestoreStack2
|
m_next2->m_prog = m_prog; // special avoids RestoreStack2
|
||||||
return m_next2; // reprise dans une pile existante
|
return m_next2; // included in an existing stack
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotStack* p = new CBotStack(this);
|
CBotStack* p = new CBotStack(this);
|
||||||
m_next2 = p; // chaîne l'élément
|
m_next2 = p; // chain an element
|
||||||
p->m_bBlock = bBlock;
|
p->m_bBlock = bBlock;
|
||||||
p->m_prog = m_prog;
|
p->m_prog = m_prog;
|
||||||
p->m_step = 0;
|
p->m_step = 0;
|
||||||
|
@ -328,28 +328,28 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
|
||||||
|
|
||||||
bool CBotStack::Return(CBotStack* pfils)
|
bool CBotStack::Return(CBotStack* pfils)
|
||||||
{
|
{
|
||||||
if ( pfils == this ) return true; // spécial
|
if ( pfils == this ) return true; // special
|
||||||
|
|
||||||
if (m_var != NULL) delete m_var; // valeur remplacée ?
|
if (m_var != NULL) delete m_var; // value replaced?
|
||||||
m_var = pfils->m_var; // résultat transmis
|
m_var = pfils->m_var; // result transmitted
|
||||||
pfils->m_var = NULL; // ne pas détruite la variable
|
pfils->m_var = NULL; // do not destroy the variable
|
||||||
|
|
||||||
if ( m_next != EOX ) delete m_next; // libère la pile au dessus
|
if ( m_next != EOX ) delete m_next; // releases the stack above
|
||||||
delete m_next2;m_next2 = NULL; // aussi la seconde pile (catch)
|
delete m_next2;m_next2 = NULL; // also the second stack (catch)
|
||||||
|
|
||||||
return (m_error == 0); // interrompu si erreur
|
return (m_error == 0); // interrupted if error
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotStack::StackOver()
|
bool CBotStack::StackOver()
|
||||||
{
|
{
|
||||||
return false; // pas de test de débordement dans cette version
|
return false; // no overflow check in this version
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CBotStack::Reset(void* pUser)
|
void CBotStack::Reset(void* pUser)
|
||||||
{
|
{
|
||||||
m_timer = m_initimer; // remet le timer
|
m_timer = m_initimer; // resets the timer
|
||||||
m_error = 0;
|
m_error = 0;
|
||||||
// m_start = 0;
|
// m_start = 0;
|
||||||
// m_end = 0;
|
// m_end = 0;
|
||||||
|
@ -364,9 +364,9 @@ CBotStack* CBotStack::RestoreStack(CBotInstr* instr)
|
||||||
{
|
{
|
||||||
if (m_next != NULL)
|
if (m_next != NULL)
|
||||||
{
|
{
|
||||||
m_next->m_instr = instr; // réinit (si reprise après restitution)
|
m_next->m_instr = instr; // reset (if recovery after )
|
||||||
m_next->m_prog = m_prog;
|
m_next->m_prog = m_prog;
|
||||||
return m_next; // reprise dans une pile existante
|
return m_next; // included in an existing stack
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -380,7 +380,7 @@ CBotStack* CBotStack::RestoreStackEOX(CBotCall* instr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// routine pour l'exécution pas à pas
|
// routine for execution step by step
|
||||||
bool CBotStack::IfStep()
|
bool CBotStack::IfStep()
|
||||||
{
|
{
|
||||||
if ( m_initimer > 0 || m_step++ > 0 ) return false;
|
if ( m_initimer > 0 || m_step++ > 0 ) return false;
|
||||||
|
@ -390,11 +390,11 @@ bool CBotStack::IfStep()
|
||||||
|
|
||||||
bool CBotStack::BreakReturn(CBotStack* pfils, const char* name)
|
bool CBotStack::BreakReturn(CBotStack* pfils, const char* name)
|
||||||
{
|
{
|
||||||
if ( m_error>=0 ) return false; // sortie normale
|
if ( m_error>=0 ) return false; // normal output
|
||||||
if ( m_error==-3 ) return false; // sortie normale (return en cours)
|
if ( m_error==-3 ) return false; // normal output (return current)
|
||||||
|
|
||||||
if (!m_labelBreak.IsEmpty() && (name[0] == 0 || m_labelBreak != name))
|
if (!m_labelBreak.IsEmpty() && (name[0] == 0 || m_labelBreak != name))
|
||||||
return false; // c'est pas pour moi
|
return false; // it's not for me
|
||||||
|
|
||||||
m_error = 0;
|
m_error = 0;
|
||||||
m_labelBreak.Empty();
|
m_labelBreak.Empty();
|
||||||
|
@ -406,27 +406,27 @@ bool CBotStack::IfContinue(int state, const char* name)
|
||||||
if ( m_error != -2 ) return false;
|
if ( m_error != -2 ) return false;
|
||||||
|
|
||||||
if (!m_labelBreak.IsEmpty() && (name == NULL || m_labelBreak != name))
|
if (!m_labelBreak.IsEmpty() && (name == NULL || m_labelBreak != name))
|
||||||
return false; // c'est pas pour moi
|
return false; // it's not for me
|
||||||
|
|
||||||
m_state = state; // où reprendre ?
|
m_state = state; // where again?
|
||||||
m_error = 0;
|
m_error = 0;
|
||||||
m_labelBreak.Empty();
|
m_labelBreak.Empty();
|
||||||
if ( m_next != EOX ) m_next->Delete(); // purge la pile au dessus
|
if ( m_next != EOX ) m_next->Delete(); // purge above stack
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBotStack::SetBreak(int val, const char* name)
|
void CBotStack::SetBreak(int val, const char* name)
|
||||||
{
|
{
|
||||||
m_error = -val; // réagit comme une Exception
|
m_error = -val; // reacts as an Exception
|
||||||
m_labelBreak = name;
|
m_labelBreak = name;
|
||||||
if (val == 3) // pour un return
|
if (val == 3) // for a return
|
||||||
{
|
{
|
||||||
m_retvar = m_var;
|
m_retvar = m_var;
|
||||||
m_var = NULL;
|
m_var = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remet sur la pile la valeur calculée par le dernier CBotReturn
|
// gives on the stack value calculated by the last CBotReturn
|
||||||
|
|
||||||
bool CBotStack::GivRetVar(bool bRet)
|
bool CBotStack::GivRetVar(bool bRet)
|
||||||
{
|
{
|
||||||
|
@ -438,7 +438,7 @@ bool CBotStack::GivRetVar(bool bRet)
|
||||||
m_error = 0;
|
m_error = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return bRet; // interrompu par autre chose que return
|
return bRet; // interrupted by something other than return
|
||||||
}
|
}
|
||||||
|
|
||||||
int CBotStack::GivError(int& start, int& end)
|
int CBotStack::GivError(int& start, int& end)
|
||||||
|
@ -557,22 +557,22 @@ bool CBotStack::SetState(int n, int limite)
|
||||||
{
|
{
|
||||||
m_state = n;
|
m_state = n;
|
||||||
|
|
||||||
m_timer--; // décompte les opérations
|
m_timer--; // decrement the operations \TODO decrement the operations
|
||||||
return ( m_timer > limite ); // interrompu si timer passé
|
return ( m_timer > limite ); // interrupted if timer pass
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotStack::IncState(int limite)
|
bool CBotStack::IncState(int limite)
|
||||||
{
|
{
|
||||||
m_state++;
|
m_state++;
|
||||||
|
|
||||||
m_timer--; // décompte les opérations
|
m_timer--; // decrement the operations \TODO decompte les operations
|
||||||
return ( m_timer > limite ); // interrompu si timer passé
|
return ( m_timer > limite ); // interrupted if timer pass
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CBotStack::SetError(int n, CBotToken* token)
|
void CBotStack::SetError(int n, CBotToken* token)
|
||||||
{
|
{
|
||||||
if ( n!= 0 && m_error != 0) return; // ne change pas une erreur déjà existante
|
if ( n!= 0 && m_error != 0) return; // does not change existing error
|
||||||
m_error = n;
|
m_error = n;
|
||||||
if (token != NULL)
|
if (token != NULL)
|
||||||
{
|
{
|
||||||
|
@ -601,7 +601,7 @@ void CBotStack::SetTimer(int n)
|
||||||
|
|
||||||
bool CBotStack::Execute()
|
bool CBotStack::Execute()
|
||||||
{
|
{
|
||||||
CBotCall* instr = NULL; // instruction la plus élevée
|
CBotCall* instr = NULL; // the most highest instruction
|
||||||
CBotStack* pile;
|
CBotStack* pile;
|
||||||
|
|
||||||
CBotStack* p = this;
|
CBotStack* p = this;
|
||||||
|
@ -617,9 +617,9 @@ bool CBotStack::Execute()
|
||||||
p = p->m_next;
|
p = p->m_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( instr == NULL ) return true; // exécution normale demandée
|
if ( instr == NULL ) return true; // normal execution request
|
||||||
|
|
||||||
if (!instr->Run(pile)) return false; // exécution à partir de là
|
if (!instr->Run(pile)) return false; // \TODO exécution à partir de là
|
||||||
|
|
||||||
#if STACKMEM
|
#if STACKMEM
|
||||||
pile->m_next->Delete();
|
pile->m_next->Delete();
|
||||||
|
@ -627,21 +627,21 @@ bool CBotStack::Execute()
|
||||||
delete pile->m_next;
|
delete pile->m_next;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pile->m_next = EOX; // spécial pour reprise
|
pile->m_next = EOX; // special for recovery
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// met sur le stack le pointeur à une variable
|
// puts on the stack pointer to a variable
|
||||||
void CBotStack::SetVar( CBotVar* var )
|
void CBotStack::SetVar( CBotVar* var )
|
||||||
{
|
{
|
||||||
if (m_var) delete m_var; // remplacement d'une variable
|
if (m_var) delete m_var; // replacement of a variable
|
||||||
m_var = var;
|
m_var = var;
|
||||||
}
|
}
|
||||||
|
|
||||||
// met sur le stack une copie d'une variable
|
// puts on the stack a copy of a variable
|
||||||
void CBotStack::SetCopyVar( CBotVar* var )
|
void CBotStack::SetCopyVar( CBotVar* var )
|
||||||
{
|
{
|
||||||
if (m_var) delete m_var; // remplacement d'une variable
|
if (m_var) delete m_var; // replacement of a variable
|
||||||
|
|
||||||
m_var = CBotVar::Create("", var->GivTypResult(2));
|
m_var = CBotVar::Create("", var->GivTypResult(2));
|
||||||
m_var->Copy( var );
|
m_var->Copy( var );
|
||||||
|
@ -655,7 +655,7 @@ CBotVar* CBotStack::GivVar()
|
||||||
CBotVar* CBotStack::GivPtVar()
|
CBotVar* CBotStack::GivPtVar()
|
||||||
{
|
{
|
||||||
CBotVar* p = m_var;
|
CBotVar* p = m_var;
|
||||||
m_var = NULL; // ne sera pas détruit donc
|
m_var = NULL; // therefore will not be destroyed
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,7 +680,7 @@ void CBotStack::AddVar(CBotVar* pVar)
|
||||||
{
|
{
|
||||||
CBotStack* p = this;
|
CBotStack* p = this;
|
||||||
|
|
||||||
// revient sur l'élement père
|
// returns to the father element
|
||||||
while (p != NULL && p->m_bBlock == 0) p = p->m_prev;
|
while (p != NULL && p->m_bBlock == 0) p = p->m_prev;
|
||||||
|
|
||||||
if ( p == NULL ) return;
|
if ( p == NULL ) return;
|
||||||
|
@ -690,7 +690,7 @@ void CBotStack::AddVar(CBotVar* pVar)
|
||||||
CBotVar** pp = &p->m_listVar;
|
CBotVar** pp = &p->m_listVar;
|
||||||
while ( *pp != NULL ) pp = &(*pp)->m_next;
|
while ( *pp != NULL ) pp = &(*pp)->m_next;
|
||||||
|
|
||||||
*pp = pVar; // ajoute à la suite
|
*pp = pVar; // added after
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
|
if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
|
||||||
|
@ -701,7 +701,7 @@ void CBotStack::AddVar(CBotVar* pVar)
|
||||||
{
|
{
|
||||||
if ( !m_bDontDelete ) __asm int 3;
|
if ( !m_bDontDelete ) __asm int 3;
|
||||||
delete m_listVar;
|
delete m_listVar;
|
||||||
m_listVar = pVar; // remplace directement
|
m_listVar = pVar; // direct replacement
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void CBotStack::SetBotCall(CBotProgram* p)
|
void CBotStack::SetBotCall(CBotProgram* p)
|
||||||
|
@ -728,7 +728,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo
|
||||||
{
|
{
|
||||||
CBotTypResult res;
|
CBotTypResult res;
|
||||||
|
|
||||||
// cherche d'abord selon l'identificateur
|
// first looks by the identifier
|
||||||
|
|
||||||
res = CBotCall::DoCall(nIdent, NULL, ppVar, this, rettype );
|
res = CBotCall::DoCall(nIdent, NULL, ppVar, this, rettype );
|
||||||
if (res.GivType() >= 0) return res.GivType();
|
if (res.GivType() >= 0) return res.GivType();
|
||||||
|
@ -736,7 +736,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo
|
||||||
res = m_prog->GivFunctions()->DoCall(nIdent, NULL, ppVar, this, token );
|
res = m_prog->GivFunctions()->DoCall(nIdent, NULL, ppVar, this, token );
|
||||||
if (res.GivType() >= 0) return res.GivType();
|
if (res.GivType() >= 0) return res.GivType();
|
||||||
|
|
||||||
// si pas trouvé (recompilé ?) cherche selon le nom
|
// if not found (recompile?) seeks by name
|
||||||
|
|
||||||
nIdent = 0;
|
nIdent = 0;
|
||||||
res = CBotCall::DoCall(nIdent, token, ppVar, this, rettype );
|
res = CBotCall::DoCall(nIdent, token, ppVar, this, rettype );
|
||||||
|
@ -764,11 +764,11 @@ bool SaveVar(FILE* pf, CBotVar* pVar)
|
||||||
{
|
{
|
||||||
if ( pVar == NULL )
|
if ( pVar == NULL )
|
||||||
{
|
{
|
||||||
return WriteWord(pf, 0); // met un terminateur
|
return WriteWord(pf, 0); // is a terminator
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !pVar->Save0State(pf)) return false; // entête commune
|
if ( !pVar->Save0State(pf)) return false; // common header
|
||||||
if ( !pVar->Save1State(pf) ) return false; // sauve selon la classe fille
|
if ( !pVar->Save1State(pf) ) return false; // saves as the child class
|
||||||
|
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
}
|
}
|
||||||
|
@ -776,10 +776,10 @@ bool SaveVar(FILE* pf, CBotVar* pVar)
|
||||||
|
|
||||||
void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
|
void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
|
||||||
{
|
{
|
||||||
CBotProgram* prog = m_prog; // programme courrant
|
CBotProgram* prog = m_prog; // Current program
|
||||||
|
|
||||||
CBotInstr* funct = NULL; // fonction trouvée
|
CBotInstr* funct = NULL; // function found
|
||||||
CBotInstr* instr = NULL; // instruction la plus élevée
|
CBotInstr* instr = NULL; // the highest intruction
|
||||||
|
|
||||||
CBotStack* p = this;
|
CBotStack* p = this;
|
||||||
|
|
||||||
|
@ -810,10 +810,10 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
|
||||||
|
|
||||||
CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level)
|
CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level)
|
||||||
{
|
{
|
||||||
CBotProgram* prog = m_prog; // programme courrant
|
CBotProgram* prog = m_prog; // current program
|
||||||
FunctionName = NULL;
|
FunctionName = NULL;
|
||||||
|
|
||||||
// remonte la pile dans le module courant
|
// back the stack in the current module
|
||||||
CBotStack* p = this;
|
CBotStack* p = this;
|
||||||
|
|
||||||
while (p->m_next != NULL)
|
while (p->m_next != NULL)
|
||||||
|
@ -825,7 +825,7 @@ CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// descend sur les éléments de block
|
// descends upon the elements of block
|
||||||
while ( p != NULL && !p->m_bBlock ) p = p->m_prev;
|
while ( p != NULL && !p->m_bBlock ) p = p->m_prev;
|
||||||
|
|
||||||
while ( p != NULL && level++ < 0 )
|
while ( p != NULL && level++ < 0 )
|
||||||
|
@ -836,7 +836,7 @@ CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level)
|
||||||
|
|
||||||
if ( p == NULL ) return NULL;
|
if ( p == NULL ) return NULL;
|
||||||
|
|
||||||
// recherche le nom de la fonction courante
|
// search the name of the current function
|
||||||
CBotStack* pp = p;
|
CBotStack* pp = p;
|
||||||
while ( pp != NULL )
|
while ( pp != NULL )
|
||||||
{
|
{
|
||||||
|
@ -854,30 +854,30 @@ CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level)
|
||||||
|
|
||||||
bool CBotStack::SaveState(FILE* pf)
|
bool CBotStack::SaveState(FILE* pf)
|
||||||
{
|
{
|
||||||
if ( this == NULL ) // fin de l'arbre ?
|
if ( this == NULL ) // end of the tree?
|
||||||
{
|
{
|
||||||
return WriteWord(pf, 0); // met un terminateur
|
return WriteWord(pf, 0); // is a terminator
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_next2 != NULL )
|
if ( m_next2 != NULL )
|
||||||
{
|
{
|
||||||
if (!WriteWord(pf, 2)) return false; // une marque de poursuite
|
if (!WriteWord(pf, 2)) return false; // a mark of pursuit
|
||||||
if (!m_next2->SaveState(pf)) return false;
|
if (!m_next2->SaveState(pf)) return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!WriteWord(pf, 1)) return false; // une marque de poursuite
|
if (!WriteWord(pf, 1)) return false; // a mark of pursuit
|
||||||
}
|
}
|
||||||
if (!WriteWord(pf, m_bBlock)) return false; // est-ce un bloc local
|
if (!WriteWord(pf, m_bBlock)) return false; // is a local block
|
||||||
if (!WriteWord(pf, m_state)) return false; // dans quel état
|
if (!WriteWord(pf, m_state)) return false; // in what state?
|
||||||
if (!WriteWord(pf, 0)) return false; // par compatibilité m_bDontDelete
|
if (!WriteWord(pf, 0)) return false; // by compatibility m_bDontDelete
|
||||||
if (!WriteWord(pf, m_step)) return false; // dans quel état
|
if (!WriteWord(pf, m_step)) return false; // in what state?
|
||||||
|
|
||||||
|
|
||||||
if (!SaveVar(pf, m_var)) return false; // le résultat courant
|
if (!SaveVar(pf, m_var)) return false; // current result
|
||||||
if (!SaveVar(pf, m_listVar)) return false; // les variables locales
|
if (!SaveVar(pf, m_listVar)) return false; // local variables
|
||||||
|
|
||||||
return m_next->SaveState(pf); // enregistre la suite
|
return m_next->SaveState(pf); // saves the following
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -901,20 +901,20 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
|
||||||
if (!pStack->RestoreState(pf, pStack->m_next2)) return false;
|
if (!pStack->RestoreState(pf, pStack->m_next2)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ReadWord(pf, w)) return false; // est-ce un bloc local
|
if (!ReadWord(pf, w)) return false; // is a local block
|
||||||
pStack->m_bBlock = w;
|
pStack->m_bBlock = w;
|
||||||
|
|
||||||
if (!ReadWord(pf, w)) return false; // dans quel état j'ère ?
|
if (!ReadWord(pf, w)) return false; // in what state ?
|
||||||
pStack->SetState((short)w); // dans le bon état
|
pStack->SetState((short)w); // in a good state
|
||||||
|
|
||||||
if (!ReadWord(pf, w)) return false; // dont delete ?
|
if (!ReadWord(pf, w)) return false; // dont delete?
|
||||||
// plus utilisé
|
// uses more
|
||||||
|
|
||||||
if (!ReadWord(pf, w)) return false; // pas à pas
|
if (!ReadWord(pf, w)) return false; // step by step
|
||||||
pStack->m_step = w;
|
pStack->m_step = w;
|
||||||
|
|
||||||
if (!CBotVar::RestoreState(pf, pStack->m_var)) return false; // la variable temp
|
if (!CBotVar::RestoreState(pf, pStack->m_var)) return false; // temp variable
|
||||||
if (!CBotVar::RestoreState(pf, pStack->m_listVar)) return false;// les variables locales
|
if (!CBotVar::RestoreState(pf, pStack->m_listVar)) return false;// local variables
|
||||||
|
|
||||||
return pStack->RestoreState(pf, pStack->m_next);
|
return pStack->RestoreState(pf, pStack->m_next);
|
||||||
}
|
}
|
||||||
|
@ -922,19 +922,19 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
|
||||||
|
|
||||||
bool CBotVar::Save0State(FILE* pf)
|
bool CBotVar::Save0State(FILE* pf)
|
||||||
{
|
{
|
||||||
if (!WriteWord(pf, 100+m_mPrivate))return false; // variable privée ?
|
if (!WriteWord(pf, 100+m_mPrivate))return false; // private variable?
|
||||||
if (!WriteWord(pf, m_bStatic))return false; // variable static ?
|
if (!WriteWord(pf, m_bStatic))return false; // static variable?
|
||||||
if (!WriteWord(pf, m_type.GivType()))return false; // enregiste le type (toujours non nul)
|
if (!WriteWord(pf, m_type.GivType()))return false; // saves the type (always non-zero)
|
||||||
if (!WriteWord(pf, m_binit))return false; // variable définie ?
|
if (!WriteWord(pf, m_binit))return false; // variable defined?
|
||||||
return WriteString(pf, m_token->GivString()); // et le nom de la variable
|
return WriteString(pf, m_token->GivString()); // and variable name
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotVarInt::Save0State(FILE* pf)
|
bool CBotVarInt::Save0State(FILE* pf)
|
||||||
{
|
{
|
||||||
if ( !m_defnum.IsEmpty() )
|
if ( !m_defnum.IsEmpty() )
|
||||||
{
|
{
|
||||||
if(!WriteWord(pf, 200 )) return false; // marqueur spécial
|
if(!WriteWord(pf, 200 )) return false; // special marker
|
||||||
if(!WriteString(pf, m_defnum)) return false; // nom de la valeur
|
if(!WriteString(pf, m_defnum)) return false; // name of the value
|
||||||
}
|
}
|
||||||
|
|
||||||
return CBotVar::Save0State(pf);
|
return CBotVar::Save0State(pf);
|
||||||
|
@ -942,22 +942,22 @@ bool CBotVarInt::Save0State(FILE* pf)
|
||||||
|
|
||||||
bool CBotVarInt::Save1State(FILE* pf)
|
bool CBotVarInt::Save1State(FILE* pf)
|
||||||
{
|
{
|
||||||
return WriteWord(pf, m_val); // la valeur de la variable
|
return WriteWord(pf, m_val); // the value of the variable
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotVarBoolean::Save1State(FILE* pf)
|
bool CBotVarBoolean::Save1State(FILE* pf)
|
||||||
{
|
{
|
||||||
return WriteWord(pf, m_val); // la valeur de la variable
|
return WriteWord(pf, m_val); // the value of the variable
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotVarFloat::Save1State(FILE* pf)
|
bool CBotVarFloat::Save1State(FILE* pf)
|
||||||
{
|
{
|
||||||
return WriteFloat(pf, m_val); // la valeur de la variable
|
return WriteFloat(pf, m_val); // the value of the variable
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotVarString::Save1State(FILE* pf)
|
bool CBotVarString::Save1State(FILE* pf)
|
||||||
{
|
{
|
||||||
return WriteString(pf, m_val); // la valeur de la variable
|
return WriteString(pf, m_val); // the value of the variable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -967,7 +967,7 @@ bool CBotVarClass::Save1State(FILE* pf)
|
||||||
if ( !WriteType(pf, m_type) ) return false;
|
if ( !WriteType(pf, m_type) ) return false;
|
||||||
if ( !WriteLong(pf, m_ItemIdent) ) return false;
|
if ( !WriteLong(pf, m_ItemIdent) ) return false;
|
||||||
|
|
||||||
return SaveVar(pf, m_pVar); // contenu de l'objet
|
return SaveVar(pf, m_pVar); // content of the object
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
|
@ -982,15 +982,15 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
CBotVar* pNew = NULL;
|
CBotVar* pNew = NULL;
|
||||||
CBotVar* pPrev = NULL;
|
CBotVar* pPrev = NULL;
|
||||||
|
|
||||||
while ( true ) // recupère toute une liste
|
while ( true ) // retrieves a list
|
||||||
{
|
{
|
||||||
if (!ReadWord(pf, w)) return false; // privé ou type ?
|
if (!ReadWord(pf, w)) return false; // private or type?
|
||||||
if ( w == 0 ) return true;
|
if ( w == 0 ) return true;
|
||||||
|
|
||||||
CBotString defnum;
|
CBotString defnum;
|
||||||
if ( w == 200 )
|
if ( w == 200 )
|
||||||
{
|
{
|
||||||
if (!ReadString(pf, defnum)) return false; // nombre avec un identifiant
|
if (!ReadString(pf, defnum)) return false; // number with identifier
|
||||||
if (!ReadWord(pf, w)) return false; // type
|
if (!ReadWord(pf, w)) return false; // type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -998,15 +998,15 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
if ( w >= 100 )
|
if ( w >= 100 )
|
||||||
{
|
{
|
||||||
prv = w;
|
prv = w;
|
||||||
if (!ReadWord(pf, st)) return false; // statique
|
if (!ReadWord(pf, st)) return false; // static
|
||||||
if (!ReadWord(pf, w)) return false; // type
|
if (!ReadWord(pf, w)) return false; // type
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( w == CBotTypClass ) w = CBotTypIntrinsic; // forcément intrinsèque
|
if ( w == CBotTypClass ) w = CBotTypIntrinsic; // necessarily intrinsic
|
||||||
|
|
||||||
if (!ReadWord(pf, wi)) return false; // init ?
|
if (!ReadWord(pf, wi)) return false; // init ?
|
||||||
|
|
||||||
if (!ReadString(pf, name)) return false; // nom de la variable
|
if (!ReadString(pf, name)) return false; // variable name
|
||||||
|
|
||||||
CBotToken token(name, CBotString());
|
CBotToken token(name, CBotString());
|
||||||
|
|
||||||
|
@ -1014,28 +1014,28 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
{
|
{
|
||||||
case CBotTypInt:
|
case CBotTypInt:
|
||||||
case CBotTypBoolean:
|
case CBotTypBoolean:
|
||||||
pNew = CBotVar::Create(&token, w); // crée une variable
|
pNew = CBotVar::Create(&token, w); // creates a variable
|
||||||
if (!ReadWord(pf, w)) return false;
|
if (!ReadWord(pf, w)) return false;
|
||||||
pNew->SetValInt((short)w, defnum);
|
pNew->SetValInt((short)w, defnum);
|
||||||
break;
|
break;
|
||||||
case CBotTypFloat:
|
case CBotTypFloat:
|
||||||
pNew = CBotVar::Create(&token, w); // crée une variable
|
pNew = CBotVar::Create(&token, w); // creates a variable
|
||||||
if (!ReadFloat(pf, ww)) return false;
|
if (!ReadFloat(pf, ww)) return false;
|
||||||
pNew->SetValFloat(ww);
|
pNew->SetValFloat(ww);
|
||||||
break;
|
break;
|
||||||
case CBotTypString:
|
case CBotTypString:
|
||||||
pNew = CBotVar::Create(&token, w); // crée une variable
|
pNew = CBotVar::Create(&token, w); // creates a variable
|
||||||
if (!ReadString(pf, s)) return false;
|
if (!ReadString(pf, s)) return false;
|
||||||
pNew->SetValString(s);
|
pNew->SetValString(s);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// restitue un objet intrinsic ou un élément d'un array
|
// returns an intrinsic object or element of an array
|
||||||
case CBotTypIntrinsic:
|
case CBotTypIntrinsic:
|
||||||
case CBotTypArrayBody:
|
case CBotTypArrayBody:
|
||||||
{
|
{
|
||||||
CBotTypResult r;
|
CBotTypResult r;
|
||||||
long id;
|
long id;
|
||||||
if (!ReadType(pf, r)) return false; // type complet
|
if (!ReadType(pf, r)) return false; // complete type
|
||||||
if (!ReadLong(pf, id) ) return false;
|
if (!ReadLong(pf, id) ) return false;
|
||||||
|
|
||||||
// if (!ReadString(pf, s)) return false;
|
// if (!ReadString(pf, s)) return false;
|
||||||
|
@ -1043,7 +1043,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
CBotVar* p = NULL;
|
CBotVar* p = NULL;
|
||||||
if ( id ) p = CBotVarClass::Find(id) ;
|
if ( id ) p = CBotVarClass::Find(id) ;
|
||||||
|
|
||||||
pNew = new CBotVarClass(&token, r); // crée directement une instance
|
pNew = new CBotVarClass(&token, r); // directly creates an instance
|
||||||
// attention cptuse = 0
|
// attention cptuse = 0
|
||||||
if ( !RestoreState(pf, ((CBotVarClass*)pNew)->m_pVar)) return false;
|
if ( !RestoreState(pf, ((CBotVarClass*)pNew)->m_pVar)) return false;
|
||||||
pNew->SetIdent(id);
|
pNew->SetIdent(id);
|
||||||
|
@ -1051,7 +1051,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
if ( p != NULL )
|
if ( p != NULL )
|
||||||
{
|
{
|
||||||
delete pNew;
|
delete pNew;
|
||||||
pNew = p; // reprend l'élément connu
|
pNew = p; // resume known element
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1061,18 +1061,18 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
case CBotTypNullPointer:
|
case CBotTypNullPointer:
|
||||||
if (!ReadString(pf, s)) return false;
|
if (!ReadString(pf, s)) return false;
|
||||||
{
|
{
|
||||||
pNew = CBotVar::Create(&token, CBotTypResult(w, s));// crée une variable
|
pNew = CBotVar::Create(&token, CBotTypResult(w, s));// creates a variable
|
||||||
CBotVarClass* p = NULL;
|
CBotVarClass* p = NULL;
|
||||||
long id;
|
long id;
|
||||||
ReadLong(pf, id);
|
ReadLong(pf, id);
|
||||||
// if ( id ) p = CBotVarClass::Find(id); // retrouve l'instance ( fait par RestoreInstance )
|
// if ( id ) p = CBotVarClass::Find(id); // found the instance (made by RestoreInstance)
|
||||||
|
|
||||||
// restitue une copie de l'instance d'origine
|
// returns a copy of the original instance
|
||||||
CBotVar* pInstance = NULL;
|
CBotVar* pInstance = NULL;
|
||||||
if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
|
if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
|
||||||
((CBotVarPointer*)pNew)->SetPointer( pInstance ); // et pointe dessus
|
((CBotVarPointer*)pNew)->SetPointer( pInstance ); // and point over
|
||||||
|
|
||||||
// if ( p != NULL ) ((CBotVarPointer*)pNew)->SetPointer( p ); // plutôt celui-ci !
|
// if ( p != NULL ) ((CBotVarPointer*)pNew)->SetPointer( p ); // rather this one
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1082,12 +1082,12 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
CBotTypResult r;
|
CBotTypResult r;
|
||||||
if (!ReadType(pf, r)) return false;
|
if (!ReadType(pf, r)) return false;
|
||||||
|
|
||||||
pNew = CBotVar::Create(&token, r); // crée une variable
|
pNew = CBotVar::Create(&token, r); // creates a variable
|
||||||
|
|
||||||
// restitue une copie de l'instance d'origine
|
// returns a copy of the original instance
|
||||||
CBotVar* pInstance = NULL;
|
CBotVar* pInstance = NULL;
|
||||||
if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
|
if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
|
||||||
((CBotVarPointer*)pNew)->SetPointer( pInstance ); // et pointe dessus
|
((CBotVarPointer*)pNew)->SetPointer( pInstance ); // and point over
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1109,10 +1109,10 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// gestion de la pile à la compilation
|
// management of the compile stack
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
CBotProgram* CBotCStack::m_prog = NULL; // init la variable statique
|
CBotProgram* CBotCStack::m_prog = NULL; // init the static variable
|
||||||
int CBotCStack::m_error = 0;
|
int CBotCStack::m_error = 0;
|
||||||
int CBotCStack::m_end = 0;
|
int CBotCStack::m_end = 0;
|
||||||
CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
|
CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
|
||||||
|
@ -1141,23 +1141,23 @@ CBotCStack::CBotCStack(CBotCStack* ppapa)
|
||||||
m_var = NULL;
|
m_var = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructeur
|
// destructor
|
||||||
CBotCStack::~CBotCStack()
|
CBotCStack::~CBotCStack()
|
||||||
{
|
{
|
||||||
if (m_next != NULL) delete m_next;
|
if (m_next != NULL) delete m_next;
|
||||||
if (m_prev != NULL) m_prev->m_next = NULL; // enlève de la chaîne
|
if (m_prev != NULL) m_prev->m_next = NULL; // removes chain
|
||||||
|
|
||||||
delete m_var;
|
delete m_var;
|
||||||
delete m_listVar;
|
delete m_listVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
// utilisé uniquement à la compilation
|
// used only at compile
|
||||||
CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock)
|
CBotCStack* CBotCStack::TokenStack(CBotToken* pToken, bool bBlock)
|
||||||
{
|
{
|
||||||
if (m_next != NULL) return m_next; // reprise dans une pile existante
|
if (m_next != NULL) return m_next; // include on an existing stack
|
||||||
|
|
||||||
CBotCStack* p = new CBotCStack(this);
|
CBotCStack* p = new CBotCStack(this);
|
||||||
m_next = p; // chaîne l'élément
|
m_next = p; // channel element
|
||||||
p->m_bBlock = bBlock;
|
p->m_bBlock = bBlock;
|
||||||
|
|
||||||
if (pToken != NULL) p->SetStartError(pToken->GivStart());
|
if (pToken != NULL) p->SetStartError(pToken->GivStart());
|
||||||
|
@ -1170,13 +1170,13 @@ CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
|
||||||
{
|
{
|
||||||
if ( pfils == this ) return inst;
|
if ( pfils == this ) return inst;
|
||||||
|
|
||||||
if (m_var != NULL) delete m_var; // valeur remplacée ?
|
if (m_var != NULL) delete m_var; // value replaced?
|
||||||
m_var = pfils->m_var; // résultat transmis
|
m_var = pfils->m_var; // result transmitted
|
||||||
pfils->m_var = NULL; // ne pas détruire la variable
|
pfils->m_var = NULL; // not to destroy the variable
|
||||||
|
|
||||||
if (m_error)
|
if (m_error)
|
||||||
{
|
{
|
||||||
m_start = pfils->m_start; // récupère la position de l'erreur
|
m_start = pfils->m_start; // retrieves the position of the error
|
||||||
m_end = pfils->m_end;
|
m_end = pfils->m_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1186,13 +1186,13 @@ CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
|
||||||
|
|
||||||
CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
|
CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
|
||||||
{
|
{
|
||||||
if (m_var != NULL) delete m_var; // valeur remplacée ?
|
if (m_var != NULL) delete m_var; // value replaced?
|
||||||
m_var = pfils->m_var; // résultat transmis
|
m_var = pfils->m_var; // result transmitted
|
||||||
pfils->m_var = NULL; // ne pas détruire la variable
|
pfils->m_var = NULL; // not to destroy the variable
|
||||||
|
|
||||||
if (m_error)
|
if (m_error)
|
||||||
{
|
{
|
||||||
m_start = pfils->m_start; // récupère la position de l'erreur
|
m_start = pfils->m_start; // retrieves the position of the error
|
||||||
m_end = pfils->m_end;
|
m_end = pfils->m_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1212,7 +1212,7 @@ int CBotCStack::GivError()
|
||||||
return m_error;
|
return m_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// type d'instruction sur la pile
|
// type of instruction on the stack
|
||||||
CBotTypResult CBotCStack::GivTypResult(int mode)
|
CBotTypResult CBotCStack::GivTypResult(int mode)
|
||||||
{
|
{
|
||||||
if (m_var == NULL)
|
if (m_var == NULL)
|
||||||
|
@ -1220,7 +1220,7 @@ CBotTypResult CBotCStack::GivTypResult(int mode)
|
||||||
return m_var->GivTypResult(mode);
|
return m_var->GivTypResult(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// type d'instruction sur la pile
|
// type of instruction on the stack
|
||||||
int CBotCStack::GivType(int mode)
|
int CBotCStack::GivType(int mode)
|
||||||
{
|
{
|
||||||
if (m_var == NULL)
|
if (m_var == NULL)
|
||||||
|
@ -1228,7 +1228,7 @@ int CBotCStack::GivType(int mode)
|
||||||
return m_var->GivType(mode);
|
return m_var->GivType(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pointeur sur la pile est de quelle classe ?
|
// pointer on the stack is in what class?
|
||||||
CBotClass* CBotCStack::GivClass()
|
CBotClass* CBotCStack::GivClass()
|
||||||
{
|
{
|
||||||
if ( m_var == NULL )
|
if ( m_var == NULL )
|
||||||
|
@ -1238,16 +1238,16 @@ CBotClass* CBotCStack::GivClass()
|
||||||
return m_var->GivClass();
|
return m_var->GivClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
// type d'instruction sur la pile
|
// type of instruction on the stack
|
||||||
void CBotCStack::SetType(CBotTypResult& type)
|
void CBotCStack::SetType(CBotTypResult& type)
|
||||||
{
|
{
|
||||||
if (m_var == NULL) return;
|
if (m_var == NULL) return;
|
||||||
m_var->SetType( type );
|
m_var->SetType( type );
|
||||||
}
|
}
|
||||||
|
|
||||||
// cherche une variable sur la pile
|
// seeks a variable on the stack
|
||||||
// le token peut être une suite de TokenTypVar (objet d'une classe)
|
// the token may be a result of TokenTypVar (object of a class)
|
||||||
// ou un pointeur dans le source
|
// or a pointer in the source
|
||||||
|
|
||||||
CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
|
CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
|
||||||
{
|
{
|
||||||
|
@ -1295,20 +1295,20 @@ bool CBotCStack::IsOk()
|
||||||
|
|
||||||
void CBotCStack::SetStartError( int pos )
|
void CBotCStack::SetStartError( int pos )
|
||||||
{
|
{
|
||||||
if ( m_error != 0) return; // ne change pas une erreur déjà existante
|
if ( m_error != 0) return; // does not change existing error
|
||||||
m_start = pos;
|
m_start = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBotCStack::SetError(int n, int pos)
|
void CBotCStack::SetError(int n, int pos)
|
||||||
{
|
{
|
||||||
if ( n!= 0 && m_error != 0) return; // ne change pas une erreur déjà existante
|
if ( n!= 0 && m_error != 0) return; // does not change existing error
|
||||||
m_error = n;
|
m_error = n;
|
||||||
m_end = pos;
|
m_end = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBotCStack::SetError(int n, CBotToken* p)
|
void CBotCStack::SetError(int n, CBotToken* p)
|
||||||
{
|
{
|
||||||
if (m_error) return; // ne change pas une erreur déjà existante
|
if (m_error) return; // does not change existing error
|
||||||
m_error = n;
|
m_error = n;
|
||||||
m_start = p->GivStart();
|
m_start = p->GivStart();
|
||||||
m_end = p->GivEnd();
|
m_end = p->GivEnd();
|
||||||
|
@ -1354,14 +1354,14 @@ CBotTypResult CBotCStack::GivRetType()
|
||||||
|
|
||||||
void CBotCStack::SetVar( CBotVar* var )
|
void CBotCStack::SetVar( CBotVar* var )
|
||||||
{
|
{
|
||||||
if (m_var) delete m_var; // remplacement d'une variable
|
if (m_var) delete m_var; // replacement of a variable
|
||||||
m_var = var;
|
m_var = var;
|
||||||
}
|
}
|
||||||
|
|
||||||
// met sur le stack une copie d'une variable
|
// puts on the stack a copy of a variable
|
||||||
void CBotCStack::SetCopyVar( CBotVar* var )
|
void CBotCStack::SetCopyVar( CBotVar* var )
|
||||||
{
|
{
|
||||||
if (m_var) delete m_var; // remplacement d'une variable
|
if (m_var) delete m_var; // replacement of a variable
|
||||||
|
|
||||||
if ( var == NULL ) return;
|
if ( var == NULL ) return;
|
||||||
m_var = CBotVar::Create("", var->GivTypResult(2));
|
m_var = CBotVar::Create("", var->GivTypResult(2));
|
||||||
|
@ -1377,7 +1377,7 @@ void CBotCStack::AddVar(CBotVar* pVar)
|
||||||
{
|
{
|
||||||
CBotCStack* p = this;
|
CBotCStack* p = this;
|
||||||
|
|
||||||
// revient sur l'élement père
|
// returns to the father element
|
||||||
while (p != NULL && p->m_bBlock == 0) p = p->m_prev;
|
while (p != NULL && p->m_bBlock == 0) p = p->m_prev;
|
||||||
|
|
||||||
if ( p == NULL ) return;
|
if ( p == NULL ) return;
|
||||||
|
@ -1385,14 +1385,14 @@ void CBotCStack::AddVar(CBotVar* pVar)
|
||||||
CBotVar** pp = &p->m_listVar;
|
CBotVar** pp = &p->m_listVar;
|
||||||
while ( *pp != NULL ) pp = &(*pp)->m_next;
|
while ( *pp != NULL ) pp = &(*pp)->m_next;
|
||||||
|
|
||||||
*pp = pVar; // ajoute à la suite
|
*pp = pVar; // added after
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
|
if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// test si une variable est déjà définie localement
|
// test whether a variable is already defined locally
|
||||||
|
|
||||||
bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
|
bool CBotCStack::CheckVarLocal(CBotToken* &pToken)
|
||||||
{
|
{
|
||||||
|
@ -1425,7 +1425,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
|
||||||
val = m_prog->GivFunctions()->CompileCall(p->GivString(), ppVars, nIdent);
|
val = m_prog->GivFunctions()->CompileCall(p->GivString(), ppVars, nIdent);
|
||||||
if ( val.GivType() < 0 )
|
if ( val.GivType() < 0 )
|
||||||
{
|
{
|
||||||
// pVar = NULL; // l'erreur n'est pas sur un paramètre en particulier
|
// pVar = NULL; // the error is not on a particular parameter
|
||||||
SetError( -val.GivType(), p );
|
SetError( -val.GivType(), p );
|
||||||
val.SetType(-val.GivType());
|
val.SetType(-val.GivType());
|
||||||
return val;
|
return val;
|
||||||
|
@ -1434,7 +1434,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
// test si un nom de procédure est déjà défini quelque part
|
// test if a procedure name is already defined somewhere
|
||||||
|
|
||||||
bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
|
bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
|
||||||
{
|
{
|
||||||
|
@ -1447,7 +1447,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
|
||||||
{
|
{
|
||||||
if ( pToken->GivString() == pp->GivName() )
|
if ( pToken->GivString() == pp->GivName() )
|
||||||
{
|
{
|
||||||
// les paramètres sont-ils exactement les mêmes ?
|
// are parameters exactly the same?
|
||||||
if ( pp->CheckParam( pParam ) )
|
if ( pp->CheckParam( pParam ) )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1459,7 +1459,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
|
||||||
{
|
{
|
||||||
if ( pToken->GivString() == pp->GivName() )
|
if ( pToken->GivString() == pp->GivName() )
|
||||||
{
|
{
|
||||||
// les paramètres sont-ils exactement les mêmes ?
|
// are parameters exactly the same?
|
||||||
if ( pp->CheckParam( pParam ) )
|
if ( pp->CheckParam( pParam ) )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/./////////////////////////////////////////////////////
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
//strings management
|
//strings management
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
// x
|
// x
|
||||||
// )
|
// )
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
|
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
|
||||||
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);
|
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);
|
||||||
|
|
|
@ -12,18 +12,20 @@
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
// expression du genre Opérande1 + Opérande2
|
|
||||||
// Opérande1 > Opérande2
|
///////////////////////////////////////////////////
|
||||||
|
// expression of type Opérande1 + Opérande2
|
||||||
|
// Opérande1 > Opérande2
|
||||||
|
|
||||||
#include "CBot.h"
|
#include "CBot.h"
|
||||||
|
|
||||||
// divers constructeurs
|
// various constructors
|
||||||
|
|
||||||
CBotTwoOpExpr::CBotTwoOpExpr()
|
CBotTwoOpExpr::CBotTwoOpExpr()
|
||||||
{
|
{
|
||||||
m_leftop =
|
m_leftop =
|
||||||
m_rightop = NULL; // NULL pour pouvoir faire delete sans autre
|
m_rightop = NULL; // NULL to be able to delete without other
|
||||||
name = "CBotTwoOpExpr"; // debug
|
name = "CBotTwoOpExpr"; // debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ CBotLogicExpr::CBotLogicExpr()
|
||||||
{
|
{
|
||||||
m_condition =
|
m_condition =
|
||||||
m_op1 =
|
m_op1 =
|
||||||
m_op2 = NULL; // NULL pour pouvoir faire delete sans autre
|
m_op2 = NULL; // NULL to be able to delete without other
|
||||||
name = "CBotLogicExpr"; // debug
|
name = "CBotLogicExpr"; // debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ CBotLogicExpr::~CBotLogicExpr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// type d'opérandes acceptés par les opérations
|
// type of operands accepted by operations
|
||||||
#define ENTIER ((1<<CBotTypByte)|(1<<CBotTypShort)|(1<<CBotTypChar)|(1<<CBotTypInt)|(1<<CBotTypLong))
|
#define ENTIER ((1<<CBotTypByte)|(1<<CBotTypShort)|(1<<CBotTypChar)|(1<<CBotTypInt)|(1<<CBotTypLong))
|
||||||
#define FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
|
#define FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
|
||||||
#define BOOLEEN (1<<CBotTypBoolean)
|
#define BOOLEEN (1<<CBotTypBoolean)
|
||||||
|
@ -57,9 +59,9 @@ CBotLogicExpr::~CBotLogicExpr()
|
||||||
#define POINTER (1<<CBotTypPointer)
|
#define POINTER (1<<CBotTypPointer)
|
||||||
#define INSTANCE (1<<CBotTypClass)
|
#define INSTANCE (1<<CBotTypClass)
|
||||||
|
|
||||||
// liste des opérations (précéance)
|
// list of operations (précéance)
|
||||||
// type acceptable, opérande
|
// acceptable type, operand
|
||||||
// le zéro termine un niveau de précéance
|
// zero ends level \TODO précéance
|
||||||
|
|
||||||
static int ListOp[] =
|
static int ListOp[] =
|
||||||
{
|
{
|
||||||
|
@ -114,7 +116,7 @@ bool TypeOk( int type, int test )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// compile une instruction de type A op B
|
// compiles a instruction of type A op B
|
||||||
|
|
||||||
CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
|
CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
|
||||||
{
|
{
|
||||||
|
@ -122,25 +124,25 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
||||||
|
|
||||||
if ( pOperations == NULL ) pOperations = ListOp;
|
if ( pOperations == NULL ) pOperations = ListOp;
|
||||||
int* pOp = pOperations;
|
int* pOp = pOperations;
|
||||||
while ( *pOp++ != 0 ); // suite de la table
|
while ( *pOp++ != 0 ); // follows the table
|
||||||
|
|
||||||
CBotCStack* pStk = pStack->TokenStack(); // un bout de pile svp
|
CBotCStack* pStk = pStack->TokenStack(); // one end of stack please
|
||||||
|
|
||||||
// cherche des instructions qui peuvent convenir à gauche de l'opération
|
// search the intructions that may be suitable to the left of the operation
|
||||||
CBotInstr* left = (*pOp == 0) ?
|
CBotInstr* left = (*pOp == 0) ?
|
||||||
CBotParExpr::Compile( p, pStk ) : // expression (...) à gauche
|
CBotParExpr::Compile( p, pStk ) : // expression (...) left
|
||||||
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B à gauche
|
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B left
|
||||||
|
|
||||||
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
|
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
|
||||||
|
|
||||||
// est-ce qu'on a l'opérande prévu ensuite ?
|
// did we expected the operand?
|
||||||
int TypeOp = p->GivType();
|
int TypeOp = p->GivType();
|
||||||
if ( IsInList( TypeOp, pOperations, typemasque ) )
|
if ( IsInList( TypeOp, pOperations, typemasque ) )
|
||||||
{
|
{
|
||||||
CBotTypResult type1, type2;
|
CBotTypResult type1, type2;
|
||||||
type1 = pStk->GivTypResult(); // de quel type le premier opérande ?
|
type1 = pStk->GivTypResult(); // what kind of the first operand?
|
||||||
|
|
||||||
if ( TypeOp == ID_LOGIC ) // cas spécial pour condition ? op1 : op2 ;
|
if ( TypeOp == ID_LOGIC ) // special case provided for: ? op1: op2;
|
||||||
{
|
{
|
||||||
if ( !type1.Eq(CBotTypBoolean) )
|
if ( !type1.Eq(CBotTypBoolean) )
|
||||||
{
|
{
|
||||||
|
@ -150,7 +152,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
||||||
CBotLogicExpr* inst = new CBotLogicExpr();
|
CBotLogicExpr* inst = new CBotLogicExpr();
|
||||||
inst->m_condition = left;
|
inst->m_condition = left;
|
||||||
|
|
||||||
p = p->GivNext(); // saute le token de l'opération
|
p = p->GivNext(); // skip the token of the operation
|
||||||
inst->m_op1 = CBotExpression::Compile(p, pStk);
|
inst->m_op1 = CBotExpression::Compile(p, pStk);
|
||||||
CBotToken* pp = p;
|
CBotToken* pp = p;
|
||||||
if ( inst->m_op1 == NULL || !IsOfType( p, ID_DOTS ) )
|
if ( inst->m_op1 == NULL || !IsOfType( p, ID_DOTS ) )
|
||||||
|
@ -176,39 +178,39 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
||||||
return pStack->Return(NULL, pStk);
|
return pStack->Return(NULL, pStk);
|
||||||
}
|
}
|
||||||
|
|
||||||
pStk->SetType(type1); // le plus grand des 2 types
|
pStk->SetType(type1); // the greatest of 2 types
|
||||||
|
|
||||||
return pStack->Return(inst, pStk);
|
return pStack->Return(inst, pStk);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // élément pour opération
|
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // element for operation
|
||||||
inst->SetToken(p); // mémorise l'opération
|
inst->SetToken(p); // stores the operation
|
||||||
|
|
||||||
|
|
||||||
p = p->GivNext(); // saute le token de l'opération
|
p = p->GivNext(); // skip the token of the operation
|
||||||
|
|
||||||
// cherche des instructions qui peuvent convenir à droite
|
// looking statements that may be suitable for right
|
||||||
|
|
||||||
if ( NULL != (inst->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp )) )
|
if ( NULL != (inst->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp )) )
|
||||||
// expression (...) à droite
|
// expression (...) right
|
||||||
{
|
{
|
||||||
// il y a un second opérande acceptable
|
// there is an second operand acceptable
|
||||||
|
|
||||||
type2 = pStk->GivTypResult(); // de quel type le résultat ?
|
type2 = pStk->GivTypResult(); // what kind of results?
|
||||||
|
|
||||||
// quel est le type du résultat ?
|
// what kind of result?
|
||||||
int TypeRes = MAX( type1.GivType(3), type2.GivType(3) );
|
int TypeRes = MAX( type1.GivType(3), type2.GivType(3) );
|
||||||
if ( TypeOp == ID_ADD && type1.Eq(CBotTypString) )
|
if ( TypeOp == ID_ADD && type1.Eq(CBotTypString) )
|
||||||
{
|
{
|
||||||
TypeRes = CBotTypString;
|
TypeRes = CBotTypString;
|
||||||
type2 = type1; // tout type convertible en chaîne
|
type2 = type1; // any type convertible chain
|
||||||
}
|
}
|
||||||
else if ( TypeOp == ID_ADD && type2.Eq(CBotTypString) )
|
else if ( TypeOp == ID_ADD && type2.Eq(CBotTypString) )
|
||||||
{
|
{
|
||||||
TypeRes = CBotTypString;
|
TypeRes = CBotTypString;
|
||||||
type1 = type2; // tout type convertible en chaîne
|
type1 = type2; // any type convertible chain
|
||||||
}
|
}
|
||||||
else if (!TypeOk( TypeRes, typemasque )) type1.SetType(99);// erreur de type
|
else if (!TypeOk( TypeRes, typemasque )) type1.SetType(99);// error of type
|
||||||
|
|
||||||
switch ( TypeOp )
|
switch ( TypeOp )
|
||||||
{
|
{
|
||||||
|
@ -224,25 +226,25 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
||||||
case ID_LS:
|
case ID_LS:
|
||||||
TypeRes = CBotTypBoolean;
|
TypeRes = CBotTypBoolean;
|
||||||
}
|
}
|
||||||
if ( TypeCompatible (type1, type2, TypeOp ) ) // les résultats sont-ils compatibles
|
if ( TypeCompatible (type1, type2, TypeOp ) ) // the results are compatible
|
||||||
{
|
{
|
||||||
// si ok, enregistre l'opérande dans l'objet
|
// ok so, saves the operand in the object
|
||||||
inst->m_leftop = left;
|
inst->m_leftop = left;
|
||||||
|
|
||||||
// spécial pour évaluer les opérations de même niveau de gauche à droite
|
// special for evaluation of the operations of the same level from left to right
|
||||||
while ( IsInList( p->GivType(), pOperations, typemasque ) ) // même(s) opération(s) suit ?
|
while ( IsInList( p->GivType(), pOperations, typemasque ) ) // same operation(s) follows?
|
||||||
{
|
{
|
||||||
TypeOp = p->GivType();
|
TypeOp = p->GivType();
|
||||||
CBotTwoOpExpr* i = new CBotTwoOpExpr(); // élément pour opération
|
CBotTwoOpExpr* i = new CBotTwoOpExpr(); // element for operation
|
||||||
i->SetToken(p); // mémorise l'opération
|
i->SetToken(p); // stores the operation
|
||||||
i->m_leftop = inst; // opérande de gauche
|
i->m_leftop = inst; // left operand
|
||||||
type1 = TypeRes;
|
type1 = TypeRes;
|
||||||
|
|
||||||
p = p->GivNext(); // avance à la suite
|
p = p->GivNext(); // advance after
|
||||||
i->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp );
|
i->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp );
|
||||||
type2 = pStk->GivTypResult();
|
type2 = pStk->GivTypResult();
|
||||||
|
|
||||||
if ( !TypeCompatible (type1, type2, TypeOp) ) // les résultats sont-ils compatibles
|
if ( !TypeCompatible (type1, type2, TypeOp) ) // the results are compatible
|
||||||
{
|
{
|
||||||
pStk->SetError(TX_BAD2TYPE, &i->m_token);
|
pStk->SetError(TX_BAD2TYPE, &i->m_token);
|
||||||
delete i;
|
delete i;
|
||||||
|
@ -256,25 +258,25 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
|
||||||
|
|
||||||
CBotTypResult t(type1);
|
CBotTypResult t(type1);
|
||||||
t.SetType(TypeRes);
|
t.SetType(TypeRes);
|
||||||
// met une variable sur la pile pour avoir le type de résultat
|
// is a variable on the stack for the type of result
|
||||||
pStk->SetVar(CBotVar::Create((CBotToken*)NULL, t));
|
pStk->SetVar(CBotVar::Create((CBotToken*)NULL, t));
|
||||||
|
|
||||||
// et rend l'object à qui l'a demandé
|
// and returns the requested object
|
||||||
return pStack->Return(inst, pStk);
|
return pStack->Return(inst, pStk);
|
||||||
}
|
}
|
||||||
pStk->SetError(TX_BAD2TYPE, &inst->m_token);
|
pStk->SetError(TX_BAD2TYPE, &inst->m_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
// en cas d'erreur, libère les éléments
|
// in case of error, releases the elements
|
||||||
delete left;
|
delete left;
|
||||||
delete inst;
|
delete inst;
|
||||||
// et transmet l'erreur qui se trouve sur la pile
|
// and transmits the error to the stack
|
||||||
return pStack->Return(NULL, pStk);
|
return pStack->Return(NULL, pStk);
|
||||||
}
|
}
|
||||||
|
|
||||||
// si on n'a pas affaire à une opération + ou -
|
// if we are not dealing with an operation + or -
|
||||||
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
|
// goes to that requested, the operand (left) found
|
||||||
// à la place de l'objet "addition"
|
// instead of the object "addition"
|
||||||
return pStack->Return(left, pStk);
|
return pStack->Return(left, pStk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,62 +292,62 @@ bool IsNan(CBotVar* left, CBotVar* right, int* err = NULL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// fait l'opération sur 2 opérandes
|
// performes the operation on two operands
|
||||||
|
|
||||||
bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
|
bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
|
||||||
{
|
{
|
||||||
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
|
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
|
||||||
// ou le retrouve en cas de reprise
|
// or return in case of recovery
|
||||||
// if ( pStk1 == EOX ) return true;
|
// if ( pStk1 == EOX ) return true;
|
||||||
|
|
||||||
// selon la reprise, on peut être dans l'un des 2 états
|
// according to recovery, it may be in one of two states
|
||||||
|
|
||||||
if ( pStk1->GivState() == 0 ) // 1er état, évalue l'opérande de gauche
|
if ( pStk1->GivState() == 0 ) // first state, evaluates the left operand
|
||||||
{
|
{
|
||||||
if (!m_leftop->Execute(pStk1) ) return false; // interrompu ici ?
|
if (!m_leftop->Execute(pStk1) ) return false; // interrupted here?
|
||||||
|
|
||||||
// pour les OU et ET logique, n'évalue pas la seconde expression si pas nécessaire
|
// for OR and AND logic does not evaluate the second expression if not necessary
|
||||||
if ( (GivTokenType() == ID_LOG_AND || GivTokenType() == ID_TXT_AND ) && pStk1->GivVal() == false )
|
if ( (GivTokenType() == ID_LOG_AND || GivTokenType() == ID_TXT_AND ) && pStk1->GivVal() == false )
|
||||||
{
|
{
|
||||||
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
|
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
|
||||||
res->SetValInt(false);
|
res->SetValInt(false);
|
||||||
pStk1->SetVar(res);
|
pStk1->SetVar(res);
|
||||||
return pStack->Return(pStk1); // transmet le résultat
|
return pStack->Return(pStk1); // transmits the result
|
||||||
}
|
}
|
||||||
if ( (GivTokenType() == ID_LOG_OR||GivTokenType() == ID_TXT_OR) && pStk1->GivVal() == true )
|
if ( (GivTokenType() == ID_LOG_OR||GivTokenType() == ID_TXT_OR) && pStk1->GivVal() == true )
|
||||||
{
|
{
|
||||||
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
|
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
|
||||||
res->SetValInt(true);
|
res->SetValInt(true);
|
||||||
pStk1->SetVar(res);
|
pStk1->SetVar(res);
|
||||||
return pStack->Return(pStk1); // transmet le résultat
|
return pStack->Return(pStk1); // transmits the result
|
||||||
}
|
}
|
||||||
|
|
||||||
// passe à l'étape suivante
|
// passes to the next step
|
||||||
pStk1->SetState(1); // prêt pour la suite
|
pStk1->SetState(1); // ready for further
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
|
// requires a little more stack to avoid touching the result
|
||||||
// qui se trouve sur la pile, justement.
|
// of which is left on the stack, precisely
|
||||||
|
|
||||||
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
|
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
|
||||||
// ou le retrouve en cas de reprise
|
// or return in case of recovery
|
||||||
|
|
||||||
// 2e état, évalue l'opérande de droite
|
// 2e état, évalue l'opérande de droite
|
||||||
if ( pStk2->GivState() == 0 )
|
if ( pStk2->GivState() == 0 )
|
||||||
{
|
{
|
||||||
if ( !m_rightop->Execute(pStk2) ) return false; // interrompu ici ?
|
if ( !m_rightop->Execute(pStk2) ) return false; // interrupted here?
|
||||||
pStk2->IncState();
|
pStk2->IncState();
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotTypResult type1 = pStk1->GivTypResult(); // de quels types les résultats ?
|
CBotTypResult type1 = pStk1->GivTypResult(); // what kind of results?
|
||||||
CBotTypResult type2 = pStk2->GivTypResult();
|
CBotTypResult type2 = pStk2->GivTypResult();
|
||||||
|
|
||||||
CBotStack* pStk3 = pStk2->AddStack(this); // ajoute un élément à la pile
|
CBotStack* pStk3 = pStk2->AddStack(this); // adds an item to the stack
|
||||||
if ( pStk3->IfStep() ) return false; // montre l'opération si step by step
|
if ( pStk3->IfStep() ) return false; // shows the operation if step by step
|
||||||
|
|
||||||
// crée une variable temporaire pour y mettre le résultat
|
// creates a temporary variable to put the result
|
||||||
// quel est le type du résultat ?
|
// what kind of result?
|
||||||
int TypeRes = MAX(type1.GivType(), type2.GivType());
|
int TypeRes = MAX(type1.GivType(), type2.GivType());
|
||||||
|
|
||||||
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
|
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
|
||||||
|
@ -371,10 +373,10 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
|
||||||
TypeRes = MAX(TypeRes, CBotTypFloat);
|
TypeRes = MAX(TypeRes, CBotTypFloat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// crée une variable pour le résultat
|
// creates a variable for the result
|
||||||
CBotVar* result = CBotVar::Create( (CBotToken*)NULL, TypeRes);
|
CBotVar* result = CBotVar::Create( (CBotToken*)NULL, TypeRes);
|
||||||
|
|
||||||
// crée une variable pour effectuer le calcul dans le type adapté
|
// creates a variable to perform the calculation in the appropriate type
|
||||||
TypeRes = MAX(type1.GivType(), type2.GivType());
|
TypeRes = MAX(type1.GivType(), type2.GivType());
|
||||||
|
|
||||||
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
|
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
|
||||||
|
@ -389,70 +391,70 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
|
||||||
else temp = CBotVar::Create( (CBotToken*)NULL, TypeRes );
|
else temp = CBotVar::Create( (CBotToken*)NULL, TypeRes );
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
// fait l'opération selon la demande
|
// is a operation according to request
|
||||||
CBotVar* left = pStk1->GivVar();
|
CBotVar* left = pStk1->GivVar();
|
||||||
CBotVar* right = pStk2->GivVar();
|
CBotVar* right = pStk2->GivVar();
|
||||||
|
|
||||||
switch (GivTokenType())
|
switch (GivTokenType())
|
||||||
{
|
{
|
||||||
case ID_ADD:
|
case ID_ADD:
|
||||||
if ( !IsNan(left, right, &err) ) result->Add(left , right); // additionne
|
if ( !IsNan(left, right, &err) ) result->Add(left , right); // addition
|
||||||
break;
|
break;
|
||||||
case ID_SUB:
|
case ID_SUB:
|
||||||
if ( !IsNan(left, right, &err) ) result->Sub(left , right); // soustrait
|
if ( !IsNan(left, right, &err) ) result->Sub(left , right); // substraction
|
||||||
break;
|
break;
|
||||||
case ID_MUL:
|
case ID_MUL:
|
||||||
if ( !IsNan(left, right, &err) ) result->Mul(left , right); // multiplie
|
if ( !IsNan(left, right, &err) ) result->Mul(left , right); // multiplies
|
||||||
break;
|
break;
|
||||||
case ID_POWER:
|
case ID_POWER:
|
||||||
if ( !IsNan(left, right, &err) ) result->Power(left , right); // puissance
|
if ( !IsNan(left, right, &err) ) result->Power(left , right); // power
|
||||||
break;
|
break;
|
||||||
case ID_DIV:
|
case ID_DIV:
|
||||||
if ( !IsNan(left, right, &err) ) err = result->Div(left , right);// divise
|
if ( !IsNan(left, right, &err) ) err = result->Div(left , right);// division
|
||||||
break;
|
break;
|
||||||
case ID_MODULO:
|
case ID_MODULO:
|
||||||
if ( !IsNan(left, right, &err) ) err = result->Modulo(left , right);// reste de division
|
if ( !IsNan(left, right, &err) ) err = result->Modulo(left , right);// remainder of division
|
||||||
break;
|
break;
|
||||||
case ID_LO:
|
case ID_LO:
|
||||||
if ( !IsNan(left, right, &err) )
|
if ( !IsNan(left, right, &err) )
|
||||||
result->SetValInt(temp->Lo(left , right)); // inférieur
|
result->SetValInt(temp->Lo(left , right)); // lower
|
||||||
break;
|
break;
|
||||||
case ID_HI:
|
case ID_HI:
|
||||||
if ( !IsNan(left, right, &err) )
|
if ( !IsNan(left, right, &err) )
|
||||||
result->SetValInt(temp->Hi(left , right)); // supérieur
|
result->SetValInt(temp->Hi(left , right)); // top
|
||||||
break;
|
break;
|
||||||
case ID_LS:
|
case ID_LS:
|
||||||
if ( !IsNan(left, right, &err) )
|
if ( !IsNan(left, right, &err) )
|
||||||
result->SetValInt(temp->Ls(left , right)); // inférieur ou égal
|
result->SetValInt(temp->Ls(left , right)); // less than or equal
|
||||||
break;
|
break;
|
||||||
case ID_HS:
|
case ID_HS:
|
||||||
if ( !IsNan(left, right, &err) )
|
if ( !IsNan(left, right, &err) )
|
||||||
result->SetValInt(temp->Hs(left , right)); // supérieur ou égal
|
result->SetValInt(temp->Hs(left , right)); // greater than or equal
|
||||||
break;
|
break;
|
||||||
case ID_EQ:
|
case ID_EQ:
|
||||||
if ( IsNan(left, right) )
|
if ( IsNan(left, right) )
|
||||||
result->SetValInt(left->GivInit() == right->GivInit()) ;
|
result->SetValInt(left->GivInit() == right->GivInit()) ;
|
||||||
else
|
else
|
||||||
result->SetValInt(temp->Eq(left , right)); // égal
|
result->SetValInt(temp->Eq(left , right)); // equal
|
||||||
break;
|
break;
|
||||||
case ID_NE:
|
case ID_NE:
|
||||||
if ( IsNan(left, right) )
|
if ( IsNan(left, right) )
|
||||||
result->SetValInt(left ->GivInit() != right->GivInit()) ;
|
result->SetValInt(left ->GivInit() != right->GivInit()) ;
|
||||||
else
|
else
|
||||||
result->SetValInt(temp->Ne(left , right)); // différent
|
result->SetValInt(temp->Ne(left , right)); // different
|
||||||
break;
|
break;
|
||||||
case ID_TXT_AND:
|
case ID_TXT_AND:
|
||||||
case ID_LOG_AND:
|
case ID_LOG_AND:
|
||||||
case ID_AND:
|
case ID_AND:
|
||||||
if ( !IsNan(left, right, &err) ) result->And(left , right); // ET
|
if ( !IsNan(left, right, &err) ) result->And(left , right); // AND
|
||||||
break;
|
break;
|
||||||
case ID_TXT_OR:
|
case ID_TXT_OR:
|
||||||
case ID_LOG_OR:
|
case ID_LOG_OR:
|
||||||
case ID_OR:
|
case ID_OR:
|
||||||
if ( !IsNan(left, right, &err) ) result->Or(left , right); // OU
|
if ( !IsNan(left, right, &err) ) result->Or(left , right); // OR
|
||||||
break;
|
break;
|
||||||
case ID_XOR:
|
case ID_XOR:
|
||||||
if ( !IsNan(left, right, &err) ) result->XOr(left , right); // OU exclusif
|
if ( !IsNan(left, right, &err) ) result->XOr(left , right); // exclusive OR
|
||||||
break;
|
break;
|
||||||
case ID_ASR:
|
case ID_ASR:
|
||||||
if ( !IsNan(left, right, &err) ) result->ASR(left , right);
|
if ( !IsNan(left, right, &err) ) result->ASR(left , right);
|
||||||
|
@ -468,34 +470,34 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
|
||||||
}
|
}
|
||||||
delete temp;
|
delete temp;
|
||||||
|
|
||||||
pStk2->SetVar(result); // met le résultat sur la pile
|
pStk2->SetVar(result); // puts the result on the stack
|
||||||
if ( err ) pStk2->SetError(err, &m_token); // et l'erreur éventuelle (division par zéro)
|
if ( err ) pStk2->SetError(err, &m_token); // and the possible error (division by zero)
|
||||||
|
|
||||||
// pStk1->Return(pStk2); // libère la pile
|
// pStk1->Return(pStk2); // releases the stack
|
||||||
return pStack->Return(pStk2); // transmet le résultat
|
return pStack->Return(pStk2); // transmits the result
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
||||||
{
|
{
|
||||||
if ( !bMain ) return;
|
if ( !bMain ) return;
|
||||||
CBotStack* pStk1 = pStack->RestoreStack(this); // ajoute un élément à la pile
|
CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack
|
||||||
if ( pStk1 == NULL ) return;
|
if ( pStk1 == NULL ) return;
|
||||||
|
|
||||||
// selon la reprise, on peut être dans l'un des 2 états
|
// according to recovery, it may be in one of two states
|
||||||
|
|
||||||
if ( pStk1->GivState() == 0 ) // 1er état, évalue l'opérande de gauche
|
if ( pStk1->GivState() == 0 ) // first state, evaluates the left operand
|
||||||
{
|
{
|
||||||
m_leftop->RestoreState(pStk1, bMain); // interrompu ici !
|
m_leftop->RestoreState(pStk1, bMain); // interrupted here!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotStack* pStk2 = pStk1->RestoreStack(); // ajoute un élément à la pile
|
CBotStack* pStk2 = pStk1->RestoreStack(); // adds an item to the stack
|
||||||
if ( pStk2 == NULL ) return;
|
if ( pStk2 == NULL ) return;
|
||||||
|
|
||||||
// 2e état, évalue l'opérande de droite
|
// second state, evaluates the right operand
|
||||||
if ( pStk2->GivState() == 0 )
|
if ( pStk2->GivState() == 0 )
|
||||||
{
|
{
|
||||||
m_rightop->RestoreState(pStk2, bMain); // interrompu ici !
|
m_rightop->RestoreState(pStk2, bMain); // interrupted here!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -503,8 +505,8 @@ void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
||||||
|
|
||||||
bool CBotLogicExpr::Execute(CBotStack* &pStack)
|
bool CBotLogicExpr::Execute(CBotStack* &pStack)
|
||||||
{
|
{
|
||||||
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
|
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
|
||||||
// ou le retrouve en cas de reprise
|
// or return in case of recovery
|
||||||
// if ( pStk1 == EOX ) return true;
|
// if ( pStk1 == EOX ) return true;
|
||||||
|
|
||||||
if ( pStk1->GivState() == 0 )
|
if ( pStk1->GivState() == 0 )
|
||||||
|
@ -522,14 +524,14 @@ bool CBotLogicExpr::Execute(CBotStack* &pStack)
|
||||||
if ( !m_op2->Execute(pStk1) ) return false;
|
if ( !m_op2->Execute(pStk1) ) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pStack->Return(pStk1); // transmet le résultat
|
return pStack->Return(pStk1); // transmits the result
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
||||||
{
|
{
|
||||||
if ( !bMain ) return;
|
if ( !bMain ) return;
|
||||||
|
|
||||||
CBotStack* pStk1 = pStack->RestoreStack(this); // ajoute un élément à la pile
|
CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack
|
||||||
if ( pStk1 == NULL ) return;
|
if ( pStk1 == NULL ) return;
|
||||||
|
|
||||||
if ( pStk1->GivState() == 0 )
|
if ( pStk1->GivState() == 0 )
|
||||||
|
|
|
@ -65,10 +65,10 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
||||||
CBotString mode;
|
CBotString mode;
|
||||||
|
|
||||||
// accepts no parameters
|
// accepts no parameters
|
||||||
if ( pVar == NULL ) return TRUE;
|
if ( pVar == NULL ) return true;
|
||||||
|
|
||||||
// must be a string
|
// must be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||||
|
|
||||||
CBotString filename = pVar->GivValString();
|
CBotString filename = pVar->GivValString();
|
||||||
PrepareFilename(filename); //DR
|
PrepareFilename(filename); //DR
|
||||||
|
@ -79,10 +79,10 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
||||||
{
|
{
|
||||||
// recovers the mode
|
// recovers the mode
|
||||||
mode = pVar->GivValString();
|
mode = pVar->GivValString();
|
||||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
|
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
|
||||||
|
|
||||||
// no third parameter, only two or one possible
|
// no third parameter, only two or one possible
|
||||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the file name
|
// save the file name
|
||||||
|
@ -93,7 +93,7 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
||||||
{
|
{
|
||||||
// open the called file
|
// open the called file
|
||||||
FILE* pFile = fopen( filename, mode );
|
FILE* pFile = fopen( filename, mode );
|
||||||
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return FALSE; }
|
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return false; }
|
||||||
|
|
||||||
m_CompteurFileOpen ++;
|
m_CompteurFileOpen ++;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
|
||||||
pVar->SetValInt((long)pFile);
|
pVar->SetValInt((long)pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -126,7 +126,7 @@ CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
|
||||||
}
|
}
|
||||||
|
|
||||||
// le résultat est de type void (constructeur)
|
// le r<EFBFBD>sultat est de type void (constructeur)
|
||||||
return CBotTypResult( 0 );
|
return CBotTypResult( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
// not open? no problem
|
// not open? no problem
|
||||||
if ( pVar->GivInit() != IS_DEF) return TRUE;
|
if ( pVar->GivInit() != IS_DEF) return true;
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
|
@ -148,7 +148,7 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
||||||
|
|
||||||
pVar->SetInit(IS_NAN);
|
pVar->SetInit(IS_NAN);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,10 +159,10 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
|
||||||
bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
{
|
{
|
||||||
// there must be a parameter
|
// there must be a parameter
|
||||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
|
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
|
||||||
|
|
||||||
// must be a string
|
// must be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||||
|
|
||||||
// there may be a second parameter
|
// there may be a second parameter
|
||||||
if ( pVar->GivNext() != NULL )
|
if ( pVar->GivNext() != NULL )
|
||||||
|
@ -180,16 +180,16 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotString mode = pVar->GivValString();
|
CBotString mode = pVar->GivValString();
|
||||||
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return FALSE; }
|
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
|
||||||
|
|
||||||
// No third parameter
|
// No third parameter
|
||||||
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||||
|
|
||||||
// retrieves the element "handle"
|
// retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
// which must not be initialized
|
// which must not be initialized
|
||||||
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return FALSE; }
|
if ( pVar->GivInit() == IS_DEF) { Exception = CBotErrFileOpen; return false; }
|
||||||
|
|
||||||
// contains filename
|
// contains filename
|
||||||
pVar = pThis->GivItem("filename");
|
pVar = pThis->GivItem("filename");
|
||||||
|
@ -201,8 +201,8 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
FILE* pFile = fopen( filename, mode );
|
FILE* pFile = fopen( filename, mode );
|
||||||
if ( pFile == NULL ) //DR
|
if ( pFile == NULL ) //DR
|
||||||
{
|
{
|
||||||
pResult->SetValInt(FALSE); //DR
|
pResult->SetValInt(false); //DR
|
||||||
return TRUE; //DR
|
return true; //DR
|
||||||
}
|
}
|
||||||
|
|
||||||
m_CompteurFileOpen ++;
|
m_CompteurFileOpen ++;
|
||||||
|
@ -211,8 +211,8 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
pVar->SetValInt((long)pFile);
|
pVar->SetValInt((long)pFile);
|
||||||
|
|
||||||
pResult->SetValInt(TRUE); //DR
|
pResult->SetValInt(true); //DR
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -253,7 +253,7 @@ bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
// retrieves the element "handle"
|
// retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
|
@ -261,7 +261,7 @@ bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
|
|
||||||
pVar->SetInit(IS_NAN);
|
pVar->SetInit(IS_NAN);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -280,26 +280,26 @@ CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
|
||||||
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
{
|
{
|
||||||
// there must be a parameter
|
// there must be a parameter
|
||||||
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
|
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
|
||||||
|
|
||||||
// must be a string
|
// must be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
|
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
|
||||||
|
|
||||||
CBotString param = pVar->GivValString();
|
CBotString param = pVar->GivValString();
|
||||||
|
|
||||||
//retrieves the element "handle"
|
//retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
|
|
||||||
int res = fputs(param+CBotString("\n"), pFile);
|
int res = fputs(param+CBotString("\n"), pFile);
|
||||||
|
|
||||||
// on error throws an exception
|
// on error throws an exception
|
||||||
if ( res < 0 ) { Exception = CBotErrWrite; return FALSE; }
|
if ( res < 0 ) { Exception = CBotErrWrite; return false; }
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -324,12 +324,12 @@ CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
|
||||||
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
{
|
{
|
||||||
// there shouldn't be any parameter
|
// there shouldn't be any parameter
|
||||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||||
|
|
||||||
//retrieves the element "handle"
|
//retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
|
|
||||||
|
@ -342,11 +342,11 @@ bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0;
|
for ( i = 0 ; i < 2000 ; i++ ) if (chaine[i] == '\n') chaine[i] = 0;
|
||||||
|
|
||||||
// on error throws an exception
|
// on error throws an exception
|
||||||
if ( ferror(pFile) ) { Exception = CBotErrRead; return FALSE; }
|
if ( ferror(pFile) ) { Exception = CBotErrRead; return false; }
|
||||||
|
|
||||||
pResult->SetValString( chaine );
|
pResult->SetValString( chaine );
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
@ -365,18 +365,18 @@ CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
|
||||||
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
|
||||||
{
|
{
|
||||||
// there shouldn't be any parameter
|
// there shouldn't be any parameter
|
||||||
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
|
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
|
||||||
|
|
||||||
// retrieves the element "handle"
|
// retrieves the element "handle"
|
||||||
pVar = pThis->GivItem("handle");
|
pVar = pThis->GivItem("handle");
|
||||||
|
|
||||||
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return FALSE; }
|
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
|
||||||
|
|
||||||
FILE* pFile= (FILE*)pVar->GivValInt();
|
FILE* pFile= (FILE*)pVar->GivValInt();
|
||||||
|
|
||||||
pResult->SetValInt( feof( pFile ) );
|
pResult->SetValInt( feof( pFile ) );
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compilation
|
// compilation
|
||||||
|
|
|
@ -12,27 +12,29 @@
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.// définition des fonctions sur les chaînes
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
|
|
||||||
|
// definition of string functions
|
||||||
|
|
||||||
|
|
||||||
// donne la longueur d'une chaîne
|
// gives the length of a chain
|
||||||
// exécution
|
// execution
|
||||||
|
|
||||||
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// pas de second paramètre
|
// no second parameter
|
||||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
// recupére le contenu de la string
|
// get the contents of the string
|
||||||
CBotString s = pVar->GivValString();
|
CBotString s = pVar->GivValString();
|
||||||
|
|
||||||
// met la longueur sur la pile
|
// puts the length of the stack
|
||||||
pResult->SetValInt( s.GivLength() );
|
pResult->SetValInt( s.GivLength() );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -42,52 +44,52 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
|
|
||||||
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
|
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString )
|
if ( pVar->GivType() != CBotTypString )
|
||||||
return CBotTypResult( TX_BADPARAM );
|
return CBotTypResult( TX_BADPARAM );
|
||||||
|
|
||||||
// pas de second paramètre
|
// no second parameter
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
|
|
||||||
// le résultat final est un nombre entier
|
// the end result is an integer
|
||||||
return CBotTypResult( CBotTypInt );
|
return CBotTypResult( CBotTypInt );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// donne la partie gauche d'une chaîne
|
// gives the left side of a chain
|
||||||
// exécution
|
// execution
|
||||||
|
|
||||||
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// recupére le contenu de la string
|
// get the contents of the string
|
||||||
CBotString s = pVar->GivValString();
|
CBotString s = pVar->GivValString();
|
||||||
|
|
||||||
// il faut un second paramètre
|
// it takes a second parameter
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être un nombre
|
// which must be a number
|
||||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||||
|
|
||||||
// récupère ce nombre
|
// retrieves this number
|
||||||
int n = pVar->GivValInt();
|
int n = pVar->GivValInt();
|
||||||
|
|
||||||
// pas de 3e paramètre
|
// no third parameter
|
||||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
// prend la partie intéressante
|
// takes the interesting part
|
||||||
s = s.Left( n );
|
s = s.Left( n );
|
||||||
|
|
||||||
// la met sur la pile
|
// puts on the stack
|
||||||
pResult->SetValString( s );
|
pResult->SetValString( s );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -97,173 +99,173 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
|
|
||||||
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
|
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString )
|
if ( pVar->GivType() != CBotTypString )
|
||||||
return CBotTypResult( TX_BADSTRING );
|
return CBotTypResult( TX_BADSTRING );
|
||||||
|
|
||||||
// il faut un second paramètre
|
// it takes a second parameter
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être un nombre
|
// which must be a number
|
||||||
if ( pVar->GivType() > CBotTypDouble )
|
if ( pVar->GivType() > CBotTypDouble )
|
||||||
return CBotTypResult( TX_BADNUM );
|
return CBotTypResult( TX_BADNUM );
|
||||||
|
|
||||||
// pas de 3e paramètre
|
// no third parameter
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
|
|
||||||
// le résultat final est une string
|
// the end result is a string
|
||||||
return CBotTypResult( CBotTypString );
|
return CBotTypResult( CBotTypString );
|
||||||
}
|
}
|
||||||
|
|
||||||
// donne la partie droite d'une chaîne
|
// gives the right of a string
|
||||||
// exécution
|
// execution
|
||||||
|
|
||||||
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// recupére le contenu de la string
|
// get the contents of the string
|
||||||
CBotString s = pVar->GivValString();
|
CBotString s = pVar->GivValString();
|
||||||
|
|
||||||
// il faut un second paramètre
|
// it takes a second parameter
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être un nombre
|
// which must be a number
|
||||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||||
|
|
||||||
// récupère ce nombre
|
// retrieves this number
|
||||||
int n = pVar->GivValInt();
|
int n = pVar->GivValInt();
|
||||||
|
|
||||||
// pas de 3e paramètre
|
// no third parameter
|
||||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
// prend la partie intéressante
|
// takes the interesting part
|
||||||
s = s.Right( n );
|
s = s.Right( n );
|
||||||
|
|
||||||
// la met sur la pile
|
// puts on the stack
|
||||||
pResult->SetValString( s );
|
pResult->SetValString( s );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// donne la partie centrale d'une chaîne
|
// gives the central part of a chain
|
||||||
// exécution
|
// execution
|
||||||
|
|
||||||
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// recupére le contenu de la string
|
// get the contents of the string
|
||||||
CBotString s = pVar->GivValString();
|
CBotString s = pVar->GivValString();
|
||||||
|
|
||||||
// il faut un second paramètre
|
// it takes a second parameter
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être un nombre
|
// which must be a number
|
||||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||||
|
|
||||||
// récupère ce nombre
|
// retrieves this number
|
||||||
int n = pVar->GivValInt();
|
int n = pVar->GivValInt();
|
||||||
|
|
||||||
// 3e paramètre optionnel
|
// third parameter optional
|
||||||
if ( pVar->GivNext() != NULL )
|
if ( pVar->GivNext() != NULL )
|
||||||
{
|
{
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
|
|
||||||
// qui doit être un nombre
|
// which must be a number
|
||||||
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
|
||||||
|
|
||||||
// récupère ce nombre
|
// retrieves this number
|
||||||
int l = pVar->GivValInt();
|
int l = pVar->GivValInt();
|
||||||
|
|
||||||
// mais pas de 4e paramètre
|
// but no fourth parameter
|
||||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
// prend la partie intéressante
|
// takes the interesting part
|
||||||
s = s.Mid( n, l );
|
s = s.Mid( n, l );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// prend la partie intéressante
|
// takes the interesting part
|
||||||
s = s.Mid( n );
|
s = s.Mid( n );
|
||||||
}
|
}
|
||||||
|
|
||||||
// la met sur la pile
|
// puts on the stack
|
||||||
pResult->SetValString( s );
|
pResult->SetValString( s );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// donne la partie centrale d'une chaîne
|
// gives the central part of a chain
|
||||||
// compilation
|
// compilation
|
||||||
|
|
||||||
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
|
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString )
|
if ( pVar->GivType() != CBotTypString )
|
||||||
return CBotTypResult( TX_BADSTRING );
|
return CBotTypResult( TX_BADSTRING );
|
||||||
|
|
||||||
// il faut un second paramètre
|
// it takes a second parameter
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être un nombre
|
// which must be a number
|
||||||
if ( pVar->GivType() > CBotTypDouble )
|
if ( pVar->GivType() > CBotTypDouble )
|
||||||
return CBotTypResult( TX_BADNUM );
|
return CBotTypResult( TX_BADNUM );
|
||||||
|
|
||||||
// 3e paramètre optionnel
|
// third parameter optional
|
||||||
if ( pVar->GivNext() != NULL )
|
if ( pVar->GivNext() != NULL )
|
||||||
{
|
{
|
||||||
|
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
// qui doit être un nombre
|
// which must be a number
|
||||||
if ( pVar->GivType() > CBotTypDouble )
|
if ( pVar->GivType() > CBotTypDouble )
|
||||||
return CBotTypResult( TX_BADNUM );
|
return CBotTypResult( TX_BADNUM );
|
||||||
|
|
||||||
// pas de 4e paramètre
|
// no fourth parameter
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
}
|
}
|
||||||
|
|
||||||
// le résultat final est une string
|
// the end result is a string
|
||||||
return CBotTypResult( CBotTypString );
|
return CBotTypResult( CBotTypString );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// donne le nombre contenu dans une chaîne
|
// gives the number stored in a string
|
||||||
// exécution
|
// execution
|
||||||
|
|
||||||
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// recupére le contenu de la string
|
// get the contents of the string
|
||||||
CBotString s = pVar->GivValString();
|
CBotString s = pVar->GivValString();
|
||||||
|
|
||||||
// mais pas de 2e paramètre
|
// but no second parameter
|
||||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
float val = GivNumFloat(s);
|
float val = GivNumFloat(s);
|
||||||
|
|
||||||
// la met la valeur sur la pile
|
// puts the value on the stack
|
||||||
pResult->SetValFloat( val );
|
pResult->SetValFloat( val );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -273,49 +275,49 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
|
|
||||||
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
|
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString )
|
if ( pVar->GivType() != CBotTypString )
|
||||||
return CBotTypResult( TX_BADSTRING );
|
return CBotTypResult( TX_BADSTRING );
|
||||||
|
|
||||||
// pas de 2e paramètre
|
// no second parameter
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
|
|
||||||
// le résultat final est un nombre
|
// the end result is a number
|
||||||
return CBotTypResult( CBotTypFloat );
|
return CBotTypResult( CBotTypFloat );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// trouve une chaine dans une autre
|
// find string in other
|
||||||
// exécution
|
// exécution
|
||||||
|
|
||||||
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// recupére le contenu de la string
|
// get the contents of the string
|
||||||
CBotString s = pVar->GivValString();
|
CBotString s = pVar->GivValString();
|
||||||
|
|
||||||
// il faut un second paramètre
|
// it takes a second parameter
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// récupère ce nombre
|
// retrieves this number
|
||||||
CBotString s2 = pVar->GivValString();
|
CBotString s2 = pVar->GivValString();
|
||||||
|
|
||||||
// pas de 3e paramètre
|
// no third parameter
|
||||||
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
// met le résultat sur la pile
|
// puts the result on the stack
|
||||||
int res = s.Find(s2);
|
int res = s.Find(s2);
|
||||||
pResult->SetValInt( res );
|
pResult->SetValInt( res );
|
||||||
if ( res < 0 ) pResult->SetInit( IS_NAN );
|
if ( res < 0 ) pResult->SetInit( IS_NAN );
|
||||||
|
@ -327,74 +329,74 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
|
|
||||||
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
|
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString )
|
if ( pVar->GivType() != CBotTypString )
|
||||||
return CBotTypResult( TX_BADSTRING );
|
return CBotTypResult( TX_BADSTRING );
|
||||||
|
|
||||||
// il faut un second paramètre
|
// it takes a second parameter
|
||||||
pVar = pVar->GivNext();
|
pVar = pVar->GivNext();
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString )
|
if ( pVar->GivType() != CBotTypString )
|
||||||
return CBotTypResult( TX_BADSTRING );
|
return CBotTypResult( TX_BADSTRING );
|
||||||
|
|
||||||
// pas de 3e paramètre
|
// no third parameter
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
|
|
||||||
// le résultat final est un nombre
|
// the end result is a number
|
||||||
return CBotTypResult( CBotTypInt );
|
return CBotTypResult( CBotTypInt );
|
||||||
}
|
}
|
||||||
|
|
||||||
// donne une chaine en majuscule
|
// gives a string to uppercase
|
||||||
// exécution
|
// exécution
|
||||||
|
|
||||||
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// recupére le contenu de la string
|
// get the contents of the string
|
||||||
CBotString s = pVar->GivValString();
|
CBotString s = pVar->GivValString();
|
||||||
|
|
||||||
// mais pas de 2e paramètre
|
// but no second parameter
|
||||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
|
|
||||||
s.MakeUpper();
|
s.MakeUpper();
|
||||||
|
|
||||||
// la met la valeur sur la pile
|
// puts the value on the stack
|
||||||
pResult->SetValString( s );
|
pResult->SetValString( s );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// donne une chaine en minuscules
|
// gives a string to lowercase
|
||||||
// exécution
|
// exécution
|
||||||
|
|
||||||
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
|
||||||
|
|
||||||
// recupére le contenu de la string
|
// get the contents of the string
|
||||||
CBotString s = pVar->GivValString();
|
CBotString s = pVar->GivValString();
|
||||||
|
|
||||||
// mais pas de 2e paramètre
|
// but no second parameter
|
||||||
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
|
||||||
|
|
||||||
|
|
||||||
s.MakeLower();
|
s.MakeLower();
|
||||||
|
|
||||||
// la met la valeur sur la pile
|
// puts the value on the stack
|
||||||
pResult->SetValString( s );
|
pResult->SetValString( s );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -404,17 +406,17 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
|
||||||
|
|
||||||
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
|
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
|
||||||
{
|
{
|
||||||
// il faut un paramètre
|
// it takes a parameter
|
||||||
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
|
||||||
|
|
||||||
// qui doit être une string
|
// to be a string
|
||||||
if ( pVar->GivType() != CBotTypString )
|
if ( pVar->GivType() != CBotTypString )
|
||||||
return CBotTypResult( TX_BADSTRING );
|
return CBotTypResult( TX_BADSTRING );
|
||||||
|
|
||||||
// pas de 2e paramètre
|
// no second parameter
|
||||||
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
|
||||||
|
|
||||||
// le résultat final est une string
|
// the end result is a string
|
||||||
return CBotTypResult( CBotTypString );
|
return CBotTypResult( CBotTypString );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue