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->ivector[0] = OPA->ivector[0];
179 ptr->ivector[1] = OPA->ivector[1];
180 ptr->ivector[2] = OPA->ivector[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 (OPA->edict < 0 || OPA->edict >= prog->edictareasize)
212 prog->xfunction->profile += (st - startst);
213 prog->xstatement = st - prog->statements;
214 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
217 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
219 prog->xfunction->profile += (st - startst);
220 prog->xstatement = st - prog->statements;
221 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
225 ed = PRVM_PROG_TO_EDICT(OPA->edict);
226 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
231 if (OPA->edict < 0 || OPA->edict >= prog->edictareasize)
233 prog->xfunction->profile += (st - startst);
234 prog->xstatement = st - prog->statements;
235 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
238 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
240 prog->xfunction->profile += (st - startst);
241 prog->xstatement = st - prog->statements;
242 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
246 ed = PRVM_PROG_TO_EDICT(OPA->edict);
247 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
248 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
249 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
256 // TODO add an "int-ifnot"
257 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
258 // and entity, string, field values can never have that value
260 prog->xfunction->profile += (st - startst);
261 st += st->b - 1; // offset the s++
263 // no bounds check needed, it is done when loading progs
265 if (++jumpcount == 10000000)
267 prog->xstatement = st - prog->statements;
268 PRVM_Profile(1<<30, 1000000);
269 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
277 // TODO add an "int-if"
278 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
279 // and entity, string, field values can never have that value
281 prog->xfunction->profile += (st - startst);
282 st += st->b - 1; // offset the s++
284 // no bounds check needed, it is done when loading progs
286 if (++jumpcount == 10000000)
288 prog->xstatement = st - prog->statements;
289 PRVM_Profile(1<<30, 1000000);
290 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
297 prog->xfunction->profile += (st - startst);
298 st += st->a - 1; // offset the s++
300 // no bounds check needed, it is done when loading progs
302 if (++jumpcount == 10000000)
304 prog->xstatement = st - prog->statements;
305 PRVM_Profile(1<<30, 1000000);
306 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
320 prog->xfunction->profile += (st - startst);
322 prog->xstatement = st - prog->statements;
323 prog->argc = st->op - OP_CALL0;
325 PRVM_ERROR("NULL function in %s", PRVM_NAME);
328 if(!OPA->function || OPA->function >= (unsigned int)prog->progs->numfunctions)
330 prog->xfunction->profile += (st - startst);
331 prog->xstatement = st - prog->statements; // we better stay on the previously executed statement
332 PRVM_ERROR("%s CALL outside the program", PRVM_NAME);
337 newf = &prog->functions[OPA->function];
340 if (newf->first_statement < 0)
342 // negative statements are built in functions
343 int builtinnumber = -newf->first_statement;
344 prog->xfunction->builtinsprofile++;
345 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
346 prog->builtins[builtinnumber]();
348 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
351 st = prog->statements + PRVM_EnterFunction(newf);
357 prog->xfunction->profile += (st - startst);
358 prog->xstatement = st - prog->statements;
360 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
361 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
362 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
364 st = prog->statements + PRVM_LeaveFunction();
366 if (prog->depth <= exitdepth)
367 goto cleanup; // all done
368 if (prog->trace != cachedpr_trace)
369 goto chooseexecprogram;
373 if(prog->flag & PRVM_OP_STATE)
375 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
376 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
377 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
378 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
382 prog->xfunction->profile += (st - startst);
383 prog->xstatement = st - prog->statements;
384 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
388 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
391 OPC->_int = OPA->_int + OPB->_int;
394 OPC->_int = OPA->_int + (int) OPB->_float;
397 OPC->_float = OPA->_float + (float) OPB->_int;
400 OPC->_int = OPA->_int - OPB->_int;
403 OPC->_int = OPA->_int - (int) OPB->_float;
406 OPC->_float = OPA->_float - (float) OPB->_int;
409 OPC->_int = OPA->_int * OPB->_int;
412 OPC->_int = OPA->_int * (int) OPB->_float;
415 OPC->_float = OPA->_float * (float) OPB->_int;
418 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
419 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
420 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
424 float temp = 1.0f / OPB->_float;
425 OPC->vector[0] = temp * OPA->vector[0];
426 OPC->vector[1] = temp * OPA->vector[1];
427 OPC->vector[2] = temp * OPA->vector[2];
431 OPC->_int = OPA->_int / OPB->_int;
434 OPC->_int = OPA->_int / (int) OPB->_float;
437 OPC->_float = OPA->_float / (float) OPB->_int;
440 OPC->_float = OPA->_int;
443 OPC->_int = OPA->_float;
446 OPC->_int = OPA->_int & OPB->_int;
449 OPC->_int = OPA->_int | OPB->_int;
452 OPC->_int = OPA->_int & (int)OPB->_float;
455 OPC->_int = OPA->_int | (int)OPB->_float;
458 OPC->_float = (int)OPA->_float & OPB->_int;
461 OPC->_float = (int)OPA->_float | OPB->_int;
464 OPC->_float = OPA->_int >= OPB->_int;
467 OPC->_float = OPA->_int <= OPB->_int;
470 OPC->_float = OPA->_int > OPB->_int;
473 OPC->_float = OPA->_int < OPB->_int;
476 OPC->_float = OPA->_int && OPB->_int;
479 OPC->_float = OPA->_int || OPB->_int;
482 OPC->_float = (float)OPA->_int >= OPB->_float;
485 OPC->_float = (float)OPA->_int <= OPB->_float;
488 OPC->_float = (float)OPA->_int > OPB->_float;
491 OPC->_float = (float)OPA->_int < OPB->_float;
494 OPC->_float = (float)OPA->_int && OPB->_float;
497 OPC->_float = (float)OPA->_int || OPB->_float;
500 OPC->_float = OPA->_float >= (float)OPB->_int;
503 OPC->_float = OPA->_float <= (float)OPB->_int;
506 OPC->_float = OPA->_float > (float)OPB->_int;
509 OPC->_float = OPA->_float < (float)OPB->_int;
512 OPC->_float = OPA->_float && (float)OPB->_int;
515 OPC->_float = OPA->_float || (float)OPB->_int;
518 OPC->_float = !OPA->_int;
521 OPC->_float = OPA->_int == OPB->_int;
524 OPC->_float = (float)OPA->_int == OPB->_float;
527 OPC->_float = OPA->_float == (float)OPB->_int;
530 OPC->_float = OPA->_int != OPB->_int;
533 OPC->_float = (float)OPA->_int != OPB->_float;
536 OPC->_float = OPA->_float != (float)OPB->_int;
539 OPB->_int = OPA->_int;
543 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
545 prog->xfunction->profile += (st - startst);
546 prog->xstatement = st - prog->statements;
547 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
551 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
552 ptr->_int = OPA->_int;
556 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
558 prog->xfunction->profile += (st - startst);
559 prog->xstatement = st - prog->statements;
560 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
563 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
565 prog->xfunction->profile += (st - startst);
566 prog->xstatement = st - prog->statements;
567 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
571 ed = PRVM_PROG_TO_EDICT(OPA->edict);
572 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
578 case OP_GSTOREP_FLD: // integers
580 case OP_GSTOREP_FNC: // pointers
582 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
584 prog->xfunction->profile += (st - startst);
585 prog->xstatement = st - prog->statements;
586 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
590 pr_iglobals[OPB->_int] = OPA->_int;
594 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
596 prog->xfunction->profile += (st - startst);
597 prog->xstatement = st - prog->statements;
598 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
602 pr_iglobals[OPB->_int ] = OPA->ivector[0];
603 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
604 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
608 i = OPA->_int + (int) OPB->_float;
610 if (i < 0 || i >= pr_globaldefs)
612 prog->xfunction->profile += (st - startst);
613 prog->xstatement = st - prog->statements;
614 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
618 OPC->_int = pr_iglobals[i];
628 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
630 prog->xfunction->profile += (st - startst);
631 prog->xstatement = st - prog->statements;
632 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
636 OPC->_int = pr_iglobals[OPA->_int];
641 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
643 prog->xfunction->profile += (st - startst);
644 prog->xstatement = st - prog->statements;
645 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
649 OPC->ivector[0] = pr_iglobals[OPA->_int ];
650 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
651 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
655 if (OPA->_int < 0 || OPA->_int >= st->b)
657 prog->xfunction->profile += (st - startst);
658 prog->xstatement = st - prog->statements;
659 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
667 prog->xfunction->profile += (st - startst);
668 prog->xstatement = st - prog->statements;
669 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);