Merge pull request #793 from melex750/dev

Fix some bugs in CBOT

This fixes https://github.com/colobot/colobot/issues/728#issuecomment-205039570 and #626
master
krzys-h 2016-07-04 12:20:39 +02:00
commit 3e30ccfdfa
6 changed files with 27 additions and 12 deletions

View File

@ -121,6 +121,15 @@ CBotInstr* CBotDefArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResul
} }
} }
} }
if (pStk->IsOk()) while (true) // mark initialized
{
var = var->GetItem(0, true);
if (var == nullptr) break;
if (var->GetType() == CBotTypArrayPointer) continue;
if (var->GetType() <= CBotTypString) var->SetInit(CBotVar::InitType::DEF);
break;
}
} }
if (pStk->IsOk()) return pStack->Return(inst, pStk); if (pStk->IsOk()) return pStack->Return(inst, pStk);

View File

@ -103,6 +103,7 @@ bool CBotInstrMethode::ExecuteVar(CBotVar* &pVar, CBotStack* &pj, CBotToken* pre
if (pVar->GetPointer() == nullptr) if (pVar->GetPointer() == nullptr)
{ {
pj->SetError(CBotErrNull, prevToken); pj->SetError(CBotErrNull, prevToken);
return pj->Return(pile1);
} }
if (pile1->IfStep()) return false; if (pile1->IfStep()) return false;

View File

@ -98,7 +98,7 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
} }
} }
inst->m_expr->AddNext3(i); inst->m_expr->AddNext3b(i);
if ( p->GetType() == ID_COMMA ) continue; if ( p->GetType() == ID_COMMA ) continue;
if ( p->GetType() == ID_CLBLK ) break; if ( p->GetType() == ID_CLBLK ) break;
@ -114,10 +114,10 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
{ {
goto error; goto error;
} }
CBotVar* pv = pStk->GetVar(); // result of the expression
if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && CBotTypResult valType = pStk->GetTypResult();
!(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) ))
if (!TypeCompatible(valType, type, ID_ASS) )
{ {
pStk->SetError(CBotErrBadType1, p->GetStart()); pStk->SetError(CBotErrBadType1, p->GetStart());
goto error; goto error;
@ -133,15 +133,14 @@ CBotInstr* CBotListArray::Compile(CBotToken* &p, CBotCStack* pStack, CBotTypResu
goto error; goto error;
} }
CBotVar* pv = pStk->GetVar(); // result of the expression CBotTypResult valType = pStk->GetTypResult();
if (pv == nullptr || (!TypesCompatibles( type, pv->GetTypResult()) && if (!TypeCompatible(valType, type, ID_ASS) )
!(type.Eq(CBotTypPointer) && pv->GetTypResult().Eq(CBotTypNullPointer)) ))
{ {
pStk->SetError(CBotErrBadType1, p->GetStart()); pStk->SetError(CBotErrBadType1, p->GetStart());
goto error; goto error;
} }
inst->m_expr->AddNext3(i); inst->m_expr->AddNext3b(i);
if (p->GetType() == ID_COMMA) continue; if (p->GetType() == ID_COMMA) continue;
if (p->GetType() == ID_CLBLK) break; if (p->GetType() == ID_CLBLK) break;
@ -175,7 +174,7 @@ bool CBotListArray::Execute(CBotStack* &pj, CBotVar* pVar)
int n = 0; int n = 0;
for (; p != nullptr ; n++, p = p->GetNext3()) for (; p != nullptr ; n++, p = p->GetNext3b())
{ {
if (pile1->GetState() > n) continue; if (pile1->GetState() > n) continue;
@ -207,7 +206,7 @@ void CBotListArray::RestoreState(CBotStack* &pj, bool bMain)
int state = pile->GetState(); int state = pile->GetState();
while(state-- > 0) p = p->GetNext3() ; while(state-- > 0) p = p->GetNext3b() ;
p->RestoreState(pile, bMain); // size calculation //interrupted! p->RestoreState(pile, bMain); // size calculation //interrupted!
} }

View File

@ -62,7 +62,7 @@ protected:
virtual std::map<std::string, CBotInstr*> GetDebugLinks() override; virtual std::map<std::string, CBotInstr*> GetDebugLinks() override;
private: private:
//! An expression for an element others are linked with CBotInstr :: m_next3; //! An expression for an element others are linked with CBotInstr :: m_next3b;
CBotInstr* m_expr; CBotInstr* m_expr;
}; };

View File

@ -50,7 +50,11 @@ CBotInstr* CBotNew::Compile(CBotToken* &p, CBotCStack* pStack)
if (!IsOfType(p, ID_NEW)) return nullptr; if (!IsOfType(p, ID_NEW)) return nullptr;
// verifies that the token is a class name // verifies that the token is a class name
if (p->GetType() != TokenTypVar) return nullptr; if (p->GetType() != TokenTypVar)
{
pStack->SetError(CBotErrBadNew, p);
return nullptr;
}
CBotClass* pClass = CBotClass::Find(p); CBotClass* pClass = CBotClass::Find(p);
if (pClass == nullptr) if (pClass == nullptr)

View File

@ -214,6 +214,7 @@ bool CBotProgram::Run(void* pUser, int timer)
m_error = m_stack->GetError(m_errorStart, m_errorEnd); m_error = m_stack->GetError(m_errorStart, m_errorEnd);
m_stack->Delete(); m_stack->Delete();
m_stack = nullptr; m_stack = nullptr;
CBotClass::FreeLock(this);
return true; // execution is finished! return true; // execution is finished!
} }
@ -226,6 +227,7 @@ void CBotProgram::Stop()
m_stack->Delete(); m_stack->Delete();
m_stack = nullptr; m_stack = nullptr;
m_entryPoint = nullptr; m_entryPoint = nullptr;
CBotClass::FreeLock(this);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////