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 pr_xfunction->profile += profile - startprofile;
12 startprofile = profile;
13 // update the statement number before we error out
14 pr_xstatement = st - pr_statements;
15 Host_Error("runaway loop counter hit limit of %d opcodes\ntip: if having trouble identifying the problem, try typing profile now", profile);
19 pr_xfunction->profile += profile - startprofile;
20 startprofile = profile;
21 pr_xstatement = st - pr_statements;
22 PR_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 || !*PR_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(PR_GetString(OPA->string),PR_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(PR_GetString(OPA->string),PR_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 > pr_edictareasize)
154 pr_xfunction->profile += profile - startprofile;
155 startprofile = profile;
156 pr_xstatement = st - pr_statements;
157 Host_Error("Progs attempted to write to an out of bounds edict (%i)\n", OPB->_int);
161 ptr = (eval_t *)((qbyte *)sv.edictsfields + OPB->_int);
162 ptr->_int = OPA->_int;
166 if (OPB->_int < 0 || OPB->_int + 12 > pr_edictareasize)
168 pr_xfunction->profile += profile - startprofile;
169 startprofile = profile;
170 pr_xstatement = st - pr_statements;
171 Host_Error("Progs attempted to write to an out of bounds edict (%i)\n", OPB->_int);
175 ptr = (eval_t *)((qbyte *)sv.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)(progs->entityfields))
185 pr_xfunction->profile += profile - startprofile;
186 startprofile = profile;
187 pr_xstatement = st - pr_statements;
188 Host_Error("Progs attempted to address an invalid field (%i) in an edict\n", OPB->_int);
192 if (OPA->edict == 0 && sv.state == ss_active)
194 pr_xfunction->profile += profile - startprofile;
195 startprofile = profile;
196 pr_xstatement = st - pr_statements;
197 Host_Error("assignment to world entity");
200 ed = PROG_TO_EDICT(OPA->edict);
201 OPC->_int = (qbyte *)((int *)ed->v + OPB->_int) - (qbyte *)sv.edictsfields;
210 if ((unsigned int)(OPB->_int) >= (unsigned int)(progs->entityfields))
212 pr_xfunction->profile += profile - startprofile;
213 startprofile = profile;
214 pr_xstatement = st - pr_statements;
215 Host_Error("Progs attempted to read an invalid field in an edict (%i)\n", OPB->_int);
219 ed = PROG_TO_EDICT(OPA->edict);
220 OPC->_int = ((eval_t *)((int *)ed->v + OPB->_int))->_int;
225 if (OPB->_int < 0 || OPB->_int + 2 >= progs->entityfields)
227 pr_xfunction->profile += profile - startprofile;
228 startprofile = profile;
229 pr_xstatement = st - pr_statements;
230 Host_Error("Progs attempted to read an invalid field in an edict (%i)\n", OPB->_int);
234 ed = PROG_TO_EDICT(OPA->edict);
235 OPC->vector[0] = ((eval_t *)((int *)ed->v + OPB->_int))->vector[0];
236 OPC->vector[1] = ((eval_t *)((int *)ed->v + OPB->_int))->vector[1];
237 OPC->vector[2] = ((eval_t *)((int *)ed->v + 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 pr_xfunction->profile += profile - startprofile;
266 startprofile = profile;
267 pr_xstatement = st - pr_statements;
268 pr_argc = st->op - OP_CALL0;
270 Host_Error("NULL function");
272 newf = &pr_functions[OPA->function];
274 if (newf->first_statement < 0)
276 // negative statements are built in functions
277 int builtinnumber = -newf->first_statement;
278 pr_xfunction->builtinsprofile++;
279 if (builtinnumber < pr_numbuiltins && pr_builtins[builtinnumber])
280 pr_builtins[builtinnumber]();
282 Host_Error("No such builtin #%i", builtinnumber);
285 st = pr_statements + PR_EnterFunction(newf);
290 pr_xfunction->profile += profile - startprofile;
291 startprofile = profile;
292 pr_xstatement = st - pr_statements;
294 pr_globals[OFS_RETURN] = pr_globals[(unsigned short) st->a];
295 pr_globals[OFS_RETURN+1] = pr_globals[(unsigned short) st->a+1];
296 pr_globals[OFS_RETURN+2] = pr_globals[(unsigned short) st->a+2];
298 st = pr_statements + PR_LeaveFunction();
299 if (pr_depth <= exitdepth)
301 if (pr_trace != cachedpr_trace)
302 goto chooseexecprogram;
306 pr_xfunction->profile += profile - startprofile;
307 startprofile = profile;
308 pr_xstatement = st - pr_statements;
309 ed = PROG_TO_EDICT(pr_global_struct->self);
310 ed->v->nextthink = pr_global_struct->time + 0.1;
311 ed->v->frame = OPA->_float;
312 ed->v->think = OPB->function;
315 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
318 OPC->_int = OPA->_int + OPB->_int;
321 OPC->_int = OPA->_int + (int) OPB->_float;
324 OPC->_float = OPA->_float + (float) OPB->_int;
327 OPC->_int = OPA->_int - OPB->_int;
330 OPC->_int = OPA->_int - (int) OPB->_float;
333 OPC->_float = OPA->_float - (float) OPB->_int;
336 OPC->_int = OPA->_int * OPB->_int;
339 OPC->_int = OPA->_int * (int) OPB->_float;
342 OPC->_float = OPA->_float * (float) OPB->_int;
345 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
346 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
347 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
351 float temp = 1.0f / OPB->_float;
352 OPC->vector[0] = temp * OPA->vector[0];
353 OPC->vector[1] = temp * OPA->vector[1];
354 OPC->vector[2] = temp * OPA->vector[2];
358 OPC->_int = OPA->_int / OPB->_int;
361 OPC->_int = OPA->_int / (int) OPB->_float;
364 OPC->_float = OPA->_float / (float) OPB->_int;
367 OPC->_float = OPA->_int;
370 OPC->_int = OPA->_float;
373 OPC->_int = OPA->_int & OPB->_int;
376 OPC->_int = OPA->_int | OPB->_int;
379 OPC->_int = OPA->_int & (int)OPB->_float;
382 OPC->_int = OPA->_int | (int)OPB->_float;
385 OPC->_float = (int)OPA->_float & OPB->_int;
388 OPC->_float = (int)OPA->_float | OPB->_int;
391 OPC->_float = OPA->_int >= OPB->_int;
394 OPC->_float = OPA->_int <= 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 = (float)OPA->_int >= OPB->_float;
412 OPC->_float = (float)OPA->_int <= OPB->_float;
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 = OPA->_float >= (float)OPB->_int;
430 OPC->_float = OPA->_float <= (float)OPB->_int;
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->_int;
448 OPC->_float = OPA->_int == OPB->_int;
451 OPC->_float = (float)OPA->_int == OPB->_float;
454 OPC->_float = OPA->_float == (float)OPB->_int;
457 OPC->_float = OPA->_int != OPB->_int;
460 OPC->_float = (float)OPA->_int != OPB->_float;
463 OPC->_float = OPA->_float != (float)OPB->_int;
466 OPB->_int = OPA->_int;
470 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
472 pr_xfunction->profile += profile - startprofile;
473 startprofile = profile;
474 pr_xstatement = st - pr_statements;
475 Host_Error("Progs attempted to write to an out of bounds edict\n");
479 ptr = (eval_t *)((qbyte *)sv.edictsfields + OPB->_int);
480 ptr->_int = OPA->_int;
484 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
486 pr_xfunction->profile += profile - startprofile;
487 startprofile = profile;
488 pr_xstatement = st - pr_statements;
489 Host_Error("Progs attempted to read an out of bounds edict number\n");
492 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
494 pr_xfunction->profile += profile - startprofile;
495 startprofile = profile;
496 pr_xstatement = st - pr_statements;
497 Host_Error("Progs attempted to read an invalid field in an edict\n");
501 ed = PROG_TO_EDICT(OPA->edict);
502 OPC->_int = ((eval_t *)((int *)ed->v + OPB->_int))->_int;
508 case OP_GSTOREP_FLD: // integers
510 case OP_GSTOREP_FNC: // pointers
512 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
514 pr_xfunction->profile += profile - startprofile;
515 startprofile = profile;
516 pr_xstatement = st - pr_statements;
517 Host_Error("Progs attempted to write to an invalid indexed global\n");
521 pr_globals[OPB->_int] = OPA->_float;
525 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
527 pr_xfunction->profile += profile - startprofile;
528 startprofile = profile;
529 pr_xstatement = st - pr_statements;
530 Host_Error("Progs attempted to write to an invalid indexed global\n");
534 pr_globals[OPB->_int ] = OPA->vector[0];
535 pr_globals[OPB->_int+1] = OPA->vector[1];
536 pr_globals[OPB->_int+2] = OPA->vector[2];
540 i = OPA->_int + (int) OPB->_float;
542 if (i < 0 || i >= pr_globaldefs)
544 pr_xfunction->profile += profile - startprofile;
545 startprofile = profile;
546 pr_xstatement = st - pr_statements;
547 Host_Error("Progs attempted to address an out of bounds global\n");
551 OPC->_float = pr_globals[i];
561 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
563 pr_xfunction->profile += profile - startprofile;
564 startprofile = profile;
565 pr_xstatement = st - pr_statements;
566 Host_Error("Progs attempted to read an invalid indexed global\n");
570 OPC->_float = pr_globals[OPA->_int];
575 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
577 pr_xfunction->profile += profile - startprofile;
578 startprofile = profile;
579 pr_xstatement = st - pr_statements;
580 Host_Error("Progs attempted to read an invalid indexed global\n");
584 OPC->vector[0] = pr_globals[OPA->_int ];
585 OPC->vector[1] = pr_globals[OPA->_int+1];
586 OPC->vector[2] = pr_globals[OPA->_int+2];
590 if (OPA->_int < 0 || OPA->_int >= st->b)
592 pr_xfunction->profile += profile - startprofile;
593 startprofile = profile;
594 pr_xstatement = st - pr_statements;
595 Host_Error("Progs boundcheck failed at line number %d, value is < 0 or >= %d\n", st->b, st->c);
603 pr_xfunction->profile += profile - startprofile;
604 startprofile = profile;
605 pr_xstatement = st - pr_statements;
606 Host_Error ("Bad opcode %i", st->op);