5 #define HunkAlloc BADGDFG sdfhhsf FHS
8 #define Host_Error Sys_Error
10 // I put the following here to resolve "undefined reference to `__imp__vsnprintf'" with MinGW64 ~ Moodles
12 #if (_MSC_VER >= 1400)
13 //with MSVC 8, use MS extensions
14 #define snprintf linuxlike_snprintf_vc8
15 int VARGS linuxlike_snprintf_vc8(char *buffer, int size, const char *format, ...) LIKEPRINTF(3);
16 #define vsnprintf(a, b, c, d) vsnprintf_s(a, b, _TRUNCATE, c, d)
19 #define snprintf linuxlike_snprintf
20 int VARGS linuxlike_snprintf(char *buffer, int size, const char *format, ...) LIKEPRINTF(3);
21 #define vsnprintf linuxlike_vsnprintf
22 int VARGS linuxlike_vsnprintf(char *buffer, int size, const char *format, va_list argptr);
27 //=============================================================================
35 void PR_PrintStatement (progfuncs_t *progfuncs, dstatement16_t *s)
38 printf("PR_PrintStatement is unsupported\n");
40 if ( (unsigned)s->op < OP_NUMOPS)
42 printf ("%s ", pr_opcodes[s->op].name);
43 i = strlen(pr_opcodes[s->op].name);
48 if (s->op == OP_IF || s->op == OP_IFNOT)
49 printf ("%sbranch %i",PR_GlobalString(progfuncs, s->a),s->b);
50 else if (s->op == OP_GOTO)
52 printf ("branch %i",s->a);
54 else if ( (unsigned)(s->op - OP_STORE_F) < 6)
56 printf ("%s",PR_GlobalString(progfuncs, s->a));
57 printf ("%s", PR_GlobalStringNoContents(progfuncs, s->b));
62 printf ("%s",PR_GlobalString(progfuncs, s->a));
64 printf ("%s",PR_GlobalString(progfuncs, s->b));
66 printf ("%s", PR_GlobalStringNoContents(progfuncs, s->c));
77 char *QC_ucase(char *str)
85 if (*str >= 'a' && *str <= 'z')
86 *str = *str - 'a' + 'A';
92 void PR_StackTrace (progfuncs_t *progfuncs)
106 printf ("<NO STACK>\n");
111 globalbase = (int *)pr_globals + pr_xfunction->parm_start - pr_xfunction->locals;
114 pr_stack[pr_depth].f = pr_xfunction;
115 pr_stack[pr_depth].s = pr_xstatement;
116 for (i=pr_depth ; i>0 ; i--)
122 printf ("<NO FUNCTION>\n");
126 if (pr_stack[i].progsnum != progs)
128 progs = pr_stack[i].progsnum;
130 printf ("<%s>\n", pr_progstate[progs].filename);
133 printf ("stripped : %s\n", f->s_name+progfuncs->stringtable);
136 if (pr_progstate[progs].linenums)
137 printf ("%12s %i : %s\n", f->s_file+progfuncs->stringtable, pr_progstate[progs].linenums[pr_stack[i].s], f->s_name+progfuncs->stringtable);
139 printf ("%12s : %s\n", f->s_file+progfuncs->stringtable, f->s_name+progfuncs->stringtable);
144 for (arg = 0; arg < f->locals; arg++)
147 local = ED_GlobalAtOfs16(progfuncs, f->parm_start+arg);
150 printf(" ofs %i: %f : %i\n", f->parm_start+arg, *(float *)(globalbase - f->locals+arg), *(int *)(globalbase - f->locals+arg) );
154 printf(" %s: %s\n", local->s_name+progfuncs->stringtable, PR_ValueString(progfuncs, local->type, (eval_t*)(globalbase - f->locals+arg)));
155 if (local->type == ev_vector)
161 globalbase = localstack + localstack_used;
163 globalbase -= f->locals;
176 void PR_Profile_f (void)
178 dfunction_t *f, *best;
188 for (i=0 ; i<pr_progs->numfunctions ; i++)
190 f = &pr_functions[i];
191 if (f->profile > max && f->first_statement >=0)
200 printf ("%7i %s\n", best->profile, best->s_name);
213 Aborts the currently executing function
216 void VARGS PR_RunError (progfuncs_t *progfuncs, char *error, ...)
221 va_start (argptr,error);
222 Q_vsnprintf (string,sizeof(string)-1, error,argptr);
226 // void SV_EndRedirect (void);
230 // PR_PrintStatement (pr_statements + pr_xstatement);
231 PR_StackTrace (progfuncs);
234 //editbadfile(pr_strings + pr_xfunction->s_file, -1);
236 // pr_depth = 0; // dump the stack so host_error can shutdown functions
237 // prinst->exitdepth = 0;
239 Abort ("%s", string);
243 ============================================================================
246 The interpretation main loop
247 ============================================================================
254 Returns the new program statement counter
257 void PR_AbortStack (progfuncs_t *progfuncs);
258 int ASMCALL PR_EnterFunction (progfuncs_t *progfuncs, dfunction_t *f, int progsnum)
262 pr_stack[pr_depth].s = pr_xstatement;
263 pr_stack[pr_depth].f = pr_xfunction;
264 pr_stack[pr_depth].progsnum = progsnum;
265 pr_stack[pr_depth].pushed = pr_spushed;
267 if (pr_depth == MAX_STACK_DEPTH)
270 PR_StackTrace (progfuncs);
272 printf ("stack overflow on call to %s\n", progfuncs->stringtable+f->s_name);
274 //comment this out if you want the progs to try to continue anyway (could cause infinate loops)
275 PR_AbortStack(progfuncs);
276 Abort("Stack Overflow in %s\n", progfuncs->stringtable+f->s_name);
277 return pr_xstatement;
280 localstack_used += pr_spushed; //make sure the call doesn't hurt pushed pointers
282 // save off any locals that the new function steps on (to a side place, fromwhere they are restored on exit)
284 if (localstack_used + c > LOCALSTACK_SIZE)
286 localstack_used -= pr_spushed;
288 PR_RunError (progfuncs, "PR_ExecuteProgram: locals stack overflow\n");
291 for (i=0 ; i < c ; i++)
292 localstack[localstack_used+i] = ((int *)pr_globals)[f->parm_start + i];
293 localstack_used += c;
295 // copy parameters (set initial values)
297 for (i=0 ; i<f->numparms ; i++)
299 for (j=0 ; j<f->parm_size[i] ; j++)
301 ((int *)pr_globals)[o] = ((int *)pr_globals)[OFS_PARM0+i*3+j];
307 return f->first_statement - 1; // offset the s++
315 int ASMCALL PR_LeaveFunction (progfuncs_t *progfuncs)
320 Sys_Error ("prog stack underflow");
322 // restore locals from the stack
323 c = pr_xfunction->locals;
324 localstack_used -= c;
325 if (localstack_used < 0)
326 PR_RunError (progfuncs, "PR_ExecuteProgram: locals stack underflow\n");
328 for (i=0 ; i < c ; i++)
329 ((int *)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used+i];
333 PR_MoveParms(progfuncs, pr_stack[pr_depth].progsnum, pr_typecurrent);
334 PR_SwitchProgs(progfuncs, pr_stack[pr_depth].progsnum);
335 pr_xfunction = pr_stack[pr_depth].f;
336 pr_spushed = pr_stack[pr_depth].pushed;
338 localstack_used -= pr_spushed;
339 return pr_stack[pr_depth].s;
342 ddef32_t *ED_FindLocalOrGlobal(progfuncs_t *progfuncs, char *name, eval_t **val)
349 switch (pr_progstate[pr_typecurrent].structtype)
353 //this gets parms fine, but not locals
355 for (i = 0; i < pr_xfunction->numparms; i++)
357 def16 = ED_GlobalAtOfs16(progfuncs, pr_xfunction->parm_start+i);
360 if (!strcmp(def16->s_name+progfuncs->stringtable, name))
362 *val = (eval_t *)&pr_progstate[pr_typecurrent].globals[pr_xfunction->parm_start+i];
364 //we need something like this for functions that are not the top layer
365 // *val = (eval_t *)&localstack[localstack_used-pr_xfunction->numparms*4];
366 def.ofs = def16->ofs;
367 def.s_name = def16->s_name;
368 def.type = def16->type;
372 def16 = ED_FindGlobal16(progfuncs, name);
375 def.ofs = def16->ofs;
376 def.type = def16->type;
377 def.s_name = def16->s_name;
382 //this gets parms fine, but not locals
384 for (i = 0; i < pr_xfunction->numparms; i++)
386 def32 = ED_GlobalAtOfs32(progfuncs, pr_xfunction->parm_start+i);
389 if (!strcmp(def32->s_name+progfuncs->stringtable, name))
391 *val = (eval_t *)&pr_progstate[pr_typecurrent].globals[pr_xfunction->parm_start+i];
393 //we need something like this for functions that are not the top layer
394 // *val = (eval_t *)&localstack[localstack_used-pr_xfunction->numparms*4];
398 def32 = ED_FindGlobal32(progfuncs, name);
403 Sys_Error("Bad struct type in ED_FindLocalOrGlobal");
407 *val = (eval_t *)&pr_progstate[pr_typecurrent].globals[def32->ofs];
411 char *COM_TrimString(char *str)
414 static char buffer[256];
415 while (*str <= ' ' && *str>'\0')
418 for (i = 0; i < 255; i++)
428 char *EvaluateDebugString(progfuncs_t *progfuncs, char *key)
430 static char buf[256];
440 assignment = strchr(key, '=');
444 c = strchr(key, '.');
446 def = ED_FindLocalOrGlobal(progfuncs, key, &val);
453 def->type = ev_entity;
455 val->edict = atoi(key);
461 return "(Bad string)";
465 //go through ent vars
466 c = strchr(key, '.');
471 type = type &~DEF_SAVEGLOBAL;
472 if (current_progstate->types)
473 type = current_progstate->types[type].type;
474 if (type != ev_entity)
475 return "'.' without entity";
477 fdef = ED_FindField(progfuncs, COM_TrimString(c2));
480 return "(Bad string)";
481 val = (eval_t *) (((char *)PROG_TO_EDICT(progfuncs, val->_int)->fields) + fdef->ofs*4);
488 switch (type&~DEF_SAVEGLOBAL)
491 *(string_t *)val = PR_StringToProgs(progfuncs, ED_NewString (progfuncs, assignment, 0));
495 *(float *)val = (float)atof (assignment);
499 *(int *)val = atoi (assignment);
503 strcpy (string, assignment);
506 for (i=0 ; i<3 ; i++)
508 while (*v && *v != ' ')
511 ((float *)d)[i] = (float)atof (w);
517 *(int *)val = EDICT_TO_PROG(progfuncs, EDICT_NUM(progfuncs, atoi (assignment)));
521 fdef = ED_FindField (progfuncs, assignment);
524 size_t l,nl = strlen(assignment);
525 strcpy(buf, "Can't find field ");
527 if (nl > sizeof(buf)-l-2)
528 nl = sizeof(buf)-l-2;
529 memcpy(buf+l, assignment, nl);
530 assignment[l+nl+0] = '\n';
531 assignment[l+nl+1] = 0;
534 *(int *)val = G_INT(fdef->ofs);
542 char *s = assignment;
543 if (s[0] && s[1] == ':')
548 else if (s[0] && s[1] && s[2] == ':')
554 func = ED_FindFunction (progfuncs, s, &i, progsnum);
557 size_t l,nl = strlen(s);
559 assignment[-1] = '=';
561 strcpy(buf, "Can't find field ");
563 if (nl > sizeof(buf)-l-2)
564 nl = sizeof(buf)-l-2;
565 memcpy(buf+l, assignment, nl);
566 assignment[l+nl+0] = '\n';
567 assignment[l+nl+1] = 0;
570 *(func_t *)val = (func - pr_progstate[i].functions) | (i<<24);
578 assignment[-1] = '=';
580 strcpy(buf, PR_ValueString(progfuncs, type, val));
586 //int EditorHighlightLine(window_t *wnd, int line);
587 void SetExecutionToLine(progfuncs_t *progfuncs, int linenum)
589 int pn = pr_typecurrent;
591 dfunction_t *f = pr_xfunction;
593 switch(current_progstate->structtype)
597 for (snum = f->first_statement; pr_progstate[pn].linenums[snum] < linenum; snum++)
599 if (pr_statements16[snum].op == OP_DONE)
605 for (snum = f->first_statement; pr_progstate[pn].linenums[snum] < linenum; snum++)
607 if (pr_statements32[snum].op == OP_DONE)
612 Sys_Error("Bad struct type");
615 debugstatement = snum;
616 // EditorHighlightLine(editwnd, pr_progstate[pn].linenums[snum]);
619 //0 clear. 1 set, 2 toggle, 3 check
620 int PR_ToggleBreakpoint(progfuncs_t *progfuncs, char *filename, int linenum, int flag) //write alternate route to work by function name.
625 int pn = pr_typecurrent;
627 int op = 0; //warning about not being initialized before use
629 for (pn = 0; (unsigned)pn < maxprogs; pn++)
631 if (!pr_progstate || !pr_progstate[pn].progs)
634 if (linenum) //linenum is set means to set the breakpoint on a file and line
636 if (!pr_progstate[pn].linenums)
639 for (f = pr_progstate[pn].functions, fl = 0; fl < pr_progstate[pn].progs->numfunctions; f++, fl++)
641 if (!stricmp(f->s_file+progfuncs->stringtable, filename))
643 for (i = f->first_statement; ; i++)
645 if (pr_progstate[pn].linenums[i] >= linenum)
647 fl = pr_progstate[pn].linenums[i];
650 if ((unsigned int)pr_progstate[pn].linenums[i] > fl)
653 switch(pr_progstate[pn].structtype)
657 op = ((dstatement16_t*)pr_progstate[pn].statements + i)->op;
661 op = ((dstatement32_t*)pr_progstate[pn].statements + i)->op;
664 Sys_Error("Bad structtype");
695 switch(pr_progstate[pn].structtype)
699 ((dstatement16_t*)pr_progstate[pn].statements + i)->op = op;
703 ((dstatement32_t*)pr_progstate[pn].statements + i)->op = op;
706 Sys_Error("Bad structtype");
716 else //set the breakpoint on the first statement of the function specified.
718 for (f = pr_progstate[pn].functions, fl = 0; fl < pr_progstate[pn].progs->numfunctions; f++, fl++)
720 if (!strcmp(f->s_name+progfuncs->stringtable, filename))
722 i = f->first_statement;
723 switch(pr_progstate[pn].structtype)
727 op = ((dstatement16_t*)pr_progstate[pn].statements + i)->op;
731 op = ((dstatement32_t*)pr_progstate[pn].statements + i)->op;
734 Sys_Error("Bad structtype");
764 switch(pr_progstate[pn].structtype)
768 ((dstatement16_t*)pr_progstate[pn].statements + i)->op = op;
772 ((dstatement32_t*)pr_progstate[pn].statements + i)->op = op;
775 Sys_Error("Bad structtype");
788 int ShowStep(progfuncs_t *progfuncs, int statement)
791 // texture realcursortex;
792 static int lastline = 0;
793 static char *lastfile = 0;
795 int pn = pr_typecurrent;
797 dfunction_t *f = pr_xfunction;
799 if (f && pr_progstate[pn].linenums && externs->useeditor)
801 if (lastline == pr_progstate[pn].linenums[statement] && lastfile == f->s_file+progfuncs->stringtable)
802 return statement; //no info/same line as last time
804 lastline = pr_progstate[pn].linenums[statement];
805 lastfile = f->s_file+progfuncs->stringtable;
807 lastline = externs->useeditor(progfuncs, lastfile, lastline, 0, NULL);
809 if (pr_progstate[pn].linenums[statement] != lastline)
811 for (i = f->first_statement; ; i++)
813 if (lastline == pr_progstate[pn].linenums[i])
817 else if (lastline <= pr_progstate[pn].linenums[i])
824 else if (f) //annoying.
826 if (*(f->s_file+progfuncs->stringtable)) //if we can't get the filename, then it was stripped, and debugging it like this is useless
827 if (externs->useeditor)
828 externs->useeditor(progfuncs, f->s_file+progfuncs->stringtable, -1, 0, NULL);
836 //DMW: all pointer functions are modified to be absoloute pointers from NULL not sv_edicts
842 void PR_ExecuteCode (progfuncs_t *progfuncs, int s)
844 eval_t *t, *swtch=NULL;
846 int swtchtype = 0; //warning about not being initialized before use
847 dstatement16_t *st16;
848 dstatement32_t *st32;
860 prinst->continuestatement = -1;
864 PR_EnterJIT(progfuncs, prinst->jit, s);
868 fnum = pr_xfunction - pr_functions;
872 #define PRBOUNDSCHECK
873 #define RUNAWAYCHECK() \
876 pr_xstatement = st-pr_statements; \
877 PR_StackTrace(progfuncs); \
878 printf ("runaway loop error"); \
879 while(pr_depth > prinst->exitdepth) \
880 PR_LeaveFunction(progfuncs); \
885 #define OPA ((eval_t *)&glob[st->a])
886 #define OPB ((eval_t *)&glob[st->b])
887 #define OPC ((eval_t *)&glob[st->c])
889 restart: //jumped to when the progs might have changed.
891 switch (current_progstate->structtype)
896 st16 = &pr_statements16[s];
900 #ifdef SEPARATEINCLUDES
901 #include "execloop16d.h"
903 #include "execloop.h"
910 #include "execloop.h"
913 Sys_Error("PR_ExecuteProgram - should be unreachable");
918 st32 = &pr_statements32[s];
922 #ifdef SEPARATEINCLUDES
923 #include "execloop32d.h"
925 #include "execloop.h"
932 #ifdef SEPARATEINCLUDES
933 #include "execloop32.h"
935 #include "execloop.h"
939 Sys_Error("PR_ExecuteProgram - should be unreachable");
942 Sys_Error("PR_ExecuteProgram - bad structtype");
947 void PR_ExecuteProgram (progfuncs_t *progfuncs, func_t fnum)
951 unsigned int initial_progs;
958 unsigned int newprogs = (fnum & 0xff000000)>>24;
960 initial_progs = pr_typecurrent;
961 if (newprogs != initial_progs)
963 if (newprogs >= maxprogs || !&pr_progstate[newprogs].globals) //can happen with hexen2...
965 printf("PR_ExecuteProgram: tried branching into invalid progs\n");
968 PR_MoveParms(progfuncs, newprogs, pr_typecurrent);
969 PR_SwitchProgs(progfuncs, newprogs);
972 if (!(fnum & ~0xff000000) || (signed)(fnum & ~0xff000000) >= pr_progs->numfunctions)
974 // if (pr_global_struct->self)
975 // ED_Print (PROG_TO_EDICT(pr_global_struct->self));
976 printf("PR_ExecuteProgram: NULL function from exe\n");
977 // Host_Error ("PR_ExecuteProgram: NULL function from exe");
979 // PR_MoveParms(0, pr_typecurrent);
980 PR_SwitchProgs(progfuncs, initial_progs);
984 oldexitdepth = prinst->exitdepth;
986 f = &pr_functions[fnum & ~0xff000000];
988 if (f->first_statement < 0)
989 { // negative statements are built in functions
990 i = -f->first_statement;
992 if (i < externs->numglobalbuiltins)
993 (*externs->globalbuiltins[i]) (progfuncs, (struct globalvars_s *)current_progstate->globals);
996 i -= externs->numglobalbuiltins;
997 if (i > current_progstate->numbuiltins)
999 printf ("Bad builtin call number %i (from exe)\n", -f->first_statement);
1000 // PR_MoveParms(p, pr_typecurrent);
1001 PR_SwitchProgs(progfuncs, initial_progs);
1004 current_progstate->builtins [i] (progfuncs, (struct globalvars_s *)current_progstate->globals);
1006 PR_MoveParms(progfuncs, initial_progs, pr_typecurrent);
1007 PR_SwitchProgs(progfuncs, initial_progs);
1014 // make a stack frame
1015 prinst->exitdepth = pr_depth;
1018 s = PR_EnterFunction (progfuncs, f, initial_progs);
1020 tempdepth = prinst->numtempstringsstack;
1021 PR_ExecuteCode(progfuncs, s);
1024 PR_MoveParms(progfuncs, initial_progs, pr_typecurrent);
1025 PR_SwitchProgs(progfuncs, initial_progs);
1027 PR_FreeTemps(progfuncs, tempdepth);
1028 prinst->numtempstringsstack = tempdepth;
1030 prinst->exitdepth = oldexitdepth;
1043 typedef struct qcthread_s {
1045 qcthreadstack_t fstack[MAX_STACK_DEPTH];
1047 int lstack[LOCALSTACK_SIZE];
1053 struct qcthread_s *PR_ForkStack(progfuncs_t *progfuncs)
1054 { //QC code can call builtins that call qc code.
1055 //to get around the problems of restoring the builtins we simply don't save the thread over the builtin.
1057 int ed = prinst->exitdepth;
1058 int localsoffset, baselocalsoffset;
1059 qcthread_t *thread = memalloc(sizeof(qcthread_t));
1062 //copy out the functions stack.
1063 for (i = 0,localsoffset=0; i < ed; i++)
1065 if (i+1 == pr_depth)
1068 f = pr_stack[i+1].f;
1069 localsoffset += f->locals; //this is where it crashes
1071 baselocalsoffset = localsoffset;
1072 for (i = ed; i < pr_depth; i++)
1074 thread->fstack[i-ed].fnum = pr_stack[i].f - pr_progstate[pr_stack[i].progsnum].functions;
1075 thread->fstack[i-ed].progsnum = pr_stack[i].progsnum;
1076 thread->fstack[i-ed].statement = pr_stack[i].s;
1078 if (i+1 == pr_depth)
1081 f = pr_stack[i+1].f;
1082 localsoffset += f->locals;
1084 thread->fstackdepth = pr_depth - ed;
1086 for (i = pr_depth - 1; i >= ed ; i--)
1088 if (i+1 == pr_depth)
1091 f = pr_stack[i+1].f;
1092 localsoffset -= f->locals;
1093 for (l = 0; l < f->locals; l++)
1095 thread->lstack[localsoffset-baselocalsoffset + l ] = ((int *)pr_globals)[f->parm_start + l];
1096 ((int *)pr_globals)[f->parm_start + l] = localstack[localsoffset+l]; //copy the old value into the globals (so the older functions have the correct locals.
1100 for (i = ed; i < pr_depth ; i++) //we need to get the locals back to how they were.
1102 if (i+1 == pr_depth)
1105 f = pr_stack[i+1].f;
1107 for (l = 0; l < f->locals; l++)
1109 ((int *)pr_globals)[f->parm_start + l] = thread->lstack[localsoffset-baselocalsoffset + l];
1111 localsoffset += f->locals;
1113 thread->lstackused = localsoffset - baselocalsoffset;
1115 thread->xstatement = pr_xstatement;
1116 thread->xfunction = pr_xfunction - pr_progstate[pr_typecurrent].functions;
1117 thread->xprogs = pr_typecurrent;
1122 void PR_ResumeThread (progfuncs_t *progfuncs, struct qcthread_s *thread)
1124 dfunction_t *f, *oldf;
1126 progsnum_t initial_progs;
1132 progsnum_t prnum = thread->xprogs;
1133 int fnum = thread->xfunction;
1135 if (localstack_used + thread->lstackused > LOCALSTACK_SIZE)
1136 PR_RunError(progfuncs, "Too many locals on resumtion of QC thread\n");
1138 if (pr_depth + thread->fstackdepth > MAX_STACK_DEPTH)
1139 PR_RunError(progfuncs, "Too large stack on resumtion of QC thread\n");
1142 //do progs switching stuff as appropriate. (fteqw only)
1143 initial_progs = pr_typecurrent;
1144 PR_MoveParms(progfuncs, prnum, pr_typecurrent);
1145 PR_SwitchProgs(progfuncs, prnum);
1148 oldexitdepth = prinst->exitdepth;
1149 prinst->exitdepth = pr_depth;
1152 //add on the callstack.
1153 for (i = 0; i < thread->fstackdepth; i++)
1155 if (pr_depth == prinst->exitdepth)
1157 pr_stack[pr_depth].f = pr_xfunction;
1158 pr_stack[pr_depth].s = pr_xstatement;
1159 pr_stack[pr_depth].progsnum = initial_progs;
1163 pr_stack[pr_depth].progsnum = thread->fstack[i].progsnum;
1164 pr_stack[pr_depth].f = pr_progstate[thread->fstack[i].progsnum].functions + thread->fstack[i].fnum;
1165 pr_stack[pr_depth].s = thread->fstack[i].statement;
1168 if (i+1 == thread->fstackdepth)
1169 f = &pr_functions[fnum];
1171 f = pr_progstate[thread->fstack[i+1].progsnum].functions + thread->fstack[i+1].fnum;
1172 for (l = 0; l < f->locals; l++)
1174 localstack[localstack_used++] = ((int *)pr_globals)[f->parm_start + l];
1175 ((int *)pr_globals)[f->parm_start + l] = thread->lstack[ls++];
1181 if (ls != thread->lstackused)
1182 PR_RunError(progfuncs, "Thread stores incorrect locals count\n");
1185 f = &pr_functions[fnum];
1187 // thread->lstackused -= f->locals; //the current function is the odd one out.
1189 //add on the locals stack
1190 memcpy(localstack+localstack_used, thread->lstack, sizeof(int)*thread->lstackused);
1191 localstack_used += thread->lstackused;
1193 //bung the locals of the current function on the stack.
1194 // for (i=0 ; i < f->locals ; i++)
1195 // ((int *)pr_globals)[f->parm_start + i] = 0xff00ff00;//thread->lstack[thread->lstackused+i];
1198 // PR_EnterFunction (progfuncs, f, initial_progs);
1199 oldf = pr_xfunction;
1201 s = thread->xstatement;
1203 tempdepth = prinst->numtempstringsstack;
1204 PR_ExecuteCode(progfuncs, s);
1207 PR_MoveParms(progfuncs, initial_progs, pr_typecurrent);
1208 PR_SwitchProgs(progfuncs, initial_progs);
1209 PR_FreeTemps(progfuncs, tempdepth);
1210 prinst->numtempstringsstack = tempdepth;
1212 prinst->exitdepth = oldexitdepth;
1213 pr_xfunction = oldf;
1216 void PR_AbortStack (progfuncs_t *progfuncs)
1218 while(pr_depth > prinst->exitdepth+1)
1219 PR_LeaveFunction(progfuncs);
1220 prinst->continuestatement = 0;