2 // This code isn't #ifdef/#define protectable, don't try.
9 PRVM_PrintStatement(st);
11 #if PRVMSTATEMENTPROFILING
12 prog->statement_profile[st - prog->statements]++;
18 OPC->_float = OPA->_float + OPB->_float;
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];
26 OPC->_float = OPA->_float - OPB->_float;
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];
34 OPC->_float = OPA->_float * OPB->_float;
37 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
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];
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];
50 if( OPB->_float != 0.0f )
52 OPC->_float = OPA->_float / OPB->_float;
56 if( developer.integer >= 1 )
58 prog->xfunction->profile += (st - startst);
60 prog->xstatement = st - prog->statements;
61 VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
67 OPC->_float = (int)OPA->_float & (int)OPB->_float;
70 OPC->_float = (int)OPA->_float | (int)OPB->_float;
73 OPC->_float = OPA->_float >= OPB->_float;
76 OPC->_float = OPA->_float <= OPB->_float;
79 OPC->_float = OPA->_float > OPB->_float;
82 OPC->_float = OPA->_float < OPB->_float;
85 OPC->_float = OPA->_float && OPB->_float;
88 OPC->_float = OPA->_float || OPB->_float;
91 OPC->_float = !OPA->_float;
94 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
97 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
100 OPC->_float = !OPA->function;
103 OPC->_float = (OPA->edict == 0);
106 OPC->_float = OPA->_float == OPB->_float;
109 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
112 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
115 OPC->_float = OPA->_int == OPB->_int;
118 OPC->_float = OPA->function == OPB->function;
121 OPC->_float = OPA->_float != OPB->_float;
124 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
127 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
130 OPC->_float = OPA->_int != OPB->_int;
133 OPC->_float = OPA->function != OPB->function;
139 case OP_STORE_FLD: // integers
141 case OP_STORE_FNC: // pointers
142 OPB->_int = OPA->_int;
145 OPB->ivector[0] = OPA->ivector[0];
146 OPB->ivector[1] = OPA->ivector[1];
147 OPB->ivector[2] = OPA->ivector[2];
152 case OP_STOREP_FLD: // integers
154 case OP_STOREP_FNC: // pointers
156 if (OPB->_int < 0 || OPB->_int + 4 > prog->edictareasize)
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);
164 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
165 ptr->_int = OPA->_int;
169 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
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);
177 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
178 ptr->vector[0] = OPA->vector[0];
179 ptr->vector[1] = OPA->vector[1];
180 ptr->vector[2] = OPA->vector[2];
185 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
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);
193 if (OPA->edict == 0 && !prog->allowworldwrites)
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);
200 ed = PRVM_PROG_TO_EDICT(OPA->edict);
201 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
210 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
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);
218 ed = PRVM_PROG_TO_EDICT(OPA->edict);
219 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
224 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
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);
232 ed = PRVM_PROG_TO_EDICT(OPA->edict);
233 OPC->vector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[0];
234 OPC->vector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[1];
235 OPC->vector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[2];
243 prog->xfunction->profile += (st - startst);
244 st += st->b - 1; // offset the s++
246 if (++jumpcount == 10000000)
248 prog->xstatement = st - prog->statements;
249 PRVM_Profile(1<<30, 1000000);
250 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
258 prog->xfunction->profile += (st - startst);
259 st += st->b - 1; // offset the s++
261 if (++jumpcount == 10000000)
263 prog->xstatement = st - prog->statements;
264 PRVM_Profile(1<<30, 1000000);
265 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
271 prog->xfunction->profile += (st - startst);
272 st += st->a - 1; // offset the s++
274 if (++jumpcount == 10000000)
276 prog->xstatement = st - prog->statements;
277 PRVM_Profile(1<<30, 1000000);
278 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
291 prog->xfunction->profile += (st - startst);
293 prog->xstatement = st - prog->statements;
294 prog->argc = st->op - OP_CALL0;
296 PRVM_ERROR("NULL function in %s", PRVM_NAME);
298 newf = &prog->functions[OPA->function];
301 if (newf->first_statement < 0)
303 // negative statements are built in functions
304 int builtinnumber = -newf->first_statement;
305 prog->xfunction->builtinsprofile++;
306 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
307 prog->builtins[builtinnumber]();
309 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
312 st = prog->statements + PRVM_EnterFunction(newf);
318 prog->xfunction->profile += (st - startst);
319 prog->xstatement = st - prog->statements;
321 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
322 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
323 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
325 st = prog->statements + PRVM_LeaveFunction();
327 if (prog->depth <= exitdepth)
328 goto cleanup; // all done
329 if (prog->trace != cachedpr_trace)
330 goto chooseexecprogram;
334 if(prog->flag & PRVM_OP_STATE)
336 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
337 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
338 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
339 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
343 prog->xfunction->profile += (st - startst);
344 prog->xstatement = st - prog->statements;
345 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
349 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
352 OPC->_int = OPA->_int + OPB->_int;
355 OPC->_int = OPA->_int + (int) OPB->_float;
358 OPC->_float = OPA->_float + (float) OPB->_int;
361 OPC->_int = OPA->_int - OPB->_int;
364 OPC->_int = OPA->_int - (int) OPB->_float;
367 OPC->_float = OPA->_float - (float) OPB->_int;
370 OPC->_int = OPA->_int * OPB->_int;
373 OPC->_int = OPA->_int * (int) OPB->_float;
376 OPC->_float = OPA->_float * (float) OPB->_int;
379 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
380 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
381 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
385 float temp = 1.0f / OPB->_float;
386 OPC->vector[0] = temp * OPA->vector[0];
387 OPC->vector[1] = temp * OPA->vector[1];
388 OPC->vector[2] = temp * OPA->vector[2];
392 OPC->_int = OPA->_int / OPB->_int;
395 OPC->_int = OPA->_int / (int) OPB->_float;
398 OPC->_float = OPA->_float / (float) OPB->_int;
401 OPC->_float = OPA->_int;
404 OPC->_int = OPA->_float;
407 OPC->_int = OPA->_int & OPB->_int;
410 OPC->_int = OPA->_int | OPB->_int;
413 OPC->_int = OPA->_int & (int)OPB->_float;
416 OPC->_int = OPA->_int | (int)OPB->_float;
419 OPC->_float = (int)OPA->_float & OPB->_int;
422 OPC->_float = (int)OPA->_float | OPB->_int;
425 OPC->_float = OPA->_int >= OPB->_int;
428 OPC->_float = OPA->_int <= OPB->_int;
431 OPC->_float = OPA->_int > OPB->_int;
434 OPC->_float = OPA->_int < OPB->_int;
437 OPC->_float = OPA->_int && OPB->_int;
440 OPC->_float = OPA->_int || OPB->_int;
443 OPC->_float = (float)OPA->_int >= OPB->_float;
446 OPC->_float = (float)OPA->_int <= OPB->_float;
449 OPC->_float = (float)OPA->_int > OPB->_float;
452 OPC->_float = (float)OPA->_int < OPB->_float;
455 OPC->_float = (float)OPA->_int && OPB->_float;
458 OPC->_float = (float)OPA->_int || OPB->_float;
461 OPC->_float = OPA->_float >= (float)OPB->_int;
464 OPC->_float = OPA->_float <= (float)OPB->_int;
467 OPC->_float = OPA->_float > (float)OPB->_int;
470 OPC->_float = OPA->_float < (float)OPB->_int;
473 OPC->_float = OPA->_float && (float)OPB->_int;
476 OPC->_float = OPA->_float || (float)OPB->_int;
479 OPC->_float = !OPA->_int;
482 OPC->_float = OPA->_int == OPB->_int;
485 OPC->_float = (float)OPA->_int == OPB->_float;
488 OPC->_float = OPA->_float == (float)OPB->_int;
491 OPC->_float = OPA->_int != OPB->_int;
494 OPC->_float = (float)OPA->_int != OPB->_float;
497 OPC->_float = OPA->_float != (float)OPB->_int;
500 OPB->_int = OPA->_int;
504 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
506 prog->xfunction->profile += (st - startst);
507 prog->xstatement = st - prog->statements;
508 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
512 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
513 ptr->_int = OPA->_int;
517 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
519 prog->xfunction->profile += (st - startst);
520 prog->xstatement = st - prog->statements;
521 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
524 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
526 prog->xfunction->profile += (st - startst);
527 prog->xstatement = st - prog->statements;
528 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
532 ed = PRVM_PROG_TO_EDICT(OPA->edict);
533 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
539 case OP_GSTOREP_FLD: // integers
541 case OP_GSTOREP_FNC: // pointers
543 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
545 prog->xfunction->profile += (st - startst);
546 prog->xstatement = st - prog->statements;
547 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
551 pr_globals[OPB->_int] = OPA->_float;
555 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
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);
563 pr_globals[OPB->_int ] = OPA->vector[0];
564 pr_globals[OPB->_int+1] = OPA->vector[1];
565 pr_globals[OPB->_int+2] = OPA->vector[2];
569 i = OPA->_int + (int) OPB->_float;
571 if (i < 0 || i >= pr_globaldefs)
573 prog->xfunction->profile += (st - startst);
574 prog->xstatement = st - prog->statements;
575 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
579 OPC->_float = pr_globals[i];
589 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
591 prog->xfunction->profile += (st - startst);
592 prog->xstatement = st - prog->statements;
593 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
597 OPC->_float = pr_globals[OPA->_int];
602 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
604 prog->xfunction->profile += (st - startst);
605 prog->xstatement = st - prog->statements;
606 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
610 OPC->vector[0] = pr_globals[OPA->_int ];
611 OPC->vector[1] = pr_globals[OPA->_int+1];
612 OPC->vector[2] = pr_globals[OPA->_int+2];
616 if (OPA->_int < 0 || OPA->_int >= st->b)
618 prog->xfunction->profile += (st - startst);
619 prog->xstatement = st - prog->statements;
620 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
628 prog->xfunction->profile += (st - startst);
629 prog->xstatement = st - prog->statements;
630 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);