From 76755b2836b0dadd88f82635f661f9d9df77604d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 10 Nov 2015 21:35:42 -0800 Subject: 2423 - describe shape-shifting in html docs --- html/052tangle.cc.html | 52 ++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'html/052tangle.cc.html') diff --git a/html/052tangle.cc.html b/html/052tangle.cc.html index 95fc502f..4fc37210 100644 --- a/html/052tangle.cc.html +++ b/html/052tangle.cc.html @@ -13,6 +13,7 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .traceAbsent { color: #c00000; } .cSpecial { color: #008000; } .Comment { color: #9090ff; } @@ -20,7 +21,6 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } .Special { color: #ff6060; } .Identifier { color: #804000; } .Constant { color: #00a0a0; } -.traceContains { color: #008000; } --> @@ -69,27 +69,29 @@ Fragments_used.clear();:(before "End Command Handlers") else if (command == "before") { string label = next_word(in); - recipe tmp = slurp_body(in); + 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 label " << label << '\n' << end(); + raise_error << "can't tangle before label " << label << '\n' << end(); } else if (command == "after") { string label = next_word(in); - recipe tmp = slurp_body(in); + 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 label " << label << '\n' << end(); + raise_error << "can't tangle after label " << label << '\n' << end(); } //: after all recipes are loaded, insert fragments at appropriate labels. -:(after "int main") - Transform.push_back(insert_fragments); +:(after "Begin Transforms") +Transform.push_back(insert_fragments); // NOT idempotent -//; We might need to perform multiple passes, in case inserted fragments +//: 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") @@ -105,8 +107,8 @@ void insert_fragments(const recipe_ordinal rfalse; // create a new vector because insertions invalidate iterators vector<instruction> result; - for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) { - const instruction& inst = Recipe[r].steps.at(i); + for (long long int i = 0; i < SIZE(get(Recipe, r).steps); ++i) { + const instruction& inst = get(Recipe, r).steps.at(i); if (!inst.is_label || !is_waypoint(inst.label) || inst.tangle_done) { result.push_back(inst); continue; @@ -115,16 +117,16 @@ void insert_fragments(const recipe_ordinal rtrue; Fragments_used.insert(inst.label); ostringstream prefix; - prefix << '+' << Recipe[r].name << '_' << pass << '_' << i; - if (Before_fragments.find(inst.label) != Before_fragments.end()) { + prefix << '+' << get(Recipe, r).name << '_' << pass << '_' << i; + if (contains_key(Before_fragments, inst.label)) { append_fragment(result, Before_fragments[inst.label].steps, prefix.str()); } result.push_back(inst); - if (After_fragments.find(inst.label) != After_fragments.end()) { + if (contains_key(After_fragments, inst.label)) { append_fragment(result, After_fragments[inst.label].steps, prefix.str()); } } - Recipe[r].steps.swap(result); + get(Recipe, r).steps.swap(result); ++pass; } } @@ -145,7 +147,7 @@ void append_fragment(vector<instruction>&am for (long long int i = 0; i < SIZE(patch); ++i) { instruction inst = patch.at(i); if (inst.is_label) { - if (jump_targets.find(inst.label) != jump_targets.end()) + if (contains_key(jump_targets, inst.label)) inst.label = prefix+inst.label; base.push_back(inst); continue; @@ -153,7 +155,7 @@ void append_fragment(vector<instruction>&am for (long long int j = 0; j < SIZE(inst.ingredients); ++j) { reagent& x = inst.ingredients.at(j); if (!is_literal(x)) continue; - if (x.properties.at(0).second.at(0) == "label" && jump_targets.find(x.name) != jump_targets.end()) + if (x.properties.at(0).second->value == "label" && contains_key(jump_targets, x.name)) x.name = prefix+x.name; } base.push_back(inst); @@ -164,22 +166,22 @@ bool is_waypoint(string labelreturn *label.begin() == '<' && *label.rbegin() == '>'; } -//: warn about unapplied fragments +//: complain about unapplied fragments :(before "End Globals") bool Transform_check_insert_fragments_Ran = false; -:(before "End One-time Setup") -Transform.push_back(check_insert_fragments); // final transform +:(after "Transform.push_back(insert_fragments)") +Transform.push_back(check_insert_fragments); // idempotent :(code) void check_insert_fragments(unused recipe_ordinal) { if (Transform_check_insert_fragments_Ran) return; Transform_check_insert_fragments_Ran = true; for (map<string, recipe>::iterator p = Before_fragments.begin(); p != Before_fragments.end(); ++p) { - if (Fragments_used.find(p->first) == Fragments_used.end()) - raise << "could not locate insert before " << p->first << '\n' << end(); + if (!contains_key(Fragments_used, p->first)) + raise_error << "could not locate insert before " << p->first << '\n' << end(); } for (map<string, recipe>::iterator p = After_fragments.begin(); p != After_fragments.end(); ++p) { - if (Fragments_used.find(p->first) == Fragments_used.end()) - raise << "could not locate insert after " << p->first << '\n' << end(); + if (!contains_key(Fragments_used, p->first)) + raise_error << "could not locate insert after " << p->first << '\n' << end(); } } @@ -204,7 +206,7 @@ after <label1> [ $mem: 4 :(scenario tangle_ignores_jump_target) -% Hide_warnings = true; +% Hide_errors = true; recipe main [ 1:number <- copy 0 +label1 @@ -213,7 +215,7 @@ recipe main [ before +label1 [ 2:number <- copy 0 ] -+warn: can't tangle before label +label1 ++error: can't tangle before label +label1 +mem: storing 0 in location 1 +mem: storing 0 in location 4 # label1 -- cgit 1.4.1-2-gfad0