about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-19 15:36:49 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-19 15:37:47 -0800
commitf4b6b2c2876bb29c01bfd95f55347e7d74222974 (patch)
tree151c84af6dca71de824267275e4edfb665ec2a26
parentcae5461b1dfeb70dac6b66192fc6b12952beb723 (diff)
downloadmu-f4b6b2c2876bb29c01bfd95f55347e7d74222974.tar.gz
784 - persist traces in literate version
-rw-r--r--cpp/.traces/copy_literal (renamed from cpp/.traces/parse)3
-rw-r--r--cpp/.traces/first_recipe (renamed from cpp/.traces/literal)0
-rw-r--r--cpp/.traces/parse_multiple_ingredients5
-rw-r--r--cpp/.traces/parse_multiple_products (renamed from cpp/.traces/parse2)0
-rw-r--r--cpp/001test2
-rw-r--r--cpp/002trace13
-rw-r--r--cpp/makefile2
-rw-r--r--cpp/tangle/030tangle.cc2
8 files changed, 25 insertions, 2 deletions
diff --git a/cpp/.traces/parse b/cpp/.traces/copy_literal
index d20319d2..94d56f2e 100644
--- a/cpp/.traces/parse
+++ b/cpp/.traces/copy_literal
@@ -1,3 +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/literal b/cpp/.traces/first_recipe
index d20319d2..d20319d2 100644
--- a/cpp/.traces/literal
+++ b/cpp/.traces/first_recipe
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/parse2 b/cpp/.traces/parse_multiple_products
index f8d5050e..f8d5050e 100644
--- a/cpp/.traces/parse2
+++ b/cpp/.traces/parse_multiple_products
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<string>::iterator balancing_curly(list<string>::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<string>& lines, list<string>& 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