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 = FLOAT_IS_TRUE_FOR_INT(OPA->_int) && FLOAT_IS_TRUE_FOR_INT(OBA->_int); // TODO change this back to float, and add AND_I to be used by fteqcc for anything not a float
88 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) || FLOAT_IS_TRUE_FOR_INT(OBA->_int); // TODO change this back to float, and add OR_I to be used by fteqcc for anything not a float
91 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
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->ivector[0] = OPA->ivector[0];
179 ptr->ivector[1] = OPA->ivector[1];
180 ptr->ivector[2] = OPA->ivector[2];
185 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
187 prog->xfunction->profile += (st - startst);
188 prog->xstatement = st - prog->statements;
189 PRVM_ERROR ("%s Progs attempted to address an out of bounds edict number", PRVM_NAME);
192 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
194 prog->xfunction->profile += (st - startst);
195 prog->xstatement = st - prog->statements;
196 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
200 if (OPA->edict == 0 && !prog->allowworldwrites)
202 prog->xfunction->profile += (st - startst);
203 prog->xstatement = st - prog->statements;
204 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
207 ed = PRVM_PROG_TO_EDICT(OPA->edict);
208 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
217 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
219 prog->xfunction->profile += (st - startst);
220 prog->xstatement = st - prog->statements;
221 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
224 if ((unsigned int)(OPB->_int) >= (unsigned int)(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->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
238 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
240 prog->xfunction->profile += (st - startst);
241 prog->xstatement = st - prog->statements;
242 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
245 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
247 prog->xfunction->profile += (st - startst);
248 prog->xstatement = st - prog->statements;
249 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
253 ed = PRVM_PROG_TO_EDICT(OPA->edict);
254 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
255 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
256 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
262 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
263 // TODO add an "int-if", and change this one to OPA->_float
264 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
265 // and entity, string, field values can never have that value
267 prog->xfunction->profile += (st - startst);
268 st += st->b - 1; // offset the s++
270 // no bounds check needed, it is done when loading progs
272 if (++jumpcount == 10000000)
274 prog->xstatement = st - prog->statements;
275 PRVM_Profile(1<<30, 1000000);
276 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
283 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
284 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
285 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
286 // and entity, string, field values can never have that value
288 prog->xfunction->profile += (st - startst);
289 st += st->b - 1; // offset the s++
291 // no bounds check needed, it is done when loading progs
293 if (++jumpcount == 10000000)
295 prog->xstatement = st - prog->statements;
296 PRVM_Profile(1<<30, 1000000);
297 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
304 prog->xfunction->profile += (st - startst);
305 st += st->a - 1; // offset the s++
307 // no bounds check needed, it is done when loading progs
309 if (++jumpcount == 10000000)
311 prog->xstatement = st - prog->statements;
312 PRVM_Profile(1<<30, 1000000);
313 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
327 prog->xfunction->profile += (st - startst);
329 prog->xstatement = st - prog->statements;
330 prog->argc = st->op - OP_CALL0;
332 PRVM_ERROR("NULL function in %s", PRVM_NAME);
335 if(!OPA->function || OPA->function >= (unsigned int)prog->progs->numfunctions)
337 prog->xfunction->profile += (st - startst);
338 prog->xstatement = st - prog->statements; // we better stay on the previously executed statement
339 PRVM_ERROR("%s CALL outside the program", PRVM_NAME);
344 newf = &prog->functions[OPA->function];
347 if (newf->first_statement < 0)
349 // negative statements are built in functions
350 int builtinnumber = -newf->first_statement;
351 prog->xfunction->builtinsprofile++;
352 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
353 prog->builtins[builtinnumber]();
355 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
358 st = prog->statements + PRVM_EnterFunction(newf);
364 prog->xfunction->profile += (st - startst);
365 prog->xstatement = st - prog->statements;
367 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
368 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
369 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
371 st = prog->statements + PRVM_LeaveFunction();
373 if (prog->depth <= exitdepth)
374 goto cleanup; // all done
375 if (prog->trace != cachedpr_trace)
376 goto chooseexecprogram;
380 if(prog->flag & PRVM_OP_STATE)
382 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
383 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
384 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
385 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
389 prog->xfunction->profile += (st - startst);
390 prog->xstatement = st - prog->statements;
391 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
395 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
398 OPC->_int = OPA->_int + OPB->_int;
401 OPC->_int = OPA->_int + (int) OPB->_float;
404 OPC->_float = OPA->_float + (float) OPB->_int;
407 OPC->_int = OPA->_int - OPB->_int;
410 OPC->_int = OPA->_int - (int) OPB->_float;
413 OPC->_float = OPA->_float - (float) OPB->_int;
416 OPC->_int = OPA->_int * OPB->_int;
419 OPC->_int = OPA->_int * (int) OPB->_float;
422 OPC->_float = OPA->_float * (float) OPB->_int;
425 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
426 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
427 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
431 float temp = 1.0f / OPB->_float;
432 OPC->vector[0] = temp * OPA->vector[0];
433 OPC->vector[1] = temp * OPA->vector[1];
434 OPC->vector[2] = temp * OPA->vector[2];
438 OPC->_int = OPA->_int / OPB->_int;
441 OPC->_int = OPA->_int / (int) OPB->_float;
444 OPC->_float = OPA->_float / (float) OPB->_int;
447 OPC->_float = OPA->_int;
450 OPC->_int = OPA->_float;
453 OPC->_int = OPA->_int & OPB->_int;
456 OPC->_int = OPA->_int | OPB->_int;
459 OPC->_int = OPA->_int & (int)OPB->_float;
462 OPC->_int = OPA->_int | (int)OPB->_float;
465 OPC->_float = (int)OPA->_float & OPB->_int;
468 OPC->_float = (int)OPA->_float | OPB->_int;
471 OPC->_float = OPA->_int >= OPB->_int;
474 OPC->_float = OPA->_int <= OPB->_int;
477 OPC->_float = OPA->_int > OPB->_int;
480 OPC->_float = OPA->_int < OPB->_int;
483 OPC->_float = OPA->_int && OPB->_int;
486 OPC->_float = OPA->_int || OPB->_int;
489 OPC->_float = (float)OPA->_int >= OPB->_float;
492 OPC->_float = (float)OPA->_int <= OPB->_float;
495 OPC->_float = (float)OPA->_int > OPB->_float;
498 OPC->_float = (float)OPA->_int < OPB->_float;
501 OPC->_float = (float)OPA->_int && OPB->_float;
504 OPC->_float = (float)OPA->_int || OPB->_float;
507 OPC->_float = OPA->_float >= (float)OPB->_int;
510 OPC->_float = OPA->_float <= (float)OPB->_int;
513 OPC->_float = OPA->_float > (float)OPB->_int;
516 OPC->_float = OPA->_float < (float)OPB->_int;
519 OPC->_float = OPA->_float && (float)OPB->_int;
522 OPC->_float = OPA->_float || (float)OPB->_int;
525 OPC->_float = !OPA->_int;
528 OPC->_float = OPA->_int == OPB->_int;
531 OPC->_float = (float)OPA->_int == OPB->_float;
534 OPC->_float = OPA->_float == (float)OPB->_int;
537 OPC->_float = OPA->_int != OPB->_int;
540 OPC->_float = (float)OPA->_int != OPB->_float;
543 OPC->_float = OPA->_float != (float)OPB->_int;
546 OPB->_int = OPA->_int;
550 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
552 prog->xfunction->profile += (st - startst);
553 prog->xstatement = st - prog->statements;
554 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
558 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
559 ptr->_int = OPA->_int;
563 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
565 prog->xfunction->profile += (st - startst);
566 prog->xstatement = st - prog->statements;
567 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
570 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
572 prog->xfunction->profile += (st - startst);
573 prog->xstatement = st - prog->statements;
574 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
578 ed = PRVM_PROG_TO_EDICT(OPA->edict);
579 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
585 case OP_GSTOREP_FLD: // integers
587 case OP_GSTOREP_FNC: // pointers
589 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
591 prog->xfunction->profile += (st - startst);
592 prog->xstatement = st - prog->statements;
593 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
597 pr_iglobals[OPB->_int] = OPA->_int;
601 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
603 prog->xfunction->profile += (st - startst);
604 prog->xstatement = st - prog->statements;
605 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
609 pr_iglobals[OPB->_int ] = OPA->ivector[0];
610 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
611 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
615 i = OPA->_int + (int) OPB->_float;
617 if (i < 0 || i >= pr_globaldefs)
619 prog->xfunction->profile += (st - startst);
620 prog->xstatement = st - prog->statements;
621 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
625 OPC->_int = pr_iglobals[i];
635 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
637 prog->xfunction->profile += (st - startst);
638 prog->xstatement = st - prog->statements;
639 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
643 OPC->_int = pr_iglobals[OPA->_int];
648 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
650 prog->xfunction->profile += (st - startst);
651 prog->xstatement = st - prog->statements;
652 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
656 OPC->ivector[0] = pr_iglobals[OPA->_int ];
657 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
658 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
662 if (OPA->_int < 0 || OPA->_int >= st->b)
664 prog->xfunction->profile += (st - startst);
665 prog->xstatement = st - prog->statements;
666 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
674 prog->xfunction->profile += (st - startst);
675 prog->xstatement = st - prog->statements;
676 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);