:(before "End Mu Types Initialization")
{
type_number tmp = Type_number["integer-or-point"] = Next_type_number++;
Type[tmp].size = 2;
Type[tmp].kind = exclusive_container;
Type[tmp].name = "integer-or-point";
vector<type_number> t1;
t1.push_back(integer);
Type[tmp].elements.push_back(t1);
vector<type_number> t2;
t2.push_back(point);
Type[tmp].elements.push_back(t2);
Type[tmp].element_names.push_back("i");
Type[tmp].element_names.push_back("p");
}
:(scenario copy_exclusive_container)
recipe main [
1:integer <- copy 1:literal
2:integer <- copy 34:literal
3:integer <- copy 35:literal
4:integer-or-point <- copy 1:integer-or-point
]
+mem: storing 1 in location 4
+mem: storing 34 in location 5
+mem: storing 35 in location 6
:(before "End size_of(types) Cases")
if (t.kind == exclusive_container) {
size_t result = 0;
for (index_t i = 0; i < t.size; ++i) {
size_t tmp = size_of(t.elements[i]);
if (tmp > result) result = tmp;
}
return result+1;
}
:(before "End Mu Types Initialization")
Type_number["variant"] = 0;
:(scenario maybe_convert)
recipe main [
12:integer <- copy 1:literal
13:integer <- copy 35:literal
14:integer <- copy 36:literal
20:address:point <- maybe-convert 12:integer-or-point, 1:variant
]
+mem: storing 13 in location 20
:(scenario maybe_convert_fail)
recipe main [
12:integer <- copy 1:literal
13:integer <- copy 35:literal
14:integer <- copy 36:literal
20:address:point <- maybe-convert 12:integer-or-point, 0:variant
]
+mem: storing 0 in location 20
:(before "End Primitive Recipe Declarations")
MAYBE_CONVERT,
:(before "End Primitive Recipe Numbers")
Recipe_number["maybe-convert"] = MAYBE_CONVERT;
:(before "End Primitive Recipe Implementations")
case MAYBE_CONVERT: {
trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name;
reagent base = canonize(current_instruction().ingredients[0]);
index_t base_address = base.value;
type_number base_type = base.types[0];
assert(Type[base_type].kind == exclusive_container);
trace("run") << "ingredient 1 is " << current_instruction().ingredients[1].name;
assert(isa_literal(current_instruction().ingredients[1]));
index_t tag = current_instruction().ingredients[1].value;
vector<long long int> result;
if (tag == static_cast<index_t>(Memory[base_address])) {
result.push_back(base_address+1);
}
else {
result.push_back(0);
}
write_memory(current_instruction().products[0], result);
break;
}