diff options
Diffstat (limited to 'cpp/010vm.cc')
-rw-r--r-- | cpp/010vm.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cpp/010vm.cc b/cpp/010vm.cc index 40f8f269..e38a5958 100644 --- a/cpp/010vm.cc +++ b/cpp/010vm.cc @@ -30,6 +30,7 @@ struct instruction { vector<reagent> products; // only if !is_label instruction(); void clear(); + string to_string() const; }; :(before "struct instruction") @@ -218,6 +219,22 @@ string reagent::to_string() const { return out.str(); } +string instruction::to_string() const { + if (is_label) return label; + ostringstream out; + for (size_t i = 0; i < products.size(); ++i) { + if (i > 0) out << ", "; + out << products[i].to_string(); + } + if (!products.empty()) out << " <- "; + out << name << ' '; + for (size_t i = 0; i < ingredients.size(); ++i) { + if (i > 0) out << ", "; + out << ingredients[i].to_string(); + } + return out.str(); +} + string slurp_until(istream& in, char delim) { ostringstream out; char c; |