about summary refs log tree commit diff stats
path: root/html/035lookup.cc.html
Commit message (Expand)AuthorAgeFilesLines
* 4447Kartik Agaram2018-07-271-467/+517
* 4243Kartik Agaram2018-05-121-2/+2
* 4239Kartik Agaram2018-05-081-8/+8
* 4228Kartik K. Agaram2018-03-151-409/+426
* 4199Kartik K. Agaram2018-01-251-537/+466
* 4161Kartik K. Agaram2017-12-151-8/+8
* 4155Kartik K. Agaram2017-12-071-17/+17
* 4134 - 'input' = 'ingredient'Kartik K. Agaram2017-12-031-5/+5
* 4109Kartik K. Agaram2017-11-051-55/+55
* 4102Kartik K. Agaram2017-11-011-62/+62
* 4003Kartik K. Agaram2017-09-231-53/+53
* 3990Kartik K. Agaram2017-09-031-2/+2
* 3971Kartik K. Agaram2017-08-191-2/+2
* 3927Kartik K. Agaram2017-06-191-12/+12
* 3900Kartik K. Agaram2017-06-021-7/+7
* 3897 - various updates to documentationKartik K. Agaram2017-05-291-11/+11
* 3896Kartik K. Agaram2017-05-291-2/+2
* 3877Kartik K. Agaram2017-05-261-1/+1
* 3848Kartik K. Agaram2017-05-061-1/+1
* 3845Kartik K. Agaram2017-05-061-1/+1
* 3764 - better colors for cross-linksKartik K. Agaram2017-03-081-4/+5
* 3761Kartik K. Agaram2017-03-071-35/+36
* 3750Kartik K. Agaram2017-03-021-13/+13
* 3749Kartik K. Agaram2017-03-021-13/+13
* 3746Kartik K. Agaram2017-02-071-4/+4
* 3716Kartik K. Agaram2016-12-261-0/+2
* 3713 - cross-link calls with definitions in htmlKartik K. Agaram2016-12-261-105/+105
* 3710Kartik K. Agaram2016-12-261-540/+540
* 3709 - line numbers in htmlKartik K. Agaram2016-12-261-545/+569
* 3604Kartik K. Agaram2016-10-271-2/+18
* 3544Kartik K. Agaram2016-10-221-1/+1
* 3543Kartik K. Agaram2016-10-221-1/+1
* 3524Kartik K. Agaram2016-10-201-1/+1
* 3431Kartik K. Agaram2016-09-301-34/+35
* 3395Kartik K. Agaram2016-09-171-77/+77
* 3355Kartik K. Agaram2016-09-151-1/+1
* 3315Kartik K. Agaram2016-09-101-3/+5
* 3227Kartik K. Agaram2016-08-181-4/+0
* 3219Kartik K. Agaram2016-08-171-0/+2
* 3158Kartik K. Agaram2016-07-271-0/+44
* 3102Kartik K. Agaram2016-07-051-8/+12
* 2996Kartik K. Agaram2016-05-211-0/+516
s="n">new_type_name = next_word(in); assert(has_data(in) || !new_type_name.empty()); if (!has_data(in) || new_type_name.empty()) { raise << "incomplete 'type' statement; must be of the form 'type <new type name> = <type expression>'\n" << end(); return; } string arrow = next_word(in); assert(has_data(in) || !arrow.empty()); if (arrow.empty()) { raise << "incomplete 'type' statement 'type " << new_type_name << "'\n" << end(); return; } if (arrow != "=") { raise << "'type' statements must be of the form 'type <new type name> = <type expression>' but got 'type " << new_type_name << ' ' << arrow << "'\n" << end(); return; } if (!has_data(in)) { raise << "incomplete 'type' statement 'type " << new_type_name << " ='\n" << end(); return; } string old = next_word(in); if (old.empty()) { raise << "incomplete 'type' statement 'type " << new_type_name << " ='\n" << end(); raise << "'type' statements must be of the form 'type <new type name> = <type expression>' but got 'type " << new_type_name << ' ' << arrow << "'\n" << end(); return; } if (contains_key(Type_abbreviations, new_type_name)) { raise << "'type' conflict: '" << new_type_name << "' defined as both '" << names_to_string_without_quotes(get(Type_abbreviations, new_type_name)) << "' and '" << old << "'\n" << end(); return; } trace(9990, "type") << "alias " << new_type_name << " = " << old << end(); type_tree* old_type = new_type_tree(old); put(Type_abbreviations, new_type_name, old_type); } type_tree* new_type_tree(const string& x) { string_tree* type_names = starts_with(x, "(") ? parse_string_tree(x) : parse_string_list(x); type_tree* result = new_type_tree(type_names); delete type_names; expand_type_abbreviations(result); return result; } string_tree* parse_string_list(const string& s) { istringstream in(s); in >> std::noskipws; return parse_property_list(in); } :(scenario type_error1) % Hide_errors = true; type foo +error: incomplete 'type' statement 'type foo' :(scenario type_error2) % Hide_errors = true; type foo = +error: incomplete 'type' statement 'type foo =' :(scenario type_error3) % Hide_errors = true; type foo bar baz +error: 'type' statements must be of the form 'type <new type name> = <type expression>' but got 'type foo bar' :(scenario type_conflict_error) % Hide_errors = true; type foo = bar type foo = baz +error: 'type' conflict: 'foo' defined as both 'bar' and 'baz' :(scenario type_abbreviation_for_compound) type foo = address:number def main [ 1:foo <- copy null ] +transform: product type after expanding abbreviations: ("address" "number") //: cleaning up type abbreviations between tests and before exiting :(before "End save_snapshots") Type_abbreviations_snapshot = Type_abbreviations; :(before "End restore_snapshots") restore_type_abbreviations(); :(before "End One-time Setup") atexit(clear_type_abbreviations); :(code) void restore_type_abbreviations() { for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p) { if (!contains_key(Type_abbreviations_snapshot, p->first)) delete p->second; } Type_abbreviations.clear(); Type_abbreviations = Type_abbreviations_snapshot; } void clear_type_abbreviations() { for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p) delete p->second; Type_abbreviations.clear(); } //:: A few default abbreviations. :(before "End Mu Types Initialization") put(Type_abbreviations, "&", new_type_tree("address")); put(Type_abbreviations, "@", new_type_tree("array")); put(Type_abbreviations, "num", new_type_tree("number")); put(Type_abbreviations, "bool", new_type_tree("boolean")); put(Type_abbreviations, "char", new_type_tree("character")); :(scenario use_type_abbreviations_when_declaring_type_abbreviations) type foo = &:num def main [ 1:foo <- copy null ] +transform: product type after expanding abbreviations: ("address" "number") //:: Expand type aliases before running. //: We'll do this in a transform so that we don't need to define abbreviations //: before we use them. :(scenario abbreviations_for_address_and_array) def main [ f 1:&:num # abbreviation for 'address:number' f 2:@:num # abbreviation for 'array:number' f 3:&:@:num # combining '&' and '@' f 4:&:&:@:&:@:num # ..any number of times f {5: (array (& num) 3)} # support for dilated reagents and more complex parse trees ] def f [ ] +transform: --- expand type abbreviations in recipe 'main' +transform: ingredient type after expanding abbreviations: ("address" "number") +transform: ingredient type after expanding abbreviations: ("array" "number") +transform: ingredient type after expanding abbreviations: ("address" "array" "number") +transform: ingredient type after expanding abbreviations: ("address" "address" "array" "address" "array" "number") +transform: ingredient type after expanding abbreviations: ("array" ("address" "number") "3") :(before "Transform.push_back(update_instruction_operations)") Transform.push_back(expand_type_abbreviations); // idempotent // Begin Type Modifying Transforms // End Type Modifying Transforms :(code) void expand_type_abbreviations(const recipe_ordinal r) { expand_type_abbreviations(get(Recipe, r)); } void expand_type_abbreviations(const recipe& caller) { trace(9991, "transform") << "--- expand type abbreviations in recipe '" << caller.name << "'" << end(); for (int i = 0; i < SIZE(caller.steps); ++i) { const instruction& inst = caller.steps.at(i); trace(9991, "transform") << "instruction '" << to_original_string(inst) << end(); for (long int i = 0; i < SIZE(inst.ingredients); ++i) { expand_type_abbreviations(inst.ingredients.at(i).type); trace(9992, "transform") << "ingredient type after expanding abbreviations: " << names_to_string(inst.ingredients.at(i).type) << end(); } for (long int i = 0; i < SIZE(inst.products); ++i) { expand_type_abbreviations(inst.products.at(i).type); trace(9992, "transform") << "product type after expanding abbreviations: " << names_to_string(inst.products.at(i).type) << end(); } } // End Expand Type Abbreviations(caller) } void expand_type_abbreviations(type_tree* type) { if (!type) return; if (!type->atom) { expand_type_abbreviations(type->left); expand_type_abbreviations(type->right); return; } if (contains_key(Type_abbreviations, type->name)) *type = type_tree(*get(Type_abbreviations, type->name)); }