1 #ifdef PRVMTIMEPROFILING
3 prog->xstatement = st - prog->statements; \
4 tm = Sys_DirtyTime(); \
5 prog->xfunction->profile += (st - startst); \
6 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
9 prog->xstatement = st - prog->statements; \
10 prog->xfunction->profile += (st - startst);
13 // This code isn't #ifdef/#define protectable, don't try.
15 #if PRVMSLOWINTERPRETER
17 if (prog->watch_global_type != ev_void)
19 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
20 prog->xstatement = st + 1 - prog->statements;
21 PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, f);
23 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
25 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
26 prog->xstatement = st + 1 - prog->statements;
27 PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, f);
36 #if PRVMSLOWINTERPRETER
38 PRVM_PrintStatement(prog, st);
39 prog->statement_profile[st - prog->statements]++;
40 if (prog->break_statement >= 0)
41 if ((st - prog->statements) == prog->break_statement)
43 prog->xstatement = st - prog->statements;
44 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
51 OPC->_float = OPA->_float + OPB->_float;
54 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
55 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
56 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
59 OPC->_float = OPA->_float - OPB->_float;
62 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
63 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
64 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
67 OPC->_float = OPA->_float * OPB->_float;
70 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
73 tempfloat = OPA->_float;
74 OPC->vector[0] = tempfloat * OPB->vector[0];
75 OPC->vector[1] = tempfloat * OPB->vector[1];
76 OPC->vector[2] = tempfloat * OPB->vector[2];
79 tempfloat = OPB->_float;
80 OPC->vector[0] = tempfloat * OPA->vector[0];
81 OPC->vector[1] = tempfloat * OPA->vector[1];
82 OPC->vector[2] = tempfloat * OPA->vector[2];
85 if( OPB->_float != 0.0f )
87 OPC->_float = OPA->_float / OPB->_float;
91 if (developer.integer)
93 prog->xfunction->profile += (st - startst);
95 prog->xstatement = st - prog->statements;
96 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
102 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
105 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
108 OPC->_float = OPA->_float >= OPB->_float;
111 OPC->_float = OPA->_float <= OPB->_float;
114 OPC->_float = OPA->_float > OPB->_float;
117 OPC->_float = OPA->_float < OPB->_float;
120 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
123 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
126 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
129 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
132 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
135 OPC->_float = !OPA->function;
138 OPC->_float = (OPA->edict == 0);
141 OPC->_float = OPA->_float == OPB->_float;
144 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
147 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
150 OPC->_float = OPA->_int == OPB->_int;
153 OPC->_float = OPA->function == OPB->function;
156 OPC->_float = OPA->_float != OPB->_float;
159 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
162 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
165 OPC->_float = OPA->_int != OPB->_int;
168 OPC->_float = OPA->function != OPB->function;
174 case OP_STORE_FLD: // integers
176 case OP_STORE_FNC: // pointers
177 OPB->_int = OPA->_int;
180 OPB->ivector[0] = OPA->ivector[0];
181 OPB->ivector[1] = OPA->ivector[1];
182 OPB->ivector[2] = OPA->ivector[2];
187 case OP_STOREP_FLD: // integers
189 case OP_STOREP_FNC: // pointers
190 if (OPB->_int < 0 || OPB->_int + 1 > prog->entityfieldsarea)
193 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
196 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
198 prog->xstatement = st - prog->statements;
199 VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
201 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
202 ptr->_int = OPA->_int;
205 if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea)
208 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
211 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
213 prog->xstatement = st - prog->statements;
214 VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
216 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
217 ptr->ivector[0] = OPA->ivector[0];
218 ptr->ivector[1] = OPA->ivector[1];
219 ptr->ivector[2] = OPA->ivector[2];
223 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
226 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
229 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
232 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
236 if (OPA->edict == 0 && !prog->allowworldwrites)
239 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
243 ed = PRVM_PROG_TO_EDICT(OPA->edict);
244 OPC->_int = ed->fields.fp - prog->edictsfields + OPB->_int;
252 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
255 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
258 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
261 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
264 ed = PRVM_PROG_TO_EDICT(OPA->edict);
265 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
269 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
272 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
275 if (OPB->_int < 0 || OPB->_int + 2 >= prog->entityfields)
278 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
281 ed = PRVM_PROG_TO_EDICT(OPA->edict);
282 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
283 OPC->ivector[0] = ptr->ivector[0];
284 OPC->ivector[1] = ptr->ivector[1];
285 OPC->ivector[2] = ptr->ivector[2];
291 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
292 // TODO add an "int-if", and change this one to OPA->_float
293 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
294 // and entity, string, field values can never have that value
296 prog->xfunction->profile += (st - startst);
297 st = prog->statements + st->jumpabsolute - 1; // offset the st++
299 // no bounds check needed, it is done when loading progs
300 if (++jumpcount == 10000000 && prvm_runawaycheck)
302 prog->xstatement = st - prog->statements;
303 PRVM_Profile(prog, 1<<30, 1000000, 0);
304 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
310 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
311 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
312 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
313 // and entity, string, field values can never have that value
315 prog->xfunction->profile += (st - startst);
316 st = prog->statements + st->jumpabsolute - 1; // offset the st++
318 // no bounds check needed, it is done when loading progs
319 if (++jumpcount == 10000000 && prvm_runawaycheck)
321 prog->xstatement = st - prog->statements;
322 PRVM_Profile(prog, 1<<30, 0.01, 0);
323 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
329 prog->xfunction->profile += (st - startst);
330 st = prog->statements + st->jumpabsolute - 1; // offset the st++
332 // no bounds check needed, it is done when loading progs
333 if (++jumpcount == 10000000 && prvm_runawaycheck)
335 prog->xstatement = st - prog->statements;
336 PRVM_Profile(prog, 1<<30, 0.01, 0);
337 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
350 #ifdef PRVMTIMEPROFILING
351 tm = Sys_DirtyTime();
352 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
355 prog->xfunction->profile += (st - startst);
357 prog->xstatement = st - prog->statements;
358 prog->argc = st->op - OP_CALL0;
360 prog->error_cmd("NULL function in %s", prog->name);
362 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
365 prog->error_cmd("%s CALL outside the program", prog->name);
369 newf = &prog->functions[OPA->function];
372 if (newf->first_statement < 0)
374 // negative statements are built in functions
375 int builtinnumber = -newf->first_statement;
376 prog->xfunction->builtinsprofile++;
377 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
379 prog->builtins[builtinnumber](prog);
380 #ifdef PRVMTIMEPROFILING
381 tm = Sys_DirtyTime();
382 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
383 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
388 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
390 if (prog->trace != cachedpr_trace)
391 goto chooseexecprogram;
394 st = prog->statements + PRVM_EnterFunction(prog, newf);
400 #ifdef PRVMTIMEPROFILING
401 tm = Sys_DirtyTime();
402 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
405 prog->xfunction->profile += (st - startst);
406 prog->xstatement = st - prog->statements;
408 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
409 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
410 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
412 st = prog->statements + PRVM_LeaveFunction(prog);
414 if (prog->depth <= exitdepth)
415 goto cleanup; // all done
419 if(prog->flag & PRVM_OP_STATE)
421 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
422 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
423 PRVM_gameedictfloat(ed,frame) = OPA->_float;
424 PRVM_gameedictfunction(ed,think) = OPB->function;
429 prog->xstatement = st - prog->statements;
430 prog->error_cmd("OP_STATE not supported by %s", prog->name);
434 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
437 OPC->_int = OPA->_int + OPB->_int;
440 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
443 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
446 OPC->_int = OPA->_int - OPB->_int;
449 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
452 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
455 OPC->_int = OPA->_int * OPB->_int;
458 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
461 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
464 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
465 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
466 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
470 float temp = 1.0f / OPB->_float;
471 OPC->vector[0] = temp * OPA->vector[0];
472 OPC->vector[1] = temp * OPA->vector[1];
473 OPC->vector[2] = temp * OPA->vector[2];
477 OPC->_int = OPA->_int / OPB->_int;
480 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
483 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
486 OPC->_float = OPA->_int;
489 OPC->_int = OPA->_float;
492 OPC->_int = OPA->_int & OPB->_int;
495 OPC->_int = OPA->_int | OPB->_int;
498 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
501 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
504 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
507 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
510 OPC->_float = OPA->_int >= OPB->_int;
513 OPC->_float = OPA->_int <= OPB->_int;
516 OPC->_float = OPA->_int > OPB->_int;
519 OPC->_float = OPA->_int < OPB->_int;
522 OPC->_float = OPA->_int && OPB->_int;
525 OPC->_float = OPA->_int || OPB->_int;
528 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
531 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
534 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
537 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
540 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
543 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
546 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
549 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
552 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
555 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
558 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
561 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
564 OPC->_float = !OPA->_int;
567 OPC->_float = OPA->_int == OPB->_int;
570 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
573 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
576 OPC->_float = OPA->_int != OPB->_int;
579 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
582 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
585 OPB->_int = OPA->_int;
589 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
592 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
596 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
597 ptr->_int = OPA->_int;
601 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
604 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
607 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
610 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
614 ed = PRVM_PROG_TO_EDICT(OPA->edict);
615 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
621 case OP_GSTOREP_FLD: // integers
623 case OP_GSTOREP_FNC: // pointers
625 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
628 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
632 pr_iglobals[OPB->_int] = OPA->_int;
636 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
639 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
643 pr_iglobals[OPB->_int ] = OPA->ivector[0];
644 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
645 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
649 i = OPA->_int + (prvm_int_t) OPB->_float;
651 if (i < 0 || i >= pr_globaldefs)
654 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
658 OPC->_int = pr_iglobals[i];
668 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
671 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
675 OPC->_int = pr_iglobals[OPA->_int];
680 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
683 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
687 OPC->ivector[0] = pr_iglobals[OPA->_int ];
688 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
689 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
693 if (OPA->_int < 0 || OPA->_int >= st->b)
696 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
705 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
708 #if PRVMSLOWINTERPRETER
710 if (prog->watch_global_type != ev_void)
712 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
713 prog->xstatement = st - prog->statements;
714 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
716 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
718 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
719 prog->xstatement = st - prog->statements;
720 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);