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_strings[OPA->string];
88 OPC->_float = !OPA->function;
91 OPC->_float = (PROG_TO_EDICT(OPA->edict) == sv.edicts);
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_strings+OPA->string,pr_strings+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_strings+OPA->string,pr_strings+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\n");
150 if (OPB->_int % pr_edict_size < ((qbyte *)&sv.edicts->v - (qbyte *)sv.edicts))
152 pr_xstatement = st - pr_statements;
153 Host_Error("Progs attempted to write to an engine edict field\n");
157 ptr = (eval_t *)((qbyte *)sv.edicts + OPB->_int);
158 ptr->_int = OPA->_int;
162 if (OPB->_int < 0 || OPB->_int + 12 > pr_edictareasize)
164 pr_xstatement = st - pr_statements;
165 Host_Error("Progs attempted to write to an out of bounds edict\n");
169 ptr = (eval_t *)((qbyte *)sv.edicts + OPB->_int);
170 ptr->vector[0] = OPA->vector[0];
171 ptr->vector[1] = OPA->vector[1];
172 ptr->vector[2] = OPA->vector[2];
179 if (OPA->edict == 0 && sv.state == ss_active)
181 pr_xstatement = st - pr_statements;
182 Host_Error ("assignment to world entity");
187 pr_xstatement = st - pr_statements;
188 Host_Error("Progs attempted to address an out of bounds edict\n");
192 else if (OPA->edict >= pr_edictareasize)
194 pr_xstatement = st - pr_statements;
195 Host_Error("Progs attempted to address an out of bounds edict\n");
198 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
200 pr_xstatement = st - pr_statements;
201 Host_Error("Progs attempted to address an invalid field in an edict\n");
205 if (OPA->edict == 0 && sv.state == ss_active)
207 pr_xstatement = st - pr_statements;
208 Host_Error ("assignment to world entity");
212 ed = PROG_TO_EDICT(OPA->edict);
213 OPC->_int = (qbyte *)((int *)&ed->v + OPB->_int) - (qbyte *)sv.edicts;
222 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
224 pr_xstatement = st - pr_statements;
225 Host_Error("Progs attempted to read an out of bounds edict number\n");
228 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
230 pr_xstatement = st - pr_statements;
231 Host_Error("Progs attempted to read an invalid field in an edict\n");
235 ed = PROG_TO_EDICT(OPA->edict);
236 OPC->_int = ((eval_t *)((int *)&ed->v + OPB->_int))->_int;
241 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
243 pr_xstatement = st - pr_statements;
244 Host_Error("Progs attempted to read an out of bounds edict number\n");
247 if (OPB->_int < 0 || OPB->_int + 2 >= progs->entityfields)
249 pr_xstatement = st - pr_statements;
250 Host_Error("Progs attempted to read an invalid field in an edict\n");
254 ed = PROG_TO_EDICT(OPA->edict);
255 OPC->vector[0] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[0];
256 OPC->vector[1] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[1];
257 OPC->vector[2] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[2];
264 st += st->b - 1; // offset the s++
269 st += st->b - 1; // offset the s++
273 st += st->a - 1; // offset the s++
285 pr_xfunction->profile += profile - startprofile;
286 startprofile = profile;
287 pr_xstatement = st - pr_statements;
288 pr_argc = st->op - OP_CALL0;
290 Host_Error ("NULL function");
292 newf = &pr_functions[OPA->function];
294 if (newf->first_statement < 0)
296 // negative statements are built in functions
297 if ((-newf->first_statement) >= pr_numbuiltins)
298 Host_Error ("Bad builtin call number");
299 pr_builtins[-newf->first_statement] ();
302 st = pr_statements + PR_EnterFunction(newf);
307 pr_globals[OFS_RETURN] = pr_globals[(unsigned short) st->a];
308 pr_globals[OFS_RETURN+1] = pr_globals[(unsigned short) st->a+1];
309 pr_globals[OFS_RETURN+2] = pr_globals[(unsigned short) st->a+2];
311 st = pr_statements + PR_LeaveFunction();
312 if (pr_depth <= exitdepth)
314 if (pr_trace != cachedpr_trace)
315 goto chooseexecprogram;
319 ed = PROG_TO_EDICT(pr_global_struct->self);
320 ed->v.nextthink = pr_global_struct->time + 0.1;
321 ed->v.frame = OPA->_float;
322 ed->v.think = OPB->function;
325 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
328 OPC->_int = OPA->_int + OPB->_int;
331 OPC->_int = OPA->_int + (int) OPB->_float;
334 OPC->_float = OPA->_float + (float) OPB->_int;
337 OPC->_int = OPA->_int - OPB->_int;
340 OPC->_int = OPA->_int - (int) OPB->_float;
343 OPC->_float = OPA->_float - (float) OPB->_int;
346 OPC->_int = OPA->_int * OPB->_int;
349 OPC->_int = OPA->_int * (int) OPB->_float;
352 OPC->_float = OPA->_float * (float) OPB->_int;
355 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
356 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
357 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
361 float temp = 1.0f / OPB->_float;
362 OPC->vector[0] = temp * OPA->vector[0];
363 OPC->vector[1] = temp * OPA->vector[1];
364 OPC->vector[2] = temp * OPA->vector[2];
368 OPC->_int = OPA->_int / OPB->_int;
371 OPC->_int = OPA->_int / (int) OPB->_float;
374 OPC->_float = OPA->_float / (float) OPB->_int;
377 OPC->_float = OPA->_int;
380 OPC->_int = OPA->_float;
383 OPC->_int = OPA->_int & OPB->_int;
386 OPC->_int = OPA->_int | OPB->_int;
389 OPC->_int = OPA->_int & (int)OPB->_float;
392 OPC->_int = OPA->_int | (int)OPB->_float;
395 OPC->_float = (int)OPA->_float & OPB->_int;
398 OPC->_float = (int)OPA->_float | OPB->_int;
401 OPC->_float = OPA->_int >= OPB->_int;
404 OPC->_float = OPA->_int <= OPB->_int;
407 OPC->_float = OPA->_int > OPB->_int;
410 OPC->_float = OPA->_int < OPB->_int;
413 OPC->_float = OPA->_int && OPB->_int;
416 OPC->_float = OPA->_int || OPB->_int;
419 OPC->_float = (float)OPA->_int >= OPB->_float;
422 OPC->_float = (float)OPA->_int <= OPB->_float;
425 OPC->_float = (float)OPA->_int > OPB->_float;
428 OPC->_float = (float)OPA->_int < OPB->_float;
431 OPC->_float = (float)OPA->_int && OPB->_float;
434 OPC->_float = (float)OPA->_int || OPB->_float;
437 OPC->_float = OPA->_float >= (float)OPB->_int;
440 OPC->_float = OPA->_float <= (float)OPB->_int;
443 OPC->_float = OPA->_float > (float)OPB->_int;
446 OPC->_float = OPA->_float < (float)OPB->_int;
449 OPC->_float = OPA->_float && (float)OPB->_int;
452 OPC->_float = OPA->_float || (float)OPB->_int;
455 OPC->_float = !OPA->_int;
458 OPC->_float = OPA->_int == OPB->_int;
461 OPC->_float = (float)OPA->_int == OPB->_float;
464 OPC->_float = OPA->_float == (float)OPB->_int;
467 OPC->_float = OPA->_int != OPB->_int;
470 OPC->_float = (float)OPA->_int != OPB->_float;
473 OPC->_float = OPA->_float != (float)OPB->_int;
476 OPB->_int = OPA->_int;
480 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
482 pr_xstatement = st - pr_statements;
483 Host_Error("Progs attempted to write to an out of bounds edict\n");
486 if (OPB->_int % pr_edict_size < ((qbyte *)&sv.edicts->v - (qbyte *)sv.edicts))
488 pr_xstatement = st - pr_statements;
489 Host_Error("Progs attempted to write to an engine edict field\n");
493 ptr = (eval_t *)((qbyte *)sv.edicts + OPB->_int);
494 ptr->_int = OPA->_int;
498 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
500 pr_xstatement = st - pr_statements;
501 Host_Error("Progs attempted to read an out of bounds edict number\n");
504 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
506 pr_xstatement = st - pr_statements;
507 Host_Error("Progs attempted to read an invalid field in an edict\n");
511 ed = PROG_TO_EDICT(OPA->edict);
512 OPC->_int = ((eval_t *)((int *)&ed->v + OPB->_int))->_int;
518 case OP_GSTOREP_FLD: // integers
520 case OP_GSTOREP_FNC: // pointers
522 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
524 pr_xstatement = st - pr_statements;
525 Host_Error("Progs attempted to write to an invalid indexed global\n");
529 pr_globals[OPB->_int] = OPA->_float;
533 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
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_xstatement = st - pr_statements;
551 Host_Error("Progs attempted to address an out of bounds global\n");
555 OPC->_float = pr_globals[i];
565 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
567 pr_xstatement = st - pr_statements;
568 Host_Error("Progs attempted to read an invalid indexed global\n");
572 OPC->_float = pr_globals[OPA->_int];
577 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
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_xstatement = st - pr_statements;
593 Host_Error("Progs boundcheck failed at line number %d, value is < 0 or >= %d\n", st->b, st->c);
601 pr_xstatement = st - pr_statements;
602 Host_Error ("Bad opcode %i", st->op);