about summary refs log blame commit diff stats
path: root/relayout
blob: 8ea48920a3bf4ec9127bf453db7795607c52992a (plain) (tree)
b1bbe92d pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.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 { co
#!/bin/bash
# Helper to change the numerical prefixes across the repo, say if you want to
# create room between 023 and 024, and so on.
#
# Assumes there's only ever one file with any numeric prefix. If you move
# 003trace.test.cc you might need to do some manual patch-up.

set -e

if [[ $# -eq 0 && `git diff HEAD |wc -l` -gt 0 ]]
then
  echo "Uncommitted changes"
  exit
fi

if [[ $# -gt 0 ]] # dry run
then
  git() {
    echo $*
  }
fi

#

index=0
ls [0-9]* |grep -v "trace.test" |sort -n |
  while read file
  do
    while [[ $file != `printf "%03d" $index`* ]]
    do
      echo
      index=$(($index+1))
    done
    echo $file
    index=$(($index+1))
  done > .layout

vim -c "set nu" .layout

#

root() {
  echo $1 |sed 's/^[0-9]*//'
}

index=0
cat .layout |
  while read file
  do
    if [ ! -z $file ]
    then
      newfile=`printf "%03d" $index``root $file`
      if [[ $newfile != $file ]]
      then
        echo git mv $file $newfile
        git mv $file $newfile
      fi
    fi
    index=$(($index+1))
  done

rm .layout

# Scenarios considered:
#   Don't redo the layout if Vim exits with error.
ass="nb">true; def main [ 1:point <- merge 3, 4 2:point-number <- merge 1:point ] +error: main: too few ingredients in '2:point-number <- merge 1:point' :(scenario merge_check_recursive_containers_3) def main [ 1:point-number <- merge 3, 4, 5 ] $error: 0 :(scenario merge_check_recursive_containers_4) % Hide_errors = true; def main [ 1:point-number <- merge 3, 4 ] +error: main: too few ingredients in '1:point-number <- merge 3, 4' :(scenario merge_check_reflexive) % Hide_errors = true; def main [ 1:point <- merge 3, 4 2:point <- merge 1:point ] $error: 0 //: Since a container can be merged in several ways, we need to be able to //: backtrack through different possibilities. Later we'll allow creating //: exclusive containers which contain just one of rather than all of their //: elements. That will also require backtracking capabilities. Here's the //: state we need to maintain for backtracking: :(before "End Types") struct merge_check_point { reagent container; int container_element_index; merge_check_point(const reagent& c, int i) :container(c), container_element_index(i) {} }; struct merge_check_state { stack<merge_check_point> data; }; :(before "End Checks") Transform.push_back(check_merge_calls); // idempotent :(code) void check_merge_calls(const recipe_ordinal r) { const recipe& caller = get(Recipe, r); trace(9991, "transform") << "--- type-check merge instructions in recipe " << caller.name << end(); for (int i = 0; i < SIZE(caller.steps); ++i) { const instruction& inst = caller.steps.at(i); if (inst.name != "merge") continue; if (SIZE(inst.products) != 1) { raise << maybe(caller.name) << "'merge' should yield a single product in '" << to_original_string(inst) << "'\n" << end(); continue; } reagent/*copy*/ product = inst.products.at(0); // Update product While Type-checking Merge const type_tree* product_base_type = product.type->atom ? product.type : product.type->left; assert(product_base_type->atom); if (product_base_type->value == 0 || !contains_key(Type, product_base_type->value)) { raise << maybe(caller.name) << "'merge' should yield a container in '" << to_original_string(inst) << "'\n" << end(); continue; } const type_info& info = get(Type, product_base_type->value); if (info.kind != CONTAINER && info.kind != EXCLUSIVE_CONTAINER) { raise << maybe(caller.name) << "'merge' should yield a container in '" << to_original_string(inst) << "'\n" << end(); continue; } check_merge_call(inst.ingredients, product, caller, inst); } } void check_merge_call(const vector<reagent>& ingredients, const reagent& product, const recipe& caller, const instruction& inst) { int ingredient_index = 0; merge_check_state state; state.data.push(merge_check_point(product, 0)); while (true) { assert(!state.data.empty()); trace("transform") << ingredient_index << " vs " << SIZE(ingredients) << end(); if (ingredient_index >= SIZE(ingredients)) { raise << maybe(caller.name) << "too few ingredients in '" << to_original_string(inst) << "'\n" << end(); return; } reagent& container = state.data.top().container; if (!container.type) return; // error handled elsewhere const type_tree* top_root_type = container.type->atom ? container.type : container.type->left; assert(top_root_type->atom); type_info& container_info = get(Type, top_root_type->value); switch (container_info.kind) { case CONTAINER: { // degenerate case: merge with the same type always succeeds if (state.data.top().container_element_index == 0 && types_coercible(container, inst.ingredients.at(ingredient_index))) return; const reagent& expected_ingredient = element_type(container.type, state.data.top().container_element_index); trace("transform") << "checking container " << to_string(container) << " || " << to_string(expected_ingredient) << " vs ingredient " << ingredient_index << end(); // if the current element is the ingredient we expect, move on to the next element/ingredient if (types_coercible(expected_ingredient, ingredients.at(ingredient_index))) { ++ingredient_index; ++state.data.top().container_element_index; while (state.data.top().container_element_index >= SIZE(get(Type, get_base_type(state.data.top().container.type)->value).elements)) { state.data.pop(); if (state.data.empty()) { if (ingredient_index < SIZE(ingredients)) raise << maybe(caller.name) << "too many ingredients in '" << to_original_string(inst) << "'\n" << end(); return; } ++state.data.top().container_element_index; } } // if not, maybe it's a field of the current element else { // no change to ingredient_index state.data.push(merge_check_point(expected_ingredient, 0)); } break; } // End check_merge_call Special-cases default: { if (!types_coercible(container, ingredients.at(ingredient_index))) { raise << maybe(caller.name) << "incorrect type of ingredient " << ingredient_index << " in '" << to_original_string(inst) << "'\n" << end(); raise << " (expected '" << debug_string(container) << "')\n" << end(); raise << " (got '" << debug_string(ingredients.at(ingredient_index)) << "')\n" << end(); return; } ++ingredient_index; // ++state.data.top().container_element_index; // unnecessary, but wouldn't do any harm do { state.data.pop(); if (state.data.empty()) { if (ingredient_index < SIZE(ingredients)) raise << maybe(caller.name) << "too many ingredients in '" << to_original_string(inst) << "'\n" << end(); return; } ++state.data.top().container_element_index; } while (state.data.top().container_element_index >= SIZE(get(Type, get_base_type(state.data.top().container.type)->value).elements)); } } } // never gets here assert(false); } //: replaced in a later layer //: todo: find some clean way to take this call completely out of this layer const type_tree* get_base_type(const type_tree* t) { return t; } :(scenario merge_check_product) % Hide_errors = true; def main [ 1:num <- merge 3 ] +error: main: 'merge' should yield a container in '1:num <- merge 3' :(before "End Includes") #include <stack> using std::stack;