about summary refs log tree commit diff stats
path: root/html/041jump_target.cc.html
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-22 16:27:36 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-22 16:27:36 -0700
commitc02478c4010d54acfaed0318a2c2c689b468e92e (patch)
tree8cdc5a15f685e4ef27205a59306f5781a10b3899 /html/041jump_target.cc.html
parent6a9d8191dfb5606f8d3630375f3ec045bd534ba3 (diff)
downloadmu-c02478c4010d54acfaed0318a2c2c689b468e92e.tar.gz
3558
Diffstat (limited to 'html/041jump_target.cc.html')
-rw-r--r--html/041jump_target.cc.html29
1 files changed, 16 insertions, 13 deletions
diff --git a/html/041jump_target.cc.html b/html/041jump_target.cc.html
index 2c6b6fde..98c5eab7 100644
--- a/html/041jump_target.cc.html
+++ b/html/041jump_target.cc.html
@@ -34,14 +34,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 </head>
 <body>
 <pre id='vimCodeElement'>
-<span class="Comment">//: Support jumps to special labels called 'targets'. Targets must be in the</span>
-<span class="Comment">//: same recipe as the jump, and must be unique in that recipe. Targets always</span>
-<span class="Comment">//: start with a '+'.</span>
+<span class="Comment">//: Support jumps to a specific label (the 'jump target') in the same recipe.</span>
+<span class="Comment">//: Jump targets must be unique and unambiguous within any recipe.</span>
 <span class="Comment">//:</span>
-<span class="Comment">//: We'll also treat 'break' and 'loop' as jumps. The choice of name is</span>
-<span class="Comment">//: just documentation about intent; use 'break' to indicate you're exiting</span>
-<span class="Comment">//: one or more loop nests, and 'loop' to indicate you're skipping to the next</span>
-<span class="Comment">//: iteration of some containing loop nest.</span>
+<span class="Comment">//: The 'break' and 'loop' pseudo instructions can also take jump targets.</span>
+<span class="Comment">//: Which instruction you use is just documentation about intent; use 'break'</span>
+<span class="Comment">//: to indicate you're exiting one or more loop nests, and 'loop' to indicate</span>
+<span class="Comment">//: you're skipping to the next iteration of some containing loop nest.</span>
+
+<span class="Comment">//: Since they have to be unique in a recipe, not all labels can be jump</span>
+<span class="Comment">//: targets.</span>
+<span class="Normal">bool</span> is_jump_target<span class="Delimiter">(</span><span class="Normal">const</span> string&amp; label<span class="Delimiter">)</span> <span class="Delimiter">{</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>label == <span class="Constant">&quot;{&quot;</span> || label == <span class="Constant">&quot;}&quot;</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
+  <span class="Comment">// End is_jump_target Special-cases</span>
+  <span class="Identifier">return</span> is_label_word<span class="Delimiter">(</span>label<span class="Delimiter">);</span>
+<span class="Delimiter">}</span>
 
 <span class="Delimiter">:(scenario jump_to_label)</span>
 <span class="muRecipe">def</span> main [
@@ -62,7 +69,8 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa
   map&lt;string<span class="Delimiter">,</span> <span class="Normal">int</span>&gt; offset<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 &lt; SIZE<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>steps<span class="Delimiter">);</span>  ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
     <span class="Normal">const</span> instruction&amp; inst = get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>steps<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span>
-    <span class="Normal">if</span> <span class="Delimiter">(</span>starts_with<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">,</span> <span class="Constant">&quot;+&quot;</span><span class="Delimiter">))</span> <span class="Delimiter">{</span>
+    <span class="Normal">if</span> <span class="Delimiter">(</span>!inst<span class="Delimiter">.</span>is_label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
+    <span class="Normal">if</span> <span class="Delimiter">(</span>is_jump_target<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>label<span class="Delimiter">))</span> <span class="Delimiter">{</span>
       <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>offset<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">))</span> <span class="Delimiter">{</span>
         put<span class="Delimiter">(</span>offset<span class="Delimiter">,</span> inst<span class="Delimiter">.</span>label<span class="Delimiter">,</span> i<span class="Delimiter">);</span>
       <span class="Delimiter">}</span>
@@ -101,7 +109,6 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa
   <span class="Delimiter">}</span>
 <span class="Delimiter">}</span>
 
-<span class="Delimiter">:(code)</span>
 <span class="Normal">void</span> replace_offset<span class="Delimiter">(</span>reagent&amp; x<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">const</span><span class="Comment">*/</span> map&lt;string<span class="Delimiter">,</span> <span class="Normal">int</span>&gt;&amp; offset<span class="Delimiter">,</span> <span class="Normal">const</span> <span class="Normal">int</span> current_offset<span class="Delimiter">,</span> <span class="Normal">const</span> recipe_ordinal r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>!is_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Delimiter">{</span>
     raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;jump target must be offset or label but is '&quot;</span> &lt;&lt; x<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
@@ -123,10 +130,6 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa
   x<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>get<span class="Delimiter">(</span>offset<span class="Delimiter">,</span> x<span class="Delimiter">.</span>name<span class="Delimiter">)</span> - current_offset<span class="Delimiter">);</span>
 <span class="Delimiter">}</span>
 
-<span class="Normal">bool</span> is_jump_target<span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span>
-  <span class="Identifier">return</span> starts_with<span class="Delimiter">(</span>label<span class="Delimiter">,</span> <span class="Constant">&quot;+&quot;</span><span class="Delimiter">);</span>
-<span class="Delimiter">}</span>
-
 <span class="Delimiter">:(scenario break_to_label)</span>
 <span class="muRecipe">def</span> main [
   <span class="Delimiter">{</span>