2 // This code isn't #ifdef/#define protectable, don't try.
9 PRVM_PrintStatement(st);
15 OPC->_float = OPA->_float + OPB->_float;
18 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
19 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
20 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
23 OPC->_float = OPA->_float - OPB->_float;
26 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
27 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
28 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
31 OPC->_float = OPA->_float * OPB->_float;
34 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
37 OPC->vector[0] = OPA->_float * OPB->vector[0];
38 OPC->vector[1] = OPA->_float * OPB->vector[1];
39 OPC->vector[2] = OPA->_float * OPB->vector[2];
42 OPC->vector[0] = OPB->_float * OPA->vector[0];
43 OPC->vector[1] = OPB->_float * OPA->vector[1];
44 OPC->vector[2] = OPB->_float * OPA->vector[2];
47 OPC->_float = OPA->_float / OPB->_float;
50 OPC->_float = (int)OPA->_float & (int)OPB->_float;
53 OPC->_float = (int)OPA->_float | (int)OPB->_float;
56 OPC->_float = OPA->_float >= 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;
77 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
80 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
83 OPC->_float = !OPA->function;
86 OPC->_float = (OPA->edict == 0);
89 OPC->_float = OPA->_float == OPB->_float;
92 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
95 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
98 OPC->_float = OPA->_int == OPB->_int;
101 OPC->_float = OPA->function == OPB->function;
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;
122 case OP_STORE_FLD: // integers
124 case OP_STORE_FNC: // pointers
125 OPB->_int = OPA->_int;
128 OPB->ivector[0] = OPA->ivector[0];
129 OPB->ivector[1] = OPA->ivector[1];
130 OPB->ivector[2] = OPA->ivector[2];
135 case OP_STOREP_FLD: // integers
137 case OP_STOREP_FNC: // pointers
139 if (OPB->_int < 0 || OPB->_int + 4 > prog->edictareasize)
141 prog->xfunction->profile += (st - startst);
142 prog->xstatement = st - prog->statements;
143 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
147 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
148 ptr->_int = OPA->_int;
152 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
154 prog->xfunction->profile += (st - startst);
155 prog->xstatement = st - prog->statements;
156 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
160 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
161 ptr->vector[0] = OPA->vector[0];
162 ptr->vector[1] = OPA->vector[1];
163 ptr->vector[2] = OPA->vector[2];
168 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
170 prog->xfunction->profile += (st - startst);
171 prog->xstatement = st - prog->statements;
172 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
176 if (OPA->edict == 0 && !prog->allowworldwrites)
178 prog->xfunction->profile += (st - startst);
179 prog->xstatement = st - prog->statements;
180 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
183 ed = PRVM_PROG_TO_EDICT(OPA->edict);
184 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
193 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
195 prog->xfunction->profile += (st - startst);
196 prog->xstatement = st - prog->statements;
197 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
201 ed = PRVM_PROG_TO_EDICT(OPA->edict);
202 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
207 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
209 prog->xfunction->profile += (st - startst);
210 prog->xstatement = st - prog->statements;
211 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
215 ed = PRVM_PROG_TO_EDICT(OPA->edict);
216 OPC->vector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[0];
217 OPC->vector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[1];
218 OPC->vector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[2];
226 prog->xfunction->profile += (st - startst);
227 st += st->b - 1; // offset the s++
229 if (++jumpcount> 1000000)
231 prog->xstatement = st - prog->statements;
232 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);
240 prog->xfunction->profile += (st - startst);
241 st += st->b - 1; // offset the s++
243 if (++jumpcount> 1000000)
245 prog->xstatement = st - prog->statements;
246 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);
252 prog->xfunction->profile += (st - startst);
253 st += st->a - 1; // offset the s++
255 if (++jumpcount> 1000000)
257 prog->xstatement = st - prog->statements;
258 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);
271 prog->xfunction->profile += (st - startst);
273 prog->xstatement = st - prog->statements;
274 prog->argc = st->op - OP_CALL0;
276 PRVM_ERROR("NULL function in %s", PRVM_NAME);
278 newf = &prog->functions[OPA->function];
281 if (newf->first_statement < 0)
283 // negative statements are built in functions
284 int builtinnumber = -newf->first_statement;
285 prog->xfunction->builtinsprofile++;
286 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
287 prog->builtins[builtinnumber]();
289 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
292 st = prog->statements + PRVM_EnterFunction(newf);
298 prog->xfunction->profile += (st - startst);
299 prog->xstatement = st - prog->statements;
301 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
302 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
303 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
305 st = prog->statements + PRVM_LeaveFunction();
307 if (prog->depth <= exitdepth)
309 if (prog->trace != cachedpr_trace)
310 goto chooseexecprogram;
314 if(prog->flag & PRVM_OP_STATE)
316 ed = PRVM_PROG_TO_EDICT(PRVM_G_INT(prog->self->ofs));
317 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("nextthink")->ofs) = *prog->time + 0.1;
318 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("frame")->ofs) = OPA->_float;
319 *(func_t *)((float*)ed->fields.vp + PRVM_ED_FindField ("think")->ofs) = OPB->function;
323 prog->xfunction->profile += (st - startst);
324 prog->xstatement = st - prog->statements;
325 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
329 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
332 OPC->_int = OPA->_int + OPB->_int;
335 OPC->_int = OPA->_int + (int) OPB->_float;
338 OPC->_float = OPA->_float + (float) OPB->_int;
341 OPC->_int = OPA->_int - OPB->_int;
344 OPC->_int = OPA->_int - (int) OPB->_float;
347 OPC->_float = OPA->_float - (float) OPB->_int;
350 OPC->_int = OPA->_int * OPB->_int;
353 OPC->_int = OPA->_int * (int) OPB->_float;
356 OPC->_float = OPA->_float * (float) OPB->_int;
359 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
360 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
361 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
365 float temp = 1.0f / OPB->_float;
366 OPC->vector[0] = temp * OPA->vector[0];
367 OPC->vector[1] = temp * OPA->vector[1];
368 OPC->vector[2] = temp * OPA->vector[2];
372 OPC->_int = OPA->_int / OPB->_int;
375 OPC->_int = OPA->_int / (int) OPB->_float;
378 OPC->_float = OPA->_float / (float) OPB->_int;
381 OPC->_float = OPA->_int;
384 OPC->_int = OPA->_float;
387 OPC->_int = OPA->_int & OPB->_int;
390 OPC->_int = OPA->_int | OPB->_int;
393 OPC->_int = OPA->_int & (int)OPB->_float;
396 OPC->_int = OPA->_int | (int)OPB->_float;
399 OPC->_float = (int)OPA->_float & OPB->_int;
402 OPC->_float = (int)OPA->_float | OPB->_int;
405 OPC->_float = OPA->_int >= 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 = (float)OPA->_int >= OPB->_float;
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 = OPA->_float >= (float)OPB->_int;
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->_int;
462 OPC->_float = OPA->_int == OPB->_int;
465 OPC->_float = (float)OPA->_int == OPB->_float;
468 OPC->_float = OPA->_float == (float)OPB->_int;
471 OPC->_float = OPA->_int != OPB->_int;
474 OPC->_float = (float)OPA->_int != OPB->_float;
477 OPC->_float = OPA->_float != (float)OPB->_int;
480 OPB->_int = OPA->_int;
484 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
486 prog->xfunction->profile += (st - startst);
487 prog->xstatement = st - prog->statements;
488 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
492 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
493 ptr->_int = OPA->_int;
497 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
499 prog->xfunction->profile += (st - startst);
500 prog->xstatement = st - prog->statements;
501 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
504 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
506 prog->xfunction->profile += (st - startst);
507 prog->xstatement = st - prog->statements;
508 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
512 ed = PRVM_PROG_TO_EDICT(OPA->edict);
513 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
519 case OP_GSTOREP_FLD: // integers
521 case OP_GSTOREP_FNC: // pointers
523 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
525 prog->xfunction->profile += (st - startst);
526 prog->xstatement = st - prog->statements;
527 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
531 pr_globals[OPB->_int] = OPA->_float;
535 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
537 prog->xfunction->profile += (st - startst);
538 prog->xstatement = st - prog->statements;
539 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
543 pr_globals[OPB->_int ] = OPA->vector[0];
544 pr_globals[OPB->_int+1] = OPA->vector[1];
545 pr_globals[OPB->_int+2] = OPA->vector[2];
549 i = OPA->_int + (int) OPB->_float;
551 if (i < 0 || i >= pr_globaldefs)
553 prog->xfunction->profile += (st - startst);
554 prog->xstatement = st - prog->statements;
555 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
559 OPC->_float = pr_globals[i];
569 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
571 prog->xfunction->profile += (st - startst);
572 prog->xstatement = st - prog->statements;
573 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
577 OPC->_float = pr_globals[OPA->_int];
582 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
584 prog->xfunction->profile += (st - startst);
585 prog->xstatement = st - prog->statements;
586 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
590 OPC->vector[0] = pr_globals[OPA->_int ];
591 OPC->vector[1] = pr_globals[OPA->_int+1];
592 OPC->vector[2] = pr_globals[OPA->_int+2];
596 if (OPA->_int < 0 || OPA->_int >= st->b)
598 prog->xfunction->profile += (st - startst);
599 prog->xstatement = st - prog->statements;
600 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
608 prog->xfunction->profile += (st - startst);
609 prog->xstatement = st - prog->statements;
610 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);