Beispiel #1
0
void CBotIf :: RestoreState(CBotStack* &pj, bool bMain)
{
    if ( !bMain ) return;

    CBotStack* pile = pj->RestoreStack(this);       // adds an item to the stack
    if ( pile == nullptr ) return;

    // according to recovery, it may be in one of two states
    if( pile->GetState() == 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->GetVal() == true )                           // condition was true?
    {
        if (m_block != nullptr )                              // block may be absent
             m_block->RestoreState(pile, bMain);            // interrupted here!
    }
    else
    {
        if (m_blockElse != nullptr )                          // if there is an alternate block
             m_blockElse->RestoreState(pile, bMain);        // interrupted here!
    }
}
Beispiel #2
0
bool CBotWhile::Execute(CBotStack* &pj)
{
    CBotStack* pile = pj->AddStack(this);   // adds an item to the stack
                                            // or find in case of recovery
//  if ( pile == EOX ) return true;

    if ( pile->IfStep() ) return false;

    while( true ) switch( pile->GetState() )    // executes the loop
    {                                           // there are two possible states (depending on recovery)
    case 0:
        // evaluates the condition
        if ( !m_condition->Execute(pile) ) return false; // interrupted here?

        // the result of the condition is on the stack

        // terminates if an error or if the condition is false
        if ( !pile->IsOk() || pile->GetVal() != true )
        {
            return pj->Return(pile);                    // sends the results and releases the stack
        }

        // the condition is true, pass in the second mode

        if (!pile->SetState(1)) return false;           // ready for further

    case 1:
        // evaluates the associated statement block
        if (m_block != nullptr &&
            !m_block->Execute(pile) )
        {
            if (pile->IfContinue(0, m_label)) continue; // if continued, will return to test
            return pj->BreakReturn(pile, m_label);      // sends the results and releases the stack
        }

        // terminates if there is an error
        if ( !pile->IsOk() )
        {
            return pj->Return(pile);                    // sends the results and releases the stack
        }

        // returns to the test again
        if (!pile->SetState(0, 0)) return false;
        continue;
    }
}
Beispiel #3
0
bool CBotThrow :: Execute(CBotStack* &pj)
{
    CBotStack*  pile = pj->AddStack(this);
//  if ( pile == EOX ) return true;

    if ( pile->GetState() == 0 )
    {
        if ( !m_Value->Execute(pile) ) return false;
        pile->IncState();
    }

    if ( pile->IfStep() ) return false;

    int val = pile->GetVal();
    if ( val < 0 ) val = TX_BADTHROW;
    pile->SetError( val, &m_token );
    return pj->Return( pile );
}
Beispiel #4
0
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;

    if ( pile->IfStep() ) return false;

    // according to recovery, it may be in one of two states
    if( pile->GetState() == 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
        }

        // 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->GetVal() == true )                           // condition was true?
    {
        if (m_block != nullptr &&                             // block may be absent
            !m_block->Execute(pile) ) return false;         // interrupted here?
    }
    else
    {
        if (m_blockElse != nullptr &&                         // 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);
}
Beispiel #5
0
bool CBotFor :: Execute(CBotStack* &pj)
{
    CBotStack* pile = pj->AddStack(this, true);     // adds an item to the stack (variables locales)
                                                    // or find in case of recovery
//  if ( pile == EOX ) return true;

    if ( pile->IfStep() ) return false;

    while( true ) switch( pile->GetState() )    // executes the loop
    {                                           // there are four possible states (depending on recovery)
    case 0:
        // initialize
        if ( m_Init != nullptr &&
             !m_Init->Execute(pile) ) return false;     // interrupted here ?
        if (!pile->SetState(1)) return false;           // ready for further

    case 1:
        // evaluates the condition
        if ( m_Test != nullptr )                           // no strings attached? -> True!
        {
            if (!m_Test->Execute(pile) ) return false;  // interrupted here ?

            // the result of the condition is on the stack

            // terminates if an error or if the condition is false
            if ( !pile->IsOk() || pile->GetVal() != true )
            {
                return pj->Return(pile);                // sends the results and releases the stack
            }
        }

        // la condition est vrai, passe à la suite
        if (!pile->SetState(2)) return false;           // ready for further

    case 2:
        // evaluates the associated statement block
        if ( m_Block != nullptr &&
            !m_Block->Execute(pile) )
        {
            if (pile->IfContinue(3, m_label)) continue; // if continued, going on to incrementation
            return pj->BreakReturn(pile, m_label);      // sends the results and releases the stack
        }

        // terminates if there is an error
        if ( !pile->IsOk() )
        {
            return pj->Return(pile);                    // sends the results and releases the stack
        }

        if (!pile->SetState(3)) return false;           // ready for further

    case 3:
        // evalutate the incrementation
        if ( m_Incr != nullptr &&
            !m_Incr->Execute(pile) ) return false;      // interrupted here ?

        // returns to the test again
        if (!pile->SetState(1, 0)) return false;            // returns to the test
        continue;
    }
}