Transation of comments complete

dev-ui
Michał Konopacki 2012-08-08 02:01:06 +02:00
parent 0844a0f7bd
commit 0919796df7
10 changed files with 5551 additions and 5538 deletions

View File

@ -12,18 +12,20 @@
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
// expression du genre Opérande1 + Opérande2
// Opérande1 - Opérande2
// * along with this program. If not, see http://www.gnu.org/licenses/.
///////////////////////////////////////////////////
// expressions of type Operand1 + Operand2
// Operand1 - Operand2
#include "CBot.h"
// divers constructeurs
// various constructors
CBotAddExpr::CBotAddExpr()
{
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
}
@ -38,105 +40,105 @@ CBotAddExpr::~CBotAddExpr()
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
if (left == NULL) return pStack->Return(NULL, pStk); // si erreur, la transmet
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B left
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 ||
p->GetType() == ID_SUB) // plus ou moins
p->GetType() == ID_SUB) // more or less
{
CBotAddExpr* inst = new CBotAddExpr(); // élément pour opération
inst->SetToken(p); // mémorise l'opération
CBotAddExpr* inst = new CBotAddExpr(); // element for operation
inst->SetToken(p); // stores the operation
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;
// et rend l'object à qui l'a demandé
// and makes the object on demand
return pStack->Return(inst, pStk);
}
}
// en cas d'erreur, libère les éléments
// in case of error, free the elements
delete left;
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);
}
// si on n'a pas affaire à une opération + ou -
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
// à la place de l'objet "addition"
// if we are not dealing with an operation + or -
// goes to that requested, the operand (left) found
// place the object "addition"
return pStack->Return(left, pStk);
}
// fait l'opération d'addition ou de soustraction
// operation is addition or subtraction
bool CBotAddExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or is found in case of recovery
// 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
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
if ( pStk1->GetState() == 0 && // first state, evaluates the left operand
!m_leftop->Execute(pStk1) ) return FALSE; // interrupted here?
// passe à l'étape suivante
pStk1->SetState(1); // prêt pour la suite
// passes to the next step
pStk1->SetState(1); // ready for further
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
// qui se trouve sur la pile, justement.
// requires a little more stack to not touch the result of the left
// which is on the stack, precisely.
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// or is found in case of recovery
// 2e état, évalue l'opérande de droite
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
// Second state, evaluates the right operand
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();
// 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));
// fait l'opération selon la demande
// is the operation as requested
switch (GetTokenType())
{
case ID_ADD:
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition
break;
case ID_SUB:
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction
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
return pStack->Return(pStk1); // transmet le résultat
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmits the result
}

View File

