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 )
58 prog->xfunction->profile += (st - startst);
60 prog->xstatement = st - prog->statements;
61 VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
67 OPC->_float = (int)OPA->_float & (int)OPB->_float;
70 OPC->_float = (int)OPA->_float | (int)OPB->_float;
73 OPC->_float = OPA->_float >= OPB->_float;
76 OPC->_float = OPA->_float <= OPB->_float;
79 OPC->_float = OPA->_float > OPB->_float;
82 OPC->_float = OPA->_float < OPB->_float;
85 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) && FLOAT_IS_TRUE_FOR_INT(OPB->_int); // TODO change this back to float, and add AND_I to be used by fteqcc for anything not a float
88 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) || FLOAT_IS_TRUE_FOR_INT(OPB->_int); // TODO change this back to float, and add OR_I to be used by fteqcc for anything not a float
91 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
94 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
97 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
100 OPC->_float = !OPA->function;
103 OPC->_float = (OPA->edict == 0);
106 OPC->_float = OPA->_float == OPB->_float;
109 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
112 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
115 OPC->_float = OPA->_int == OPB->_int;
118 OPC->_float = OPA->function == OPB->function;
121 OPC->_float = OPA->_float != OPB->_float;
124 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
127 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
130 OPC->_float = OPA->_int != OPB->_int;
133 OPC->_float = OPA->function != OPB->function;
139 case OP_STORE_FLD: // integers
141 case OP_STORE_FNC: // pointers
142 OPB->_int = OPA->_int;
145 OPB->ivector[0] = OPA->ivector[0];
146 OPB->ivector[1] = OPA->ivector[1];
147 OPB->ivector[2] = OPA->ivector[2];
152 case OP_STOREP_FLD: // integers
154 case OP_STOREP_FNC: // pointers
156 if (OPB->_int < 0 || OPB->_int + 1 > prog->entityfieldsarea)
158 prog->xfunction->profile += (st - startst);
159 prog->xstatement = st - prog->statements;
160 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
164 if (OPB->_int < prog->progs->entityfields && !prog->allowworldwrites)
165 Con_DPrintf("WARNING: assignment to world.%s (field %i) in %s\n", PRVM_GetString(PRVM_ED_FieldAtOfs(OPB->_int)->s_name), OPB->_int, PRVM_NAME);
166 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
167 ptr->_int = OPA->_int;
171 if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea)
173 prog->xfunction->profile += (st - startst);
174 prog->xstatement = st - prog->statements;
175 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
179 if (OPB->_int < prog->progs->entityfields && !prog->allowworldwrites)
180 Con_DPrintf("WARNING: assignment to world.%s (field %i) in %s\n", PRVM_GetString(PRVM_ED_FieldAtOfs(OPB->_int)->s_name), OPB->_int, PRVM_NAME);
181 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
182 ptr->ivector[0] = OPA->ivector[0];
183 ptr->ivector[1] = OPA->ivector[1];
184 ptr->ivector[2] = OPA->ivector[2];
189 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
191 prog->xfunction->profile += (st - startst);
192 prog->xstatement = st - prog->statements;
193 PRVM_ERROR ("%s Progs attempted to address an out of bounds edict number", PRVM_NAME);
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 address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
205 if (OPA->edict == 0 && !prog->allowworldwrites)
207 prog->xfunction->profile += (st - startst);
208 prog->xstatement = st - prog->statements;
209 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
213 ed = PRVM_PROG_TO_EDICT(OPA->edict);
214 OPC->_int = ed->fields.vp - prog->edictsfields + OPB->_int;
223 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
225 prog->xfunction->profile += (st - startst);
226 prog->xstatement = st - prog->statements;
227 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
230 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
232 prog->xfunction->profile += (st - startst);
233 prog->xstatement = st - prog->statements;
234 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
238 ed = PRVM_PROG_TO_EDICT(OPA->edict);
239 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
244 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
246 prog->xfunction->profile += (st - startst);
247 prog->xstatement = st - prog->statements;
248 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
251 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
253 prog->xfunction->profile += (st - startst);
254 prog->xstatement = st - prog->statements;
255 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
259 ed = PRVM_PROG_TO_EDICT(OPA->edict);
260 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
261 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
262 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
268 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
269 // TODO add an "int-if", and change this one to OPA->_float
270 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
271 // and entity, string, field values can never have that value
273 prog->xfunction->profile += (st - startst);
274 st += st->b - 1; // offset the s++
276 // no bounds check needed, it is done when loading progs
278 if (++jumpcount == 10000000)
280 prog->xstatement = st - prog->statements;
281 PRVM_Profile(1<<30, 1000000, 0);
282 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
289 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
290 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
291 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
292 // and entity, string, field values can never have that value
294 prog->xfunction->profile += (st - startst);
295 st += st->b - 1; // offset the s++
297 // no bounds check needed, it is done when loading progs
299 if (++jumpcount == 10000000)
301 prog->xstatement = st - prog->statements;
302 PRVM_Profile(1<<30, 1000000, 0);
303 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
310 prog->xfunction->profile += (st - startst);
311 st += st->a - 1; // offset the s++
313 // no bounds check needed, it is done when loading progs
315 if (++jumpcount == 10000000)
317 prog->xstatement = st - prog->statements;
318 PRVM_Profile(1<<30, 1000000, 0);
319 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
333 prog->xfunction->profile += (st - startst);
335 prog->xstatement = st - prog->statements;
336 prog->argc = st->op - OP_CALL0;
338 PRVM_ERROR("NULL function in %s", PRVM_NAME);
341 if(!OPA->function || OPA->function >= (unsigned int)prog->progs->numfunctions)
343 prog->xfunction->profile += (st - startst);
344 prog->xstatement = st - prog->statements; // we better stay on the previously executed statement
345 PRVM_ERROR("%s CALL outside the program", PRVM_NAME);
350 newf = &prog->functions[OPA->function];
353 if (newf->first_statement < 0)
355 // negative statements are built in functions
356 int builtinnumber = -newf->first_statement;
357 prog->xfunction->builtinsprofile++;
358 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
359 prog->builtins[builtinnumber]();
361 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
364 st = prog->statements + PRVM_EnterFunction(newf);
370 prog->xfunction->profile += (st - startst);
371 prog->xstatement = st - prog->statements;
373 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
374 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
375 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
377 st = prog->statements + PRVM_LeaveFunction();
379 if (prog->depth <= exitdepth)
380 goto cleanup; // all done
381 if (prog->trace != cachedpr_trace)
382 goto chooseexecprogram;
386 if(prog->flag & PRVM_OP_STATE)
388 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
389 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
390 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
391 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
395 prog->xfunction->profile += (st - startst);
396 prog->xstatement = st - prog->statements;
397 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
401 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
404 OPC->_int = OPA->_int + OPB->_int;
407 OPC->_int = OPA->_int + (int) OPB->_float;
410 OPC->_float = OPA->_float + (float) OPB->_int;
413 OPC->_int = OPA->_int - OPB->_int;
416 OPC->_int = OPA->_int - (int) OPB->_float;
419 OPC->_float = OPA->_float - (float) OPB->_int;
422 OPC->_int = OPA->_int * OPB->_int;
425 OPC->_int = OPA->_int * (int) OPB->_float;
428 OPC->_float = OPA->_float * (float) OPB->_int;
431 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
432 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
433 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
437 float temp = 1.0f / OPB->_float;
438 OPC->vector[0] = temp * OPA->vector[0];
439 OPC->vector[1] = temp * OPA->vector[1];
440 OPC->vector[2] = temp * OPA->vector[2];
444 OPC->_int = OPA->_int / OPB->_int;
447 OPC->_int = OPA->_int / (int) OPB->_float;
450 OPC->_float = OPA->_float / (float) OPB->_int;
453 OPC->_float = OPA->_int;
456 OPC->_int = OPA->_float;
459 OPC->_int = OPA->_int & OPB->_int;
462 OPC->_int = OPA->_int | OPB->_int;
465 OPC->_int = OPA->_int & (int)OPB->_float;
468 OPC->_int = OPA->_int | (int)OPB->_float;
471 OPC->_float = (int)OPA->_float & OPB->_int;
474 OPC->_float = (int)OPA->_float | OPB->_int;
477 OPC->_float = OPA->_int >= OPB->_int;
480 OPC->_float = OPA->_int <= OPB->_int;
483 OPC->_float = OPA->_int > OPB->_int;
486 OPC->_float = OPA->_int < OPB->_int;
489 OPC->_float = OPA->_int && OPB->_int;
492 OPC->_float = OPA->_int || OPB->_int;
495 OPC->_float = (float)OPA->_int >= OPB->_float;
498 OPC->_float = (float)OPA->_int <= OPB->_float;
501 OPC->_float = (float)OPA->_int > OPB->_float;
504 OPC->_float = (float)OPA->_int < OPB->_float;
507 OPC->_float = (float)OPA->_int && OPB->_float;
510 OPC->_float = (float)OPA->_int || OPB->_float;
513 OPC->_float = OPA->_float >= (float)OPB->_int;
516 OPC->_float = OPA->_float <= (float)OPB->_int;
519 OPC->_float = OPA->_float > (float)OPB->_int;
522 OPC->_float = OPA->_float < (float)OPB->_int;
525 OPC->_float = OPA->_float && (float)OPB->_int;
528 OPC->_float = OPA->_float || (float)OPB->_int;
531 OPC->_float = !OPA->_int;
534 OPC->_float = OPA->_int == OPB->_int;
537 OPC->_float = (float)OPA->_int == OPB->_float;
540 OPC->_float = OPA->_float == (float)OPB->_int;
543 OPC->_float = OPA->_int != OPB->_int;
546 OPC->_float = (float)OPA->_int != OPB->_float;
549 OPC->_float = OPA->_float != (float)OPB->_int;
552 OPB->_int = OPA->_int;
556 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
558 prog->xfunction->profile += (st - startst);
559 prog->xstatement = st - prog->statements;
560 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
564 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
565 ptr->_int = OPA->_int;
569 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
571 prog->xfunction->profile += (st - startst);
572 prog->xstatement = st - prog->statements;
573 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
576 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
578 prog->xfunction->profile += (st - startst);
579 prog->xstatement = st - prog->statements;
580 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
584 ed = PRVM_PROG_TO_EDICT(OPA->edict);
585 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
591 case OP_GSTOREP_FLD: // integers
593 case OP_GSTOREP_FNC: // pointers
595 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
597 prog->xfunction->profile += (st - startst);
598 prog->xstatement = st - prog->statements;
599 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
603 pr_iglobals[OPB->_int] = OPA->_int;
607 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
609 prog->xfunction->profile += (st - startst);
610 prog->xstatement = st - prog->statements;
611 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
615 pr_iglobals[OPB->_int ] = OPA->ivector[0];
616 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
617 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
621 i = OPA->_int + (int) OPB->_float;
623 if (i < 0 || i >= pr_globaldefs)
625 prog->xfunction->profile += (st - startst);
626 prog->xstatement = st - prog->statements;
627 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
631 OPC->_int = pr_iglobals[i];
641 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
643 prog->xfunction->profile += (st - startst);
644 prog->xstatement = st - prog->statements;
645 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
649 OPC->_int = pr_iglobals[OPA->_int];
654 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
656 prog->xfunction->profile += (st - startst);
657 prog->xstatement = st - prog->statements;
658 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
662 OPC->ivector[0] = pr_iglobals[OPA->_int ];
663 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
664 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
668 if (OPA->_int < 0 || OPA->_int >= st->b)
670 prog->xfunction->profile += (st - startst);
671 prog->xstatement = st - prog->statements;
672 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
680 prog->xfunction->profile += (st - startst);
681 prog->xstatement = st - prog->statements;
682 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);