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];
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
246 prog->xfunction->profile += (st - startst);
247 st += st->b - 1; // offset the s++
250 if (++jumpcount == 10000000)
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);
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
266 prog->xfunction->profile += (st - startst);
267 st += st->b - 1; // offset the s++
270 if (++jumpcount == 10000000)
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);
281 prog->xfunction->profile += (st - startst);
282 st += st->a - 1; // offset the s++
285 if (++jumpcount == 10000000)
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);
303 prog->xfunction->profile += (st - startst);
305 prog->xstatement = st - prog->statements;
306 prog->argc = st->op - OP_CALL0;
308 PRVM_ERROR("NULL function in %s", PRVM_NAME);
310 newf = &prog->functions[OPA->function];
313 if (newf->first_statement < 0)
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]();
321 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
324 st = prog->statements + PRVM_EnterFunction(newf);
330 prog->xfunction->profile += (st - startst);
331 prog->xstatement = st - prog->statements;
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];
337 st = prog->statements + PRVM_LeaveFunction();
339 if (prog->depth <= exitdepth)
340 goto cleanup; // all done
341 if (prog->trace != cachedpr_trace)
342 goto chooseexecprogram;
346 if(prog->flag & PRVM_OP_STATE)
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;
355 prog->xfunction->profile += (st - startst);
356 prog->xstatement = st - prog->statements;
357 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
361 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
364 OPC->_int = OPA->_int + OPB->_int;
367 OPC->_int = OPA->_int + (int) OPB->_float;
370 OPC->_float = OPA->_float + (float) OPB->_int;
373 OPC->_int = OPA->_int - OPB->_int;
376 OPC->_int = OPA->_int - (int) OPB->_float;
379 OPC->_float = OPA->_float - (float) OPB->_int;
382 OPC->_int = OPA->_int * OPB->_int;
385 OPC->_int = OPA->_int * (int) OPB->_float;
388 OPC->_float = OPA->_float * (float) OPB->_int;
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];
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];
404 OPC->_int = OPA->_int / OPB->_int;
407 OPC->_int = OPA->_int / (int) OPB->_float;
410 OPC->_float = OPA->_float / (float) OPB->_int;
413 OPC->_float = OPA->_int;
416 OPC->_int = OPA->_float;
419 OPC->_int = OPA->_int & OPB->_int;
422 OPC->_int = OPA->_int | OPB->_int;
425 OPC->_int = OPA->_int & (int)OPB->_float;
428 OPC->_int = OPA->_int | (int)OPB->_float;
431 OPC->_float = (int)OPA->_float & OPB->_int;
434 OPC->_float = (int)OPA->_float | 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 = OPA->_int && OPB->_int;
452 OPC->_float = OPA->_int || OPB->_int;
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 = (float)OPA->_int && OPB->_float;
470 OPC->_float = (float)OPA->_int || OPB->_float;
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->_float && (float)OPB->_int;
488 OPC->_float = OPA->_float || (float)OPB->_int;
491 OPC->_float = !OPA->_int;
494 OPC->_float = OPA->_int == OPB->_int;
497 OPC->_float = (float)OPA->_int == OPB->_float;
500 OPC->_float = OPA->_float == (float)OPB->_int;
503 OPC->_float = OPA->_int != OPB->_int;
506 OPC->_float = (float)OPA->_int != OPB->_float;
509 OPC->_float = OPA->_float != (float)OPB->_int;
512 OPB->_int = OPA->_int;
516 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
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);
524 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
525 ptr->_int = OPA->_int;
529 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
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);
536 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
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);
544 ed = PRVM_PROG_TO_EDICT(OPA->edict);
545 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
551 case OP_GSTOREP_FLD: // integers
553 case OP_GSTOREP_FNC: // pointers
555 if (OPB->_int < 0 || OPB->_int >= 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_iglobals[OPB->_int] = OPA->_int;
567 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
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);
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];
581 i = OPA->_int + (int) OPB->_float;
583 if (i < 0 || i >= pr_globaldefs)
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);
591 OPC->_int = pr_iglobals[i];
601 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
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);
609 OPC->_int = pr_iglobals[OPA->_int];
614 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
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);
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];
628 if (OPA->_int < 0 || OPA->_int >= st->b)
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);
640 prog->xfunction->profile += (st - startst);
641 prog->xstatement = st - prog->statements;
642 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);