]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_exec.c
removed \n from all Host_Error, Sys_Error, PRVM_ERROR, PF_ERROR calls, since Host_Err...
[xonotic/darkplaces.git] / prvm_exec.c
index 6ef71c3c119928a28ab34818b868a5afc202c6d5..2f8c97aeebc3d12de5e056dc07e4ed1261029017 100644 (file)
@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
 #include "quakedef.h"
+#include "progsvm.h"
 
 char *prvm_opnames[] =
 {
@@ -122,7 +123,14 @@ PRVM_PrintStatement
 */
 void PRVM_PrintStatement (dstatement_t *s)
 {
-       int             i;
+       size_t i;
+
+       if( prog->statement_linenums ) {
+               int opnum;
+
+               opnum = s - prog->statements;
+               Con_Printf( "%s:%i: ", PRVM_GetString( prog->xfunction->s_file ), prog->statement_linenums[ opnum ] );
+       }
 
        if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0]))
        {
@@ -203,6 +211,8 @@ void PRVM_Profile_f (void)
        if(!PRVM_SetProgFromString(Cmd_Argv(1)))
                return;
 
+       Con_Printf( "%s Profile:\n[Profile] [BuiltinProfile] [CallCount]\n", PRVM_NAME );
+
        num = 0;
        do
        {
@@ -220,10 +230,11 @@ void PRVM_Profile_f (void)
                if (best)
                {
                        //if (num < howmany)
-                               Con_Printf("%s: %7i %7i %s\n", PRVM_NAME, best->profile, best->builtinsprofile, PRVM_GetString(best->s_name));
+                               Con_Printf("%7i %7i %7i %s\n", best->profile, best->builtinsprofile, best->callcount, PRVM_GetString(best->s_name));
                        num++;
                        best->profile = 0;
                        best->builtinsprofile = 0;
+                       best->callcount = 0;
                }
        } while (best);
 
@@ -242,7 +253,7 @@ void PRVM_CrashAll()
                PRVM_SetProg(i);
                PRVM_Crash();
        }
-       
+
        prog = oldprog;
 }
 
@@ -251,7 +262,7 @@ void PRVM_PrintState(void)
        int i;
        if (prog->xfunction)
        {
-               for (i = -4;i <= 0;i++)
+               for (i = -7; i <= 0;i++)
                        if (prog->xstatement + i >= prog->xfunction->first_statement)
                                PRVM_PrintStatement (prog->statements + prog->xstatement + i);
        }
