diff options
Diffstat (limited to '042name.cc')
-rw-r--r-- | 042name.cc | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/042name.cc b/042name.cc index e1f35136..f183962c 100644 --- a/042name.cc +++ b/042name.cc @@ -6,8 +6,8 @@ def main [ x:num <- copy 0 ] -+name: assign x 2 -+mem: storing 0 in location 2 ++name: assign x 1 ++mem: storing 0 in location 1 :(scenarios transform) :(scenario transform_names_fails_on_use_before_define) @@ -42,7 +42,7 @@ void transform_names(const recipe_ordinal r) { map<string, int>& names = Name[r]; // store the indices 'used' so far in the map int& curr_idx = names[""]; - curr_idx = 2; // reserve indices 0 and 1 for the chaining slot in a later layer + ++curr_idx; // avoid using index 0, benign skip in some other cases for (int i = 0; i < SIZE(caller.steps); ++i) { instruction& inst = caller.steps.at(i); // End transform_names(inst) Special-cases @@ -135,21 +135,13 @@ bool is_compound_type_starting_with(const type_tree* type, const string& expecte return type->left->value == get(Type_ordinal, expected_name); } -int find_element_offset(const type_ordinal t, const string& name, const string& recipe_name) { +int find_element_name(const type_ordinal t, const string& name, const string& recipe_name) { const type_info& container = get(Type, t); for (int i = 0; i < SIZE(container.elements); ++i) if (container.elements.at(i).name == name) return i; raise << maybe(recipe_name) << "unknown element '" << name << "' in container '" << get(Type, t).name << "'\n" << end(); return -1; } -int find_element_location(int base_address, const string& name, const type_tree* type, const string& recipe_name) { - int offset = find_element_offset(get_base_type(type)->value, name, recipe_name); - if (offset == -1) return offset; - int result = base_address; - for (int i = 0; i < offset; ++i) - result += size_of(element_type(type, i)); - return result; -} bool is_numeric_location(const reagent& x) { if (is_literal(x)) return false; @@ -178,26 +170,26 @@ def main [ x:point <- merge 34, 35 y:num <- copy 3 ] -+name: assign x 2 ++name: assign x 1 # skip location 2 because x occupies two locations -+name: assign y 4 ++name: assign y 3 :(scenario transform_names_supports_static_arrays) def main [ x:@:num:3 <- create-array y:num <- copy 3 ] -+name: assign x 2 ++name: assign x 1 # skip locations 2, 3, 4 because x occupies four locations -+name: assign y 6 ++name: assign y 5 :(scenario transform_names_passes_dummy) # _ is just a dummy result that never gets consumed def main [ _, x:num <- copy 0, 1 ] -+name: assign x 2 --name: assign _ 2 ++name: assign x 1 +-name: assign _ 1 //: an escape hatch to suppress name conversion that we'll use later :(scenarios run) @@ -206,7 +198,7 @@ def main [ def main [ x:num/raw <- copy 0 ] --name: assign x 2 +-name: assign x 1 +error: can't write to location 0 in 'x:num/raw <- copy 0' :(scenarios transform) @@ -274,7 +266,7 @@ if (inst.name == "get" || inst.name == "get-location" || inst.name == "put") { // since first non-address in base type must be a container, we don't have to canonize type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type); if (contains_key(Type, base_type)) { // otherwise we'll raise an error elsewhere - inst.ingredients.at(1).set_value(find_element_offset(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); + inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); trace(9993, "name") << "element " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " is at offset " << no_scientific(inst.ingredients.at(1).value) << end(); } } @@ -294,8 +286,8 @@ def main [ a:point <- copy 0/unsafe b:num <- copy 0/unsafe ] -+name: assign a 2 -+name: assign b 4 ++name: assign a 1 ++name: assign b 3 //:: Support variant names for exclusive containers in 'maybe-convert'. @@ -324,7 +316,7 @@ if (inst.name == "maybe-convert") { // since first non-address in base type must be an exclusive container, we don't have to canonize type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type); if (contains_key(Type, base_type)) { // otherwise we'll raise an error elsewhere - inst.ingredients.at(1).set_value(find_element_offset(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); + inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); trace(9993, "name") << "variant " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " has tag " << no_scientific(inst.ingredients.at(1).value) << end(); } } |