Whitespace fix

dev-ui
Piotr Dziwinski 2012-08-08 22:35:17 +02:00
parent beca66071c
commit bc24b9f9e5
14 changed files with 6106 additions and 6106 deletions

View File

@ -16,7 +16,7 @@
///////////////////////////////////////////////////
// expressions of type Operand1 + Operand2
// Operand1 - Operand2
// Operand1 - Operand2
#include "CBot.h"
@ -24,15 +24,15 @@
CBotAddExpr::CBotAddExpr()
{
m_leftop =
m_rightop = NULL; // NULL to be able to delete without further
name = "CBotAddExpr"; // debug
m_leftop =
m_rightop = NULL; // NULL to be able to delete without further
name = "CBotAddExpr"; // debug
}
CBotAddExpr::~CBotAddExpr()
{
delete m_leftop;
delete m_rightop;
delete m_leftop;
delete m_rightop;
}
@ -40,54 +40,54 @@ CBotAddExpr::~CBotAddExpr()
CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
{
CBotStack* pStk = pStack->TokenStack(); // one end of stack please
CBotStack* pStk = pStack->TokenStack(); // one end of stack please
// looking statements that may be suitable to the left of the operation + or -
// looking statements that may be suitable to the left of the operation + or -
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B left
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
CBotInstr* left = CBotMulExpr::Compile( p, pStk ); // expression A * B left
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
// do we have the token + or - next?
// do we have the token + or - next?
if ( p->GetType() == ID_ADD ||
p->GetType() == ID_SUB) // more or less
{
CBotAddExpr* inst = new CBotAddExpr(); // element for operation
inst->SetToken(p); // stores the operation
if ( p->GetType() == ID_ADD ||
p->GetType() == ID_SUB) // more or less
{
CBotAddExpr* inst = new CBotAddExpr(); // element for operation
inst->SetToken(p); // stores the operation
int type1, type2;
type1 = pStack->GetType(); // what kind of the first operand?
int type1, type2;
type1 = pStack->GetType(); // what kind of the first operand?
p = p->Next(); // skip the token of the operation
p = p->Next(); // skip the token of the operation
// looking statements that may be suitable for right
// looking statements that may be suitable for right
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) rigth
{
// there is an acceptable second operand
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression (...) rigth
{
// there is an acceptable second operand
type2 = pStack->GetType(); // what kind of results?
type2 = pStack->GetType(); // what kind of results?
if ( type1 == type2 ) // are the results consistent ?
{
// ok so, saves the operand in the object
inst->m_leftop = left;
// and makes the object on demand
return pStack->Return(inst, pStk);
}
}
if ( type1 == type2 ) // are the results consistent ?
{
// ok so, saves the operand in the object
inst->m_leftop = left;
// and makes the object on demand
return pStack->Return(inst, pStk);
}
}
// in case of error, free the elements
delete left;
delete inst;
// and transmits the error that is on the stack
return pStack->Return(NULL, pStk);
}
// in case of error, free the elements
delete left;
delete inst;
// and transmits the error that is on the stack
return pStack->Return(NULL, pStk);
}
// if we are not dealing with an operation + or -
// 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);
// place the object "addition"
return pStack->Return(left, pStk);
}
@ -97,48 +97,48 @@ CBotInstr* CBotAddExpr::Compile(CBotToken* &p, CBotStack* pStack)
bool CBotAddExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or is found in case of recovery
// if ( pSk1 == EOX ) return TRUE;
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or is found in case of recovery
// if ( pSk1 == EOX ) return TRUE;
// according to recovery, it may be in one of two states
// according to recovery, it may be in one of two states
if ( pStk1->GetState() == 0 && // first state, evaluates the left operand
!m_leftop->Execute(pStk1) ) return FALSE; // interrupted here?
if ( pStk1->GetState() == 0 && // first state, evaluates the left operand
!m_leftop->Execute(pStk1) ) return FALSE; // interrupted here?
// passes to the next step
pStk1->SetState(1); // ready for further
// passes to the next step
pStk1->SetState(1); // ready for further
// requires a little more stack to not touch the result of the left
// which is on the stack, precisely.
// requires a little more stack to not touch the result of the left
// which is on the stack, precisely.
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// or is found in case of recovery
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// or is found in case of recovery
// Second state, evaluates the right operand
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here?
// Second state, evaluates the right operand
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here?
int type1 = pStk1->GetType(); // what kind of results?
int type2 = pStk2->GetType();
int type1 = pStk1->GetType(); // what kind of results?
int type2 = pStk2->GetType();
// creates a temporary variable to put the result
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
// creates a temporary variable to put the result
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
// is the operation as requested
switch (GetTokenType())
{
case ID_ADD:
result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition
break;
case ID_SUB:
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction
break;
}
pStk2->SetVar(result); // puts the result on the stack
// is the operation as requested
switch (GetTokenType())
{
case ID_ADD:
result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition
break;
case ID_SUB:
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction
break;
}
pStk2->SetVar(result); // puts the result on the stack
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmits the result
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmits the result
}

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@
///////////////////////////////////////////////////
// expression of type Opérande1 > Opérande2
// Opérande1 != Opérande2
// Opérande1 != Opérande2
// etc.
#include "CBot.h"
@ -25,15 +25,15 @@
CBotCompExpr::CBotCompExpr()
{
m_leftop =
m_rightop = NULL;
name = "CBotCompExpr";
m_leftop =
m_rightop = NULL;
name = "CBotCompExpr";
}
CBotCompExpr::~CBotCompExpr()
{
delete m_leftop;
delete m_rightop;
delete m_leftop;
delete m_rightop;
}
fichier plus utilise;
@ -42,44 +42,44 @@ fichier plus utilise;
CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotCStack* pStk = pStack->AddStack();
CBotCStack* pStk = pStack->AddStack();
CBotInstr* left = CBotAddExpr::Compile( p, pStk ); // expression A + B left
if (left == NULL) return pStack->Return(NULL, pStk); // error
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) // the various comparisons
{
CBotCompExpr* inst = new CBotCompExpr(); // element for operation
inst->SetToken(p); // stores the operation
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) // the various comparisons
{
CBotCompExpr* inst = new CBotCompExpr(); // element for operation
inst->SetToken(p); // stores the operation
int type1, type2;
type1 = pStack->GetType();
int type1, type2;
type1 = pStack->GetType();
p = p->Next();
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B right
{
type2 = pStack->GetType();
// are the results compatible
if ( type1 == type2 )
{
inst->m_leftop = left;
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
// the result is a boolean
return pStack->Return(inst, pStk);
}
}
p = p->Next();
if ( NULL != (inst->m_rightop = CBotAddExpr::Compile( p, pStk )) ) // expression A + B right
{
type2 = pStack->GetType();
// are the results compatible
if ( type1 == type2 )
{
inst->m_leftop = left;
pStk->SetVar(new CBotVar(NULL, CBotTypBoolean));
// the result is a boolean
return pStack->Return(inst, pStk);
}
}
delete left;
delete inst;
return pStack->Return(NULL, pStk);
}
delete left;
delete inst;
return pStack->Return(NULL, pStk);
}
return pStack->Return(left, pStk);
return pStack->Return(left, pStk);
}
@ -87,47 +87,47 @@ CBotInstr* CBotCompExpr::Compile(CBotToken* &p, CBotCStack* pStack)
bool CBotCompExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this);
// if ( pStk1 == EOX ) return TRUE;
CBotStack* pStk1 = pStack->AddStack(this);
// if ( pStk1 == EOX ) return TRUE;
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here ?
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here ?
pStk1->SetState(1); // finished
pStk1->SetState(1); // finished
// requires a little more stack to not touch the result of the left
CBotStack* pStk2 = pStk1->AddStack();
// requires a little more stack to not touch the result of the left
CBotStack* pStk2 = pStk1->AddStack();
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ?
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ?
int type1 = pStk1->GetType();
int type2 = pStk2->GetType();
int type1 = pStk1->GetType();
int type2 = pStk2->GetType();
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
switch (GetTokenType())
{
case ID_LO:
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower
break;
case ID_HI:
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher
break;
case ID_LS:
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal
break;
case ID_HS:
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal
break;
case ID_EQ:
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal
break;
case ID_NE:
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal
break;
}
pStk2->SetVar(result); // puts the result on the stack
switch (GetTokenType())
{
case ID_LO:
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower
break;
case ID_HI:
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher
break;
case ID_LS:
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal
break;
case ID_HS:
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal
break;
case ID_EQ:
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal
break;
case ID_NE:
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal
break;
}
pStk2->SetVar(result); // puts the result on the stack
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmit the result
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

