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/010vm.cc.html | 118 +++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 58 deletions(-) (limited to 'html/010vm.cc.html') diff --git a/html/010vm.cc.html b/html/010vm.cc.html index 48374903..45e698f0 100644 --- a/html/010vm.cc.html +++ b/html/010vm.cc.html @@ -13,15 +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; } -.SalientComment { color: #00ffff; } -.Constant { color: #00a0a0; } .cSpecial { color: #008000; } +.Identifier { color: #804000; } .PreProc { color: #c000c0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } +.SalientComment { color: #00ffff; } .CommentedCode { color: #6c6c6c; } -.Identifier { color: #804000; } +.Constant { color: #00a0a0; } --> @@ -46,12 +45,12 @@ recipe_ordinal Next_recipe_ordinal = 1//: adding two phone numbers is meaningless. Here each recipe does something //: incommensurable with any other recipe. :(after "Types") -typedef long long int recipe_ordinal; +typedef long long int recipe_ordinal; :(before "End Types") // Recipes are lists of instructions. To perform or 'run' a recipe, the // computer runs its instructions. -struct recipe { +struct recipe { string name; vector<instruction> steps; // End recipe Fields @@ -63,8 +62,8 @@ recipe_ordinal Next_recipe_ordinal = 1// or just a single 'label' starting with a non-alphanumeric character // +label // Labels don't do anything, they're just waypoints. -struct instruction { - bool is_label; +struct instruction { + bool is_label; string label; // only if is_label string name; // only if !is_label recipe_ordinal operation; // Recipe_ordinal[name] @@ -72,8 +71,8 @@ recipe_ordinal Next_recipe_ordinal = 1; // only if !is_label // End instruction Fields instruction(); - void clear(); - string to_string() const; + void clear(); + string to_string() const; }; :(before "struct instruction") @@ -81,27 +80,27 @@ recipe_ordinal Next_recipe_ordinal = 1// either to numbers or to locations in memory along with 'type' tags telling // us how to interpret them. They also can contain arbitrary other lists of // properties besides types, but we're getting ahead of ourselves. -struct reagent { +struct reagent { string original_string; vector<pair<string, vector<string> > > properties; string name; - double value; - bool initialized; + double value; + bool initialized; vector<type_ordinal> types; reagent(string s); reagent(); - void set_value(double v) { value = v; initialized = true; } - string to_string() const; + void set_value(double v) { value = v; initialized = true; } + string to_string() const; }; :(before "struct reagent") -struct property { +struct property { vector<string> values; }; :(before "End Globals") // Locations refer to a common 'memory'. Each location can store a number. -map<long long int, double> Memory; +map<long long int, double> Memory; :(before "End Setup") Memory.clear(); @@ -114,13 +113,13 @@ Memory.clear(); // Unlike most computers today, mu stores types in a single big table, shared // by all the mu programs on the computer. This is useful in providing a // seamless experience to help understand arbitrary mu programs. -typedef long long int type_ordinal; +typedef long long int type_ordinal; :(before "End Globals") map<string, type_ordinal> Type_ordinal; map<type_ordinal, type_info> Type; type_ordinal Next_type_ordinal = 1; :(code) -void setup_types() { +void setup_types() { Type.clear(); Type_ordinal.clear(); Type_ordinal["literal"] = 0; Next_type_ordinal = 1; @@ -154,23 +153,23 @@ setup_types(); // container, but if bank accounts may be either for individuals or groups, // with different properties for each, that may require an exclusive container // whose variants are individual-account and joint-account containers. -enum kind_of_type { +enum kind_of_type { primitive, container, exclusive_container }; -struct type_info { +struct type_info { string name; kind_of_type kind; - long long int size; // only if type is not primitive; primitives and addresses have size 1 (except arrays are dynamic) + long long int size; // only if type is not primitive; primitives and addresses have size 1 (except arrays are dynamic) vector<vector<type_ordinal> > elements; vector<string> element_names; // End type_info Fields type_info() :kind(primitive), size(0) {} }; -enum primitive_recipes { +enum primitive_recipes { IDLE = 0, COPY, // End Primitive Recipe Declarations @@ -181,7 +180,7 @@ setup_types(); //: to know how to do *something* out of the box. For the following //: recipes there are only codes, no entries in the book, because mu just knows //: what to do for them. -void setup_recipes() { +void setup_recipes() { Recipe.clear(); Recipe_ordinal.clear(); Recipe_ordinal["idle"] = IDLE; // Primitive Recipe Numbers @@ -196,6 +195,7 @@ setup_types(); setup_recipes(); assert(MAX_PRIMITIVE_RECIPES < 200); // level 0 is primitives; until 199 Next_recipe_ordinal = 200; +Recipe_ordinal["main"] = Next_recipe_ordinal++; // End Load Recipes :(before "End Test Run Initialization") assert(Next_recipe_ordinal < 1000); // recipes being tested didn't overflow into test space @@ -210,7 +210,7 @@ Next_recipe_ordinal = 1000 instruction::instruction() :is_label(false), operation(IDLE) { // End instruction Constructor } -void instruction::clear() { is_label=false; label.clear(); operation=IDLE; ingredients.clear(); products.clear(); } +void instruction::clear() { is_label=false; label.clear(); operation=IDLE; ingredients.clear(); products.clear(); } // Reagents have the form <name>:<type>:<type>:.../<property>/<property>/... reagent::reagent(string s) :original_string(s), value(0), initialized(false) { @@ -218,30 +218,32 @@ reagent::reagent(string s istringstream in(s); in >> std::noskipws; // properties - while (!in.eof()) { + while (!in.eof()) { istringstream row(slurp_until(in, '/')); row >> std::noskipws; string name = slurp_until(row, ':'); vector<string> values; - while (!row.eof()) + while (!row.eof()) values.push_back(slurp_until(row, ':')); properties.push_back(pair<string, vector<string> >(name, values)); } // structures for the first row of properties name = properties.at(0).first; - for (long long int i = 0; i < SIZE(properties.at(0).second); ++i) { + for (long long int i = 0; i < SIZE(properties.at(0).second); ++i) { string type = properties.at(0).second.at(i); - if (Type_ordinal.find(type) == Type_ordinal.end()) { + if (Type_ordinal.find(type) == Type_ordinal.end() + // types can contain integers, like for array sizes + && !is_integer(type)) { //? cerr << type << " is " << Next_type_ordinal << '\n'; //? 1 Type_ordinal[type] = Next_type_ordinal++; } types.push_back(Type_ordinal[type]); } - if (is_integer(name) && types.empty()) { + if (is_integer(name) && types.empty()) { types.push_back(0); properties.at(0).second.push_back("literal"); } - if (name == "_" && types.empty()) { + if (name == "_" && types.empty()) { types.push_back(0); properties.at(0).second.push_back("dummy"); } @@ -255,19 +257,19 @@ reagent::reagent() :value properties.push_back(pair<string, vector<string> >("", vector<string>())); } -string reagent::to_string() const { +string reagent::to_string() const { ostringstream out; out << "{name: \"" << name << "\""; - if (!properties.empty()) { + if (!properties.empty()) { out << ", properties: ["; - for (long long int i = 0; i < SIZE(properties); ++i) { + for (long long int i = 0; i < SIZE(properties); ++i) { out << "\"" << properties.at(i).first << "\": "; - for (long long int j = 0; j < SIZE(properties.at(i).second); ++j) { - if (j > 0) out << ':'; + for (long long int j = 0; j < SIZE(properties.at(i).second); ++j) { + if (j > 0) out << ':'; out << "\"" << properties.at(i).second.at(j) << "\""; } - if (i < SIZE(properties)-1) out << ", "; - else out << "]"; + if (i < SIZE(properties)-1) out << ", "; + else out << "]"; } } out << "}"; @@ -275,27 +277,27 @@ string reagent::to_string() return out.str(); } -string instruction::to_string() const { - if (is_label) return label; +string instruction::to_string() const { + if (is_label) return label; ostringstream out; - for (long long int i = 0; i < SIZE(products); ++i) { - if (i > 0) out << ", "; + for (long long int i = 0; i < SIZE(products); ++i) { + if (i > 0) out << ", "; out << products.at(i).original_string; } - if (!products.empty()) out << " <- "; + if (!products.empty()) out << " <- "; out << name << ' '; - for (long long int i = 0; i < SIZE(ingredients); ++i) { - if (i > 0) out << ", "; + for (long long int i = 0; i < SIZE(ingredients); ++i) { + if (i > 0) out << ", "; out << ingredients.at(i).original_string; } return out.str(); } -string slurp_until(istream& in, char delim) { +string slurp_until(istream& in, char delim) { ostringstream out; - char c; - while (in >> c) { - if (c == delim) { + char c; + while (in >> c) { + if (c == delim) { // drop the delim break; } @@ -304,29 +306,29 @@ string slurp_until(istream& inreturn out.str(); } -bool has_property(reagent x, string name) { - for (long long int i = /*skip name:type*/1; i < SIZE(x.properties); ++i) { - if (x.properties.at(i).first == name) return true; +bool has_property(reagent x, string name) { + for (long long int i = /*skip name:type*/1; i < SIZE(x.properties); ++i) { + if (x.properties.at(i).first == name) return true; } return false; } -vector<string> property(const reagent& r, const string& name) { - for (long long int p = /*skip name:type*/1; p != SIZE(r.properties); ++p) { - if (r.properties.at(p).first == name) +vector<string> property(const reagent& r, const string& name) { + for (long long int p = /*skip name:type*/1; p != SIZE(r.properties); ++p) { + if (r.properties.at(p).first == name) return r.properties.at(p).second; } return vector<string>(); } -void dump_memory() { - for (map<long long int, double>::iterator p = Memory.begin(); p != Memory.end(); ++p) { +void dump_memory() { + for (map<long long int, double>::iterator p = Memory.begin(); p != Memory.end(); ++p) { cout << p->first << ": " << p->second << '\n'; } } :(before "End Includes") #include<utility> -using std::pair; +using std::pair; -- cgit 1.4.1-2-gfad0