summary refs log tree commit diff stats
Commit message (Expand)AuthorAgeFilesLines
* some clean upshut2009-12-225-7/+11
* slightly improved get_permission_string() algorithmhut2009-12-221-9/+10
* (half-assed) implementation of parallel directory loaderhut2009-12-227-73/+165
* improved auto-previewshut2009-12-229-41/+84
* "open with" dialog if no application was foundhut2009-12-221-2/+4
* fixed cut/paste for the case where nothing is copied yethut2009-12-202-0/+4
* improved titlebar, shrinks if its too largehut2009-12-201-20/+169
* Added option for autoloading previews.hut2009-12-203-7/+13
* postpone directory previews if not loaded yethut2009-12-202-3/+19
* fixed CTRL+Lhut2009-12-181-2/+2
* improved the file operationshut2009-12-181-10/+31
* notification widgethut2009-12-185-7/+110
* UI.redraw now redraws widgets. old redraw is now redraw_windowhut2009-12-183-5/+9
* added provisional filesystem operations (cp/cut/paste/delete/mkdir)hut2009-12-185-10/+103
* re-indented docstringshut2009-12-1713-57/+75
* added quick_open() in abstract Command classhut2009-12-171-0/+3
* quit command, aliaseshut2009-12-172-10/+23
* fixed colorschemes, added unittest for colorschemeshut2009-12-172-3/+34
* fixed history (fast_forward worked reversed)hut2009-12-171-3/+3
* added history to consolehut2009-12-172-16/+47
* extended history by a couple of methodshut2009-12-172-10/+33
* tons of stuffhut2009-12-178-38/+146
* fixed CD command / tab completionhut2009-12-153-49/+48
* Added console commands + tab completionhut2009-12-155-10/+180
* fine tuninghut2009-12-152-98/+107
* turned different console types into seperate subclasseshut2009-12-151-36/+46
* changed default key binding implementationhut2009-12-152-89/+79
* updated umlhut2009-12-154-5/+11
* cleanups, display link destinationshut2009-12-155-30/+71
* different way of squeezing the last columnhut2009-12-151-4/+14
* implemented statusbar widgethut2009-12-146-2/+187
* added an option for collapse_previewhut2009-12-143-1/+3
* fixed directory testhut2009-12-141-0/+3
* "poke" widgets, expand last column if there's no previewhut2009-12-144-9/+56
* Don't initialize options while importing.hut2009-12-143-42/+46
* updated / added testshut2009-12-139-24/+249
* clean ups, commentshut2009-12-1322-36/+77
* updated bookmarkshut2009-12-133-92/+143
* added docstrings everywherehut2009-12-1311-45/+137
* fixed issues with scrolling/invalid mouse bstateshut2009-12-132-3/+13
* implemented FileListContainerhut2009-12-128-52/+105
* updated UML projecthut2009-12-1220-2562/+1679
* merged main with __init__hut2009-12-125-93/+94
* clean ups/fixeshut2009-12-128-41/+58
* clean upshut2009-12-115-15/+7
* run all tests with a single executablehut2009-12-112-0/+16
* fixed cd-after-exithut2009-12-111-1/+1
* Reorganization of gui/widget hierarchy and directory structurehut2009-12-1117-247/+348
* restructurationshut2009-12-1121-104/+155
* add documentation of some builtin moduleshut2009-12-111-0/+5
*/ .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 */
//: Exclusive containers contain exactly one of a fixed number of 'variants'
//: of different types.
//:
//: They also implicitly contain a tag describing precisely which variant is
//: currently stored in them.

