fix other mandelbrot variants
[mu.git] / archive / 1.vm / 055shape_shifting_container.cc
blob909e6fc59c9736df1c554c51f9629d7575c9934e
1 //:: Container definitions can contain 'type ingredients'
3 //: pre-requisite: extend our notion of containers to not necessarily be
4 //: atomic types
5 :(after "Update GET base_type in Check")
6 base_type = get_base_type(base_type);
7 :(after "Update GET base_type in Run")
8 base_type = get_base_type(base_type);
9 :(after "Update PUT base_type in Check")
10 base_type = get_base_type(base_type);
11 :(after "Update PUT base_type in Run")
12 base_type = get_base_type(base_type);
13 :(after "Update MAYBE_CONVERT base_type in Check")
14 base_type = get_base_type(base_type);
15 :(after "Update base_type in element_type")
16 base_type = get_base_type(base_type);
17 :(after "Update base_type in skip_addresses")
18 base_type = get_base_type(base_type);
19 :(replace{} "const type_tree* get_base_type(const type_tree* t)")
20 const type_tree* get_base_type(const type_tree* t) {
21 const type_tree* result = t->atom ? t : t->left;
22 if (!result->atom)
23 raise << "invalid type " << to_string(t) << '\n' << end();
24 return result;
27 :(code)
28 void test_ill_formed_container() {
29 Hide_errors = true;
30 run(
31 "def main [\n"
32 " {1: ((foo) num)} <- copy 0\n"
33 "]\n"
35 // no crash
38 //: update size_of to handle non-atom container types
40 void test_size_of_shape_shifting_container() {
41 run(
42 "container foo:_t [\n"
43 " x:_t\n"
44 " y:num\n"
45 "]\n"
46 "def main [\n"
47 " 1:foo:num <- merge 12, 13\n"
48 " 3:foo:point <- merge 14, 15, 16\n"
49 "]\n"
51 CHECK_TRACE_CONTENTS(
52 "mem: storing 12 in location 1\n"
53 "mem: storing 13 in location 2\n"
54 "mem: storing 14 in location 3\n"
55 "mem: storing 15 in location 4\n"
56 "mem: storing 16 in location 5\n"
59 void test_size_of_shape_shifting_container_2() {
60 run(
61 // multiple type ingredients
62 "container foo:_a:_b [\n"
63 " x:_a\n"
64 " y:_b\n"
65 "]\n"
66 "def main [\n"
67 " 1:foo:num:bool <- merge 34, true\n"
68 "]\n"
70 CHECK_TRACE_COUNT("error", 0);
72 void test_size_of_shape_shifting_container_3() {
73 run(
74 "container foo:_a:_b [\n"
75 " x:_a\n"
76 " y:_b\n"
77 "]\n"
78 "def main [\n"
79 " 1:text <- new [abc]\n"
80 // compound types for type ingredients
81 " {3: (foo number (address array character))} <- merge 34/x, 1:text/y\n"
82 "]\n"
84 CHECK_TRACE_COUNT("error", 0);
87 void test_size_of_shape_shifting_container_4() {
88 run(
89 "container foo:_a:_b [\n"
90 " x:_a\n"
91 " y:_b\n"
92 "]\n"
93 "container bar:_a:_b [\n"
94 // dilated element
95 " {data: (foo _a (address _b))}\n"
96 "]\n"
97 "def main [\n"
98 " 1:text <- new [abc]\n"
99 " 3:bar:num:@:char <- merge 34/x, 1:text/y\n"
100 "]\n"
102 CHECK_TRACE_COUNT("error", 0);
105 void test_shape_shifting_container_extend() {
106 run(
107 "container foo:_a [\n"
108 " x:_a\n"
109 "]\n"
110 "container foo:_a [\n"
111 " y:_a\n"
112 "]\n"
114 CHECK_TRACE_COUNT("error", 0);
117 void test_shape_shifting_container_extend_error() {
118 Hide_errors = true;
119 run(
120 "container foo:_a [\n"
121 " x:_a\n"
122 "]\n"
123 "container foo:_b [\n"
124 " y:_b\n"
125 "]\n"
127 CHECK_TRACE_CONTENTS(
128 "error: headers of container 'foo' must use identical type ingredients\n"
132 void test_type_ingredient_must_start_with_underscore() {
133 Hide_errors = true;
134 run(
135 "container foo:t [\n"
136 " x:num\n"
137 "]\n"
139 CHECK_TRACE_CONTENTS(
140 "error: foo: type ingredient 't' must begin with an underscore\n"
144 :(before "End Globals")
145 // We'll use large type ordinals to mean "the following type of the variable".
146 // For example, if we have a generic type called foo:_elem, the type
147 // ingredient _elem in foo's type_info will have value START_TYPE_INGREDIENTS,
148 // and we'll handle it by looking in the current reagent for the next type
149 // that appears after foo.
150 extern const int START_TYPE_INGREDIENTS = 2000;
151 :(before "End Commandline Parsing") // after loading .mu files
152 assert(Next_type_ordinal < START_TYPE_INGREDIENTS);
154 :(before "End type_info Fields")
155 map<string, type_ordinal> type_ingredient_names;
157 //: Suppress unknown type checks in shape-shifting containers.
159 :(before "Check Container Field Types(info)")
160 if (!info.type_ingredient_names.empty()) continue;
162 :(before "End container Name Refinements")
163 if (name.find(':') != string::npos) {
164 trace(101, "parse") << "container has type ingredients; parsing" << end();
165 if (!read_type_ingredients(name, command)) {
166 // error; skip rest of the container definition and continue
167 slurp_balanced_bracket(in);
168 return;
172 :(code)
173 bool read_type_ingredients(string& name, const string& command) {
174 string save_name = name;
175 istringstream in(save_name);
176 name = slurp_until(in, ':');
177 map<string, type_ordinal> type_ingredient_names;
178 if (!slurp_type_ingredients(in, type_ingredient_names, name)) {
179 return false;
181 if (contains_key(Type_ordinal, name)
182 && contains_key(Type, get(Type_ordinal, name))) {
183 const type_info& previous_info = get(Type, get(Type_ordinal, name));
184 // we've already seen this container; make sure type ingredients match
185 if (!type_ingredients_match(type_ingredient_names, previous_info.type_ingredient_names)) {
186 raise << "headers of " << command << " '" << name << "' must use identical type ingredients\n" << end();
187 return false;
189 return true;
191 // we haven't seen this container before
192 if (!contains_key(Type_ordinal, name) || get(Type_ordinal, name) == 0)
193 put(Type_ordinal, name, Next_type_ordinal++);
194 type_info& info = get_or_insert(Type, get(Type_ordinal, name));
195 info.type_ingredient_names.swap(type_ingredient_names);
196 return true;
199 bool slurp_type_ingredients(istream& in, map<string, type_ordinal>& out, const string& container_name) {
200 int next_type_ordinal = START_TYPE_INGREDIENTS;
201 while (has_data(in)) {
202 string curr = slurp_until(in, ':');
203 if (curr.empty()) {
204 raise << container_name << ": empty type ingredients not permitted\n" << end();
205 return false;
207 if (!starts_with(curr, "_")) {
208 raise << container_name << ": type ingredient '" << curr << "' must begin with an underscore\n" << end();
209 return false;
211 if (out.find(curr) != out.end()) {
212 raise << container_name << ": can't repeat type ingredient name'" << curr << "' in a single container definition\n" << end();
213 return false;
215 put(out, curr, next_type_ordinal++);
217 return true;
220 bool type_ingredients_match(const map<string, type_ordinal>& a, const map<string, type_ordinal>& b) {
221 if (SIZE(a) != SIZE(b)) return false;
222 for (map<string, type_ordinal>::const_iterator p = a.begin(); p != a.end(); ++p) {
223 if (!contains_key(b, p->first)) return false;
224 if (p->second != get(b, p->first)) return false;
226 return true;
229 :(before "End insert_container Special-cases")
230 // check for use of type ingredients
231 else if (is_type_ingredient_name(type->name)) {
232 type->value = get(info.type_ingredient_names, type->name);
234 :(code)
235 bool is_type_ingredient_name(const string& type) {
236 return starts_with(type, "_");
239 :(before "End Container Type Checks")
240 if (type->value >= START_TYPE_INGREDIENTS
241 && (type->value - START_TYPE_INGREDIENTS) < SIZE(get(Type, type->value).type_ingredient_names))
242 return;
244 :(code)
245 void test_size_of_shape_shifting_exclusive_container() {
246 run(
247 "exclusive-container foo:_t [\n"
248 " x:_t\n"
249 " y:num\n"
250 "]\n"
251 "def main [\n"
252 " 1:foo:num <- merge 0/x, 34\n"
253 " 3:foo:point <- merge 0/x, 15, 16\n"
254 " 6:foo:point <- merge 1/y, 23\n"
255 "]\n"
257 CHECK_TRACE_CONTENTS(
258 "run: {1: (\"foo\" \"number\")} <- merge {0: \"literal\", \"x\": ()}, {34: \"literal\"}\n"
259 "mem: storing 0 in location 1\n"
260 "mem: storing 34 in location 2\n"
261 "run: {3: (\"foo\" \"point\")} <- merge {0: \"literal\", \"x\": ()}, {15: \"literal\"}, {16: \"literal\"}\n"
262 "mem: storing 0 in location 3\n"
263 "mem: storing 15 in location 4\n"
264 "mem: storing 16 in location 5\n"
265 "run: {6: (\"foo\" \"point\")} <- merge {1: \"literal\", \"y\": ()}, {23: \"literal\"}\n"
266 "mem: storing 1 in location 6\n"
267 "mem: storing 23 in location 7\n"
268 "run: return\n"
270 // no other stores
271 CHECK_EQ(trace_count_prefix("mem", "storing"), 7);
274 :(before "End variant_type Special-cases")
275 if (contains_type_ingredient(element))
276 replace_type_ingredients(element.type, type->right, info, " while computing variant type of exclusive-container");
278 :(code)
279 void test_get_on_shape_shifting_container() {
280 run(
281 "container foo:_t [\n"
282 " x:_t\n"
283 " y:num\n"
284 "]\n"
285 "def main [\n"
286 " 1:foo:point <- merge 14, 15, 16\n"
287 " 4:num <- get 1:foo:point, y:offset\n"
288 "]\n"
290 CHECK_TRACE_CONTENTS(
291 "mem: storing 16 in location 4\n"
295 void test_get_on_shape_shifting_container_2() {
296 run(
297 "container foo:_t [\n"
298 " x:_t\n"
299 " y:num\n"
300 "]\n"
301 "def main [\n"
302 " 1:foo:point <- merge 14, 15, 16\n"
303 " 4:point <- get 1:foo:point, x:offset\n"
304 "]\n"
306 CHECK_TRACE_CONTENTS(
307 "mem: storing 14 in location 4\n"
308 "mem: storing 15 in location 5\n"
312 void test_get_on_shape_shifting_container_3() {
313 run(
314 "container foo:_t [\n"
315 " x:_t\n"
316 " y:num\n"
317 "]\n"
318 "def main [\n"
319 " 1:num/alloc-id, 2:num <- copy 0, 34\n"
320 " 3:foo:&:point <- merge 1:&:point, 48\n"
321 " 6:&:point <- get 1:foo:&:point, x:offset\n"
322 "]\n"
324 CHECK_TRACE_CONTENTS(
325 "mem: storing 0 in location 6\n"
326 "mem: storing 34 in location 7\n"
330 void test_get_on_shape_shifting_container_inside_container() {
331 run(
332 "container foo:_t [\n"
333 " x:_t\n"
334 " y:num\n"
335 "]\n"
336 "container bar [\n"
337 " x:foo:point\n"
338 " y:num\n"
339 "]\n"
340 "def main [\n"
341 " 1:bar <- merge 14, 15, 16, 17\n"
342 " 5:num <- get 1:bar, 1:offset\n"
343 "]\n"
345 CHECK_TRACE_CONTENTS(
346 "mem: storing 17 in location 5\n"
350 void test_get_on_complex_shape_shifting_container() {
351 run(
352 "container foo:_a:_b [\n"
353 " x:_a\n"
354 " y:_b\n"
355 "]\n"
356 "def main [\n"
357 " 1:text <- new [abc]\n"
358 " {3: (foo number (address array character))} <- merge 34/x, 1:text/y\n"
359 " 6:text <- get {3: (foo number (address array character))}, y:offset\n"
360 " 8:bool <- equal 1:text, 6:text\n"
361 "]\n"
363 CHECK_TRACE_CONTENTS(
364 "mem: storing 1 in location 8\n"
368 :(before "End element_type Special-cases")
369 replace_type_ingredients(element, type, info, " while computing element type of container");
371 :(before "End size_of(type) Non-atom Special-cases")
372 assert(type->left->atom);
373 if (!contains_key(Type, type->left->value)) {
374 raise << "no such type " << type->left->value << '\n' << end();
375 return 0;
377 type_info t = get(Type, type->left->value);
378 if (t.kind == CONTAINER) {
379 // size of a container is the sum of the sizes of its elements
380 int result = 0;
381 for (int i = 0; i < SIZE(t.elements); ++i) {
382 // todo: strengthen assertion to disallow mutual type recursion
383 if (get_base_type(t.elements.at(i).type)->value == get_base_type(type)->value) {
384 raise << "container " << t.name << " can't include itself as a member\n" << end();
385 return 0;
387 result += size_of(element_type(type, i));
389 return result;
391 if (t.kind == EXCLUSIVE_CONTAINER) {
392 // size of an exclusive container is the size of its largest variant
393 // (So like containers, it can't contain arrays.)
394 int result = 0;
395 for (int i = 0; i < SIZE(t.elements); ++i) {
396 reagent tmp;
397 tmp.type = new type_tree(*type);
398 int size = size_of(variant_type(tmp, i));
399 if (size > result) result = size;
401 // ...+1 for its tag.
402 return result+1;
405 :(code)
406 void test_complex_shape_shifting_exclusive_container() {
407 run(
408 "exclusive-container foo:_a [\n"
409 " x:_a\n"
410 " y:num\n"
411 "]\n"
412 "def main [\n"
413 " 1:text <- new [abc]\n"
414 " 3:foo:point <- merge 0/variant, 34/xx, 35/xy\n"
415 " 10:point, 20:bool <- maybe-convert 3:foo:point, 0/variant\n"
416 "]\n"
418 CHECK_TRACE_CONTENTS(
419 "mem: storing 1 in location 20\n"
420 "mem: storing 35 in location 11\n"
424 bool contains_type_ingredient(const reagent& x) {
425 return contains_type_ingredient(x.type);
428 bool contains_type_ingredient(const type_tree* type) {
429 if (!type) return false;
430 if (type->atom) return type->value >= START_TYPE_INGREDIENTS;
431 return contains_type_ingredient(type->left) || contains_type_ingredient(type->right);
434 void replace_type_ingredients(reagent& element, const type_tree* caller_type, const type_info& info, const string& location_for_error_messages) {
435 if (contains_type_ingredient(element)) {
436 if (!caller_type->right)
437 raise << "illegal type " << names_to_string(caller_type) << " seems to be missing a type ingredient or three" << location_for_error_messages << '\n' << end();
438 replace_type_ingredients(element.type, caller_type->right, info, location_for_error_messages);
442 // replace all type_ingredients in element_type with corresponding elements of callsite_type
443 void replace_type_ingredients(type_tree* element_type, const type_tree* callsite_type, const type_info& container_info, const string& location_for_error_messages) {
444 if (!callsite_type) return; // error but it's already been raised above
445 if (!element_type) return;
446 if (!element_type->atom) {
447 if (element_type->right == NULL && is_type_ingredient(element_type->left)) {
448 int type_ingredient_index = to_type_ingredient_index(element_type->left);
449 if (corresponding(callsite_type, type_ingredient_index, is_final_type_ingredient(type_ingredient_index, container_info))->right) {
450 // replacing type ingredient at end of list, and replacement is a non-degenerate compound type -- (a b) but not (a)
451 replace_type_ingredient_at(type_ingredient_index, element_type, callsite_type, container_info, location_for_error_messages);
452 return;
455 replace_type_ingredients(element_type->left, callsite_type, container_info, location_for_error_messages);
456 replace_type_ingredients(element_type->right, callsite_type, container_info, location_for_error_messages);
457 return;
459 if (is_type_ingredient(element_type))
460 replace_type_ingredient_at(to_type_ingredient_index(element_type), element_type, callsite_type, container_info, location_for_error_messages);
463 const type_tree* corresponding(const type_tree* type, int index, bool final) {
464 for (const type_tree* curr = type; curr; curr = curr->right, --index) {
465 assert_for_now(!curr->atom);
466 if (index == 0)
467 return final ? curr : curr->left;
469 assert_for_now(false);
472 bool is_type_ingredient(const type_tree* type) {
473 return type->atom && type->value >= START_TYPE_INGREDIENTS;
476 int to_type_ingredient_index(const type_tree* type) {
477 assert(type->atom);
478 return type->value-START_TYPE_INGREDIENTS;
481 void replace_type_ingredient_at(const int type_ingredient_index, type_tree* element_type, const type_tree* callsite_type, const type_info& container_info, const string& location_for_error_messages) {
482 if (!has_nth_type(callsite_type, type_ingredient_index)) {
483 raise << "illegal type " << names_to_string(callsite_type) << " seems to be missing a type ingredient or three" << location_for_error_messages << '\n' << end();
484 return;
486 *element_type = *nth_type_ingredient(callsite_type, type_ingredient_index, container_info);
489 const type_tree* nth_type_ingredient(const type_tree* callsite_type, int type_ingredient_index, const type_info& container_info) {
490 bool final = is_final_type_ingredient(type_ingredient_index, container_info);
491 const type_tree* curr = callsite_type;
492 for (int i = 0; i < type_ingredient_index; ++i) {
493 assert(curr);
494 assert(!curr->atom);
495 //? cerr << "type ingredient " << i << " is " << to_string(curr->left) << '\n';
496 curr = curr->right;
498 assert(curr);
499 if (curr->atom) return curr;
500 if (!final) return curr->left;
501 if (!curr->right) return curr->left;
502 return curr;
505 bool is_final_type_ingredient(int type_ingredient_index, const type_info& container_info) {
506 for (map<string, type_ordinal>::const_iterator p = container_info.type_ingredient_names.begin();
507 p != container_info.type_ingredient_names.end();
508 ++p) {
509 if (p->second > START_TYPE_INGREDIENTS+type_ingredient_index) return false;
511 return true;
514 :(before "End Unit Tests")
515 void test_replace_type_ingredients_entire() {
516 run("container foo:_elem [\n"
517 " x:_elem\n"
518 " y:num\n"
519 "]\n");
520 reagent callsite("x:foo:point");
521 reagent element = element_type(callsite.type, 0);
522 CHECK_EQ(to_string(element), "{x: \"point\"}");
525 void test_replace_type_ingredients_tail() {
526 run("container foo:_elem [\n"
527 " x:_elem\n"
528 "]\n"
529 "container bar:_elem [\n"
530 " x:foo:_elem\n"
531 "]\n");
532 reagent callsite("x:bar:point");
533 reagent element = element_type(callsite.type, 0);
534 CHECK_EQ(to_string(element), "{x: (\"foo\" \"point\")}");
537 void test_replace_type_ingredients_head_tail_multiple() {
538 run("container foo:_elem [\n"
539 " x:_elem\n"
540 "]\n"
541 "container bar:_elem [\n"
542 " x:foo:_elem\n"
543 "]\n");
544 reagent callsite("x:bar:address:array:character");
545 reagent element = element_type(callsite.type, 0);
546 CHECK_EQ(to_string(element), "{x: (\"foo\" \"address\" \"array\" \"character\")}");
549 void test_replace_type_ingredients_head_middle() {
550 run("container foo:_elem [\n"
551 " x:_elem\n"
552 "]\n"
553 "container bar:_elem [\n"
554 " x:foo:_elem:num\n"
555 "]\n");
556 reagent callsite("x:bar:address");
557 reagent element = element_type(callsite.type, 0);
558 CHECK_EQ(to_string(element), "{x: (\"foo\" \"address\" \"number\")}");
561 void test_replace_last_type_ingredient_with_multiple() {
562 run("container foo:_a:_b [\n"
563 " x:_a\n"
564 " y:_b\n"
565 "]\n");
566 reagent callsite("{f: (foo number (address array character))}");
567 reagent element1 = element_type(callsite.type, 0);
568 CHECK_EQ(to_string(element1), "{x: \"number\"}");
569 reagent element2 = element_type(callsite.type, 1);
570 CHECK_EQ(to_string(element2), "{y: (\"address\" \"array\" \"character\")}");
573 void test_replace_last_type_ingredient_inside_compound() {
574 run("container foo:_a:_b [\n"
575 " {x: (bar _a (address _b))}\n"
576 "]\n");
577 reagent callsite("f:foo:number:array:character");
578 reagent element = element_type(callsite.type, 0);
579 CHECK_EQ(names_to_string_without_quotes(element.type), "(bar number (address array character))");
582 void test_replace_middle_type_ingredient_with_multiple() {
583 run("container foo:_a:_b:_c [\n"
584 " x:_a\n"
585 " y:_b\n"
586 " z:_c\n"
587 "]\n");
588 reagent callsite("{f: (foo number (address array character) boolean)}");
589 reagent element1 = element_type(callsite.type, 0);
590 CHECK_EQ(to_string(element1), "{x: \"number\"}");
591 reagent element2 = element_type(callsite.type, 1);
592 CHECK_EQ(to_string(element2), "{y: (\"address\" \"array\" \"character\")}");
593 reagent element3 = element_type(callsite.type, 2);
594 CHECK_EQ(to_string(element3), "{z: \"boolean\"}");
597 void test_replace_middle_type_ingredient_with_multiple2() {
598 run("container foo:_key:_value [\n"
599 " key:_key\n"
600 " value:_value\n"
601 "]\n");
602 reagent callsite("{f: (foo (address array character) number)}");
603 reagent element = element_type(callsite.type, 0);
604 CHECK_EQ(to_string(element), "{key: (\"address\" \"array\" \"character\")}");
607 void test_replace_middle_type_ingredient_with_multiple3() {
608 run("container foo_table:_key:_value [\n"
609 " data:&:@:foo_table_row:_key:_value\n"
610 "]\n"
611 "\n"
612 "container foo_table_row:_key:_value [\n"
613 " key:_key\n"
614 " value:_value\n"
615 "]\n");
616 reagent callsite("{f: (foo_table (address array character) number)}");
617 reagent element = element_type(callsite.type, 0);
618 CHECK_EQ(to_string(element), "{data: (\"address\" \"array\" \"foo_table_row\" (\"address\" \"array\" \"character\") \"number\")}");
621 :(code)
622 bool has_nth_type(const type_tree* base, int n) {
623 assert(n >= 0);
624 if (!base) return false;
625 if (n == 0) return true;
626 return has_nth_type(base->right, n-1);
629 void test_get_on_shape_shifting_container_error() {
630 Hide_errors = true;
631 run(
632 "container foo:_t [\n"
633 " x:_t\n"
634 " y:num\n"
635 "]\n"
636 "def main [\n"
637 " 1:foo:point <- merge 14, 15, 16\n"
638 " 10:num <- get 1:foo, 1:offset\n"
639 "]\n"
641 CHECK_TRACE_CONTENTS(
642 "error: illegal type \"foo\" seems to be missing a type ingredient or three while computing element type of container\n"
644 // todo: improve error message
647 void test_typos_in_container_definitions() {
648 Hide_errors = true;
649 run(
650 "container foo:_t [\n"
651 " x:adress:_t # typo\n"
652 "]\n"
653 "def main [\n"
654 " local-scope\n"
655 " x:address:foo:num <- new {(foo num): type}\n"
656 "]\n"
658 // no crash
661 void test_typos_in_recipes() {
662 Hide_errors = true;
663 run(
664 "def foo [\n"
665 " local-scope\n"
666 " x:adress:array:number <- copy null # typo\n"
667 "]\n"
669 // shouldn't crash
672 //:: 'merge' on shape-shifting containers
674 void test_merge_check_shape_shifting_container_containing_exclusive_container() {
675 run(
676 "container foo:_elem [\n"
677 " x:num\n"
678 " y:_elem\n"
679 "]\n"
680 "exclusive-container bar [\n"
681 " x:num\n"
682 " y:num\n"
683 "]\n"
684 "def main [\n"
685 " 1:foo:bar <- merge 23, 1/y, 34\n"
686 "]\n"
688 CHECK_TRACE_CONTENTS(
689 "mem: storing 23 in location 1\n"
690 "mem: storing 1 in location 2\n"
691 "mem: storing 34 in location 3\n"
693 CHECK_TRACE_COUNT("error", 0);
696 void test_merge_check_shape_shifting_container_containing_exclusive_container_2() {
697 Hide_errors = true;
698 run(
699 "container foo:_elem [\n"
700 " x:num\n"
701 " y:_elem\n"
702 "]\n"
703 "exclusive-container bar [\n"
704 " x:num\n"
705 " y:num\n"
706 "]\n"
707 "def main [\n"
708 " 1:foo:bar <- merge 23, 1/y, 34, 35\n"
709 "]\n"
711 CHECK_TRACE_CONTENTS(
712 "error: main: too many ingredients in '1:foo:bar <- merge 23, 1/y, 34, 35'\n"
716 void test_merge_check_shape_shifting_exclusive_container_containing_container() {
717 run(
718 "exclusive-container foo:_elem [\n"
719 " x:num\n"
720 " y:_elem\n"
721 "]\n"
722 "container bar [\n"
723 " x:num\n"
724 " y:num\n"
725 "]\n"
726 "def main [\n"
727 " 1:foo:bar <- merge 1/y, 23, 34\n"
728 "]\n"
730 CHECK_TRACE_CONTENTS(
731 "mem: storing 1 in location 1\n"
732 "mem: storing 23 in location 2\n"
733 "mem: storing 34 in location 3\n"
735 CHECK_TRACE_COUNT("error", 0);
738 void test_merge_check_shape_shifting_exclusive_container_containing_container_2() {
739 run(
740 "exclusive-container foo:_elem [\n"
741 " x:num\n"
742 " y:_elem\n"
743 "]\n"
744 "container bar [\n"
745 " x:num\n"
746 " y:num\n"
747 "]\n"
748 "def main [\n"
749 " 1:foo:bar <- merge 0/x, 23\n"
750 "]\n"
752 CHECK_TRACE_COUNT("error", 0);
755 void test_merge_check_shape_shifting_exclusive_container_containing_container_3() {
756 Hide_errors = true;
757 run(
758 "exclusive-container foo:_elem [\n"
759 " x:num\n"
760 " y:_elem\n"
761 "]\n"
762 "container bar [\n"
763 " x:num\n"
764 " y:num\n"
765 "]\n"
766 "def main [\n"
767 " 1:foo:bar <- merge 1/y, 23\n"
768 "]\n"
770 CHECK_TRACE_CONTENTS(
771 "error: main: too few ingredients in '1:foo:bar <- merge 1/y, 23'\n"