diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-07-12 00:11:56 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-07-12 00:11:56 -0700 |
commit | d5d908dda655c791329563522faad42d7e4ee618 (patch) | |
tree | 628b8a23e13878c45ef39dfbffb860c676da5304 /html/040brace.cc.html | |
parent | 9864bdd0792b697d7b03e692ba7f82cf5669c41c (diff) | |
download | mu-d5d908dda655c791329563522faad42d7e4ee618.tar.gz |
1766
Diffstat (limited to 'html/040brace.cc.html')
-rw-r--r-- | html/040brace.cc.html | 158 |
1 files changed, 64 insertions, 94 deletions
diff --git a/html/040brace.cc.html b/html/040brace.cc.html index 12122f75..f5f3921c 100644 --- a/html/040brace.cc.html +++ b/html/040brace.cc.html @@ -14,6 +14,7 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .traceContains { color: #008000; } +.cSpecial { color: #008000; } .Constant { color: #00a0a0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } @@ -69,7 +70,7 @@ recipe main [ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>transform_braces<span class="Delimiter">);</span> <span class="Delimiter">:(code)</span> -void transform_braces<span class="Delimiter">(</span>const recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span> +void transform_braces<span class="Delimiter">(</span>const recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="CommentedCode">//? cout << "AAA transform_braces\n"; //? 1</span> <span class="CommentedCode">//? exit(0); //? 1</span> const int OPEN = <span class="Constant">0</span><span class="Delimiter">,</span> CLOSE = <span class="Constant">1</span><span class="Delimiter">;</span> @@ -89,103 +90,65 @@ void transform_braces<span class="Delimiter">(</span>const recipe_number r<span stack<<span class="Comment">/*</span><span class="Comment">step</span><span class="Comment">*/</span>long long int> open_braces<span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"recipe "</span> << Recipe[r]<span class="Delimiter">.</span>name<span class="Delimiter">;</span> for <span class="Delimiter">(</span>long long int index = <span class="Constant">0</span><span class="Delimiter">;</span> index < SIZE<span class="Delimiter">(</span>Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">);</span> ++index<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cerr << index << '\n'; //? 1</span> instruction& inst = Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">);</span> -<span class="CommentedCode">//? cout << "AAA " << inst.name << ": " << inst.operation << '\n'; //? 1</span> - if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"{"</span><span class="Delimiter">)</span> open_braces<span class="Delimiter">.</span>push<span class="Delimiter">(</span>index<span class="Delimiter">);</span> - else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"}"</span><span class="Delimiter">)</span> open_braces<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> - else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> - <span class="Delimiter">;</span> <span class="Comment">// do nothing</span> - else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && is_literal<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> <span class="Delimiter">{</span> - <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - reagent ing<span class="Delimiter">;</span> - ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">()</span>-index<span class="Delimiter">);</span> - ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << index << <span class="Constant">": "</span> << ing<span class="Delimiter">.</span>to_string<span class="Delimiter">();</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << index << <span class="Constant">": "</span> << Recipe[r]<span class="Delimiter">.</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>index<span class="Delimiter">).</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>to_string<span class="Delimiter">();</span> - <span class="Delimiter">}</span> - <span class="Delimiter">}</span> - else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && is_literal<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> <span class="Delimiter">{</span> - <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - reagent ing<span class="Delimiter">;</span> - ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>matching_brace<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">(),</span> braces<span class="Delimiter">)</span> - index - <span class="Constant">1</span><span class="Delimiter">);</span> - ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - <span class="Delimiter">}</span> - else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop-if"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-if"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span> && is_literal<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> <span class="Delimiter">{</span> - <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - reagent ing<span class="Delimiter">;</span> - ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">()</span>-index<span class="Delimiter">);</span> - ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if "</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="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"{"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + open_braces<span class="Delimiter">.</span>push<span class="Delimiter">(</span>index<span class="Delimiter">);</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break-if"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-if"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span> && is_literal<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> <span class="Delimiter">{</span> - <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - reagent ing<span class="Delimiter">;</span> - ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>matching_brace<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">(),</span> braces<span class="Delimiter">)</span> - index - <span class="Constant">1</span><span class="Delimiter">);</span> - ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if "</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="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label == <span class="Constant">"}"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> + open_braces<span class="Delimiter">.</span>pop<span class="Delimiter">();</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"loop-unless"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> - inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">;</span> - if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span> && is_literal<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> <span class="Delimiter">{</span> - <span class="Comment">// explicit target; a later phase will handle it</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - reagent ing<span class="Delimiter">;</span> - ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">()</span>-index<span class="Delimiter">);</span> - ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless "</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="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"loop"</span>] + && inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"loop-if"</span>] + && inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"loop-unless"</span>] + && inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"break"</span>] + && inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"break-if"</span>] + && inst<span class="Delimiter">.</span>operation != Recipe_ordinal[<span class="Constant">"break-unless"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << inst<span class="Delimiter">.</span>name << <span class="Constant">" ..."</span><span class="Delimiter">;</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> - else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>operation == Recipe_number[<span class="Constant">"break-unless"</span>]<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span class="CommentedCode">//? cout << "AAA break-unless\n"; //? 1</span> - inst<span class="Delimiter">.</span>operation = Recipe_number[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">;</span> + <span class="Comment">// update instruction operation</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + inst<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"jump-if"</span>]<span class="Delimiter">;</span> + else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + inst<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"jump-unless"</span>]<span class="Delimiter">;</span> + else + inst<span class="Delimiter">.</span>operation = Recipe_ordinal[<span class="Constant">"jump"</span>]<span class="Delimiter">;</span> + <span class="Comment">// check for explicitly provided targets</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos || inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Comment">// conditional branches check arg 1</span> if <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> > <span class="Constant">1</span> && is_literal<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> <span class="Delimiter">{</span> - <span class="Comment">// explicit target; a later phase will handle it</span> trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> - <span class="Delimiter">}</span> - else <span class="Delimiter">{</span> - reagent ing<span class="Delimiter">;</span> - ing<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>matching_brace<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">(),</span> braces<span class="Delimiter">)</span> - index - <span class="Constant">1</span><span class="Delimiter">);</span> - ing<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_number[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> - inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>ing<span class="Delimiter">);</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless "</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="Constant">", "</span> << ing<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> else <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << inst<span class="Delimiter">.</span>name << <span class="Constant">" ..."</span><span class="Delimiter">;</span> + <span class="Comment">// unconditional branches check arg 0</span> + if <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && is_literal<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> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</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="Constant">":offset"</span><span class="Delimiter">;</span> + <span class="Identifier">continue</span><span class="Delimiter">;</span> + <span class="Delimiter">}</span> <span class="Delimiter">}</span> + <span class="Comment">// if implicit, compute target</span> + reagent target<span class="Delimiter">;</span> + target<span class="Delimiter">.</span>types<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>Type_ordinal[<span class="Constant">"offset"</span>]<span class="Delimiter">);</span> + target<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + if <span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> + raise << inst<span class="Delimiter">.</span>name << <span class="Constant">" wasn't inside {}</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> + else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"loop"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + target<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">()</span>-index<span class="Delimiter">);</span> + else <span class="Comment">// break instruction</span> + target<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>matching_brace<span class="Delimiter">(</span>open_braces<span class="Delimiter">.</span>top<span class="Delimiter">(),</span> braces<span class="Delimiter">)</span> - index - <span class="Constant">1</span><span class="Delimiter">);</span> + inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>target<span class="Delimiter">);</span> + <span class="Comment">// log computed target</span> + if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-if"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-if "</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="Constant">", "</span> << target<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + else if <span class="Delimiter">(</span>inst<span class="Delimiter">.</span>name<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">"-unless"</span><span class="Delimiter">)</span> != string::npos<span class="Delimiter">)</span> + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump-unless "</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="Constant">", "</span> << target<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> + else + trace<span class="Delimiter">(</span><span class="Constant">"after-brace"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << target<span class="Delimiter">.</span>value << <span class="Constant">":offset"</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> @@ -219,12 +182,12 @@ LOOP<span class="Delimiter">,</span> LOOP_IF<span class="Delimiter">,</span> LOOP_UNLESS<span class="Delimiter">,</span> <span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> -Recipe_number[<span class="Constant">"break"</span>] = BREAK<span class="Delimiter">;</span> -Recipe_number[<span class="Constant">"break-if"</span>] = BREAK_IF<span class="Delimiter">;</span> -Recipe_number[<span class="Constant">"break-unless"</span>] = BREAK_UNLESS<span class="Delimiter">;</span> -Recipe_number[<span class="Constant">"loop"</span>] = LOOP<span class="Delimiter">;</span> -Recipe_number[<span class="Constant">"loop-if"</span>] = LOOP_IF<span class="Delimiter">;</span> -Recipe_number[<span class="Constant">"loop-unless"</span>] = LOOP_UNLESS<span class="Delimiter">;</span> +Recipe_ordinal[<span class="Constant">"break"</span>] = BREAK<span class="Delimiter">;</span> +Recipe_ordinal[<span class="Constant">"break-if"</span>] = BREAK_IF<span class="Delimiter">;</span> +Recipe_ordinal[<span class="Constant">"break-unless"</span>] = BREAK_UNLESS<span class="Delimiter">;</span> +Recipe_ordinal[<span class="Constant">"loop"</span>] = LOOP<span class="Delimiter">;</span> +Recipe_ordinal[<span class="Constant">"loop-if"</span>] = LOOP_IF<span class="Delimiter">;</span> +Recipe_ordinal[<span class="Constant">"loop-unless"</span>] = LOOP_UNLESS<span class="Delimiter">;</span> <span class="Delimiter">:(scenario loop)</span> recipe main [ @@ -427,6 +390,13 @@ recipe test-factorial [ <span class="Constant">4</span>:number<span class="Special"> <- </span>copy <span class="Constant">2</span>:number <span class="Comment"># trigger a read</span> ] <span class="traceContains">+mem: location 2 is 120</span> + +<span class="Delimiter">:(scenario break_outside_braces_warns)</span> +<span class="Special">% Hide_warnings = true;</span> +recipe main [ + <span class="Identifier">break</span> +] +<span class="traceContains">+warn: break wasn't inside {}</span> </pre> </body> </html> |