about summary refs log tree commit diff stats
path: root/cpp/017and-record
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/017and-record')
-rw-r--r--cpp/017and-record27
1 files changed, 27 insertions, 0 deletions
diff --git a/cpp/017and-record b/cpp/017and-record
new file mode 100644
index 00000000..a9a3c0a0
--- /dev/null
+++ b/cpp/017and-record
@@ -0,0 +1,27 @@
+// Support for records.
+:(before "End Mu Types")
+// We'll use this record as a running example, with two fields: an integer and
+// a boolean.
+int integer_boolean = Type_number["integer-boolean"] = Next_type_number++;
+Type[integer_boolean].size = 2;
+Type[integer_boolean].is_record = true;
+vector<type_number> i;
+i.push_back(integer);
+Type[integer_boolean].elements.push_back(i);
+vector<type_number> b;
+b.push_back(boolean);
+Type[integer_boolean].elements.push_back(b);
+
+// Records can be copied around with a single instruction just like integers,
+// no matter how large they are.
+:(scenario copy_multiple_locations)
+recipe main [
+  1:integer <- copy 34:literal
+  2:boolean <- copy 0:literal
+  3:integer-boolean <- copy 1:integer-boolean
+]
++run: ingredient 0 is 1
++mem: location 1 is 34
++mem: location 2 is 0
++mem: storing in location 3
++mem: storing in location 4