From c2593dc417fb23b5410f7f0f99a5a570ced6f658 Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Mon, 10 Sep 2012 10:23:15 +0100 Subject: [PATCH] Make a main program that doesn't spam debugging info. --- c/Makefile | 5 ++++- c/execute.c | 28 +++++++++++++++++++--------- c/main.c | 2 -- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/c/Makefile b/c/Makefile index 2c4379d..cad2330 100644 --- a/c/Makefile +++ b/c/Makefile @@ -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 $@ $^ diff --git a/c/execute.c b/c/execute.c index 5e6a2c5..62984ca 100644 --- a/c/execute.c +++ b/c/execute.c @@ -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"); + + printf("\n"); +#endif if (backtracking) { - printf("\t"); 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(); } diff --git a/c/main.c b/c/main.c index b71bcad..7e274c4 100644 --- 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); } -- 2.40.0