2 // This code isn't #ifdef/#define protectable, don't try.
7 if (++profile > 10000000) // LordHavoc: increased runaway loop limit 100x
9 // LordHavoc: update profile counter for debugging reasons
10 // (identifying erroneous loops and recursion patterns)
11 prog->xfunction->profile += profile - startprofile;
12 startprofile = profile;
13 // update the statement number before we error out
14 prog->xstatement = st - prog->statements;
15 PRVM_ERROR("runaway loop counter hit limit of %d opcodes\ntip: if having trouble identifying the problem, try typing profile now in %s", profile, PRVM_NAME);
19 prog->xfunction->profile += profile - startprofile;
20 startprofile = profile;
21 prog->xstatement = st - prog->statements;
22 PRVM_PrintStatement(st);
28 OPC->_float = OPA->_float + OPB->_float;
31 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
32 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
33 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
36 OPC->_float = OPA->_float - OPB->_float;
39 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
40 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
41 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
44 OPC->_float = OPA->_float * OPB->_float;
47 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
50 OPC->vector[0] = OPA->_float * OPB->vector[0];
51 OPC->vector[1] = OPA->_float * OPB->vector[1];
52 OPC->vector[2] = OPA->_float * OPB->vector[2];
55 OPC->vector[0] = OPB->_float * OPA->vector[0];
56 OPC->vector[1] = OPB->_float * OPA->vector[1];
57 OPC->vector[2] = OPB->_float * OPA->vector[2];
60 OPC->_float = OPA->_float / OPB->_float;
63 OPC->_float = (int)OPA->_float & (int)OPB->_float;
66 OPC->_float = (int)OPA->_float | (int)OPB->_float;
69 OPC->_float = OPA->_float >= 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 = OPA->_float || OPB->_float;
87 OPC->_float = !OPA->_float;
90 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
93 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
96 OPC->_float = !OPA->function;
99 OPC->_float = (OPA->edict == 0);
102 OPC->_float = OPA->_float == OPB->_float;
105 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
108 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
111 OPC->_float = OPA->_int == OPB->_int;
114 OPC->_float = OPA->function == OPB->function;
117 OPC->_float = OPA->_float != OPB->_float;
120 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
123 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
126 OPC->_float = OPA->_int != OPB->_int;
129 OPC->_float = OPA->function != OPB->function;
135 case OP_STORE_FLD: // integers
137 case OP_STORE_FNC: // pointers
138 OPB->_int = OPA->_int;
141 OPB->ivector[0] = OPA->ivector[0];
142 OPB->ivector[1] = OPA->ivector[1];
143 OPB->ivector[2] = OPA->ivector[2];
148 case OP_STOREP_FLD: // integers
150 case OP_STOREP_FNC: // pointers
152 if (OPB->_int < 0 || OPB->_int + 4 > prog->edictareasize)
154 prog->xfunction->profile += profile - startprofile;
155 startprofile = profile;
156 prog->xstatement = st - prog->statements;
157 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)\n", PRVM_NAME, OPB->_int);
161 ptr = (prvm_eval_t *)((qbyte *)prog->edictsfields + OPB->_int);
162 ptr->_int = OPA->_int;
166 if (OPB->_int < 0 || OPB->_int + 12 > prog->edictareasize)
168 prog->xfunction->profile += profile - startprofile;
169 startprofile = profile;
170 prog->xstatement = st - prog->statements;
171 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)\n", PRVM_NAME, OPB->_int);
175 ptr = (prvm_eval_t *)((qbyte *)prog->edictsfields + OPB->_int);
176 ptr->vector[0] = OPA->vector[0];
177 ptr->vector[1] = OPA->vector[1];
178 ptr->vector[2] = OPA->vector[2];
183 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
185 prog->xfunction->profile += profile - startprofile;
186 startprofile = profile;
187 prog->xstatement = st - prog->statements;
188 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict\n", PRVM_NAME, OPB->_int);
192 /*if (OPA->edict == 0 && sv.state == ss_active)
194 prog->xfunction->profile += profile - startprofile;
195 startprofile = profile;
196 prog->xstatement = st - prog->statements;
197 Host_Error("assignment to world entity in %s", PRVM_NAME);
200 ed = PRVM_PROG_TO_EDICT(OPA->edict);
201 OPC->_int = (qbyte *)((int *)ed->fields.vp + OPB->_int) - (qbyte *)prog->edictsfields;
210 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
212 prog->xfunction->profile += profile - startprofile;
213 startprofile = profile;
214 prog->xstatement = st - prog->statements;
215 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)\n", PRVM_NAME, OPB->_int);
219 ed = PRVM_PROG_TO_EDICT(OPA->edict);
220 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
225 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
227 prog->xfunction->profile += profile - startprofile;
228 startprofile = profile;
229 prog->xstatement = st - prog->statements;
230 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)\n", PRVM_NAME, OPB->_int);
234 ed = PRVM_PROG_TO_EDICT(OPA->edict);
235 OPC->vector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[0];
236 OPC->vector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[1];
237 OPC->vector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->vector[2];
244 st += st->b - 1; // offset the s++
249 st += st->b - 1; // offset the s++
253 st += st->a - 1; // offset the s++
265 prog->xfunction->profile += profile - startprofile;
266 startprofile = profile;
267 prog->xstatement = st - prog->statements;
268 prog->argc = st->op - OP_CALL0;
270 PRVM_ERROR("NULL function in %s", PRVM_NAME);
272 newf = &prog->functions[OPA->function];
275 if (newf->first_statement < 0)
277 // negative statements are built in functions
278 int builtinnumber = -newf->first_statement;
279 prog->xfunction->builtinsprofile++;
280 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
281 prog->builtins[builtinnumber]();
283 PRVM_ERROR("No such builtin #%i in %s", builtinnumber, PRVM_NAME);
286 st = prog->statements + PRVM_EnterFunction(newf);
291 prog->xfunction->profile += profile - startprofile;
292 startprofile = profile;
293 prog->xstatement = st - prog->statements;
295 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
296 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
297 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
299 st = prog->statements + PRVM_LeaveFunction();
300 if (prog->depth <= exitdepth)
302 if (prog->trace != cachedpr_trace)
303 goto chooseexecprogram;
307 if(prog->flag & PRVM_OP_STATE)
309 prog->xfunction->profile += profile - startprofile;
310 startprofile = profile;
311 prog->xstatement = st - prog->statements;
312 ed = PRVM_PROG_TO_EDICT(PRVM_G_INT(prog->self->ofs));
313 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("nextthink")->ofs) = *prog->time + 0.1;
314 PRVM_E_FLOAT(ed,PRVM_ED_FindField ("frame")->ofs) = OPA->_float;
315 *(func_t *)((float*)ed->fields.vp + PRVM_ED_FindField ("think")->ofs) = OPB->function;
318 PRVM_ERROR("OP_STATE not supported by %s\n", PRVM_NAME);
321 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
324 OPC->_int = OPA->_int + OPB->_int;
327 OPC->_int = OPA->_int + (int) OPB->_float;
330 OPC->_float = OPA->_float + (float) OPB->_int;
333 OPC->_int = OPA->_int - OPB->_int;
336 OPC->_int = OPA->_int - (int) OPB->_float;
339 OPC->_float = OPA->_float - (float) OPB->_int;
342 OPC->_int = OPA->_int * OPB->_int;
345 OPC->_int = OPA->_int * (int) OPB->_float;
348 OPC->_float = OPA->_float * (float) OPB->_int;
351 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
352 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
353 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
357 float temp = 1.0f / OPB->_float;
358 OPC->vector[0] = temp * OPA->vector[0];
359 OPC->vector[1] = temp * OPA->vector[1];
360 OPC->vector[2] = temp * OPA->vector[2];
364 OPC->_int = OPA->_int / OPB->_int;
367 OPC->_int = OPA->_int / (int) OPB->_float;
370 OPC->_float = OPA->_float / (float) OPB->_int;
373 OPC->_float = OPA->_int;
376 OPC->_int = OPA->_float;
379 OPC->_int = OPA->_int & OPB->_int;
382 OPC->_int = OPA->_int | OPB->_int;
385 OPC->_int = OPA->_int & (int)OPB->_float;
388 OPC->_int = OPA->_int | (int)OPB->_float;
391 OPC->_float = (int)OPA->_float & OPB->_int;
394 OPC->_float = (int)OPA->_float | OPB->_int;
397 OPC->_float = OPA->_int >= OPB->_int;
400 OPC->_float = OPA->_int <= OPB->_int;
403 OPC->_float = OPA->_int > OPB->_int;
406 OPC->_float = OPA->_int < OPB->_int;
409 OPC->_float = OPA->_int && OPB->_int;
412 OPC->_float = OPA->_int || OPB->_int;
415 OPC->_float = (float)OPA->_int >= OPB->_float;
418 OPC->_float = (float)OPA->_int <= OPB->_float;
421 OPC->_float = (float)OPA->_int > OPB->_float;
424 OPC->_float = (float)OPA->_int < OPB->_float;
427 OPC->_float = (float)OPA->_int && OPB->_float;
430 OPC->_float = (float)OPA->_int || OPB->_float;
433 OPC->_float = OPA->_float >= (float)OPB->_int;
436 OPC->_float = OPA->_float <= (float)OPB->_int;
439 OPC->_float = OPA->_float > (float)OPB->_int;
442 OPC->_float = OPA->_float < (float)OPB->_int;
445 OPC->_float = OPA->_float && (float)OPB->_int;
448 OPC->_float = OPA->_float || (float)OPB->_int;
451 OPC->_float = !OPA->_int;
454 OPC->_float = OPA->_int == OPB->_int;
457 OPC->_float = (float)OPA->_int == OPB->_float;
460 OPC->_float = OPA->_float == (float)OPB->_int;
463 OPC->_float = OPA->_int != OPB->_int;
466 OPC->_float = (float)OPA->_int != OPB->_float;
469 OPC->_float = OPA->_float != (float)OPB->_int;
472 OPB->_int = OPA->_int;
476 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
478 pr_xfunction->profile += profile - startprofile;
479 startprofile = profile;
480 pr_xstatement = st - pr_statements;
481 Host_Error("Progs attempted to write to an out of bounds edict\n");
485 ptr = (prvm_eval_t *)((qbyte *)prog->edictsfields + OPB->_int);
486 ptr->_int = OPA->_int;
490 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
492 pr_xfunction->profile += profile - startprofile;
493 startprofile = profile;
494 pr_xstatement = st - pr_statements;
495 Host_Error("Progs attempted to read an out of bounds edict number\n");
498 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
500 pr_xfunction->profile += profile - startprofile;
501 startprofile = profile;
502 pr_xstatement = st - pr_statements;
503 Host_Error("Progs attempted to read an invalid field in an edict\n");
507 ed = PRVM_PROG_TO_EDICT(OPA->edict);
508 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
514 case OP_GSTOREP_FLD: // integers
516 case OP_GSTOREP_FNC: // pointers
518 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
520 pr_xfunction->profile += profile - startprofile;
521 startprofile = profile;
522 pr_xstatement = st - pr_statements;
523 Host_Error("Progs attempted to write to an invalid indexed global\n");
527 pr_globals[OPB->_int] = OPA->_float;
531 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
533 pr_xfunction->profile += profile - startprofile;
534 startprofile = profile;
535 pr_xstatement = st - pr_statements;
536 Host_Error("Progs attempted to write to an invalid indexed global\n");
540 pr_globals[OPB->_int ] = OPA->vector[0];
541 pr_globals[OPB->_int+1] = OPA->vector[1];
542 pr_globals[OPB->_int+2] = OPA->vector[2];
546 i = OPA->_int + (int) OPB->_float;
548 if (i < 0 || i >= pr_globaldefs)
550 pr_xfunction->profile += profile - startprofile;
551 startprofile = profile;
552 pr_xstatement = st - pr_statements;
553 Host_Error("Progs attempted to address an out of bounds global\n");
557 OPC->_float = pr_globals[i];
567 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
569 pr_xfunction->profile += profile - startprofile;
570 startprofile = profile;
571 pr_xstatement = st - pr_statements;
572 Host_Error("Progs attempted to read an invalid indexed global\n");
576 OPC->_float = pr_globals[OPA->_int];
581 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
583 pr_xfunction->profile += profile - startprofile;
584 startprofile = profile;
585 pr_xstatement = st - pr_statements;
586 Host_Error("Progs attempted to read an invalid indexed global\n");
590 OPC->vector[0] = pr_globals[OPA->_int ];
591 OPC->vector[1] = pr_globals[OPA->_int+1];
592 OPC->vector[2] = pr_globals[OPA->_int+2];
596 if (OPA->_int < 0 || OPA->_int >= st->b)
598 pr_xfunction->profile += profile - startprofile;
599 startprofile = profile;
600 pr_xstatement = st - pr_statements;
601 Host_Error("Progs boundcheck failed at line number %d, value is < 0 or >= %d\n", st->b, st->c);
609 prog->xfunction->profile += profile - startprofile;
610 startprofile = profile;
611 prog->xstatement = st - prog->statements;
612 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);