From 2b37bbeae29e55f1456a4540741ceefdb5a0aa4b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 4 Apr 2017 00:10:47 -0700 Subject: 3809 --- 010vm.cc | 3 +- 026call.cc | 4 +- 038new_text.cc | 2 +- html/010vm.cc.html | 453 ++++++++++++++++++++++++----------------------- html/026call.cc.html | 4 +- html/038new_text.cc.html | 2 +- 6 files changed, 235 insertions(+), 233 deletions(-) diff --git a/010vm.cc b/010vm.cc index fea11a50..d23a9fbd 100644 --- a/010vm.cc +++ b/010vm.cc @@ -628,7 +628,8 @@ string to_original_string(const instruction& inst) { out << inst.products.at(i).original_string; } if (!inst.products.empty()) out << " <- "; - out << inst.name << ' '; + out << inst.name; + if (!inst.ingredients.empty()) out << ' '; for (int i = 0; i < SIZE(inst.ingredients); ++i) { if (i > 0) out << ", "; out << inst.ingredients.at(i).original_string; diff --git a/026call.cc b/026call.cc index 7ad4dd33..269515cc 100644 --- a/026call.cc +++ b/026call.cc @@ -133,14 +133,14 @@ void finish_call_housekeeping(const instruction& call_instruction, const vector< def main [ foo ] -+error: main: undefined operation in 'foo ' ++error: main: undefined operation in 'foo' :(scenario calling_undefined_recipe_handles_missing_result) % Hide_errors = true; def main [ x:num <- foo ] -+error: main: undefined operation in 'x:num <- foo ' ++error: main: undefined operation in 'x:num <- foo' //:: finally, we need to fix the termination conditions for the run loop diff --git a/038new_text.cc b/038new_text.cc index d6019e5e..41a29b6e 100644 --- a/038new_text.cc +++ b/038new_text.cc @@ -69,7 +69,7 @@ int new_mu_text(const string& contents) { def main [ [abc] ] -+error: main: instruction '[abc]' has no recipe in '[abc] ' ++error: main: instruction '[abc]' has no recipe in '[abc]' //: stash recognizes strings diff --git a/html/010vm.cc.html b/html/010vm.cc.html index 9b80d3ee..6d967836 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -692,232 +692,233 @@ if ('onhashchange' in window) { 628 ¦ out << inst.products.at(i).original_string; 629 } 630 if (!inst.products.empty()) out << " <- "; -631 out << inst.name << ' '; -632 for (int i = 0; i < SIZE(inst.ingredients); ++i) { -633 ¦ if (i > 0) out << ", "; -634 ¦ out << inst.ingredients.at(i).original_string; -635 } -636 return out.str(); -637 } -638 -639 string to_string(const instruction& inst) { -640 if (inst.is_label) return inst.label; -641 ostringstream out; -642 for (int i = 0; i < SIZE(inst.products); ++i) { -643 ¦ if (i > 0) out << ", "; -644 ¦ out << to_string(inst.products.at(i)); -645 } -646 if (!inst.products.empty()) out << " <- "; -647 out << inst.name << ' '; -648 for (int i = 0; i < SIZE(inst.ingredients); ++i) { -649 ¦ if (i > 0) out << ", "; -650 ¦ out << to_string(inst.ingredients.at(i)); -651 } -652 return out.str(); -653 } -654 -655 string to_string(const reagent& r) { -656 if (is_dummy(r)) return "_"; -657 ostringstream out; -658 out << "{"; -659 out << r.name << ": " << names_to_string(r.type); -660 if (!r.properties.empty()) { -661 ¦ for (int i = 0; i < SIZE(r.properties); ++i) -662 ¦ ¦ out << ", \"" << r.properties.at(i).first << "\": " << to_string(r.properties.at(i).second); -663 } -664 out << "}"; -665 return out.str(); -666 } -667 -668 // special name for ignoring some products -669 bool is_dummy(const reagent& x) { -670 return x.name == "_"; -671 } -672 -673 string debug_string(const reagent& x) { -674 ostringstream out; -675 out << x.name << ": " << x.value << ' ' << to_string(x.type) << " -- " << to_string(x); -676 return out.str(); -677 } -678 -679 string to_string(const string_tree* property) { -680 if (!property) return "()"; -681 ostringstream out; -682 dump(property, out); -683 return out.str(); -684 } -685 -686 void dump(const string_tree* x, ostream& out) { -687 if (!x) return; -688 if (x->atom) { -689 ¦ out << '"' << x->value << '"'; -690 ¦ return; -691 } -692 out << '('; -693 const string_tree* curr = x; -694 while (curr && !curr->atom) { -695 ¦ dump(curr->left, out); -696 ¦ if (curr->right) out << ' '; -697 ¦ curr = curr->right; -698 } -699 // check for dotted list; should never happen -700 if (curr) { -701 ¦ out << ". "; -702 ¦ dump(curr, out); -703 } -704 out << ')'; -705 } -706 -707 string to_string(const type_tree* type) { -708 // abbreviate a single-node tree to just its contents -709 if (!type) return "NULLNULLNULL"; // should never happen -710 ostringstream out; -711 dump(type, out); -712 return out.str(); -713 } -714 -715 void dump(const type_tree* x, ostream& out) { -716 if (!x) return; -717 if (x->atom) { -718 ¦ dump(x->value, out); -719 ¦ return; -720 } -721 out << '('; -722 const type_tree* curr = x; -723 while (curr && !curr->atom) { -724 ¦ dump(curr->left, out); -725 ¦ if (curr->right) out << ' '; -726 ¦ curr = curr->right; -727 } -728 // check for dotted list; should never happen -729 if (curr) { -730 ¦ out << ". "; -731 ¦ dump(curr, out); -732 } -733 out << ')'; -734 } -735 -736 void dump(type_ordinal type, ostream& out) { -737 if (contains_key(Type, type)) -738 ¦ out << get(Type, type).name; -739 else -740 ¦ out << "?" << type; -741 } -742 -743 string names_to_string(const type_tree* type) { -744 // abbreviate a single-node tree to just its contents -745 if (!type) return "()"; // should never happen -746 ostringstream out; -747 dump_names(type, out); -748 return out.str(); -749 } -750 -751 void dump_names(const type_tree* x, ostream& out) { -752 if (!x) return; -753 if (x->atom) { -754 ¦ out << '"' << x->name << '"'; -755 ¦ return; -756 } -757 out << '('; -758 const type_tree* curr = x; -759 while (curr && !curr->atom) { -760 ¦ dump_names(curr->left, out); -761 ¦ if (curr->right) out << ' '; -762 ¦ curr = curr->right; -763 } -764 // check for dotted list; should never happen -765 if (curr) { -766 ¦ out << ". "; -767 ¦ dump_names(curr, out); -768 } -769 out << ')'; -770 } -771 -772 string names_to_string_without_quotes(const type_tree* type) { -773 // abbreviate a single-node tree to just its contents -774 if (!type) return "NULLNULLNULL"; // should never happen -775 ostringstream out; -776 dump_names_without_quotes(type, out); -777 return out.str(); -778 } -779 -780 void dump_names_without_quotes(const type_tree* x, ostream& out) { -781 if (!x) return; -782 if (x->atom) { -783 ¦ out << x->name; -784 ¦ return; -785 } -786 out << '('; -787 const type_tree* curr = x; -788 while (curr && !curr->atom) { -789 ¦ dump_names_without_quotes(curr->left, out); -790 ¦ if (curr->right) out << ' '; -791 ¦ curr = curr->right; -792 } -793 // check for dotted list; should never happen -794 if (curr) { -795 ¦ out << ". "; -796 ¦ dump_names_without_quotes(curr, out); -797 } -798 out << ')'; -799 } -800 -801 //: helper to print numbers without excessive precision -802 -803 :(before "End Types") -804 struct no_scientific { -805 double x; -806 explicit no_scientific(double y) :x(y) {} -807 }; -808 -809 :(code) -810 ostream& operator<<(ostream& os, no_scientific x) { -811 if (!isfinite(x.x)) { -812 ¦ // Infinity or NaN -813 ¦ os << x.x; -814 ¦ return os; -815 } -816 ostringstream tmp; -817 // more accurate, but too slow -818 //? tmp.precision(308); // for 64-bit numbers -819 tmp << std::fixed << x.x; -820 os << trim_floating_point(tmp.str()); -821 return os; -822 } -823 -824 string trim_floating_point(const string& in) { -825 if (in.empty()) return ""; -826 if (in.find('.') == string::npos) return in; -827 int length = SIZE(in); -828 while (length > 1) { -829 ¦ if (in.at(length-1) != '0') break; -830 ¦ --length; -831 } -832 if (in.at(length-1) == '.') --length; -833 if (length == 0) return "0"; -834 return in.substr(0, length); -835 } -836 -837 void test_trim_floating_point() { -838 CHECK_EQ(trim_floating_point(""), ""); -839 CHECK_EQ(trim_floating_point(".0"), "0"); -840 CHECK_EQ(trim_floating_point("1.5000"), "1.5"); -841 CHECK_EQ(trim_floating_point("1.000001"), "1.000001"); -842 CHECK_EQ(trim_floating_point("23.000000"), "23"); -843 CHECK_EQ(trim_floating_point("23.0"), "23"); -844 CHECK_EQ(trim_floating_point("23."), "23"); -845 CHECK_EQ(trim_floating_point("23"), "23"); -846 CHECK_EQ(trim_floating_point("230"), "230"); -847 CHECK_EQ(trim_floating_point("3.000000"), "3"); -848 CHECK_EQ(trim_floating_point("3.0"), "3"); -849 CHECK_EQ(trim_floating_point("3."), "3"); -850 CHECK_EQ(trim_floating_point("3"), "3"); -851 } -852 -853 :(before "End Includes") -854 #include <utility> -855 using std::pair; -856 #include <math.h> +631 out << inst.name; +632 if (!inst.ingredients.empty()) out << ' '; +633 for (int i = 0; i < SIZE(inst.ingredients); ++i) { +634 ¦ if (i > 0) out << ", "; +635 ¦ out << inst.ingredients.at(i).original_string; +636 } +637 return out.str(); +638 } +639 +640 string to_string(const instruction& inst) { +641 if (inst.is_label) return inst.label; +642 ostringstream out; +643 for (int i = 0; i < SIZE(inst.products); ++i) { +644 ¦ if (i > 0) out << ", "; +645 ¦ out << to_string(inst.products.at(i)); +646 } +647 if (!inst.products.empty()) out << " <- "; +648 out << inst.name << ' '; +649 for (int i = 0; i < SIZE(inst.ingredients); ++i) { +650 ¦ if (i > 0) out << ", "; +651 ¦ out << to_string(inst.ingredients.at(i)); +652 } +653 return out.str(); +654 } +655 +656 string to_string(const reagent& r) { +657 if (is_dummy(r)) return "_"; +658 ostringstream out; +659 out << "{"; +660 out << r.name << ": " << names_to_string(r.type); +661 if (!r.properties.empty()) { +662 ¦ for (int i = 0; i < SIZE(r.properties); ++i) +663 ¦ ¦ out << ", \"" << r.properties.at(i).first << "\": " << to_string(r.properties.at(i).second); +664 } +665 out << "}"; +666 return out.str(); +667 } +668 +669 // special name for ignoring some products +670 bool is_dummy(const reagent& x) { +671 return x.name == "_"; +672 } +673 +674 string debug_string(const reagent& x) { +675 ostringstream out; +676 out << x.name << ": " << x.value << ' ' << to_string(x.type) << " -- " << to_string(x); +677 return out.str(); +678 } +679 +680 string to_string(const string_tree* property) { +681 if (!property) return "()"; +682 ostringstream out; +683 dump(property, out); +684 return out.str(); +685 } +686 +687 void dump(const string_tree* x, ostream& out) { +688 if (!x) return; +689 if (x->atom) { +690 ¦ out << '"' << x->value << '"'; +691 ¦ return; +692 } +693 out << '('; +694 const string_tree* curr = x; +695 while (curr && !curr->atom) { +696 ¦ dump(curr->left, out); +697 ¦ if (curr->right) out << ' '; +698 ¦ curr = curr->right; +699 } +700 // check for dotted list; should never happen +701 if (curr) { +702 ¦ out << ". "; +703 ¦ dump(curr, out); +704 } +705 out << ')'; +706 } +707 +708 string to_string(const type_tree* type) { +709 // abbreviate a single-node tree to just its contents +710 if (!type) return "NULLNULLNULL"; // should never happen +711 ostringstream out; +712 dump(type, out); +713 return out.str(); +714 } +715 +716 void dump(const type_tree* x, ostream& out) { +717 if (!x) return; +718 if (x->atom) { +719 ¦ dump(x->value, out); +720 ¦ return; +721 } +722 out << '('; +723 const type_tree* curr = x; +724 while (curr && !curr->atom) { +725 ¦ dump(curr->left, out); +726 ¦ if (curr->right) out << ' '; +727 ¦ curr = curr->right; +728 } +729 // check for dotted list; should never happen +730 if (curr) { +731 ¦ out << ". "; +732 ¦ dump(curr, out); +733 } +734 out << ')'; +735 } +736 +737 void dump(type_ordinal type, ostream& out) { +738 if (contains_key(Type, type)) +739 ¦ out << get(Type, type).name; +740 else +741 ¦ out << "?" << type; +742 } +743 +744 string names_to_string(const type_tree* type) { +745 // abbreviate a single-node tree to just its contents +746 if (!type) return "()"; // should never happen +747 ostringstream out; +748 dump_names(type, out); +749 return out.str(); +750 } +751 +752 void dump_names(const type_tree* x, ostream& out) { +753 if (!x) return; +754 if (x->atom) { +755 ¦ out << '"' << x->name << '"'; +756 ¦ return; +757 } +758 out << '('; +759 const type_tree* curr = x; +760 while (curr && !curr->atom) { +761 ¦ dump_names(curr->left, out); +762 ¦ if (curr->right) out << ' '; +763 ¦ curr = curr->right; +764 } +765 // check for dotted list; should never happen +766 if (curr) { +767 ¦ out << ". "; +768 ¦ dump_names(curr, out); +769 } +770 out << ')'; +771 } +772 +773 string names_to_string_without_quotes(const type_tree* type) { +774 // abbreviate a single-node tree to just its contents +775 if (!type) return "NULLNULLNULL"; // should never happen +776 ostringstream out; +777 dump_names_without_quotes(type, out); +778 return out.str(); +779 } +780 +781 void dump_names_without_quotes(const type_tree* x, ostream& out) { +782 if (!x) return; +783 if (x->atom) { +784 ¦ out << x->name; +785 ¦ return; +786 } +787 out << '('; +788 const type_tree* curr = x; +789 while (curr && !curr->atom) { +790 ¦ dump_names_without_quotes(curr->left, out); +791 ¦ if (curr->right) out << ' '; +792 ¦ curr = curr->right; +793 } +794 // check for dotted list; should never happen +795 if (curr) { +796 ¦ out << ". "; +797 ¦ dump_names_without_quotes(curr, out); +798 } +799 out << ')'; +800 } +801 +802 //: helper to print numbers without excessive precision +803 +804 :(before "End Types") +805 struct no_scientific { +806 double x; +807 explicit no_scientific(double y) :x(y) {} +808 }; +809 +810 :(code) +811 ostream& operator<<(ostream& os, no_scientific x) { +812 if (!isfinite(x.x)) { +813 ¦ // Infinity or NaN +814 ¦ os << x.x; +815 ¦ return os; +816 } +817 ostringstream tmp; +818 // more accurate, but too slow +819 //? tmp.precision(308); // for 64-bit numbers +820 tmp << std::fixed << x.x; +821 os << trim_floating_point(tmp.str()); +822 return os; +823 } +824 +825 string trim_floating_point(const string& in) { +826 if (in.empty()) return ""; +827 if (in.find('.') == string::npos) return in; +828 int length = SIZE(in); +829 while (length > 1) { +830 ¦ if (in.at(length-1) != '0') break; +831 ¦ --length; +832 } +833 if (in.at(length-1) == '.') --length; +834 if (length == 0) return "0"; +835 return in.substr(0, length); +836 } +837 +838 void test_trim_floating_point() { +839 CHECK_EQ(trim_floating_point(""), ""); +840 CHECK_EQ(trim_floating_point(".0"), "0"); +841 CHECK_EQ(trim_floating_point("1.5000"), "1.5"); +842 CHECK_EQ(trim_floating_point("1.000001"), "1.000001"); +843 CHECK_EQ(trim_floating_point("23.000000"), "23"); +844 CHECK_EQ(trim_floating_point("23.0"), "23"); +845 CHECK_EQ(trim_floating_point("23."), "23"); +846 CHECK_EQ(trim_floating_point("23"), "23"); +847 CHECK_EQ(trim_floating_point("230"), "230"); +848 CHECK_EQ(trim_floating_point("3.000000"), "3"); +849 CHECK_EQ(trim_floating_point("3.0"), "3"); +850 CHECK_EQ(trim_floating_point("3."), "3"); +851 CHECK_EQ(trim_floating_point("3"), "3"); +852 } +853 +854 :(before "End Includes") +855 #include <utility> +856 using std::pair; +857 #include <math.h> diff --git a/html/026call.cc.html b/html/026call.cc.html index 40a396b5..bafd5907 100644 --- a/html/026call.cc.html +++ b/html/026call.cc.html @@ -197,14 +197,14 @@ if ('onhashchange' in window) { 133 def main [ 134 foo 135 ] -136 +error: main: undefined operation in 'foo ' +136 +error: main: undefined operation in 'foo' 137 138 :(scenario calling_undefined_recipe_handles_missing_result) 139 % Hide_errors = true; 140 def main [ 141 x:num <- foo 142 ] -143 +error: main: undefined operation in 'x:num <- foo ' +143 +error: main: undefined operation in 'x:num <- foo' 144 145 //:: finally, we need to fix the termination conditions for the run loop 146 diff --git a/html/038new_text.cc.html b/html/038new_text.cc.html index d28cf8c8..207543cc 100644 --- a/html/038new_text.cc.html +++ b/html/038new_text.cc.html @@ -134,7 +134,7 @@ if ('onhashchange' in window) { 69 def main [ 70 [abc] 71 ] - 72 +error: main: instruction '[abc]' has no recipe in '[abc] ' + 72 +error: main: instruction '[abc]' has no recipe in '[abc]' 73 74 //: stash recognizes strings 75 -- cgit 1.4.1-2-gfad0