From a97a00df51316a9246a13f6efb17a8a8f97bbd51 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 6 May 2017 22:48:37 -0700 Subject: 3848 Improve an error message. Still lots of room for improving how we render reagents in errors. --- html/010vm.cc.html | 295 ++++++++++++++++++++++++++--------------------------- 1 file changed, 146 insertions(+), 149 deletions(-) (limited to 'html/010vm.cc.html') diff --git a/html/010vm.cc.html b/html/010vm.cc.html index 6d967836..eed4d75a 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -770,155 +770,152 @@ if ('onhashchange' in window) { 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> +709 if (type == NULL) return "()"; +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 if (type == NULL) return "()"; // should never happen +745 ostringstream out; +746 dump_names(type, out); +747 return out.str(); +748 } +749 +750 void dump_names(const type_tree* x, ostream& out) { +751 if (!x) return; +752 if (x->atom) { +753 ¦ out << '"' << x->name << '"'; +754 ¦ return; +755 } +756 out << '('; +757 const type_tree* curr = x; +758 while (curr && !curr->atom) { +759 ¦ dump_names(curr->left, out); +760 ¦ if (curr->right) out << ' '; +761 ¦ curr = curr->right; +762 } +763 // check for dotted list; should never happen +764 if (curr) { +765 ¦ out << ". "; +766 ¦ dump_names(curr, out); +767 } +768 out << ')'; +769 } +770 +771 string names_to_string_without_quotes(const type_tree* type) { +772 if (type == NULL) return "()"; +773 ostringstream out; +774 dump_names_without_quotes(type, out); +775 return out.str(); +776 } +777 +778 void dump_names_without_quotes(const type_tree* x, ostream& out) { +779 if (!x) return; +780 if (x->atom) { +781 ¦ out << x->name; +782 ¦ return; +783 } +784 out << '('; +785 const type_tree* curr = x; +786 while (curr && !curr->atom) { +787 ¦ dump_names_without_quotes(curr->left, out); +788 ¦ if (curr->right) out << ' '; +789 ¦ curr = curr->right; +790 } +791 // check for dotted list; should never happen +792 if (curr) { +793 ¦ out << ". "; +794 ¦ dump_names_without_quotes(curr, out); +795 } +796 out << ')'; +797 } +798 +799 //: helper to print numbers without excessive precision +800 +801 :(before "End Types") +802 struct no_scientific { +803 double x; +804 explicit no_scientific(double y) :x(y) {} +805 }; +806 +807 :(code) +808 ostream& operator<<(ostream& os, no_scientific x) { +809 if (!isfinite(x.x)) { +810 ¦ // Infinity or NaN +811 ¦ os << x.x; +812 ¦ return os; +813 } +814 ostringstream tmp; +815 // more accurate, but too slow +816 //? tmp.precision(308); // for 64-bit numbers +817 tmp << std::fixed << x.x; +818 os << trim_floating_point(tmp.str()); +819 return os; +820 } +821 +822 string trim_floating_point(const string& in) { +823 if (in.empty()) return ""; +824 if (in.find('.') == string::npos) return in; +825 int length = SIZE(in); +826 while (length > 1) { +827 ¦ if (in.at(length-1) != '0') break; +828 ¦ --length; +829 } +830 if (in.at(length-1) == '.') --length; +831 if (length == 0) return "0"; +832 return in.substr(0, length); +833 } +834 +835 void test_trim_floating_point() { +836 CHECK_EQ(trim_floating_point(""), ""); +837 CHECK_EQ(trim_floating_point(".0"), "0"); +838 CHECK_EQ(trim_floating_point("1.5000"), "1.5"); +839 CHECK_EQ(trim_floating_point("1.000001"), "1.000001"); +840 CHECK_EQ(trim_floating_point("23.000000"), "23"); +841 CHECK_EQ(trim_floating_point("23.0"), "23"); +842 CHECK_EQ(trim_floating_point("23."), "23"); +843 CHECK_EQ(trim_floating_point("23"), "23"); +844 CHECK_EQ(trim_floating_point("230"), "230"); +845 CHECK_EQ(trim_floating_point("3.000000"), "3"); +846 CHECK_EQ(trim_floating_point("3.0"), "3"); +847 CHECK_EQ(trim_floating_point("3."), "3"); +848 CHECK_EQ(trim_floating_point("3"), "3"); +849 } +850 +851 :(before "End Includes") +852 #include <utility> +853 using std::pair; +854 #include <math.h> -- cgit 1.4.1-2-gfad0