From 65361948ca7975553757a0e0df4ac7352413044c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 14 May 2015 16:04:45 -0700 Subject: 1376 - update github docs --- html/041name.cc.html | 197 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 127 insertions(+), 70 deletions(-) (limited to 'html/041name.cc.html') diff --git a/html/041name.cc.html b/html/041name.cc.html index 6734c604..18fbd523 100644 --- a/html/041name.cc.html +++ b/html/041name.cc.html @@ -2,7 +2,7 @@ -Mu - 041name.cc +~/Desktop/s/mu/041name.cc @@ -14,15 +14,15 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } -.Identifier { color: #008080; } -.SalientComment { color: #00ffff; } +.CommentedCode { color: #6c6c6c; } +.traceAbsent { color: #c00000; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } -.CommentedCode { color: #6c6c6c; } +.Identifier { color: #008080; } +.SalientComment { color: #00ffff; } .traceContains { color: #008000; } -.traceAbsent { color: #c00000; } --> @@ -40,7 +40,7 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } :(scenario convert_names) recipe main [ - x:integer <- copy 0:literal + x:number <- copy 0:literal ] +name: assign x 1 +run: instruction main/0 @@ -49,7 +49,7 @@ recipe main [ :(scenario convert_names_warns) % Hide_warnings = true; recipe main [ - x:integer <- copy y:integer + x:number <- copy y:number ] +warn: use before set: y in main @@ -60,62 +60,57 @@ recipe main [ map<recipe_number, map<string, index_t> > Name; :(after "Clear Other State For recently_added_recipes") for (index_t i = 0; i < recently_added_recipes.size(); ++i) { - Name.erase(recently_added_recipes[i]); + Name.erase(recently_added_recipes.at(i)); } :(code) void transform_names(const recipe_number r) { + bool names_used = false; + bool numeric_locations_used = false; map<string, index_t>& names = Name[r]; // store the indices 'used' so far in the map index_t& curr_idx = names[""]; ++curr_idx; // avoid using index 0, benign skip in some other cases -//? cout << "Recipe " << r << ": " << Recipe[r].name << '\n'; //? 3 -//? cout << Recipe[r].steps.size() << '\n'; //? 2 for (index_t i = 0; i < Recipe[r].steps.size(); ++i) { -//? cout << "instruction " << i << '\n'; //? 2 - instruction& inst = Recipe[r].steps[i]; + instruction& inst = Recipe[r].steps.at(i); // Per-recipe Transforms // map names to addresses for (index_t in = 0; in < inst.ingredients.size(); ++in) { -//? cout << "ingredients\n"; //? 2 - if (is_raw(inst.ingredients[in])) continue; -//? cout << "ingredient " << inst.ingredients[in].name << '\n'; //? 3 -//? cout << "ingredient " << inst.ingredients[in].to_string() << '\n'; //? 1 - if (inst.ingredients[in].name == "default-space") - inst.ingredients[in].initialized = true; - if (inst.ingredients[in].types.empty()) - raise << "missing type in " << inst.to_string() << '\n'; - assert(!inst.ingredients[in].types.empty()); - if (inst.ingredients[in].types[0] // not a literal - && !inst.ingredients[in].initialized - && !is_number(inst.ingredients[in].name)) { - if (!already_transformed(inst.ingredients[in], names)) { - raise << "use before set: " << inst.ingredients[in].name << " in " << Recipe[r].name << '\n'; - } - inst.ingredients[in].set_value(lookup_name(inst.ingredients[in], r)); -//? cout << "lookup ingredient " << Recipe[r].name << "/" << i << ": " << inst.ingredients[in].to_string() << '\n'; //? 1 + 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))) continue; + if (!already_transformed(inst.ingredients.at(in), names)) { + raise << "use before set: " << inst.ingredients.at(in).name << " in " << Recipe[r].name << '\n'; } + inst.ingredients.at(in).set_value(lookup_name(inst.ingredients.at(in), r)); } for (index_t out = 0; out < inst.products.size(); ++out) { -//? cout << "products\n"; //? 1 - if (is_raw(inst.products[out])) continue; -//? cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 4 -//? cout << inst.products[out].types[0] << '\n'; //? 1 - if (inst.products[out].name == "default-space") - inst.products[out].initialized = true; - if (inst.products[out].types[0] // not a literal - && !inst.products[out].initialized - && !is_number(inst.products[out].name)) { - if (names.find(inst.products[out].name) == names.end()) { - trace("name") << "assign " << inst.products[out].name << " " << curr_idx; - names[inst.products[out].name] = curr_idx; - curr_idx += size_of(inst.products[out]); - } - inst.products[out].set_value(lookup_name(inst.products[out], r)); -//? cout << "lookup product " << Recipe[r].name << "/" << i << ": " << inst.products[out].to_string() << '\n'; //? 1 + 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))) continue; + if (names.find(inst.products.at(out).name) == names.end()) { + trace("name") << "assign " << inst.products.at(out).name << " " << curr_idx; + names[inst.products.at(out).name] = curr_idx; + curr_idx += size_of(inst.products.at(out)); } + inst.products.at(out).set_value(lookup_name(inst.products.at(out), r)); } } + if (names_used && numeric_locations_used) + raise << "mixing variable names and numeric addresses in " << Recipe[r].name << '\n'; +} + +bool disqualified(/*mutable*/ reagent& x) { + if (x.types.empty()) + raise << "missing type in " << x.to_string() << '\n'; + assert(!x.types.empty()); + if (is_raw(x)) return true; + if (isa_literal(x)) return true; + if (is_number(x.name)) return true; + if (x.name == "default-space") + x.initialized = true; + if (x.initialized) return true; + return false; } bool already_transformed(const reagent& r, const map<string, index_t>& names) { @@ -128,7 +123,7 @@ index_t lookup_name(const reagent& r(const vector<type_number>& types) { for (index_t i = 0; i < types.size(); ++i) { - if (types[i] != Type_number["address"]) return types[i]; + if (types.at(i) != Type_number["address"]) return types.at(i); } raise << "expected a container" << '\n' << die(); return -1; @@ -138,23 +133,48 @@ int find_element_name(const type_number t; //? cout << "looking for element " << name << " in type " << container.name << " with " << container.element_names.size() << " elements\n"; //? 1 for (index_t i = 0; i < container.element_names.size(); ++i) { - if (container.element_names[i] == name) return i; + if (container.element_names.at(i) == name) return i; } raise << "unknown element " << name << " in container " << t << '\n' << die(); return -1; } +bool is_numeric_location(const reagent& x) { + if (isa_literal(x)) return false; + if (is_raw(x)) return false; + if (x.name == "0") return false; // used for chaining lexical scopes + return is_number(x.name); +} + +bool is_named_location(const reagent& x) { + if (isa_literal(x)) return false; + if (is_raw(x)) return false; + if (is_special_name(x.name)) return false; + return !is_number(x.name); +} + bool is_raw(const reagent& r) { for (index_t i = /*skip value+type*/1; i < r.properties.size(); ++i) { - if (r.properties[i].first == "raw") return true; + if (r.properties.at(i).first == "raw") return true; } return false; } +bool is_special_name(const string& s) { + if (s == "_") return true; + // lexical scopes + if (s == "default-space") return true; + if (s == "0") return true; + // tests will use these in later layers even though tests will mostly use numeric addresses + if (s == "screen") return true; + if (s == "keyboard") return true; + return false; +} + :(scenario convert_names_passes_dummy) # _ is just a dummy result that never gets consumed recipe main [ - _, x:integer <- copy 0:literal + _, x:number <- copy 0:literal, 1:literal ] +name: assign x 1 -name: assign _ 1 @@ -162,7 +182,7 @@ recipe main [ //: one reserved word that we'll need later :(scenario convert_names_passes_default_space) recipe main [ - default-space:integer, x:integer <- copy 0:literal + default-space:number, x:number <- copy 0:literal, 1:literal ] +name: assign x 1 -name: assign default-space 1 @@ -170,10 +190,46 @@ recipe main [ //: an escape hatch to suppress name conversion that we'll use later :(scenario convert_names_passes_raw) recipe main [ - x:integer/raw <- copy 0:literal + x:number/raw <- copy 0:literal ] -name: assign x 1 +:(scenario convert_names_warns_when_mixing_names_and_numeric_locations) +% Hide_warnings = true; +recipe main [ + x:number <- copy 1:number +] ++warn: mixing variable names and numeric addresses in main + +:(scenario convert_names_warns_when_mixing_names_and_numeric_locations2) +% Hide_warnings = true; +recipe main [ + x:number <- copy 1:literal + 1:number <- copy x:number +] ++warn: mixing variable names and numeric addresses in main + +:(scenario convert_names_does_not_warn_when_mixing_names_and_raw_locations) +% Hide_warnings = true; +recipe main [ + x:number <- copy 1:number/raw +] +-warn: mixing variable names and numeric addresses in main + +:(scenario convert_names_does_not_warn_when_mixing_names_and_literals) +% Hide_warnings = true; +recipe main [ + x:number <- copy 1:literal +] +-warn: mixing variable names and numeric addresses in main + +:(scenario convert_names_does_not_warn_when_mixing_special_names_and_numeric_locations) +% Hide_warnings = true; +recipe main [ + screen:number <- copy 1:number +] +-warn: mixing variable names and numeric addresses in main + //:: Support element names for containers in 'get' and 'get-address'. //: update our running example container for the next test @@ -182,8 +238,9 @@ Type[point].element_names Type[point].element_names.push_back("y"); :(scenario convert_names_transforms_container_elements) recipe main [ - a:integer <- get 0:point, y:offset - b:integer <- get 0:point, x:offset + p:address:point <- copy 0:literal # unsafe + a:number <- get p:address:point/deref, y:offset + b:number <- get p:address:point/deref, x:offset ] +name: element y of type point is at offset 1 +name: element x of type point is at offset 0 @@ -194,13 +251,13 @@ if (inst.operation || inst.operation == Recipe_number["get-address"]) { // at least 2 args, and second arg is offset assert(inst.ingredients.size() >= 2); -//? cout << inst.ingredients[1].to_string() << '\n'; //? 1 - assert(isa_literal(inst.ingredients[1])); - if (inst.ingredients[1].name.find_first_not_of("0123456789") == string::npos) continue; +//? cout << inst.ingredients.at(1).to_string() << '\n'; //? 1 + assert(isa_literal(inst.ingredients.at(1))); + if (inst.ingredients.at(1).name.find_first_not_of("0123456789") == string::npos) continue; // since first non-address in base type must be a container, we don't have to canonize - type_number base_type = skip_addresses(inst.ingredients[0].types); - inst.ingredients[1].set_value(find_element_name(base_type, inst.ingredients[1].name)); - trace("name") << "element " << inst.ingredients[1].name << " of type " << Type[base_type].name << " is at offset " << inst.ingredients[1].value; + type_number 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)); + trace("name") << "element " << inst.ingredients.at(1).name << " of type " << Type[base_type].name << " is at offset " << inst.ingredients.at(1).value; } //: this test is actually illegal so can't call run @@ -208,7 +265,7 @@ if (inst.operation :(scenario convert_names_handles_containers) recipe main [ a:point <- copy 0:literal - b:integer <- copy 0:literal + b:number <- copy 0:literal ] +name: assign a 1 +name: assign b 3 @@ -218,12 +275,12 @@ recipe main [ :(scenarios run) :(scenario maybe_convert_named) recipe main [ - 12:integer <- copy 1:literal - 13:integer <- copy 35:literal - 14:integer <- copy 36:literal - 20:address:point <- maybe-convert 12:integer-or-point, p:variant + 12:number <- copy 1:literal + 13:number <- copy 35:literal + 14:number <- copy 36:literal + 20:address:point <- maybe-convert 12:number-or-point, p:variant ] -+name: variant p of type integer-or-point has tag 1 ++name: variant p of type number-or-point has tag 1 +mem: storing 13 in location 20 :(after "Per-recipe Transforms") @@ -231,12 +288,12 @@ recipe main [ if (inst.operation == Recipe_number["maybe-convert"]) { // at least 2 args, and second arg is offset assert(inst.ingredients.size() >= 2); - assert(isa_literal(inst.ingredients[1])); - if (inst.ingredients[1].name.find_first_not_of("0123456789") == string::npos) continue; + assert(isa_literal(inst.ingredients.at(1))); + if (inst.ingredients.at(1).name.find_first_not_of("0123456789") == string::npos) continue; // since first non-address in base type must be an exclusive container, we don't have to canonize - type_number base_type = skip_addresses(inst.ingredients[0].types); - inst.ingredients[1].set_value(find_element_name(base_type, inst.ingredients[1].name)); - trace("name") << "variant " << inst.ingredients[1].name << " of type " << Type[base_type].name << " has tag " << inst.ingredients[1].value; + type_number 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)); + trace("name") << "variant " << inst.ingredients.at(1).name << " of type " << Type[base_type].name << " has tag " << inst.ingredients.at(1).value; } -- cgit 1.4.1-2-gfad0