2 // This code isn't #ifdef/#define protectable, don't try.
6 st++; // TODO bounds check
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 = OPA->_float && OPB->_float;
88 OPC->_float = OPA->_float || OPB->_float;
91 OPC->_float = !OPA->_float;
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 + 4 > prog->edictareasize)
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 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
165 ptr->_int = OPA->_int;
169 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
171 prog->xfunction->profile += (st - startst);
172 prog->xstatement = st - prog->statements;
173 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
177 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
178 ptr->ivector[0] = OPA->ivector[0];
179 ptr->ivector[1] = OPA->ivector[1];
180 ptr->ivector[2] = OPA->ivector[2];
185 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
187 prog->xfunction->profile += (st - startst);
188 prog->xstatement = st - prog->statements;
189 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
193 if (OPA->edict == 0 && !prog->allowworldwrites)
195 prog->xfunction->profile += (st - startst);
196 prog->xstatement = st - prog->statements;
197 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
200 ed = PRVM_PROG_TO_EDICT(OPA->edict);
201 OPC->_int = (unsigned char *)((int *)ed->fields.vp + OPB->_int) - (unsigned char *)prog->edictsfields;
210 if ((unsigned int)(OPB->_int) >= (unsigned int)(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); // TODO bounds check entity number
219 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
224 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
226 prog->xfunction->profile += (st - startst);
227 prog->xstatement = st - prog->statements;
228 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
232 ed = PRVM_PROG_TO_EDICT(OPA->edict); // TODO bounds check entity number
233 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
234 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
235 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
242 // TODO add an "int-ifnot"
243 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
244 // and entity, string, field values can never have that value
246 prog->xfunction->profile += (st - startst);
247 st += st->b - 1; // offset the s++
250 if (++jumpcount == 10000000)
252 prog->xstatement = st - prog->statements;
253 PRVM_Profile(1<<30, 1000000);
254 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
262 // TODO add an "int-if"
263 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
264 // and entity, string, field values can never have that value
266 prog->xfunction->profile += (st - startst);
267 st += st->b - 1; // offset the s++
270 if (++jumpcount == 10000000)
272 prog->xstatement = st - prog->statements;
273 PRVM_Profile(1<<30, 1000000);
274 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
281 prog->xfunction->profile += (st - startst);
282 st += st->a - 1; // offset the s++
285 if (++jumpcount == 10000000)
287 prog->xstatement = st - prog->statements;
288 PRVM_Profile(1<<30, 1000000);
289 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
303 prog->xfunction->profile += (st - startst);
305 prog->xstatement = st - prog->statements;
306 prog->argc = st->op - OP_CALL0;
308 PRVM_ERROR("NULL function in %s", PRVM_NAME);
309 newf = &prog->functions[OPA->function]; // TODO bounds check function
312 if (newf->first_statement < 0)
314 // negative statements are built in functions
315 int builtinnumber = -newf->first_statement;
316 prog->xfunction->builtinsprofile++;
317 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
318 prog->builtins[builtinnumber]();
320 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
323 st = prog->statements + PRVM_EnterFunction(newf);
329 prog->xfunction->profile += (st - startst);
330 prog->xstatement = st - prog->statements;
332 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
333 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
334 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
336 st = prog->statements + PRVM_LeaveFunction();
338 if (prog->depth <= exitdepth)
339 goto cleanup; // all done
340 if (prog->trace != cachedpr_trace)
341 goto chooseexecprogram;
345 if(prog->flag & PRVM_OP_STATE)
347 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
348 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
349 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
350 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
354 prog->xfunction->profile += (st - startst);
355 prog->xstatement = st - prog->statements;
356 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
360 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
363 OPC->_int = OPA->_int + OPB->_int;
366 OPC->_int = OPA->_int + (int) OPB->_float;
369 OPC->_float = OPA->_float + (float) OPB->_int;
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->_int = OPA->_int * OPB->_int;
384 OPC->_int = OPA->_int * (int) OPB->_float;
387 OPC->_float = OPA->_float * (float) OPB->_int;
390 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
391 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
392 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
396 float temp = 1.0f / OPB->_float;
397 OPC->vector[0] = temp * OPA->vector[0];
398 OPC->vector[1] = temp * OPA->vector[1];
399 OPC->vector[2] = temp * OPA->vector[2];
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->_float = OPA->_int;
415 OPC->_int = OPA->_float;
418 OPC->_int = OPA->_int & OPB->_int;
421 OPC->_int = OPA->_int | OPB->_int;
424 OPC->_int = OPA->_int & (int)OPB->_float;
427 OPC->_int = OPA->_int | (int)OPB->_float;
430 OPC->_float = (int)OPA->_float & OPB->_int;
433 OPC->_float = (int)OPA->_float | OPB->_int;
436 OPC->_float = OPA->_int >= OPB->_int;
439 OPC->_float = OPA->_int <= OPB->_int;
442 OPC->_float = OPA->_int > OPB->_int;
445 OPC->_float = OPA->_int < OPB->_int;
448 OPC->_float = OPA->_int && OPB->_int;
451 OPC->_float = OPA->_int || OPB->_int;
454 OPC->_float = (float)OPA->_int >= OPB->_float;
457 OPC->_float = (float)OPA->_int <= OPB->_float;
460 OPC->_float = (float)OPA->_int > OPB->_float;
463 OPC->_float = (float)OPA->_int < OPB->_float;
466 OPC->_float = (float)OPA->_int && OPB->_float;
469 OPC->_float = (float)OPA->_int || OPB->_float;
472 OPC->_float = OPA->_float >= (float)OPB->_int;
475 OPC->_float = OPA->_float <= (float)OPB->_int;
478 OPC->_float = OPA->_float > (float)OPB->_int;
481 OPC->_float = OPA->_float < (float)OPB->_int;
484 OPC->_float = OPA->_float && (float)OPB->_int;
487 OPC->_float = OPA->_float || (float)OPB->_int;
490 OPC->_float = !OPA->_int;
493 OPC->_float = OPA->_int == OPB->_int;
496 OPC->_float = (float)OPA->_int == OPB->_float;
499 OPC->_float = OPA->_float == (float)OPB->_int;
502 OPC->_float = OPA->_int != OPB->_int;
505 OPC->_float = (float)OPA->_int != OPB->_float;
508 OPC->_float = OPA->_float != (float)OPB->_int;
511 OPB->_int = OPA->_int;
515 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
517 prog->xfunction->profile += (st - startst);
518 prog->xstatement = st - prog->statements;
519 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
523 ptr = (prvm_eval_t *)((unsigned char *)prog->edictsfields + OPB->_int);
524 ptr->_int = OPA->_int;
528 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
530 prog->xfunction->profile += (st - startst);
531 prog->xstatement = st - prog->statements;
532 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
535 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
537 prog->xfunction->profile += (st - startst);
538 prog->xstatement = st - prog->statements;
539 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
543 ed = PRVM_PROG_TO_EDICT(OPA->edict);
544 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
550 case OP_GSTOREP_FLD: // integers
552 case OP_GSTOREP_FNC: // pointers
554 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
556 prog->xfunction->profile += (st - startst);
557 prog->xstatement = st - prog->statements;
558 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
562 pr_iglobals[OPB->_int] = OPA->_int;
566 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
568 prog->xfunction->profile += (st - startst);
569 prog->xstatement = st - prog->statements;
570 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
574 pr_iglobals[OPB->_int ] = OPA->ivector[0];
575 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
576 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
580 i = OPA->_int + (int) OPB->_float;
582 if (i < 0 || i >= pr_globaldefs)
584 prog->xfunction->profile += (st - startst);
585 prog->xstatement = st - prog->statements;
586 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
590 OPC->_int = pr_iglobals[i];
600 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
602 prog->xfunction->profile += (st - startst);
603 prog->xstatement = st - prog->statements;
604 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
608 OPC->_int = pr_iglobals[OPA->_int];
613 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
615 prog->xfunction->profile += (st - startst);
616 prog->xstatement = st - prog->statements;
617 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
621 OPC->ivector[0] = pr_iglobals[OPA->_int ];
622 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
623 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
627 if (OPA->_int < 0 || OPA->_int >= st->b)
629 prog->xfunction->profile += (st - startst);
630 prog->xstatement = st - prog->statements;
631 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
639 prog->xfunction->profile += (st - startst);
640 prog->xstatement = st - prog->statements;
641 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);