:(before "End Mu Types Initialization")
//: We'll use this container as a running example, with two number elements.
{
type_ordinal tmp = put(Type_ordinal, "number-or-point", Next_type_ordinal++);
get_or_insert(Type, tmp).size = 2;
get(Type, tmp).kind = EXCLUSIVE_CONTAINER;
get(Type, tmp).name = "number-or-point";
get(Type, tmp).element_type_names.push_back(new string_tree("number"));
get(Type, tmp).elements.push_back(new type_tree(number));
get(Type, tmp).element_names.push_back("i");
get(Type, tmp).element_type_names.push_back(new string_tree("point"));
get(Type, tmp).elements.push_back(new type_tree(point));
get(Type, tmp).element_names.push_back("p");
}

//: Tests in this layer often explicitly setup memory before reading it as an
//: array. Don't do this in general. I'm tagging exceptions with /raw to
//: avoid errors.
:(scenario copy_exclusive_container)
# Copying exclusive containers copies all their contents and an extra location for the tag.
recipe main [
  1:number <- copy 1  # 'point' variant
  2:number <- copy 34
  3:number <- copy 35
  4:number-or-point <- copy 1:number-or-point/unsafe
]
+mem: storing 1 in location 4
+mem: storing 34 in location 5
+mem: storing 35 in location 6

:(before "End size_of(type) Cases")
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) {
    // End size_of(type) Exclusive Container Cases
    long long int size = size_of(t.elements.at(i));
    if (size > result) result = size;
  }
  // ...+1 for its tag.
  return result+1;
}

//:: To access variants of an exclusive container, use 'maybe-convert'.
//: It always returns an address (so that you can modify it) or null (to
//: signal that the conversion failed (because the container contains a
//: different variant).

//: 'maybe-convert' requires a literal in ingredient 1. We'll use a synonym
//: called 'variant'.
:(before "End Mu Types Initialization")
put(Type_ordinal, "variant", 0);

:(scenario maybe_convert)
recipe main [
  12:number <- copy 1
  13:number <- copy 35
  14:number <- copy 36
  20:address:point <- maybe-convert 12:number-or-point/unsafe, 1:variant
]
+mem: storing 13 in location 20

:(scenario maybe_convert_fail)
recipe main [
  12:number <- copy 1
  13:number <- copy 35
  14:number <- copy 36
  20:address:number <- maybe-convert 12:number-or-point/unsafe, 0:variant
]
+mem: storing 0 in location 20

