From 9570363aec35e187e2395b1760a4b94e71580ac9 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 29 Jul 2015 15:55:05 -0700 Subject: 1885 --- html/033exclusive_container.cc.html | 73 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 37 deletions(-) (limited to 'html/033exclusive_container.cc.html') diff --git a/html/033exclusive_container.cc.html b/html/033exclusive_container.cc.html index 3ab9bc99..2aaf30fb 100644 --- a/html/033exclusive_container.cc.html +++ b/html/033exclusive_container.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; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } -.SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> @@ -62,23 +61,23 @@ Type[tmp].element_names.< :(scenario copy_exclusive_container) # Copying exclusive containers copies all their contents and an extra location for the tag. recipe main [ - 1:number <- copy 1:literal # 'point' variant - 2:number <- copy 34:literal - 3:number <- copy 35:literal - 4:number-or-point <- copy 1:number-or-point/raw # unsafe + 1:number <- copy 1 # 'point' variant + 2:number <- copy 34 + 3:number <- copy 35 + 4:number-or-point <- copy 1:number-or-point/raw # unsafe ] +mem: storing 1 in location 4 +mem: storing 34 in location 5 +mem: storing 35 in location 6 :(before "End size_of(types) Cases") -if (t.kind == exclusive_container) { +if (t.kind == exclusive_container) { // size of an exclusive container is the size of its largest variant // (So like containers, it can't contain arrays.) - long long int result = 0; - for (long long int i = 0; i < t.size; ++i) { - long long int tmp = size_of(t.elements.at(i)); - if (tmp > result) result = tmp; + long long int result = 0; + for (long long int i = 0; i < t.size; ++i) { + long long int tmp = size_of(t.elements.at(i)); + if (tmp > result) result = tmp; } // ...+1 for its tag. return result+1; @@ -96,19 +95,19 @@ Type_ordinal["variant"] = :(scenario maybe_convert) recipe main [ - 12:number <- copy 1:literal - 13:number <- copy 35:literal - 14:number <- copy 36:literal - 20:address:point <- maybe-convert 12:number-or-point/raw, 1:variant # unsafe + 12:number <- copy 1 + 13:number <- copy 35 + 14:number <- copy 36 + 20:address:point <- maybe-convert 12:number-or-point/raw, 1:variant # unsafe ] +mem: storing 13 in location 20 :(scenario maybe_convert_fail) recipe main [ - 12:number <- copy 1:literal - 13:number <- copy 35:literal - 14:number <- copy 36:literal - 20:address:point <- maybe-convert 12:number-or-point/raw, 0:variant # unsafe + 12:number <- copy 1 + 13:number <- copy 35 + 14:number <- copy 36 + 20:address:point <- maybe-convert 12:number-or-point/raw, 0:variant # unsafe ] +mem: storing 0 in location 20 @@ -117,28 +116,28 @@ MAYBE_CONVERT, :(before "End Primitive Recipe Numbers") Recipe_ordinal["maybe-convert"] = MAYBE_CONVERT; :(before "End Primitive Recipe Implementations") -case MAYBE_CONVERT: { - if (SIZE(ingredients) != 2) { +case MAYBE_CONVERT: { + if (SIZE(ingredients) != 2) { raise << current_recipe_name() << ": 'maybe-convert' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end(); break; } reagent base = canonize(current_instruction().ingredients.at(0)); - long long int base_address = base.value; + long long int base_address = base.value; type_ordinal base_type = base.types.at(0); - if (Type[base_type].kind != exclusive_container) { + if (Type[base_type].kind != exclusive_container) { raise << current_recipe_name () << ": first ingredient of 'maybe-convert' should be an exclusive-container, but got " << base.original_string << '\n' << end(); break; } - if (!is_literal(current_instruction().ingredients.at(1))) { + if (!is_literal(current_instruction().ingredients.at(1))) { raise << current_recipe_name() << ": second ingredient of 'maybe-convert' should have type 'variant', but got " << current_instruction().ingredients.at(1).original_string << '\n' << end(); break; } - long long int tag = current_instruction().ingredients.at(1).value; - long long int result; - if (tag == static_cast<long long int>(Memory[base_address])) { + long long int tag = current_instruction().ingredients.at(1).value; + long long int result; + if (tag == static_cast<long long int>(Memory[base_address])) { result = base_address+1; } - else { + else { result = 0; } products.resize(1); @@ -150,8 +149,8 @@ Recipe_ordinal["maybe-convert"] = MAYBE_ :(scenario exclusive_container) exclusive-container foo [ - x:number - y:number + x:number + y:number ] +parse: reading exclusive-container foo +parse: element name: x @@ -160,21 +159,21 @@ exclusive-container foo [ +parse: type: 1 :(before "End Command Handlers") -else if (command == "exclusive-container") { +else if (command == "exclusive-container") { insert_container(command, exclusive_container, in); } //:: To construct exclusive containers out of variant types, use 'merge'. :(scenario lift_to_exclusive_container) exclusive-container foo [ - x:number - y:number + x:number + y:number ] recipe main [ - 1:number <- copy 34:literal - 2:foo <- merge 0:literal/x, 1:number - 4:foo <- merge 1:literal/x, 1:number + 1:number <- copy 34 + 2:foo <- merge 0/x, 1:number + 4:foo <- merge 1/x, 1:number ] +mem: storing 0 in location 2 +mem: storing 34 in location 3 -- cgit 1.4.1-2-gfad0