Fixed treating 'bool' as 'int' in CBot engine
Appears to fix #199 - further testing requireddev-time-step
parent
95eee3a340
commit
964d3574fd
|
@ -115,7 +115,7 @@ CBotInstr* CBotFor::Compile(CBotToken* &p, CBotCStack* pStack)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CBotFor :: Execute(CBotStack* &pj)
|
bool CBotFor :: Execute(CBotStack* &pj)
|
||||||
{
|
{
|
||||||
CBotStack* pile = pj->AddStack(this, true); // adds an item to the stack (variables locales)
|
CBotStack* pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // adds an item to the stack (variables locales)
|
||||||
// or find in case of recovery
|
// or find in case of recovery
|
||||||
// if ( pile == EOX ) return true;
|
// if ( pile == EOX ) return true;
|
||||||
|
|
||||||
|
|
|
@ -345,7 +345,7 @@ static int xx = 0;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
|
bool CBotFunction::Execute(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInstance)
|
||||||
{
|
{
|
||||||
CBotStack* pile = pj->AddStack(this, 2); // one end of stack local to this function
|
CBotStack* pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_2); // one end of stack local to this function
|
||||||
// if ( pile == EOX ) return true;
|
// if ( pile == EOX ) return true;
|
||||||
|
|
||||||
pile->SetBotCall(m_pProg); // bases for routines
|
pile->SetBotCall(m_pProg); // bases for routines
|
||||||
|
@ -401,7 +401,7 @@ void CBotFunction::RestoreState(CBotVar** ppVars, CBotStack* &pj, CBotVar* pInst
|
||||||
|
|
||||||
pile->SetBotCall(m_pProg); // bases for routines
|
pile->SetBotCall(m_pProg); // bases for routines
|
||||||
|
|
||||||
if ( pile->GetBlock() < 2 )
|
if ( pile->GetBlock() != CBotStack::UnknownEnumBlock::UNKNOWN_2 )
|
||||||
{
|
{
|
||||||
CBotStack* pile2 = pile->RestoreStack(nullptr); // one end of stack local to this function
|
CBotStack* pile2 = pile->RestoreStack(nullptr); // one end of stack local to this function
|
||||||
if ( pile2 == nullptr ) return;
|
if ( pile2 == nullptr ) return;
|
||||||
|
@ -604,14 +604,14 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar** ppVars, CBotS
|
||||||
|
|
||||||
if ( pt != nullptr )
|
if ( pt != nullptr )
|
||||||
{
|
{
|
||||||
CBotStack* pStk1 = pStack->AddStack(pt, 2); // to put "this"
|
CBotStack* pStk1 = pStack->AddStack(pt, CBotStack::UnknownEnumBlock::UNKNOWN_2); // to put "this"
|
||||||
// if ( pStk1 == EOX ) return true;
|
// if ( pStk1 == EOX ) return true;
|
||||||
|
|
||||||
pStk1->SetBotCall(pt->m_pProg); // it may have changed module
|
pStk1->SetBotCall(pt->m_pProg); // it may have changed module
|
||||||
|
|
||||||
if ( pStk1->IfStep() ) return false;
|
if ( pStk1->IfStep() ) return false;
|
||||||
|
|
||||||
CBotStack* pStk3 = pStk1->AddStack(nullptr, true); // parameters
|
CBotStack* pStk3 = pStk1->AddStack(nullptr, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // parameters
|
||||||
|
|
||||||
// preparing parameters on the stack
|
// preparing parameters on the stack
|
||||||
|
|
||||||
|
@ -683,7 +683,7 @@ void CBotFunction::RestoreCall(long& nIdent, const char* name, CBotVar** ppVars,
|
||||||
|
|
||||||
pStk1->SetBotCall(pt->m_pProg); // it may have changed module
|
pStk1->SetBotCall(pt->m_pProg); // it may have changed module
|
||||||
|
|
||||||
if ( pStk1->GetBlock() < 2 )
|
if ( pStk1->GetBlock() != CBotStack::UnknownEnumBlock::UNKNOWN_2 )
|
||||||
{
|
{
|
||||||
CBotStack* pStk2 = pStk1->RestoreStack(nullptr); // used more
|
CBotStack* pStk2 = pStk1->RestoreStack(nullptr); // used more
|
||||||
if ( pStk2 == nullptr ) return;
|
if ( pStk2 == nullptr ) return;
|
||||||
|
@ -733,11 +733,11 @@ int CBotFunction::DoCall(long& nIdent, const char* name, CBotVar* pThis, CBotVar
|
||||||
{
|
{
|
||||||
// DEBUG( "CBotFunction::DoCall" + pt->GetName(), 0, pStack);
|
// DEBUG( "CBotFunction::DoCall" + pt->GetName(), 0, pStack);
|
||||||
|
|
||||||
CBotStack* pStk = pStack->AddStack(pt, 2);
|
CBotStack* pStk = pStack->AddStack(pt, CBotStack::UnknownEnumBlock::UNKNOWN_2);
|
||||||
// if ( pStk == EOX ) return true;
|
// if ( pStk == EOX ) return true;
|
||||||
|
|
||||||
pStk->SetBotCall(pt->m_pProg); // it may have changed module
|
pStk->SetBotCall(pt->m_pProg); // it may have changed module
|
||||||
CBotStack* pStk3 = pStk->AddStack(nullptr, true); // to set parameters passed
|
CBotStack* pStk3 = pStk->AddStack(nullptr, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // to set parameters passed
|
||||||
|
|
||||||
// preparing parameters on the stack
|
// preparing parameters on the stack
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ CBotInstr* CBotInstrMethode::Compile(CBotToken* &p, CBotCStack* pStack, CBotVar*
|
||||||
bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend)
|
bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* prevToken, bool bStep, bool bExtend)
|
||||||
{
|
{
|
||||||
CBotVar* ppVars[1000];
|
CBotVar* ppVars[1000];
|
||||||
CBotStack* pile1 = pj->AddStack(this, true); // a place for the copy of This
|
CBotStack* pile1 = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // a place for the copy of This
|
||||||
|
|
||||||
if (pVar->GetPointer() == nullptr)
|
if (pVar->GetPointer() == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -221,7 +221,7 @@ void CBotInstrMethode::RestoreStateVar(CBotStack* &pile, bool bMain)
|
||||||
bool CBotInstrMethode::Execute(CBotStack* &pj)
|
bool CBotInstrMethode::Execute(CBotStack* &pj)
|
||||||
{
|
{
|
||||||
CBotVar* ppVars[1000];
|
CBotVar* ppVars[1000];
|
||||||
CBotStack* pile1 = pj->AddStack(this, true); // place for the copy of This
|
CBotStack* pile1 = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); // place for the copy of This
|
||||||
|
|
||||||
if (pile1->IfStep()) return false;
|
if (pile1->IfStep()) return false;
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ CBotInstr* CBotListInstr::Compile(CBotToken* &p, CBotCStack* pStack, bool bLocal
|
||||||
bool CBotListInstr::Execute(CBotStack* &pj)
|
bool CBotListInstr::Execute(CBotStack* &pj)
|
||||||
{
|
{
|
||||||
|
|
||||||
CBotStack* pile = pj->AddStack(this, true); //needed for SetState()
|
CBotStack* pile = pj->AddStack(this, CBotStack::UnknownEnumBlock::UNKNOWN_TRUE); //needed for SetState()
|
||||||
if (pile->StackOver() ) return pj->Return( pile);
|
if (pile->StackOver() ) return pj->Return( pile);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ CBotStack* CBotStack::FirstStack()
|
||||||
// completely empty
|
// completely empty
|
||||||
memset(p, 0, size);
|
memset(p, 0, size);
|
||||||
|
|
||||||
p-> m_bBlock = true;
|
p-> m_bBlock = UnknownEnumBlock::UNKNOWN_TRUE ;
|
||||||
m_timer = m_initimer; // sets the timer at the beginning
|
m_timer = m_initimer; // sets the timer at the beginning
|
||||||
|
|
||||||
CBotStack* pp = p;
|
CBotStack* pp = p;
|
||||||
|
@ -140,7 +140,7 @@ void CBotStack::Delete()
|
||||||
|
|
||||||
// routine improved
|
// routine improved
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
|
CBotStack* CBotStack::AddStack(CBotInstr* instr, UnknownEnumBlock bBlock)
|
||||||
{
|
{
|
||||||
if (m_next != nullptr)
|
if (m_next != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -168,12 +168,12 @@ CBotStack* CBotStack::AddStack(CBotInstr* instr, bool bBlock)
|
||||||
p->m_prev = this;
|
p->m_prev = this;
|
||||||
p->m_state = 0;
|
p->m_state = 0;
|
||||||
p->m_call = nullptr;
|
p->m_call = nullptr;
|
||||||
p->m_bFunc = false;
|
p->m_bFunc = IsFunctionParam::FALSE;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
|
CBotStack* CBotStack::AddStackEOX(CBotCall* instr, UnknownEnumBlock bBlock)
|
||||||
{
|
{
|
||||||
if (m_next != nullptr)
|
if (m_next != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -186,12 +186,12 @@ CBotStack* CBotStack::AddStackEOX(CBotCall* instr, bool bBlock)
|
||||||
}
|
}
|
||||||
CBotStack* p = AddStack(nullptr, bBlock);
|
CBotStack* p = AddStack(nullptr, bBlock);
|
||||||
p->m_call = instr;
|
p->m_call = instr;
|
||||||
p->m_bFunc = 2; // special
|
p->m_bFunc = IsFunctionParam::UNKNOWN_EOX_SPECIAL; // special
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CBotStack* CBotStack::AddStack2(bool bBlock)
|
CBotStack* CBotStack::AddStack2(UnknownEnumBlock bBlock)
|
||||||
{
|
{
|
||||||
if (m_next2 != nullptr)
|
if (m_next2 != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -215,7 +215,7 @@ CBotStack* CBotStack::AddStack2(bool bBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool CBotStack::GetBlock()
|
CBotStack::UnknownEnumBlock CBotStack::GetBlock()
|
||||||
{
|
{
|
||||||
return m_bBlock;
|
return m_bBlock;
|
||||||
}
|
}
|
||||||
|
@ -723,7 +723,7 @@ void CBotStack::AddVar(CBotVar* pVar)
|
||||||
CBotStack* p = this;
|
CBotStack* p = this;
|
||||||
|
|
||||||
// returns to the father element
|
// returns to the father element
|
||||||
while (p != nullptr && p->m_bBlock == 0) p = p->m_prev;
|
while (p != nullptr && p->m_bBlock == UnknownEnumBlock::UNKNOWN_FALSE) p = p->m_prev;
|
||||||
|
|
||||||
if ( p == nullptr ) return;
|
if ( p == nullptr ) return;
|
||||||
|
|
||||||
|
@ -743,7 +743,7 @@ void CBotStack::AddVar(CBotVar* pVar)
|
||||||
void CBotStack::SetBotCall(CBotProgram* p)
|
void CBotStack::SetBotCall(CBotProgram* p)
|
||||||
{
|
{
|
||||||
m_prog = p;
|
m_prog = p;
|
||||||
m_bFunc = true;
|
m_bFunc = IsFunctionParam::TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -826,7 +826,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
|
||||||
while (p->m_next != nullptr)
|
while (p->m_next != nullptr)
|
||||||
{
|
{
|
||||||
if ( p->m_instr != nullptr ) instr = p->m_instr;
|
if ( p->m_instr != nullptr ) instr = p->m_instr;
|
||||||
if ( p->m_bFunc == 1 && p->m_instr != nullptr ) funct = p->m_instr;
|
if ( p->m_bFunc == IsFunctionParam::TRUE && p->m_instr != nullptr ) funct = p->m_instr;
|
||||||
if ( p->m_next->m_prog != prog ) break ;
|
if ( p->m_next->m_prog != prog ) break ;
|
||||||
|
|
||||||
if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ;
|
if (p->m_next2 && p->m_next2->m_state != 0) p = p->m_next2 ;
|
||||||
|
@ -834,7 +834,7 @@ void CBotStack::GetRunPos(const char* &FunctionName, int &start, int &end)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( p->m_instr != nullptr ) instr = p->m_instr;
|
if ( p->m_instr != nullptr ) instr = p->m_instr;
|
||||||
if ( p->m_bFunc == 1 && p->m_instr != nullptr ) funct = p->m_instr;
|
if ( p->m_bFunc == IsFunctionParam::TRUE && p->m_instr != nullptr ) funct = p->m_instr;
|
||||||
|
|
||||||
if ( funct == nullptr ) return;
|
if ( funct == nullptr ) return;
|
||||||
|
|
||||||
|
@ -868,13 +868,13 @@ CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level)
|
||||||
|
|
||||||
|
|
||||||
// descends upon the elements of block
|
// descends upon the elements of block
|
||||||
while ( p != nullptr && !p->m_bBlock ) p = p->m_prev;
|
while ( p != nullptr && p->m_bBlock != UnknownEnumBlock::UNKNOWN_FALSE ) p = p->m_prev;
|
||||||
// Now p is on the beggining of the top block (with local variables)
|
// Now p is on the beggining of the top block (with local variables)
|
||||||
|
|
||||||
while ( p != nullptr && level++ < 0 )
|
while ( p != nullptr && level++ < 0 )
|
||||||
{
|
{
|
||||||
p = p->m_prev;
|
p = p->m_prev;
|
||||||
while ( p != nullptr && !p->m_bBlock ) p = p->m_prev;
|
while ( p != nullptr && p->m_bBlock != UnknownEnumBlock::UNKNOWN_FALSE ) p = p->m_prev;
|
||||||
}
|
}
|
||||||
// Now p is on the block "level"
|
// Now p is on the block "level"
|
||||||
|
|
||||||
|
@ -884,7 +884,7 @@ CBotVar* CBotStack::GetStackVars(const char* &FunctionName, int level)
|
||||||
CBotStack* pp = p;
|
CBotStack* pp = p;
|
||||||
while ( pp != nullptr )
|
while ( pp != nullptr )
|
||||||
{
|
{
|
||||||
if ( pp->m_bFunc == 1 ) break;
|
if ( pp->m_bFunc == IsFunctionParam::TRUE) break;
|
||||||
pp = pp->m_prev;
|
pp = pp->m_prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -913,7 +913,7 @@ bool CBotStack::SaveState(FILE* pf)
|
||||||
{
|
{
|
||||||
if (!WriteWord(pf, 1)) return false; // a mark of pursuit
|
if (!WriteWord(pf, 1)) return false; // a mark of pursuit
|
||||||
}
|
}
|
||||||
if (!WriteWord(pf, m_bBlock)) return false; // is a local block
|
if (!WriteWord(pf, static_cast<unsigned short>(m_bBlock))) return false; // is a local block
|
||||||
if (!WriteWord(pf, m_state)) return false; // in what state?
|
if (!WriteWord(pf, m_state)) return false; // in what state?
|
||||||
if (!WriteWord(pf, 0)) return false; // by compatibility m_bDontDelete
|
if (!WriteWord(pf, 0)) return false; // by compatibility m_bDontDelete
|
||||||
if (!WriteWord(pf, m_step)) return false; // in what state?
|
if (!WriteWord(pf, m_step)) return false; // in what state?
|
||||||
|
@ -947,7 +947,7 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ReadWord(pf, w)) return false; // is a local block
|
if (!ReadWord(pf, w)) return false; // is a local block
|
||||||
pStack->m_bBlock = w;
|
pStack->m_bBlock = static_cast<UnknownEnumBlock>(w);
|
||||||
|
|
||||||
if (!ReadWord(pf, w)) return false; // in what state ?
|
if (!ReadWord(pf, w)) return false; // in what state ?
|
||||||
pStack->SetState(static_cast<short>(w)); // in a good state
|
pStack->SetState(static_cast<short>(w)); // in a good state
|
||||||
|
|
|
@ -45,6 +45,9 @@ class CBotToken;
|
||||||
class CBotStack
|
class CBotStack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum class UnknownEnumBlock : unsigned short { UNKNOWN_FALSE = 0, UNKNOWN_TRUE = 1, UNKNOWN_2 = 2 }; // TODO: figure out what these mean ~krzys_h
|
||||||
|
enum class IsFunctionParam : unsigned short { FALSE = 0, TRUE = 1, UNKNOWN_EOX_SPECIAL = 2 }; // TODO: just guessing the meaning of values, should be verified ~krzys_h
|
||||||
|
|
||||||
#if STACKMEM
|
#if STACKMEM
|
||||||
/**
|
/**
|
||||||
* \brief FirstStack Allocate first stack
|
* \brief FirstStack Allocate first stack
|
||||||
|
@ -169,12 +172,12 @@ public:
|
||||||
CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false);
|
CBotVar* CopyVar(CBotToken& Token, bool bUpdate = false);
|
||||||
|
|
||||||
|
|
||||||
CBotStack* AddStack(CBotInstr* instr = nullptr, bool bBlock = false); // extends the stack
|
CBotStack* AddStack(CBotInstr* instr = nullptr, UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack
|
||||||
CBotStack* AddStackEOX(CBotCall* instr = nullptr, bool bBlock = false); // extends the stack
|
CBotStack* AddStackEOX(CBotCall* instr = nullptr, UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack
|
||||||
CBotStack* RestoreStack(CBotInstr* instr = nullptr);
|
CBotStack* RestoreStack(CBotInstr* instr = nullptr);
|
||||||
CBotStack* RestoreStackEOX(CBotCall* instr = nullptr);
|
CBotStack* RestoreStackEOX(CBotCall* instr = nullptr);
|
||||||
|
|
||||||
CBotStack* AddStack2(bool bBlock = false); // extends the stack
|
CBotStack* AddStack2(UnknownEnumBlock bBlock = UnknownEnumBlock::UNKNOWN_FALSE); // extends the stack
|
||||||
bool Return(CBotStack* pFils); // transmits the result over
|
bool Return(CBotStack* pFils); // transmits the result over
|
||||||
bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack
|
bool ReturnKeep(CBotStack* pFils); // transmits the result without reducing the stack
|
||||||
bool BreakReturn(CBotStack* pfils, const char* name = nullptr);
|
bool BreakReturn(CBotStack* pfils, const char* name = nullptr);
|
||||||
|
@ -206,7 +209,7 @@ public:
|
||||||
void SetBotCall(CBotProgram* p);
|
void SetBotCall(CBotProgram* p);
|
||||||
CBotProgram* GetBotCall(bool bFirst = false);
|
CBotProgram* GetBotCall(bool bFirst = false);
|
||||||
void* GetPUser();
|
void* GetPUser();
|
||||||
bool GetBlock();
|
UnknownEnumBlock GetBlock();
|
||||||
|
|
||||||
|
|
||||||
bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype);
|
bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, CBotTypResult& rettype);
|
||||||
|
@ -221,8 +224,6 @@ public:
|
||||||
void GetRunPos(const char* &FunctionName, int &start, int &end);
|
void GetRunPos(const char* &FunctionName, int &start, int &end);
|
||||||
CBotVar* GetStackVars(const char* &FunctionName, int level);
|
CBotVar* GetStackVars(const char* &FunctionName, int level);
|
||||||
|
|
||||||
int m_temp;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CBotStack* m_next;
|
CBotStack* m_next;
|
||||||
CBotStack* m_next2;
|
CBotStack* m_next2;
|
||||||
|
@ -243,7 +244,7 @@ private:
|
||||||
CBotVar* m_var; // result of the operations
|
CBotVar* m_var; // result of the operations
|
||||||
CBotVar* m_listVar; // variables declared at this level
|
CBotVar* m_listVar; // variables declared at this level
|
||||||
|
|
||||||
bool m_bBlock; // is part of a block (variables are local to this block)
|
UnknownEnumBlock m_bBlock; // is part of a block (variables are local to this block)
|
||||||
bool m_bOver; // stack limits?
|
bool m_bOver; // stack limits?
|
||||||
// bool m_bDontDelete; // special, not to destroy the variable during delete
|
// bool m_bDontDelete; // special, not to destroy the variable during delete
|
||||||
CBotProgram* m_prog; // user-defined functions
|
CBotProgram* m_prog; // user-defined functions
|
||||||
|
@ -258,7 +259,7 @@ private:
|
||||||
void* m_pUser;
|
void* m_pUser;
|
||||||
|
|
||||||
CBotInstr* m_instr; // the corresponding instruction
|
CBotInstr* m_instr; // the corresponding instruction
|
||||||
bool m_bFunc; // an input of a function?
|
IsFunctionParam m_bFunc; // an input of a function?
|
||||||
CBotCall* m_call; // recovery point in a extern call
|
CBotCall* m_call; // recovery point in a extern call
|
||||||
friend class CBotTry;
|
friend class CBotTry;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue