4 if (++profile > 1000000) // LordHavoc: increased runaway loop limit 10x
6 pr_xstatement = st - pr_statements;
7 PR_RunError ("runaway loop error");
11 PR_PrintStatement (st);
17 OPC->_float = OPA->_float + OPB->_float;
20 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
21 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
22 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
25 OPC->_float = OPA->_float - OPB->_float;
28 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
29 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
30 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
33 OPC->_float = OPA->_float * OPB->_float;
36 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
39 OPC->vector[0] = OPA->_float * OPB->vector[0];
40 OPC->vector[1] = OPA->_float * OPB->vector[1];
41 OPC->vector[2] = OPA->_float * OPB->vector[2];
44 OPC->vector[0] = OPB->_float * OPA->vector[0];
45 OPC->vector[1] = OPB->_float * OPA->vector[1];
46 OPC->vector[2] = OPB->_float * OPA->vector[2];
49 OPC->_float = OPA->_float / OPB->_float;
52 OPC->_float = (int)OPA->_float & (int)OPB->_float;
55 OPC->_float = (int)OPA->_float | (int)OPB->_float;
58 OPC->_float = OPA->_float >= 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;
79 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
82 OPC->_float = !OPA->string || !pr_strings[OPA->string];
85 OPC->_float = !OPA->function;
88 OPC->_float = (PROG_TO_EDICT(OPA->edict) == sv.edicts);
91 OPC->_float = OPA->_float == OPB->_float;
94 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
97 OPC->_float = !strcmp(pr_strings+OPA->string,pr_strings+OPB->string);
100 OPC->_float = OPA->_int == OPB->_int;
103 OPC->_float = OPA->function == OPB->function;
106 OPC->_float = OPA->_float != OPB->_float;
109 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
112 OPC->_float = strcmp(pr_strings+OPA->string,pr_strings+OPB->string);
115 OPC->_float = OPA->_int != OPB->_int;
118 OPC->_float = OPA->function != OPB->function;
124 case OP_STORE_FLD: // integers
126 case OP_STORE_FNC: // pointers
127 OPB->_int = OPA->_int;
130 OPB->vector[0] = OPA->vector[0];
131 OPB->vector[1] = OPA->vector[1];
132 OPB->vector[2] = OPA->vector[2];
137 case OP_STOREP_FLD: // integers
139 case OP_STOREP_FNC: // pointers
141 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
143 pr_xstatement = st - pr_statements;
144 PR_RunError("Progs attempted to write to an out of bounds edict\n");
147 if (OPB->_int % pr_edict_size < ((byte *)&sv.edicts->v - (byte *)sv.edicts))
149 pr_xstatement = st - pr_statements;
150 PR_RunError("Progs attempted to write to an engine edict field\n");
154 ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
155 ptr->_int = OPA->_int;
159 if (OPB->_int < 0 || OPB->_int + 12 > pr_edictareasize)
161 pr_xstatement = st - pr_statements;
162 PR_RunError("Progs attempted to write to an out of bounds edict\n");
166 ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
167 ptr->vector[0] = OPA->vector[0];
168 ptr->vector[1] = OPA->vector[1];
169 ptr->vector[2] = OPA->vector[2];
176 if (OPA->edict == 0 && sv.state == ss_active)
178 pr_xstatement = st - pr_statements;
179 PR_RunError ("assignment to world entity");
184 pr_xstatement = st - pr_statements;
185 PR_RunError("Progs attempted to address an out of bounds edict\n");
189 else if (OPA->edict >= pr_edictareasize)
191 pr_xstatement = st - pr_statements;
192 PR_RunError("Progs attempted to address an out of bounds edict\n");
195 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
197 pr_xstatement = st - pr_statements;
198 PR_RunError("Progs attempted to address an invalid field in an edict\n");
202 if (OPA->edict == 0 && sv.state == ss_active)
204 pr_xstatement = st - pr_statements;
205 PR_RunError ("assignment to world entity");
209 ed = PROG_TO_EDICT(OPA->edict);
210 OPC->_int = (byte *)((int *)&ed->v + OPB->_int) - (byte *)sv.edicts;
219 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
221 pr_xstatement = st - pr_statements;
222 PR_RunError("Progs attempted to read an out of bounds edict number\n");
225 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
227 pr_xstatement = st - pr_statements;
228 PR_RunError("Progs attempted to read an invalid field in an edict\n");
232 ed = PROG_TO_EDICT(OPA->edict);
233 OPC->_int = ((eval_t *)((int *)&ed->v + OPB->_int))->_int;
238 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
240 pr_xstatement = st - pr_statements;
241 PR_RunError("Progs attempted to read an out of bounds edict number\n");
244 if (OPB->_int < 0 || OPB->_int + 2 >= progs->entityfields)
246 pr_xstatement = st - pr_statements;
247 PR_RunError("Progs attempted to read an invalid field in an edict\n");
251 ed = PROG_TO_EDICT(OPA->edict);
252 OPC->vector[0] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[0];
253 OPC->vector[1] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[1];
254 OPC->vector[2] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[2];
261 st += st->b - 1; // offset the s++
266 st += st->b - 1; // offset the s++
270 st += st->a - 1; // offset the s++
282 pr_xfunction->profile += profile - startprofile;
283 startprofile = profile;
284 pr_xstatement = st - pr_statements;
285 pr_argc = st->op - OP_CALL0;
287 PR_RunError ("NULL function");
289 newf = &pr_functions[OPA->function];
291 if (newf->first_statement < 0)
293 // negative statements are built in functions
294 if ((-newf->first_statement) >= pr_numbuiltins)
295 PR_RunError ("Bad builtin call number");
296 pr_builtins[-newf->first_statement] ();
299 st = pr_statements + PR_EnterFunction(newf);
304 pr_globals[OFS_RETURN] = pr_globals[(unsigned short) st->a];
305 pr_globals[OFS_RETURN+1] = pr_globals[(unsigned short) st->a+1];
306 pr_globals[OFS_RETURN+2] = pr_globals[(unsigned short) st->a+2];
308 st = pr_statements + PR_LeaveFunction();
309 if (pr_depth <= exitdepth)
311 if (pr_trace != cachedpr_trace)
312 goto chooseexecprogram;
316 ed = PROG_TO_EDICT(pr_global_struct->self);
317 ed->v.nextthink = pr_global_struct->time + 0.1;
318 ed->v.frame = OPA->_float;
319 ed->v.think = OPB->function;
322 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
325 OPC->_int = OPA->_int + OPB->_int;
328 OPC->_int = OPA->_int + (int) OPB->_float;
331 OPC->_float = OPA->_float + (float) OPB->_int;
334 OPC->_int = OPA->_int - OPB->_int;
337 OPC->_int = OPA->_int - (int) OPB->_float;
340 OPC->_float = OPA->_float - (float) OPB->_int;
343 OPC->_int = OPA->_int * OPB->_int;
346 OPC->_int = OPA->_int * (int) OPB->_float;
349 OPC->_float = OPA->_float * (float) OPB->_int;
352 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
353 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
354 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
358 float temp = 1.0f / OPB->_float;
359 OPC->vector[0] = temp * OPA->vector[0];
360 OPC->vector[1] = temp * OPA->vector[1];
361 OPC->vector[2] = temp * OPA->vector[2];
365 OPC->_int = OPA->_int / OPB->_int;
368 OPC->_int = OPA->_int / (int) OPB->_float;
371 OPC->_float = OPA->_float / (float) OPB->_int;
374 OPC->_float = OPA->_int;
377 OPC->_int = OPA->_float;
380 OPC->_int = OPA->_int & OPB->_int;
383 OPC->_int = OPA->_int | OPB->_int;
386 OPC->_int = OPA->_int & (int)OPB->_float;
389 OPC->_int = OPA->_int | (int)OPB->_float;
392 OPC->_float = (int)OPA->_float & OPB->_int;
395 OPC->_float = (int)OPA->_float | OPB->_int;
398 OPC->_float = OPA->_int >= 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 = (float)OPA->_int >= OPB->_float;
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 = OPA->_float >= (float)OPB->_int;
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->_int;
455 OPC->_float = OPA->_int == OPB->_int;
458 OPC->_float = (float)OPA->_int == OPB->_float;
461 OPC->_float = OPA->_float == (float)OPB->_int;
464 OPC->_float = OPA->_int != OPB->_int;
467 OPC->_float = (float)OPA->_int != OPB->_float;
470 OPC->_float = OPA->_float != (float)OPB->_int;
473 OPB->_int = OPA->_int;
477 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
479 pr_xstatement = st - pr_statements;
480 PR_RunError("Progs attempted to write to an out of bounds edict\n");
483 if (OPB->_int % pr_edict_size < ((byte *)&sv.edicts->v - (byte *)sv.edicts))
485 pr_xstatement = st - pr_statements;
486 PR_RunError("Progs attempted to write to an engine edict field\n");
490 ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
491 ptr->_int = OPA->_int;
495 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
497 pr_xstatement = st - pr_statements;
498 PR_RunError("Progs attempted to read an out of bounds edict number\n");
501 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
503 pr_xstatement = st - pr_statements;
504 PR_RunError("Progs attempted to read an invalid field in an edict\n");
508 ed = PROG_TO_EDICT(OPA->edict);
509 OPC->_int = ((eval_t *)((int *)&ed->v + OPB->_int))->_int;
515 case OP_GSTOREP_FLD: // integers
517 case OP_GSTOREP_FNC: // pointers
519 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
521 pr_xstatement = st - pr_statements;
522 PR_RunError("Progs attempted to write to an invalid indexed global\n");
526 pr_globals[OPB->_int] = OPA->_float;
530 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
532 pr_xstatement = st - pr_statements;
533 PR_RunError("Progs attempted to write to an invalid indexed global\n");
537 pr_globals[OPB->_int ] = OPA->vector[0];
538 pr_globals[OPB->_int+1] = OPA->vector[1];
539 pr_globals[OPB->_int+2] = OPA->vector[2];
543 i = OPA->_int + (int) OPB->_float;
545 if (i < 0 || i >= pr_globaldefs)
547 pr_xstatement = st - pr_statements;
548 PR_RunError("Progs attempted to address an out of bounds global\n");
552 OPC->_float = pr_globals[i];
562 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
564 pr_xstatement = st - pr_statements;
565 PR_RunError("Progs attempted to read an invalid indexed global\n");
569 OPC->_float = pr_globals[OPA->_int];
574 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
576 pr_xstatement = st - pr_statements;
577 PR_RunError("Progs attempted to read an invalid indexed global\n");
581 OPC->vector[0] = pr_globals[OPA->_int ];
582 OPC->vector[1] = pr_globals[OPA->_int+1];
583 OPC->vector[2] = pr_globals[OPA->_int+2];
587 if (OPA->_int < 0 || OPA->_int >= st->b)
589 pr_xstatement = st - pr_statements;
590 PR_RunError("Progs boundcheck failed at line number %d, value is < 0 or >= %d\n", st->b, st->c);
598 pr_xstatement = st - pr_statements;
599 PR_RunError ("Bad opcode %i", st->op);