From f4b6b2c2876bb29c01bfd95f55347e7d74222974 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 19 Feb 2015 15:36:49 -0800 Subject: 784 - persist traces in literate version --- cpp/.traces/copy_literal | 6 ++++++ cpp/.traces/first_recipe | 3 +++ cpp/.traces/literal | 3 --- cpp/.traces/parse | 3 --- cpp/.traces/parse2 | 4 ---- cpp/.traces/parse_multiple_ingredients | 5 +++++ cpp/.traces/parse_multiple_products | 4 ++++ cpp/001test | 2 ++ cpp/002trace | 13 ++++++++++++- cpp/makefile | 2 ++ cpp/tangle/030tangle.cc | 2 +- 11 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 cpp/.traces/copy_literal create mode 100644 cpp/.traces/first_recipe delete mode 100644 cpp/.traces/literal delete mode 100644 cpp/.traces/parse delete mode 100644 cpp/.traces/parse2 create mode 100644 cpp/.traces/parse_multiple_ingredients create mode 100644 cpp/.traces/parse_multiple_products (limited to 'cpp') diff --git a/cpp/.traces/copy_literal b/cpp/.traces/copy_literal new file mode 100644 index 00000000..94d56f2e --- /dev/null +++ b/cpp/.traces/copy_literal @@ -0,0 +1,6 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "23", type: 0} +parse/0: product: {name: "1", type: 1} +run/0: instruction 0 +run/0: ingredient 0 is 23 +mem/0: storing in location 1 diff --git a/cpp/.traces/first_recipe b/cpp/.traces/first_recipe new file mode 100644 index 00000000..d20319d2 --- /dev/null +++ b/cpp/.traces/first_recipe @@ -0,0 +1,3 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "23", type: 0} +parse/0: product: {name: "1", type: 1} diff --git a/cpp/.traces/literal b/cpp/.traces/literal deleted file mode 100644 index d20319d2..00000000 --- a/cpp/.traces/literal +++ /dev/null @@ -1,3 +0,0 @@ -parse/0: instruction: 1 -parse/0: ingredient: {name: "23", type: 0} -parse/0: product: {name: "1", type: 1} diff --git a/cpp/.traces/parse b/cpp/.traces/parse deleted file mode 100644 index d20319d2..00000000 --- a/cpp/.traces/parse +++ /dev/null @@ -1,3 +0,0 @@ -parse/0: instruction: 1 -parse/0: ingredient: {name: "23", type: 0} -parse/0: product: {name: "1", type: 1} diff --git a/cpp/.traces/parse2 b/cpp/.traces/parse2 deleted file mode 100644 index f8d5050e..00000000 --- a/cpp/.traces/parse2 +++ /dev/null @@ -1,4 +0,0 @@ -parse/0: instruction: 1 -parse/0: ingredient: {name: "23", type: 0} -parse/0: product: {name: "1", type: 1} -parse/0: product: {name: "2", type: 1} diff --git a/cpp/.traces/parse_multiple_ingredients b/cpp/.traces/parse_multiple_ingredients new file mode 100644 index 00000000..ee0c09ba --- /dev/null +++ b/cpp/.traces/parse_multiple_ingredients @@ -0,0 +1,5 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "23", type: 0} +parse/0: ingredient: {name: "4", type: 1} +parse/0: product: {name: "1", type: 1} +parse/0: product: {name: "2", type: 1} diff --git a/cpp/.traces/parse_multiple_products b/cpp/.traces/parse_multiple_products new file mode 100644 index 00000000..f8d5050e --- /dev/null +++ b/cpp/.traces/parse_multiple_products @@ -0,0 +1,4 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "23", type: 0} +parse/0: product: {name: "1", type: 1} +parse/0: product: {name: "2", type: 1} diff --git a/cpp/001test b/cpp/001test index 45ec591d..ed10e97e 100644 --- a/cpp/001test +++ b/cpp/001test @@ -20,6 +20,8 @@ bool Passed = true; long Num_failures = 0; +#define TEST(name) void test_##name() { Trace_file = #name; + #define CHECK(X) \ if (!(X)) { \ ++Num_failures; \ diff --git a/cpp/002trace b/cpp/002trace index 4d584cb1..e3ebd17e 100644 --- a/cpp/002trace +++ b/cpp/002trace @@ -185,9 +185,20 @@ ostream& operator<<(ostream& os, unused die) { #define DUMP(layer) cerr << Trace_stream->readable_contents(layer) // Trace_stream is a resource, lease_tracer uses RAII to manage it. +string Trace_file; +static string Trace_dir = ".traces/"; struct lease_tracer { lease_tracer() { Trace_stream = new trace_stream; } - ~lease_tracer() { delete Trace_stream, Trace_stream = NULL; } + ~lease_tracer() { +//? cerr << "write to file? " << Trace_file << "$\n"; //? 2 + if (!Trace_file.empty()) { +//? cerr << "writing\n"; //? 2 + ofstream fout((Trace_dir+Trace_file).c_str()); + fout << Trace_stream->readable_contents(""); + fout.close(); + } + delete Trace_stream, Trace_stream = NULL, Trace_file = ""; + } }; #define START_TRACING_UNTIL_END_OF_SCOPE lease_tracer leased_tracer; diff --git a/cpp/makefile b/cpp/makefile index 97187383..fe801a95 100644 --- a/cpp/makefile +++ b/cpp/makefile @@ -17,9 +17,11 @@ autogenerated_lists: mu.cc function_list test_list function_list: mu.cc @grep -h "^[^ #].*) {" mu.cc |perl -pwe 's/ {.*/;/' > function_list + @grep -h "^[[:space:]]*TEST(" mu.cc |perl -pwe 's/^\s*TEST\((.*)\)$$/void test_$$1();/' >> function_list test_list: mu.cc @grep -h "^[[:space:]]*void test_" mu.cc |perl -pwe 's/^\s*void (.*)\(\) {.*/$$1,/' > test_list + @grep -h "^[[:space:]]*TEST(" mu.cc |perl -pwe 's/^\s*TEST\((.*)\)$$/test_$$1,/' >> test_list clean: cd tangle && make clean diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc index 2dda8667..c47c8cc1 100644 --- a/cpp/tangle/030tangle.cc +++ b/cpp/tangle/030tangle.cc @@ -181,7 +181,7 @@ list::iterator balancing_curly(list::iterator orig) { // followed by one or more lines trace shouldn't include ('-') // Remember to update is_input below if you add to this format. void emit_test(const string& name, list& lines, list& result) { - result.push_back("void test_"+name+"() {"); + result.push_back("TEST("+name+")"); while (any_non_input_line(lines)) { if (!any_line_starts_with(lines, "=>")) emit_session(lines, result); // simpler version; no need to check result -- cgit 1.4.1-2-gfad0