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 OPC->_float = OPA->_float / OPB->_float;
53 OPC->_float = (int)OPA->_float & (int)OPB->_float;
56 OPC->_float = (int)OPA->_float | (int)OPB->_float;
59 OPC->_float = OPA->_float >= OPB->_float;
62 OPC->_float = OPA->_float <= OPB->_float;
65 OPC->_float = OPA->_float > OPB->_float;
68 OPC->_float = OPA->_float < OPB->_float;
71 OPC->_float = OPA->_float && OPB->_float;
74 OPC->_float = OPA->_float || OPB->_float;
77 OPC->_float = !OPA->_float;
80 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
83 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
86 OPC->_float = !OPA->function;
89 OPC->_float = (OPA->edict == 0);
92 OPC->_float = OPA->_float == OPB->_float;
95 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
98 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
101 OPC->_float = OPA->_int == OPB->_int;
104 OPC->_float = OPA->function == OPB->function;
107 OPC->_float = OPA->_float != OPB->_float;
110 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
113 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
116 OPC->_float = OPA->_int != OPB->_int;
119 OPC->_float = OPA->function != OPB->function;
125 case OP_STORE_FLD: // integers
127 case OP_STORE_FNC: // pointers
128 OPB->_int = OPA->_int;
131 OPB->ivector[0] = OPA->ivector[0];
132 OPB->ivector[1] = OPA->ivector[1];
133 OPB->ivector[2] = OPA->ivector[2];
138 case OP_STOREP_FLD: // integers
140 case OP_STOREP_FNC: // pointers
142 if (OPB->_int < 0 || OPB->_int + 4 > prog->edictareasize)
144 prog->xfunction->profile += (st - startst);
145 prog->xstatement = st - prog->statements;
146 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
150 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
151 ptr->_int = OPA->_int;
155 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
157 prog->xfunction->profile += (st - startst);
158 prog->xstatement = st - prog->statements;
159 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
163 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
164 ptr->vector[0] = OPA->vector[0];
165 ptr->vector[1] = OPA->vector[1];
166 ptr->vector[2] = OPA->vector[2];
171 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
173 prog->xfunction->profile += (st - startst);
174 prog->xstatement = st - prog->statements;
175 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
179 if (OPA->edict == 0 && !prog->allowworldwrites)
181 prog->xfunction->profile += (st - startst);
182 prog->xstatement = st - prog->statements;
183 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
186 ed = PRVM_PROG_TO_EDICT(OPA->edict);
187 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
196 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
198 prog->xfunction->profile += (st - startst);
199 prog->xstatement = st - prog->statements;
200 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
204 ed = PRVM_PROG_TO_EDICT(OPA->edict);
205 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
210 if (OPB->_int < 0 || OPB->_int + 2 >= 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->vector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[0];
220 OPC->vector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[1];
221 OPC->vector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[2];
229 prog->xfunction->profile += (st - startst);
230 st += st->b - 1; // offset the s++
232 if (++jumpcount == 10000000)
234 prog->xstatement = st - prog->statements;
235 PRVM_Profile(1<<30, 1000000);
236 PRVM_ERROR("runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", jumpcount, PRVM_NAME);
244 prog->xfunction->profile += (st - startst);
245 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("runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", jumpcount, PRVM_NAME);
257 prog->xfunction->profile += (st - startst);
258 st += st->a - 1; // offset the s++
260 if (++jumpcount == 10000000)
262 prog->xstatement = st - prog->statements;
263 PRVM_Profile(1<<30, 1000000);
264 PRVM_ERROR("runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", jumpcount, PRVM_NAME);
277 prog->xfunction->profile += (st - startst);
279 prog->xstatement = st - prog->statements;
280 prog->argc = st->op - OP_CALL0;
282 PRVM_ERROR("NULL function in %s", PRVM_NAME);
284 newf = &prog->functions[OPA->function];
287 if (newf->first_statement < 0)
289 // negative statements are built in functions
290 int builtinnumber = -newf->first_statement;
291 prog->xfunction->builtinsprofile++;
292 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
293 prog->builtins[builtinnumber]();
295 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
298 st = prog->statements + PRVM_EnterFunction(newf);
304 prog->xfunction->profile += (st - startst);
305 prog->xstatement = st - prog->statements;
307 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
308 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
309 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
311 st = prog->statements + PRVM_LeaveFunction();
313 if (prog->depth <= exitdepth)
315 if (prog->trace != cachedpr_trace)
316 goto chooseexecprogram;
320 if(prog->flag & PRVM_OP_STATE)
322 ed = PRVM_PROG_TO_EDICT(PRVM_G_INT(prog->self->ofs));
323 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("nextthink")->ofs) = *prog->time + 0.1;
324 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("frame")->ofs) = OPA->_float;
325 *(func_t *)((float*)ed->fields.vp + PRVM_ED_FindField ("think")->ofs) = OPB->function;
329 prog->xfunction->profile += (st - startst);
330 prog->xstatement = st - prog->statements;
331 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
335 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
338 OPC->_int = OPA->_int + OPB->_int;
341 OPC->_int = OPA->_int + (int) OPB->_float;
344 OPC->_float = OPA->_float + (float) OPB->_int;
347 OPC->_int = OPA->_int - OPB->_int;
350 OPC->_int = OPA->_int - (int) OPB->_float;
353 OPC->_float = OPA->_float - (float) OPB->_int;
356 OPC->_int = OPA->_int * OPB->_int;
359 OPC->_int = OPA->_int * (int) OPB->_float;
362 OPC->_float = OPA->_float * (float) OPB->_int;
365 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
366 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
367 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
371 float temp = 1.0f / OPB->_float;
372 OPC->vector[0] = temp * OPA->vector[0];
373 OPC->vector[1] = temp * OPA->vector[1];
374 OPC->vector[2] = temp * OPA->vector[2];
378 OPC->_int = OPA->_int / OPB->_int;
381 OPC->_int = OPA->_int / (int) OPB->_float;
384 OPC->_float = OPA->_float / (float) OPB->_int;
387 OPC->_float = OPA->_int;
390 OPC->_int = OPA->_float;
393 OPC->_int = OPA->_int & OPB->_int;
396 OPC->_int = OPA->_int | OPB->_int;
399 OPC->_int = OPA->_int & (int)OPB->_float;
402 OPC->_int = OPA->_int | (int)OPB->_float;
405 OPC->_float = (int)OPA->_float & OPB->_int;
408 OPC->_float = (int)OPA->_float | OPB->_int;
411 OPC->_float = OPA->_int >= OPB->_int;
414 OPC->_float = OPA->_int <= OPB->_int;
417 OPC->_float = OPA->_int > OPB->_int;
420 OPC->_float = OPA->_int < OPB->_int;
423 OPC->_float = OPA->_int && OPB->_int;
426 OPC->_float = OPA->_int || OPB->_int;
429 OPC->_float = (float)OPA->_int >= OPB->_float;
432 OPC->_float = (float)OPA->_int <= OPB->_float;
435 OPC->_float = (float)OPA->_int > OPB->_float;
438 OPC->_float = (float)OPA->_int < OPB->_float;
441 OPC->_float = (float)OPA->_int && OPB->_float;
444 OPC->_float = (float)OPA->_int || OPB->_float;
447 OPC->_float = OPA->_float >= (float)OPB->_int;
450 OPC->_float = OPA->_float <= (float)OPB->_int;
453 OPC->_float = OPA->_float > (float)OPB->_int;
456 OPC->_float = OPA->_float < (float)OPB->_int;
459 OPC->_float = OPA->_float && (float)OPB->_int;
462 OPC->_float = OPA->_float || (float)OPB->_int;
465 OPC->_float = !OPA->_int;
468 OPC->_float = OPA->_int == OPB->_int;
471 OPC->_float = (float)OPA->_int == OPB->_float;
474 OPC->_float = OPA->_float == (float)OPB->_int;
477 OPC->_float = OPA->_int != OPB->_int;
480 OPC->_float = (float)OPA->_int != OPB->_float;
483 OPC->_float = OPA->_float != (float)OPB->_int;
486 OPB->_int = OPA->_int;
490 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
492 prog->xfunction->profile += (st - startst);
493 prog->xstatement = st - prog->statements;
494 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
498 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
499 ptr->_int = OPA->_int;
503 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
505 prog->xfunction->profile += (st - startst);
506 prog->xstatement = st - prog->statements;
507 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
510 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
512 prog->xfunction->profile += (st - startst);
513 prog->xstatement = st - prog->statements;
514 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
518 ed = PRVM_PROG_TO_EDICT(OPA->edict);
519 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
525 case OP_GSTOREP_FLD: // integers
527 case OP_GSTOREP_FNC: // pointers
529 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
531 prog->xfunction->profile += (st - startst);
532 prog->xstatement = st - prog->statements;
533 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
537 pr_globals[OPB->_int] = OPA->_float;
541 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
543 prog->xfunction->profile += (st - startst);
544 prog->xstatement = st - prog->statements;
545 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
549 pr_globals[OPB->_int ] = OPA->vector[0];
550 pr_globals[OPB->_int+1] = OPA->vector[1];
551 pr_globals[OPB->_int+2] = OPA->vector[2];
555 i = OPA->_int + (int) OPB->_float;
557 if (i < 0 || i >= pr_globaldefs)
559 prog->xfunction->profile += (st - startst);
560 prog->xstatement = st - prog->statements;
561 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
565 OPC->_float = pr_globals[i];
575 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
577 prog->xfunction->profile += (st - startst);
578 prog->xstatement = st - prog->statements;
579 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
583 OPC->_float = pr_globals[OPA->_int];
588 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
590 prog->xfunction->profile += (st - startst);
591 prog->xstatement = st - prog->statements;
592 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
596 OPC->vector[0] = pr_globals[OPA->_int ];
597 OPC->vector[1] = pr_globals[OPA->_int+1];
598 OPC->vector[2] = pr_globals[OPA->_int+2];
602 if (OPA->_int < 0 || OPA->_int >= st->b)
604 prog->xfunction->profile += (st - startst);
605 prog->xstatement = st - prog->statements;
606 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
614 prog->xfunction->profile += (st - startst);
615 prog->xstatement = st - prog->statements;
616 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);