about summary refs log tree commit diff stats
path: root/cpp/017and-record
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-19 23:49:13 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-19 23:49:13 -0800
commitb291f85b8d0ece9312b066a84cbeca1b367fe85f (patch)
treee3e443337918a47ac2f3707b1b77957c34a6131d /cpp/017and-record
parent9dc2948276388d2ca6556f4a8d13d55406775ac7 (diff)
downloadmu-b291f85b8d0ece9312b066a84cbeca1b367fe85f.tar.gz
798 - start of record support
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