From 90560d7194f3e451ddab9d4033c98d2e6aec977b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 23 Aug 2015 10:19:23 -0700 Subject: 2062 --- html/042name.cc.html | 147 +++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 74 deletions(-) (limited to 'html/042name.cc.html') diff --git a/html/042name.cc.html b/html/042name.cc.html index d4567520..c0f0a2cf 100644 --- a/html/042name.cc.html +++ b/html/042name.cc.html @@ -13,17 +13,16 @@ 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; } -.Constant { color: #00a0a0; } .cSpecial { color: #008000; } .SalientComment { color: #00ffff; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.traceAbsent { color: #c00000; } +.CommentedCode { color: #6c6c6c; } +.Constant { color: #00a0a0; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.CommentedCode { color: #6c6c6c; } +.traceContains { color: #008000; } --> @@ -41,7 +40,7 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } :(scenario transform_names) recipe main [ - x:number <- copy 0 + x:number <- copy 0 ] +name: assign x 1 +mem: storing 0 in location 1 @@ -50,7 +49,7 @@ recipe main [ :(scenario transform_names_warns) % Hide_warnings = true; recipe main [ - x:number <- copy y:number + x:number <- copy y:number ] +warn: use before set: y in main @@ -58,38 +57,38 @@ recipe main [ Transform.push_back(transform_names); :(before "End Globals") -map<recipe_ordinal, map<string, long long int> > Name; +map<recipe_ordinal, map<string, long long int> > Name; :(after "Clear Other State For recently_added_recipes") -for (long long int i = 0; i < SIZE(recently_added_recipes); ++i) { +for (long long int i = 0; i < SIZE(recently_added_recipes); ++i) { Name.erase(recently_added_recipes.at(i)); } :(code) -void transform_names(const recipe_ordinal r) { - bool names_used = false; - bool numeric_locations_used = false; - map<string, long long int>& names = Name[r]; +void transform_names(const recipe_ordinal r) { + bool names_used = false; + bool numeric_locations_used = false; + map<string, long long int>& names = Name[r]; // store the indices 'used' so far in the map - long long int& curr_idx = names[""]; + long long int& curr_idx = names[""]; ++curr_idx; // avoid using index 0, benign skip in some other cases - for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) { + for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) { instruction& inst = Recipe[r].steps.at(i); // Per-recipe Transforms // map names to addresses - for (long long int in = 0; in < SIZE(inst.ingredients); ++in) { - if (is_numeric_location(inst.ingredients.at(in))) numeric_locations_used = true; - if (is_named_location(inst.ingredients.at(in))) names_used = true; - if (disqualified(inst.ingredients.at(in), inst)) continue; - if (!already_transformed(inst.ingredients.at(in), names)) { + for (long long int in = 0; in < SIZE(inst.ingredients); ++in) { + if (is_numeric_location(inst.ingredients.at(in))) numeric_locations_used = true; + if (is_named_location(inst.ingredients.at(in))) names_used = true; + if (disqualified(inst.ingredients.at(in), inst)) continue; + if (!already_transformed(inst.ingredients.at(in), names)) { raise << "use before set: " << inst.ingredients.at(in).name << " in " << Recipe[r].name << '\n' << end(); } inst.ingredients.at(in).set_value(lookup_name(inst.ingredients.at(in), r)); } - for (long long int out = 0; out < SIZE(inst.products); ++out) { - if (is_numeric_location(inst.products.at(out))) numeric_locations_used = true; - if (is_named_location(inst.products.at(out))) names_used = true; - if (disqualified(inst.products.at(out), inst)) continue; - if (names.find(inst.products.at(out).name) == names.end()) { + for (long long int out = 0; out < SIZE(inst.products); ++out) { + if (is_numeric_location(inst.products.at(out))) numeric_locations_used = true; + if (is_named_location(inst.products.at(out))) names_used = true; + if (disqualified(inst.products.at(out), inst)) continue; + if (names.find(inst.products.at(out).name) == names.end()) { trace("name") << "assign " << inst.products.at(out).name << " " << curr_idx << end(); names[inst.products.at(out).name] = curr_idx; curr_idx += size_of(inst.products.at(out)); @@ -97,74 +96,74 @@ map<recipe_ordinal, map<string.products.at(out).set_value(lookup_name(inst.products.at(out), r)); } } - if (names_used && numeric_locations_used && r != Recipe_ordinal["interactive"]) + if (names_used && numeric_locations_used) raise << "mixing variable names and numeric addresses in " << Recipe[r].name << '\n' << end(); } -bool disqualified(/*mutable*/ reagent& x, const instruction& inst) { +bool disqualified(/*mutable*/ reagent& x, const instruction& inst) { //? cerr << x.to_string() << '\n'; //? 1 - if (x.types.empty()) { + if (x.types.empty()) { raise << "missing type in '" << inst.to_string() << "'\n" << end(); return true; } - if (is_raw(x)) return true; - if (is_literal(x)) return true; - if (is_integer(x.name)) return true; + if (is_raw(x)) return true; + if (is_literal(x)) return true; + if (is_integer(x.name)) return true; // End Disqualified Reagents - if (x.initialized) return true; + if (x.initialized) return true; return false; } -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) { return names.find(r.name) != names.end(); } -long long int lookup_name(const reagent& r, const recipe_ordinal default_recipe) { +long long int lookup_name(const reagent& r, const recipe_ordinal default_recipe) { return Name[default_recipe][r.name]; } -type_ordinal skip_addresses(const vector<type_ordinal>& types) { - for (long long int i = 0; i < SIZE(types); ++i) { - if (types.at(i) != Type_ordinal["address"]) return types.at(i); +type_ordinal skip_addresses(const vector<type_ordinal>& types) { + for (long long int i = 0; i < SIZE(types); ++i) { + if (types.at(i) != Type_ordinal["address"]) return types.at(i); } raise << "expected a container" << '\n' << end(); return -1; } -int find_element_name(const type_ordinal t, const string& name) { - const type_info& container = Type[t]; +int find_element_name(const type_ordinal t, const string& name) { + const type_info& container = Type[t]; //? cout << "looking for element " << name << " in type " << container.name << " with " << SIZE(container.element_names) << " elements\n"; //? 1 - for (long long int i = 0; i < SIZE(container.element_names); ++i) { - if (container.element_names.at(i) == name) return i; + for (long long int i = 0; i < SIZE(container.element_names); ++i) { + if (container.element_names.at(i) == name) return i; } raise << "unknown element " << name << " in container " << Type[t].name << '\n' << end(); return -1; } -bool is_numeric_location(const reagent& x) { - if (is_literal(x)) return false; - if (is_raw(x)) return false; - if (x.name == "0") return false; // used for chaining lexical scopes +bool is_numeric_location(const reagent& x) { + if (is_literal(x)) return false; + if (is_raw(x)) return false; + if (x.name == "0") return false; // used for chaining lexical scopes return is_integer(x.name); } -bool is_named_location(const reagent& x) { - if (is_literal(x)) return false; - if (is_raw(x)) return false; - if (is_special_name(x.name)) return false; +bool is_named_location(const reagent& x) { + if (is_literal(x)) return false; + if (is_raw(x)) return false; + if (is_special_name(x.name)) return false; return !is_integer(x.name); } -bool is_raw(const reagent& r) { - for (long long int i = /*skip value+type*/1; i < SIZE(r.properties); ++i) { - if (r.properties.at(i).first == "raw") return true; +bool is_raw(const reagent& r) { + for (long long int i = /*skip value+type*/1; i < SIZE(r.properties); ++i) { + if (r.properties.at(i).first == "raw") return true; } return false; } -bool is_special_name(const string& s) { - if (s == "_") return true; - if (s == "0") return true; +bool is_special_name(const string& s) { + if (s == "_") return true; + if (s == "0") return true; // End is_special_name Cases return false; } @@ -182,7 +181,7 @@ recipe main [ :(scenario transform_names_passes_raw) % Hide_warnings = true; recipe main [ - x:number/raw <- copy 0 + x:number/raw <- copy 0 ] -name: assign x 1 +warn: can't write to location 0 in 'x:number/raw <- copy 0' @@ -191,14 +190,14 @@ recipe main [ :(scenario transform_names_warns_when_mixing_names_and_numeric_locations) % Hide_warnings = true; recipe main [ - x:number <- copy 1:number + x:number <- copy 1:number ] +warn: mixing variable names and numeric addresses in main -:(scenario transform_names_warns_when_mixing_names_and_numeric_locations2) +:(scenario transform_names_warns_when_mixing_names_and_numeric_locations_2) % Hide_warnings = true; recipe main [ - x:number <- copy 1 + x:number <- copy 1 1:number <- copy x:number ] +warn: mixing variable names and numeric addresses in main @@ -206,7 +205,7 @@ recipe main [ :(scenario transform_names_does_not_warn_when_mixing_names_and_raw_locations) % Hide_warnings = true; recipe main [ - x:number <- copy 1:number/raw + x:number <- copy 1:number/raw ] -warn: mixing variable names and numeric addresses in main $warn: 0 @@ -214,7 +213,7 @@ $warn: 0 :(scenario transform_names_does_not_warn_when_mixing_names_and_literals) % Hide_warnings = true; recipe main [ - x:number <- copy 1 + x:number <- copy 1 ] -warn: mixing variable names and numeric addresses in main $warn: 0 @@ -227,24 +226,24 @@ Type[point].element_names Type[point].element_names.push_back("y"); :(scenario transform_names_transforms_container_elements) recipe main [ - p:address:point <- copy 0 # unsafe - a:number <- get *p:address:point, y:offset - b:number <- get *p:address:point, x:offset + p:address:point <- copy 0 # unsafe + a:number <- get *p:address:point, y:offset + b:number <- get *p:address:point, x:offset ] +name: element y of type point is at offset 1 +name: element x of type point is at offset 0 :(after "Per-recipe Transforms") // replace element names of containers with offsets -if (inst.operation == Recipe_ordinal["get"] +if (inst.operation == Recipe_ordinal["get"] || inst.operation == Recipe_ordinal["get-address"]) { - if (SIZE(inst.ingredients) != 2) { + if (SIZE(inst.ingredients) != 2) { raise << Recipe[r].name << ": exactly 2 ingredients expected in '" << inst.to_string() << "'\n" << end(); break; } - if (!is_literal(inst.ingredients.at(1))) + if (!is_literal(inst.ingredients.at(1))) raise << Recipe[r].name << ": expected ingredient 1 of " << (inst.operation == Recipe_ordinal["get"] ? "'get'" : "'get-address'") << " to have type 'offset'; got " << inst.ingredients.at(1).original_string << '\n' << end(); - if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { + if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { // since first non-address in base type must be a container, we don't have to canonize type_ordinal base_type = skip_addresses(inst.ingredients.at(0).types); inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name)); @@ -256,8 +255,8 @@ recipe main [ :(scenarios transform) :(scenario transform_names_handles_containers) recipe main [ - a:point <- copy 0 - b:number <- copy 0 + a:point <- copy 0 + b:number <- copy 0 ] +name: assign a 1 +name: assign b 3 @@ -270,20 +269,20 @@ recipe main [ 12:number <- copy 1 13:number <- copy 35 14:number <- copy 36 - 20:address:point <- maybe-convert 12:number-or-point/raw, p:variant # unsafe + 20:address:point <- maybe-convert 12:number-or-point/raw, p:variant # unsafe ] +name: variant p of type number-or-point has tag 1 +mem: storing 13 in location 20 :(after "Per-recipe Transforms") // convert variant names of exclusive containers -if (inst.operation == Recipe_ordinal["maybe-convert"]) { - if (SIZE(inst.ingredients) != 2) { +if (inst.operation == Recipe_ordinal["maybe-convert"]) { + if (SIZE(inst.ingredients) != 2) { raise << Recipe[r].name << ": exactly 2 ingredients expected in '" << current_instruction().to_string() << "'\n" << end(); break; } assert(is_literal(inst.ingredients.at(1))); - if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { + if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { // since first non-address in base type must be an exclusive container, we don't have to canonize type_ordinal base_type = skip_addresses(inst.ingredients.at(0).types); inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name)); -- cgit 1.4.1-2-gfad0