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_ERROR("runaway loop counter hit limit of %d jumps\ntip: if having trouble identifying the problem, try typing profile now in %s", jumpcount, PRVM_NAME);
243 prog->xfunction->profile += (st - startst);
244 st += st->b - 1; // offset the s++
246 if (++jumpcount == 10000000)
248 prog->xstatement = st - prog->statements;
249 PRVM_ERROR("runaway loop counter hit limit of %d jumps\ntip: if having trouble identifying the problem, try typing profile now in %s", jumpcount, PRVM_NAME);
255 prog->xfunction->profile += (st - startst);
256 st += st->a - 1; // offset the s++
258 if (++jumpcount == 10000000)
260 prog->xstatement = st - prog->statements;
261 PRVM_ERROR("runaway loop counter hit limit of %d jumps\ntip: if having trouble identifying the problem, try typing profile now in %s", jumpcount, PRVM_NAME);
274 prog->xfunction->profile += (st - startst);
276 prog->xstatement = st - prog->statements;
277 prog->argc = st->op - OP_CALL0;
279 PRVM_ERROR("NULL function in %s", PRVM_NAME);
281 newf = &prog->functions[OPA->function];
284 if (newf->first_statement < 0)
286 // negative statements are built in functions
287 int builtinnumber = -newf->first_statement;
288 prog->xfunction->builtinsprofile++;
289 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
290 prog->builtins[builtinnumber]();
292 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
295 st = prog->statements + PRVM_EnterFunction(newf);
301 prog->xfunction->profile += (st - startst);
302 prog->xstatement = st - prog->statements;
304 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
305 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
306 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
308 st = prog->statements + PRVM_LeaveFunction();
310 if (prog->depth <= exitdepth)
312 if (prog->trace != cachedpr_trace)
313 goto chooseexecprogram;
317 if(prog->flag & PRVM_OP_STATE)
319 ed = PRVM_PROG_TO_EDICT(PRVM_G_INT(prog->self->ofs));
320 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("nextthink")->ofs) = *prog->time + 0.1;
321 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("frame")->ofs) = OPA->_float;
322 *(func_t *)((float*)ed->fields.vp + PRVM_ED_FindField ("think")->ofs) = OPB->function;
326 prog->xfunction->profile += (st - startst);
327 prog->xstatement = st - prog->statements;
328 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
332 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
335 OPC->_int = OPA->_int + OPB->_int;
338 OPC->_int = OPA->_int + (int) OPB->_float;
341 OPC->_float = OPA->_float + (float) OPB->_int;
344 OPC->_int = OPA->_int - OPB->_int;
347 OPC->_int = OPA->_int - (int) OPB->_float;
350 OPC->_float = OPA->_float - (float) OPB->_int;
353 OPC->_int = OPA->_int * OPB->_int;
356 OPC->_int = OPA->_int * (int) OPB->_float;
359 OPC->_float = OPA->_float * (float) OPB->_int;
362 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
363 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
364 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
368 float temp = 1.0f / OPB->_float;
369 OPC->vector[0] = temp * OPA->vector[0];
370 OPC->vector[1] = temp * OPA->vector[1];
371 OPC->vector[2] = temp * OPA->vector[2];
375 OPC->_int = OPA->_int / OPB->_int;
378 OPC->_int = OPA->_int / (int) OPB->_float;
381 OPC->_float = OPA->_float / (float) OPB->_int;
384 OPC->_float = OPA->_int;
387 OPC->_int = OPA->_float;
390 OPC->_int = OPA->_int & OPB->_int;
393 OPC->_int = OPA->_int | OPB->_int;
396 OPC->_int = OPA->_int & (int)OPB->_float;
399 OPC->_int = OPA->_int | (int)OPB->_float;
402 OPC->_float = (int)OPA->_float & OPB->_int;
405 OPC->_float = (int)OPA->_float | OPB->_int;
408 OPC->_float = OPA->_int >= 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 = (float)OPA->_int >= OPB->_float;
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 = OPA->_float >= (float)OPB->_int;
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->_int;
465 OPC->_float = OPA->_int == OPB->_int;
468 OPC->_float = (float)OPA->_int == OPB->_float;
471 OPC->_float = OPA->_float == (float)OPB->_int;
474 OPC->_float = OPA->_int != OPB->_int;
477 OPC->_float = (float)OPA->_int != OPB->_float;
480 OPC->_float = OPA->_float != (float)OPB->_int;
483 OPB->_int = OPA->_int;
487 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
489 prog->xfunction->profile += (st - startst);
490 prog->xstatement = st - prog->statements;
491 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
495 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
496 ptr->_int = OPA->_int;
500 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
502 prog->xfunction->profile += (st - startst);
503 prog->xstatement = st - prog->statements;
504 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
507 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
509 prog->xfunction->profile += (st - startst);
510 prog->xstatement = st - prog->statements;
511 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
515 ed = PRVM_PROG_TO_EDICT(OPA->edict);
516 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
522 case OP_GSTOREP_FLD: // integers
524 case OP_GSTOREP_FNC: // pointers
526 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
528 prog->xfunction->profile += (st - startst);
529 prog->xstatement = st - prog->statements;
530 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
534 pr_globals[OPB->_int] = OPA->_float;
538 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
540 prog->xfunction->profile += (st - startst);
541 prog->xstatement = st - prog->statements;
542 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
546 pr_globals[OPB->_int ] = OPA->vector[0];
547 pr_globals[OPB->_int+1] = OPA->vector[1];
548 pr_globals[OPB->_int+2] = OPA->vector[2];
552 i = OPA->_int + (int) OPB->_float;
554 if (i < 0 || i >= pr_globaldefs)
556 prog->xfunction->profile += (st - startst);
557 prog->xstatement = st - prog->statements;
558 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
562 OPC->_float = pr_globals[i];
572 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
574 prog->xfunction->profile += (st - startst);
575 prog->xstatement = st - prog->statements;
576 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
580 OPC->_float = pr_globals[OPA->_int];
585 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
587 prog->xfunction->profile += (st - startst);
588 prog->xstatement = st - prog->statements;
589 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
593 OPC->vector[0] = pr_globals[OPA->_int ];
594 OPC->vector[1] = pr_globals[OPA->_int+1];
595 OPC->vector[2] = pr_globals[OPA->_int+2];
599 if (OPA->_int < 0 || OPA->_int >= st->b)
601 prog->xfunction->profile += (st - startst);
602 prog->xstatement = st - prog->statements;
603 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
611 prog->xfunction->profile += (st - startst);
612 prog->xstatement = st - prog->statements;
613 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);