2 // This code isn't #ifdef/#define protectable, don't try.
8 #if PRVMSLOWINTERPRETER
10 PRVM_PrintStatement(st);
11 prog->statement_profile[st - prog->statements]++;
17 OPC->_float = OPA->_float + OPB->_float;
20 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
21 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
22 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
25 OPC->_float = OPA->_float - OPB->_float;
28 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
29 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
30 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
33 OPC->_float = OPA->_float * OPB->_float;
36 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
39 OPC->vector[0] = OPA->_float * OPB->vector[0];
40 OPC->vector[1] = OPA->_float * OPB->vector[1];
41 OPC->vector[2] = OPA->_float * OPB->vector[2];
44 OPC->vector[0] = OPB->_float * OPA->vector[0];
45 OPC->vector[1] = OPB->_float * OPA->vector[1];
46 OPC->vector[2] = OPB->_float * OPA->vector[2];
49 if( OPB->_float != 0.0f )
51 OPC->_float = OPA->_float / OPB->_float;
55 if (developer.integer)
57 prog->xfunction->profile += (st - startst);
59 prog->xstatement = st - prog->statements;
60 VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
66 OPC->_float = (int)OPA->_float & (int)OPB->_float;
69 OPC->_float = (int)OPA->_float | (int)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 = 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
87 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
90 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
93 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
96 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
99 OPC->_float = !OPA->function;
102 OPC->_float = (OPA->edict == 0);
105 OPC->_float = OPA->_float == OPB->_float;
108 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
111 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
114 OPC->_float = OPA->_int == OPB->_int;
117 OPC->_float = OPA->function == OPB->function;
120 OPC->_float = OPA->_float != OPB->_float;
123 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
126 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
129 OPC->_float = OPA->_int != OPB->_int;
132 OPC->_float = OPA->function != OPB->function;
138 case OP_STORE_FLD: // integers
140 case OP_STORE_FNC: // pointers
141 OPB->_int = OPA->_int;
144 OPB->ivector[0] = OPA->ivector[0];
145 OPB->ivector[1] = OPA->ivector[1];
146 OPB->ivector[2] = OPA->ivector[2];
151 case OP_STOREP_FLD: // integers
153 case OP_STOREP_FNC: // pointers
154 if (OPB->_int < 0 || OPB->_int + 1 > prog->entityfieldsarea)
156 prog->xfunction->profile += (st - startst);
157 prog->xstatement = st - prog->statements;
158 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
161 if (OPB->_int < prog->progs->entityfields && !prog->allowworldwrites)
162 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);
163 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
164 ptr->_int = OPA->_int;
167 if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea)
169 prog->xfunction->profile += (st - startst);
170 prog->xstatement = st - prog->statements;
171 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
174 if (OPB->_int < prog->progs->entityfields && !prog->allowworldwrites)
175 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);
176 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
177 ptr->ivector[0] = OPA->ivector[0];
178 ptr->ivector[1] = OPA->ivector[1];
179 ptr->ivector[2] = OPA->ivector[2];
183 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
185 prog->xfunction->profile += (st - startst);
186 prog->xstatement = st - prog->statements;
187 PRVM_ERROR ("%s Progs attempted to address an out of bounds edict number", PRVM_NAME);
190 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
192 prog->xfunction->profile += (st - startst);
193 prog->xstatement = st - prog->statements;
194 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
198 if (OPA->edict == 0 && !prog->allowworldwrites)
200 prog->xfunction->profile += (st - startst);
201 prog->xstatement = st - prog->statements;
202 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
206 ed = PRVM_PROG_TO_EDICT(OPA->edict);
207 OPC->_int = ed->fields.vp - prog->edictsfields + OPB->_int;
215 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
217 prog->xfunction->profile += (st - startst);
218 prog->xstatement = st - prog->statements;
219 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
222 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
224 prog->xfunction->profile += (st - startst);
225 prog->xstatement = st - prog->statements;
226 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
229 ed = PRVM_PROG_TO_EDICT(OPA->edict);
230 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
234 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
236 prog->xfunction->profile += (st - startst);
237 prog->xstatement = st - prog->statements;
238 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
241 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
243 prog->xfunction->profile += (st - startst);
244 prog->xstatement = st - prog->statements;
245 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
248 ed = PRVM_PROG_TO_EDICT(OPA->edict);
249 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
250 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
251 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
257 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
258 // TODO add an "int-if", and change this one to OPA->_float
259 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
260 // and entity, string, field values can never have that value
262 prog->xfunction->profile += (st - startst);
263 st += st->b - 1; // offset the s++
265 // no bounds check needed, it is done when loading progs
266 if (++jumpcount == 10000000 && prvm_runawaycheck)
268 prog->xstatement = st - prog->statements;
269 PRVM_Profile(1<<30, 1000000, 0);
270 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
276 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
277 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
278 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
279 // and entity, string, field values can never have that value
281 prog->xfunction->profile += (st - startst);
282 st += st->b - 1; // offset the s++
284 // no bounds check needed, it is done when loading progs
285 if (++jumpcount == 10000000 && prvm_runawaycheck)
287 prog->xstatement = st - prog->statements;
288 PRVM_Profile(1<<30, 1000000, 0);
289 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
295 prog->xfunction->profile += (st - startst);
296 st += st->a - 1; // offset the s++
298 // no bounds check needed, it is done when loading progs
299 if (++jumpcount == 10000000 && prvm_runawaycheck)
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);
316 prog->xfunction->profile += (st - startst);
318 prog->xstatement = st - prog->statements;
319 prog->argc = st->op - OP_CALL0;
321 PRVM_ERROR("NULL function in %s", PRVM_NAME);
323 if(!OPA->function || OPA->function >= (unsigned int)prog->progs->numfunctions)
325 prog->xfunction->profile += (st - startst);
326 prog->xstatement = st - prog->statements; // we better stay on the previously executed statement
327 PRVM_ERROR("%s CALL outside the program", PRVM_NAME);
331 newf = &prog->functions[OPA->function];
334 if (newf->first_statement < 0)
336 // negative statements are built in functions
337 int builtinnumber = -newf->first_statement;
338 prog->xfunction->builtinsprofile++;
339 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
340 prog->builtins[builtinnumber]();
342 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
345 st = prog->statements + PRVM_EnterFunction(newf);
351 prog->xfunction->profile += (st - startst);
352 prog->xstatement = st - prog->statements;
354 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
355 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
356 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
358 st = prog->statements + PRVM_LeaveFunction();
360 if (prog->depth <= exitdepth)
361 goto cleanup; // all done
362 if (prog->trace != cachedpr_trace)
363 goto chooseexecprogram;
367 if(prog->flag & PRVM_OP_STATE)
369 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
370 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
371 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
372 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
376 prog->xfunction->profile += (st - startst);
377 prog->xstatement = st - prog->statements;
378 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
382 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
385 OPC->_int = OPA->_int + OPB->_int;
388 OPC->_int = OPA->_int + (int) OPB->_float;
391 OPC->_float = OPA->_float + (float) OPB->_int;
394 OPC->_int = OPA->_int - OPB->_int;
397 OPC->_int = OPA->_int - (int) OPB->_float;
400 OPC->_float = OPA->_float - (float) OPB->_int;
403 OPC->_int = OPA->_int * OPB->_int;
406 OPC->_int = OPA->_int * (int) OPB->_float;
409 OPC->_float = OPA->_float * (float) OPB->_int;
412 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
413 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
414 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
418 float temp = 1.0f / OPB->_float;
419 OPC->vector[0] = temp * OPA->vector[0];
420 OPC->vector[1] = temp * OPA->vector[1];
421 OPC->vector[2] = temp * OPA->vector[2];
425 OPC->_int = OPA->_int / OPB->_int;
428 OPC->_int = OPA->_int / (int) OPB->_float;
431 OPC->_float = OPA->_float / (float) OPB->_int;
434 OPC->_float = OPA->_int;
437 OPC->_int = OPA->_float;
440 OPC->_int = OPA->_int & OPB->_int;
443 OPC->_int = OPA->_int | OPB->_int;
446 OPC->_int = OPA->_int & (int)OPB->_float;
449 OPC->_int = OPA->_int | (int)OPB->_float;
452 OPC->_float = (int)OPA->_float & OPB->_int;
455 OPC->_float = (int)OPA->_float | OPB->_int;
458 OPC->_float = OPA->_int >= OPB->_int;
461 OPC->_float = OPA->_int <= OPB->_int;
464 OPC->_float = OPA->_int > OPB->_int;
467 OPC->_float = OPA->_int < OPB->_int;
470 OPC->_float = OPA->_int && OPB->_int;
473 OPC->_float = OPA->_int || OPB->_int;
476 OPC->_float = (float)OPA->_int >= OPB->_float;
479 OPC->_float = (float)OPA->_int <= OPB->_float;
482 OPC->_float = (float)OPA->_int > OPB->_float;
485 OPC->_float = (float)OPA->_int < OPB->_float;
488 OPC->_float = (float)OPA->_int && OPB->_float;
491 OPC->_float = (float)OPA->_int || OPB->_float;
494 OPC->_float = OPA->_float >= (float)OPB->_int;
497 OPC->_float = OPA->_float <= (float)OPB->_int;
500 OPC->_float = OPA->_float > (float)OPB->_int;
503 OPC->_float = OPA->_float < (float)OPB->_int;
506 OPC->_float = OPA->_float && (float)OPB->_int;
509 OPC->_float = OPA->_float || (float)OPB->_int;
512 OPC->_float = !OPA->_int;
515 OPC->_float = OPA->_int == OPB->_int;
518 OPC->_float = (float)OPA->_int == OPB->_float;
521 OPC->_float = OPA->_float == (float)OPB->_int;
524 OPC->_float = OPA->_int != OPB->_int;
527 OPC->_float = (float)OPA->_int != OPB->_float;
530 OPC->_float = OPA->_float != (float)OPB->_int;
533 OPB->_int = OPA->_int;
537 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
539 prog->xfunction->profile += (st - startst);
540 prog->xstatement = st - prog->statements;
541 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
545 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
546 ptr->_int = OPA->_int;
550 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
552 prog->xfunction->profile += (st - startst);
553 prog->xstatement = st - prog->statements;
554 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
557 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
559 prog->xfunction->profile += (st - startst);
560 prog->xstatement = st - prog->statements;
561 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
565 ed = PRVM_PROG_TO_EDICT(OPA->edict);
566 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
572 case OP_GSTOREP_FLD: // integers
574 case OP_GSTOREP_FNC: // pointers
576 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
578 prog->xfunction->profile += (st - startst);
579 prog->xstatement = st - prog->statements;
580 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
584 pr_iglobals[OPB->_int] = OPA->_int;
588 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
590 prog->xfunction->profile += (st - startst);
591 prog->xstatement = st - prog->statements;
592 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
596 pr_iglobals[OPB->_int ] = OPA->ivector[0];
597 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
598 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
602 i = OPA->_int + (int) OPB->_float;
604 if (i < 0 || i >= pr_globaldefs)
606 prog->xfunction->profile += (st - startst);
607 prog->xstatement = st - prog->statements;
608 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
612 OPC->_int = pr_iglobals[i];
622 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
624 prog->xfunction->profile += (st - startst);
625 prog->xstatement = st - prog->statements;
626 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
630 OPC->_int = pr_iglobals[OPA->_int];
635 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
637 prog->xfunction->profile += (st - startst);
638 prog->xstatement = st - prog->statements;
639 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
643 OPC->ivector[0] = pr_iglobals[OPA->_int ];
644 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
645 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
649 if (OPA->_int < 0 || OPA->_int >= st->b)
651 prog->xfunction->profile += (st - startst);
652 prog->xstatement = st - prog->statements;
653 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
661 prog->xfunction->profile += (st - startst);
662 prog->xstatement = st - prog->statements;
663 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);