From c02478c4010d54acfaed0318a2c2c689b468e92e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 22 Oct 2016 16:27:36 -0700 Subject: 3558 --- html/052tangle.cc.html | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'html/052tangle.cc.html') diff --git a/html/052tangle.cc.html b/html/052tangle.cc.html index 59947dbd..4aff0513 100644 --- a/html/052tangle.cc.html +++ b/html/052tangle.cc.html @@ -15,14 +15,14 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color * { font-size: 12pt; font-size: 1em; } .Constant { color: #00a0a0; } .traceAbsent { color: #c00000; } -.cSpecial { color: #008000; } +.traceContains { color: #008000; } .muRecipe { color: #ff8700; } +.cSpecial { color: #008000; } .Comment { color: #9090ff; } .Delimiter { color: #800080; } .Special { color: #c00000; } -.traceContains { color: #008000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Identifier { color: #c0a020; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } --> @@ -35,12 +35,20 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 //: Allow code for recipes to be pulled in from multiple places and inserted
-//: at special labels called 'waypoints'. Unlike jump targets, a recipe can
-//: have multiple ambiguous waypoints with the same name. Any 'before' and
-//: 'after' fragments will simply be inserted at all applicable waypoints.
+//: at special labels called 'waypoints' using two new top-level commands:
+//:   before
+//:   after
+
+//: Most labels are local: they must be unique to a recipe, and are invisible
+//: outside the recipe. However, waypoints are global: a recipe can have
+//: multiple of them, you can't use them as jump targets.
+:(before "End is_jump_target Special-cases")
+if (is_waypoint(label)) return false;
 //: Waypoints are always surrounded by '<>', e.g. <handle-request>.
-//:
-//: todo: switch recipe.steps to a more efficient data structure.
+:(code)
+bool is_waypoint(string label) {
+  return *label.begin() == '<' && *label.rbegin() == '>';
+}
 
 :(scenario tangle_before)
 def main [
@@ -80,7 +88,7 @@ Fragments_used.clear();if (is_waypoint(label))
     Before_fragments[label].steps.insert(Before_fragments[label].steps.end(), tmp.steps.begin(), tmp.steps.end());
   else
-    raise << "can't tangle before label " << label << '\n' << end();
+    raise << "can't tangle before non-waypoint " << label << '\n' << end();
   // End before Command Handler
 }
 else if (command == "after") {
@@ -95,7 +103,7 @@ Fragments_used.clear();if (is_waypoint(label))
     After_fragments[label].steps.insert(After_fragments[label].steps.begin(), tmp.steps.begin(), tmp.steps.end());
   else
-    raise << "can't tangle after label " << label << '\n' << end();
+    raise << "can't tangle after non-waypoint " << label << '\n' << end();
   // End after Command Handler
 }
 
@@ -176,18 +184,13 @@ tangle_done = false;}
     for (int j = 0;  j < SIZE(inst.ingredients);  ++j) {
       reagent& x = inst.ingredients.at(j);
-      if (!is_literal(x)) continue;
-      if (x.type->name == "label" && contains_key(jump_targets, x.name))
+      if (is_jump_target(x.name) && contains_key(jump_targets, x.name))
         x.name = prefix+x.name;
     }
     base.push_back(inst);
   }
 }
 
-bool is_waypoint(string label) {
-  return *label.begin() == '<' && *label.rbegin() == '>';
-}
-
 //: complain about unapplied fragments
 //: This can't run during transform because later (shape-shifting recipes)
 //: we'll encounter situations where fragments might get used long after
@@ -238,7 +241,7 @@ $mem: 4
 before +label1 [
   2:num <- copy 0
 ]
-+error: can't tangle before label +label1
++error: can't tangle before non-waypoint +label1
 
 :(scenario tangle_keeps_labels_separate)
 def main [
-- 
cgit 1.4.1-2-gfad0