@@ -262,21 +273,21 @@ void PRVM_PrintState(void)
 
 void PRVM_Crash()
 {
-       if (prog->depth < 1)
-       {
-               // kill the stack just to be sure
-               prog->depth = 0;
-               prog->localstack_used = 0;
+       if (prog == NULL)
                return;
-       }
 
-       Con_Printf("QuakeC crash report for %s:\n", PRVM_NAME);
-       PRVM_PrintState();
+       if( prog->depth > 0 )
+       {
+               Con_Printf("QuakeC crash report for %s:\n", PRVM_NAME);
+               PRVM_PrintState();
+       }
 
        // dump the stack so host_error can shutdown functions
        prog->depth = 0;
        prog->localstack_used = 0;
 
+       // reset the prog pointer
+       prog = NULL;
 }
 
 /*
@@ -299,7 +310,7 @@ int PRVM_EnterFunction (mfunction_t *f)
        int             i, j, c, o;
 
        if (!f)
-               PRVM_ERROR ("PRVM_EnterFunction: NULL function in %s\n", PRVM_NAME);
+               PRVM_ERROR ("PRVM_EnterFunction: NULL function in %s", PRVM_NAME);
 
        prog->stack[prog->depth].s = prog->xstatement;
        prog->stack[prog->depth].f = prog->xfunction;
@@ -310,10 +321,10 @@ int PRVM_EnterFunction (mfunction_t *f)
 // save off any locals that the new function steps on
        c = f->locals;
        if (prog->localstack_used + c > PRVM_LOCALSTACK_SIZE)
-               PRVM_ERROR ("PRVM_ExecuteProgram: locals stack overflow in %s\n", PRVM_NAME);
+               PRVM_ERROR ("PRVM_ExecuteProgram: locals stack overflow in %s", PRVM_NAME);
 
        for (i=0 ; i < c ; i++)
-               prog->localstack[prog->localstack_used+i] = ((int *)prog->globals)[f->parm_start + i];
+               prog->localstack[prog->localstack_used+i] = ((int *)prog->globals.generic)[f->parm_start + i];
        prog->localstack_used += c;
 
 // copy parameters
@@ -322,7 +333,7 @@ int PRVM_EnterFunction (mfunction_t *f)
        {
                for (j=0 ; j<f->parm_size[i] ; j++)
                {
-                       ((int *)prog->globals)[o] = ((int *)prog->globals)[OFS_PARM0+i*3+j];
+                       ((int *)prog->globals.generic)[o] = ((int *)prog->globals.generic)[OFS_PARM0+i*3+j];
                        o++;
                }
        }
@@ -344,15 +355,15 @@ int PRVM_LeaveFunction (void)
                PRVM_ERROR ("prog stack underflow in %s", PRVM_NAME);
 
        if (!prog->xfunction)
-               PRVM_ERROR ("PR_LeaveFunction: NULL function in %s\n", PRVM_NAME);
+               PRVM_ERROR ("PR_LeaveFunction: NULL function in %s", PRVM_NAME);
 // restore locals from the stack
        c = prog->xfunction->locals;
        prog->localstack_used -= c;
        if (prog->localstack_used < 0)
-               PRVM_ERROR ("PRVM_ExecuteProgram: locals stack underflow in %s\n", PRVM_NAME);
+               PRVM_ERROR ("PRVM_ExecuteProgram: locals stack underflow in %s", PRVM_NAME);
 
        for (i=0 ; i < c ; i++)
-               ((int *)prog->globals)[prog->xfunction->parm_start + i] = prog->localstack[prog->localstack_used+i];
+               ((int *)prog->globals.generic)[prog->xfunction->parm_start + i] = prog->localstack[prog->localstack_used+i];
 
 // up stack
        prog->depth--;
@@ -375,13 +386,13 @@ PRVM_ExecuteProgram
 ====================
 */
 // LordHavoc: optimized
-#define OPA ((prvm_eval_t *)&prog->globals[(unsigned short) st->a])
-#define OPB ((prvm_eval_t *)&prog->globals[(unsigned short) st->b])
-#define OPC ((prvm_eval_t *)&prog->globals[(unsigned short) st->c])
+#define OPA ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->a])
+#define OPB ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->b])
+#define OPC ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->c])
 extern cvar_t prvm_boundscheck;
 extern cvar_t prvm_traceqc;
 extern int             PRVM_ED_FindFieldOffset (const char *field);
-extern ddef_t* PRVM_ED_FindGlobal(const char *name); 
+extern ddef_t* PRVM_ED_FindGlobal(const char *name);
 void PRVM_ExecuteProgram (func_t fnum, const char *errormessage)
 {
        dstatement_t    *st;
@@ -390,11 +401,11 @@ void PRVM_ExecuteProgram (func_t fnum, const char *errormessage)
        prvm_eval_t     *ptr;
        int             profile, startprofile, cachedpr_trace, exitdepth;
 
-       if (!fnum || fnum >= prog->progs->numfunctions)
+       if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions)
        {
                if (prog->self && PRVM_G_INT(prog->self->ofs))
                        PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_G_INT(prog->self->ofs)));
-               PRVM_ERROR ("PR_ExecuteProgram: %s", errormessage);
+               PRVM_ERROR ("PRVM_ExecuteProgram: %s", errormessage);
        }
 
        f = &prog->functions[fnum];