diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-22 16:27:36 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-22 16:27:36 -0700 |
commit | c02478c4010d54acfaed0318a2c2c689b468e92e (patch) | |
tree | 8cdc5a15f685e4ef27205a59306f5781a10b3899 /html/053recipe_header.cc.html | |
parent | 6a9d8191dfb5606f8d3630375f3ec045bd534ba3 (diff) | |
download | mu-c02478c4010d54acfaed0318a2c2c689b468e92e.tar.gz |
3558
Diffstat (limited to 'html/053recipe_header.cc.html')
-rw-r--r-- | html/053recipe_header.cc.html | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/html/053recipe_header.cc.html b/html/053recipe_header.cc.html index 69b77f7f..d379b46a 100644 --- a/html/053recipe_header.cc.html +++ b/html/053recipe_header.cc.html @@ -458,7 +458,7 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>fill_in_reply_ingredients<span class="Delimiter">);</span> <span class="Comment">// idempotent</span> <span class="Delimiter">:(code)</span> -<span class="Normal">void</span> fill_in_reply_ingredients<span class="Delimiter">(</span>recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> fill_in_reply_ingredients<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> recipe& caller_recipe = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!caller_recipe<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">9991</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"--- fill in reply ingredients from header for recipe "</span> << caller_recipe<span class="Delimiter">.</span>name << end<span class="Delimiter">();</span> @@ -559,6 +559,49 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa ] <span class="traceContains">+error: main: '3:num <- add2 1:num, 2:num' should write to '1:num' rather than '3:num'</span> +<span class="Comment">//: One special-case is recipe 'main'. Make sure it's only ever taking in text</span> +<span class="Comment">//: ingredients, and returning a single number.</span> + +<span class="Delimiter">:(scenario recipe_header_ingredients_constrained_for_main)</span> +<span class="Special">% Hide_errors = true;</span> +<span class="muRecipe">def</span> main x:num [ +] +<span class="traceContains">+error: ingredients of recipe 'main' must all be text (address:array:character)</span> + +<span class="Delimiter">:(scenario recipe_header_products_constrained_for_main)</span> +<span class="Special">% Hide_errors = true;</span> +<span class="muRecipe">def</span> main<span class="muRecipe"> -> </span>x:text [ +] +<span class="traceContains">+error: recipe 'main' must return at most a single product, a number</span> + +<span class="Delimiter">:(scenario recipe_header_products_constrained_for_main_2)</span> +<span class="Special">% Hide_errors = true;</span> +<span class="muRecipe">def</span> main<span class="muRecipe"> -> </span>x:num<span class="Delimiter">,</span> y:num [ +] +<span class="traceContains">+error: recipe 'main' must return at most a single product, a number</span> + +<span class="Delimiter">:(after "Transform.push_back(expand_type_abbreviations)")</span> +Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>check_recipe_header_constraints<span class="Delimiter">);</span> +<span class="Delimiter">:(code)</span> +<span class="Normal">void</span> check_recipe_header_constraints<span class="Delimiter">(</span><span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">const</span> recipe& caller = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>caller<span class="Delimiter">.</span>name != <span class="Constant">"main"</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!caller<span class="Delimiter">.</span>has_header<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> + reagent<span class="Comment">/*</span><span class="Comment">local</span><span class="Comment">*/</span> expected_ingredient<span class="Delimiter">(</span><span class="Constant">"x:address:array:character"</span><span class="Delimiter">);</span> + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>!types_strictly_match<span class="Delimiter">(</span>expected_ingredient<span class="Delimiter">,</span> caller<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)))</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"ingredients of recipe 'main' must all be text (address:array:character)</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Delimiter">}</span> + <span class="Normal">int</span> nprod = SIZE<span class="Delimiter">(</span>caller<span class="Delimiter">.</span>products<span class="Delimiter">);</span> + reagent<span class="Comment">/*</span><span class="Comment">local</span><span class="Comment">*/</span> expected_product<span class="Delimiter">(</span><span class="Constant">"x:number"</span><span class="Delimiter">);</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>nprod > <span class="Constant">1</span> + || <span class="Delimiter">(</span>nprod == <span class="Constant">1</span> && !types_strictly_match<span class="Delimiter">(</span>expected_product<span class="Delimiter">,</span> caller<span class="Delimiter">.</span>products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">))))</span> <span class="Delimiter">{</span> + raise << <span class="Constant">"recipe 'main' must return at most a single product, a number</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> + <span class="Delimiter">}</span> +<span class="Delimiter">}</span> + <span class="Delimiter">:(before "End Includes")</span> <span class="Normal">using</span> std::min<span class="Delimiter">;</span> <span class="Normal">using</span> std::max<span class="Delimiter">;</span> |