diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-03-21 02:25:52 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-03-21 02:25:52 -0700 |
commit | acc4792d2f7c787aad064876a1eb2d00bdf076b2 (patch) | |
tree | 22aaf0d8ff820082d66008311607e639c2d48989 /010vm.cc | |
parent | dad3bedd1ca78162f87a235c10b036a06492a5f5 (diff) | |
download | mu-acc4792d2f7c787aad064876a1eb2d00bdf076b2.tar.gz |
2803
Show more thorough information about instructions in the trace, but keep the original form in error messages.
Diffstat (limited to '010vm.cc')
-rw-r--r-- | 010vm.cc | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/010vm.cc b/010vm.cc index 1120280c..c3618ffe 100644 --- a/010vm.cc +++ b/010vm.cc @@ -34,7 +34,7 @@ struct instruction { string label; // only if is_label string name; // only if !is_label string old_name; // before our automatic rewrite rules - string original_string; + string original_string; // for error messages recipe_ordinal operation; // get(Recipe_ordinal, name) vector<reagent> ingredients; // only if !is_label vector<reagent> products; // only if !is_label @@ -451,7 +451,7 @@ string debug_string(const recipe& x) { return out.str(); } -string to_string(const instruction& inst) { +string to_original_string(const instruction& inst) { if (inst.is_label) return inst.label; ostringstream out; for (int i = 0; i < SIZE(inst.products); ++i) { @@ -467,20 +467,40 @@ string to_string(const instruction& inst) { return out.str(); } +string to_string(const instruction& inst) { + if (inst.is_label) return inst.label; + ostringstream out; + for (int i = 0; i < SIZE(inst.products); ++i) { + if (i > 0) out << ", "; + out << to_string(inst.products.at(i)); + } + if (!inst.products.empty()) out << " <- "; + out << inst.name << ' '; + for (int i = 0; i < SIZE(inst.ingredients); ++i) { + if (i > 0) out << ", "; + out << to_string(inst.ingredients.at(i)); + } + return out.str(); +} + string to_string(const reagent& r) { + if (is_dummy(r)) return "_"; ostringstream out; + out << "{"; out << r.name << ": " << names_to_string(r.type); if (!r.properties.empty()) { - out << ", {"; - for (int i = 0; i < SIZE(r.properties); ++i) { - if (i > 0) out << ", "; - out << "\"" << r.properties.at(i).first << "\": " << to_string(r.properties.at(i).second); - } - out << "}"; + for (int i = 0; i < SIZE(r.properties); ++i) + out << ", \"" << r.properties.at(i).first << "\": " << to_string(r.properties.at(i).second); } + out << "}"; return out.str(); } +// special name for ignoring some products +inline bool is_dummy(const reagent& x) { + return x.name == "_"; +} + string debug_string(const reagent& x) { ostringstream out; out << x.name << ": " << x.value << ' ' << to_string(x.type) << " -- " << to_string(x); |