about summary refs log tree commit diff stats
path: root/arc/.traces/convert-names-record-fields-indirect
blob: d621b275ea4015b9aa3cee3c89adaf076ee8b74e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
cn0: convert-names in 
cn0: (((x integer)) <- ((get)) ((34 integer-boolean-pair-address) (deref)) ((bool offset))) nil nil
cn0: field-access bool in 34integer-boolean-pair-addressderef of type integer-boolean-pair
cn0: new field; computing location
cn0: field location 1
cn0: checking arg ((34 integer-boolean-pair-address) (deref))
maybe-add: ((34 integer-boolean-pair-address) (deref))
cn0: checking arg ((bool offset))
cn0: checking oarg ((x integer))
maybe-add: ((x integer))
cn0: location for oarg ((x integer)): 1
cn1: (((1 integer)) <- ((get)) ((34 integer-boolean-pair-address) (deref)) ((1 offset)))
rd.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
//: Some simple sanity checks for types, and also attempts to guess them where
//: they aren't provided.
//:
//: You still have to provide the full type the first time you mention a
//: variable in a recipe. You have to explicitly name :offset and :variant
//: every single time. You can't use the same name with multiple types in a
//: single recipe.

:(scenario transform_fails_on_reusing_name_with_different_type)
% Hide_errors = true;
def main [
  x:num <- copy 1
  x:bool <- copy 1
]
+error: main: 'x' used with multiple types

:(after "Transform.push_back(expand_type_abbreviations)")
Transform.push_back(check_or_set_types_by_name);  // idempotent

:(code)
void check_or_set_types_by_name(const recipe_ordinal r) {
  trace(9991, "transform") << "--- deduce types for recipe " << get(Recipe, r).name << end();
  recipe& caller = get(Recipe, r);
  set<reagent> known;
  for (int i = 0;  i < SIZE(caller.steps);  ++i) {
    instruction& inst = caller.steps.at(i);
    for (int in = 0;  in < SIZE(inst.ingredients);  ++in) {
      deduce_missing_type(known, inst.ingredients.at(in));
      check_type(known, inst.ingredients.at(in), caller);
    }
    for (int out = 0;  out < SIZE(inst.products);  ++out) {
      deduce_missing_type(known, inst.products.at(out));
      check_type(known, inst.products.at(out), caller);
    }
  }
}

void deduce_missing_type(set<reagent>& known, reagent& x) {
  if (x.type) return;
  if (is_jump_target(x.name)) {
    x.type = new type_tree("label");
    return;
  }
  if (known.find(x) == known.end()) return;
  x.type = new type_tree(*known.find(x)->type);
  trace(9992, "transform") << x.name << " <= " << names_to_string(x.type) << end();
}

void check_type(set<reagent>& known, const reagent& x, const recipe& caller) {
  if (is_literal(x)) return;
  if (is_integer(x.name)) return;  // if you use raw locations you're probably doing something unsafe
  if (!x.type) return;  // might get filled in by other logic later
  if (is_jump_target(x.name)) {
    if (!x.type->atom || x.type->name != "label")
      raise << maybe(caller.name) << "non-label '" << x.name << "' must begin with a letter\n" << end();
    return;
  }
  if (known.find(x) == known.end()) {
    trace(9992, "transform") << x.name << " => " << names_to_string(x.type) << end();
    known.insert(x);
  }
  if (!types_strictly_match(known.find(x)->type, x.type)) {
    raise << maybe(caller.name) << "'" << x.name << "' used with multiple types\n" << end();
    return;
  }
  if (is_mu_array(x)) {
    if (!x.type->right) {
      raise << maybe(caller.name) << "'" << x.name << ": can't be just an array. What is it an array of?\n" << end();
      return;
    }
    if (!x.type->right->right) {
      raise << caller.name << " can't determine the size of array variable '" << x.name << "'. Either allocate it separately and make the type of '" << x.name << "' an address, or specify the length of the array in the type of '" << x.name << "'.\n" << end();
      return;
    }
  }
}

:(scenario transform_fills_in_missing_types)
def main [
  x:num <- copy 1
  y:num <- add x, 1
]
# x is in location 1, y in location 2
+mem: storing 2 in location 2

:(scenario transform_fills_in_missing_types_in_product)
def main [
  x:num <- copy 1
  x <- copy 2
]
# x is in location 1
+mem: storing 2 in location 1

:(scenario transform_fills_in_missing_types_in_product_and_ingredient)
def main [
  x:num <- copy 1
  x <- add x, 1
]
# x is in location 1
+mem: storing 2 in location 1

:(scenario transform_fills_in_missing_label_type)
def main [
  jump +target
  1:num <- copy 0
  +target
]
-mem: storing 0 in location 1

:(scenario transform_fails_on_missing_types_in_first_mention)
% Hide_errors = true;
def main [
  x <- copy 1
  x:num <- copy 2
]
+error: main: missing type for 'x' in 'x <- copy 1'

:(scenario transform_fails_on_wrong_type_for_label)
% Hide_errors = true;
def main [
  +foo:num <- copy 34
]
+error: main: non-label '+foo' must begin with a letter

:(scenario typo_in_address_type_fails)
% Hide_errors = true;
def main [
  y:&:charcter <- new character:type
  *y <- copy 67
]
+error: main: unknown type charcter in 'y:&:charcter <- new character:type'

:(scenario array_type_without_size_fails)
% Hide_errors = true;
def main [
  x:@:num <- merge 2, 12, 13
]
+error: main can't determine the size of array variable 'x'. Either allocate it separately and make the type of 'x' an address, or specify the length of the array in the type of 'x'.

:(scenarios transform)
:(scenario transform_checks_types_of_identical_reagents_in_multiple_spaces)
def foo [  # dummy
]
def main [
  local-scope
  0:space/names:foo <- copy 0  # specify surrounding space
  x:bool <- copy 1/true
  x:num/space:1 <- copy 34
  x/space:1 <- copy 35
]
$error: 0

:(scenario transform_handles_empty_reagents)
% Hide_errors = true;
def main [
  add *
]
+error: illegal name '*'
# no crash