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 ((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->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];
243 prog->xfunction->profile += (st - startst);
244 st += st->b - 1; // offset the s++
247 if (++jumpcount == 10000000)
249 prog->xstatement = st - prog->statements;
250 PRVM_Profile(1<<30, 1000000);
251 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
260 prog->xfunction->profile += (st - startst);
261 st += st->b - 1; // offset the s++
264 if (++jumpcount == 10000000)
266 prog->xstatement = st - prog->statements;
267 PRVM_Profile(1<<30, 1000000);
268 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
275 prog->xfunction->profile += (st - startst);
276 st += st->a - 1; // offset the s++
279 if (++jumpcount == 10000000)
281 prog->xstatement = st - prog->statements;
282 PRVM_Profile(1<<30, 1000000);
283 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);
299 prog->xstatement = st - prog->statements;
300 prog->argc = st->op - OP_CALL0;
302 PRVM_ERROR("NULL function in %s", PRVM_NAME);
304 newf = &prog->functions[OPA->function];
307 if (newf->first_statement < 0)
309 // negative statements are built in functions
310 int builtinnumber = -newf->first_statement;
311 prog->xfunction->builtinsprofile++;
312 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
313 prog->builtins[builtinnumber]();
315 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
318 st = prog->statements + PRVM_EnterFunction(newf);
324 prog->xfunction->profile += (st - startst);
325 prog->xstatement = st - prog->statements;
327 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
328 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
329 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
331 st = prog->statements + PRVM_LeaveFunction();
333 if (prog->depth <= exitdepth)
334 goto cleanup; // all done
335 if (prog->trace != cachedpr_trace)
336 goto chooseexecprogram;
340 if(prog->flag & PRVM_OP_STATE)
342 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
343 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
344 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
345 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
349 prog->xfunction->profile += (st - startst);
350 prog->xstatement = st - prog->statements;
351 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
355 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
358 OPC->_int = OPA->_int + OPB->_int;
361 OPC->_int = OPA->_int + (int) OPB->_float;
364 OPC->_float = OPA->_float + (float) OPB->_int;
367 OPC->_int = OPA->_int - OPB->_int;
370 OPC->_int = OPA->_int - (int) OPB->_float;
373 OPC->_float = OPA->_float - (float) OPB->_int;
376 OPC->_int = OPA->_int * OPB->_int;
379 OPC->_int = OPA->_int * (int) OPB->_float;
382 OPC->_float = OPA->_float * (float) OPB->_int;
385 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
386 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
387 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
391 float temp = 1.0f / OPB->_float;
392 OPC->vector[0] = temp * OPA->vector[0];
393 OPC->vector[1] = temp * OPA->vector[1];
394 OPC->vector[2] = temp * OPA->vector[2];
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->_float = OPA->_int;
410 OPC->_int = OPA->_float;
413 OPC->_int = OPA->_int & OPB->_int;
416 OPC->_int = OPA->_int | OPB->_int;
419 OPC->_int = OPA->_int & (int)OPB->_float;
422 OPC->_int = OPA->_int | (int)OPB->_float;
425 OPC->_float = (int)OPA->_float & OPB->_int;
428 OPC->_float = (int)OPA->_float | 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 = OPA->_int && OPB->_int;
446 OPC->_float = OPA->_int || OPB->_int;
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 = (float)OPA->_int && OPB->_float;
464 OPC->_float = (float)OPA->_int || OPB->_float;
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->_float && (float)OPB->_int;
482 OPC->_float = OPA->_float || (float)OPB->_int;
485 OPC->_float = !OPA->_int;
488 OPC->_float = OPA->_int == OPB->_int;
491 OPC->_float = (float)OPA->_int == OPB->_float;
494 OPC->_float = OPA->_float == (float)OPB->_int;
497 OPC->_float = OPA->_int != OPB->_int;
500 OPC->_float = (float)OPA->_int != OPB->_float;
503 OPC->_float = OPA->_float != (float)OPB->_int;
506 OPB->_int = OPA->_int;
510 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
512 prog->xfunction->profile += (st - startst);
513 prog->xstatement = st - prog->statements;
514 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
518 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
519 ptr->_int = OPA->_int;
523 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
525 prog->xfunction->profile += (st - startst);
526 prog->xstatement = st - prog->statements;
527 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
530 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
532 prog->xfunction->profile += (st - startst);
533 prog->xstatement = st - prog->statements;
534 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
538 ed = PRVM_PROG_TO_EDICT(OPA->edict);
539 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
545 case OP_GSTOREP_FLD: // integers
547 case OP_GSTOREP_FNC: // pointers
549 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
551 prog->xfunction->profile += (st - startst);
552 prog->xstatement = st - prog->statements;
553 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
557 pr_iglobals[OPB->_int] = OPA->_int;
561 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
563 prog->xfunction->profile += (st - startst);
564 prog->xstatement = st - prog->statements;
565 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
569 pr_iglobals[OPB->_int ] = OPA->ivector[0];
570 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
571 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
575 i = OPA->_int + (int) OPB->_float;
577 if (i < 0 || i >= pr_globaldefs)
579 prog->xfunction->profile += (st - startst);
580 prog->xstatement = st - prog->statements;
581 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
585 OPC->_int = pr_iglobals[i];
595 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
597 prog->xfunction->profile += (st - startst);
598 prog->xstatement = st - prog->statements;
599 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
603 OPC->_int = pr_iglobals[OPA->_int];
608 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
610 prog->xfunction->profile += (st - startst);
611 prog->xstatement = st - prog->statements;
612 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
616 OPC->ivector[0] = pr_iglobals[OPA->_int ];
617 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
618 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
622 if (OPA->_int < 0 || OPA->_int >= st->b)
624 prog->xfunction->profile += (st - startst);
625 prog->xstatement = st - prog->statements;
626 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
634 prog->xfunction->profile += (st - startst);
635 prog->xstatement = st - prog->statements;
636 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);