@ -12,14 +12,16 @@
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
// expression du genre Opérande1 > Opérande2
// Opérande1 != Opérande2
// * along with this program. If not, see http://www.gnu.org/licenses/.
///////////////////////////////////////////////////
// expression of type Opérande1 > Opérande2
// Opérande1 != Opérande2
// etc.
#include "CBot.h"
// divers constructeurs
// various constructeurs
CBotCompExpr::CBotCompExpr()
{
@ -36,38 +38,38 @@ CBotCompExpr::~CBotCompExpr()
fichier plus utilise;
// compile une instruction de type A < B
// compile instruction of type A < B
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotCStack* pStk = pStack->AddStack();
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B à gauche
if (left == NULL) return pStack->Return(NULL, pStk); // erreur
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B left
if (left == NULL) return pStack->Return(NULL, pStk); // error
if ( p->GetType() == ID_HI ||
p->GetType() == ID_LO ||
p->GetType() == ID_HS ||
p->GetType() == ID_LS ||
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
inst->SetToken(p); // mémorise l'opération
CBotCompExpr* inst = new CBotCompExpr(); // element for operation
inst->SetToken(p); // stores the operation
int type1, type2;
type1 = pStack->GetType();
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();
// les résultats sont-ils compatibles
// are the results compatible
if ( type1 == type2 )
{
inst->m_leftop = left;
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
// le résultat est un boolean
// the result is a boolean
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)
{
CBotStack* pStk1 = pStack->AddStack(this);
// 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();
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ?
int type1 = pStk1->GetType();
int type2 = pStk2->GetType();
@ -105,27 +107,27 @@ bool CBotCompExpr::Execute(CBotStack* &pStack)
switch (GetTokenType())
{
case ID_LO:
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // inférieur
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower
break;
case ID_HI:
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // supérieur
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher
break;
case ID_LS:
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // inférieur ou égal
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal
break;
case ID_HS:
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // supérieur ou égal
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal
break;
case ID_EQ:
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // égal
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal
break;
case ID_NE:
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // différent
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal
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
return pStack->Return(pStk1); // transmet le résultat
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmit the result
}

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.//////////////////////////////////////////////////////////////////////
// * along with this program. If not, see http://www.gnu.org/licenses/.
//Management of the stack
@ -25,7 +25,7 @@
#define ITIMER 100
////////////////////////////////////////////////////////////////////////////
// gestion de la pile d'exécution
// management of a execution of a stack
////////////////////////////////////////////////////////////////////////////
int CBotStack::m_initimer = ITIMER;
@ -46,14 +46,14 @@ CBotStack* CBotStack::FirstStack()
long size = sizeof(CBotStack);
size *= (MAXSTACK+10);
// demande une tranche mémoire pour la pile
// request a slice of memory for the stack
p = (CBotStack*)malloc(size);
// la vide totalement
// completely empty
memset(p, 0, size);
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;
pp += MAXSTACK;
@ -73,7 +73,7 @@ CBotStack* CBotStack::FirstStack()
}
#endif
m_error = 0; // évite des blocages car m_error est static
m_error = 0; // avoids deadlocks because m_error is static
return p;
}
@ -85,7 +85,7 @@ CBotStack::CBotStack(CBotStack* ppapa)
CBotStack::~CBotStack()
{
ASM_TRAP(); // utiliser Delete() à la place
ASM_TRAP(); // use Delete () instead
}
void CBotStack::Delete()
@ -98,10 +98,10 @@ void CBotStack::Delete()
if (m_prev != NULL)
{
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 )
m_prev->m_next2 = NULL; // enlève de la chaîne
m_prev->m_next2 = NULL; // removes chain
}
delete m_var;
@ -113,7 +113,7 @@ void CBotStack::Delete()
int n = m_index;
#endif
// efface le bloc libéré
// clears the freed block
memset(this, 0, sizeof(CBotStack));
m_bOver = bOver;
#ifdef _DEBUG
@ -125,12 +125,12 @@ void CBotStack::Delete()
}
// routine optimisée
// routine improved
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
{
if (m_next != NULL)
{
return m_next; // reprise dans une pile existante
return m_next; // included in an existing stack
}
#ifdef _DEBUG
@ -146,7 +146,7 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
}
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_instr = instr;
p->m_prog = m_prog;
@ -167,11 +167,11 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
m_next = NULL;
return EOX;
}
return m_next; // reprise dans une pile existante
return m_next; // included in an existing stack
}
CBotStack* p = AddStack(NULL, bBlock);
p->m_call = instr;
p->m_bFunc = 2; // spécial
p->m_bFunc = 2; // special
return p;
}
@ -179,8 +179,8 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
{
if (m_next2 != NULL)
{
m_next2->m_prog = m_prog; // spécial évite un RestoreStack2
return m_next2; // reprise dans une pile existante
m_next2->m_prog = m_prog; // special avoids RestoreStack2
return m_next2; // included in an existing stack
}
CBotStack* p = this;
@ -190,7 +190,7 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
}
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_bBlock = bBlock;
p->m_prog = m_prog;
@ -205,27 +205,27 @@ bool CBotStack::GivBlock()
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 ?
m_var = pfils->m_var; // résultat transmis
pfils->m_var = NULL; // ne pas détruire la variable
if (m_var != NULL) delete m_var; // value replaced?
m_var = pfils->m_var; // result transmitted
pfils->m_var = NULL; // not to destroy the variable
m_next->Delete();m_next = NULL; // libère la pile au dessus
m_next2->Delete();m_next2 = NULL; // aussi la seconde pile (catch)
m_next->Delete();m_next = NULL; // releases the stack above
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)
{
if ( pfils == this ) return true; // spécial
if ( pfils == this ) return true; // special
if (m_var != NULL) delete m_var; // valeur remplacée ?
m_var = pfils->m_var; // résultat transmis
pfils->m_var = NULL; // ne pas détruire la variable
if (m_var != NULL) delete m_var; // value replaced?
m_var = pfils->m_var; // result transmitted
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()
@ -248,7 +248,7 @@ CBotStack::CBotStack(CBotStack* ppapa)
m_state = 0;
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_bDontDelete = false;
@ -260,27 +260,27 @@ CBotStack::CBotStack(CBotStack* ppapa)
m_bFunc = false;
}
// destructeur
// destructor
CBotStack::~CBotStack()
{
if ( m_next != EOX) delete m_next;
delete m_next2;
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;
if ( !m_bDontDelete ) delete m_listVar;
}
// routine à optimiser
// \TODO routine has/to optimize
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
{
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);
m_next = p; // chaîne l'élément
m_next = p; // chain an element
p->m_bBlock = bBlock;
p->m_instr = instr;
p->m_prog = m_prog;
@ -297,15 +297,15 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
m_next = NULL;
return EOX;
}
return m_next; // reprise dans une pile existante
return m_next; // included in an existing stack
}
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_call = instr;
p->m_prog = m_prog;
p->m_step = 0;
p->m_bFunc = 2; // spécial
p->m_bFunc = 2; // special
return p;
}
@ -313,12 +313,12 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
{
if (m_next2 != NULL)
{
m_next2->m_prog = m_prog; // spécial évite un RestoreStack2
return m_next2; // reprise dans une pile existante
m_next2->m_prog = m_prog; // special avoids RestoreStack2
return m_next2; // included in an existing stack
}
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_prog = m_prog;
p->m_step = 0;
@ -328,28 +328,28 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
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 ?
m_var = pfils->m_var; // résultat transmis
pfils->m_var = NULL; // ne pas détruite la variable
if (m_var != NULL) delete m_var; // value replaced?
m_var = pfils->m_var; // result transmitted
pfils->m_var = NULL; // do not destroy the variable
if ( m_next != EOX ) delete m_next; // libère la pile au dessus
delete m_next2;m_next2 = NULL; // aussi la seconde pile (catch)
if ( m_next != EOX ) delete m_next; // releases the stack above
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()
{
return false; // pas de test de débordement dans cette version
return false; // no overflow check in this version
}
#endif
void CBotStack::Reset(void* pUser)
{
m_timer = m_initimer; // remet le timer
m_timer = m_initimer; // resets the timer
m_error = 0;
// m_start = 0;
// m_end = 0;
@ -364,9 +364,9 @@ CBotStack* CBotStack::RestoreStack(CBotInstr* instr)
{
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;
return m_next; // reprise dans une pile existante
return m_next; // included in an existing stack
}
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()
{
if ( m_initimer > 0 || m_step++ > 0 ) return false;
@ -390,11 +390,11 @@ bool CBotStack::IfStep()
bool CBotStack::BreakReturn(CBotStack* pfils, const char* name)
{
if ( m_error>=0 ) return false; // sortie normale
if ( m_error==-3 ) return false; // sortie normale (return en cours)
if ( m_error>=0 ) return false; // normal output
if ( m_error==-3 ) return false; // normal output (return current)
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_labelBreak.Empty();
@ -406,27 +406,27 @@ bool CBotStack::IfContinue(int state, const char* name)
if ( m_error != -2 ) return false;
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_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;
}
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;
if (val == 3) // pour un return
if (val == 3) // for a return
{
m_retvar = m_var;
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)
{
@ -438,7 +438,7 @@ bool CBotStack::GivRetVar(bool bRet)
m_error = 0;
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)
@ -557,22 +557,22 @@ bool CBotStack::SetState(int n, int limite)
{
m_state = n;
m_timer--; // décompte les opérations
return ( m_timer > limite ); // interrompu si timer passé
m_timer--; // decrement the operations \TODO decrement the operations
return ( m_timer > limite ); // interrupted if timer pass
}
bool CBotStack::IncState(int limite)
{
m_state++;
m_timer--; // décompte les opérations
return ( m_timer > limite ); // interrompu si timer passé
m_timer--; // decrement the operations \TODO decompte les operations
return ( m_timer > limite ); // interrupted if timer pass
}
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;
if (token != NULL)
{
@ -601,7 +601,7 @@ void CBotStack::SetTimer(int n)
bool CBotStack::Execute()
{
CBotCall* instr = NULL; // instruction la plus élevée
CBotCall* instr = NULL; // the most highest instruction
CBotStack* pile;
CBotStack* p = this;
@ -617,9 +617,9 @@ bool CBotStack::Execute()
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
pile->m_next->Delete();
@ -627,21 +627,21 @@ bool CBotStack::Execute()
delete pile->m_next;
#endif
pile->m_next = EOX; // spécial pour reprise
pile->m_next = EOX; // special for recovery
return true;
}
// met sur le stack le pointeur à une variable
// puts on the stack pointer to a variable
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;
}
// met sur le stack une copie d'une variable
// puts on the stack a copy of a variable
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->Copy( var );
@ -655,7 +655,7 @@ CBotVar* CBotStack::GivVar()
CBotVar* CBotStack::GivPtVar()
{
CBotVar* p = m_var;
m_var = NULL; // ne sera pas détruit donc
m_var = NULL; // therefore will not be destroyed
return p;
}
@ -680,7 +680,7 @@ void CBotStack::AddVar(CBotVar* pVar)
{
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;
if ( p == NULL ) return;
@ -690,7 +690,7 @@ void CBotStack::AddVar(CBotVar* pVar)
CBotVar** pp = &p->m_listVar;
while ( *pp != NULL ) pp = &(*pp)->m_next;
*pp = pVar; // ajoute à la suite
*pp = pVar; // added after
#ifdef _DEBUG
if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
@ -701,7 +701,7 @@ void CBotStack::AddVar(CBotVar* pVar)
{
if ( !m_bDontDelete ) __asm int 3;
delete m_listVar;
m_listVar = pVar; // remplace directement
m_listVar = pVar; // direct replacement
}*/
void CBotStack::SetBotCall(CBotProgram* p)
@ -728,7 +728,7 @@ bool CBotStack::ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBo
{
CBotTypResult res;
// cherche d'abord selon l'identificateur
// first looks by the identifier
res = CBotCall::DoCall(nIdent, NULL, ppVar, this, rettype );
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 );
if (res.GivType() >= 0) return res.GivType();
// si pas trouvé (recompilé ?) cherche selon le nom
// if not found (recompile?) seeks by name
nIdent = 0;
res = CBotCall::DoCall(nIdent, token, ppVar, this, rettype );
@ -764,11 +764,11 @@ bool SaveVar(FILE* pf, CBotVar* pVar)
{
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->Save1State(pf) ) return false; // sauve selon la classe fille
if ( !pVar->Save0State(pf)) return false; // common header
if ( !pVar->Save1State(pf) ) return false; // saves as the child class
pVar = pVar->GivNext();
}
@ -776,10 +776,10 @@ bool SaveVar(FILE* pf, CBotVar* pVar)
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* instr = NULL; // instruction la plus élevée
CBotInstr* funct = NULL; // function found
CBotInstr* instr = NULL; // the highest intruction
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)
{
CBotProgram* prog = m_prog; // programme courrant
CBotProgram* prog = m_prog; // current program
FunctionName = NULL;
// remonte la pile dans le module courant
// back the stack in the current module
CBotStack* p = this;
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 && level++ < 0 )
@ -836,7 +836,7 @@ CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level)
if ( p == NULL ) return NULL;
// recherche le nom de la fonction courante
// search the name of the current function
CBotStack* pp = p;
while ( pp != NULL )
{
@ -854,30 +854,30 @@ CBotVar* CBotStack::GivStackVars(const char* &FunctionName, int level)
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 (!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;
}
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_state)) return false; // dans quel état
if (!WriteWord(pf, 0)) return false; // par compatibilité m_bDontDelete
if (!WriteWord(pf, m_step)) return false; // dans quel état
if (!WriteWord(pf, m_bBlock)) return false; // is a local block
if (!WriteWord(pf, m_state)) return false; // in what state?
if (!WriteWord(pf, 0)) return false; // by compatibility m_bDontDelete
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_listVar)) return false; // les variables locales
if (!SaveVar(pf, m_var)) return false; // current result
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 (!ReadWord(pf, w)) return false; // est-ce un bloc local
if (!ReadWord(pf, w)) return false; // is a local block
pStack->m_bBlock = w;
if (!ReadWord(pf, w)) return false; // dans quel état j'ère ?
pStack->SetState((short)w); // dans le bon état
if (!ReadWord(pf, w)) return false; // in what state ?
pStack->SetState((short)w); // in a good state
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;
if (!CBotVar::RestoreState(pf, pStack->m_var)) return false; // la variable temp
if (!CBotVar::RestoreState(pf, pStack->m_listVar)) return false;// les variables locales
if (!CBotVar::RestoreState(pf, pStack->m_var)) return false; // temp variable
if (!CBotVar::RestoreState(pf, pStack->m_listVar)) return false;// local variables
return pStack->RestoreState(pf, pStack->m_next);
}
@ -922,19 +922,19 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
bool CBotVar::Save0State(FILE* pf)
{
if (!WriteWord(pf, 100+m_mPrivate))return false; // variable privée ?
if (!WriteWord(pf, m_bStatic))return false; // variable static ?
if (!WriteWord(pf, m_type.GivType()))return false; // enregiste le type (toujours non nul)
if (!WriteWord(pf, m_binit))return false; // variable définie ?
return WriteString(pf, m_token->GivString()); // et le nom de la variable
if (!WriteWord(pf, 100+m_mPrivate))return false; // private variable?
if (!WriteWord(pf, m_bStatic))return false; // static variable?
if (!WriteWord(pf, m_type.GivType()))return false; // saves the type (always non-zero)
if (!WriteWord(pf, m_binit))return false; // variable defined?
return WriteString(pf, m_token->GivString()); // and variable name
}
bool CBotVarInt::Save0State(FILE* pf)
{
if ( !m_defnum.IsEmpty() )
{
if(!WriteWord(pf, 200 )) return false; // marqueur spécial
if(!WriteString(pf, m_defnum)) return false; // nom de la valeur
if(!WriteWord(pf, 200 )) return false; // special marker
if(!WriteString(pf, m_defnum)) return false; // name of the value
}
return CBotVar::Save0State(pf);
@ -942,22 +942,22 @@ bool CBotVarInt::Save0State(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)
{
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)
{
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)
{
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 ( !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)
@ -982,15 +982,15 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
CBotVar* pNew = 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;
CBotString defnum;
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
}
@ -998,15 +998,15 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
if ( w >= 100 )
{
prv = w;
if (!ReadWord(pf, st)) return false; // statique
if (!ReadWord(pf, st)) return false; // static
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 (!ReadString(pf, name)) return false; // nom de la variable
if (!ReadString(pf, name)) return false; // variable name
CBotToken token(name, CBotString());
@ -1014,28 +1014,28 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
{
case CBotTypInt:
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;
pNew->SetValInt((short)w, defnum);
break;
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;
pNew->SetValFloat(ww);
break;
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;
pNew->SetValString(s);
break;
// restitue un objet intrinsic ou un élément d'un array
// returns an intrinsic object or element of an array
case CBotTypIntrinsic:
case CBotTypArrayBody:
{
CBotTypResult r;
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 (!ReadString(pf, s)) return false;
@ -1043,7 +1043,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
CBotVar* p = NULL;
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
if ( !RestoreState(pf, ((CBotVarClass*)pNew)->m_pVar)) return false;
pNew->SetIdent(id);
@ -1051,7 +1051,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
if ( p != NULL )
{
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:
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;
long 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;
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;
@ -1082,12 +1082,12 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
CBotTypResult r;
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;
if ( !CBotVar::RestoreState( pf, pInstance ) ) return false;
((CBotVarPointer*)pNew)->SetPointer( pInstance ); // et pointe dessus
((CBotVarPointer*)pNew)->SetPointer( pInstance ); // and point over
}
break;
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_end = 0;
CBotTypResult CBotCStack::m_retTyp = CBotTypResult(0);
@ -1141,23 +1141,23 @@ CBotCStack::CBotCStack(CBotCStack* ppapa)
m_var = NULL;
}
// destructeur
// destructor
CBotCStack::~CBotCStack()
{
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_listVar;
}
// utilisé uniquement à la compilation
// used only at compile
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);
m_next = p; // chaîne l'élément
m_next = p; // channel element
p->m_bBlock = bBlock;
if (pToken != NULL) p->SetStartError(pToken->GivStart());
@ -1170,13 +1170,13 @@ CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
{
if ( pfils == this ) return inst;
if (m_var != NULL) delete m_var; // valeur remplacée ?
m_var = pfils->m_var; // résultat transmis
pfils->m_var = NULL; // ne pas détruire la variable
if (m_var != NULL) delete m_var; // value replaced?
m_var = pfils->m_var; // result transmitted
pfils->m_var = NULL; // not to destroy the variable
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;
}
@ -1186,13 +1186,13 @@ CBotInstr* CBotCStack::Return(CBotInstr* inst, CBotCStack* pfils)
CBotFunction* CBotCStack::ReturnFunc(CBotFunction* inst, CBotCStack* pfils)
{
if (m_var != NULL) delete m_var; // valeur remplacée ?
m_var = pfils->m_var; // résultat transmis
pfils->m_var = NULL; // ne pas détruire la variable
if (m_var != NULL) delete m_var; // value replaced?
m_var = pfils->m_var; // result transmitted
pfils->m_var = NULL; // not to destroy the variable
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;
}
@ -1212,7 +1212,7 @@ int CBotCStack::GivError()
return m_error;
}
// type d'instruction sur la pile
// type of instruction on the stack
CBotTypResult CBotCStack::GivTypResult(int mode)
{
if (m_var == NULL)
@ -1220,7 +1220,7 @@ CBotTypResult CBotCStack::GivTypResult(int mode)
return m_var->GivTypResult(mode);
}
// type d'instruction sur la pile
// type of instruction on the stack
int CBotCStack::GivType(int mode)
{
if (m_var == NULL)
@ -1228,7 +1228,7 @@ int CBotCStack::GivType(int 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()
{
if ( m_var == NULL )
@ -1238,16 +1238,16 @@ CBotClass* CBotCStack::GivClass()
return m_var->GivClass();
}
// type d'instruction sur la pile
// type of instruction on the stack
void CBotCStack::SetType(CBotTypResult& type)
{
if (m_var == NULL) return;
m_var->SetType( type );
}
// cherche une variable sur la pile
// le token peut être une suite de TokenTypVar (objet d'une classe)
// ou un pointeur dans le source
// seeks a variable on the stack
// the token may be a result of TokenTypVar (object of a class)
// or a pointer in the source
CBotVar* CBotCStack::FindVar(CBotToken* &pToken)
{
@ -1295,20 +1295,20 @@ bool CBotCStack::IsOk()
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;
}
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_end = pos;
}
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_start = p->GivStart();
m_end = p->GivEnd();
@ -1354,14 +1354,14 @@ CBotTypResult CBotCStack::GivRetType()
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;
}
// met sur le stack une copie d'une variable
// puts on the stack a copy of a variable
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;
m_var = CBotVar::Create("", var->GivTypResult(2));
@ -1377,7 +1377,7 @@ void CBotCStack::AddVar(CBotVar* pVar)
{
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;
if ( p == NULL ) return;
@ -1385,14 +1385,14 @@ void CBotCStack::AddVar(CBotVar* pVar)
CBotVar** pp = &p->m_listVar;
while ( *pp != NULL ) pp = &(*pp)->m_next;
*pp = pVar; // ajoute à la suite
*pp = pVar; // added after
#ifdef _DEBUG
if ( pVar->GivUniqNum() == 0 ) ASM_TRAP();
#endif
}
// test si une variable est déjà définie localement
// test whether a variable is already defined locally
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);
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 );
val.SetType(-val.GivType());
return val;
@ -1434,7 +1434,7 @@ CBotTypResult CBotCStack::CompileCall(CBotToken* &p, CBotVar** ppVars, long& nId
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)
{
@ -1447,7 +1447,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
{
if ( pToken->GivString() == pp->GivName() )
{
// les paramètres sont-ils exactement les mêmes ?
// are parameters exactly the same?
if ( pp->CheckParam( pParam ) )
return true;
}
@ -1459,7 +1459,7 @@ bool CBotCStack::CheckCall(CBotToken* &pToken, CBotDefParam* pParam)
{
if ( pToken->GivString() == pp->GivName() )
{
// les paramètres sont-ils exactement les mêmes ?
// are parameters exactly the same?
if ( pp->CheckParam( pParam ) )
return true;
}

View File

@ -12,7 +12,8 @@
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/./////////////////////////////////////////////////////
// * along with this program. If not, see http://www.gnu.org/licenses/.
/////////////////////////////////////////////////////
//strings management

View File

@ -32,6 +32,7 @@
// x
// )
#pragma once
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);

View File

@ -12,18 +12,20 @@
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.///////////////////////////////////////////////////
// expression du genre Opérande1 + Opérande2
// Opérande1 > Opérande2
// * along with this program. If not, see http://www.gnu.org/licenses/.
///////////////////////////////////////////////////
// expression of type Opérande1 + Opérande2
// Opérande1 > Opérande2
#include "CBot.h"
// divers constructeurs
// various constructors
CBotTwoOpExpr::CBotTwoOpExpr()
{
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
}
@ -37,7 +39,7 @@ CBotLogicExpr::CBotLogicExpr()
{
m_condition =
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
}
@ -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 FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
#define BOOLEEN (1<<CBotTypBoolean)
@ -57,9 +59,9 @@ CBotLogicExpr::~CBotLogicExpr()
#define POINTER (1<<CBotTypPointer)
#define INSTANCE (1<<CBotTypClass)
// liste des opérations (précéance)
// type acceptable, opérande
// le zéro termine un niveau de précéance
// list of operations (précéance)
// acceptable type, operand
// zero ends level \TODO précéance
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)
{
@ -122,25 +124,25 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
if ( pOperations == NULL ) pOperations = ListOp;
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) ?
CBotParExpr::Compile( p, pStk ) : // expression (...) à gauche
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B à gauche
CBotParExpr::Compile( p, pStk ) : // expression (...) left
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();
if ( IsInList( TypeOp, pOperations, typemasque ) )
{
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) )
{
@ -150,7 +152,7 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
CBotLogicExpr* inst = new CBotLogicExpr();
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);
CBotToken* pp = p;
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);
}
pStk->SetType(type1); // le plus grand des 2 types
pStk->SetType(type1); // the greatest of 2 types
return pStack->Return(inst, pStk);
}
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // élément pour opération
inst->SetToken(p); // mémorise l'opération
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // element for operation
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 )) )
// 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) );
if ( TypeOp == ID_ADD && type1.Eq(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) )
{
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 )
{
@ -224,25 +226,25 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
case ID_LS:
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;
// spécial pour évaluer les opérations de même niveau de gauche à droite
while ( IsInList( p->GivType(), pOperations, typemasque ) ) // même(s) opération(s) suit ?
// special for evaluation of the operations of the same level from left to right
while ( IsInList( p->GivType(), pOperations, typemasque ) ) // same operation(s) follows?
{
TypeOp = p->GivType();
CBotTwoOpExpr* i = new CBotTwoOpExpr(); // élément pour opération
i->SetToken(p); // mémorise l'opération
i->m_leftop = inst; // opérande de gauche
CBotTwoOpExpr* i = new CBotTwoOpExpr(); // element for operation
i->SetToken(p); // stores the operation
i->m_leftop = inst; // left operand
type1 = TypeRes;
p = p->GivNext(); // avance à la suite
p = p->GivNext(); // advance after
i->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp );
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);
delete i;
@ -256,25 +258,25 @@ CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOpera
CBotTypResult t(type1);
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));
// et rend l'object à qui l'a demandé
// and returns the requested object
return pStack->Return(inst, pStk);
}
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 inst;
// et transmet l'erreur qui se trouve sur la pile
// and transmits the error to the stack
return pStack->Return(NULL, pStk);
}
// si on n'a pas affaire à une opération + ou -
// rend à qui l'a demandé, l'opérande (de gauche) trouvé
// à la place de l'objet "addition"
// if we are not dealing with an operation + or -
// goes to that requested, the operand (left) found
// instead of the object "addition"
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)
{
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or return in case of recovery
// 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 )
{
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
res->SetValInt(false);
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 )
{
CBotVar* res = CBotVar::Create( (CBotToken*)NULL, CBotTypBoolean);
res->SetValInt(true);
pStk1->SetVar(res);
return pStack->Return(pStk1); // transmet le résultat
return pStack->Return(pStk1); // transmits the result
}
// passe à l'étape suivante
pStk1->SetState(1); // prêt pour la suite
// passes to the next step
pStk1->SetState(1); // ready for further
}
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
// qui se trouve sur la pile, justement.
// requires a little more stack to avoid touching the result
// of which is left on the stack, precisely
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// 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 ( !m_rightop->Execute(pStk2) ) return false; // interrompu ici ?
if ( !m_rightop->Execute(pStk2) ) return false; // interrupted here?
pStk2->IncState();
}
CBotTypResult type1 = pStk1->GivTypResult(); // de quels types les résultats ?
CBotTypResult type1 = pStk1->GivTypResult(); // what kind of results?
CBotTypResult type2 = pStk2->GivTypResult();
CBotStack* pStk3 = pStk2->AddStack(this); // ajoute un élément à la pile
if ( pStk3->IfStep() ) return false; // montre l'opération si step by step
CBotStack* pStk3 = pStk2->AddStack(this); // adds an item to the stack
if ( pStk3->IfStep() ) return false; // shows the operation if step by step
// crée une variable temporaire pour y mettre le résultat
// quel est le type du résultat ?
// creates a temporary variable to put the result
// what kind of result?
int TypeRes = MAX(type1.GivType(), type2.GivType());
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
@ -371,10 +373,10 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
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);
// 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());
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
@ -389,70 +391,70 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
else temp = CBotVar::Create( (CBotToken*)NULL, TypeRes );
int err = 0;
// fait l'opération selon la demande
// is a operation according to request
CBotVar* left = pStk1->GivVar();
CBotVar* right = pStk2->GivVar();
switch (GivTokenType())
{
case ID_ADD:
if ( !IsNan(left, right, &err) ) result->Add(left , right); // additionne
if ( !IsNan(left, right, &err) ) result->Add(left , right); // addition
break;
case ID_SUB:
if ( !IsNan(left, right, &err) ) result->Sub(left , right); // soustrait
if ( !IsNan(left, right, &err) ) result->Sub(left , right); // substraction
break;
case ID_MUL:
if ( !IsNan(left, right, &err) ) result->Mul(left , right); // multiplie
if ( !IsNan(left, right, &err) ) result->Mul(left , right); // multiplies
break;
case ID_POWER:
if ( !IsNan(left, right, &err) ) result->Power(left , right); // puissance
if ( !IsNan(left, right, &err) ) result->Power(left , right); // power
break;
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;
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;
case ID_LO:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Lo(left , right)); // inférieur
result->SetValInt(temp->Lo(left , right)); // lower
break;
case ID_HI:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Hi(left , right)); // supérieur
result->SetValInt(temp->Hi(left , right)); // top
break;
case ID_LS:
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;
case ID_HS:
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;
case ID_EQ:
if ( IsNan(left, right) )
result->SetValInt(left->GivInit() == right->GivInit()) ;
else
result->SetValInt(temp->Eq(left , right)); // égal
result->SetValInt(temp->Eq(left , right)); // equal
break;
case ID_NE:
if ( IsNan(left, right) )
result->SetValInt(left ->GivInit() != right->GivInit()) ;
else
result->SetValInt(temp->Ne(left , right)); // différent
result->SetValInt(temp->Ne(left , right)); // different
break;
case ID_TXT_AND:
case ID_LOG_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;
case ID_TXT_OR:
case ID_LOG_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;
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;
case ID_ASR:
if ( !IsNan(left, right, &err) ) result->ASR(left , right);
@ -468,34 +470,34 @@ bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
}
delete temp;
pStk2->SetVar(result); // met le résultat sur la pile
if ( err ) pStk2->SetError(err, &m_token); // et l'erreur éventuelle (division par zéro)
pStk2->SetVar(result); // puts the result on the stack
if ( err ) pStk2->SetError(err, &m_token); // and the possible error (division by zero)
// pStk1->Return(pStk2); // libère la pile
return pStack->Return(pStk2); // transmet le résultat
// pStk1->Return(pStk2); // releases the stack
return pStack->Return(pStk2); // transmits the result
}
void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain)
{
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;
// 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;
}
CBotStack* pStk2 = pStk1->RestoreStack(); // ajoute un élément à la pile
CBotStack* pStk2 = pStk1->RestoreStack(); // adds an item to the stack
if ( pStk2 == NULL ) return;
// 2e état, évalue l'opérande de droite
// second state, evaluates the right operand
if ( pStk2->GivState() == 0 )
{
m_rightop->RestoreState(pStk2, bMain); // interrompu ici !
m_rightop->RestoreState(pStk2, bMain); // interrupted here!
return;
}
}
@ -503,8 +505,8 @@ void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain)
bool CBotLogicExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or return in case of recovery
// if ( pStk1 == EOX ) return true;
if ( pStk1->GivState() == 0 )
@ -522,14 +524,14 @@ bool CBotLogicExpr::Execute(CBotStack* &pStack)
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)
{
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->GivState() == 0 )