@ -22,17 +22,17 @@
// various constructors / destructors
CBotIf::CBotIf()
{
m_Condition =
m_Block =
m_BlockElse = NULL; // NULL so that delete is not possible further
name = "CBotIf"; // debug
m_Condition =
m_Block =
m_BlockElse = NULL; // NULL so that delete is not possible further
name = "CBotIf"; // debug
}
CBotIf::~CBotIf()
{
delete m_Condition; // frees the condition
delete m_Block; // frees the block of instruction1
delete m_BlockElse; // frees the block of instruction2
delete m_Condition; // frees the condition
delete m_Block; // frees the block of instruction1
delete m_BlockElse; // frees the block of instruction2
}
// compilation (static routine)
@ -40,47 +40,47 @@ CBotIf::~CBotIf()
CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
{
CBotToken* pp = p; // preserves at the ^ token (starting instruction)
CBotToken* pp = p; // preserves at the ^ token (starting instruction)
if (!IsOfType(p, ID_IF)) return NULL; // should never happen
if (!IsOfType(p, ID_IF)) return NULL; // should never happen
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
CBotCStack* pStk = pStack->TokenStack(pp); // un petit bout de pile svp
CBotIf* inst = new CBotIf(); // create the object
inst->SetToken( pp );
CBotIf* inst = new CBotIf(); // create the object
inst->SetToken( pp );
if ( NULL != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
{
// the condition does exist
if ( NULL != (inst->m_Condition = CBotCondition::Compile( p, pStk )) )
{
// the condition does exist
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
if ( pStk->IsOk() )
{
// the statement block is ok (can be empty)
inst->m_Block = CBotBlock::CompileBlkOrInst( p, pStk, true );
if ( pStk->IsOk() )
{
// the statement block is ok (can be empty)
// see if the next instruction is the token "else"
if (IsOfType(p, ID_ELSE))
{
// if so, compiles the following statement block
inst->m_BlockElse = CBotBlock::CompileBlkOrInst( p, pStk, true );
if (!pStk->IsOk())
{
// there is no correct block after the else
// frees the object, and transmits the error that is on the stack
delete inst;
return pStack->Return(NULL, pStk);
}
}
// see if the next instruction is the token "else"
if (IsOfType(p, ID_ELSE))
{
// if so, compiles the following statement block
inst->m_BlockElse = CBotBlock::CompileBlkOrInst( p, pStk, true );
if (!pStk->IsOk())
{
// there is no correct block after the else
// frees the object, and transmits the error that is on the stack
delete inst;
return pStack->Return(NULL, pStk);
}
}
// return the corrent object to the application
return pStack->Return(inst, pStk);
}
}
// return the corrent object to the application
return pStack->Return(inst, pStk);
}
}
// error, frees the object
delete inst;
// and transmits the error that is on the stack.
return pStack->Return(NULL, pStk);
// error, frees the object
delete inst;
// and transmits the error that is on the stack.
return pStack->Return(NULL, pStk);
}
@ -88,74 +88,74 @@ CBotInstr* CBotIf::Compile(CBotToken* &p, CBotCStack* pStack)
bool CBotIf :: Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); // adds an item to the stack
// or found in case of recovery
// if ( pile == EOX ) return true;
CBotStack* pile = pj->AddStack(this); // adds an item to the stack
// or found in case of recovery
// if ( pile == EOX ) return true;
if ( pile->IfStep() ) return false;
if ( pile->IfStep() ) return false;
// according to recovery, it may be in one of two states
if( pile->GivState() == 0 )
{
// evaluates the condition
if ( !m_Condition->Execute(pile) ) return false; // interrupted here?
// according to recovery, it may be in one of two states
if( pile->GivState() == 0 )
{
// evaluates the condition
if ( !m_Condition->Execute(pile) ) return false; // interrupted here?
// terminates if there is an error
if ( !pile->IsOk() )
{
return pj->Return(pile); // returns the results and releases the stack
}
// terminates if there is an error
if ( !pile->IsOk() )
{
return pj->Return(pile); // returns the results and releases the stack
}
// passes into the second state
if (!pile->SetState(1)) return false; // ready for further
}
// second state, evaluates the associated instructions
// the result of the condition is on the stack
// passes into the second state
if (!pile->SetState(1)) return false; // ready for further
}
// second state, evaluates the associated instructions
// the result of the condition is on the stack
if ( pile->GivVal() == true ) // condition was true?
{
if ( m_Block != NULL && // block may be absent
!m_Block->Execute(pile) ) return false; // interrupted here?
}
else
{
if ( m_BlockElse != NULL && // if there is an alternate block
!m_BlockElse->Execute(pile) ) return false; // interrupted here
}
if ( pile->GivVal() == true ) // condition was true?
{
if ( m_Block != NULL && // block may be absent
!m_Block->Execute(pile) ) return false; // interrupted here?
}
else
{
if ( m_BlockElse != NULL && // if there is an alternate block
!m_BlockElse->Execute(pile) ) return false; // interrupted here
}
// sends the results and releases the stack
return pj->Return(pile);
// sends the results and releases the stack
return pj->Return(pile);
}
void CBotIf :: RestoreState(CBotStack* &pj, bool bMain)
{
if ( !bMain ) return;
if ( !bMain ) return;
CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack
if ( pile == NULL ) return;
CBotStack* pile = pj->RestoreStack(this); // adds an item to the stack
if ( pile == NULL ) return;
// according to recovery, it may be in one of two states
if( pile->GivState() == 0 )
{
// evaluates the condition
m_Condition->RestoreState(pile, bMain); // interrupted here!
return;
}
// second state, evaluates the associated instructions
// the result of the condition is on the stack
// according to recovery, it may be in one of two states
if( pile->GivState() == 0 )
{
// evaluates the condition
m_Condition->RestoreState(pile, bMain); // interrupted here!
return;
}
// second state, evaluates the associated instructions
// the result of the condition is on the stack
if ( pile->GivVal() == true ) // condition was true?
{
if ( m_Block != NULL ) // block may be absent
m_Block->RestoreState(pile, bMain); // interrupted here!
}
else
{
if ( m_BlockElse != NULL ) // if there is an alternate block
m_BlockElse->RestoreState(pile, bMain); // interrupted here!
}
if ( pile->GivVal() == true ) // condition was true?
{
if ( m_Block != NULL ) // block may be absent
m_Block->RestoreState(pile, bMain); // interrupted here!
}
else
{
if ( m_BlockElse != NULL ) // if there is an alternate block
m_BlockElse->RestoreState(pile, bMain); // interrupted here!
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,38 +1,38 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// interpreter of the lanuage CBot for game COLOBOT
// writing a program is first transformed into a list of tokens
// before tackling the compiler itself
// for example
// int var = 3 * ( pos.y + x )
// is decomposed into (each line is a token)
// int
// var
// =
// 3
// *
// (
// pos.y
// +
// x
// )
#pragma once
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// interpreter of the lanuage CBot for game COLOBOT
// writing a program is first transformed into a list of tokens
// before tackling the compiler itself
// for example
// int var = 3 * ( pos.y + x )
// is decomposed into (each line is a token)
// int
// var
// =
// 3
// *
// (
// pos.y
// +
// x
// )
#pragma once
extern bool IsOfType(CBotToken* &p, int type1, int type2 = -1);
extern bool IsOfTypeList(CBotToken* &p, int type1, ...);

View File

@ -16,7 +16,7 @@
///////////////////////////////////////////////////
// expression of type Opérande1 + Opérande2
// Opérande1 > Opérande2
// Opérande1 > Opérande2
#include "CBot.h"
@ -24,271 +24,271 @@
CBotTwoOpExpr::CBotTwoOpExpr()
{
m_leftop =
m_rightop = NULL; // NULL to be able to delete without other
name = "CBotTwoOpExpr"; // debug
m_leftop =
m_rightop = NULL; // NULL to be able to delete without other
name = "CBotTwoOpExpr"; // debug
}
CBotTwoOpExpr::~CBotTwoOpExpr()
{
delete m_leftop;
delete m_rightop;
delete m_leftop;
delete m_rightop;
}
CBotLogicExpr::CBotLogicExpr()
{
m_condition =
m_op1 =
m_op2 = NULL; // NULL to be able to delete without other
name = "CBotLogicExpr"; // debug
m_condition =
m_op1 =
m_op2 = NULL; // NULL to be able to delete without other
name = "CBotLogicExpr"; // debug
}
CBotLogicExpr::~CBotLogicExpr()
{
delete m_condition;
delete m_op1;
delete m_op2;
delete m_condition;
delete m_op1;
delete m_op2;
}
// 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)
#define CHAINE (1<<CBotTypString)
#define POINTER (1<<CBotTypPointer)
#define INSTANCE (1<<CBotTypClass)
#define ENTIER ((1<<CBotTypByte)|(1<<CBotTypShort)|(1<<CBotTypChar)|(1<<CBotTypInt)|(1<<CBotTypLong))
#define FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
#define BOOLEEN (1<<CBotTypBoolean)
#define CHAINE (1<<CBotTypString)
#define POINTER (1<<CBotTypPointer)
#define INSTANCE (1<<CBotTypClass)
// list of operations (précéance)
// acceptable type, operand
// zero ends level \TODO précéance
// acceptable type, operand
// zero ends level \TODO précéance
static int ListOp[] =
static int ListOp[] =
{
BOOLEEN, ID_LOGIC, 0,
BOOLEEN, ID_TXT_OR,
BOOLEEN, ID_LOG_OR, 0,
BOOLEEN, ID_TXT_AND,
BOOLEEN, ID_LOG_AND, 0,
BOOLEEN|ENTIER, ID_OR, 0,
BOOLEEN|ENTIER, ID_XOR, 0,
BOOLEEN|ENTIER, ID_AND, 0,
BOOLEEN|ENTIER|FLOTANT
|CHAINE
|POINTER
|INSTANCE,ID_EQ,
BOOLEEN|ENTIER|FLOTANT
|CHAINE
|POINTER
|INSTANCE,ID_NE, 0,
ENTIER|FLOTANT|CHAINE, ID_HI,
ENTIER|FLOTANT|CHAINE, ID_LO,
ENTIER|FLOTANT|CHAINE, ID_HS,
ENTIER|FLOTANT|CHAINE, ID_LS, 0,
ENTIER, ID_SR,
ENTIER, ID_SL,
ENTIER, ID_ASR, 0,
ENTIER|FLOTANT|CHAINE, ID_ADD,
ENTIER|FLOTANT, ID_SUB, 0,
ENTIER|FLOTANT, ID_MUL,
ENTIER|FLOTANT, ID_DIV,
ENTIER|FLOTANT, ID_MODULO, 0,
ENTIER|FLOTANT, ID_POWER, 0,
0,
BOOLEEN, ID_LOGIC, 0,
BOOLEEN, ID_TXT_OR,
BOOLEEN, ID_LOG_OR, 0,
BOOLEEN, ID_TXT_AND,
BOOLEEN, ID_LOG_AND, 0,
BOOLEEN|ENTIER, ID_OR, 0,
BOOLEEN|ENTIER, ID_XOR, 0,
BOOLEEN|ENTIER, ID_AND, 0,
BOOLEEN|ENTIER|FLOTANT
|CHAINE
|POINTER
|INSTANCE,ID_EQ,
BOOLEEN|ENTIER|FLOTANT
|CHAINE
|POINTER
|INSTANCE,ID_NE, 0,
ENTIER|FLOTANT|CHAINE, ID_HI,
ENTIER|FLOTANT|CHAINE, ID_LO,
ENTIER|FLOTANT|CHAINE, ID_HS,
ENTIER|FLOTANT|CHAINE, ID_LS, 0,
ENTIER, ID_SR,
ENTIER, ID_SL,
ENTIER, ID_ASR, 0,
ENTIER|FLOTANT|CHAINE, ID_ADD,
ENTIER|FLOTANT, ID_SUB, 0,
ENTIER|FLOTANT, ID_MUL,
ENTIER|FLOTANT, ID_DIV,
ENTIER|FLOTANT, ID_MODULO, 0,
ENTIER|FLOTANT, ID_POWER, 0,
0,
};
bool IsInList( int val, int* list, int& typemasque )
{
while (true)
{
if ( *list == 0 ) return false;
typemasque = *list++;
if ( *list++ == val ) return true;
}
while (true)
{
if ( *list == 0 ) return false;
typemasque = *list++;
if ( *list++ == val ) return true;
}
}
bool TypeOk( int type, int test )
{
while (true)
{
if ( type == 0 ) return (test & 1);
type--; test /= 2;
}
while (true)
{
if ( type == 0 ) return (test & 1);
type--; test /= 2;
}
}
// compiles a instruction of type A op B
CBotInstr* CBotTwoOpExpr::Compile(CBotToken* &p, CBotCStack* pStack, int* pOperations)
{
int typemasque;
int typemasque;
if ( pOperations == NULL ) pOperations = ListOp;
int* pOp = pOperations;
while ( *pOp++ != 0 ); // follows the table
if ( pOperations == NULL ) pOperations = ListOp;
int* pOp = pOperations;
while ( *pOp++ != 0 ); // follows the table
CBotCStack* pStk = pStack->TokenStack(); // one end of stack please
CBotCStack* pStk = pStack->TokenStack(); // one end of stack please
// search the intructions that may be suitable to the left of the operation
CBotInstr* left = (*pOp == 0) ?
CBotParExpr::Compile( p, pStk ) : // expression (...) left
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B left
// search the intructions that may be suitable to the left of the operation
CBotInstr* left = (*pOp == 0) ?
CBotParExpr::Compile( p, pStk ) : // expression (...) left
CBotTwoOpExpr::Compile( p, pStk, pOp ); // expression A * B left
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
if (left == NULL) return pStack->Return(NULL, pStk); // if error, transmit
// did we expected the operand?
int TypeOp = p->GivType();
if ( IsInList( TypeOp, pOperations, typemasque ) )
{
CBotTypResult type1, type2;
type1 = pStk->GivTypResult(); // what kind of the first operand?
// did we expected the operand?
int TypeOp = p->GivType();
if ( IsInList( TypeOp, pOperations, typemasque ) )
{
CBotTypResult type1, type2;
type1 = pStk->GivTypResult(); // what kind of the first operand?
if ( TypeOp == ID_LOGIC ) // special case provided for: ? op1: op2;
{
if ( !type1.Eq(CBotTypBoolean) )
{
pStk->SetError( TX_BADTYPE, p);
return pStack->Return(NULL, pStk);
}
CBotLogicExpr* inst = new CBotLogicExpr();
inst->m_condition = left;
if ( TypeOp == ID_LOGIC ) // special case provided for: ? op1: op2;
{
if ( !type1.Eq(CBotTypBoolean) )
{
pStk->SetError( TX_BADTYPE, p);
return pStack->Return(NULL, pStk);
}
CBotLogicExpr* inst = new CBotLogicExpr();
inst->m_condition = left;
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 ) )
{
pStk->SetError( TX_MISDOTS, p->GivStart());
delete inst;
return pStack->Return(NULL, pStk);
}
type1 = pStk->GivTypResult();
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 ) )
{
pStk->SetError( TX_MISDOTS, p->GivStart());
delete inst;
return pStack->Return(NULL, pStk);
}
type1 = pStk->GivTypResult();
inst->m_op2 = CBotExpression::Compile(p, pStk);
if ( inst->m_op2 == NULL )
{
pStk->SetError( TX_ENDOF, p->GivStart() );
delete inst;
return pStack->Return(NULL, pStk);
}
type2 = pStk->GivTypResult();
if (!TypeCompatible(type1, type2))
{
pStk->SetError( TX_BAD2TYPE, pp );
delete inst;
return pStack->Return(NULL, pStk);
}
inst->m_op2 = CBotExpression::Compile(p, pStk);
if ( inst->m_op2 == NULL )
{
pStk->SetError( TX_ENDOF, p->GivStart() );
delete inst;
return pStack->Return(NULL, pStk);
}
type2 = pStk->GivTypResult();
if (!TypeCompatible(type1, type2))
{
pStk->SetError( TX_BAD2TYPE, pp );
delete inst;
return pStack->Return(NULL, pStk);
}
pStk->SetType(type1); // the greatest of 2 types
pStk->SetType(type1); // the greatest of 2 types
return pStack->Return(inst, pStk);
}
return pStack->Return(inst, pStk);
}
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // element for operation
inst->SetToken(p); // stores the operation
CBotTwoOpExpr* inst = new CBotTwoOpExpr(); // element for operation
inst->SetToken(p); // stores the operation
p = p->GivNext(); // skip the token of the operation
p = p->GivNext(); // skip the token of the operation
// looking statements that may be suitable for right
// looking statements that may be suitable for right
if ( NULL != (inst->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp )) )
// expression (...) right
{
// there is an second operand acceptable
if ( NULL != (inst->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp )) )
// expression (...) right
{
// there is an second operand acceptable
type2 = pStk->GivTypResult(); // what kind of results?
type2 = pStk->GivTypResult(); // what kind of results?
// what kind of result?
int TypeRes = MAX( type1.GivType(3), type2.GivType(3) );
if ( TypeOp == ID_ADD && type1.Eq(CBotTypString) )
{
TypeRes = CBotTypString;
type2 = type1; // any type convertible chain
}
else if ( TypeOp == ID_ADD && type2.Eq(CBotTypString) )
{
TypeRes = CBotTypString;
type1 = type2; // any type convertible chain
}
else if (!TypeOk( TypeRes, typemasque )) type1.SetType(99);// error of type
// what kind of result?
int TypeRes = MAX( type1.GivType(3), type2.GivType(3) );
if ( TypeOp == ID_ADD && type1.Eq(CBotTypString) )
{
TypeRes = CBotTypString;
type2 = type1; // any type convertible chain
}
else if ( TypeOp == ID_ADD && type2.Eq(CBotTypString) )
{
TypeRes = CBotTypString;
type1 = type2; // any type convertible chain
}
else if (!TypeOk( TypeRes, typemasque )) type1.SetType(99);// error of type
switch ( TypeOp )
{
case ID_LOG_OR:
case ID_LOG_AND:
case ID_TXT_OR:
case ID_TXT_AND:
case ID_EQ:
case ID_NE:
case ID_HI:
case ID_LO:
case ID_HS:
case ID_LS:
TypeRes = CBotTypBoolean;
}
if ( TypeCompatible (type1, type2, TypeOp ) ) // the results are compatible
{
// ok so, saves the operand in the object
inst->m_leftop = left;
switch ( TypeOp )
{
case ID_LOG_OR:
case ID_LOG_AND:
case ID_TXT_OR:
case ID_TXT_AND:
case ID_EQ:
case ID_NE:
case ID_HI:
case ID_LO:
case ID_HS:
case ID_LS:
TypeRes = CBotTypBoolean;
}
if ( TypeCompatible (type1, type2, TypeOp ) ) // the results are compatible
{
// ok so, saves the operand in the object
inst->m_leftop = left;
// 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(); // element for operation
i->SetToken(p); // stores the operation
i->m_leftop = inst; // left operand
type1 = TypeRes;
// 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(); // element for operation
i->SetToken(p); // stores the operation
i->m_leftop = inst; // left operand
type1 = TypeRes;
p = p->GivNext(); // advance after
i->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp );
type2 = pStk->GivTypResult();
p = p->GivNext(); // advance after
i->m_rightop = CBotTwoOpExpr::Compile( p, pStk, pOp );
type2 = pStk->GivTypResult();
if ( !TypeCompatible (type1, type2, TypeOp) ) // the results are compatible
{
pStk->SetError(TX_BAD2TYPE, &i->m_token);
delete i;
return pStack->Return(NULL, pStk);
}
if ( !TypeCompatible (type1, type2, TypeOp) ) // the results are compatible
{
pStk->SetError(TX_BAD2TYPE, &i->m_token);
delete i;
return pStack->Return(NULL, pStk);
}
if ( TypeRes != CBotTypString )
TypeRes = MAX(type1.GivType(), type2.GivType());
inst = i;
}
if ( TypeRes != CBotTypString )
TypeRes = MAX(type1.GivType(), type2.GivType());
inst = i;
}
CBotTypResult t(type1);
t.SetType(TypeRes);
// is a variable on the stack for the type of result
pStk->SetVar(CBotVar::Create((CBotToken*)NULL, t));
CBotTypResult t(type1);
t.SetType(TypeRes);
// is a variable on the stack for the type of result
pStk->SetVar(CBotVar::Create((CBotToken*)NULL, t));
// and returns the requested object
return pStack->Return(inst, pStk);
}
pStk->SetError(TX_BAD2TYPE, &inst->m_token);
}
// and returns the requested object
return pStack->Return(inst, pStk);
}
pStk->SetError(TX_BAD2TYPE, &inst->m_token);
}
// in case of error, releases the elements
delete left;
delete inst;
// and transmits the error to the stack
return pStack->Return(NULL, pStk);
}
// in case of error, releases the elements
delete left;
delete inst;
// and transmits the error to the stack
return pStack->Return(NULL, pStk);
}
// 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);
// 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);
}
bool IsNan(CBotVar* left, CBotVar* right, int* err = NULL)
{
if ( left ->GivInit() > IS_DEF || right->GivInit() > IS_DEF )
{
if ( err != NULL ) *err = TX_OPNAN ;
return true;
}
return false;
if ( left ->GivInit() > IS_DEF || right->GivInit() > IS_DEF )
{
if ( err != NULL ) *err = TX_OPNAN ;
return true;
}
return false;
}
@ -296,273 +296,273 @@ bool IsNan(CBotVar* left, CBotVar* right, int* err = NULL)
bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or return in case of recovery
// if ( pStk1 == EOX ) return true;
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or return in case of recovery
// if ( pStk1 == EOX ) return true;
// according to recovery, it may be in one of two states
// according to recovery, it may be in one of two states
if ( pStk1->GivState() == 0 ) // first state, evaluates the left operand
{
if (!m_leftop->Execute(pStk1) ) return false; // interrupted here?
if ( pStk1->GivState() == 0 ) // first state, evaluates the left operand
{
if (!m_leftop->Execute(pStk1) ) return false; // interrupted here?
// 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); // 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); // transmits the result
}
// 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); // 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); // transmits the result
}
// passes to the next step
pStk1->SetState(1); // ready for further
}
// passes to the next step
pStk1->SetState(1); // ready for further
}
// requires a little more stack to avoid touching the result
// of which is left on the stack, precisely
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// or return in case of recovery
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// or return in case of recovery
// 2e état, évalue l'opérande de droite
if ( pStk2->GivState() == 0 )
{
if ( !m_rightop->Execute(pStk2) ) return false; // interrupted here?
pStk2->IncState();
}
// 2e état, évalue l'opérande de droite
if ( pStk2->GivState() == 0 )
{
if ( !m_rightop->Execute(pStk2) ) return false; // interrupted here?
pStk2->IncState();
}
CBotTypResult type1 = pStk1->GivTypResult(); // what kind of results?
CBotTypResult type2 = pStk2->GivTypResult();
CBotTypResult type1 = pStk1->GivTypResult(); // what kind of results?
CBotTypResult type2 = pStk2->GivTypResult();
CBotStack* pStk3 = pStk2->AddStack(this); // adds an item to the stack
if ( pStk3->IfStep() ) return false; // shows the operation if 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
// creates a temporary variable to put the result
// what kind of result?
int TypeRes = MAX(type1.GivType(), type2.GivType());
// 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) )
{
TypeRes = CBotTypString;
}
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
{
TypeRes = CBotTypString;
}
switch ( GivTokenType() )
{
case ID_LOG_OR:
case ID_LOG_AND:
case ID_TXT_OR:
case ID_TXT_AND:
case ID_EQ:
case ID_NE:
case ID_HI:
case ID_LO:
case ID_HS:
case ID_LS:
TypeRes = CBotTypBoolean;
break;
case ID_DIV:
TypeRes = MAX(TypeRes, CBotTypFloat);
}
switch ( GivTokenType() )
{
case ID_LOG_OR:
case ID_LOG_AND:
case ID_TXT_OR:
case ID_TXT_AND:
case ID_EQ:
case ID_NE:
case ID_HI:
case ID_LO:
case ID_HS:
case ID_LS:
TypeRes = CBotTypBoolean;
break;
case ID_DIV:
TypeRes = MAX(TypeRes, CBotTypFloat);
}
// creates a variable for the result
CBotVar* result = CBotVar::Create( (CBotToken*)NULL, TypeRes);
// creates a variable for the result
CBotVar* result = CBotVar::Create( (CBotToken*)NULL, TypeRes);
// creates a variable to perform the calculation in the appropriate type
TypeRes = MAX(type1.GivType(), type2.GivType());
// creates a variable to perform the calculation in the appropriate type
TypeRes = MAX(type1.GivType(), type2.GivType());
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
{
TypeRes = CBotTypString;
}
if ( GivTokenType() == ID_ADD && type1.Eq(CBotTypString) )
{
TypeRes = CBotTypString;
}
CBotVar* temp;
CBotVar* temp;
if ( TypeRes == CBotTypPointer ) TypeRes = CBotTypNullPointer;
if ( TypeRes == CBotTypClass ) temp = CBotVar::Create( (CBotToken*)NULL, CBotTypResult(CBotTypIntrinsic, type1.GivClass() ) );
else temp = CBotVar::Create( (CBotToken*)NULL, TypeRes );
if ( TypeRes == CBotTypPointer ) TypeRes = CBotTypNullPointer;
if ( TypeRes == CBotTypClass ) temp = CBotVar::Create( (CBotToken*)NULL, CBotTypResult(CBotTypIntrinsic, type1.GivClass() ) );
else temp = CBotVar::Create( (CBotToken*)NULL, TypeRes );
int err = 0;
// is a operation according to request
CBotVar* left = pStk1->GivVar();
CBotVar* right = pStk2->GivVar();
int err = 0;
// 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); // addition
break;
case ID_SUB:
if ( !IsNan(left, right, &err) ) result->Sub(left , right); // substraction
break;
case ID_MUL:
if ( !IsNan(left, right, &err) ) result->Mul(left , right); // multiplies
break;
case ID_POWER:
if ( !IsNan(left, right, &err) ) result->Power(left , right); // power
break;
case ID_DIV:
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);// remainder of division
break;
case ID_LO:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Lo(left , right)); // lower
break;
case ID_HI:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Hi(left , right)); // top
break;
case ID_LS:
if ( !IsNan(left, right, &err) )
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)); // 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)); // equal
break;
case ID_NE:
if ( IsNan(left, right) )
result->SetValInt(left ->GivInit() != right->GivInit()) ;
else
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); // AND
break;
case ID_TXT_OR:
case ID_LOG_OR:
case ID_OR:
if ( !IsNan(left, right, &err) ) result->Or(left , right); // OR
break;
case ID_XOR:
if ( !IsNan(left, right, &err) ) result->XOr(left , right); // exclusive OR
break;
case ID_ASR:
if ( !IsNan(left, right, &err) ) result->ASR(left , right);
break;
case ID_SR:
if ( !IsNan(left, right, &err) ) result->SR(left , right);
break;
case ID_SL:
if ( !IsNan(left, right, &err) ) result->SL(left , right);
break;
default:
ASM_TRAP();
}
delete temp;
switch (GivTokenType())
{
case ID_ADD:
if ( !IsNan(left, right, &err) ) result->Add(left , right); // addition
break;
case ID_SUB:
if ( !IsNan(left, right, &err) ) result->Sub(left , right); // substraction
break;
case ID_MUL:
if ( !IsNan(left, right, &err) ) result->Mul(left , right); // multiplies
break;
case ID_POWER:
if ( !IsNan(left, right, &err) ) result->Power(left , right); // power
break;
case ID_DIV:
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);// remainder of division
break;
case ID_LO:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Lo(left , right)); // lower
break;
case ID_HI:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Hi(left , right)); // top
break;
case ID_LS:
if ( !IsNan(left, right, &err) )
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)); // 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)); // equal
break;
case ID_NE:
if ( IsNan(left, right) )
result->SetValInt(left ->GivInit() != right->GivInit()) ;
else
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); // AND
break;
case ID_TXT_OR:
case ID_LOG_OR:
case ID_OR:
if ( !IsNan(left, right, &err) ) result->Or(left , right); // OR
break;
case ID_XOR:
if ( !IsNan(left, right, &err) ) result->XOr(left , right); // exclusive OR
break;
case ID_ASR:
if ( !IsNan(left, right, &err) ) result->ASR(left , right);
break;
case ID_SR:
if ( !IsNan(left, right, &err) ) result->SR(left , right);
break;
case ID_SL:
if ( !IsNan(left, right, &err) ) result->SL(left , right);
break;
default:
ASM_TRAP();
}
delete temp;
pStk2->SetVar(result); // puts the result on the stack
if ( err ) pStk2->SetError(err, &m_token); // and the possible error (division by zero)
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); // releases the stack
return pStack->Return(pStk2); // transmits the result
// 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); // adds an item to the stack
if ( pStk1 == NULL ) return;
if ( !bMain ) return;
CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack
if ( pStk1 == NULL ) return;
// according to recovery, it may be in one of two states
// according to recovery, it may be in one of two states
if ( pStk1->GivState() == 0 ) // first state, evaluates the left operand
{
m_leftop->RestoreState(pStk1, bMain); // interrupted here!
return;
}
if ( pStk1->GivState() == 0 ) // first state, evaluates the left operand
{
m_leftop->RestoreState(pStk1, bMain); // interrupted here!
return;
}
CBotStack* pStk2 = pStk1->RestoreStack(); // adds an item to the stack
if ( pStk2 == NULL ) return;
CBotStack* pStk2 = pStk1->RestoreStack(); // adds an item to the stack
if ( pStk2 == NULL ) return;
// second state, evaluates the right operand
if ( pStk2->GivState() == 0 )
{
m_rightop->RestoreState(pStk2, bMain); // interrupted here!
return;
}
// second state, evaluates the right operand
if ( pStk2->GivState() == 0 )
{
m_rightop->RestoreState(pStk2, bMain); // interrupted here!
return;
}
}
bool CBotLogicExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or return in case of recovery
// if ( pStk1 == EOX ) return true;
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 )
{
if ( !m_condition->Execute(pStk1) ) return false;
if (!pStk1->SetState(1)) return false;
}
if ( pStk1->GivState() == 0 )
{
if ( !m_condition->Execute(pStk1) ) return false;
if (!pStk1->SetState(1)) return false;
}
if ( pStk1->GivVal() == true )
{
if ( !m_op1->Execute(pStk1) ) return false;
}
else
{
if ( !m_op2->Execute(pStk1) ) return false;
}
if ( pStk1->GivVal() == true )
{
if ( !m_op1->Execute(pStk1) ) return false;
}
else
{
if ( !m_op2->Execute(pStk1) ) return false;
}
return pStack->Return(pStk1); // transmits the result
return pStack->Return(pStk1); // transmits the result
}
void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain)
{
if ( !bMain ) return;
if ( !bMain ) return;
CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack
if ( pStk1 == NULL ) return;
CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack
if ( pStk1 == NULL ) return;
if ( pStk1->GivState() == 0 )
{
m_condition->RestoreState(pStk1, bMain);
return;
}
if ( pStk1->GivState() == 0 )
{
m_condition->RestoreState(pStk1, bMain);
return;
}
if ( pStk1->GivVal() == true )
{
m_op1->RestoreState(pStk1, bMain);
}
else
{
m_op2->RestoreState(pStk1, bMain);
}
if ( pStk1->GivVal() == true )
{
m_op1->RestoreState(pStk1, bMain);
}
else
{
m_op2->RestoreState(pStk1, bMain);
}
}
#if 0
void t()
{
int x,y;
1>0 ? x = 0 : y = 0;
int x,y;
1>0 ? x = 0 : y = 0;
}
#endif
#if 01
void t(bool t)
{
int x;
x = 1 + t ? 1 : 3 + 4 * 2 ;
t ? 0 : "test";
int x;
x = 1 + t ? 1 : 3 + 4 * 2 ;
t ? 0 : "test";
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,428 +1,428 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// ClassFile.cpp
//
// definition of methods for class FILE
// Static variables
static CBotClass* m_pClassFILE;
static CBotProgram* m_pFuncFile;
static int m_CompteurFileOpen = 0;
// Prepares a file name.
void PrepareFilename(CBotString &filename) //DD!
{
int pos;
pos = filename.ReverseFind('\\');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // remove the records (files)??
}
pos = filename.ReverseFind('/');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // also those with /
}
pos = filename.ReverseFind(':');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // also removes the drive letter C:
}
filename = CBotString("files\\") + filename;
}
// constructor of the class
// gets the filename as a parameter
// execution
bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
CBotString mode;
// accepts no parameters
if ( pVar == NULL ) return true;
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// recovers the mode
mode = pVar->GivValString();
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; }
}
// save the file name
pVar = pThis->GivItem("filename");
pVar->SetValString(filename);
if ( ! mode.IsEmpty() )
{
// open the called file
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return false; }
m_CompteurFileOpen ++;
// save the handle of file
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
}
return true;
}
// compilation
CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
{
// accepts no parameters
if ( pVar == NULL ) return CBotTypResult( 0 );
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
}
// le r<>sultat est de type void (constructeur)
return CBotTypResult( 0 );
}
// destructor of the class
// execution
bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
// not open? no problem
if ( pVar->GivInit() != IS_DEF) return true;
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
m_CompteurFileOpen --;
pVar->SetInit(IS_NAN);
return true;
}
// FILE :: open method
// get the r / w mode as a parameter
// execution
bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there must be a parameter
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
// there may be a second parameter
if ( pVar->GivNext() != NULL )
{
// in this case the first parameter is the file name
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
// saves the file name
CBotVar* pVar2 = pThis->GivItem("filename");
pVar2->SetValString(filename);
// next parameter is the mode
pVar = pVar -> GivNext();
}
CBotString mode = pVar->GivValString();
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
// No third parameter
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; }
// contains filename
pVar = pThis->GivItem("filename");
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DD! (if the name was assigned by h.filename = "...";
// open requsted file
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) //DR
{
pResult->SetValInt(false); //DR
return true; //DR
}
m_CompteurFileOpen ++;
// saves the handle of file
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
pResult->SetValInt(true); //DR
return true;
}
// compilation
CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar)
{
// there must be a parameter
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
}
// the result is of type bool
return CBotTypResult(CBotTypBoolean); //DR
}
// FILE :: close method
// execution
bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// it should not be any parameter
if ( pVar != NULL ) return CBotErrOverParam;
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
m_CompteurFileOpen --;
pVar->SetInit(IS_NAN);
return true;
}
// compilation
CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
{
// it should not be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function returns a result "void"
return CBotTypResult( 0 );
}
// FILE :: writeln method
// execution
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there must be a parameter
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
// must be a string
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; }
FILE* pFile= (FILE*)pVar->GivValInt();
int res = fputs(param+CBotString("\n"), pFile);
// on error throws an exception
if ( res < 0 ) { Exception = CBotErrWrite; return false; }
return true;
}
// compilation
CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
{
// there must be a parameter
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
// must be a string
if ( pVar->GivType() != CBotTypString ) return CBotTypResult( CBotErrBadString );
// no other parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
// function returns "void" result
return CBotTypResult( 0 );
}
// FILE :: readln method
// execution
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there shouldn't be any parameter
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
//retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
char chaine[2000];
int i;
for ( i = 0 ; i < 2000 ; i++ ) chaine[i] = 0;
fgets(chaine, 1999, pFile);
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; }
pResult->SetValString( chaine );
return true;
}
// compilation
CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
{
// there shouldn't be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function return "string" result
return CBotTypResult( CBotTypString );
}
// FILE :: readln method
// execution
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there shouldn't be any parameter
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
pResult->SetValInt( feof( pFile ) );
return true;
}
// compilation
CBotTypResult cfeof (CBotVar* pThis, CBotVar* &pVar)
{
// there shouldn't be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function return boolean result
return CBotTypResult( CBotTypBoolean );
}
void InitClassFILE()
{
// creates a class for file management
// the usage is as follows:
// file canal( "NomFichier.txt" )
// canal.open( "r" ); // open reading
// s = canal.readln( ); // reads a line
// canal.close(); // closes the file
// create class FILE
m_pClassFILE = new CBotClass("file", NULL);
// add the component ".filename"
m_pClassFILE->AddItem("filename", CBotTypString);
// add the component ".handle"
m_pClassFILE->AddItem("handle", CBotTypInt, PR_PRIVATE);
// define a constructor and destructor
m_pClassFILE->AddFunction("file", rfconstruct, cfconstruct );
m_pClassFILE->AddFunction("~file", rfdestruct, NULL );
// defined associated methods
m_pClassFILE->AddFunction("open", rfopen, cfopen );
m_pClassFILE->AddFunction("close", rfclose, cfclose );
m_pClassFILE->AddFunction("writeln", rfwrite, cfwrite );
m_pClassFILE->AddFunction("readln", rfread, cfread );
m_pClassFILE->AddFunction("eof", rfeof, cfeof );
m_pFuncFile = new CBotProgram( );
CBotStringArray ListFonctions;
m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
m_pFuncFile->SetIdent(-2); // restoreState as a special identifier for this function
}
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// ClassFile.cpp
//
// definition of methods for class FILE
// Static variables
static CBotClass* m_pClassFILE;
static CBotProgram* m_pFuncFile;
static int m_CompteurFileOpen = 0;
// Prepares a file name.
void PrepareFilename(CBotString &filename) //DD!
{
int pos;
pos = filename.ReverseFind('\\');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // remove the records (files)??
}
pos = filename.ReverseFind('/');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // also those with /
}
pos = filename.ReverseFind(':');
if ( pos > 0 )
{
filename = filename.Mid(pos+1); // also removes the drive letter C:
}
filename = CBotString("files\\") + filename;
}
// constructor of the class
// gets the filename as a parameter
// execution
bool rfconstruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
CBotString mode;
// accepts no parameters
if ( pVar == NULL ) return true;
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// recovers the mode
mode = pVar->GivValString();
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; }
}
// save the file name
pVar = pThis->GivItem("filename");
pVar->SetValString(filename);
if ( ! mode.IsEmpty() )
{
// open the called file
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) { Exception = CBotErrFileOpen; return false; }
m_CompteurFileOpen ++;
// save the handle of file
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
}
return true;
}
// compilation
CBotTypResult cfconstruct (CBotVar* pThis, CBotVar* &pVar)
{
// accepts no parameters
if ( pVar == NULL ) return CBotTypResult( 0 );
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
}
// le r<>sultat est de type void (constructeur)
return CBotTypResult( 0 );
}
// destructor of the class
// execution
bool rfdestruct (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
// not open? no problem
if ( pVar->GivInit() != IS_DEF) return true;
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
m_CompteurFileOpen --;
pVar->SetInit(IS_NAN);
return true;
}
// FILE :: open method
// get the r / w mode as a parameter
// execution
bool rfopen (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there must be a parameter
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
// must be a string
if ( pVar->GivType() != CBotTypString ) { Exception = CBotErrBadString; return false; }
// there may be a second parameter
if ( pVar->GivNext() != NULL )
{
// in this case the first parameter is the file name
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DR
// saves the file name
CBotVar* pVar2 = pThis->GivItem("filename");
pVar2->SetValString(filename);
// next parameter is the mode
pVar = pVar -> GivNext();
}
CBotString mode = pVar->GivValString();
if ( mode != "r" && mode != "w" ) { Exception = CBotErrBadParam; return false; }
// No third parameter
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; }
// contains filename
pVar = pThis->GivItem("filename");
CBotString filename = pVar->GivValString();
PrepareFilename(filename); //DD! (if the name was assigned by h.filename = "...";
// open requsted file
FILE* pFile = fopen( filename, mode );
if ( pFile == NULL ) //DR
{
pResult->SetValInt(false); //DR
return true; //DR
}
m_CompteurFileOpen ++;
// saves the handle of file
pVar = pThis->GivItem("handle");
pVar->SetValInt((long)pFile);
pResult->SetValInt(true); //DR
return true;
}
// compilation
CBotTypResult cfopen (CBotVar* pThis, CBotVar* &pVar)
{
// there must be a parameter
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// there may be a second parameter
pVar = pVar->GivNext();
if ( pVar != NULL )
{
// must be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( CBotErrBadString );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
}
// the result is of type bool
return CBotTypResult(CBotTypBoolean); //DR
}
// FILE :: close method
// execution
bool rfclose (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// it should not be any parameter
if ( pVar != NULL ) return CBotErrOverParam;
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
fclose(pFile);
m_CompteurFileOpen --;
pVar->SetInit(IS_NAN);
return true;
}
// compilation
CBotTypResult cfclose (CBotVar* pThis, CBotVar* &pVar)
{
// it should not be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function returns a result "void"
return CBotTypResult( 0 );
}
// FILE :: writeln method
// execution
bool rfwrite (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there must be a parameter
if ( pVar == NULL ) { Exception = CBotErrLowParam; return false; }
// must be a string
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; }
FILE* pFile= (FILE*)pVar->GivValInt();
int res = fputs(param+CBotString("\n"), pFile);
// on error throws an exception
if ( res < 0 ) { Exception = CBotErrWrite; return false; }
return true;
}
// compilation
CBotTypResult cfwrite (CBotVar* pThis, CBotVar* &pVar)
{
// there must be a parameter
if ( pVar == NULL ) return CBotTypResult( CBotErrLowParam );
// must be a string
if ( pVar->GivType() != CBotTypString ) return CBotTypResult( CBotErrBadString );
// no other parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( CBotErrOverParam );
// function returns "void" result
return CBotTypResult( 0 );
}
// FILE :: readln method
// execution
bool rfread (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there shouldn't be any parameter
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
//retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
char chaine[2000];
int i;
for ( i = 0 ; i < 2000 ; i++ ) chaine[i] = 0;
fgets(chaine, 1999, pFile);
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; }
pResult->SetValString( chaine );
return true;
}
// compilation
CBotTypResult cfread (CBotVar* pThis, CBotVar* &pVar)
{
// there shouldn't be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function return "string" result
return CBotTypResult( CBotTypString );
}
// FILE :: readln method
// execution
bool rfeof (CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, int& Exception)
{
// there shouldn't be any parameter
if ( pVar != NULL ) { Exception = CBotErrOverParam; return false; }
// retrieves the element "handle"
pVar = pThis->GivItem("handle");
if ( pVar->GivInit() != IS_DEF) { Exception = CBotErrNotOpen; return false; }
FILE* pFile= (FILE*)pVar->GivValInt();
pResult->SetValInt( feof( pFile ) );
return true;
}
// compilation
CBotTypResult cfeof (CBotVar* pThis, CBotVar* &pVar)
{
// there shouldn't be any parameter
if ( pVar != NULL ) return CBotTypResult( CBotErrOverParam );
// function return boolean result
return CBotTypResult( CBotTypBoolean );
}
void InitClassFILE()
{
// creates a class for file management
// the usage is as follows:
// file canal( "NomFichier.txt" )
// canal.open( "r" ); // open reading
// s = canal.readln( ); // reads a line
// canal.close(); // closes the file
// create class FILE
m_pClassFILE = new CBotClass("file", NULL);
// add the component ".filename"
m_pClassFILE->AddItem("filename", CBotTypString);
// add the component ".handle"
m_pClassFILE->AddItem("handle", CBotTypInt, PR_PRIVATE);
// define a constructor and destructor
m_pClassFILE->AddFunction("file", rfconstruct, cfconstruct );
m_pClassFILE->AddFunction("~file", rfdestruct, NULL );
// defined associated methods
m_pClassFILE->AddFunction("open", rfopen, cfopen );
m_pClassFILE->AddFunction("close", rfclose, cfclose );
m_pClassFILE->AddFunction("writeln", rfwrite, cfwrite );
m_pClassFILE->AddFunction("readln", rfread, cfread );
m_pClassFILE->AddFunction("eof", rfeof, cfeof );
m_pFuncFile = new CBotProgram( );
CBotStringArray ListFonctions;
m_pFuncFile->Compile( "public file openfile(string name, string mode) {return new file(name, mode);}", ListFonctions);
m_pFuncFile->SetIdent(-2); // restoreState as a special identifier for this function
}

