diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-12-21 22:20:53 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-12-22 00:45:48 -0800 |
commit | fa708f553a3c314aa1eda75cee3c4e5e3b4f40db (patch) | |
tree | 2ad692ae2c9ebe177bbf9ad4073eaffc58dce4d5 | |
parent | fe8bf967a945c7d9e6aba36e42518262d54bd348 (diff) | |
download | mu-fa708f553a3c314aa1eda75cee3c4e5e3b4f40db.tar.gz |
4162
-rw-r--r-- | 002test.cc | 25 | ||||
-rw-r--r-- | 010vm.cc | 25 | ||||
-rw-r--r-- | html/002test.cc.html | 197 | ||||
-rw-r--r-- | html/010vm.cc.html | 141 | ||||
-rw-r--r-- | html/012transform.cc.html | 2 | ||||
-rw-r--r-- | html/028call_return.cc.html | 2 | ||||
-rw-r--r-- | html/030container.cc.html | 8 | ||||
-rw-r--r-- | html/032array.cc.html | 14 | ||||
-rw-r--r-- | html/041jump_target.cc.html | 2 | ||||
-rw-r--r-- | html/042name.cc.html | 6 | ||||
-rw-r--r-- | html/043space.cc.html | 4 | ||||
-rw-r--r-- | html/044space_surround.cc.html | 2 | ||||
-rw-r--r-- | html/045closure_name.cc.html | 2 | ||||
-rw-r--r-- | html/046check_type_by_name.cc.html | 2 | ||||
-rw-r--r-- | html/050scenario.cc.html | 4 | ||||
-rw-r--r-- | html/074wait.cc.html | 4 | ||||
-rw-r--r-- | html/085scenario_console.cc.html | 8 | ||||
-rw-r--r-- | html/subx/002test.cc.html | 197 | ||||
-rw-r--r-- | subx/002test.cc | 25 |
19 files changed, 310 insertions, 360 deletions
diff --git a/002test.cc b/002test.cc index f6623c90..33560a9d 100644 --- a/002test.cc +++ b/002test.cc @@ -82,30 +82,5 @@ void run_test(size_t i) { // End Test Teardown } -bool is_integer(const string& s) { - return s.find_first_not_of("0123456789-") == string::npos // no other characters - && s.find_first_of("0123456789") != string::npos // at least one digit - && s.find('-', 1) == string::npos; // '-' only at first position -} - -int to_integer(string n) { - char* end = NULL; - // safe because string.c_str() is guaranteed to be null-terminated - int result = strtoll(n.c_str(), &end, /*any base*/0); - if (*end != '\0') cerr << "tried to convert " << n << " to number\n"; - assert(*end == '\0'); - return result; -} - -void test_is_integer() { - CHECK(is_integer("1234")); - CHECK(is_integer("-1")); - CHECK(!is_integer("234.0")); - CHECK(is_integer("-567")); - CHECK(!is_integer("89-0")); - CHECK(!is_integer("-")); - CHECK(!is_integer("1e3")); // not supported -} - :(before "End Includes") #include <stdlib.h> diff --git a/010vm.cc b/010vm.cc index 09348f2d..f5138329 100644 --- a/010vm.cc +++ b/010vm.cc @@ -806,6 +806,31 @@ void dump_names_without_quotes(const type_tree* x, ostream& out) { out << ')'; } +bool is_integer(const string& s) { + return s.find_first_not_of("0123456789-") == string::npos // no other characters + && s.find_first_of("0123456789") != string::npos // at least one digit + && s.find('-', 1) == string::npos; // '-' only at first position +} + +int to_integer(string n) { + char* end = NULL; + // safe because string.c_str() is guaranteed to be null-terminated + int result = strtoll(n.c_str(), &end, /*any base*/0); + if (*end != '\0') cerr << "tried to convert " << n << " to number\n"; + assert(*end == '\0'); + return result; +} + +void test_is_integer() { + CHECK(is_integer("1234")); + CHECK(is_integer("-1")); + CHECK(!is_integer("234.0")); + CHECK(is_integer("-567")); + CHECK(!is_integer("89-0")); + CHECK(!is_integer("-")); + CHECK(!is_integer("1e3")); // not supported +} + //: helper to print numbers without excessive precision :(before "End Types") diff --git a/html/002test.cc.html b/html/002test.cc.html index 29ae89bc..6677685d 100644 --- a/html/002test.cc.html +++ b/html/002test.cc.html @@ -60,117 +60,92 @@ if ('onhashchange' in window) { </head> <body onload='JumpToLine();'> <pre id='vimCodeElement'> -<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: A simple test harness. To create new tests, define functions starting with</span> -<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: 'test_'. To run all tests so defined, run:</span> -<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: $ ./mu test</span> -<span id="L4" class="LineNr"> 4 </span><span class="Comment">//:</span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: Every layer should include tests, and can reach into previous layers.</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: However, it seems like a good idea never to reach into tests from previous</span> -<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: layers. Every test should be a contract that always passes as originally</span> -<span id="L8" class="LineNr"> 8 </span><span class="Comment">//: written, regardless of any later layers. Avoid writing 'temporary' tests</span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: that are only meant to work until some layer.</span> -<span id="L10" class="LineNr"> 10 </span> -<span id="L11" class="LineNr"> 11 </span><span class="Delimiter">:(before "End Types")</span> -<span id="L12" class="LineNr"> 12 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*test_fn<span class="Delimiter">)(</span><span class="Normal">void</span><span class="Delimiter">);</span> -<span id="L13" class="LineNr"> 13 </span><span class="Delimiter">:(before "Globals")</span> -<span id="L14" class="LineNr"> 14 </span><span class="Comment">// move a global ahead into types that we can't generate an extern declaration for</span> -<span id="L15" class="LineNr"> 15 </span><span class="Normal">const</span> <a href='002test.cc.html#L12'>test_fn</a> Tests[] = <span class="Delimiter">{</span> -<span id="L16" class="LineNr"> 16 </span> <span class="PreProc">#include </span><span class="Constant">"test_list"</span> <span class="Comment">// auto-generated; see 'build' script</span> -<span id="L17" class="LineNr"> 17 </span><span class="Delimiter">};</span> -<span id="L18" class="LineNr"> 18 </span> -<span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L20" class="LineNr"> 20 </span><span class="Normal">bool</span> Run_tests = <span class="Constant">false</span><span class="Delimiter">;</span> -<span id="L21" class="LineNr"> 21 </span><span class="Normal">bool</span> Passed = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> -<span id="L22" class="LineNr"> 22 </span> -<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(before "End Includes")</span> -<span id="L24" class="LineNr"> 24 </span><span class="PreProc">#define CHECK(X) \</span> -<span id="L25" class="LineNr"> 25 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (Passed && !(X)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> -<span id="L26" class="LineNr"> 26 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span id="L27" class="LineNr"> 27 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> Passed = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span id="L28" class="LineNr"> 28 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> -<span id="L29" class="LineNr"> 29 </span><span class="PreProc"> </span><span class="Delimiter">}</span> -<span id="L30" class="LineNr"> 30 </span> -<span id="L31" class="LineNr"> 31 </span><span class="PreProc">#define CHECK_EQ(X</span><span class="Delimiter">,</span><span class="PreProc"> Y) \</span> -<span id="L32" class="LineNr"> 32 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (Passed && (X) != (Y)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> -<span id="L33" class="LineNr"> 33 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="Constant">" == "</span><span class="PreProc"> << #Y << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span id="L34" class="LineNr"> 34 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">" got "</span><span class="PreProc"> << (X) << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> BEWARE: multiple eval </span><span class="Comment">*/</span><span class="PreProc"> \</span> -<span id="L35" class="LineNr"> 35 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> Passed = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span id="L36" class="LineNr"> 36 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> -<span id="L37" class="LineNr"> 37 </span><span class="PreProc"> </span><span class="Delimiter">}</span> -<span id="L38" class="LineNr"> 38 </span> -<span id="L39" class="LineNr"> 39 </span><span class="Delimiter">:(before "End Reset")</span> -<span id="L40" class="LineNr"> 40 </span>Passed = <span class="Constant">true</span><span class="Delimiter">;</span> -<span id="L41" class="LineNr"> 41 </span> -<span id="L42" class="LineNr"> 42 </span><span class="Delimiter">:(before "End Commandline Parsing")</span> -<span id="L43" class="LineNr"> 43 </span><span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && <a href='001help.cc.html#L73'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"test"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L44" class="LineNr"> 44 </span> Run_tests = <span class="Constant">true</span><span class="Delimiter">;</span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> <span class="Comment">// shift 'test' out of commandline args</span> -<span id="L45" class="LineNr"> 45 </span><span class="Delimiter">}</span> -<span id="L46" class="LineNr"> 46 </span> -<span id="L47" class="LineNr"> 47 </span><span class="Delimiter">:(before "End Main")</span> -<span id="L48" class="LineNr"> 48 </span><span class="Normal">if</span> <span class="Delimiter">(</span>Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L49" class="LineNr"> 49 </span> <span class="Comment">// Test Runs</span> -<span id="L50" class="LineNr"> 50 </span> <span class="Comment">// we run some tests and then exit; assume no state need be maintained afterward</span> -<span id="L51" class="LineNr"> 51 </span> -<span id="L52" class="LineNr"> 52 </span> <span class="Normal">long</span> num_failures = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Comment">// End Test Run Initialization</span> -<span id="L54" class="LineNr"> 54 </span> <span class="Normal">time_t</span> t<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> -<span id="L55" class="LineNr"> 55 </span> cerr << <span class="Constant">"C tests: "</span> << ctime<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> -<span id="L56" class="LineNr"> 56 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests<span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L57" class="LineNr"> 57 </span><span class="CommentedCode">//? cerr << "running .build/test_list line " << (i+1) << '\n';</span> -<span id="L58" class="LineNr"> 58 </span> <span class="Conceal">¦</span> <a href='002test.cc.html#L74'>run_test</a><span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> -<span id="L60" class="LineNr"> 60 </span> <span class="Conceal">¦</span> <span class="Normal">else</span> ++num_failures<span class="Delimiter">;</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Delimiter">}</span> -<span id="L62" class="LineNr"> 62 </span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L63" class="LineNr"> 63 </span> <span class="Comment">// End Tests</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>num_failures > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Conceal">¦</span> cerr << num_failures << <span class="Constant">" failure"</span> -<span id="L66" class="LineNr"> 66 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span><< <span class="Delimiter">(</span>num_failures > <span class="Constant">1</span> ? <span class="Constant">"s"</span> : <span class="Constant">""</span><span class="Delimiter">)</span> -<span id="L67" class="LineNr"> 67 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span><< <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> -<span id="L69" class="LineNr"> 69 </span> <span class="Delimiter">}</span> -<span id="L70" class="LineNr"> 70 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L71" class="LineNr"> 71 </span><span class="Delimiter">}</span> -<span id="L72" class="LineNr"> 72 </span> -<span id="L73" class="LineNr"> 73 </span><span class="Delimiter">:(code)</span> -<span id="L74" class="LineNr"> 74 </span><span class="Normal">void</span> <a href='002test.cc.html#L74'>run_test</a><span class="Delimiter">(</span><span class="Normal">size_t</span> i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L75" class="LineNr"> 75 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= <span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests<span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Conceal">¦</span> cerr << <span class="Constant">"no test "</span> << i << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L77" class="LineNr"> 77 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L78" class="LineNr"> 78 </span> <span class="Delimiter">}</span> -<span id="L79" class="LineNr"> 79 </span> <a href='000organization.cc.html#L134'>reset</a><span class="Delimiter">();</span> -<span id="L80" class="LineNr"> 80 </span> <span class="Comment">// End Test Setup</span> -<span id="L81" class="LineNr"> 81 </span> <span class="Delimiter">(</span>*Tests[i]<span class="Delimiter">)();</span> -<span id="L82" class="LineNr"> 82 </span> <span class="Comment">// End Test Teardown</span> -<span id="L83" class="LineNr"> 83 </span><span class="Delimiter">}</span> -<span id="L84" class="LineNr"> 84 </span> -<span id="L85" class="LineNr"> 85 </span><span class="Normal">bool</span> <a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L86" class="LineNr"> 86 </span> <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-"</span><span class="Delimiter">)</span> == string::npos <span class="Comment">// no other characters</span> -<span id="L87" class="LineNr"> 87 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && s<span class="Delimiter">.</span>find_first_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos <span class="Comment">// at least one digit</span> -<span id="L88" class="LineNr"> 88 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'-'</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">;</span> <span class="Comment">// '-' only at first position</span> -<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">}</span> -<span id="L90" class="LineNr"> 90 </span> -<span id="L91" class="LineNr"> 91 </span><span class="Normal">int</span> <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Normal">char</span>* <a href='003trace.cc.html#L203'>end</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> -<span id="L93" class="LineNr"> 93 </span> <span class="Comment">// safe because string.c_str() is guaranteed to be null-terminated</span> -<span id="L94" class="LineNr"> 94 </span> <span class="Normal">int</span> result = strtoll<span class="Delimiter">(</span>n<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">any base</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span> -<span id="L95" class="LineNr"> 95 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*end != <span class="cSpecial">'\0'</span><span class="Delimiter">)</span> cerr << <span class="Constant">"tried to convert "</span> << n << <span class="Constant">" to number</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L96" class="LineNr"> 96 </span> assert<span class="Delimiter">(</span>*end == <span class="cSpecial">'\0'</span><span class="Delimiter">);</span> -<span id="L97" class="LineNr"> 97 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span id="L98" class="LineNr"> 98 </span><span class="Delimiter">}</span> -<span id="L99" class="LineNr"> 99 </span> -<span id="L100" class="LineNr">100 </span><span class="Normal">void</span> <a href='002test.cc.html#L100'>test_is_integer</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L101" class="LineNr">101 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span><span class="Constant">"1234"</span><span class="Delimiter">));</span> -<span id="L102" class="LineNr">102 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span><span class="Constant">"-1"</span><span class="Delimiter">));</span> -<span id="L103" class="LineNr">103 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"234.0"</span><span class="Delimiter">));</span> -<span id="L104" class="LineNr">104 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span><span class="Constant">"-567"</span><span class="Delimiter">));</span> -<span id="L105" class="LineNr">105 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"89-0"</span><span class="Delimiter">));</span> -<span id="L106" class="LineNr">106 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"-"</span><span class="Delimiter">));</span> -<span id="L107" class="LineNr">107 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"1e3"</span><span class="Delimiter">));</span> <span class="Comment">// not supported</span> -<span id="L108" class="LineNr">108 </span><span class="Delimiter">}</span> -<span id="L109" class="LineNr">109 </span> -<span id="L110" class="LineNr">110 </span><span class="Delimiter">:(before "End Includes")</span> -<span id="L111" class="LineNr">111 </span><span class="PreProc">#include </span><span class="Constant"><stdlib.h></span> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: A simple test harness. To create new tests, define functions starting with</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: 'test_'. To run all tests so defined, run:</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: $ ./mu test</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//:</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: Every layer should include tests, and can reach into previous layers.</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: However, it seems like a good idea never to reach into tests from previous</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: layers. Every test should be a contract that always passes as originally</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">//: written, regardless of any later layers. Avoid writing 'temporary' tests</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: that are only meant to work until some layer.</span> +<span id="L10" class="LineNr">10 </span> +<span id="L11" class="LineNr">11 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L12" class="LineNr">12 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*test_fn<span class="Delimiter">)(</span><span class="Normal">void</span><span class="Delimiter">);</span> +<span id="L13" class="LineNr">13 </span><span class="Delimiter">:(before "Globals")</span> +<span id="L14" class="LineNr">14 </span><span class="Comment">// move a global ahead into types that we can't generate an extern declaration for</span> +<span id="L15" class="LineNr">15 </span><span class="Normal">const</span> <a href='002test.cc.html#L12'>test_fn</a> Tests[] = <span class="Delimiter">{</span> +<span id="L16" class="LineNr">16 </span> <span class="PreProc">#include </span><span class="Constant">"test_list"</span> <span class="Comment">// auto-generated; see 'build' script</span> +<span id="L17" class="LineNr">17 </span><span class="Delimiter">};</span> +<span id="L18" class="LineNr">18 </span> +<span id="L19" class="LineNr">19 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L20" class="LineNr">20 </span><span class="Normal">bool</span> Run_tests = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L21" class="LineNr">21 </span><span class="Normal">bool</span> Passed = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> +<span id="L22" class="LineNr">22 </span> +<span id="L23" class="LineNr">23 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L24" class="LineNr">24 </span><span class="PreProc">#define CHECK(X) \</span> +<span id="L25" class="LineNr">25 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (Passed && !(X)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> +<span id="L26" class="LineNr">26 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L27" class="LineNr">27 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> Passed = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L28" class="LineNr">28 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L29" class="LineNr">29 </span><span class="PreProc"> </span><span class="Delimiter">}</span> +<span id="L30" class="LineNr">30 </span> +<span id="L31" class="LineNr">31 </span><span class="PreProc">#define CHECK_EQ(X</span><span class="Delimiter">,</span><span class="PreProc"> Y) \</span> +<span id="L32" class="LineNr">32 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (Passed && (X) != (Y)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> +<span id="L33" class="LineNr">33 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="Constant">" == "</span><span class="PreProc"> << #Y << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L34" class="LineNr">34 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">" got "</span><span class="PreProc"> << (X) << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> BEWARE: multiple eval </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L35" class="LineNr">35 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> Passed = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L36" class="LineNr">36 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L37" class="LineNr">37 </span><span class="PreProc"> </span><span class="Delimiter">}</span> +<span id="L38" class="LineNr">38 </span> +<span id="L39" class="LineNr">39 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L40" class="LineNr">40 </span>Passed = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L41" class="LineNr">41 </span> +<span id="L42" class="LineNr">42 </span><span class="Delimiter">:(before "End Commandline Parsing")</span> +<span id="L43" class="LineNr">43 </span><span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && <a href='001help.cc.html#L73'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"test"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L44" class="LineNr">44 </span> Run_tests = <span class="Constant">true</span><span class="Delimiter">;</span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> <span class="Comment">// shift 'test' out of commandline args</span> +<span id="L45" class="LineNr">45 </span><span class="Delimiter">}</span> +<span id="L46" class="LineNr">46 </span> +<span id="L47" class="LineNr">47 </span><span class="Delimiter">:(before "End Main")</span> +<span id="L48" class="LineNr">48 </span><span class="Normal">if</span> <span class="Delimiter">(</span>Run_tests<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L49" class="LineNr">49 </span> <span class="Comment">// Test Runs</span> +<span id="L50" class="LineNr">50 </span> <span class="Comment">// we run some tests and then exit; assume no state need be maintained afterward</span> +<span id="L51" class="LineNr">51 </span> +<span id="L52" class="LineNr">52 </span> <span class="Normal">long</span> num_failures = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L53" class="LineNr">53 </span> <span class="Comment">// End Test Run Initialization</span> +<span id="L54" class="LineNr">54 </span> <span class="Normal">time_t</span> t<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> +<span id="L55" class="LineNr">55 </span> cerr << <span class="Constant">"C tests: "</span> << ctime<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> +<span id="L56" class="LineNr">56 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests<span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L57" class="LineNr">57 </span><span class="CommentedCode">//? cerr << "running .build/test_list line " << (i+1) << '\n';</span> +<span id="L58" class="LineNr">58 </span> <span class="Conceal">¦</span> <a href='002test.cc.html#L74'>run_test</a><span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L59" class="LineNr">59 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>Passed<span class="Delimiter">)</span> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> +<span id="L60" class="LineNr">60 </span> <span class="Conceal">¦</span> <span class="Normal">else</span> ++num_failures<span class="Delimiter">;</span> +<span id="L61" class="LineNr">61 </span> <span class="Delimiter">}</span> +<span id="L62" class="LineNr">62 </span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L63" class="LineNr">63 </span> <span class="Comment">// End Tests</span> +<span id="L64" class="LineNr">64 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>num_failures > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L65" class="LineNr">65 </span> <span class="Conceal">¦</span> cerr << num_failures << <span class="Constant">" failure"</span> +<span id="L66" class="LineNr">66 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span><< <span class="Delimiter">(</span>num_failures > <span class="Constant">1</span> ? <span class="Constant">"s"</span> : <span class="Constant">""</span><span class="Delimiter">)</span> +<span id="L67" class="LineNr">67 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span><< <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L68" class="LineNr">68 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L69" class="LineNr">69 </span> <span class="Delimiter">}</span> +<span id="L70" class="LineNr">70 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L71" class="LineNr">71 </span><span class="Delimiter">}</span> +<span id="L72" class="LineNr">72 </span> +<span id="L73" class="LineNr">73 </span><span class="Delimiter">:(code)</span> +<span id="L74" class="LineNr">74 </span><span class="Normal">void</span> <a href='002test.cc.html#L74'>run_test</a><span class="Delimiter">(</span><span class="Normal">size_t</span> i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L75" class="LineNr">75 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= <span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests<span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L76" class="LineNr">76 </span> <span class="Conceal">¦</span> cerr << <span class="Constant">"no test "</span> << i << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L77" class="LineNr">77 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L78" class="LineNr">78 </span> <span class="Delimiter">}</span> +<span id="L79" class="LineNr">79 </span> <a href='000organization.cc.html#L134'>reset</a><span class="Delimiter">();</span> +<span id="L80" class="LineNr">80 </span> <span class="Comment">// End Test Setup</span> +<span id="L81" class="LineNr">81 </span> <span class="Delimiter">(</span>*Tests[i]<span class="Delimiter">)();</span> +<span id="L82" class="LineNr">82 </span> <span class="Comment">// End Test Teardown</span> +<span id="L83" class="LineNr">83 </span><span class="Delimiter">}</span> +<span id="L84" class="LineNr">84 </span> +<span id="L85" class="LineNr">85 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L86" class="LineNr">86 </span><span class="PreProc">#include </span><span class="Constant"><stdlib.h></span> </pre> </body> </html> diff --git a/html/010vm.cc.html b/html/010vm.cc.html index 64c81ae2..3d6de025 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -351,7 +351,7 @@ if ('onhashchange' in window) { <span id="L287" class="LineNr">287 </span> type = <a href='018type_abbreviations.cc.html#L58'>new_type_tree</a><span class="Delimiter">(</span>type_names<span class="Delimiter">);</span> <span id="L288" class="LineNr">288 </span> <span class="Normal">delete</span> type_names<span class="Delimiter">;</span> <span id="L289" class="LineNr">289 </span> <span class="Comment">// special cases</span> -<span id="L290" class="LineNr">290 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>name<span class="Delimiter">)</span> && type == <span class="Constant">NULL</span><span class="Delimiter">)</span> +<span id="L290" class="LineNr">290 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>name<span class="Delimiter">)</span> && type == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span id="L291" class="LineNr">291 </span> <span class="Conceal">¦</span> type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Constant">"literal"</span><span class="Delimiter">);</span> <span id="L292" class="LineNr">292 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>name == <span class="Constant">"_"</span> && type == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span id="L293" class="LineNr">293 </span> <span class="Conceal">¦</span> type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Constant">"literal"</span><span class="Delimiter">);</span> @@ -408,7 +408,7 @@ if ('onhashchange' in window) { <span id="L344" class="LineNr">344 </span> <span class="Conceal">¦</span> <span class="Normal">int</span> value = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L345" class="LineNr">345 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">))</span> <span id="L346" class="LineNr">346 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> value = get<span class="Delimiter">(</span>Type_ordinal<span class="Delimiter">,</span> type_name<span class="Delimiter">);</span> -<span id="L347" class="LineNr">347 </span> <span class="Conceal">¦</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>type_name<span class="Delimiter">))</span> <span class="Comment">// sometimes types will contain non-type tags, like numbers for the size of an array</span> +<span id="L347" class="LineNr">347 </span> <span class="Conceal">¦</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>type_name<span class="Delimiter">))</span> <span class="Comment">// sometimes types will contain non-type tags, like numbers for the size of an array</span> <span id="L348" class="LineNr">348 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> value = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L349" class="LineNr">349 </span> <span class="Conceal">¦</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>properties<span class="Delimiter">-></span>value == <span class="Constant">"->"</span><span class="Delimiter">)</span> <span class="Comment">// used in recipe types</span> <span id="L350" class="LineNr">350 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> value = <span class="Constant">0</span><span class="Delimiter">;</span> @@ -870,62 +870,87 @@ if ('onhashchange' in window) { <span id="L806" class="LineNr">806 </span> out << <span class="Constant">')'</span><span class="Delimiter">;</span> <span id="L807" class="LineNr">807 </span><span class="Delimiter">}</span> <span id="L808" class="LineNr">808 </span> -<span id="L809" class="LineNr">809 </span><span class="Comment">//: helper to print numbers without excessive precision</span> -<span id="L810" class="LineNr">810 </span> -<span id="L811" class="LineNr">811 </span><span class="Delimiter">:(before "End Types")</span> -<span id="L812" class="LineNr">812 </span><span class="Normal">struct</span> no_scientific <span class="Delimiter">{</span> -<span id="L813" class="LineNr">813 </span> <span class="Normal">double</span> x<span class="Delimiter">;</span> -<span id="L814" class="LineNr">814 </span> <span class="Normal">explicit</span> no_scientific<span class="Delimiter">(</span><span class="Normal">double</span> y<span class="Delimiter">)</span> :x<span class="Delimiter">(</span>y<span class="Delimiter">)</span> <span class="Delimiter">{}</span> -<span id="L815" class="LineNr">815 </span><span class="Delimiter">};</span> -<span id="L816" class="LineNr">816 </span> -<span id="L817" class="LineNr">817 </span><span class="Delimiter">:(code)</span> -<span id="L818" class="LineNr">818 </span>ostream& <span class="Normal">operator</span><<<span class="Delimiter">(</span>ostream& os<span class="Delimiter">,</span> no_scientific x<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L819" class="LineNr">819 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!isfinite<span class="Delimiter">(</span>x<span class="Delimiter">.</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L820" class="LineNr">820 </span> <span class="Conceal">¦</span> <span class="Comment">// Infinity or NaN</span> -<span id="L821" class="LineNr">821 </span> <span class="Conceal">¦</span> os << x<span class="Delimiter">.</span>x<span class="Delimiter">;</span> -<span id="L822" class="LineNr">822 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> os<span class="Delimiter">;</span> -<span id="L823" class="LineNr">823 </span> <span class="Delimiter">}</span> -<span id="L824" class="LineNr">824 </span> ostringstream tmp<span class="Delimiter">;</span> -<span id="L825" class="LineNr">825 </span> <span class="Comment">// more accurate, but too slow</span> -<span id="L826" class="LineNr">826 </span><span class="CommentedCode">//? tmp.precision(308); // for 64-bit numbers</span> -<span id="L827" class="LineNr">827 </span> tmp << std::fixed << x<span class="Delimiter">.</span>x<span class="Delimiter">;</span> -<span id="L828" class="LineNr">828 </span> os << trim_floating_point<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>str<span class="Delimiter">());</span> -<span id="L829" class="LineNr">829 </span> <span class="Identifier">return</span> os<span class="Delimiter">;</span> -<span id="L830" class="LineNr">830 </span><span class="Delimiter">}</span> -<span id="L831" class="LineNr">831 </span> -<span id="L832" class="LineNr">832 </span>string trim_floating_point<span class="Delimiter">(</span><span class="Normal">const</span> string& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L833" class="LineNr">833 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> -<span id="L834" class="LineNr">834 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'.'</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">)</span> <span class="Identifier">return</span> in<span class="Delimiter">;</span> -<span id="L835" class="LineNr">835 </span> <span class="Normal">int</span> length = <a href='001help.cc.html#L141'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> -<span id="L836" class="LineNr">836 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>length > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L837" class="LineNr">837 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>length-<span class="Constant">1</span><span class="Delimiter">)</span> != <span class="Constant">'0'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L838" class="LineNr">838 </span> <span class="Conceal">¦</span> --length<span class="Delimiter">;</span> -<span id="L839" class="LineNr">839 </span> <span class="Delimiter">}</span> -<span id="L840" class="LineNr">840 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>length-<span class="Constant">1</span><span class="Delimiter">)</span> == <span class="Constant">'.'</span><span class="Delimiter">)</span> --length<span class="Delimiter">;</span> -<span id="L841" class="LineNr">841 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>length == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">"0"</span><span class="Delimiter">;</span> -<span id="L842" class="LineNr">842 </span> <span class="Identifier">return</span> in<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> length<span class="Delimiter">);</span> -<span id="L843" class="LineNr">843 </span><span class="Delimiter">}</span> -<span id="L844" class="LineNr">844 </span> -<span id="L845" class="LineNr">845 </span><span class="Normal">void</span> test_trim_floating_point<span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L846" class="LineNr">846 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">),</span> <span class="Constant">""</span><span class="Delimiter">);</span> -<span id="L847" class="LineNr">847 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">".0"</span><span class="Delimiter">),</span> <span class="Constant">"0"</span><span class="Delimiter">);</span> -<span id="L848" class="LineNr">848 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"1.5000"</span><span class="Delimiter">),</span> <span class="Constant">"1.5"</span><span class="Delimiter">);</span> -<span id="L849" class="LineNr">849 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"1.000001"</span><span class="Delimiter">),</span> <span class="Constant">"1.000001"</span><span class="Delimiter">);</span> -<span id="L850" class="LineNr">850 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"23.000000"</span><span class="Delimiter">),</span> <span class="Constant">"23"</span><span class="Delimiter">);</span> -<span id="L851" class="LineNr">851 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"23.0"</span><span class="Delimiter">),</span> <span class="Constant">"23"</span><span class="Delimiter">);</span> -<span id="L852" class="LineNr">852 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"23."</span><span class="Delimiter">),</span> <span class="Constant">"23"</span><span class="Delimiter">);</span> -<span id="L853" class="LineNr">853 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"23"</span><span class="Delimiter">),</span> <span class="Constant">"23"</span><span class="Delimiter">);</span> -<span id="L854" class="LineNr">854 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"230"</span><span class="Delimiter">),</span> <span class="Constant">"230"</span><span class="Delimiter">);</span> -<span id="L855" class="LineNr">855 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"3.000000"</span><span class="Delimiter">),</span> <span class="Constant">"3"</span><span class="Delimiter">);</span> -<span id="L856" class="LineNr">856 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"3.0"</span><span class="Delimiter">),</span> <span class="Constant">"3"</span><span class="Delimiter">);</span> -<span id="L857" class="LineNr">857 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"3."</span><span class="Delimiter">),</span> <span class="Constant">"3"</span><span class="Delimiter">);</span> -<span id="L858" class="LineNr">858 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"3"</span><span class="Delimiter">),</span> <span class="Constant">"3"</span><span class="Delimiter">);</span> -<span id="L859" class="LineNr">859 </span><span class="Delimiter">}</span> -<span id="L860" class="LineNr">860 </span> -<span id="L861" class="LineNr">861 </span><span class="Delimiter">:(before "End Includes")</span> -<span id="L862" class="LineNr">862 </span><span class="PreProc">#include </span><span class="Constant"><utility></span> -<span id="L863" class="LineNr">863 </span><span class="Normal">using</span> std::pair<span class="Delimiter">;</span> -<span id="L864" class="LineNr">864 </span><span class="PreProc">#include </span><span class="Constant"><math.h></span> +<span id="L809" class="LineNr">809 </span><span class="Normal">bool</span> is_integer<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L810" class="LineNr">810 </span> <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-"</span><span class="Delimiter">)</span> == string::npos <span class="Comment">// no other characters</span> +<span id="L811" class="LineNr">811 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && s<span class="Delimiter">.</span>find_first_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos <span class="Comment">// at least one digit</span> +<span id="L812" class="LineNr">812 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'-'</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">;</span> <span class="Comment">// '-' only at first position</span> +<span id="L813" class="LineNr">813 </span><span class="Delimiter">}</span> +<span id="L814" class="LineNr">814 </span> +<span id="L815" class="LineNr">815 </span><span class="Normal">int</span> to_integer<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L816" class="LineNr">816 </span> <span class="Normal">char</span>* <a href='003trace.cc.html#L203'>end</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L817" class="LineNr">817 </span> <span class="Comment">// safe because string.c_str() is guaranteed to be null-terminated</span> +<span id="L818" class="LineNr">818 </span> <span class="Normal">int</span> result = strtoll<span class="Delimiter">(</span>n<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">any base</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L819" class="LineNr">819 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*end != <span class="cSpecial">'\0'</span><span class="Delimiter">)</span> cerr << <span class="Constant">"tried to convert "</span> << n << <span class="Constant">" to number</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L820" class="LineNr">820 </span> assert<span class="Delimiter">(</span>*end == <span class="cSpecial">'\0'</span><span class="Delimiter">);</span> +<span id="L821" class="LineNr">821 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L822" class="LineNr">822 </span><span class="Delimiter">}</span> +<span id="L823" class="LineNr">823 </span> +<span id="L824" class="LineNr">824 </span><span class="Normal">void</span> test_is_integer<span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L825" class="LineNr">825 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span><span class="Constant">"1234"</span><span class="Delimiter">));</span> +<span id="L826" class="LineNr">826 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span><span class="Constant">"-1"</span><span class="Delimiter">));</span> +<span id="L827" class="LineNr">827 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"234.0"</span><span class="Delimiter">));</span> +<span id="L828" class="LineNr">828 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span><span class="Constant">"-567"</span><span class="Delimiter">));</span> +<span id="L829" class="LineNr">829 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"89-0"</span><span class="Delimiter">));</span> +<span id="L830" class="LineNr">830 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"-"</span><span class="Delimiter">));</span> +<span id="L831" class="LineNr">831 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"1e3"</span><span class="Delimiter">));</span> <span class="Comment">// not supported</span> +<span id="L832" class="LineNr">832 </span><span class="Delimiter">}</span> +<span id="L833" class="LineNr">833 </span> +<span id="L834" class="LineNr">834 </span><span class="Comment">//: helper to print numbers without excessive precision</span> +<span id="L835" class="LineNr">835 </span> +<span id="L836" class="LineNr">836 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L837" class="LineNr">837 </span><span class="Normal">struct</span> no_scientific <span class="Delimiter">{</span> +<span id="L838" class="LineNr">838 </span> <span class="Normal">double</span> x<span class="Delimiter">;</span> +<span id="L839" class="LineNr">839 </span> <span class="Normal">explicit</span> no_scientific<span class="Delimiter">(</span><span class="Normal">double</span> y<span class="Delimiter">)</span> :x<span class="Delimiter">(</span>y<span class="Delimiter">)</span> <span class="Delimiter">{}</span> +<span id="L840" class="LineNr">840 </span><span class="Delimiter">};</span> +<span id="L841" class="LineNr">841 </span> +<span id="L842" class="LineNr">842 </span><span class="Delimiter">:(code)</span> +<span id="L843" class="LineNr">843 </span>ostream& <span class="Normal">operator</span><<<span class="Delimiter">(</span>ostream& os<span class="Delimiter">,</span> no_scientific x<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L844" class="LineNr">844 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!isfinite<span class="Delimiter">(</span>x<span class="Delimiter">.</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L845" class="LineNr">845 </span> <span class="Conceal">¦</span> <span class="Comment">// Infinity or NaN</span> +<span id="L846" class="LineNr">846 </span> <span class="Conceal">¦</span> os << x<span class="Delimiter">.</span>x<span class="Delimiter">;</span> +<span id="L847" class="LineNr">847 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> os<span class="Delimiter">;</span> +<span id="L848" class="LineNr">848 </span> <span class="Delimiter">}</span> +<span id="L849" class="LineNr">849 </span> ostringstream tmp<span class="Delimiter">;</span> +<span id="L850" class="LineNr">850 </span> <span class="Comment">// more accurate, but too slow</span> +<span id="L851" class="LineNr">851 </span><span class="CommentedCode">//? tmp.precision(308); // for 64-bit numbers</span> +<span id="L852" class="LineNr">852 </span> tmp << std::fixed << x<span class="Delimiter">.</span>x<span class="Delimiter">;</span> +<span id="L853" class="LineNr">853 </span> os << trim_floating_point<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>str<span class="Delimiter">());</span> +<span id="L854" class="LineNr">854 </span> <span class="Identifier">return</span> os<span class="Delimiter">;</span> +<span id="L855" class="LineNr">855 </span><span class="Delimiter">}</span> +<span id="L856" class="LineNr">856 </span> +<span id="L857" class="LineNr">857 </span>string trim_floating_point<span class="Delimiter">(</span><span class="Normal">const</span> string& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L858" class="LineNr">858 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L859" class="LineNr">859 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'.'</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">)</span> <span class="Identifier">return</span> in<span class="Delimiter">;</span> +<span id="L860" class="LineNr">860 </span> <span class="Normal">int</span> length = <a href='001help.cc.html#L141'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> +<span id="L861" class="LineNr">861 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>length > <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L862" class="LineNr">862 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>length-<span class="Constant">1</span><span class="Delimiter">)</span> != <span class="Constant">'0'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L863" class="LineNr">863 </span> <span class="Conceal">¦</span> --length<span class="Delimiter">;</span> +<span id="L864" class="LineNr">864 </span> <span class="Delimiter">}</span> +<span id="L865" class="LineNr">865 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>in<span class="Delimiter">.</span>at<span class="Delimiter">(</span>length-<span class="Constant">1</span><span class="Delimiter">)</span> == <span class="Constant">'.'</span><span class="Delimiter">)</span> --length<span class="Delimiter">;</span> +<span id="L866" class="LineNr">866 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>length == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">"0"</span><span class="Delimiter">;</span> +<span id="L867" class="LineNr">867 </span> <span class="Identifier">return</span> in<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> length<span class="Delimiter">);</span> +<span id="L868" class="LineNr">868 </span><span class="Delimiter">}</span> +<span id="L869" class="LineNr">869 </span> +<span id="L870" class="LineNr">870 </span><span class="Normal">void</span> test_trim_floating_point<span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L871" class="LineNr">871 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">),</span> <span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L872" class="LineNr">872 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">".0"</span><span class="Delimiter">),</span> <span class="Constant">"0"</span><span class="Delimiter">);</span> +<span id="L873" class="LineNr">873 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"1.5000"</span><span class="Delimiter">),</span> <span class="Constant">"1.5"</span><span class="Delimiter">);</span> +<span id="L874" class="LineNr">874 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"1.000001"</span><span class="Delimiter">),</span> <span class="Constant">"1.000001"</span><span class="Delimiter">);</span> +<span id="L875" class="LineNr">875 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"23.000000"</span><span class="Delimiter">),</span> <span class="Constant">"23"</span><span class="Delimiter">);</span> +<span id="L876" class="LineNr">876 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"23.0"</span><span class="Delimiter">),</span> <span class="Constant">"23"</span><span class="Delimiter">);</span> +<span id="L877" class="LineNr">877 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"23."</span><span class="Delimiter">),</span> <span class="Constant">"23"</span><span class="Delimiter">);</span> +<span id="L878" class="LineNr">878 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"23"</span><span class="Delimiter">),</span> <span class="Constant">"23"</span><span class="Delimiter">);</span> +<span id="L879" class="LineNr">879 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"230"</span><span class="Delimiter">),</span> <span class="Constant">"230"</span><span class="Delimiter">);</span> +<span id="L880" class="LineNr">880 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"3.000000"</span><span class="Delimiter">),</span> <span class="Constant">"3"</span><span class="Delimiter">);</span> +<span id="L881" class="LineNr">881 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"3.0"</span><span class="Delimiter">),</span> <span class="Constant">"3"</span><span class="Delimiter">);</span> +<span id="L882" class="LineNr">882 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"3."</span><span class="Delimiter">),</span> <span class="Constant">"3"</span><span class="Delimiter">);</span> +<span id="L883" class="LineNr">883 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trim_floating_point<span class="Delimiter">(</span><span class="Constant">"3"</span><span class="Delimiter">),</span> <span class="Constant">"3"</span><span class="Delimiter">);</span> +<span id="L884" class="LineNr">884 </span><span class="Delimiter">}</span> +<span id="L885" class="LineNr">885 </span> +<span id="L886" class="LineNr">886 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L887" class="LineNr">887 </span><span class="PreProc">#include </span><span class="Constant"><utility></span> +<span id="L888" class="LineNr">888 </span><span class="Normal">using</span> std::pair<span class="Delimiter">;</span> +<span id="L889" class="LineNr">889 </span><span class="PreProc">#include </span><span class="Constant"><math.h></span> </pre> </body> </html> diff --git a/html/012transform.cc.html b/html/012transform.cc.html index f4e8fc5b..2d50f1b6 100644 --- a/html/012transform.cc.html +++ b/html/012transform.cc.html @@ -151,7 +151,7 @@ if ('onhashchange' in window) { <span id="L92" class="LineNr"> 92 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L93" class="LineNr"> 93 </span> <span class="Comment">// End Reagent-parsing Exceptions</span> <span id="L94" class="LineNr"> 94 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L95" class="LineNr"> 95 </span> r<span class="Delimiter">.</span><a href='010vm.cc.html#L65'>set_value</a><span class="Delimiter">(</span><a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">));</span> +<span id="L95" class="LineNr"> 95 </span> r<span class="Delimiter">.</span><a href='010vm.cc.html#L65'>set_value</a><span class="Delimiter">(</span>to_integer<span class="Delimiter">(</span>r<span class="Delimiter">.</span>name<span class="Delimiter">));</span> <span id="L96" class="LineNr"> 96 </span><span class="Delimiter">}</span> <span id="L97" class="LineNr"> 97 </span> <span id="L98" class="LineNr"> 98 </span><span class="Comment">// helper for tests -- temporarily suppress run</span> diff --git a/html/028call_return.cc.html b/html/028call_return.cc.html index 0b3a579c..e781e265 100644 --- a/html/028call_return.cc.html +++ b/html/028call_return.cc.html @@ -160,7 +160,7 @@ if ('onhashchange' in window) { <span id="L97" class="LineNr"> 97 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L174'>raise</a> << <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"'same-as-ingredient' metadata should take exactly one value in '"</span> << to_original_string<span class="Delimiter">(</span>return_inst<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> <span id="L98" class="LineNr"> 98 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Identifier">goto</span> finish_return_check<span class="Delimiter">;</span> <span id="L99" class="LineNr"> 99 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Delimiter">}</span> -<span id="L100" class="LineNr">100 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">int</span> ingredient_index = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>tmp<span class="Delimiter">-></span>value<span class="Delimiter">);</span> +<span id="L100" class="LineNr">100 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">int</span> ingredient_index = to_integer<span class="Delimiter">(</span>tmp<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span id="L101" class="LineNr">101 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>ingredient_index >= <a href='001help.cc.html#L141'>SIZE</a><span class="Delimiter">(</span>caller_instruction<span class="Delimiter">.</span>ingredients<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L102" class="LineNr">102 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L174'>raise</a> << <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"too few ingredients in '"</span> << to_original_string<span class="Delimiter">(</span>caller_instruction<span class="Delimiter">)</span> << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> <span id="L103" class="LineNr">103 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Identifier">goto</span> finish_return_check<span class="Delimiter">;</span> diff --git a/html/030container.cc.html b/html/030container.cc.html index 5a4d0c9f..a18761ba 100644 --- a/html/030container.cc.html +++ b/html/030container.cc.html @@ -448,8 +448,8 @@ if ('onhashchange' in window) { <span id="L381" class="LineNr">381 </span> <span class="Conceal">¦</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L382" class="LineNr">382 </span> <span class="Delimiter">}</span> <span id="L383" class="LineNr">383 </span> <span class="Normal">int</span> offset_value = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L384" class="LineNr">384 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L385" class="LineNr">385 </span> <span class="Conceal">¦</span> offset_value = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">);</span> +<span id="L384" class="LineNr">384 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L385" class="LineNr">385 </span> <span class="Conceal">¦</span> offset_value = to_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span id="L386" class="LineNr">386 </span> <span class="Delimiter">}</span> <span id="L387" class="LineNr">387 </span> <span class="Comment">// End update GET offset_value in Check</span> <span id="L388" class="LineNr">388 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>offset_value < <span class="Constant">0</span> || offset_value >= <a href='001help.cc.html#L141'>SIZE</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> @@ -598,8 +598,8 @@ if ('onhashchange' in window) { <span id="L531" class="LineNr">531 </span> <span class="Delimiter">}</span> <span id="L532" class="LineNr">532 </span> <span class="Normal">int</span> offset_value = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L533" class="LineNr">533 </span> <span class="Comment">//: later layers will permit non-integer offsets</span> -<span id="L534" class="LineNr">534 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L535" class="LineNr">535 </span> <span class="Conceal">¦</span> offset_value = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">);</span> +<span id="L534" class="LineNr">534 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L535" class="LineNr">535 </span> <span class="Conceal">¦</span> offset_value = to_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span id="L536" class="LineNr">536 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>offset_value < <span class="Constant">0</span> || offset_value >= <a href='001help.cc.html#L141'>SIZE</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L537" class="LineNr">537 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L174'>raise</a> << <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"invalid offset '"</span> << offset_value << <span class="Constant">"' for '"</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">-></span>value<span class="Delimiter">).</span>name << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> <span id="L538" class="LineNr">538 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Identifier">break</span><span class="Delimiter">;</span> diff --git a/html/032array.cc.html b/html/032array.cc.html index 469d3fd7..a1426054 100644 --- a/html/032array.cc.html +++ b/html/032array.cc.html @@ -120,7 +120,7 @@ if ('onhashchange' in window) { <span id="L55" class="LineNr"> 55 </span> type_tree* array_length_from_type = product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span id="L56" class="LineNr"> 56 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!product<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span id="L57" class="LineNr"> 57 </span> <span class="Conceal">¦</span> array_length_from_type = array_length_from_type<span class="Delimiter">-></span>left<span class="Delimiter">;</span> -<span id="L58" class="LineNr"> 58 </span> <span class="Normal">int</span> <a href='032array.cc.html#L397'>array_length</a> = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>array_length_from_type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Normal">int</span> <a href='032array.cc.html#L397'>array_length</a> = to_integer<span class="Delimiter">(</span>array_length_from_type<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span id="L59" class="LineNr"> 59 </span> <span class="Comment">// initialize array length, so that size_of will work</span> <span id="L60" class="LineNr"> 60 </span> <a href='003trace.cc.html#L167'>trace</a><span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing "</span> << <a href='032array.cc.html#L397'>array_length</a> << <span class="Constant">" in location "</span> << base_address << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> <span id="L61" class="LineNr"> 61 </span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> base_address<span class="Delimiter">,</span> <a href='032array.cc.html#L397'>array_length</a><span class="Delimiter">);</span> <span class="Comment">// in array elements</span> @@ -181,9 +181,9 @@ if ('onhashchange' in window) { <span id="L116" class="LineNr">116 </span><span class="Delimiter">:(code)</span> <span id="L117" class="LineNr">117 </span><span class="Normal">int</span> <a href='032array.cc.html#L117'>static_array_length</a><span class="Delimiter">(</span><span class="Normal">const</span> type_tree* type<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L118" class="LineNr">118 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!type<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>right && !type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right && !type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && !type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right <span class="Comment">// exactly 3 types</span> -<span id="L119" class="LineNr">119 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && <a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// third 'type' is a number</span> +<span id="L119" class="LineNr">119 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// third 'type' is a number</span> <span id="L120" class="LineNr">120 </span> <span class="Conceal">¦</span> <span class="Comment">// get size from type</span> -<span id="L121" class="LineNr">121 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">);</span> +<span id="L121" class="LineNr">121 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span id="L122" class="LineNr">122 </span> <span class="Delimiter">}</span> <span id="L123" class="LineNr">123 </span> cerr << <a href='028call_return.cc.html#L163'>to_string</a><span class="Delimiter">(</span>type<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L124" class="LineNr">124 </span> assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> @@ -205,7 +205,7 @@ if ('onhashchange' in window) { <span id="L140" class="LineNr">140 </span>$error: <span class="Constant">0</span> <span id="L141" class="LineNr">141 </span> <span id="L142" class="LineNr">142 </span><span class="Delimiter">:(before "End <a href='030container.cc.html#L661'>insert_container</a> Special-cases")</span> -<span id="L143" class="LineNr">143 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// sometimes types will contain non-type tags, like numbers for the size of an array</span> +<span id="L143" class="LineNr">143 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// sometimes types will contain non-type tags, like numbers for the size of an array</span> <span id="L144" class="LineNr">144 </span> type<span class="Delimiter">-></span>value = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L145" class="LineNr">145 </span><span class="Delimiter">}</span> <span id="L146" class="LineNr">146 </span> @@ -452,7 +452,7 @@ if ('onhashchange' in window) { <span id="L387" class="LineNr">387 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">;</span> <span id="L388" class="LineNr">388 </span> <span class="Delimiter">}</span> <span id="L389" class="LineNr">389 </span> <span class="Comment">// hack: support array:num:3 without requiring extra parens</span> -<span id="L390" class="LineNr">390 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && <a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L390" class="LineNr">390 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L391" class="LineNr">391 </span> <span class="Conceal">¦</span> assert<span class="Delimiter">(</span>!type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">);</span> <span id="L392" class="LineNr">392 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">;</span> <span id="L393" class="LineNr">393 </span> <span class="Delimiter">}</span> @@ -463,9 +463,9 @@ if ('onhashchange' in window) { <span id="L398" class="LineNr">398 </span> <span class="Comment">// x should already be canonized.</span> <span id="L399" class="LineNr">399 </span> <span class="Comment">// hack: look for length in type</span> <span id="L400" class="LineNr">400 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom && !x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right <span class="Comment">// exactly 3 types</span> -<span id="L401" class="LineNr">401 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && <a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// third 'type' is a number</span> +<span id="L401" class="LineNr">401 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left && x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// third 'type' is a number</span> <span id="L402" class="LineNr">402 </span> <span class="Conceal">¦</span> <span class="Comment">// get size from type</span> -<span id="L403" class="LineNr">403 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">);</span> +<span id="L403" class="LineNr">403 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">-></span>right<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name<span class="Delimiter">);</span> <span id="L404" class="LineNr">404 </span> <span class="Delimiter">}</span> <span id="L405" class="LineNr">405 </span> <span class="Comment">// this should never happen at transform time</span> <span id="L406" class="LineNr">406 </span> <span class="Identifier">return</span> <a href='001help.cc.html#L229'>get_or_insert</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> x<span class="Delimiter">.</span>value<span class="Delimiter">);</span> diff --git a/html/041jump_target.cc.html b/html/041jump_target.cc.html index 08231a30..8119c8da 100644 --- a/html/041jump_target.cc.html +++ b/html/041jump_target.cc.html @@ -144,7 +144,7 @@ if ('onhashchange' in window) { <span id="L80" class="LineNr"> 80 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L81" class="LineNr"> 81 </span> <span class="Delimiter">}</span> <span id="L82" class="LineNr"> 82 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>initialized<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L83" class="LineNr"> 83 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// non-labels will be handled like other number operands</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// non-labels will be handled like other number operands</span> <span id="L84" class="LineNr"> 84 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_jump_target<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L85" class="LineNr"> 85 </span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L174'>raise</a> << <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"can't jump to label '"</span> << x<span class="Delimiter">.</span>name << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span id="L86" class="LineNr"> 86 </span> <span class="Conceal">¦</span> x<span class="Delimiter">.</span><a href='010vm.cc.html#L65'>set_value</a><span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Comment">// no jump by default</span> diff --git a/html/042name.cc.html b/html/042name.cc.html index 9b82dae4..2ffe6cc1 100644 --- a/html/042name.cc.html +++ b/html/042name.cc.html @@ -117,7 +117,7 @@ if ('onhashchange' in window) { <span id="L52" class="LineNr"> 52 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='042name.cc.html#L97'>is_disqualified</a><span class="Delimiter">(</span>ingredient<span class="Delimiter">,</span> inst<span class="Delimiter">,</span> caller<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L53" class="LineNr"> 53 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='042name.cc.html#L146'>is_numeric_location</a><span class="Delimiter">(</span>ingredient<span class="Delimiter">))</span> numeric_locations_used = <span class="Constant">true</span><span class="Delimiter">;</span> <span id="L54" class="LineNr"> 54 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='042name.cc.html#L153'>is_named_location</a><span class="Delimiter">(</span>ingredient<span class="Delimiter">))</span> names_used = <span class="Constant">true</span><span class="Delimiter">;</span> -<span id="L55" class="LineNr"> 55 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>ingredient<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>ingredient<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L56" class="LineNr"> 56 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!already_transformed<span class="Delimiter">(</span>ingredient<span class="Delimiter">,</span> names<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L57" class="LineNr"> 57 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L174'>raise</a> << <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name<span class="Delimiter">)</span> << <span class="Constant">"tried to read ingredient '"</span> << ingredient<span class="Delimiter">.</span>name << <span class="Constant">"' in '"</span> << to_original_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"' but it hasn't been written to yet</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> <span id="L58" class="LineNr"> 58 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Comment">// use-before-set Error</span> @@ -138,7 +138,7 @@ if ('onhashchange' in window) { <span id="L73" class="LineNr"> 73 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='042name.cc.html#L97'>is_disqualified</a><span class="Delimiter">(</span>product<span class="Delimiter">,</span> inst<span class="Delimiter">,</span> caller<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L74" class="LineNr"> 74 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='042name.cc.html#L146'>is_numeric_location</a><span class="Delimiter">(</span>product<span class="Delimiter">))</span> numeric_locations_used = <span class="Constant">true</span><span class="Delimiter">;</span> <span id="L75" class="LineNr"> 75 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='042name.cc.html#L153'>is_named_location</a><span class="Delimiter">(</span>product<span class="Delimiter">))</span> names_used = <span class="Constant">true</span><span class="Delimiter">;</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>product<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>product<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L77" class="LineNr"> 77 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>names<span class="Delimiter">.</span>find<span class="Delimiter">(</span>product<span class="Delimiter">.</span>name<span class="Delimiter">)</span> == names<span class="Delimiter">.</span><a href='003trace.cc.html#L203'>end</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> <span id="L78" class="LineNr"> 78 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L167'>trace</a><span class="Delimiter">(</span><span class="Constant">9993</span><span class="Delimiter">,</span> <span class="Constant">"name"</span><span class="Delimiter">)</span> << <span class="Constant">"assign "</span> << product<span class="Delimiter">.</span>name << <span class="Constant">" "</span> << curr_idx << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> <span id="L79" class="LineNr"> 79 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> names[product<span class="Delimiter">.</span>name] = curr_idx<span class="Delimiter">;</span> @@ -212,7 +212,7 @@ if ('onhashchange' in window) { <span id="L147" class="LineNr">147 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span id="L148" class="LineNr">148 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='022arithmetic.cc.html#L108'>is_raw</a><span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span id="L149" class="LineNr">149 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>name == <span class="Constant">"0"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span> <span class="Comment">// used for chaining lexical scopes</span> -<span id="L150" class="LineNr">150 </span> <span class="Identifier">return</span> <a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">);</span> +<span id="L150" class="LineNr">150 </span> <span class="Identifier">return</span> is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span id="L151" class="LineNr">151 </span><span class="Delimiter">}</span> <span id="L152" class="LineNr">152 </span> <span id="L153" class="LineNr">153 </span><span class="Normal">bool</span> <a href='042name.cc.html#L153'>is_named_location</a><span class="Delimiter">(</span><span class="Normal">const</span> reagent& x<span class="Delimiter">)</span> <span class="Delimiter">{</span> diff --git a/html/043space.cc.html b/html/043space.cc.html index d1c3f7bb..8ffc0236 100644 --- a/html/043space.cc.html +++ b/html/043space.cc.html @@ -539,8 +539,8 @@ if ('onhashchange' in window) { <span id="L473" class="LineNr">473 </span> <span id="L474" class="LineNr">474 </span><span class="Normal">bool</span> <span class="Normal">operator</span><<span class="Delimiter">(</span><span class="Normal">const</span> reagent& a<span class="Delimiter">,</span> <span class="Normal">const</span> reagent& b<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L475" class="LineNr">475 </span> <span class="Normal">int</span> aspace = <span class="Constant">0</span><span class="Delimiter">,</span> bspace = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L476" class="LineNr">476 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>a<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">))</span> aspace = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>property<span class="Delimiter">(</span>a<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">)-></span>value<span class="Delimiter">);</span> -<span id="L477" class="LineNr">477 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>b<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">))</span> bspace = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>property<span class="Delimiter">(</span>b<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">)-></span>value<span class="Delimiter">);</span> +<span id="L476" class="LineNr">476 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>a<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">))</span> aspace = to_integer<span class="Delimiter">(</span>property<span class="Delimiter">(</span>a<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">)-></span>value<span class="Delimiter">);</span> +<span id="L477" class="LineNr">477 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>b<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">))</span> bspace = to_integer<span class="Delimiter">(</span>property<span class="Delimiter">(</span>b<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">)-></span>value<span class="Delimiter">);</span> <span id="L478" class="LineNr">478 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>aspace != bspace<span class="Delimiter">)</span> <span class="Identifier">return</span> aspace < bspace<span class="Delimiter">;</span> <span id="L479" class="LineNr">479 </span> <span class="Identifier">return</span> a<span class="Delimiter">.</span>name < b<span class="Delimiter">.</span>name<span class="Delimiter">;</span> <span id="L480" class="LineNr">480 </span><span class="Delimiter">}</span> diff --git a/html/044space_surround.cc.html b/html/044space_surround.cc.html index c2eaec77..95578028 100644 --- a/html/044space_surround.cc.html +++ b/html/044space_surround.cc.html @@ -117,7 +117,7 @@ if ('onhashchange' in window) { <span id="L54" class="LineNr">54 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">"space"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L55" class="LineNr">55 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second || x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span id="L56" class="LineNr">56 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L174'>raise</a> << <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span><a href='026call.cc.html#L87'>current_recipe_name</a><span class="Delimiter">())</span> << <span class="Constant">"/space metadata should take exactly one value in '"</span> << x<span class="Delimiter">.</span>original_string << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> -<span id="L57" class="LineNr">57 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Identifier">return</span> <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">-></span>value<span class="Delimiter">);</span> +<span id="L57" class="LineNr">57 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span id="L58" class="LineNr">58 </span> <span class="Conceal">¦</span> <span class="Delimiter">}</span> <span id="L59" class="LineNr">59 </span> <span class="Delimiter">}</span> <span id="L60" class="LineNr">60 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> diff --git a/html/045closure_name.cc.html b/html/045closure_name.cc.html index ab77a6b9..7a4ec80b 100644 --- a/html/045closure_name.cc.html +++ b/html/045closure_name.cc.html @@ -151,7 +151,7 @@ if ('onhashchange' in window) { <span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">}</span> <span id="L89" class="LineNr"> 89 </span> string_tree* p = property<span class="Delimiter">(</span>x<span class="Delimiter">,</span> <span class="Constant">"space"</span><span class="Delimiter">);</span> <span id="L90" class="LineNr"> 90 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!p || !p<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <a href='003trace.cc.html#L174'>raise</a> << <span class="Constant">"/space property should have exactly one (non-negative integer) value</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> -<span id="L91" class="LineNr"> 91 </span> <span class="Normal">int</span> n = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span>value<span class="Delimiter">);</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Normal">int</span> n = to_integer<span class="Delimiter">(</span>p<span class="Delimiter">-></span>value<span class="Delimiter">);</span> <span id="L92" class="LineNr"> 92 </span> assert<span class="Delimiter">(</span>n >= <span class="Constant">0</span><span class="Delimiter">);</span> <span id="L93" class="LineNr"> 93 </span> <a href='010vm.cc.html#L14'>recipe_ordinal</a> surrounding_recipe = <a href='045closure_name.cc.html#L119'>lookup_surrounding_recipe</a><span class="Delimiter">(</span>default_recipe<span class="Delimiter">,</span> n<span class="Delimiter">);</span> <span id="L94" class="LineNr"> 94 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>surrounding_recipe == -<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Identifier">return</span> -<span class="Constant">1</span><span class="Delimiter">;</span> diff --git a/html/046check_type_by_name.cc.html b/html/046check_type_by_name.cc.html index 1b8868ea..e0024aa2 100644 --- a/html/046check_type_by_name.cc.html +++ b/html/046check_type_by_name.cc.html @@ -122,7 +122,7 @@ if ('onhashchange' in window) { <span id="L58" class="LineNr"> 58 </span> <span id="L59" class="LineNr"> 59 </span><span class="Normal">void</span> <a href='046check_type_by_name.cc.html#L59'>check_type</a><span class="Delimiter">(</span>set<reagent>& known<span class="Delimiter">,</span> <span class="Normal">const</span> reagent& x<span class="Delimiter">,</span> <span class="Normal">const</span> recipe& caller<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L60" class="LineNr"> 60 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// if you use raw locations you're probably doing something unsafe</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// if you use raw locations you're probably doing something unsafe</span> <span id="L62" class="LineNr"> 62 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// might get filled in by other logic later</span> <span id="L63" class="LineNr"> 63 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='041jump_target.cc.html#L11'>is_jump_target</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L64" class="LineNr"> 64 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom || x<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name != <span class="Constant">"label"</span><span class="Delimiter">)</span> diff --git a/html/050scenario.cc.html b/html/050scenario.cc.html index a7a239ae..01c3e6e6 100644 --- a/html/050scenario.cc.html +++ b/html/050scenario.cc.html @@ -475,7 +475,7 @@ if ('onhashchange' in window) { <span id="L408" class="LineNr">408 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='046check_type_by_name.cc.html#L59'>check_type</a><span class="Delimiter">(</span>lhs<span class="Delimiter">,</span> in<span class="Delimiter">);</span> <span id="L409" class="LineNr">409 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L410" class="LineNr">410 </span> <span class="Conceal">¦</span> <span class="Delimiter">}</span> -<span id="L411" class="LineNr">411 </span> <span class="Conceal">¦</span> <span class="Normal">int</span> <a href='043space.cc.html#L82'>address</a> = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> +<span id="L411" class="LineNr">411 </span> <span class="Conceal">¦</span> <span class="Normal">int</span> <a href='043space.cc.html#L82'>address</a> = to_integer<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> <span id="L412" class="LineNr">412 </span> <span class="Conceal">¦</span> <a href='011load.cc.html#L209'>skip_whitespace_and_comments</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span id="L413" class="LineNr">413 </span> <span class="Conceal">¦</span> string _assign<span class="Delimiter">;</span> in >> _assign<span class="Delimiter">;</span> assert<span class="Delimiter">(</span>_assign == <span class="Constant">"<-"</span><span class="Delimiter">);</span> <span id="L414" class="LineNr">414 </span> <span class="Conceal">¦</span> <a href='011load.cc.html#L209'>skip_whitespace_and_comments</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> @@ -508,7 +508,7 @@ if ('onhashchange' in window) { <span id="L441" class="LineNr">441 </span><span class="Normal">void</span> <a href='046check_type_by_name.cc.html#L59'>check_type</a><span class="Delimiter">(</span><span class="Normal">const</span> string& lhs<span class="Delimiter">,</span> istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L442" class="LineNr">442 </span> reagent x<span class="Delimiter">(</span>lhs<span class="Delimiter">);</span> <span id="L443" class="LineNr">443 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)</span> && is_mu_character<span class="Delimiter">(</span><a href='032array.cc.html#L381'>array_element</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>type<span class="Delimiter">)))</span> <span class="Delimiter">{</span> -<span id="L444" class="LineNr">444 </span> <span class="Conceal">¦</span> x<span class="Delimiter">.</span><a href='010vm.cc.html#L65'>set_value</a><span class="Delimiter">(</span><a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">));</span> +<span id="L444" class="LineNr">444 </span> <span class="Conceal">¦</span> x<span class="Delimiter">.</span><a href='010vm.cc.html#L65'>set_value</a><span class="Delimiter">(</span>to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>name<span class="Delimiter">));</span> <span id="L445" class="LineNr">445 </span> <span class="Conceal">¦</span> <a href='011load.cc.html#L209'>skip_whitespace_and_comments</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span id="L446" class="LineNr">446 </span> <span class="Conceal">¦</span> string _assign = <a href='011load.cc.html#L167'>next_word</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> <span id="L447" class="LineNr">447 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>_assign<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> diff --git a/html/074wait.cc.html b/html/074wait.cc.html index 02633390..1fa4bb98 100644 --- a/html/074wait.cc.html +++ b/html/074wait.cc.html @@ -245,8 +245,8 @@ if ('onhashchange' in window) { <span id="L180" class="LineNr">180 </span> <span class="Delimiter">}</span> <span id="L181" class="LineNr">181 </span> <span class="Normal">int</span> offset_value = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L182" class="LineNr">182 </span> <span class="Comment">//: later layers will permit non-integer offsets</span> -<span id="L183" class="LineNr">183 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L184" class="LineNr">184 </span> <span class="Conceal">¦</span> offset_value = <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">);</span> +<span id="L183" class="LineNr">183 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L184" class="LineNr">184 </span> <span class="Conceal">¦</span> offset_value = to_integer<span class="Delimiter">(</span>offset<span class="Delimiter">.</span>name<span class="Delimiter">);</span> <span id="L185" class="LineNr">185 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>offset_value < <span class="Constant">0</span> || offset_value >= <a href='001help.cc.html#L141'>SIZE</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>elements<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L186" class="LineNr">186 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L174'>raise</a> << <a href='013update_operation.cc.html#L25'>maybe</a><span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> << <span class="Constant">"invalid offset "</span> << offset_value << <span class="Constant">" for '"</span> << get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> base_type<span class="Delimiter">).</span>name << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> <span id="L187" class="LineNr">187 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Identifier">break</span><span class="Delimiter">;</span> diff --git a/html/085scenario_console.cc.html b/html/085scenario_console.cc.html index f186df95..6775ab78 100644 --- a/html/085scenario_console.cc.html +++ b/html/085scenario_console.cc.html @@ -131,15 +131,15 @@ if ('onhashchange' in window) { <span id="L69" class="LineNr"> 69 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L167'>trace</a><span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 'left-click' event starting at "</span> << Current_routine<span class="Delimiter">-></span>alloc << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> <span id="L70" class="LineNr"> 70 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">tag for 'touch-event' variant of 'event' exclusive-container</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">);</span> <span id="L71" class="LineNr"> 71 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address+<span class="Comment">/*</span><span class="Comment">skip tag</span><span class="Comment">*/</span><span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">offset of 'type' in 'mouse-event'</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">,</span> TB_KEY_MOUSE_LEFT<span class="Delimiter">);</span> -<span id="L72" class="LineNr"> 72 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address+<span class="Comment">/*</span><span class="Comment">skip tag</span><span class="Comment">*/</span><span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">offset of 'row' in 'mouse-event'</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">,</span> <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> -<span id="L73" class="LineNr"> 73 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address+<span class="Comment">/*</span><span class="Comment">skip tag</span><span class="Comment">*/</span><span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">offset of 'column' in 'mouse-event'</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">,</span> <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address+<span class="Comment">/*</span><span class="Comment">skip tag</span><span class="Comment">*/</span><span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">offset of 'row' in 'mouse-event'</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">,</span> to_integer<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address+<span class="Comment">/*</span><span class="Comment">skip tag</span><span class="Comment">*/</span><span class="Constant">1</span>+<span class="Comment">/*</span><span class="Comment">offset of 'column' in 'mouse-event'</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">,</span> to_integer<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>name<span class="Delimiter">));</span> <span id="L74" class="LineNr"> 74 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> curr_address += <a href='085scenario_console.cc.html#L296'>size_of_event</a><span class="Delimiter">();</span> <span id="L75" class="LineNr"> 75 </span> <span class="Conceal">¦</span> <span class="Delimiter">}</span> <span id="L76" class="LineNr"> 76 </span> <span class="Conceal">¦</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name == <span class="Constant">"press"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L77" class="LineNr"> 77 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='003trace.cc.html#L167'>trace</a><span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 'press' event starting at "</span> << curr_address << <a href='003trace.cc.html#L203'>end</a><span class="Delimiter">();</span> <span id="L78" class="LineNr"> 78 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> string key = inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name<span class="Delimiter">;</span> -<span id="L79" class="LineNr"> 79 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span>key<span class="Delimiter">))</span> -<span id="L80" class="LineNr"> 80 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address+<span class="Constant">1</span><span class="Delimiter">,</span> <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>key<span class="Delimiter">));</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_integer<span class="Delimiter">(</span>key<span class="Delimiter">))</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address+<span class="Constant">1</span><span class="Delimiter">,</span> to_integer<span class="Delimiter">(</span>key<span class="Delimiter">));</span> <span id="L81" class="LineNr"> 81 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>contains_key<span class="Delimiter">(</span>Key<span class="Delimiter">,</span> key<span class="Delimiter">))</span> <span id="L82" class="LineNr"> 82 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <a href='001help.cc.html#L221'>put</a><span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> curr_address+<span class="Constant">1</span><span class="Delimiter">,</span> Key[key]<span class="Delimiter">);</span> <span id="L83" class="LineNr"> 83 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Normal">else</span> diff --git a/html/subx/002test.cc.html b/html/subx/002test.cc.html index cfbb0a7b..75b41571 100644 --- a/html/subx/002test.cc.html +++ b/html/subx/002test.cc.html @@ -60,117 +60,92 @@ if ('onhashchange' in window) { </head> <body onload='JumpToLine();'> <pre id='vimCodeElement'> -<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: A simple test harness. To create new tests, define functions starting with</span> -<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: 'test_'. To run all tests so defined, run:</span> -<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: $ ./mu test</span> -<span id="L4" class="LineNr"> 4 </span><span class="Comment">//:</span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: Every layer should include tests, and can reach into previous layers.</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: However, it seems like a good idea never to reach into tests from previous</span> -<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: layers. Every test should be a contract that always passes as originally</span> -<span id="L8" class="LineNr"> 8 </span><span class="Comment">//: written, regardless of any later layers. Avoid writing 'temporary' tests</span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: that are only meant to work until some layer.</span> -<span id="L10" class="LineNr"> 10 </span> -<span id="L11" class="LineNr"> 11 </span><span class="Delimiter">:(before "End Types")</span> -<span id="L12" class="LineNr"> 12 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*test_fn<span class="Delimiter">)(</span><span class="Normal">void</span><span class="Delimiter">);</span> -<span id="L13" class="LineNr"> 13 </span><span class="Delimiter">:(before "Globals")</span> -<span id="L14" class="LineNr"> 14 </span><span class="Comment">// move a global ahead into types that we can't generate an extern declaration for</span> -<span id="L15" class="LineNr"> 15 </span><span class="Normal">const</span> <a href='002test.cc.html#L12'>test_fn</a> Tests[] = <span class="Delimiter">{</span> -<span id="L16" class="LineNr"> 16 </span> <span class="PreProc">#include </span><span class="Constant">"test_list"</span> <span class="Comment">// auto-generated; see 'build' script</span> -<span id="L17" class="LineNr"> 17 </span><span class="Delimiter">};</span> -<span id="L18" class="LineNr"> 18 </span> -<span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L20" class="LineNr"> 20 </span><span class="Normal">bool</span> <a href='002test.cc.html#L20'>Run_tests</a> = <span class="Constant">false</span><span class="Delimiter">;</span> -<span id="L21" class="LineNr"> 21 </span><span class="Normal">bool</span> <a href='002test.cc.html#L21'>Passed</a> = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> -<span id="L22" class="LineNr"> 22 </span> -<span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(before "End Includes")</span> -<span id="L24" class="LineNr"> 24 </span><span class="PreProc">#define CHECK(X) \</span> -<span id="L25" class="LineNr"> 25 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (Passed && !(X)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> -<span id="L26" class="LineNr"> 26 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span id="L27" class="LineNr"> 27 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> <a href='002test.cc.html#L21'>Passed</a> = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span id="L28" class="LineNr"> 28 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> -<span id="L29" class="LineNr"> 29 </span><span class="PreProc"> </span><span class="Delimiter">}</span> -<span id="L30" class="LineNr"> 30 </span> -<span id="L31" class="LineNr"> 31 </span><span class="PreProc">#define CHECK_EQ(X</span><span class="Delimiter">,</span><span class="PreProc"> Y) \</span> -<span id="L32" class="LineNr"> 32 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (Passed && (X) != (Y)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> -<span id="L33" class="LineNr"> 33 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="Constant">" == "</span><span class="PreProc"> << #Y << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span id="L34" class="LineNr"> 34 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">" got "</span><span class="PreProc"> << (X) << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> BEWARE: multiple eval </span><span class="Comment">*/</span><span class="PreProc"> \</span> -<span id="L35" class="LineNr"> 35 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> <a href='002test.cc.html#L21'>Passed</a> = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> -<span id="L36" class="LineNr"> 36 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> -<span id="L37" class="LineNr"> 37 </span><span class="PreProc"> </span><span class="Delimiter">}</span> -<span id="L38" class="LineNr"> 38 </span> -<span id="L39" class="LineNr"> 39 </span><span class="Delimiter">:(before "End Reset")</span> -<span id="L40" class="LineNr"> 40 </span><a href='002test.cc.html#L21'>Passed</a> = <span class="Constant">true</span><span class="Delimiter">;</span> -<span id="L41" class="LineNr"> 41 </span> -<span id="L42" class="LineNr"> 42 </span><span class="Delimiter">:(before "End Commandline Parsing")</span> -<span id="L43" class="LineNr"> 43 </span><span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && <a href='001help.cc.html#L23'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"test"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L44" class="LineNr"> 44 </span> <a href='002test.cc.html#L20'>Run_tests</a> = <span class="Constant">true</span><span class="Delimiter">;</span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> <span class="Comment">// shift 'test' out of commandline args</span> -<span id="L45" class="LineNr"> 45 </span><span class="Delimiter">}</span> -<span id="L46" class="LineNr"> 46 </span> -<span id="L47" class="LineNr"> 47 </span><span class="Delimiter">:(before "End Main")</span> -<span id="L48" class="LineNr"> 48 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L20'>Run_tests</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L49" class="LineNr"> 49 </span> <span class="Comment">// Test Runs</span> -<span id="L50" class="LineNr"> 50 </span> <span class="Comment">// we run some tests and then exit; assume no state need be maintained afterward</span> -<span id="L51" class="LineNr"> 51 </span> -<span id="L52" class="LineNr"> 52 </span> <span class="Normal">long</span> num_failures = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Comment">// End Test Run Initialization</span> -<span id="L54" class="LineNr"> 54 </span> <span class="Normal">time_t</span> t<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> -<span id="L55" class="LineNr"> 55 </span> cerr << <span class="Constant">"C tests: "</span> << ctime<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> -<span id="L56" class="LineNr"> 56 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L57" class="LineNr"> 57 </span><span class="CommentedCode">//? cerr << "running .build/test_list line " << (i+1) << '\n';</span> -<span id="L58" class="LineNr"> 58 </span> <span class="Conceal">¦</span> <a href='002test.cc.html#L74'>run_test</a><span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a><span class="Delimiter">)</span> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> -<span id="L60" class="LineNr"> 60 </span> <span class="Conceal">¦</span> <span class="Normal">else</span> ++num_failures<span class="Delimiter">;</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Delimiter">}</span> -<span id="L62" class="LineNr"> 62 </span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L63" class="LineNr"> 63 </span> <span class="Comment">// End Tests</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>num_failures > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Conceal">¦</span> cerr << num_failures << <span class="Constant">" failure"</span> -<span id="L66" class="LineNr"> 66 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span><< <span class="Delimiter">(</span>num_failures > <span class="Constant">1</span> ? <span class="Constant">"s"</span> : <span class="Constant">""</span><span class="Delimiter">)</span> -<span id="L67" class="LineNr"> 67 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span><< <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> -<span id="L69" class="LineNr"> 69 </span> <span class="Delimiter">}</span> -<span id="L70" class="LineNr"> 70 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L71" class="LineNr"> 71 </span><span class="Delimiter">}</span> -<span id="L72" class="LineNr"> 72 </span> -<span id="L73" class="LineNr"> 73 </span><span class="Delimiter">:(code)</span> -<span id="L74" class="LineNr"> 74 </span><span class="Normal">void</span> <a href='002test.cc.html#L74'>run_test</a><span class="Delimiter">(</span><span class="Normal">size_t</span> i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L75" class="LineNr"> 75 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Conceal">¦</span> cerr << <span class="Constant">"no test "</span> << i << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L77" class="LineNr"> 77 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L78" class="LineNr"> 78 </span> <span class="Delimiter">}</span> -<span id="L79" class="LineNr"> 79 </span> <a href='000organization.cc.html#L139'>reset</a><span class="Delimiter">();</span> -<span id="L80" class="LineNr"> 80 </span> <span class="Comment">// End Test Setup</span> -<span id="L81" class="LineNr"> 81 </span> <span class="Delimiter">(</span>*Tests[i]<span class="Delimiter">)();</span> -<span id="L82" class="LineNr"> 82 </span> <span class="Comment">// End Test Teardown</span> -<span id="L83" class="LineNr"> 83 </span><span class="Delimiter">}</span> -<span id="L84" class="LineNr"> 84 </span> -<span id="L85" class="LineNr"> 85 </span><span class="Normal">bool</span> <a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L86" class="LineNr"> 86 </span> <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-"</span><span class="Delimiter">)</span> == string::npos <span class="Comment">// no other characters</span> -<span id="L87" class="LineNr"> 87 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && s<span class="Delimiter">.</span>find_first_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos <span class="Comment">// at least one digit</span> -<span id="L88" class="LineNr"> 88 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'-'</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">)</span> == string::npos<span class="Delimiter">;</span> <span class="Comment">// '-' only at first position</span> -<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">}</span> -<span id="L90" class="LineNr"> 90 </span> -<span id="L91" class="LineNr"> 91 </span><span class="Normal">int</span> <a href='002test.cc.html#L91'>to_integer</a><span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Normal">char</span>* <a href='003trace.cc.html#L184'>end</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> -<span id="L93" class="LineNr"> 93 </span> <span class="Comment">// safe because string.c_str() is guaranteed to be null-terminated</span> -<span id="L94" class="LineNr"> 94 </span> <span class="Normal">int</span> result = strtoll<span class="Delimiter">(</span>n<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">any base</span><span class="Comment">*/</span><span class="Constant">0</span><span class="Delimiter">);</span> -<span id="L95" class="LineNr"> 95 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*end != <span class="cSpecial">'\0'</span><span class="Delimiter">)</span> cerr << <span class="Constant">"tried to convert "</span> << n << <span class="Constant">" to number</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L96" class="LineNr"> 96 </span> assert<span class="Delimiter">(</span>*end == <span class="cSpecial">'\0'</span><span class="Delimiter">);</span> -<span id="L97" class="LineNr"> 97 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span id="L98" class="LineNr"> 98 </span><span class="Delimiter">}</span> -<span id="L99" class="LineNr"> 99 </span> -<span id="L100" class="LineNr">100 </span><span class="Normal">void</span> <a href='002test.cc.html#L100'>test_is_integer</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L101" class="LineNr">101 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span><span class="Constant">"1234"</span><span class="Delimiter">));</span> -<span id="L102" class="LineNr">102 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span><span class="Constant">"-1"</span><span class="Delimiter">));</span> -<span id="L103" class="LineNr">103 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"234.0"</span><span class="Delimiter">));</span> -<span id="L104" class="LineNr">104 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span><a href='002test.cc.html#L85'>is_integer</a><span class="Delimiter">(</span><span class="Constant">"-567"</span><span class="Delimiter">));</span> -<span id="L105" class="LineNr">105 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"89-0"</span><span class="Delimiter">));</span> -<span id="L106" class="LineNr">106 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"-"</span><span class="Delimiter">));</span> -<span id="L107" class="LineNr">107 </span> <a href='002test.cc.html#L24'>CHECK</a><span class="Delimiter">(</span>!is_integer<span class="Delimiter">(</span><span class="Constant">"1e3"</span><span class="Delimiter">));</span> <span class="Comment">// not supported</span> -<span id="L108" class="LineNr">108 </span><span class="Delimiter">}</span> -<span id="L109" class="LineNr">109 </span> -<span id="L110" class="LineNr">110 </span><span class="Delimiter">:(before "End Includes")</span> -<span id="L111" class="LineNr">111 </span><span class="PreProc">#include </span><span class="Constant"><stdlib.h></span> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: A simple test harness. To create new tests, define functions starting with</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">//: 'test_'. To run all tests so defined, run:</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">//: $ ./mu test</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">//:</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment">//: Every layer should include tests, and can reach into previous layers.</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment">//: However, it seems like a good idea never to reach into tests from previous</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment">//: layers. Every test should be a contract that always passes as originally</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">//: written, regardless of any later layers. Avoid writing 'temporary' tests</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment">//: that are only meant to work until some layer.</span> +<span id="L10" class="LineNr">10 </span> +<span id="L11" class="LineNr">11 </span><span class="Delimiter">:(before "End Types")</span> +<span id="L12" class="LineNr">12 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*test_fn<span class="Delimiter">)(</span><span class="Normal">void</span><span class="Delimiter">);</span> +<span id="L13" class="LineNr">13 </span><span class="Delimiter">:(before "Globals")</span> +<span id="L14" class="LineNr">14 </span><span class="Comment">// move a global ahead into types that we can't generate an extern declaration for</span> +<span id="L15" class="LineNr">15 </span><span class="Normal">const</span> <a href='002test.cc.html#L12'>test_fn</a> Tests[] = <span class="Delimiter">{</span> +<span id="L16" class="LineNr">16 </span> <span class="PreProc">#include </span><span class="Constant">"test_list"</span> <span class="Comment">// auto-generated; see 'build' script</span> +<span id="L17" class="LineNr">17 </span><span class="Delimiter">};</span> +<span id="L18" class="LineNr">18 </span> +<span id="L19" class="LineNr">19 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L20" class="LineNr">20 </span><span class="Normal">bool</span> <a href='002test.cc.html#L20'>Run_tests</a> = <span class="Constant">false</span><span class="Delimiter">;</span> +<span id="L21" class="LineNr">21 </span><span class="Normal">bool</span> <a href='002test.cc.html#L21'>Passed</a> = <span class="Constant">true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> +<span id="L22" class="LineNr">22 </span> +<span id="L23" class="LineNr">23 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L24" class="LineNr">24 </span><span class="PreProc">#define CHECK(X) \</span> +<span id="L25" class="LineNr">25 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (Passed && !(X)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> +<span id="L26" class="LineNr">26 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L27" class="LineNr">27 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> <a href='002test.cc.html#L21'>Passed</a> = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L28" class="LineNr">28 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L29" class="LineNr">29 </span><span class="PreProc"> </span><span class="Delimiter">}</span> +<span id="L30" class="LineNr">30 </span> +<span id="L31" class="LineNr">31 </span><span class="PreProc">#define CHECK_EQ(X</span><span class="Delimiter">,</span><span class="PreProc"> Y) \</span> +<span id="L32" class="LineNr">32 </span><span class="PreProc"> </span><span class="Normal">if</span><span class="PreProc"> (Passed && (X) != (Y)) </span><span class="Delimiter">{</span><span class="PreProc"> \</span> +<span id="L33" class="LineNr">33 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span><span class="PreProc"> << __FUNCTION__ << </span><span class="Constant">"("</span><span class="PreProc"> << </span><span class="Constant">__FILE__</span><span class="PreProc"> << </span><span class="Constant">":"</span><span class="PreProc"> << </span><span class="Constant">__LINE__</span><span class="PreProc"> << </span><span class="Constant">"): "</span><span class="PreProc"> << #X << </span><span class="Constant">" == "</span><span class="PreProc"> << #Y << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L34" class="LineNr">34 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> cerr << </span><span class="Constant">" got "</span><span class="PreProc"> << (X) << </span><span class="cSpecial">'\n'</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> BEWARE: multiple eval </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L35" class="LineNr">35 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> <a href='002test.cc.html#L21'>Passed</a> = </span><span class="Constant">false</span><span class="Delimiter">;</span><span class="PreProc"> \</span> +<span id="L36" class="LineNr">36 </span><span class="PreProc"> </span><span class="Conceal">¦</span><span class="PreProc"> </span><span class="Identifier">return</span><span class="Delimiter">;</span><span class="PreProc"> </span><span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span><span class="PreProc"> \</span> +<span id="L37" class="LineNr">37 </span><span class="PreProc"> </span><span class="Delimiter">}</span> +<span id="L38" class="LineNr">38 </span> +<span id="L39" class="LineNr">39 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L40" class="LineNr">40 </span><a href='002test.cc.html#L21'>Passed</a> = <span class="Constant">true</span><span class="Delimiter">;</span> +<span id="L41" class="LineNr">41 </span> +<span id="L42" class="LineNr">42 </span><span class="Delimiter">:(before "End Commandline Parsing")</span> +<span id="L43" class="LineNr">43 </span><span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && <a href='001help.cc.html#L23'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"test"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L44" class="LineNr">44 </span> <a href='002test.cc.html#L20'>Run_tests</a> = <span class="Constant">true</span><span class="Delimiter">;</span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> <span class="Comment">// shift 'test' out of commandline args</span> +<span id="L45" class="LineNr">45 </span><span class="Delimiter">}</span> +<span id="L46" class="LineNr">46 </span> +<span id="L47" class="LineNr">47 </span><span class="Delimiter">:(before "End Main")</span> +<span id="L48" class="LineNr">48 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L20'>Run_tests</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L49" class="LineNr">49 </span> <span class="Comment">// Test Runs</span> +<span id="L50" class="LineNr">50 </span> <span class="Comment">// we run some tests and then exit; assume no state need be maintained afterward</span> +<span id="L51" class="LineNr">51 </span> +<span id="L52" class="LineNr">52 </span> <span class="Normal">long</span> num_failures = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L53" class="LineNr">53 </span> <span class="Comment">// End Test Run Initialization</span> +<span id="L54" class="LineNr">54 </span> <span class="Normal">time_t</span> t<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> +<span id="L55" class="LineNr">55 </span> cerr << <span class="Constant">"C tests: "</span> << ctime<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> +<span id="L56" class="LineNr">56 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L57" class="LineNr">57 </span><span class="CommentedCode">//? cerr << "running .build/test_list line " << (i+1) << '\n';</span> +<span id="L58" class="LineNr">58 </span> <span class="Conceal">¦</span> <a href='002test.cc.html#L74'>run_test</a><span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L59" class="LineNr">59 </span> <span class="Conceal">¦</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a><span class="Delimiter">)</span> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> +<span id="L60" class="LineNr">60 </span> <span class="Conceal">¦</span> <span class="Normal">else</span> ++num_failures<span class="Delimiter">;</span> +<span id="L61" class="LineNr">61 </span> <span class="Delimiter">}</span> +<span id="L62" class="LineNr">62 </span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L63" class="LineNr">63 </span> <span class="Comment">// End Tests</span> +<span id="L64" class="LineNr">64 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>num_failures > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L65" class="LineNr">65 </span> <span class="Conceal">¦</span> cerr << num_failures << <span class="Constant">" failure"</span> +<span id="L66" class="LineNr">66 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span><< <span class="Delimiter">(</span>num_failures > <span class="Constant">1</span> ? <span class="Constant">"s"</span> : <span class="Constant">""</span><span class="Delimiter">)</span> +<span id="L67" class="LineNr">67 </span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span> <span class="Conceal">¦</span><< <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L68" class="LineNr">68 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L69" class="LineNr">69 </span> <span class="Delimiter">}</span> +<span id="L70" class="LineNr">70 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L71" class="LineNr">71 </span><span class="Delimiter">}</span> +<span id="L72" class="LineNr">72 </span> +<span id="L73" class="LineNr">73 </span><span class="Delimiter">:(code)</span> +<span id="L74" class="LineNr">74 </span><span class="Normal">void</span> <a href='002test.cc.html#L74'>run_test</a><span class="Delimiter">(</span><span class="Normal">size_t</span> i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L75" class="LineNr">75 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L76" class="LineNr">76 </span> <span class="Conceal">¦</span> cerr << <span class="Constant">"no test "</span> << i << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L77" class="LineNr">77 </span> <span class="Conceal">¦</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L78" class="LineNr">78 </span> <span class="Delimiter">}</span> +<span id="L79" class="LineNr">79 </span> <a href='000organization.cc.html#L139'>reset</a><span class="Delimiter">();</span> +<span id="L80" class="LineNr">80 </span> <span class="Comment">// End Test Setup</span> +<span id="L81" class="LineNr">81 </span> <span class="Delimiter">(</span>*Tests[i]<span class="Delimiter">)();</span> +<span id="L82" class="LineNr">82 </span> <span class="Comment">// End Test Teardown</span> +<span id="L83" class="LineNr">83 </span><span class="Delimiter">}</span> +<span id="L84" class="LineNr">84 </span> +<span id="L85" class="LineNr">85 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L86" class="LineNr">86 </span><span class="PreProc">#include </span><span class="Constant"><stdlib.h></span> </pre> </body> </html> diff --git a/subx/002test.cc b/subx/002test.cc index f6623c90..33560a9d 100644 --- a/subx/002test.cc +++ b/subx/002test.cc @@ -82,30 +82,5 @@ void run_test(size_t i) { // End Test Teardown } -bool is_integer(const string& s) { - return s.find_first_not_of("0123456789-") == string::npos // no other characters - && s.find_first_of("0123456789") != string::npos // at least one digit - && s.find('-', 1) == string::npos; // '-' only at first position -} - -int to_integer(string n) { - char* end = NULL; - // safe because string.c_str() is guaranteed to be null-terminated - int result = strtoll(n.c_str(), &end, /*any base*/0); - if (*end != '\0') cerr << "tried to convert " << n << " to number\n"; - assert(*end == '\0'); - return result; -} - -void test_is_integer() { - CHECK(is_integer("1234")); - CHECK(is_integer("-1")); - CHECK(!is_integer("234.0")); - CHECK(is_integer("-567")); - CHECK(!is_integer("89-0")); - CHECK(!is_integer("-")); - CHECK(!is_integer("1e3")); // not supported -} - :(before "End Includes") #include <stdlib.h> |