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_vec_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 OPC->vector[0] = OPA->_float * OPB->vector[0];
74 OPC->vector[1] = OPA->_float * OPB->vector[1];
75 OPC->vector[2] = OPA->_float * OPB->vector[2];
78 OPC->vector[0] = OPB->_float * OPA->vector[0];
79 OPC->vector[1] = OPB->_float * OPA->vector[1];
80 OPC->vector[2] = OPB->_float * OPA->vector[2];
83 if( OPB->_float != 0.0f )
85 OPC->_float = OPA->_float / OPB->_float;
89 if (developer.integer)
91 prog->xfunction->profile += (st - startst);
93 prog->xstatement = st - prog->statements;
94 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
100 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
103 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
106 OPC->_float = OPA->_float >= OPB->_float;
109 OPC->_float = OPA->_float <= OPB->_float;
112 OPC->_float = OPA->_float > OPB->_float;
115 OPC->_float = OPA->_float < OPB->_float;
118 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
121 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
124 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
127 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
130 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
133 OPC->_float = !OPA->function;
136 OPC->_float = (OPA->edict == 0);
139 OPC->_float = OPA->_float == OPB->_float;
142 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
145 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
148 OPC->_float = OPA->_int == OPB->_int;
151 OPC->_float = OPA->function == OPB->function;
154 OPC->_float = OPA->_float != OPB->_float;
157 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
160 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
163 OPC->_float = OPA->_int != OPB->_int;
166 OPC->_float = OPA->function != OPB->function;
172 case OP_STORE_FLD: // integers
174 case OP_STORE_FNC: // pointers
175 OPB->_int = OPA->_int;
178 OPB->ivector[0] = OPA->ivector[0];
179 OPB->ivector[1] = OPA->ivector[1];
180 OPB->ivector[2] = OPA->ivector[2];
185 case OP_STOREP_FLD: // integers
187 case OP_STOREP_FNC: // pointers
188 if (OPB->_int < 0 || OPB->_int + 1 > prog->entityfieldsarea)
191 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
194 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
196 prog->xstatement = st - prog->statements;
197 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);
199 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
200 ptr->_int = OPA->_int;
203 if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea)
206 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
209 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
211 prog->xstatement = st - prog->statements;
212 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);
214 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
215 ptr->ivector[0] = OPA->ivector[0];
216 ptr->ivector[1] = OPA->ivector[1];
217 ptr->ivector[2] = OPA->ivector[2];
221 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
224 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
227 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
230 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
234 if (OPA->edict == 0 && !prog->allowworldwrites)
237 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
241 ed = PRVM_PROG_TO_EDICT(OPA->edict);
242 OPC->_int = ed->fields.fp - prog->edictsfields + OPB->_int;
250 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
253 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
256 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
259 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
262 ed = PRVM_PROG_TO_EDICT(OPA->edict);
263 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
267 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
270 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
273 if (OPB->_int < 0 || OPB->_int + 2 >= prog->entityfields)
276 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
279 ed = PRVM_PROG_TO_EDICT(OPA->edict);
280 OPC->ivector[0] = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->ivector[0];
281 OPC->ivector[1] = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->ivector[1];
282 OPC->ivector[2] = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->ivector[2];
288 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
289 // TODO add an "int-if", and change this one to OPA->_float
290 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
291 // and entity, string, field values can never have that value
293 prog->xfunction->profile += (st - startst);
294 st = prog->statements + st->jumpabsolute - 1; // offset the st++
296 // no bounds check needed, it is done when loading progs
297 if (++jumpcount == 10000000 && prvm_runawaycheck)
299 prog->xstatement = st - prog->statements;
300 PRVM_Profile(prog, 1<<30, 1000000, 0);
301 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
307 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
308 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
309 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
310 // and entity, string, field values can never have that value
312 prog->xfunction->profile += (st - startst);
313 st = prog->statements + st->jumpabsolute - 1; // offset the st++
315 // no bounds check needed, it is done when loading progs
316 if (++jumpcount == 10000000 && prvm_runawaycheck)
318 prog->xstatement = st - prog->statements;
319 PRVM_Profile(prog, 1<<30, 0.01, 0);
320 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
326 prog->xfunction->profile += (st - startst);
327 st = prog->statements + st->jumpabsolute - 1; // offset the st++
329 // no bounds check needed, it is done when loading progs
330 if (++jumpcount == 10000000 && prvm_runawaycheck)
332 prog->xstatement = st - prog->statements;
333 PRVM_Profile(prog, 1<<30, 0.01, 0);
334 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
347 #ifdef PRVMTIMEPROFILING
348 tm = Sys_DirtyTime();
349 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
352 prog->xfunction->profile += (st - startst);
354 prog->xstatement = st - prog->statements;
355 prog->argc = st->op - OP_CALL0;
357 prog->error_cmd("NULL function in %s", prog->name);
359 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
362 prog->error_cmd("%s CALL outside the program", prog->name);
366 newf = &prog->functions[OPA->function];
369 if (newf->first_statement < 0)
371 // negative statements are built in functions
372 int builtinnumber = -newf->first_statement;
373 prog->xfunction->builtinsprofile++;
374 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
376 prog->builtins[builtinnumber](prog);
377 #ifdef PRVMTIMEPROFILING
378 tm = Sys_DirtyTime();
379 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
380 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
385 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
387 if (prog->trace != cachedpr_trace)
388 goto chooseexecprogram;
391 st = prog->statements + PRVM_EnterFunction(prog, newf);
397 #ifdef PRVMTIMEPROFILING
398 tm = Sys_DirtyTime();
399 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
402 prog->xfunction->profile += (st - startst);
403 prog->xstatement = st - prog->statements;
405 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
406 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
407 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
409 st = prog->statements + PRVM_LeaveFunction(prog);
411 if (prog->depth <= exitdepth)
412 goto cleanup; // all done
416 if(prog->flag & PRVM_OP_STATE)
418 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
419 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
420 PRVM_gameedictfloat(ed,frame) = OPA->_float;
421 PRVM_gameedictfunction(ed,think) = OPB->function;
426 prog->xstatement = st - prog->statements;
427 prog->error_cmd("OP_STATE not supported by %s", prog->name);
431 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
434 OPC->_int = OPA->_int + OPB->_int;
437 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
440 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
443 OPC->_int = OPA->_int - OPB->_int;
446 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
449 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
452 OPC->_int = OPA->_int * OPB->_int;
455 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
458 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
461 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
462 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
463 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
467 float temp = 1.0f / OPB->_float;
468 OPC->vector[0] = temp * OPA->vector[0];
469 OPC->vector[1] = temp * OPA->vector[1];
470 OPC->vector[2] = temp * OPA->vector[2];
474 OPC->_int = OPA->_int / OPB->_int;
477 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
480 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
483 OPC->_float = OPA->_int;
486 OPC->_int = OPA->_float;
489 OPC->_int = OPA->_int & OPB->_int;
492 OPC->_int = OPA->_int | OPB->_int;
495 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
498 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
501 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
504 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
507 OPC->_float = OPA->_int >= 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 = (prvm_vec_t)OPA->_int >= OPB->_float;
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 = OPA->_float >= (prvm_vec_t)OPB->_int;
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->_int;
564 OPC->_float = OPA->_int == OPB->_int;
567 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
570 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
573 OPC->_float = OPA->_int != OPB->_int;
576 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
579 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
582 OPB->_int = OPA->_int;
586 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
589 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
593 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
594 ptr->_int = OPA->_int;
598 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
601 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
604 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
607 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
611 ed = PRVM_PROG_TO_EDICT(OPA->edict);
612 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
618 case OP_GSTOREP_FLD: // integers
620 case OP_GSTOREP_FNC: // pointers
622 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
625 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
629 pr_iglobals[OPB->_int] = OPA->_int;
633 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
636 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
640 pr_iglobals[OPB->_int ] = OPA->ivector[0];
641 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
642 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
646 i = OPA->_int + (prvm_int_t) OPB->_float;
648 if (i < 0 || i >= pr_globaldefs)
651 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
655 OPC->_int = pr_iglobals[i];
665 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
668 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
672 OPC->_int = pr_iglobals[OPA->_int];
677 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
680 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
684 OPC->ivector[0] = pr_iglobals[OPA->_int ];
685 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
686 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
690 if (OPA->_int < 0 || OPA->_int >= st->b)
693 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
702 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
705 #if PRVMSLOWINTERPRETER
707 if (prog->watch_global_type != ev_void)
709 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
710 prog->xstatement = st - prog->statements;
711 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
713 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
715 prvm_vec_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
716 prog->xstatement = st - prog->statements;
717 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);