View File

@ -22,21 +22,21 @@
bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// no second parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// no second parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// get the contents of the string
CBotString s = pVar->GivValString();
// puts the length of the stack
pResult->SetValInt( s.GivLength() );
return true;
// puts the length of the stack
pResult->SetValInt( s.GivLength() );
return true;
}
// int xxx ( string )
@ -44,18 +44,18 @@ bool rStrLen( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADPARAM );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is an integer
return CBotTypResult( CBotTypInt );
// the end result is an integer
return CBotTypResult( CBotTypInt );
}
@ -64,34 +64,34 @@ CBotTypResult cIntStr( CBotVar* &pVar, void* pUser )
bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// get the contents of the string
CBotString s = pVar->GivValString();
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int n = pVar->GivValInt();
// retrieves this number
int n = pVar->GivValInt();
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// takes the interesting part
s = s.Left( n );
// takes the interesting part
s = s.Left( n );
// puts on the stack
pResult->SetValString( s );
return true;
// puts on the stack
pResult->SetValString( s );
return true;
}
// string xxx ( string, int )
@ -99,26 +99,26 @@ bool rStrLeft( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is a string
return CBotTypResult( CBotTypString );
// the end result is a string
return CBotTypResult( CBotTypString );
}
// gives the right of a string
@ -126,34 +126,34 @@ CBotTypResult cStrStrInt( CBotVar* &pVar, void* pUser )
bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// get the contents of the string
CBotString s = pVar->GivValString();
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int n = pVar->GivValInt();
// retrieves this number
int n = pVar->GivValInt();
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// takes the interesting part
s = s.Right( n );
// takes the interesting part
s = s.Right( n );
// puts on the stack
pResult->SetValString( s );
return true;
// puts on the stack
pResult->SetValString( s );
return true;
}
// gives the central part of a chain
@ -161,51 +161,51 @@ bool rStrRight( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// get the contents of the string
CBotString s = pVar->GivValString();
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int n = pVar->GivValInt();
// retrieves this number
int n = pVar->GivValInt();
// third parameter optional
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int l = pVar->GivValInt();
// third parameter optional
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// which must be a number
if ( pVar->GivType() > CBotTypDouble ) { ex = TX_BADNUM ; return true; }
// retrieves this number
int l = pVar->GivValInt();
// but no fourth parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
// but no fourth parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
// takes the interesting part
s = s.Mid( n, l );
}
else
{
// takes the interesting part
s = s.Mid( n );
}
// takes the interesting part
s = s.Mid( n, l );
}
else
{
// takes the interesting part
s = s.Mid( n );
}
// puts on the stack
pResult->SetValString( s );
return true;
// puts on the stack
pResult->SetValString( s );
return true;
}
// gives the central part of a chain
@ -213,36 +213,36 @@ bool rStrMid( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// third parameter optional
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// third parameter optional
if ( pVar->GivNext() != NULL )
{
pVar = pVar->GivNext();
// which must be a number
if ( pVar->GivType() > CBotTypDouble )
return CBotTypResult( TX_BADNUM );
// no fourth parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
}
// no fourth parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
}
// the end result is a string
return CBotTypResult( CBotTypString );
// the end result is a string
return CBotTypResult( CBotTypString );
}
@ -251,23 +251,23 @@ CBotTypResult cStrStrIntInt( CBotVar* &pVar, void* pUser )
bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// get the contents of the string
CBotString s = pVar->GivValString();
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
float val = GivNumFloat(s);
float val = GivNumFloat(s);
// puts the value on the stack
pResult->SetValFloat( val );
return true;
// puts the value on the stack
pResult->SetValFloat( val );
return true;
}
// float xxx ( string )
@ -275,18 +275,18 @@ bool rStrVal( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is a number
return CBotTypResult( CBotTypFloat );
// the end result is a number
return CBotTypResult( CBotTypFloat );
}
@ -295,33 +295,33 @@ CBotTypResult cFloatStr( CBotVar* &pVar, void* pUser )
bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// get the contents of the string
CBotString s = pVar->GivValString();
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// retrieves this number
CBotString s2 = pVar->GivValString();
// retrieves this number
CBotString s2 = pVar->GivValString();
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// no third parameter
if ( pVar->GivNext() != NULL ) { ex = TX_OVERPARAM ; return true; }
// puts the result on the stack
int res = s.Find(s2);
pResult->SetValInt( res );
if ( res < 0 ) pResult->SetInit( IS_NAN );
return true;
// puts the result on the stack
int res = s.Find(s2);
pResult->SetValInt( res );
if ( res < 0 ) pResult->SetInit( IS_NAN );
return true;
}
// int xxx ( string, string )
@ -329,26 +329,26 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a second parameter
pVar = pVar->GivNext();
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// no third parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is a number
return CBotTypResult( CBotTypInt );
// the end result is a number
return CBotTypResult( CBotTypInt );
}
// gives a string to uppercase
@ -356,24 +356,24 @@ CBotTypResult cIntStrStr( CBotVar* &pVar, void* pUser )
bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// get the contents of the string
CBotString s = pVar->GivValString();
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
s.MakeUpper();
s.MakeUpper();
// puts the value on the stack
pResult->SetValString( s );
return true;
// puts the value on the stack
pResult->SetValString( s );
return true;
}
// gives a string to lowercase
@ -381,24 +381,24 @@ bool rStrUpper( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// it takes a parameter
if ( pVar == NULL ) { ex = TX_LOWPARAM ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// to be a string
if ( pVar->GivType() != CBotTypString ) { ex = TX_BADSTRING ; return true; }
// get the contents of the string
CBotString s = pVar->GivValString();
// get the contents of the string
CBotString s = pVar->GivValString();
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
// but no second parameter
if ( pVar->GivNext() != NULL ){ ex = TX_OVERPARAM ; return true; }
s.MakeLower();
s.MakeLower();
// puts the value on the stack
pResult->SetValString( s );
return true;
// puts the value on the stack
pResult->SetValString( s );
return true;
}
// string xxx ( string )
@ -406,31 +406,31 @@ bool rStrLower( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
CBotTypResult cStrStr( CBotVar* &pVar, void* pUser )
{
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// it takes a parameter
if ( pVar == NULL ) return CBotTypResult( TX_LOWPARAM );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// to be a string
if ( pVar->GivType() != CBotTypString )
return CBotTypResult( TX_BADSTRING );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// no second parameter
if ( pVar->GivNext() != NULL ) return CBotTypResult( TX_OVERPARAM );
// the end result is a string
return CBotTypResult( CBotTypString );
// the end result is a string
return CBotTypResult( CBotTypString );
}
void InitStringFunctions()
{
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
CBotProgram::AddFunction("strlen", rStrLen, cIntStr );
CBotProgram::AddFunction("strleft", rStrLeft, cStrStrInt );
CBotProgram::AddFunction("strright", rStrRight, cStrStrInt );
CBotProgram::AddFunction("strmid", rStrMid, cStrStrIntInt );
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
CBotProgram::AddFunction("strval", rStrVal, cFloatStr );
CBotProgram::AddFunction("strfind", rStrFind, cIntStrStr );
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
CBotProgram::AddFunction("strupper", rStrUpper, cStrStr );
CBotProgram::AddFunction("strlower", rStrLower, cStrStr );
}

View File

@ -1,177 +1,177 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
#pragma once
#ifndef _RESOURCE_H_
#define _RESOURCE_H_
enum EID
{
ID_IF = 2000,
ID_ELSE,
ID_WHILE,
ID_DO,
ID_FOR,
ID_BREAK,
ID_CONTINUE,
ID_SWITCH,
ID_CASE,
ID_DEFAULT,
ID_TRY,
ID_THROW,
ID_CATCH,
ID_FINALLY,
ID_TXT_AND,
ID_TXT_OR,
ID_TXT_NOT,
ID_RETURN,
ID_CLASS,
ID_EXTENDS,
ID_SYNCHO,
ID_NEW,
ID_PUBLIC,
ID_EXTERN,
ID_FINAL,
ID_STATIC,
ID_PROTECTED,
ID_PRIVATE,
ID_REPEAT,
ID_DEBUGDD,
ID_INT,
ID_FLOAT,
ID_BOOLEAN,
ID_STRING,
ID_VOID,
ID_BOOL,
ID_TRUE = 2200,
ID_FALSE,
ID_NULL,
ID_NAN,
ID_OPENPAR = 2300,
ID_CLOSEPAR,
ID_OPBLK,
ID_CLBLK,
ID_SEP,
ID_COMMA,
ID_DOTS,
ID_DOT,
ID_OPBRK,
ID_CLBRK,
ID_DBLDOTS,
ID_LOGIC,
ID_ADD,
ID_SUB,
ID_MUL,
ID_DIV,
ID_ASS,
ID_ASSADD,
ID_ASSSUB,
ID_ASSMUL,
ID_ASSDIV,
ID_ASSOR,
ID_ASSAND,
ID_ASSXOR,
ID_ASSSL,
ID_ASSSR,
ID_ASSASR,
ID_SL,
ID_SR,
ID_ASR,
ID_INC,
ID_DEC,
ID_LO,
ID_HI,
ID_LS,
ID_HS,
ID_EQ,
ID_NE,
ID_AND,
ID_XOR,
ID_OR,
ID_LOG_AND,
ID_LOG_OR,
ID_LOG_NOT,
ID_NOT,
ID_MODULO,
ID_POWER,
ID_ASSMODULO,
TX_UNDEF = 4000,
TX_NAN,
ID_SUPER = 6000
};
#define TX_OPENPAR 5000
#define TX_CLOSEPAR 5001
#define TX_NOTBOOL 5002
#define TX_UNDEFVAR 5003
#define TX_BADLEFT 5004
#define TX_ENDOF 5005
#define TX_OUTCASE 5006
#define TX_NOTERM 5007
#define TX_CLOSEBLK 5008
#define TX_ELSEWITHOUTIF 5009
#define TX_OPENBLK 5010
#define TX_BADTYPE 5011
#define TX_REDEFVAR 5012
#define TX_BAD2TYPE 5013
#define TX_UNDEFCALL 5014
#define TX_MISDOTS 5015
#define TX_WHILE 5016
#define TX_BREAK 5017
#define TX_LABEL 5018
#define TX_NOLABEL 5019
#define TX_NOCASE 5020
#define TX_BADNUM 5021
#define TX_VOID 5022
#define TX_NOTYP 5023
#define TX_NOVAR 5024
#define TX_NOFONC 5025
#define TX_OVERPARAM 5026
#define TX_REDEF 5027
#define TX_LOWPARAM 5028
#define TX_BADPARAM 5029
#define TX_NUMPARAM 5030
#define TX_NOITEM 5031
#define TX_DOT 5032
#define TX_NOCONST 5033
#define TX_REDEFCLASS 5034
#define TX_CLBRK 5035
#define TX_RESERVED 5036
#define TX_BADNEW 5037
#define TX_OPBRK 5038
#define TX_BADSTRING 5039
#define TX_BADINDEX 5040
#define TX_PRIVATE 5041
#define TX_NOPUBLIC 5042
#define TX_DIVZERO 6000
#define TX_NOTINIT 6001
#define TX_BADTHROW 6002
#define TX_NORETVAL 6003
#define TX_NORUN 6004
#define TX_NOCALL 6005
#define TX_NOCLASS 6006
#define TX_NULLPT 6007
#define TX_OPNAN 6008
#define TX_OUTARRAY 6009
#define TX_STACKOVER 6010
#define TX_DELETEDPT 6011
#define TX_FILEOPEN 6012
#define TX_NOTOPEN 6013
#define TX_ERRREAD 6014
#define TX_ERRWRITE 6015
#endif //_RESOURCE_H_
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
#pragma once
#ifndef _RESOURCE_H_
#define _RESOURCE_H_
enum EID
{
ID_IF = 2000,
ID_ELSE,
ID_WHILE,
ID_DO,
ID_FOR,
ID_BREAK,
ID_CONTINUE,
ID_SWITCH,
ID_CASE,
ID_DEFAULT,
ID_TRY,
ID_THROW,
ID_CATCH,
ID_FINALLY,
ID_TXT_AND,
ID_TXT_OR,
ID_TXT_NOT,
ID_RETURN,
ID_CLASS,
ID_EXTENDS,
ID_SYNCHO,
ID_NEW,
ID_PUBLIC,
ID_EXTERN,
ID_FINAL,
ID_STATIC,
ID_PROTECTED,
ID_PRIVATE,
ID_REPEAT,
ID_DEBUGDD,
ID_INT,
ID_FLOAT,
ID_BOOLEAN,
ID_STRING,
ID_VOID,
ID_BOOL,
ID_TRUE = 2200,
ID_FALSE,
ID_NULL,
ID_NAN,
ID_OPENPAR = 2300,
ID_CLOSEPAR,
ID_OPBLK,
ID_CLBLK,
ID_SEP,
ID_COMMA,
ID_DOTS,
ID_DOT,
ID_OPBRK,
ID_CLBRK,
ID_DBLDOTS,
ID_LOGIC,
ID_ADD,
ID_SUB,
ID_MUL,
ID_DIV,
ID_ASS,
ID_ASSADD,
ID_ASSSUB,
ID_ASSMUL,
ID_ASSDIV,
ID_ASSOR,
ID_ASSAND,
ID_ASSXOR,
ID_ASSSL,
ID_ASSSR,
ID_ASSASR,
ID_SL,
ID_SR,
ID_ASR,
ID_INC,
ID_DEC,
ID_LO,
ID_HI,
ID_LS,
ID_HS,
ID_EQ,
ID_NE,
ID_AND,
ID_XOR,
ID_OR,
ID_LOG_AND,
ID_LOG_OR,
ID_LOG_NOT,
ID_NOT,
ID_MODULO,
ID_POWER,
ID_ASSMODULO,
TX_UNDEF = 4000,
TX_NAN,
ID_SUPER = 6000
};
#define TX_OPENPAR 5000
#define TX_CLOSEPAR 5001
#define TX_NOTBOOL 5002
#define TX_UNDEFVAR 5003
#define TX_BADLEFT 5004
#define TX_ENDOF 5005
#define TX_OUTCASE 5006
#define TX_NOTERM 5007
#define TX_CLOSEBLK 5008
#define TX_ELSEWITHOUTIF 5009
#define TX_OPENBLK 5010
#define TX_BADTYPE 5011
#define TX_REDEFVAR 5012
#define TX_BAD2TYPE 5013
#define TX_UNDEFCALL 5014
#define TX_MISDOTS 5015
#define TX_WHILE 5016
#define TX_BREAK 5017
#define TX_LABEL 5018
#define TX_NOLABEL 5019
#define TX_NOCASE 5020
#define TX_BADNUM 5021
#define TX_VOID 5022
#define TX_NOTYP 5023
#define TX_NOVAR 5024
#define TX_NOFONC 5025
#define TX_OVERPARAM 5026
#define TX_REDEF 5027
#define TX_LOWPARAM 5028
#define TX_BADPARAM 5029
#define TX_NUMPARAM 5030
#define TX_NOITEM 5031
#define TX_DOT 5032
#define TX_NOCONST 5033
#define TX_REDEFCLASS 5034
#define TX_CLBRK 5035
#define TX_RESERVED 5036
#define TX_BADNEW 5037
#define TX_OPBRK 5038
#define TX_BADSTRING 5039
#define TX_BADINDEX 5040
#define TX_PRIVATE 5041
#define TX_NOPUBLIC 5042
#define TX_DIVZERO 6000
#define TX_NOTINIT 6001
#define TX_BADTHROW 6002
#define TX_NORETVAL 6003
#define TX_NORUN 6004
#define TX_NOCALL 6005
#define TX_NOCLASS 6006
#define TX_NULLPT 6007
#define TX_OPNAN 6008
#define TX_OUTARRAY 6009
#define TX_STACKOVER 6010
#define TX_DELETEDPT 6011
#define TX_FILEOPEN 6012
#define TX_NOTOPEN 6013
#define TX_ERRREAD 6014
#define TX_ERRWRITE 6015
#endif //_RESOURCE_H_