]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - exec.c
Merging in new-syntax
[xonotic/gmqcc.git] / exec.c
diff --git a/exec.c b/exec.c
index ee0fb1b38d149936bac8809779bc6c041b9ebf72..872475befa00ac994caef9d899db9fb6172db755 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -50,6 +50,8 @@ MEM_VEC_FUN_RESIZE(qc_program,  size_t, profile)
 
 MEM_VEC_FUNCTIONS(qc_program,   prog_builtin, builtins)
 
+MEM_VEC_FUNCTIONS(qc_program,   const char*, function_stack)
+
 static void loaderror(const char *fmt, ...)
 {
     int     err = errno;
@@ -375,7 +377,7 @@ static void trace_print_global(qc_program *prog, unsigned int glob, int vtype)
             len = printf("$");
         else
             len = printf("%s ", name);
-        vtype = def->type;
+        vtype = def->type & DEF_TYPEMASK;
     }
     else
         len = printf("[@%u] ", glob);
@@ -417,6 +419,12 @@ static void prog_print_statement(qc_program *prog, prog_section_statement *st)
         printf("<illegal instruction %d>\n", st->opcode);
         return;
     }
+    if ((prog->xflags & VMXF_TRACE) && prog->function_stack_count) {
+        size_t i;
+        for (i = 0; i < prog->function_stack_count; ++i)
+            printf("->");
+        printf("%s:", prog->function_stack[prog->function_stack_count-1]);
+    }
     printf(" <> %-12s", asm_instr[st->opcode].m);
     if (st->opcode >= INSTR_IF &&
         st->opcode <= INSTR_IFNOT)
@@ -427,6 +435,7 @@ static void prog_print_statement(qc_program *prog, prog_section_statement *st)
     else if (st->opcode >= INSTR_CALL0 &&
              st->opcode <= INSTR_CALL8)
     {
+        trace_print_global(prog, st->o1.u1, TYPE_FUNCTION);
         printf("\n");
     }
     else if (st->opcode == INSTR_GOTO)
@@ -513,6 +522,10 @@ static qcint prog_enterfunction(qc_program *prog, prog_section_function *func)
     st.stmt     = prog->statement;
     st.function = func;
 
+    if (prog->xflags & VMXF_TRACE) {
+        (void)!qc_program_function_stack_add(prog, prog_getstring(prog, func->name));
+    }
+
 #ifdef QCVM_BACKUP_STRATEGY_CALLER_VARS
     if (prog->stack_count)
     {
@@ -565,6 +578,11 @@ static qcint prog_leavefunction(qc_program *prog)
 
     qc_exec_stack st = prog->stack[prog->stack_count-1];
 
+    if (prog->xflags & VMXF_TRACE) {
+        if (prog->function_stack_count)
+            prog->function_stack_count--;
+    }
+
 #ifdef QCVM_BACKUP_STRATEGY_CALLER_VARS
     if (prog->stack_count > 1) {
         prev  = prog->stack[prog->stack_count-2].function;
@@ -1197,8 +1215,7 @@ while (1) {
             }
 
             ed = prog_getedict(prog, OPA->edict);
-            OPC->_int = ((qcint*)ed) - prog->entitydata;
-            OPC->_int += OPB->_int;
+            OPC->_int = ((qcint*)ed) - prog->entitydata + OPB->_int;
             break;
 
         case INSTR_STORE_F: