//:: Container definitions can contain 'type ingredients' //: pre-requisite: extend our notion of containers to not necessarily be //: atomic types :(before "End is_mu_container(type) Special-cases") if (!type->atom) return is_mu_container(get_base_type(type)); :(before "End is_mu_exclusive_container(type) Special-cases") if (!type->atom) return is_mu_exclusive_container(get_base_type(type)); :(after "Update GET base_type in Check") base_type = get_base_type(base_type); :(after "Update GET base_type in Run") base_type = get_base_type(base_type); :(after "Update PUT base_type in Check") base_type = get_base_type(base_type); :(after "Update PUT base_type in Run") base_type = get_base_type(base_type); :(after "Update MAYBE_CONVERT base_type in Check") base_type = get_base_type(base_type); :(after "Update base_type in size_of(type)") base_type = get_base_type(base_type); :(after "Update base_type in element_type") base_type = get_base_type(base_type); :(after "Update base_type in compute_container_address_offsets") base_type = get_base_type(base_type); :(after "Update base_type in append_container_address_offsets") base_type = get_base_type(base_type); :(after "Update element_base_type For Exclusive Container in append_addresses") element_base_type = get_base_type(element_base_type); :(after "Update base_type in skip_addresses") base_type = get_base_type(base_type); :(replace{} "const type_tree* get_base_type(const type_tree* t)") const type_tree* get_base_type(const type_tree* t) { const type_tree* result = t->atom ? t : t->left; if (!result->atom) raise << "invalid type " << to_string(t) << '\n' << end(); return result; } :(scenario ill_formed_container) % Hide_errors = true; def main [ {1: ((foo) num)} <- copy 0 ] # no crash :(scenario size_of_shape_shifting_container) container foo:_t [ x:_t y:num ] def main [ 1:foo:num <- merge 12, 13 3:foo:point <- merge 14, 15, 16 ] +mem: storing 12 in location 1 +mem: storing 13 in location 2 +mem: storing 14 in location 3 +mem: storing 15 in location 4 +mem: storing 16 in location 5 :(scenario size_of_shape_shifting_container_2) # multiple type ingredients container foo:_a:_b [ x:_a y:_b ] def main [ 1:foo:num:bool <- merge 34, 1/true ] $error: 0 :(scenario size_of_shape_shifting_container_3) container foo:_a:_b [ x:_a y:_b ] def main [ 1:text <- new [abc] # compound types for type ingredients {2: (foo number (address array character))} <- merge 34/x, 1:text/y ] $error: 0 :(scenario size_of_shape_shifting_container_4) container foo:_a:_b [ x:_a y:_b ] container bar:_a:_b [ # dilated element {data: (foo _a (address _b))} ] def main [ 1:text <- new [abc] 2:bar:num:@:char <- merge 34/x, 1:text/y ] $error: 0 :(scenario shape_shifting_container_extend) container foo:_a [ x:_a ] container foo:_a [ y:_a ] $error: 0 :(scenario shape_shifting_container_extend_error) % Hide_errors = true; container foo:_a [ x:_a ] container foo:_b [ y:_b ] +error: headers of container 'foo' must use identical type ingredients :(scenario type_ingredient_must_start_with_underscore) % Hide_errors = true; container foo:t [ x:num ] +error: foo: type ingredient 't' must begin with an underscore :(before "End Globals") // We'll use large type ordinals to mean "the following type of the variable". // For example, if we have a generic type called foo:_elem, the type // ingredient _elem in foo's type_info will have value START_TYPE_INGREDIENTS, // and we'll handle it by looking in the current reagent for the next type // that appears after foo. extern const int START_TYPE_INGREDIENTS = 2000; :(before "End Commandline Parsing") // after loading .mu files assert(Next_type_ordinal < START_TYPE_INGREDIENTS); :(before "End type_info Fields") map type_ingredient_names; //: Suppress unknown type checks in shape-shifting containers. :(before "Check Container Field Types(info)") if (!info.type_ingredient_names.empty()) continue; :(before "End container Name Refinements") if (name.find(':') != string::npos) { trace("parse") << "container has type ingredients; parsing" << end(); if (!read_type_ingredients(name, command)) { // error; skip rest of the container definition and continue slurp_balanced_bracket(in); return; } } :(code) bool read_type_ingredients(string& name, const string& command) { string save_name = name; istringstream in(save_name); name = slurp_until(in, ':'); map type_ingredient_names; if (!slurp_type_ingredients(in, type_ingredient_names, name)) { return false; } if (contains_key(Type_ordinal, name) && contains_key(Type, get(Type_ordinal, name))) { const type_info& previous_info = get(Type, get(Type_ordinal, name)); // we've already seen this container; make sure type ingredients match if (!type_ingredients_match(type_ingredient_names, previous_info.type_ingredient_names)) { raise << "headers of " << command << " '" << name << "' must use identical type ingredients\n" << end(); return false; } return true; } // we haven't seen this container before if (!contains_key(Type_ordinal, name) || get(Type_ordinal, name) == 0) put(Type_ordinal, name, Next_type_ordinal++); type_info& info = get_or_insert(Type, get(Type_ordinal, name)); info.type_ingredient_names.swap(type_ingredient_names); return true; } bool slurp_type_ingredients(istream& in, map& out, const string& container_name) { int next_type_ordinal = START_TYPE_INGREDIENTS; while (has_data(in)) { string curr = slurp_until(in, ':'); if (curr.empty()) { raise << container_name << ": empty type ingredients not permitted\n" << end(); return false; } if (!starts_with(curr, "_")) { raise << container_name << ": type ingredient '" << curr << "' must begin with an underscore\n" << end(); return false; } if (out.find(curr) != out.end()) { raise << container_name << ": can't repeat type ingredient name'" << curr << "' in a single container definition\n" << end(); return false; } put(out, curr, next_type_ordinal++); } return true; } bool type_ingredients_match(const map& a, const map& b) { if (SIZE(a) != SIZE(b)) return false; for (map::const_iterator p = a.begin(); p != a.end(); ++p) { if (!contains_key(b, p->first)) return false; if (p->second != get(b, p->first)) return false; } return true; } :(before "End insert_container Special-cases") // check for use of type ingredients else if (is_type_ingredient_name(type->name)) { type->value = get(info.type_ingredient_names, type->name); } :(code) bool is_type_ingredient_name(const string& type) { return starts_with(type, "_"); } :(before "End Container Type Checks") if (type->value >= START_TYPE_INGREDIENTS && (type->value - START_TYPE_INGREDIENTS) < SIZE(get(Type, type->value).type_ingredient_names)) return; :(scenario size_of_shape_shifting_exclusive_container) exclusive-container foo:_t [ x:_t y:num ] def main [ 1:foo:num <- merge 0/x, 34 3:foo:point <- merge 0/x, 15, 16 6:foo:point <- merge 1/y, 23 ] +run: {1: ("foo" "number")} <- merge {0: "literal", "x": ()}, {34: "literal"} +mem: storing 0 in location 1 +mem: storing 34 in location 2 +run: {3: ("foo" "point")} <- merge {0: "literal", "x": ()}, {15: "literal"}, {16: "literal"} +mem: storing 0 in location 3 +mem: storing 15 in location 4 +mem: storing 16 in location 5 +run: {6: ("foo" "point")} <- merge {1: "literal", "y": ()}, {23: "literal"} +mem: storing 1 in location 6 +mem: storing 23 in location 7 +run: return # no other stores % CHECK_EQ(trace_count_prefix("mem", "storing"), 7); :(before "End variant_type Special-cases") if (contains_type_ingredient(element)) replace_type_ingredients(element.type, type->right, info, " while computing variant type of exclusive-container"); :(scenario get_o
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: package ranger.gui.widgets</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.gui.html"><font color="#ffffff">gui</font></a>.widgets</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/code/ranger/ranger/gui/widgets/__init__.py">/home/hut/code/ranger/ranger/gui/widgets/__init__.py</a></font></td></tr></table>
    <p><tt>#&nbsp;Copyright&nbsp;(C)&nbsp;2009,&nbsp;2010&nbsp;&nbsp;Roman&nbsp;Zimbelmann&nbsp;&lt;romanz@lavabit.com&gt;<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
#&nbsp;it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
#&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;either&nbsp;version&nbsp;3&nbsp;of&nbsp;the&nbsp;License,&nbsp;or<br>
#&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
#&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
#&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
#&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
#<br>
#&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License<br>
#&nbsp;along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see&nbsp;&lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.</tt></p