View File

@ -65,10 +65,10 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
CBotString mode;
// accepts no parameters
if ( pVar == NULL ) return TRUE;
if ( pVar == NULL ) return true;
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
@ -79,10 +79,10 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
{
// recovers the mode
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
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
}
// save the file name
@ -93,7 +93,7 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
{
// open the called file
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return FALSE; }
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return false; }
m_CompteurFileOpen ++;
@ -102,7 +102,7 @@ bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exceptio
pVar->SetValInt((long)pFile);
}
return TRUE;
return true;
}
// compilation
@ -126,7 +126,7 @@ CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
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 );
}
@ -140,7 +140,7 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
pVar = pThis->GivItem("handle");
// not open? no problem
if ( pVar->GivInit() != IS_DEF) return TRUE;
if ( pVar->GivInit() != IS_DEF) return true;
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
@ -148,7 +148,7 @@ bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception
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)
{
// there must be a parameter
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
// 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
if ( pVar->GivNext() != NULL )
@ -180,16 +180,16 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
}
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
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return FALSE; }
if ( pVar->GivNext() != NULL ) { Exception = CBotErrOverParam; return false; }
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
// 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
pVar = pThis->GivItem("filename");
@ -201,8 +201,8 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) //DR
{
pResult->SetValInt(FALSE); //DR
return TRUE; //DR
pResult->SetValInt(false); //DR
return true; //DR
}
m_CompteurFileOpen ++;
@ -211,8 +211,8 @@ bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
pResult->SetValInt(TRUE); //DR
return TRUE;
pResult->SetValInt(true); //DR
return true;
}
// compilation
@ -253,7 +253,7 @@ bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
// retrieves the element "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();
fclose(pFile);
@ -261,7 +261,7 @@ bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
pVar->SetInit(IS_NAN);
return TRUE;
return true;
}
// compilation
@ -280,26 +280,26 @@ CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there must be a parameter
if ( pVar == NULL ) { Exception = CBotErrLowParam; return FALSE; }
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return FALSE; }
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
CBotString param = pVar->GivValString();
//retrieves the element "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();
int res = fputs(param+CBotString("\n"), pFile);
// on error throws an exception
if ( res < 0 ) { Exception = CBotErrWrite; return FALSE; }
if ( res < 0 ) { Exception = CBotErrWrite; return false; }
return TRUE;
return true;
}
// compilation
@ -324,12 +324,12 @@ CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there shouldn't be any parameter
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
//retrieves the element "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();
@ -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;
// on error throws an exception
if ( ferror(pFile) ) { Exception = CBotErrRead; return FALSE; }
if ( ferror(pFile) ) { Exception = CBotErrRead; return false; }
pResult->SetValString( chaine );
return TRUE;
return true;
}
// compilation
@ -365,18 +365,18 @@ CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there shouldn't be any parameter
if ( pVar != NULL ) { Exception = CBotErrOverParam; return FALSE; }
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
// retrieves the element "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();
pResult->SetValInt( feof( pFile ) );
return TRUE;
return true;
}
// compilation

