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 ) {
57 VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
63 OPC->_float = (int)OPA->_float & (int)OPB->_float;
66 OPC->_float = (int)OPA->_float | (int)OPB->_float;
69 OPC->_float = OPA->_float >= OPB->_float;
72 OPC->_float = OPA->_float <= OPB->_float;
75 OPC->_float = OPA->_float > OPB->_float;
78 OPC->_float = OPA->_float < OPB->_float;
81 OPC->_float = OPA->_float && OPB->_float;
84 OPC->_float = OPA->_float || OPB->_float;
87 OPC->_float = !OPA->_float;
90 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
93 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
96 OPC->_float = !OPA->function;
99 OPC->_float = (OPA->edict == 0);
102 OPC->_float = OPA->_float == OPB->_float;
105 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
108 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
111 OPC->_float = OPA->_int == OPB->_int;
114 OPC->_float = OPA->function == OPB->function;
117 OPC->_float = OPA->_float != OPB->_float;
120 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
123 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
126 OPC->_float = OPA->_int != OPB->_int;
129 OPC->_float = OPA->function != OPB->function;
135 case OP_STORE_FLD: // integers
137 case OP_STORE_FNC: // pointers
138 OPB->_int = OPA->_int;
141 OPB->ivector[0] = OPA->ivector[0];
142 OPB->ivector[1] = OPA->ivector[1];
143 OPB->ivector[2] = OPA->ivector[2];
148 case OP_STOREP_FLD: // integers
150 case OP_STOREP_FNC: // pointers
152 if (OPB->_int < 0 || OPB->_int + 4 > 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->_int = OPA->_int;
165 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
167 prog->xfunction->profile += (st - startst);
168 prog->xstatement = st - prog->statements;
169 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
173 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
174 ptr->vector[0] = OPA->vector[0];
175 ptr->vector[1] = OPA->vector[1];
176 ptr->vector[2] = OPA->vector[2];
181 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
183 prog->xfunction->profile += (st - startst);
184 prog->xstatement = st - prog->statements;
185 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
189 if (OPA->edict == 0 && !prog->allowworldwrites)
191 prog->xfunction->profile += (st - startst);
192 prog->xstatement = st - prog->statements;
193 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
196 ed = PRVM_PROG_TO_EDICT(OPA->edict);
197 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
206 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
208 prog->xfunction->profile += (st - startst);
209 prog->xstatement = st - prog->statements;
210 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
214 ed = PRVM_PROG_TO_EDICT(OPA->edict);
215 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
220 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
222 prog->xfunction->profile += (st - startst);
223 prog->xstatement = st - prog->statements;
224 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
228 ed = PRVM_PROG_TO_EDICT(OPA->edict);
229 OPC->vector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[0];
230 OPC->vector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[1];
231 OPC->vector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[2];
239 prog->xfunction->profile += (st - startst);
240 st += st->b - 1; // offset the s++
242 if (++jumpcount == 10000000)
244 prog->xstatement = st - prog->statements;
245 PRVM_Profile(1<<30, 1000000);
246 PRVM_ERROR("runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", jumpcount, PRVM_NAME);
254 prog->xfunction->profile += (st - startst);
255 st += st->b - 1; // offset the s++
257 if (++jumpcount == 10000000)
259 prog->xstatement = st - prog->statements;
260 PRVM_Profile(1<<30, 1000000);
261 PRVM_ERROR("runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", jumpcount, PRVM_NAME);
267 prog->xfunction->profile += (st - startst);
268 st += st->a - 1; // offset the s++
270 if (++jumpcount == 10000000)
272 prog->xstatement = st - prog->statements;
273 PRVM_Profile(1<<30, 1000000);
274 PRVM_ERROR("runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", jumpcount, PRVM_NAME);
287 prog->xfunction->profile += (st - startst);
289 prog->xstatement = st - prog->statements;
290 prog->argc = st->op - OP_CALL0;
292 PRVM_ERROR("NULL function in %s", PRVM_NAME);
294 newf = &prog->functions[OPA->function];
297 if (newf->first_statement < 0)
299 // negative statements are built in functions
300 int builtinnumber = -newf->first_statement;
301 prog->xfunction->builtinsprofile++;
302 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
303 prog->builtins[builtinnumber]();
305 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
308 st = prog->statements + PRVM_EnterFunction(newf);
314 prog->xfunction->profile += (st - startst);
315 prog->xstatement = st - prog->statements;
317 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
318 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
319 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
321 st = prog->statements + PRVM_LeaveFunction();
323 if (prog->depth <= exitdepth)
325 if (prog->trace != cachedpr_trace)
326 goto chooseexecprogram;
330 if(prog->flag & PRVM_OP_STATE)
332 ed = PRVM_PROG_TO_EDICT(PRVM_G_INT(prog->self->ofs));
333 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("nextthink")->ofs) = *prog->time + 0.1;
334 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("frame")->ofs) = OPA->_float;
335 *(func_t *)((float*)ed->fields.vp + PRVM_ED_FindField ("think")->ofs) = OPB->function;
339 prog->xfunction->profile += (st - startst);
340 prog->xstatement = st - prog->statements;
341 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
345 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
348 OPC->_int = OPA->_int + OPB->_int;
351 OPC->_int = OPA->_int + (int) OPB->_float;
354 OPC->_float = OPA->_float + (float) OPB->_int;
357 OPC->_int = OPA->_int - OPB->_int;
360 OPC->_int = OPA->_int - (int) OPB->_float;
363 OPC->_float = OPA->_float - (float) OPB->_int;
366 OPC->_int = OPA->_int * OPB->_int;
369 OPC->_int = OPA->_int * (int) OPB->_float;
372 OPC->_float = OPA->_float * (float) OPB->_int;
375 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
376 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
377 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
381 float temp = 1.0f / OPB->_float;
382 OPC->vector[0] = temp * OPA->vector[0];
383 OPC->vector[1] = temp * OPA->vector[1];
384 OPC->vector[2] = temp * OPA->vector[2];
388 OPC->_int = OPA->_int / OPB->_int;
391 OPC->_int = OPA->_int / (int) OPB->_float;
394 OPC->_float = OPA->_float / (float) OPB->_int;
397 OPC->_float = OPA->_int;
400 OPC->_int = OPA->_float;
403 OPC->_int = OPA->_int & OPB->_int;
406 OPC->_int = OPA->_int | OPB->_int;
409 OPC->_int = OPA->_int & (int)OPB->_float;
412 OPC->_int = OPA->_int | (int)OPB->_float;
415 OPC->_float = (int)OPA->_float & OPB->_int;
418 OPC->_float = (int)OPA->_float | OPB->_int;
421 OPC->_float = OPA->_int >= OPB->_int;
424 OPC->_float = OPA->_int <= OPB->_int;
427 OPC->_float = OPA->_int > OPB->_int;
430 OPC->_float = OPA->_int < OPB->_int;
433 OPC->_float = OPA->_int && OPB->_int;
436 OPC->_float = OPA->_int || OPB->_int;
439 OPC->_float = (float)OPA->_int >= OPB->_float;
442 OPC->_float = (float)OPA->_int <= OPB->_float;
445 OPC->_float = (float)OPA->_int > OPB->_float;
448 OPC->_float = (float)OPA->_int < OPB->_float;
451 OPC->_float = (float)OPA->_int && OPB->_float;
454 OPC->_float = (float)OPA->_int || OPB->_float;
457 OPC->_float = OPA->_float >= (float)OPB->_int;
460 OPC->_float = OPA->_float <= (float)OPB->_int;
463 OPC->_float = OPA->_float > (float)OPB->_int;
466 OPC->_float = OPA->_float < (float)OPB->_int;
469 OPC->_float = OPA->_float && (float)OPB->_int;
472 OPC->_float = OPA->_float || (float)OPB->_int;
475 OPC->_float = !OPA->_int;
478 OPC->_float = OPA->_int == OPB->_int;
481 OPC->_float = (float)OPA->_int == OPB->_float;
484 OPC->_float = OPA->_float == (float)OPB->_int;
487 OPC->_float = OPA->_int != OPB->_int;
490 OPC->_float = (float)OPA->_int != OPB->_float;
493 OPC->_float = OPA->_float != (float)OPB->_int;
496 OPB->_int = OPA->_int;
500 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
502 prog->xfunction->profile += (st - startst);
503 prog->xstatement = st - prog->statements;
504 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
508 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
509 ptr->_int = OPA->_int;
513 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
515 prog->xfunction->profile += (st - startst);
516 prog->xstatement = st - prog->statements;
517 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
520 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
522 prog->xfunction->profile += (st - startst);
523 prog->xstatement = st - prog->statements;
524 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
528 ed = PRVM_PROG_TO_EDICT(OPA->edict);
529 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
535 case OP_GSTOREP_FLD: // integers
537 case OP_GSTOREP_FNC: // pointers
539 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
541 prog->xfunction->profile += (st - startst);
542 prog->xstatement = st - prog->statements;
543 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
547 pr_globals[OPB->_int] = OPA->_float;
551 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
553 prog->xfunction->profile += (st - startst);
554 prog->xstatement = st - prog->statements;
555 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
559 pr_globals[OPB->_int ] = OPA->vector[0];
560 pr_globals[OPB->_int+1] = OPA->vector[1];
561 pr_globals[OPB->_int+2] = OPA->vector[2];
565 i = OPA->_int + (int) OPB->_float;
567 if (i < 0 || i >= pr_globaldefs)
569 prog->xfunction->profile += (st - startst);
570 prog->xstatement = st - prog->statements;
571 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
575 OPC->_float = pr_globals[i];
585 if (OPA->_int < 0 || OPA->_int >= 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->_float = pr_globals[OPA->_int];
598 if (OPA->_int < 0 || OPA->_int + 2 >= 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->vector[0] = pr_globals[OPA->_int ];
607 OPC->vector[1] = pr_globals[OPA->_int+1];
608 OPC->vector[2] = pr_globals[OPA->_int+2];
612 if (OPA->_int < 0 || OPA->_int >= st->b)
614 prog->xfunction->profile += (st - startst);
615 prog->xstatement = st - prog->statements;
616 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
624 prog->xfunction->profile += (st - startst);
625 prog->xstatement = st - prog->statements;
626 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);