about summary refs log tree commit diff stats
path: root/031container.cc
diff options
context:
space:
mode:
Diffstat (limited to '031container.cc')
-rw-r--r--031container.cc127
1 files changed, 0 insertions, 127 deletions
diff --git a/031container.cc b/031container.cc
index 3a525f80..14a90501 100644
--- a/031container.cc
+++ b/031container.cc
@@ -281,133 +281,6 @@ def main [
 ]
 # just don't die
 
-//:: To write to elements of containers, you need their address.
-
-:(scenario get_address)
-def main [
-  12:number <- copy 34
-  13:number <- copy 35
-  15:address:number <- get-address 12:point, 1:offset
-]
-+mem: storing 13 in location 15
-
-:(before "End Primitive Recipe Declarations")
-GET_ADDRESS,
-:(before "End Primitive Recipe Numbers")
-put(Recipe_ordinal, "get-address", GET_ADDRESS);
-:(before "End Primitive Recipe Checks")
-case GET_ADDRESS: {
-  if (SIZE(inst.ingredients) != 2) {
-    raise << maybe(get(Recipe, r).name) << "'get-address' expects exactly 2 ingredients in '" << to_original_string(inst) << "'\n" << end();
-    break;
-  }
-  reagent base = inst.ingredients.at(0);
-  if (!canonize_type(base)) break;
-  if (!base.type || !base.type->value || !contains_key(Type, base.type->value) || get(Type, base.type->value).kind != CONTAINER) {
-    raise << maybe(get(Recipe, r).name) << "first ingredient of 'get-address' should be a container, but got " << inst.ingredients.at(0).original_string << '\n' << end();
-    break;
-  }
-  type_ordinal base_type = base.type->value;
-  reagent offset = inst.ingredients.at(1);
-  if (!is_literal(offset) || !is_mu_scalar(offset)) {
-    raise << maybe(get(Recipe, r).name) << "second ingredient of 'get-address' should have type 'offset', but got " << inst.ingredients.at(1).original_string << '\n' << end();
-    break;
-  }
-  int offset_value = 0;
-  if (is_integer(offset.name)) {  // later layers permit non-integer offsets
-    offset_value = to_integer(offset.name);
-    if (offset_value < 0 || offset_value >= SIZE(get(Type, base_type).elements)) {
-      raise << maybe(get(Recipe, r).name) << "invalid offset " << offset_value << " for " << get(Type, base_type).name << '\n' << end();
-      break;
-    }
-  }
-  else {
-    offset_value = offset.value;
-  }
-  // same type as for GET..
-  reagent element = element_type(base, offset_value);
-  // ..except for an address at the start
-  element.type = new type_tree("address", get(Type_ordinal, "address"), element.type);
-  if (!types_coercible(inst.products.at(0), element)) {
-    raise << maybe(get(Recipe, r).name) << "'get-address " << base.original_string << ", " << offset.original_string << "' should write to " << names_to_string_without_quotes(element.type) << " but " << inst.products.at(0).name << " has type " << names_to_string_without_quotes(inst.products.at(0).type) << '\n' << end();
-    break;
-  }
-  break;
-}
-:(before "End Primitive Recipe Implementations")
-case GET_ADDRESS: {
-  reagent base = current_instruction().ingredients.at(0);
-  canonize(base);
-  int base_address = base.value;
-  if (base_address == 0) {
-    raise << maybe(current_recipe_name()) << "tried to access location 0 in '" << to_original_string(current_instruction()) << "'\n" << end();
-    break;
-  }
-  type_ordinal base_type = base.type->value;
-  int offset = ingredients.at(1).at(0);
-  if (offset < 0 || offset >= SIZE(get(Type, base_type).elements)) break;  // copied from Check above
-  int result = base_address;
-  for (int i = 0; i < offset; ++i)
-    result += size_of(element_type(base, i));
-  trace(9998, "run") << "address to copy is " << result << end();
-  products.resize(1);
-  products.at(0).push_back(result);
-  break;
-}
-
-:(scenario get_address_out_of_bounds)
-% Hide_errors = true;
-def main [
-  12:number <- copy 34
-  13:number <- copy 35
-  14:number <- copy 36
-  get-address 12:point-number/raw, 2:offset  # point-number occupies 3 locations but has only 2 fields; out of bounds
-]
-+error: main: invalid offset 2 for point-number
-
-:(scenario get_address_out_of_bounds_2)
-% Hide_errors = true;
-def main [
-  12:number <- copy 34
-  13:number <- copy 35
-  14:number <- copy 36
-  get-address 12:point-number/raw, -1:offset
-]
-+error: main: invalid offset -1 for point-number
-
-:(scenario get_address_product_type_mismatch)
-% Hide_errors = true;
-container boolbool [
-  x:boolean
-  y:boolean
-]
-def main [
-  12:boolean <- copy 1
-  13:boolean <- copy 0
-  15:boolean <- get-address 12:boolbool, 1:offset
-]
-+error: main: 'get-address 12:boolbool, 1:offset' should write to (address boolean) but 15 has type boolean
-
-:(scenario get_address_indirect)
-# 'get-address' can read from container address
-def main [
-  1:number <- copy 2
-  2:number <- copy 34
-  3:number <- copy 35
-  4:address:number <- get-address 1:address:point/lookup, 0:offset
-]
-+mem: storing 2 in location 4
-
-:(scenario get_address_indirect2)
-def main [
-  1:number <- copy 2
-  2:number <- copy 34
-  3:number <- copy 35
-  4:address:number <- copy 5/unsafe
-  4:address:number/lookup <- get-address 1:address:point/lookup, 0:offset
-]
-+mem: storing 2 in location 5
-
 //:: To write to elements of containers, use 'put'.
 
 :(scenario put)