2 /* Expected variables */
6 #define OPA ( (qcany*) (prog->globals + st->o1.u1) )
7 #define OPB ( (qcany*) (prog->globals + st->o2.u1) )
8 #define OPC ( (qcany*) (prog->globals + st->o3.u1) )
10 #define GLOBAL(x) ( (qcany*) (prog->globals + (x)) )
12 /* to be consistent with current darkplaces behaviour */
13 #if !defined(FLOAT_IS_TRUE_FOR_INT)
14 # define FLOAT_IS_TRUE_FOR_INT(x) ( (x) & 0x7FFFFFFF )
18 prog_section_function *newf;
25 prog->profile[st - prog->code]++;
29 prog_print_statement(prog, st);
35 qcvmerror(prog, "Illegal instruction in %s\n", prog->filename);
40 /* TODO: add instruction count to function profile count */
41 GLOBAL(OFS_RETURN)->ivector[0] = OPA->ivector[0];
42 GLOBAL(OFS_RETURN)->ivector[1] = OPA->ivector[1];
43 GLOBAL(OFS_RETURN)->ivector[2] = OPA->ivector[2];
45 st = prog->code + prog_leavefunction(prog);
46 if (!prog->stack_count)
52 OPC->_float = OPA->_float * OPB->_float;
55 OPC->_float = OPA->vector[0]*OPB->vector[0] +
56 OPA->vector[1]*OPB->vector[1] +
57 OPA->vector[2]*OPB->vector[2];
60 OPC->vector[0] = OPA->_float * OPB->vector[0];
61 OPC->vector[1] = OPA->_float * OPB->vector[1];
62 OPC->vector[2] = OPA->_float * OPB->vector[2];
65 OPC->vector[0] = OPB->_float * OPA->vector[0];
66 OPC->vector[1] = OPB->_float * OPA->vector[1];
67 OPC->vector[2] = OPB->_float * OPA->vector[2];
70 if (OPB->_float != 0.0f)
71 OPC->_float = OPA->_float / OPB->_float;
77 OPC->_float = OPA->_float + OPB->_float;
80 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
81 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
82 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
85 OPC->_float = OPA->_float - OPB->_float;
88 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
89 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
90 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
94 OPC->_float = (OPA->_float == OPB->_float);
97 OPC->_float = ((OPA->vector[0] == OPB->vector[0]) &&
98 (OPA->vector[1] == OPB->vector[1]) &&
99 (OPA->vector[2] == OPB->vector[2]) );
102 OPC->_float = !strcmp(prog_getstring(prog, OPA->string),
103 prog_getstring(prog, OPB->string));
106 OPC->_float = (OPA->_int == OPB->_int);
109 OPC->_float = (OPA->function == OPB->function);
112 OPC->_float = (OPA->_float != OPB->_float);
115 OPC->_float = ((OPA->vector[0] != OPB->vector[0]) ||
116 (OPA->vector[1] != OPB->vector[1]) ||
117 (OPA->vector[2] != OPB->vector[2]) );
120 OPC->_float = !!strcmp(prog_getstring(prog, OPA->string),
121 prog_getstring(prog, OPB->string));
124 OPC->_float = (OPA->_int != OPB->_int);
127 OPC->_float = (OPA->function != OPB->function);
131 OPC->_float = (OPA->_float <= OPB->_float);
134 OPC->_float = (OPA->_float >= OPB->_float);
137 OPC->_float = (OPA->_float < OPB->_float);
140 OPC->_float = (OPA->_float > OPB->_float);
148 if (OPA->edict < 0 || OPA->edict >= prog->entities) {
149 qcvmerror(prog, "progs `%s` attempted to read an out of bounds entity", prog->filename);
152 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields)) {
153 qcvmerror(prog, "prog `%s` attempted to read an invalid field from entity (%i)",
158 ed = prog_getedict(prog, OPA->edict);
159 OPC->_int = ((qcany*)( ((qcint*)ed) + OPB->_int ))->_int;
162 if (OPA->edict < 0 || OPA->edict >= prog->entities) {
163 qcvmerror(prog, "progs `%s` attempted to read an out of bounds entity", prog->filename);
166 if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfields)
168 qcvmerror(prog, "prog `%s` attempted to read an invalid field from entity (%i)",
173 ed = prog_getedict(prog, OPA->edict);
174 OPC->ivector[0] = ((qcany*)( ((qcint*)ed) + OPB->_int ))->ivector[0];
175 OPC->ivector[1] = ((qcany*)( ((qcint*)ed) + OPB->_int ))->ivector[1];
176 OPC->ivector[2] = ((qcany*)( ((qcint*)ed) + OPB->_int ))->ivector[2];
180 if (OPA->edict < 0 || OPA->edict >= prog->entities) {
181 qcvmerror(prog, "prog `%s` attempted to address an out of bounds entity %i", prog->filename, OPA->edict);
184 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
186 qcvmerror(prog, "prog `%s` attempted to read an invalid field from entity (%i)",
192 ed = prog_getedict(prog, OPA->edict);
193 OPC->_int = ((qcint*)ed) - prog->entitydata;
194 OPC->_int += OPB->_int;
199 case INSTR_STORE_ENT:
200 case INSTR_STORE_FLD:
201 case INSTR_STORE_FNC:
202 OPB->_int = OPA->_int;
205 OPB->ivector[0] = OPA->ivector[0];
206 OPB->ivector[1] = OPA->ivector[1];
207 OPB->ivector[2] = OPA->ivector[2];
212 case INSTR_STOREP_ENT:
213 case INSTR_STOREP_FLD:
214 case INSTR_STOREP_FNC:
215 if (OPB->_int < 0 || OPB->_int >= prog->entitydata_count) {
216 qcvmerror(prog, "`%s` attempted to write to an out of bounds edict (%i)", prog->filename, OPB->_int);
219 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
220 qcvmerror(prog, "`%s` tried to assign to world.%s (field %i)\n",
222 prog_getstring(prog, prog_entfield(prog, OPB->_int)->name),
224 ptr = (qcany*)(prog->entitydata + OPB->_int);
225 ptr->_int = OPA->_int;
228 if (OPB->_int < 0 || OPB->_int + 2 >= prog->entitydata_count) {
229 qcvmerror(prog, "`%s` attempted to write to an out of bounds edict (%i)", prog->filename, OPB->_int);
232 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
233 qcvmerror(prog, "`%s` tried to assign to world.%s (field %i)\n",
235 prog_getstring(prog, prog_entfield(prog, OPB->_int)->name),
237 ptr = (qcany*)(prog->entitydata + OPB->_int);
238 ptr->ivector[0] = OPA->ivector[0];
239 ptr->ivector[1] = OPA->ivector[1];
240 ptr->ivector[2] = OPA->ivector[2];
244 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
247 OPC->_float = !OPA->vector[0] &&
252 OPC->_float = !OPA->string ||
253 !*prog_getstring(prog, OPA->string);
256 OPC->_float = (OPA->edict == 0);
259 OPC->_float = !OPA->function;
263 /* this is consistent with darkplaces' behaviour */
264 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
266 st += st->o2.s1 - 1; /* offset the s++ */
267 if (++jumpcount >= maxjumps)
268 qcvmerror(prog, "`%s` hit the runaway loop counter limit of %li jumps", prog->filename, jumpcount);
272 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
274 st += st->o2.s1 - 1; /* offset the s++ */
275 if (++jumpcount >= maxjumps)
276 qcvmerror(prog, "`%s` hit the runaway loop counter limit of %li jumps", prog->filename, jumpcount);
289 prog->argc = st->opcode - INSTR_CALL0;
291 qcvmerror(prog, "NULL function in `%s`", prog->filename);
293 if(!OPA->function || OPA->function >= (unsigned int)prog->functions_count)
295 qcvmerror(prog, "CALL outside the program in `%s`", prog->filename);
299 newf = &prog->functions[OPA->function];
302 prog->statement = (st - prog->code) + 1;
306 /* negative statements are built in functions */
307 int builtinnumber = -newf->entry;
308 if (builtinnumber < prog->builtins_count && prog->builtins[builtinnumber])
309 prog->builtins[builtinnumber](prog);
311 qcvmerror(prog, "No such builtin #%i in %s! Try updating your gmqcc sources",
312 builtinnumber, prog->filename);
315 st = prog->code + prog_enterfunction(prog, newf);
321 qcvmerror(prog, "`%s` tried to execute a STATE operation", prog->filename);
325 st += st->o1.s1 - 1; /* offset the s++ */
326 if (++jumpcount == 10000000)
327 qcvmerror(prog, "`%s` hit the runaway loop counter limit of %li jumps", prog->filename, jumpcount);
331 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) &&
332 FLOAT_IS_TRUE_FOR_INT(OPB->_int);
335 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) ||
336 FLOAT_IS_TRUE_FOR_INT(OPB->_int);
340 OPC->_float = ((int)OPA->_float) & ((int)OPB->_float);
343 OPC->_float = ((int)OPA->_float) | ((int)OPB->_float);