]> granicus.if.org Git - jq/commitdiff
Make a main program that doesn't spam debugging info.
authorStephen Dolan <mu@netsoc.tcd.ie>
Mon, 10 Sep 2012 09:23:15 +0000 (10:23 +0100)
committerStephen Dolan <mu@netsoc.tcd.ie>
Mon, 10 Sep 2012 09:23:15 +0000 (10:23 +0100)
c/Makefile
c/execute.c
c/main.c

index 2c4379de863c8fa6b101771fb7383ee14263d222..cad23302bf50a6c88eb8a3a700a9734c316e7ea7 100644 (file)
@@ -22,7 +22,10 @@ parser.tab.h: parser.tab.c
 jv_unicode.c: jv_utf8_tables.h
 
 parsertest: parser.tab.c lexer.yy.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c
-       $(CC) -o $@ $^
+       $(CC) -DJQ_DEBUG=1 -o $@ $^
+
+jq: parser.tab.c lexer.yy.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c
+       $(CC) -DJQ_DEBUG=0 -o $@ $^
 
 jv_test: jv_test.c jv.c jv_print.c jv_dtoa.c
        $(CC) -DNO_JANSSON -o $@ $^
index 5e6a2c5121e274308bd42030ecdb651640a9d375..62984ca4b28245ed8f5483877976493205c9ff07 100644 (file)
@@ -148,10 +148,10 @@ jv jq_next() {
 
   int backtracking = 0;
   while (1) {
-    dump_operation(frame_current_bytecode(&frame_stk), pc);
-
-    uint16_t opcode = *pc++;
+    uint16_t opcode = *pc;
 
+#if JQ_DEBUG
+    dump_operation(frame_current_bytecode(&frame_stk), pc);
     printf("\t");
     const struct opcode_description* opdesc = opcode_describe(opcode);
     data_stk_elem* param;
@@ -167,13 +167,15 @@ jv jq_next() {
       printf("<%d>", jv_get_refcnt(param->sv.value));
     }
 
+    if (backtracking) printf("\t<backtracking>");
+
+    printf("\n");
+#endif
     if (backtracking) {
-      printf("\t<backtracking>");
       opcode = ON_BACKTRACK(opcode);
       backtracking = 0;
     }
-
-    printf("\n");
+    pc++;
 
     switch (opcode) {
     default: assert(0 && "invalid instruction");
@@ -235,9 +237,11 @@ jv jq_next() {
       uint16_t v = *pc++;
       frame_ptr fp = frame_get_level(&frame_stk, frame_current(&frame_stk), level);
       jv* var = frame_local_var(fp, v);
+      #if JQ_DEBUG
       printf("V%d = ", v);
       jv_dump(jv_copy(*var));
       printf("\n");
+      #endif
       stack_push(stackval_replace(stack_pop(), jv_copy(*var)));
       break;
     }
@@ -248,9 +252,11 @@ jv jq_next() {
       frame_ptr fp = frame_get_level(&frame_stk, frame_current(&frame_stk), level);
       jv* var = frame_local_var(fp, v);
       stackval val = stack_pop();
+      #if JQ_DEBUG
       printf("V%d = ", v);
       jv_dump(jv_copy(val.value));
       printf("\n");
+      #endif
       jv_free(*var);
       *var = val.value;
       break;
@@ -368,7 +374,6 @@ jv jq_next() {
       stackval top = stack_pop();
       cfunc_input[0] = top.value;
       struct cfunction* func = &frame_current_bytecode(&frame_stk)->globals->cfunctions[*pc++];
-      printf(" call %s\n", func->name);
       func->fptr(cfunc_input, cfunc_output);
       top.value = cfunc_output[0];
       stack_push(top);
@@ -386,7 +391,6 @@ jv jq_next() {
       cfunc_input[1] = a;
       cfunc_input[2] = b;
       struct cfunction* func = &frame_current_bytecode(&frame_stk)->globals->cfunctions[*pc++];
-      printf(" call %s\n", func->name);
       func->fptr(cfunc_input, cfunc_output);
       top.value = cfunc_output[0];
       stack_push(top);
@@ -450,7 +454,11 @@ void jq_teardown() {
 }
 
 void run_program(struct bytecode* bc) {
-  char buf[4096];
+#if JQ_DEBUG
+  dump_disassembly(0, bc);
+  printf("\n");
+#endif
+  char buf[409600];
   fgets(buf, sizeof(buf), stdin);
   jq_init(bc, jv_parse(buf));
   jv result;
@@ -458,6 +466,8 @@ void run_program(struct bytecode* bc) {
     jv_dump(result);
     printf("\n");
   }
+  #if JQ_DEBUG
   printf("end of results\n");
+  #endif
   jq_teardown();
 }
index b71bcad5010710b9f1354b80a676569ddc9b7d3c..7e274c4a151b7fe4609fa1334373ad2e720d708c 100644 (file)
--- a/c/main.c
+++ b/c/main.c
@@ -88,8 +88,6 @@ int main(int argc, char* argv[]) {
   blk = gen_cbinding(&builtins, blk);
   struct bytecode* bc = block_compile(blk);
   block_free(blk);
-  dump_disassembly(0, bc);
-  printf("\n");
   run_program(bc);
   bytecode_free(bc);
 }