:(before "End Primitive Recipe Declarations")
MAYBE_CONVERT,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "maybe-convert", MAYBE_CONVERT);
:(before "End Primitive Recipe Checks")
case MAYBE_CONVERT: {
  const recipe& caller = get(Recipe, r);
  if (SIZE(inst.ingredients) != 2) {
    raise_error << maybe(caller.name) << "'maybe-convert' expects exactly 2 ingredients in '" << inst.to_string() << "'\n" << end();
    break;
  }
  reagent base = inst.ingredients.at(0);
  canonize_type(base);
  if (!base.type || !base.type->value || get(Type, base.type->value).kind != EXCLUSIVE_CONTAINER) {
    raise_error << maybe(caller.name) << "first ingredient of 'maybe-convert' should be an exclusive-container, but got " << base.original_string << '\n' << end();
    break;
  }
  if (!is_literal(inst.ingredients.at(1))) {
    raise_error << maybe(caller.name) << "second ingredient of 'maybe-convert' should have type 'variant', but got " << inst.ingredients.at(1).original_string << '\n' << end();
    break;
  }
  if (inst.products.empty()) break;
  reagent product = inst.products.at(0);
  if (!canonize_type(product)) break;
  reagent& offset = inst.ingredients.at(1);
  populate_value(offset);
  if (offset.value >= SIZE(get(Type, base.type->value).elements)) {
    raise_error << maybe(caller.name) << "invalid tag " << offset.value << " in '" << inst.to_string() << '\n' << end();
    break;
  }
  reagent variant = variant_type(base, offset.value);
  variant.type = new type_tree(get(Type_ordinal, "address"), variant.type);
  if (!types_coercible(product, variant)) {
    raise_error << maybe(caller.name) << "'maybe-convert " << base.original_string << ", " << inst.ingredients.at(1).original_string << "' should write to " << debug_string(variant.type) << " but " << product.name << " has type " << debug_string(product.type) << '\n' << end();
    break;
  }
  break;
}
:(before "End Primitive Recipe Implementations")
case MAYBE_CONVERT: {
  reagent base = current_instruction().ingredients.at(0);
  canonize(base);
  long long int base_address = base.value;
  if (base_address == 0) {
    raise_error << maybe(current_recipe_name()) << "tried to access location 0 in '" << current_instruction().to_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>(get_or_insert(Memory, base_address))) {
    result = base_address+1;
  }
  else {
    result = 0;
  }
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(code)
const reagent variant_type(const reagent& canonized_base, long long int tag) {
  assert(tag >= 0);
  assert(contains_key(Type, canonized_base.type->value));
  assert(!get(Type, canonized_base.type->value).name.empty());
  const type_info& info = get(Type, canonized_base.type->value);
  assert(info.kind == EXCLUSIVE_CONTAINER);
  reagent element;
  element.type = new type_tree(*info.elements.at(tag));
  element.properties.at(0).second = new string_tree(*info.element_type_names.at(tag));
  // End variant_type Special-cases
  return element;
}

:(scenario maybe_convert_product_type_mismatch)
% Hide_errors = true;
recipe main [
  12:number <- copy 1
  13:number <- copy 35
  14:number <- copy 36
  20:address:number <- maybe-convert 12:number-or-point/unsafe, 1:variant
]
+error: main: 'maybe-convert 12:number-or-point/unsafe, 1:variant' should write to <address : <point : <>>> but 20 has type <address : <number : <>>>


//:: Allow exclusive containers to be defined in mu code.

:(scenario exclusive_container)
exclusive-container foo [
  x:number
  y:number
]
+parse: --- defining exclusive-container foo
+parse:   element name: x
+parse:   type: 1
+parse:   element name: y
+parse:   type: 1

:(before "End Command Handlers")
else if (command == "exclusive-container") {
  insert_container(command, EXCLUSIVE_CONTAINER, in);
}

//: arrays are disallowed inside exclusive containers unless their length is
//: fixed in advance

:(scenario exclusive_container_contains_array)
% Hide_errors = true;
exclusive-container foo [
  x:array:number:3
]
$error: 0

:(scenario exclusive_container_warns_on_dynamic_array_element)
% Hide_errors = true;
exclusive-container foo [
  x:array:number
]
+error: container 'foo' cannot determine size of element x

//:: To construct exclusive containers out of variant types, use 'merge'.
:(scenario lift_to_exclusive_container)
exclusive-container foo [
  x:number
  y:number
]

recipe main [
  1:number <- copy 34
  2:foo <- merge 0/x, 1:number  # tag must be a literal when merging exclusive containers
  4:foo <- merge 1/y, 1:number
]
+mem: storing 0 in location 2
+mem: storing 34 in location 3
+mem: storing 1 in location 4
+mem: storing 34 in location 5

//: type-checking for 'merge' on exclusive containers

:(scenario merge_handles_exclusive_container)
% Hide_errors = true;
exclusive-container foo [
  x:number
  y:bar
]
container bar [
  z:number
]
recipe main [
  1:foo <- merge 0/x, 34
]
+mem: storing 0 in location 1
+mem: storing 34 in location 2
$error: 0

:(scenario merge_requires_literal_tag_for_exclusive_container)
% Hide_errors = true;
exclusive-container foo [
  x:number
  y:bar
]
container bar [
  z:number
]
recipe main [
  local-scope
  1:number <- copy 0
  2:foo <- merge 1:number, 34
]
+error: main: ingredient 0 of 'merge' should be a literal, for the tag of exclusive-container foo

:(before "End valid_merge Cases")
case EXCLUSIVE_CONTAINER: {
  assert(state.data.top().container_element_index == 0);
  trace(9999, "transform") << "checking exclusive container " << debug_string(container) << " vs ingredient " << ingredient_index << end();
  if (!is_literal(ingredients.at(ingredient_index))) {
    raise_error << maybe(caller.name) << "ingredient " << ingredient_index << " of 'merge' should be a literal, for the tag of exclusive-container " << container_info.name << '\n' << end();
    return;
  }
  reagent ingredient = ingredients.at(ingredient_index);  // unnecessary copy just to keep this function from modifying caller
  populate_value(ingredient);
  if (ingredient.value >= SIZE(container_info.elements)) {
    raise_error << maybe(caller.name) << "invalid tag at " << ingredient_index << " for " << container_info.name << " in '" << inst.to_string() << '\n' << end();
    return;
  }
  reagent variant = variant_type(container, ingredient.value);
  trace(9999, "transform") << "tag: " << ingredient.value << end();
  // replace union with its variant
  state.data.pop();
  state.data.push(merge_check_point(variant, 0));
  ++ingredient_index;
  break;
}

:(scenario merge_check_container_containing_exclusive_container)
% Hide_errors = true;
container foo [
  x:number
  y:bar
]
exclusive-container bar [
  x:number
  y:number
]
recipe main [
  1:foo <- merge 23, 1/y, 34
]
+mem: storing 23 in location 1
+mem: storing 1 in location 2
+mem: storing 34 in location 3
$error: 0

:(scenario merge_check_container_containing_exclusive_container_2)
% Hide_errors = true;
container foo [
  x:number
  y:bar
]
exclusive-container bar [
  x:number
  y:number
]
recipe main [
  1:foo <- merge 23, 1/y, 34, 35
]
+error: main: too many ingredients in '1:foo <- merge 23, 1/y, 34, 35'

:(scenario merge_check_exclusive_container_containing_container)
% Hide_errors = true;
exclusive-container foo [
  x:number
  y:bar
]
container bar [
  x:number
  y:number
]
recipe main [
  1:foo <- merge 1/y, 23, 34
]
+mem: storing 1 in location 1
+mem: storing 23 in location 2
+mem: storing 34 in location 3
$error: 0

:(scenario merge_check_exclusive_container_containing_container_2)
% Hide_errors = true;
exclusive-container foo [
  x:number
  y:bar
]
container bar [
  x:number
  y:number
]
recipe main [
  1:foo <- merge 0/x, 23
]
$error: 0

:(scenario merge_check_exclusive_container_containing_container_3)
% Hide_errors = true;
exclusive-container foo [
  x:number
  y:bar
]
container bar [
  x:number
  y:number
]
recipe main [
  1:foo <- merge 1/y, 23
]
+error: main: too few ingredients in '1:foo <- merge 1/y, 23'

//: Since the different variants of an exclusive-container might have
//: different sizes, relax the size mismatch check for 'merge' instructions.
:(before "End size_mismatch(x) Cases")
if (current_instruction().operation == MERGE
    && !current_instruction().products.empty()
    && current_instruction().products.at(0).type) {
  reagent x = current_instruction().products.at(0);
  canonize(x);
  if (get(Type, x.type->value).kind == EXCLUSIVE_CONTAINER) {
    return size_of(x) < SIZE(data);
  }
}

:(scenario merge_exclusive_container_with_mismatched_sizes)
container foo [
  x:number
  y:number
]

exclusive-container bar [
  x:number
  y:foo
]

recipe main [
  1:number <- copy 34
  2:number <- copy 35
  3:bar <- merge 0/x, 1:number
  6:bar <- merge 1/foo, 1:number, 2:number
]
+mem: storing 0 in location 3
+mem: storing 34 in location 4
# bar is always 3 large so location 5 is skipped
+mem: storing 1 in location 6
+mem: storing 34 in location 7
+mem: storing 35 in location 8