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/046closure_name.cc.html | 90 +++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 39 deletions(-) (limited to 'html/046closure_name.cc.html') diff --git a/html/046closure_name.cc.html b/html/046closure_name.cc.html index 4587a5aa..13c7ddd2 100644 --- a/html/046closure_name.cc.html +++ b/html/046closure_name.cc.html @@ -13,13 +13,14 @@ 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; } +.Identifier { color: #804000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } -.Identifier { color: #804000; } -.traceContains { color: #008000; } +.CommentedCode { color: #6c6c6c; } --> @@ -59,47 +60,58 @@ recipe increment-counter [ reply y:number/space:1 ] -+name: recipe increment-counter is surrounded by new-counter ++name: lexically surrounding space for recipe increment-counter comes from new-counter +mem: storing 5 in location 3 //: To make this work, compute the recipe that provides names for the -//: surrounding space of each recipe. This must happen before transform_names. +//: surrounding space of each recipe. :(before "End Globals") map<recipe_ordinal, recipe_ordinal> Surrounding_space; -:(after "int main") - Transform.push_back(collect_surrounding_spaces); +:(before "Transform.push_back(transform_names)") +Transform.push_back(collect_surrounding_spaces); // idempotent :(code) void collect_surrounding_spaces(const recipe_ordinal r) { - for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) { - const instruction& inst = Recipe[r].steps.at(i); + trace(9991, "transform") << "--- collect surrounding spaces for recipe " << get(Recipe, r).name << end(); +//? cerr << "--- collect surrounding spaces for recipe " << get(Recipe, r).name << '\n'; + 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) continue; for (long long int j = 0; j < SIZE(inst.products); ++j) { if (is_literal(inst.products.at(j))) continue; if (inst.products.at(j).name != "0") continue; - if (SIZE(inst.products.at(j).types) != 3 - || inst.products.at(j).types.at(0) != Type_ordinal["address"] - || inst.products.at(j).types.at(1) != Type_ordinal["array"] - || inst.products.at(j).types.at(2) != Type_ordinal["location"]) { - raise << "slot 0 should always have type address:array:location, but is " << inst.products.at(j).to_string() << '\n' << end(); + type_tree* type = inst.products.at(j).type; + if (!type + || type->value != get(Type_ordinal, "address") + || !type->right + || type->right->value != get(Type_ordinal, "array") + || !type->right->right + || type->right->right->value != get(Type_ordinal, "location") + || type->right->right->right) { + raise_error << "slot 0 should always have type address:array:location, but is " << inst.products.at(j).to_string() << '\n' << end(); + continue; + } + string_tree* s = property(inst.products.at(j), "names"); + if (!s) { + raise_error << "slot 0 requires a /names property in recipe " << get(Recipe, r).name << end(); continue; } - vector<string> s = property(inst.products.at(j), "names"); - if (s.empty()) { - raise << "slot 0 requires a /names property in recipe " << Recipe[r].name << end(); + if (s->right) raise_error << "slot 0 should have a single value in /names, but got " << inst.products.at(j).to_string() << '\n' << end(); + const string& surrounding_recipe_name = s->value; + if (contains_key(Surrounding_space, r) + && Surrounding_space[r] != get(Recipe_ordinal, surrounding_recipe_name)) { + raise_error << "recipe " << get(Recipe, r).name << " can have only one 'surrounding' recipe but has " << get(Recipe, Surrounding_space[r]).name << " and " << surrounding_recipe_name << '\n' << end(); continue; } - if (SIZE(s) > 1) raise << "slot 0 should have a single value in /names, but got " << inst.products.at(j).to_string() << '\n' << end(); - string surrounding_recipe_name = s.at(0); - if (Surrounding_space.find(r) != Surrounding_space.end() - && Surrounding_space[r] != Recipe_ordinal[surrounding_recipe_name]) { - raise << "recipe " << Recipe[r].name << " can have only one 'surrounding' recipe but has " << Recipe[Surrounding_space[r]].name << " and " << surrounding_recipe_name << '\n' << end(); + trace(9993, "name") << "lexically surrounding space for recipe " << get(Recipe, r).name << " comes from " << surrounding_recipe_name << end(); +//? cerr << "lexically surrounding space for recipe " << get(Recipe, r).name << " comes from " << surrounding_recipe_name << '\n'; + if (!contains_key(Recipe_ordinal, surrounding_recipe_name)) { + raise << "can't find recipe providing surrounding space for " << get(Recipe, r).name << ": " << surrounding_recipe_name << '\n' << end(); continue; } - trace("name") << "recipe " << Recipe[r].name << " is surrounded by " << surrounding_recipe_name << end(); - Surrounding_space[r] = Recipe_ordinal[surrounding_recipe_name]; + Surrounding_space[r] = get(Recipe_ordinal, surrounding_recipe_name); } } } @@ -110,12 +122,12 @@ void collect_surrounding_spaces(const recipe_ordi :(replace{} "long long int lookup_name(const reagent& r, const recipe_ordinal default_recipe)") long long int lookup_name(const reagent& x, const recipe_ordinal default_recipe) { if (!has_property(x, "space")) { - if (Name[default_recipe].empty()) raise << "name not found: " << x.name << '\n' << end(); + if (Name[default_recipe].empty()) raise_error << "name not found: " << x.name << '\n' << end(); return Name[default_recipe][x.name]; } - vector<string> p = property(x, "space"); - if (SIZE(p) != 1) raise << "/space property should have exactly one (non-negative integer) value\n" << end(); - long long int n = to_integer(p.at(0)); + string_tree* p = property(x, "space"); + if (!p || p->right) raise_error << "/space property should have exactly one (non-negative integer) value\n" << end(); + long long int n = to_integer(p->value); assert(n >= 0); recipe_ordinal surrounding_recipe = lookup_surrounding_recipe(default_recipe, n); set<recipe_ordinal> done; @@ -127,12 +139,12 @@ long long int lookup_name(const reagent& x// recursively call transform_names on it. long long int lookup_name(const reagent& x, const recipe_ordinal r, set<recipe_ordinal>& done, vector<recipe_ordinal>& path) { if (!Name[r].empty()) return Name[r][x.name]; - if (done.find(r) != done.end()) { - raise << "can't compute address of " << x.to_string() << " because " << end(); + if (contains_key(done, r)) { + raise_error << "can't compute address of " << x.to_string() << " because " << end(); for (long long int i = 1; i < SIZE(path); ++i) { - raise << path.at(i-1) << " requires computing names of " << path.at(i) << '\n' << end(); + raise_error << path.at(i-1) << " requires computing names of " << path.at(i) << '\n' << end(); } - raise << path.at(SIZE(path)-1) << " requires computing names of " << r << "..ad infinitum\n" << end(); + raise_error << path.at(SIZE(path)-1) << " requires computing names of " << r << "..ad infinitum\n" << end(); return 0; } done.insert(r); @@ -144,26 +156,26 @@ long long int lookup_name(const reagent& x(const recipe_ordinal r, long long int n) { if (n == 0) return r; - if (Surrounding_space.find(r) == Surrounding_space.end()) { - raise << "don't know surrounding recipe of " << Recipe[r].name << '\n' << end(); + if (!contains_key(Surrounding_space, r)) { + raise_error << "don't know surrounding recipe of " << get(Recipe, r).name << '\n' << end(); return 0; } assert(Surrounding_space[r]); return lookup_surrounding_recipe(Surrounding_space[r], n-1); } -//: weaken use-before-set warnings just a tad +//: weaken use-before-set detection just a tad :(replace{} "bool already_transformed(const reagent& r, const map<string, long long int>& names)") bool already_transformed(const reagent& r, const map<string, long long int>& names) { if (has_property(r, "space")) { - vector<string> p = property(r, "space"); - if (SIZE(p) != 1) { - raise << "/space property should have exactly one (non-negative integer) value in " << r.original_string << '\n' << end(); + string_tree* p = property(r, "space"); + if (!p || p->right) { + raise_error << "/space property should have exactly one (non-negative integer) value in " << r.original_string << '\n' << end(); return false; } - if (p.at(0) != "0") return true; + if (p->value != "0") return true; } - return names.find(r.name) != names.end(); + return contains_key(names, r.name); } -- cgit 1.4.1-2-gfad0