//: Allow code for recipes to be pulled in from multiple places and inserted //: 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. . :(code) bool is_waypoint(string label) { return *label.begin() == '<' && *label.rbegin() == '>'; } void test_tangle_before() { run( "def main [\n" " 1:num <- copy 0\n" " \n" " 3:num <- copy 0\n" "]\n" "before [\n" " 2:num <- copy 0\n" "]\n" ); CHECK_TRACE_CONTENTS( "mem: storing 0 in location 1\n" "mem: storing 0 in location 2\n" "mem: storing 0 in location 3\n" ); // nothing else CHECK_TRACE_COUNT("mem", 3); } //: while loading recipes, load before/after fragments :(before "End Globals") map Before_fragments, After_fragments; set Fragments_used; :(before "End Reset") Before_fragments.clear(); After_fragments.clear(); Fragments_used.clear(); :(before "End Command Handlers") else if (command == "before") { string label = next_word(in); if (label.empty()) { assert(!has_data(in)); raise << "incomplete 'before' block at end of file\n" << end(); return result; } recipe tmp; slurp_body(in, tmp); 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 non-waypoint " << label << '\n' << end(); // End before Command Handler } else if (command == "after") { string label = next_word(in); if (label.empty()) { assert(!has_data(in)); raise << "incomplete 'after' block at end of file\n" << end(); return result; } recipe tmp; slurp_body(in, tmp); 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 non-waypoint " << label << '\n' << end(); // End after Command Handler } //: after all recipes are loaded, insert fragments at appropriate labels. :(after "Begin Instruction Inserting/Deleting Transforms") Transform.push_back(insert_fragments); // NOT idempotent //: We might need to perform multiple passes, in case inserted fragments //: include more labels that need further insertions. Track which labels we've //: already processed using an extra field. :(before "End instruction Fields") mutable bool tangle_done; :(before "End instruction Constructor") tangle_done = false; :(code) void insert_fragments(const recipe_ordinal r) { insert_fragments(get(Recipe, r)); } void insert_fragments(recipe& r) { trace(101, "transform") << "--- insert fragments into recipe " << r.name << end(); bool made_progress = true; int pass = 0; while (made_progress) { made_progress = false; // create a new vector because insertions invalidate iterators vector result; for (int i = 0; i < SIZE(r.steps); ++i) { const instruction& inst = r.steps.at(i); if (!inst.is_label || !is_waypoint(inst.label) || inst.tangle_done) { result.push_back(inst); continue; } inst.tangle_done = true; made_progress = true; Fragments_used.insert(inst.label); ostringstream prefix; prefix << '+' << r.name << '_' << pass << '_' << i; // ok to use contains_key even though Before_fragments uses [], // because appending an empty recipe is a noop if (contains_key(Before_fragments, inst.label)) { trace(102, "transform") << "insert fragments before label " << inst.label << end(); append_fragment(result, Before_fragments[inst.label].steps, prefix.str()); } result.push_back(i
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.ext.get_all_modules</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.ext.html"><font color="#ffffff">ext</font></a>.get_all_modules</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/work/ranger/ranger/ext/get_all_modules.py">/home/hut/work/ranger/ranger/ext/get_all_modules.py</a></font></td></tr></table>
    <p></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=