]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - exec.c
It's -config=file, not -config file
[xonotic/gmqcc.git] / exec.c
diff --git a/exec.c b/exec.c
index 8dc9e3cb17de0fb8575eb85b01e2d3ab5b632a1a..41c43660ef408531baa9b3fb2fd9968a7d0967f6 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -477,7 +477,8 @@ static void prog_print_statement(qc_program *prog, prog_section_statement *st)
 static qcint prog_enterfunction(qc_program *prog, prog_section_function *func)
 {
     qc_exec_stack st;
-    size_t p, parampos;
+    size_t  parampos;
+    int32_t p;
 
     /* back up locals */
     st.localsp  = vec_size(prog->localstack);
@@ -616,6 +617,8 @@ cleanup:
 #if defined(QCVM_EXECUTOR)
 #include <math.h>
 
+opts_cmd_t opts;
+
 const char *type_name[TYPE_COUNT] = {
     "void",
     "string",
@@ -631,11 +634,6 @@ const char *type_name[TYPE_COUNT] = {
     "variant"
 };
 
-bool        opts_debug    = false;
-bool        opts_memchk   = false;
-uint32_t    opts_warn [1 + (COUNT_WARNINGS / 32)];
-bool        opts_werror   = false;
-
 typedef struct {
     int         vtype;
     const char *value;
@@ -693,6 +691,17 @@ static int qc_ftos(qc_program *prog)
     return 0;
 }
 
+static int qc_stof(qc_program *prog)
+{
+    qcany *str;
+    qcany num;
+    CheckArgs(1);
+    str = GetArg(0);
+    num._float = strtof(prog_getstring(prog, str->string), NULL);
+    Return(num);
+    return 0;
+}
+
 static int qc_vtos(qc_program *prog)
 {
     char buffer[512];
@@ -758,7 +767,8 @@ static prog_builtin qc_builtins[] = {
     &qc_vtos,  /*   5   */
     &qc_error, /*   6   */
     &qc_vlen,  /*   7   */
-    &qc_etos   /*   8   */
+    &qc_etos,  /*   8   */
+    &qc_stof   /*   9   */
 };
 static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]);
 
@@ -816,6 +826,7 @@ int main(int argc, char **argv)
     size_t      xflags = VMXF_DEFAULT;
     bool        opts_printfields = false;
     bool        opts_printdefs   = false;
+    bool        opts_printfuns   = false;
     bool        opts_disasm      = false;
     bool        opts_info  = false;
 
@@ -850,6 +861,11 @@ int main(int argc, char **argv)
             ++argv;
             opts_printdefs = true;
         }
+        else if (!strcmp(argv[1], "-printfuns")) {
+            --argc;
+            ++argv;
+            opts_printfuns = true;
+        }
         else if (!strcmp(argv[1], "-printfields")) {
             --argc;
             ++argv;
@@ -914,18 +930,34 @@ int main(int argc, char **argv)
     }
     if (opts_printdefs) {
         for (i = 0; i < vec_size(prog->defs); ++i) {
-            printf("Global: %8s %-16s at %u\n",
+            printf("Global: %8s %-16s at %u%s\n",
                    type_name[prog->defs[i].type & DEF_TYPEMASK],
                    prog_getstring(prog, prog->defs[i].name),
-                   (unsigned int)prog->defs[i].offset);
+                   (unsigned int)prog->defs[i].offset,
+                   ((prog->defs[i].type & DEF_SAVEGLOBAL) ? " [SAVE]" : ""));
         }
     }
     else if (opts_printfields) {
         for (i = 0; i < vec_size(prog->fields); ++i) {
-            printf("Field: %8s %-16s at %u\n",
+            printf("Field: %8s %-16s at %u%s\n",
                    type_name[prog->fields[i].type],
                    prog_getstring(prog, prog->fields[i].name),
-                   (unsigned int)prog->fields[i].offset);
+                   (unsigned int)prog->fields[i].offset,
+                   ((prog->fields[i].type & DEF_SAVEGLOBAL) ? " [SAVE]" : ""));
+        }
+    }
+    else if (opts_printfuns) {
+        for (i = 0; i < vec_size(prog->functions); ++i) {
+            int32_t a;
+            printf("Function: %-16s taking %i parameters:(",
+                   prog_getstring(prog, prog->functions[i].name),
+                   (unsigned int)prog->functions[i].nargs);
+            for (a = 0; a < prog->functions[i].nargs; ++a) {
+                printf(" %i", prog->functions[i].argsize[a]);
+            }
+            printf(") locals: %i + %i\n",
+                   prog->functions[i].firstlocal,
+                   prog->functions[i].locals);
         }
     }
     else
@@ -956,7 +988,7 @@ void prog_disasm_function(qc_program *prog, size_t id)
         printf("FUNCTION \"%s\"\n", prog_getstring(prog, fdef->name));
 
     st = prog->code + fdef->entry;
-    while (st->opcode != AINSTR_END) {
+    while (st->opcode != INSTR_DONE) {
         prog_print_statement(prog, st);
         ++st;
     }