]> icculus.org git repositories - divverent/darkplaces.git/blob - prvm_execprogram.h
experimental change: do a float compare for OP_IF and OP_IFNOT, so negative
[divverent/darkplaces.git] / prvm_execprogram.h
1
2 // This code isn't #ifdef/#define protectable, don't try.
3
4                 while (1)
5                 {
6                         st++;
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);
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);
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
310                                 newf = &prog->functions[OPA->function];
311                                 newf->callcount++;
312
313                                 if (newf->first_statement < 0)
314                                 {
315                                         // negative statements are built in functions
316                                         int builtinnumber = -newf->first_statement;
317                                         prog->xfunction->builtinsprofile++;
318                                         if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
319                                                 prog->builtins[builtinnumber]();
320                                         else
321                                                 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
322                                 }
323                                 else
324                                         st = prog->statements + PRVM_EnterFunction(newf);
325                                 startst = st;
326                                 break;
327
328                         case OP_DONE:
329                         case OP_RETURN:
330                                 prog->xfunction->profile += (st - startst);
331                                 prog->xstatement = st - prog->statements;
332
333                                 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
334                                 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
335                                 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
336
337                                 st = prog->statements + PRVM_LeaveFunction();
338                                 startst = st;
339                                 if (prog->depth <= exitdepth)
340                                         goto cleanup; // all done
341                                 if (prog->trace != cachedpr_trace)
342                                         goto chooseexecprogram;
343                                 break;
344
345                         case OP_STATE:
346                                 if(prog->flag & PRVM_OP_STATE)
347                                 {
348                                         ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
349                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
350                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
351                                         PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
352                                 }
353                                 else
354                                 {
355                                         prog->xfunction->profile += (st - startst);
356                                         prog->xstatement = st - prog->statements;
357                                         PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
358                                 }
359                                 break;
360
361 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
362 /*
363                         case OP_ADD_I:
364                                 OPC->_int = OPA->_int + OPB->_int;
365                                 break;
366                         case OP_ADD_IF:
367                                 OPC->_int = OPA->_int + (int) OPB->_float;
368                                 break;
369                         case OP_ADD_FI:
370                                 OPC->_float = OPA->_float + (float) OPB->_int;
371                                 break;
372                         case OP_SUB_I:
373                                 OPC->_int = OPA->_int - OPB->_int;
374                                 break;
375                         case OP_SUB_IF:
376                                 OPC->_int = OPA->_int - (int) OPB->_float;
377                                 break;
378                         case OP_SUB_FI:
379                                 OPC->_float = OPA->_float - (float) OPB->_int;
380                                 break;
381                         case OP_MUL_I:
382                                 OPC->_int = OPA->_int * OPB->_int;
383                                 break;
384                         case OP_MUL_IF:
385                                 OPC->_int = OPA->_int * (int) OPB->_float;
386                                 break;
387                         case OP_MUL_FI:
388                                 OPC->_float = OPA->_float * (float) OPB->_int;
389                                 break;
390                         case OP_MUL_VI:
391                                 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
392                                 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
393                                 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
394                                 break;
395                         case OP_DIV_VF:
396                                 {
397                                         float temp = 1.0f / OPB->_float;
398                                         OPC->vector[0] = temp * OPA->vector[0];
399                                         OPC->vector[1] = temp * OPA->vector[1];
400                                         OPC->vector[2] = temp * OPA->vector[2];
401                                 }
402                                 break;
403                         case OP_DIV_I:
404                                 OPC->_int = OPA->_int / OPB->_int;
405                                 break;
406                         case OP_DIV_IF:
407                                 OPC->_int = OPA->_int / (int) OPB->_float;
408                                 break;
409                         case OP_DIV_FI:
410                                 OPC->_float = OPA->_float / (float) OPB->_int;
411                                 break;
412                         case OP_CONV_IF:
413                                 OPC->_float = OPA->_int;
414                                 break;
415                         case OP_CONV_FI:
416                                 OPC->_int = OPA->_float;
417                                 break;
418                         case OP_BITAND_I:
419                                 OPC->_int = OPA->_int & OPB->_int;
420                                 break;
421                         case OP_BITOR_I:
422                                 OPC->_int = OPA->_int | OPB->_int;
423                                 break;
424                         case OP_BITAND_IF:
425                                 OPC->_int = OPA->_int & (int)OPB->_float;
426                                 break;
427                         case OP_BITOR_IF:
428                                 OPC->_int = OPA->_int | (int)OPB->_float;
429                                 break;
430                         case OP_BITAND_FI:
431                                 OPC->_float = (int)OPA->_float & OPB->_int;
432                                 break;
433                         case OP_BITOR_FI:
434                                 OPC->_float = (int)OPA->_float | OPB->_int;
435                                 break;
436                         case OP_GE_I:
437                                 OPC->_float = OPA->_int >= OPB->_int;
438                                 break;
439                         case OP_LE_I:
440                                 OPC->_float = OPA->_int <= OPB->_int;
441                                 break;
442                         case OP_GT_I:
443                                 OPC->_float = OPA->_int > OPB->_int;
444                                 break;
445                         case OP_LT_I:
446                                 OPC->_float = OPA->_int < OPB->_int;
447                                 break;
448                         case OP_AND_I:
449                                 OPC->_float = OPA->_int && OPB->_int;
450                                 break;
451                         case OP_OR_I:
452                                 OPC->_float = OPA->_int || OPB->_int;
453                                 break;
454                         case OP_GE_IF:
455                                 OPC->_float = (float)OPA->_int >= OPB->_float;
456                                 break;
457                         case OP_LE_IF:
458                                 OPC->_float = (float)OPA->_int <= OPB->_float;
459                                 break;
460                         case OP_GT_IF:
461                                 OPC->_float = (float)OPA->_int > OPB->_float;
462                                 break;
463                         case OP_LT_IF:
464                                 OPC->_float = (float)OPA->_int < OPB->_float;
465                                 break;
466                         case OP_AND_IF:
467                                 OPC->_float = (float)OPA->_int && OPB->_float;
468                                 break;
469                         case OP_OR_IF:
470                                 OPC->_float = (float)OPA->_int || OPB->_float;
471                                 break;
472                         case OP_GE_FI:
473                                 OPC->_float = OPA->_float >= (float)OPB->_int;
474                                 break;
475                         case OP_LE_FI:
476                                 OPC->_float = OPA->_float <= (float)OPB->_int;
477                                 break;
478                         case OP_GT_FI:
479                                 OPC->_float = OPA->_float > (float)OPB->_int;
480                                 break;
481                         case OP_LT_FI:
482                                 OPC->_float = OPA->_float < (float)OPB->_int;
483                                 break;
484                         case OP_AND_FI:
485                                 OPC->_float = OPA->_float && (float)OPB->_int;
486                                 break;
487                         case OP_OR_FI:
488                                 OPC->_float = OPA->_float || (float)OPB->_int;
489                                 break;
490                         case OP_NOT_I:
491                                 OPC->_float = !OPA->_int;
492                                 break;
493                         case OP_EQ_I:
494                                 OPC->_float = OPA->_int == OPB->_int;
495                                 break;
496                         case OP_EQ_IF:
497                                 OPC->_float = (float)OPA->_int == OPB->_float;
498                                 break;
499                         case OP_EQ_FI:
500                                 OPC->_float = OPA->_float == (float)OPB->_int;
501                                 break;
502                         case OP_NE_I:
503                                 OPC->_float = OPA->_int != OPB->_int;
504                                 break;
505                         case OP_NE_IF:
506                                 OPC->_float = (float)OPA->_int != OPB->_float;
507                                 break;
508                         case OP_NE_FI:
509                                 OPC->_float = OPA->_float != (float)OPB->_int;
510                                 break;
511                         case OP_STORE_I:
512                                 OPB->_int = OPA->_int;
513                                 break;
514                         case OP_STOREP_I:
515 #if PRBOUNDSCHECK
516                                 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
517                                 {
518                                         prog->xfunction->profile += (st - startst);
519                                         prog->xstatement = st - prog->statements;
520                                         PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
521                                         goto cleanup;
522                                 }
523 #endif
524                                 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
525                                 ptr->_int = OPA->_int;
526                                 break;
527                         case OP_LOAD_I:
528 #if PRBOUNDSCHECK
529                                 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
530                                 {
531                                         prog->xfunction->profile += (st - startst);
532                                         prog->xstatement = st - prog->statements;
533                                         PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
534                                         goto cleanup;
535                                 }
536                                 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
537                                 {
538                                         prog->xfunction->profile += (st - startst);
539                                         prog->xstatement = st - prog->statements;
540                                         PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
541                                         goto cleanup;
542                                 }
543 #endif
544                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
545                                 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
546                                 break;
547
548                         case OP_GSTOREP_I:
549                         case OP_GSTOREP_F:
550                         case OP_GSTOREP_ENT:
551                         case OP_GSTOREP_FLD:            // integers
552                         case OP_GSTOREP_S:
553                         case OP_GSTOREP_FNC:            // pointers
554 #if PRBOUNDSCHECK
555                                 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
556                                 {
557                                         prog->xfunction->profile += (st - startst);
558                                         prog->xstatement = st - prog->statements;
559                                         PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
560                                         goto cleanup;
561                                 }
562 #endif
563                                 pr_iglobals[OPB->_int] = OPA->_int;
564                                 break;
565                         case OP_GSTOREP_V:
566 #if PRBOUNDSCHECK
567                                 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
568                                 {
569                                         prog->xfunction->profile += (st - startst);
570                                         prog->xstatement = st - prog->statements;
571                                         PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
572                                         goto cleanup;
573                                 }
574 #endif
575                                 pr_iglobals[OPB->_int  ] = OPA->ivector[0];
576                                 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
577                                 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
578                                 break;
579
580                         case OP_GADDRESS:
581                                 i = OPA->_int + (int) OPB->_float;
582 #if PRBOUNDSCHECK
583                                 if (i < 0 || i >= pr_globaldefs)
584                                 {
585                                         prog->xfunction->profile += (st - startst);
586                                         prog->xstatement = st - prog->statements;
587                                         PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
588                                         goto cleanup;
589                                 }
590 #endif
591                                 OPC->_int = pr_iglobals[i];
592                                 break;
593
594                         case OP_GLOAD_I:
595                         case OP_GLOAD_F:
596                         case OP_GLOAD_FLD:
597                         case OP_GLOAD_ENT:
598                         case OP_GLOAD_S:
599                         case OP_GLOAD_FNC:
600 #if PRBOUNDSCHECK
601                                 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
602                                 {
603                                         prog->xfunction->profile += (st - startst);
604                                         prog->xstatement = st - prog->statements;
605                                         PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
606                                         goto cleanup;
607                                 }
608 #endif
609                                 OPC->_int = pr_iglobals[OPA->_int];
610                                 break;
611
612                         case OP_GLOAD_V:
613 #if PRBOUNDSCHECK
614                                 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
615                                 {
616                                         prog->xfunction->profile += (st - startst);
617                                         prog->xstatement = st - prog->statements;
618                                         PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
619                                         goto cleanup;
620                                 }
621 #endif
622                                 OPC->ivector[0] = pr_iglobals[OPA->_int  ];
623                                 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
624                                 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
625                                 break;
626
627                         case OP_BOUNDCHECK:
628                                 if (OPA->_int < 0 || OPA->_int >= st->b)
629                                 {
630                                         prog->xfunction->profile += (st - startst);
631                                         prog->xstatement = st - prog->statements;
632                                         PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
633                                         goto cleanup;
634                                 }
635                                 break;
636
637 */
638
639                         default:
640                                 prog->xfunction->profile += (st - startst);
641                                 prog->xstatement = st - prog->statements;
642                                 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);
643                                 goto cleanup;
644                         }
645                 }
646