fix div0's bug
[xonotic/darkplaces.git] / prvm_execprogram.h
1
2 // This code isn't #ifdef/#define protectable, don't try.
3
4                 while (1)
5                 {
6                         st++; // TODO bounds check
7
8 #if PRVMTRACE
9                         PRVM_PrintStatement(st);
10 #endif
11 #if PRVMSTATEMENTPROFILING
12                         prog->statement_profile[st - prog->statements]++;
13 #endif
14
15                         switch (st->op)
16                         {
17                         case OP_ADD_F:
18                                 OPC->_float = OPA->_float + OPB->_float;
19                                 break;
20                         case OP_ADD_V:
21                                 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
22                                 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
23                                 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
24                                 break;
25                         case OP_SUB_F:
26                                 OPC->_float = OPA->_float - OPB->_float;
27                                 break;
28                         case OP_SUB_V:
29                                 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
30                                 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
31                                 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
32                                 break;
33                         case OP_MUL_F:
34                                 OPC->_float = OPA->_float * OPB->_float;
35                                 break;
36                         case OP_MUL_V:
37                                 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
38                                 break;
39                         case OP_MUL_FV:
40                                 OPC->vector[0] = OPA->_float * OPB->vector[0];
41                                 OPC->vector[1] = OPA->_float * OPB->vector[1];
42                                 OPC->vector[2] = OPA->_float * OPB->vector[2];
43                                 break;
44                         case OP_MUL_VF:
45                                 OPC->vector[0] = OPB->_float * OPA->vector[0];
46                                 OPC->vector[1] = OPB->_float * OPA->vector[1];
47                                 OPC->vector[2] = OPB->_float * OPA->vector[2];
48                                 break;
49                         case OP_DIV_F:
50                                 if( OPB->_float != 0.0f )
51                                 {
52                                         OPC->_float = OPA->_float / OPB->_float;
53                                 }
54                                 else
55                                 {
56                                         if( developer.integer >= 1 )
57                                         {
58                                                 prog->xfunction->profile += (st - startst);
59                                                 startst = st;
60                                                 prog->xstatement = st - prog->statements;
61                                                 VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
62                                         }
63                                         OPC->_float = 0.0f;
64                                 }
65                                 break;
66                         case OP_BITAND:
67                                 OPC->_float = (int)OPA->_float & (int)OPB->_float;
68                                 break;
69                         case OP_BITOR:
70                                 OPC->_float = (int)OPA->_float | (int)OPB->_float;
71                                 break;
72                         case OP_GE:
73                                 OPC->_float = OPA->_float >= OPB->_float;
74                                 break;
75                         case OP_LE:
76                                 OPC->_float = OPA->_float <= OPB->_float;
77                                 break;
78                         case OP_GT:
79                                 OPC->_float = OPA->_float > OPB->_float;
80                                 break;
81                         case OP_LT:
82                                 OPC->_float = OPA->_float < OPB->_float;
83                                 break;
84                         case OP_AND:
85                                 OPC->_float = OPA->_float && OPB->_float;
86                                 break;
87                         case OP_OR:
88                                 OPC->_float = OPA->_float || OPB->_float;
89                                 break;
90                         case OP_NOT_F:
91                                 OPC->_float = !OPA->_float;
92                                 break;
93                         case OP_NOT_V:
94                                 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
95                                 break;
96                         case OP_NOT_S:
97                                 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
98                                 break;
99                         case OP_NOT_FNC:
100                                 OPC->_float = !OPA->function;
101                                 break;
102                         case OP_NOT_ENT:
103                                 OPC->_float = (OPA->edict == 0);
104                                 break;
105                         case OP_EQ_F:
106                                 OPC->_float = OPA->_float == OPB->_float;
107                                 break;
108                         case OP_EQ_V:
109                                 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
110                                 break;
111                         case OP_EQ_S:
112                                 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
113                                 break;
114                         case OP_EQ_E:
115                                 OPC->_float = OPA->_int == OPB->_int;
116                                 break;
117                         case OP_EQ_FNC:
118                                 OPC->_float = OPA->function == OPB->function;
119                                 break;
120                         case OP_NE_F:
121                                 OPC->_float = OPA->_float != OPB->_float;
122                                 break;
123                         case OP_NE_V:
124                                 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
125                                 break;
126                         case OP_NE_S:
127                                 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
128                                 break;
129                         case OP_NE_E:
130                                 OPC->_float = OPA->_int != OPB->_int;
131                                 break;
132                         case OP_NE_FNC:
133                                 OPC->_float = OPA->function != OPB->function;
134                                 break;
135
136                 //==================
137                         case OP_STORE_F:
138                         case OP_STORE_ENT:
139                         case OP_STORE_FLD:              // integers
140                         case OP_STORE_S:
141                         case OP_STORE_FNC:              // pointers
142                                 OPB->_int = OPA->_int;
143                                 break;
144                         case OP_STORE_V:
145                                 OPB->ivector[0] = OPA->ivector[0];
146                                 OPB->ivector[1] = OPA->ivector[1];
147                                 OPB->ivector[2] = OPA->ivector[2];
148                                 break;
149
150                         case OP_STOREP_F:
151                         case OP_STOREP_ENT:
152                         case OP_STOREP_FLD:             // integers
153                         case OP_STOREP_S:
154                         case OP_STOREP_FNC:             // pointers
155 #if PRVMBOUNDSCHECK
156                                 if (OPB->_int < 0 || OPB->_int + 4 > prog->edictareasize)
157                                 {
158                                         prog->xfunction->profile += (st - startst);
159                                         prog->xstatement = st - prog->statements;
160                                         PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
161                                         goto cleanup;
162                                 }
163 #endif
164                                 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
165                                 ptr->_int = OPA->_int;
166                                 break;
167                         case OP_STOREP_V:
168 #if PRVMBOUNDSCHECK
169                                 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
170                                 {
171                                         prog->xfunction->profile += (st - startst);
172                                         prog->xstatement = st - prog->statements;
173                                         PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
174                                         goto cleanup;
175                                 }
176 #endif
177                                 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
178                                 ptr->ivector[0] = OPA->ivector[0];
179                                 ptr->ivector[1] = OPA->ivector[1];
180                                 ptr->ivector[2] = OPA->ivector[2];
181                                 break;
182
183                         case OP_ADDRESS:
184 #if PRVMBOUNDSCHECK
185                                 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
186                                 {
187                                         prog->xfunction->profile += (st - startst);
188                                         prog->xstatement = st - prog->statements;
189                                         PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
190                                         goto cleanup;
191                                 }
192 #endif
193                                 if (OPA->edict == 0 && !prog->allowworldwrites)
194                                 {
195                                         prog->xfunction->profile += (st - startst);
196                                         prog->xstatement = st - prog->statements;
197                                         PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
198                                         goto cleanup;
199                                 }
200                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
201                                 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
202                                 break;
203
204                         case OP_LOAD_F:
205                         case OP_LOAD_FLD:
206                         case OP_LOAD_ENT:
207                         case OP_LOAD_S:
208                         case OP_LOAD_FNC:
209 #if PRVMBOUNDSCHECK
210                                 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
211                                 {
212                                         prog->xfunction->profile += (st - startst);
213                                         prog->xstatement = st - prog->statements;
214                                         PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
215                                         goto cleanup;
216                                 }
217 #endif
218                                 ed = PRVM_PROG_TO_EDICT(OPA->edict); // TODO bounds check entity number
219                                 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
220                                 break;
221
222                         case OP_LOAD_V:
223 #if PRVMBOUNDSCHECK
224                                 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
225                                 {
226                                         prog->xfunction->profile += (st - startst);
227                                         prog->xstatement = st - prog->statements;
228                                         PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
229                                         goto cleanup;
230                                 }
231 #endif
232                                 ed = PRVM_PROG_TO_EDICT(OPA->edict); // TODO bounds check entity number
233                                 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
234                                 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
235                                 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
236                                 break;
237
238                 //==================
239
240                         case OP_IFNOT:
241                                 if (!OPA->_float)
242                                 // TODO add an "int-ifnot"
243                                 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
244                                 // and entity, string, field values can never have that value
245                                 {
246                                         prog->xfunction->profile += (st - startst);
247                                         st += st->b - 1;        // offset the s++
248                                         startst = st;
249 #if PRVMRUNAWAYCHECK
250                                         if (++jumpcount == 10000000)
251                                         {
252                                                 prog->xstatement = st - prog->statements;
253                                                 PRVM_Profile(1<<30, 1000000);
254                                                 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
255                                         }
256 #endif
257                                 }
258                                 break;
259
260                         case OP_IF:
261                                 if (OPA->_float)
262                                 // TODO add an "int-if"
263                                 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
264                                 // and entity, string, field values can never have that value
265                                 {
266                                         prog->xfunction->profile += (st - startst);
267                                         st += st->b - 1;        // offset the s++
268                                         startst = st;
269 #if PRVMRUNAWAYCHECK
270                                         if (++jumpcount == 10000000)
271                                         {
272                                                 prog->xstatement = st - prog->statements;
273                                                 PRVM_Profile(1<<30, 1000000);
274                                                 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
275                                         }
276 #endif
277                                 }
278                                 break;
279
280                         case OP_GOTO:
281                                 prog->xfunction->profile += (st - startst);
282                                 st += st->a - 1;        // offset the s++
283                                 startst = st;
284 #if PRVMRUNAWAYCHECK
285                                 if (++jumpcount == 10000000)
286                                 {
287                                         prog->xstatement = st - prog->statements;
288                                         PRVM_Profile(1<<30, 1000000);
289                                         PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
290                                 }
291 #endif
292                                 break;
293
294                         case OP_CALL0:
295                         case OP_CALL1:
296                         case OP_CALL2:
297                         case OP_CALL3:
298                         case OP_CALL4:
299                         case OP_CALL5:
300                         case OP_CALL6:
301                         case OP_CALL7:
302                         case OP_CALL8:
303                                 prog->xfunction->profile += (st - startst);
304                                 startst = st;
305                                 prog->xstatement = st - prog->statements;
306                                 prog->argc = st->op - OP_CALL0;
307                                 if (!OPA->function)
308                                         PRVM_ERROR("NULL function in %s", PRVM_NAME);
309                                 newf = &prog->functions[OPA->function]; // TODO bounds check function
310                                 newf->callcount++;
311
312                                 if (newf->first_statement < 0)
313                                 {
314                                         // negative statements are built in functions
315                                         int builtinnumber = -newf->first_statement;
316                                         prog->xfunction->builtinsprofile++;
317                                         if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
318                                                 prog->builtins[builtinnumber]();
319                                         else
320                                                 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
321                                 }
322                                 else
323                                         st = prog->statements + PRVM_EnterFunction(newf);
324                                 startst = st;
325                                 break;
326
327                         case OP_DONE:
328                         case OP_RETURN:
329                                 prog->xfunction->profile += (st - startst);
330                                 prog->xstatement = st - prog->statements;
331
332                                 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
333                                 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
334                                 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
335
336                                 st = prog->statements + PRVM_LeaveFunction();
337                                 startst = st;
338                                 if (prog->depth <= exitdepth)
339                                         goto cleanup; // all done
340                                 if (prog->trace != cachedpr_trace)
341                                         goto chooseexecprogram;
342                                 break;
343
344                         case OP_STATE:
345                                 if(prog->flag & PRVM_OP_STATE)
346                                 {
347                                         ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
348                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
349                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
350                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
351                                 }
352                                 else
353                                 {
354                                         prog->xfunction->profile += (st - startst);
355                                         prog->xstatement = st - prog->statements;
356                                         PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
357                                 }
358                                 break;
359
360 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
361 /*
362                         case OP_ADD_I:
363                                 OPC->_int = OPA->_int + OPB->_int;
364                                 break;
365                         case OP_ADD_IF:
366                                 OPC->_int = OPA->_int + (int) OPB->_float;
367                                 break;
368                         case OP_ADD_FI:
369                                 OPC->_float = OPA->_float + (float) OPB->_int;
370                                 break;
371                         case OP_SUB_I:
372                                 OPC->_int = OPA->_int - OPB->_int;
373                                 break;
374                         case OP_SUB_IF:
375                                 OPC->_int = OPA->_int - (int) OPB->_float;
376                                 break;
377                         case OP_SUB_FI:
378                                 OPC->_float = OPA->_float - (float) OPB->_int;
379                                 break;
380                         case OP_MUL_I:
381                                 OPC->_int = OPA->_int * OPB->_int;
382                                 break;
383                         case OP_MUL_IF:
384                                 OPC->_int = OPA->_int * (int) OPB->_float;
385                                 break;
386                         case OP_MUL_FI:
387                                 OPC->_float = OPA->_float * (float) OPB->_int;
388                                 break;
389                         case OP_MUL_VI:
390                                 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
391                                 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
392                                 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
393                                 break;
394                         case OP_DIV_VF:
395                                 {
396                                         float temp = 1.0f / OPB->_float;
397                                         OPC->vector[0] = temp * OPA->vector[0];
398                                         OPC->vector[1] = temp * OPA->vector[1];
399                                         OPC->vector[2] = temp * OPA->vector[2];
400                                 }
401                                 break;
402                         case OP_DIV_I:
403                                 OPC->_int = OPA->_int / OPB->_int;
404                                 break;
405                         case OP_DIV_IF:
406                                 OPC->_int = OPA->_int / (int) OPB->_float;
407                                 break;
408                         case OP_DIV_FI:
409                                 OPC->_float = OPA->_float / (float) OPB->_int;
410                                 break;
411                         case OP_CONV_IF:
412                                 OPC->_float = OPA->_int;
413                                 break;
414                         case OP_CONV_FI:
415                                 OPC->_int = OPA->_float;
416                                 break;
417                         case OP_BITAND_I:
418                                 OPC->_int = OPA->_int & OPB->_int;
419                                 break;
420                         case OP_BITOR_I:
421                                 OPC->_int = OPA->_int | OPB->_int;
422                                 break;
423                         case OP_BITAND_IF:
424                                 OPC->_int = OPA->_int & (int)OPB->_float;
425                                 break;
426                         case OP_BITOR_IF:
427                                 OPC->_int = OPA->_int | (int)OPB->_float;
428                                 break;
429                         case OP_BITAND_FI:
430                                 OPC->_float = (int)OPA->_float & OPB->_int;
431                                 break;
432                         case OP_BITOR_FI:
433                                 OPC->_float = (int)OPA->_float | OPB->_int;
434                                 break;
435                         case OP_GE_I:
436                                 OPC->_float = OPA->_int >= OPB->_int;
437                                 break;
438                         case OP_LE_I:
439                                 OPC->_float = OPA->_int <= OPB->_int;
440                                 break;
441                         case OP_GT_I:
442                                 OPC->_float = OPA->_int > OPB->_int;
443                                 break;
444                         case OP_LT_I:
445                                 OPC->_float = OPA->_int < OPB->_int;
446                                 break;
447                         case OP_AND_I:
448                                 OPC->_float = OPA->_int && OPB->_int;
449                                 break;
450                         case OP_OR_I:
451                                 OPC->_float = OPA->_int || OPB->_int;
452                                 break;
453                         case OP_GE_IF:
454                                 OPC->_float = (float)OPA->_int >= OPB->_float;
455                                 break;
456                         case OP_LE_IF:
457                                 OPC->_float = (float)OPA->_int <= OPB->_float;
458                                 break;
459                         case OP_GT_IF:
460                                 OPC->_float = (float)OPA->_int > OPB->_float;
461                                 break;
462                         case OP_LT_IF:
463                                 OPC->_float = (float)OPA->_int < OPB->_float;
464                                 break;
465                         case OP_AND_IF:
466                                 OPC->_float = (float)OPA->_int && OPB->_float;
467                                 break;
468                         case OP_OR_IF:
469                                 OPC->_float = (float)OPA->_int || OPB->_float;
470                                 break;
471                         case OP_GE_FI:
472                                 OPC->_float = OPA->_float >= (float)OPB->_int;
473                                 break;
474                         case OP_LE_FI:
475                                 OPC->_float = OPA->_float <= (float)OPB->_int;
476                                 break;
477                         case OP_GT_FI:
478                                 OPC->_float = OPA->_float > (float)OPB->_int;
479                                 break;
480                         case OP_LT_FI:
481                                 OPC->_float = OPA->_float < (float)OPB->_int;
482                                 break;
483                         case OP_AND_FI:
484                                 OPC->_float = OPA->_float && (float)OPB->_int;
485                                 break;
486                         case OP_OR_FI:
487                                 OPC->_float = OPA->_float || (float)OPB->_int;
488                                 break;
489                         case OP_NOT_I:
490                                 OPC->_float = !OPA->_int;
491                                 break;
492                         case OP_EQ_I:
493                                 OPC->_float = OPA->_int == OPB->_int;
494                                 break;
495                         case OP_EQ_IF:
496                                 OPC->_float = (float)OPA->_int == OPB->_float;
497                                 break;
498                         case OP_EQ_FI:
499                                 OPC->_float = OPA->_float == (float)OPB->_int;
500                                 break;
501                         case OP_NE_I:
502                                 OPC->_float = OPA->_int != OPB->_int;
503                                 break;
504                         case OP_NE_IF:
505                                 OPC->_float = (float)OPA->_int != OPB->_float;
506                                 break;
507                         case OP_NE_FI:
508                                 OPC->_float = OPA->_float != (float)OPB->_int;
509                                 break;
510                         case OP_STORE_I:
511                                 OPB->_int = OPA->_int;
512                                 break;
513                         case OP_STOREP_I:
514 #if PRBOUNDSCHECK
515                                 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
516                                 {
517                                         prog->xfunction->profile += (st - startst);
518                                         prog->xstatement = st - prog->statements;
519                                         PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
520                                         goto cleanup;
521                                 }
522 #endif
523                                 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
524                                 ptr->_int = OPA->_int;
525                                 break;
526                         case OP_LOAD_I:
527 #if PRBOUNDSCHECK
528                                 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
529                                 {
530                                         prog->xfunction->profile += (st - startst);
531                                         prog->xstatement = st - prog->statements;
532                                         PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
533                                         goto cleanup;
534                                 }
535                                 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
536                                 {
537                                         prog->xfunction->profile += (st - startst);
538                                         prog->xstatement = st - prog->statements;
539                                         PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
540                                         goto cleanup;
541                                 }
542 #endif
543                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
544                                 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
545                                 break;
546
547                         case OP_GSTOREP_I:
548                         case OP_GSTOREP_F:
549                         case OP_GSTOREP_ENT:
550                         case OP_GSTOREP_FLD:            // integers
551                         case OP_GSTOREP_S:
552                         case OP_GSTOREP_FNC:            // pointers
553 #if PRBOUNDSCHECK
554                                 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
555                                 {
556                                         prog->xfunction->profile += (st - startst);
557                                         prog->xstatement = st - prog->statements;
558                                         PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
559                                         goto cleanup;
560                                 }
561 #endif
562                                 pr_iglobals[OPB->_int] = OPA->_int;
563                                 break;
564                         case OP_GSTOREP_V:
565 #if PRBOUNDSCHECK
566                                 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
567                                 {
568                                         prog->xfunction->profile += (st - startst);
569                                         prog->xstatement = st - prog->statements;
570                                         PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
571                                         goto cleanup;
572                                 }
573 #endif
574                                 pr_iglobals[OPB->_int  ] = OPA->ivector[0];
575                                 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
576                                 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
577                                 break;
578
579                         case OP_GADDRESS:
580                                 i = OPA->_int + (int) OPB->_float;
581 #if PRBOUNDSCHECK
582                                 if (i < 0 || i >= pr_globaldefs)
583                                 {
584                                         prog->xfunction->profile += (st - startst);
585                                         prog->xstatement = st - prog->statements;
586                                         PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
587                                         goto cleanup;
588                                 }
589 #endif
590                                 OPC->_int = pr_iglobals[i];
591                                 break;
592
593                         case OP_GLOAD_I:
594                         case OP_GLOAD_F:
595                         case OP_GLOAD_FLD:
596                         case OP_GLOAD_ENT:
597                         case OP_GLOAD_S:
598                         case OP_GLOAD_FNC:
599 #if PRBOUNDSCHECK
600                                 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
601                                 {
602                                         prog->xfunction->profile += (st - startst);
603                                         prog->xstatement = st - prog->statements;
604                                         PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
605                                         goto cleanup;
606                                 }
607 #endif
608                                 OPC->_int = pr_iglobals[OPA->_int];
609                                 break;
610
611                         case OP_GLOAD_V:
612 #if PRBOUNDSCHECK
613                                 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
614                                 {
615                                         prog->xfunction->profile += (st - startst);
616                                         prog->xstatement = st - prog->statements;
617                                         PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
618                                         goto cleanup;
619                                 }
620 #endif
621                                 OPC->ivector[0] = pr_iglobals[OPA->_int  ];
622                                 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
623                                 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
624                                 break;
625
626                         case OP_BOUNDCHECK:
627                                 if (OPA->_int < 0 || OPA->_int >= st->b)
628                                 {
629                                         prog->xfunction->profile += (st - startst);
630                                         prog->xstatement = st - prog->statements;
631                                         PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
632                                         goto cleanup;
633                                 }
634                                 break;
635
636 */
637
638                         default:
639                                 prog->xfunction->profile += (st - startst);
640                                 prog->xstatement = st - prog->statements;
641                                 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);
642                                 goto cleanup;
643                         }
644                 }
645