2 // This code isn't #ifdef/#define protectable, don't try.
6 st++; // TODO bounds check
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];
43 OPC->vector[0] = OPB->_float * OPA->vector[0];
44 OPC->vector[1] = OPB->_float * OPA->vector[1];
45 OPC->vector[2] = OPB->_float * OPA->vector[2];
48 if( OPB->_float != 0.0f )
50 OPC->_float = OPA->_float / OPB->_float;
54 if( developer.integer >= 1 )
56 prog->xfunction->profile += (st - startst);
58 prog->xstatement = st - prog->statements;
59 VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
65 OPC->_float = (int)OPA->_float & (int)OPB->_float;
68 OPC->_float = (int)OPA->_float | (int)OPB->_float;
71 OPC->_float = OPA->_float >= OPB->_float;
74 OPC->_float = OPA->_float <= OPB->_float;
77 OPC->_float = OPA->_float > OPB->_float;
80 OPC->_float = OPA->_float < OPB->_float;
83 OPC->_float = OPA->_float && OPB->_float;
86 OPC->_float = OPA->_float || OPB->_float;
89 OPC->_float = !OPA->_float;
92 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
95 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
98 OPC->_float = !OPA->function;
101 OPC->_float = (OPA->edict == 0);
104 OPC->_float = OPA->_float == OPB->_float;
107 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
110 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
113 OPC->_float = OPA->_int == OPB->_int;
116 OPC->_float = OPA->function == OPB->function;
119 OPC->_float = OPA->_float != OPB->_float;
122 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
125 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
128 OPC->_float = OPA->_int != OPB->_int;
131 OPC->_float = OPA->function != OPB->function;
137 case OP_STORE_FLD: // integers
139 case OP_STORE_FNC: // pointers
140 OPB->_int = OPA->_int;
143 OPB->ivector[0] = OPA->ivector[0];
144 OPB->ivector[1] = OPA->ivector[1];
145 OPB->ivector[2] = OPA->ivector[2];
150 case OP_STOREP_FLD: // integers
152 case OP_STOREP_FNC: // pointers
154 if (OPB->_int < 0 || OPB->_int + 4 > prog->edictareasize)
156 prog->xfunction->profile += (st - startst);
157 prog->xstatement = st - prog->statements;
158 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
162 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
163 ptr->_int = OPA->_int;
167 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
169 prog->xfunction->profile += (st - startst);
170 prog->xstatement = st - prog->statements;
171 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
175 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
176 ptr->ivector[0] = OPA->ivector[0];
177 ptr->ivector[1] = OPA->ivector[1];
178 ptr->ivector[2] = OPA->ivector[2];
183 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
185 prog->xfunction->profile += (st - startst);
186 prog->xstatement = st - prog->statements;
187 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
191 if (OPA->edict == 0 && !prog->allowworldwrites)
193 prog->xfunction->profile += (st - startst);
194 prog->xstatement = st - prog->statements;
195 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
198 ed = PRVM_PROG_TO_EDICT(OPA->edict);
199 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
208 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
210 prog->xfunction->profile += (st - startst);
211 prog->xstatement = st - prog->statements;
212 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
216 ed = PRVM_PROG_TO_EDICT(OPA->edict); // TODO bounds check entity number
217 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
222 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
224 prog->xfunction->profile += (st - startst);
225 prog->xstatement = st - prog->statements;
226 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
230 ed = PRVM_PROG_TO_EDICT(OPA->edict); // TODO bounds check entity number
231 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
232 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
233 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
240 // TODO add an "int-ifnot"
241 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
242 // and entity, string, field values can never have that value
244 prog->xfunction->profile += (st - startst);
245 st += st->b - 1; // offset the s++
248 if (++jumpcount == 10000000)
250 prog->xstatement = st - prog->statements;
251 PRVM_Profile(1<<30, 1000000);
252 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
260 // TODO add an "int-if"
261 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
262 // and entity, string, field values can never have that value
264 prog->xfunction->profile += (st - startst);
265 st += st->b - 1; // offset the s++
268 if (++jumpcount == 10000000)
270 prog->xstatement = st - prog->statements;
271 PRVM_Profile(1<<30, 1000000);
272 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
279 prog->xfunction->profile += (st - startst);
280 st += st->a - 1; // offset the s++
283 if (++jumpcount == 10000000)
285 prog->xstatement = st - prog->statements;
286 PRVM_Profile(1<<30, 1000000);
287 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
301 prog->xfunction->profile += (st - startst);
303 prog->xstatement = st - prog->statements;
304 prog->argc = st->op - OP_CALL0;
306 PRVM_ERROR("NULL function in %s", PRVM_NAME);
307 newf = &prog->functions[OPA->function]; // TODO bounds check function
310 if (newf->first_statement < 0)
312 // negative statements are built in functions
313 int builtinnumber = -newf->first_statement;
314 prog->xfunction->builtinsprofile++;
315 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
316 prog->builtins[builtinnumber]();
318 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
321 st = prog->statements + PRVM_EnterFunction(newf);
327 prog->xfunction->profile += (st - startst);
328 prog->xstatement = st - prog->statements;
330 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
331 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
332 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
334 st = prog->statements + PRVM_LeaveFunction();
336 if (prog->depth <= exitdepth)
337 goto cleanup; // all done
338 if (prog->trace != cachedpr_trace)
339 goto chooseexecprogram;
343 if(prog->flag & PRVM_OP_STATE)
345 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
346 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
347 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
348 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
352 prog->xfunction->profile += (st - startst);
353 prog->xstatement = st - prog->statements;
354 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
358 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
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->_int = OPA->_int * OPB->_int;
382 OPC->_int = OPA->_int * (int) OPB->_float;
385 OPC->_float = OPA->_float * (float) OPB->_int;
388 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
389 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
390 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
394 float temp = 1.0f / OPB->_float;
395 OPC->vector[0] = temp * OPA->vector[0];
396 OPC->vector[1] = temp * OPA->vector[1];
397 OPC->vector[2] = temp * OPA->vector[2];
401 OPC->_int = OPA->_int / OPB->_int;
404 OPC->_int = OPA->_int / (int) OPB->_float;
407 OPC->_float = OPA->_float / (float) OPB->_int;
410 OPC->_float = OPA->_int;
413 OPC->_int = OPA->_float;
416 OPC->_int = OPA->_int & OPB->_int;
419 OPC->_int = OPA->_int | OPB->_int;
422 OPC->_int = OPA->_int & (int)OPB->_float;
425 OPC->_int = OPA->_int | (int)OPB->_float;
428 OPC->_float = (int)OPA->_float & OPB->_int;
431 OPC->_float = (int)OPA->_float | 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 = OPA->_int || OPB->_int;
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 = (float)OPA->_int || OPB->_float;
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->_float || (float)OPB->_int;
488 OPC->_float = !OPA->_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 OPC->_float = OPA->_int != OPB->_int;
503 OPC->_float = (float)OPA->_int != OPB->_float;
506 OPC->_float = OPA->_float != (float)OPB->_int;
509 OPB->_int = OPA->_int;
513 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
515 prog->xfunction->profile += (st - startst);
516 prog->xstatement = st - prog->statements;
517 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
521 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
522 ptr->_int = OPA->_int;
526 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
528 prog->xfunction->profile += (st - startst);
529 prog->xstatement = st - prog->statements;
530 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
533 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
535 prog->xfunction->profile += (st - startst);
536 prog->xstatement = st - prog->statements;
537 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
541 ed = PRVM_PROG_TO_EDICT(OPA->edict);
542 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
548 case OP_GSTOREP_FLD: // integers
550 case OP_GSTOREP_FNC: // pointers
552 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
554 prog->xfunction->profile += (st - startst);
555 prog->xstatement = st - prog->statements;
556 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
560 pr_iglobals[OPB->_int] = OPA->_int;
564 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
566 prog->xfunction->profile += (st - startst);
567 prog->xstatement = st - prog->statements;
568 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
572 pr_iglobals[OPB->_int ] = OPA->ivector[0];
573 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
574 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
578 i = OPA->_int + (int) OPB->_float;
580 if (i < 0 || i >= pr_globaldefs)
582 prog->xfunction->profile += (st - startst);
583 prog->xstatement = st - prog->statements;
584 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
588 OPC->_int = pr_iglobals[i];
598 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
600 prog->xfunction->profile += (st - startst);
601 prog->xstatement = st - prog->statements;
602 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
606 OPC->_int = pr_iglobals[OPA->_int];
611 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
613 prog->xfunction->profile += (st - startst);
614 prog->xstatement = st - prog->statements;
615 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
619 OPC->ivector[0] = pr_iglobals[OPA->_int ];
620 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
621 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
625 if (OPA->_int < 0 || OPA->_int >= st->b)
627 prog->xfunction->profile += (st - startst);
628 prog->xstatement = st - prog->statements;
629 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
637 prog->xfunction->profile += (st - startst);
638 prog->xstatement = st - prog->statements;
639 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);