about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--030container.cc27
-rw-r--r--034exclusive_container.cc17
2 files changed, 44 insertions, 0 deletions
diff --git a/030container.cc b/030container.cc
index cff5dcf1..551a76a4 100644
--- a/030container.cc
+++ b/030container.cc
@@ -371,6 +371,33 @@ void check_container_field_types() {
   }
 }
 
+//:: Construct types out of their constituent fields. Doesn't currently do
+//:: type-checking but *does* match sizes.
+:(before "End Primitive Recipe Declarations")
+MERGE,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["merge"] = MERGE;
+:(before "End Primitive Recipe Implementations")
+case MERGE: {
+  products.resize(1);
+  for (long long int i = 0; i < SIZE(ingredients); ++i)
+    for (long long int j = 0; j < SIZE(ingredients.at(i)); ++j)
+      products.at(0).push_back(ingredients.at(i).at(j));
+  break;
+}
+
+:(scenario merge)
+container foo [
+  x:number
+  y:number
+]
+
+recipe main [
+  1:foo <- merge 3:literal, 4:literal
+]
++mem: storing 3 in location 1
++mem: storing 4 in location 2
+
 //:: helpers
 
 :(code)
diff --git a/034exclusive_container.cc b/034exclusive_container.cc
index 7455cf30..08aaf3f7 100644
--- a/034exclusive_container.cc
+++ b/034exclusive_container.cc
@@ -126,3 +126,20 @@ exclusive-container foo [
 else if (command == "exclusive-container") {
   insert_container(command, exclusive_container, in);
 }
+
+//:: 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:literal
+  2:foo <- merge 0:literal/x, 1:number
+  4:foo <- merge 1:literal/x, 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