View File

@ -12,27 +12,29 @@
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://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
// exécution
// gives the length of a chain
// execution
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; }
// qui doit être une string
// to be a string
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; }
// recupére le contenu de la string
// get the contents of the string
CBotString s = pVar->GivValString();
// met la longueur sur la pile
// puts the length of the stack
pResult->SetValInt( s.GivLength() );
return true;
}
@ -42,52 +44,52 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADPARAM );
// pas de second paramètre
// no second parameter
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 );
}
// donne la partie gauche d'une chaîne
// exécution
// gives the left side of a chain
// execution
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; }
// qui doit être une string
// to be a string
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();
// il faut un second paramètre
// it takes a second parameter
pVar = pVar->GivNext();
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; }
// récupère ce nombre
// retrieves this number
int n = pVar->GivValInt();
// pas de 3e paramètre
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// prend la partie intéressante
// takes the interesting part
s = s.Left( n );
// la met sur la pile
// puts on the stack
pResult->SetValString( s );
return true;
}
@ -97,173 +99,173 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// il faut un second paramètre
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être un nombre
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// pas de 3e paramètre
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est une string
// the end result is a string
return CBotTypResult( CBotTypString );
}
// donne la partie droite d'une chaîne
// exécution
// gives the right of a string
// execution
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; }
// qui doit être une string
// to be a string
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();
// il faut un second paramètre
// it takes a second parameter
pVar = pVar->GivNext();
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; }
// récupère ce nombre
// retrieves this number
int n = pVar->GivValInt();
// pas de 3e paramètre
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// prend la partie intéressante
// takes the interesting part
s = s.Right( n );
// la met sur la pile
// puts on the stack
pResult->SetValString( s );
return true;
}
// donne la partie centrale d'une chaîne
// exécution
// gives the central part of a chain
// execution
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; }
// qui doit être une string
// to be a string
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();
// il faut un second paramètre
// it takes a second parameter
pVar = pVar->GivNext();
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; }
// récupère ce nombre
// retrieves this number
int n = pVar->GivValInt();
// 3e paramètre optionnel
// third parameter optional
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// qui doit être un nombre
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// récupère ce nombre
// retrieves this number
int l = pVar->GivValInt();
// mais pas de 4e paramètre
// but no fourth parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
// prend la partie intéressante
// takes the interesting part
s = s.Mid( n, l );
}
else
{
// prend la partie intéressante
// takes the interesting part
s = s.Mid( n );
}
// la met sur la pile
// puts on the stack
pResult->SetValString( s );
return true;
}
// donne la partie centrale d'une chaîne
// gives the central part of a chain
// compilation
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// il faut un second paramètre
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être un nombre
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// 3e paramètre optionnel
// third parameter optional
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// qui doit être un nombre
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// pas de 4e paramètre
// no fourth parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
}
// le résultat final est une string
// the end result is a string
return CBotTypResult( CBotTypString );
}
// donne le nombre contenu dans une chaîne
// exécution
// gives the number stored in a string
// execution
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; }
// qui doit être une string
// to be a string
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();
// mais pas de 2e paramètre
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
float val = GivNumFloat(s);
// la met la valeur sur la pile
// puts the value on the stack
pResult->SetValFloat( val );
return true;
}
@ -273,49 +275,49 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// pas de 2e paramètre
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est un nombre
// the end result is a number
return CBotTypResult( CBotTypFloat );
}
// trouve une chaine dans une autre
// exécution
// find string in other
// exécution
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; }
// qui doit être une string
// to be a string
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();
// il faut un second paramètre
// it takes a second parameter
pVar = pVar->GivNext();
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; }
// récupère ce nombre
// retrieves this number
CBotString s2 = pVar->GivValString();
// pas de 3e paramètre
// no third parameter
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);
pResult->SetValInt( res );
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 )
{
// il faut un paramètre
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// il faut un second paramètre
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// pas de 3e paramètre
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est un nombre
// the end result is a number
return CBotTypResult( CBotTypInt );
}
// donne une chaine en majuscule
// exécution
// gives a string to uppercase
// exécution
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; }
// qui doit être une string
// to be a string
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();
// mais pas de 2e paramètre
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
s.MakeUpper();
// la met la valeur sur la pile
// puts the value on the stack
pResult->SetValString( s );
return true;
}
// donne une chaine en minuscules
// exécution
// gives a string to lowercase
// exécution
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; }
// qui doit être une string
// to be a string
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();
// mais pas de 2e paramètre
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
s.MakeLower();
// la met la valeur sur la pile
// puts the value on the stack
pResult->SetValString( s );
return true;
}
@ -404,17 +406,17 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
{
// il faut un paramètre
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// qui doit être une string
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// pas de 2e paramètre
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// le résultat final est une string
// the end result is a string
return CBotTypResult( CBotTypString );
}