2 // This code isn't #ifdef/#define protectable, don't try.
7 if (++profile > 1000000) // LordHavoc: increased runaway loop limit 10x
9 pr_xstatement = st - pr_statements;
10 Host_Error ("runaway loop error");
14 PR_PrintStatement (st);
20 OPC->_float = OPA->_float + OPB->_float;
23 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
24 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
25 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
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->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
42 OPC->vector[0] = OPA->_float * OPB->vector[0];
43 OPC->vector[1] = OPA->_float * OPB->vector[1];
44 OPC->vector[2] = OPA->_float * OPB->vector[2];
47 OPC->vector[0] = OPB->_float * OPA->vector[0];
48 OPC->vector[1] = OPB->_float * OPA->vector[1];
49 OPC->vector[2] = OPB->_float * OPA->vector[2];
52 OPC->_float = OPA->_float / OPB->_float;
55 OPC->_float = (int)OPA->_float & (int)OPB->_float;
58 OPC->_float = (int)OPA->_float | (int)OPB->_float;
61 OPC->_float = OPA->_float >= OPB->_float;
64 OPC->_float = OPA->_float <= OPB->_float;
67 OPC->_float = OPA->_float > OPB->_float;
70 OPC->_float = OPA->_float < OPB->_float;
73 OPC->_float = OPA->_float && OPB->_float;
76 OPC->_float = OPA->_float || OPB->_float;
79 OPC->_float = !OPA->_float;
82 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
85 OPC->_float = !OPA->string || !*PR_GetString(OPA->string);
88 OPC->_float = !OPA->function;
91 OPC->_float = (OPA->edict == 0);
94 OPC->_float = OPA->_float == OPB->_float;
97 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
100 OPC->_float = !strcmp(PR_GetString(OPA->string),PR_GetString(OPB->string));
103 OPC->_float = OPA->_int == OPB->_int;
106 OPC->_float = OPA->function == OPB->function;
109 OPC->_float = OPA->_float != OPB->_float;
112 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
115 OPC->_float = strcmp(PR_GetString(OPA->string),PR_GetString(OPB->string));
118 OPC->_float = OPA->_int != OPB->_int;
121 OPC->_float = OPA->function != OPB->function;
127 case OP_STORE_FLD: // integers
129 case OP_STORE_FNC: // pointers
130 OPB->_int = OPA->_int;
133 OPB->vector[0] = OPA->vector[0];
134 OPB->vector[1] = OPA->vector[1];
135 OPB->vector[2] = OPA->vector[2];
140 case OP_STOREP_FLD: // integers
142 case OP_STOREP_FNC: // pointers
144 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
146 pr_xstatement = st - pr_statements;
147 Host_Error("Progs attempted to write to an out of bounds edict (%i)\n", OPB->_int);
151 ptr = (eval_t *)((qbyte *)sv.edictsfields + OPB->_int);
152 ptr->_int = OPA->_int;
156 if (OPB->_int < 0 || OPB->_int + 12 > pr_edictareasize)
158 pr_xstatement = st - pr_statements;
159 Host_Error("Progs attempted to write to an out of bounds edict (%i)\n", OPB->_int);
163 ptr = (eval_t *)((qbyte *)sv.edictsfields + OPB->_int);
164 ptr->vector[0] = OPA->vector[0];
165 ptr->vector[1] = OPA->vector[1];
166 ptr->vector[2] = OPA->vector[2];
170 pr_xstatement = st - pr_statements;
172 if ((unsigned int)(OPB->_int) >= (unsigned int)(progs->entityfields))
174 Host_Error("Progs attempted to address an invalid field (%i) in an edict\n", OPB->_int);
178 if (OPA->edict == 0 && sv.state == ss_active)
180 Host_Error ("assignment to world entity");
183 ed = PROG_TO_EDICT(OPA->edict);
184 OPC->_int = (qbyte *)((int *)ed->v + OPB->_int) - (qbyte *)sv.edictsfields;
192 pr_xstatement = st - pr_statements;
194 if ((unsigned int)(OPB->_int) >= (unsigned int)(progs->entityfields))
196 Host_Error("Progs attempted to read an invalid field in an edict (%i)\n", OPB->_int);
200 ed = PROG_TO_EDICT(OPA->edict);
201 OPC->_int = ((eval_t *)((int *)ed->v + OPB->_int))->_int;
205 pr_xstatement = st - pr_statements;
207 if (OPB->_int < 0 || OPB->_int + 2 >= progs->entityfields)
209 Host_Error("Progs attempted to read an invalid field in an edict (%i)\n", OPB->_int);
213 ed = PROG_TO_EDICT(OPA->edict);
214 OPC->vector[0] = ((eval_t *)((int *)ed->v + OPB->_int))->vector[0];
215 OPC->vector[1] = ((eval_t *)((int *)ed->v + OPB->_int))->vector[1];
216 OPC->vector[2] = ((eval_t *)((int *)ed->v + OPB->_int))->vector[2];
223 st += st->b - 1; // offset the s++
228 st += st->b - 1; // offset the s++
232 st += st->a - 1; // offset the s++
244 pr_xfunction->profile += profile - startprofile;
245 startprofile = profile;
246 pr_xstatement = st - pr_statements;
247 pr_argc = st->op - OP_CALL0;
249 Host_Error ("NULL function");
251 newf = &pr_functions[OPA->function];
253 if (newf->first_statement < 0)
255 // negative statements are built in functions
256 if ((-newf->first_statement) >= pr_numbuiltins)
257 Host_Error ("Bad builtin call number");
258 pr_builtins[-newf->first_statement] ();
261 st = pr_statements + PR_EnterFunction(newf);
266 pr_globals[OFS_RETURN] = pr_globals[(unsigned short) st->a];
267 pr_globals[OFS_RETURN+1] = pr_globals[(unsigned short) st->a+1];
268 pr_globals[OFS_RETURN+2] = pr_globals[(unsigned short) st->a+2];
270 st = pr_statements + PR_LeaveFunction();
271 if (pr_depth <= exitdepth)
273 if (pr_trace != cachedpr_trace)
274 goto chooseexecprogram;
278 ed = PROG_TO_EDICT(pr_global_struct->self);
279 ed->v->nextthink = pr_global_struct->time + 0.1;
280 ed->v->frame = OPA->_float;
281 ed->v->think = OPB->function;
284 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
287 OPC->_int = OPA->_int + OPB->_int;
290 OPC->_int = OPA->_int + (int) OPB->_float;
293 OPC->_float = OPA->_float + (float) OPB->_int;
296 OPC->_int = OPA->_int - OPB->_int;
299 OPC->_int = OPA->_int - (int) OPB->_float;
302 OPC->_float = OPA->_float - (float) OPB->_int;
305 OPC->_int = OPA->_int * OPB->_int;
308 OPC->_int = OPA->_int * (int) OPB->_float;
311 OPC->_float = OPA->_float * (float) OPB->_int;
314 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
315 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
316 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
320 float temp = 1.0f / OPB->_float;
321 OPC->vector[0] = temp * OPA->vector[0];
322 OPC->vector[1] = temp * OPA->vector[1];
323 OPC->vector[2] = temp * OPA->vector[2];
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->_float = OPA->_int;
339 OPC->_int = OPA->_float;
342 OPC->_int = OPA->_int & OPB->_int;
345 OPC->_int = OPA->_int | OPB->_int;
348 OPC->_int = OPA->_int & (int)OPB->_float;
351 OPC->_int = OPA->_int | (int)OPB->_float;
354 OPC->_float = (int)OPA->_float & OPB->_int;
357 OPC->_float = (int)OPA->_float | OPB->_int;
360 OPC->_float = OPA->_int >= OPB->_int;
363 OPC->_float = OPA->_int <= OPB->_int;
366 OPC->_float = OPA->_int > OPB->_int;
369 OPC->_float = OPA->_int < OPB->_int;
372 OPC->_float = OPA->_int && OPB->_int;
375 OPC->_float = OPA->_int || OPB->_int;
378 OPC->_float = (float)OPA->_int >= OPB->_float;
381 OPC->_float = (float)OPA->_int <= OPB->_float;
384 OPC->_float = (float)OPA->_int > OPB->_float;
387 OPC->_float = (float)OPA->_int < OPB->_float;
390 OPC->_float = (float)OPA->_int && OPB->_float;
393 OPC->_float = (float)OPA->_int || OPB->_float;
396 OPC->_float = OPA->_float >= (float)OPB->_int;
399 OPC->_float = OPA->_float <= (float)OPB->_int;
402 OPC->_float = OPA->_float > (float)OPB->_int;
405 OPC->_float = OPA->_float < (float)OPB->_int;
408 OPC->_float = OPA->_float && (float)OPB->_int;
411 OPC->_float = OPA->_float || (float)OPB->_int;
414 OPC->_float = !OPA->_int;
417 OPC->_float = OPA->_int == OPB->_int;
420 OPC->_float = (float)OPA->_int == OPB->_float;
423 OPC->_float = OPA->_float == (float)OPB->_int;
426 OPC->_float = OPA->_int != OPB->_int;
429 OPC->_float = (float)OPA->_int != OPB->_float;
432 OPC->_float = OPA->_float != (float)OPB->_int;
435 OPB->_int = OPA->_int;
439 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
441 pr_xstatement = st - pr_statements;
442 Host_Error("Progs attempted to write to an out of bounds edict\n");
446 ptr = (eval_t *)((qbyte *)sv.edictsfields + OPB->_int);
447 ptr->_int = OPA->_int;
451 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
453 pr_xstatement = st - pr_statements;
454 Host_Error("Progs attempted to read an out of bounds edict number\n");
457 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
459 pr_xstatement = st - pr_statements;
460 Host_Error("Progs attempted to read an invalid field in an edict\n");
464 ed = PROG_TO_EDICT(OPA->edict);
465 OPC->_int = ((eval_t *)((int *)ed->v + OPB->_int))->_int;
471 case OP_GSTOREP_FLD: // integers
473 case OP_GSTOREP_FNC: // pointers
475 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
477 pr_xstatement = st - pr_statements;
478 Host_Error("Progs attempted to write to an invalid indexed global\n");
482 pr_globals[OPB->_int] = OPA->_float;
486 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
488 pr_xstatement = st - pr_statements;
489 Host_Error("Progs attempted to write to an invalid indexed global\n");
493 pr_globals[OPB->_int ] = OPA->vector[0];
494 pr_globals[OPB->_int+1] = OPA->vector[1];
495 pr_globals[OPB->_int+2] = OPA->vector[2];
499 i = OPA->_int + (int) OPB->_float;
501 if (i < 0 || i >= pr_globaldefs)
503 pr_xstatement = st - pr_statements;
504 Host_Error("Progs attempted to address an out of bounds global\n");
508 OPC->_float = pr_globals[i];
518 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
520 pr_xstatement = st - pr_statements;
521 Host_Error("Progs attempted to read an invalid indexed global\n");
525 OPC->_float = pr_globals[OPA->_int];
530 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
532 pr_xstatement = st - pr_statements;
533 Host_Error("Progs attempted to read an invalid indexed global\n");
537 OPC->vector[0] = pr_globals[OPA->_int ];
538 OPC->vector[1] = pr_globals[OPA->_int+1];
539 OPC->vector[2] = pr_globals[OPA->_int+2];
543 if (OPA->_int < 0 || OPA->_int >= st->b)
545 pr_xstatement = st - pr_statements;
546 Host_Error("Progs boundcheck failed at line number %d, value is < 0 or >= %d\n", st->b, st->c);
554 pr_xstatement = st - pr_statements;
555 Host_Error ("Bad opcode %i", st->op);