~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/3rdparty/squirrel/squirrel/sqvm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Kooijman, Matthijs Kooijman
  • Date: 2009-10-01 22:52:59 UTC
  • mfrom: (1.1.8 upstream) (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091001225259-5kpkp4sthbszpyif
[ Matthijs Kooijman ]
* New upstream release
* Use printf instead of echo -en in openttd-wrapper to make it POSIX
  compatible (Closes: #547758).
* Remove three patches that are now included in upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
                                        res = i1 / i2;
51
51
                                        break;
52
52
                                case '*': res = i1 * i2; break;
53
 
                                case '%': res = i1 % i2; break;
 
53
                                case '%': if(i2 == 0) { Raise_Error(_SC("modulo by zero")); return false; }
 
54
                                        res = i1 % i2;
 
55
                                        break;
54
56
                                default: res = 0xDEADBEEF;
55
57
                                }
56
58
                                trg = res;
321
323
                SQInteger ndef = func->_ndefaultparams;
322
324
                if(ndef && nargs < paramssize) {
323
325
                        SQInteger diff = paramssize - nargs;
 
326
                        if (diff > ndef) {
 
327
                                Raise_Error(_SC("wrong number of parameters"));
 
328
                                return false;
 
329
                        }
324
330
                        for(SQInteger n = ndef - diff; n < ndef; n++) {
325
331
                                _stack._vals[stackbase + (nargs++)] = closure->_defaultparams[n];
326
332
                        }
682
688
                        break;
683
689
                case ET_RESUME_GENERATOR: _generator(closure)->Resume(this, target); ci->_root = SQTrue; traps += ci->_etraps; break;
684
690
                case ET_RESUME_VM:
 
691
                case ET_RESUME_THROW_VM:
685
692
                        traps = _suspended_traps;
686
693
                        ci->_root = _suspended_root;
687
694
                        ci->_vargs = _suspend_varargs;
688
695
                        _suspended = SQFalse;
 
696
                        if(et  == ET_RESUME_THROW_VM) { SQ_THROW(); }
689
697
                        break;
690
698
                case ET_RESUME_OPENTTD:
691
699
                        traps = _suspended_traps;
741
749
                                                        _GUARD(gen->Yield(this));
742
750
                                                        Return(1, ct_target, clo);
743
751
                                                        STK(ct_target) = gen;
744
 
                                                        while (last_top >= _top) _stack._vals[last_top--].Null();
745
 
                                                        continue;
746
752
                                                }
 
753
                                                while (last_top >= _top) _stack._vals[last_top--].Null();
747
754
                                                }
748
755
                                                continue;
749
756
                                        case OT_NATIVECLOSURE: {
1135
1142
        }
1136
1143
 
1137
1144
 
 
1145
        /* Store the call stack size, so we can restore that */
 
1146
        SQInteger cstksize = _callsstacksize;
1138
1147
        SQInteger ret;
1139
1148
        try {
1140
1149
                SQBool can_suspend = this->_can_suspend;
1145
1154
                _nnativecalls--;
1146
1155
                suspend = false;
1147
1156
 
 
1157
                _callsstacksize = cstksize;
1148
1158
                _stackbase = oldstackbase;
1149
1159
                _top = oldtop;
1150
1160
 
1154
1164
                throw;
1155
1165
        }
1156
1166
 
 
1167
        assert(cstksize == _callsstacksize);
 
1168
 
1157
1169
        _nnativecalls--;
1158
1170
        suspend = false;
1159
1171
        if( ret == SQ_SUSPEND_FLAG) suspend = true;
1496
1508
        }
1497
1509
}
1498
1510
 
1499
 
void SQVM::Push(const SQObjectPtr &o) { _stack[_top++] = o; }
 
1511
void SQVM::Push(const SQObjectPtr &o) {
 
1512
        /* Normally the stack shouldn't get this full, sometimes it might. As of now
 
1513
         * all cases have been bugs in "our" (OpenTTD) code. Trigger an assert for
 
1514
         * all debug builds and for the release builds just increase the stack size.
 
1515
         * This way getting a false positive isn't that bad (releases work fine) and
 
1516
         * if there is something fishy it can be caught in RCs/nightlies. */
 
1517
#ifdef NDEBUG
 
1518
        if (_top >= (int)_stack.capacity()) _stack.resize(2 * _stack.capacity());
 
1519
#else
 
1520
        assert(_top < (int)_stack.capacity());
 
1521
#endif
 
1522
        _stack[_top++] = o;
 
1523
}
1500
1524
SQObjectPtr &SQVM::Top() { return _stack[_top-1]; }
1501
1525
SQObjectPtr &SQVM::PopGet() { return _stack[--_top]; }
1502
1526
SQObjectPtr &SQVM::GetUp(SQInteger n) { return _stack[_top+n]; }