about summary refs log tree commit diff stats
path: root/010vm.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-02-19 14:50:44 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-02-19 14:50:44 -0800
commit6cc999ae812b835786f08a0b8d958a545c3d8ef0 (patch)
tree6eb40a9e71d4cc24a3a34c56aa471ca0b49c32b6 /010vm.cc
parent8a3d101e3d617107596c3eed393571eb5cbddbd6 (diff)
downloadmu-6cc999ae812b835786f08a0b8d958a545c3d8ef0.tar.gz
2670 - better names for string conversions
  to_string(): relatively stable fields only; for trace()
  debug_string(): all fields; for debugging
  inspect(): for a form that can be parsed back later
Diffstat (limited to '010vm.cc')
-rw-r--r--010vm.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/010vm.cc b/010vm.cc
index a14bd0d7..711f8fa4 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -401,6 +401,8 @@ void dump_memory() {
 //: Use to_string() in trace(), and try to avoid relying on unstable codes that
 //: will perturb .traces/ from commit to commit.
 //: Use debug_string() while debugging, and throw everything into it.
+//: Use inspect() only for emitting a canonical format that can be parsed back
+//: into the value.
 
 string to_string(const recipe& r) {
   ostringstream out;
@@ -450,7 +452,7 @@ string to_string(const reagent& r) {
     out << "{";
     for (long long int i = 0; i < SIZE(r.properties); ++i) {
       if (i > 0) out << ", ";
-      out << "\"" << r.properties.at(i).first << "\": " << debug_string(r.properties.at(i).second);
+      out << "\"" << r.properties.at(i).first << "\": " << to_string(r.properties.at(i).second);
     }
     out << "}";
   }
@@ -463,13 +465,13 @@ string debug_string(const reagent& x) {
   return out.str();
 }
 
-string to_string(const string_tree* x) {
+string inspect(const string_tree* x) {
   ostringstream out;
-  dump(x, out);
+  dump_inspect(x, out);
   return out.str();
 }
 
-void dump(const string_tree* x, ostream& out) {
+void dump_inspect(const string_tree* x, ostream& out) {
   if (!x->left && !x->right) {
     out << x->value;
     return;
@@ -478,25 +480,25 @@ void dump(const string_tree* x, ostream& out) {
   for (const string_tree* curr = x; curr; curr = curr->right) {
     if (curr != x) out << ' ';
     if (curr->left)
-      dump(curr->left, out);
+      dump_inspect(curr->left, out);
     else
       out << curr->value;
   }
   out << ')';
 }
 
-string debug_string(const string_tree* property) {
+string to_string(const string_tree* property) {
   if (!property) return "()";
   ostringstream out;
   if (!property->left && !property->right)
     // abbreviate a single-node tree to just its contents
     out << '"' << property->value << '"';
   else
-    dump_debug(property, out);
+    dump(property, out);
   return out.str();
 }
 
-void dump_debug(const string_tree* x, ostream& out) {
+void dump(const string_tree* x, ostream& out) {
   if (!x->left && !x->right) {
     out << x->value;
     return;
@@ -505,7 +507,7 @@ void dump_debug(const string_tree* x, ostream& out) {
   for (const string_tree* curr = x; curr; curr = curr->right) {
     if (curr != x) out << ' ';
     if (curr->left)
-      dump_debug(curr->left, out);
+      dump(curr->left, out);
     else
       out << '"' << curr->value << '"';
   }