about summary refs log tree commit diff stats
path: root/cpp/010vm
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-16 10:35:49 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-16 10:35:49 -0700
commitdb5c9550e972d114aaabb95b14cfd1e3ea185349 (patch)
tree9217134d1154e45f5375f94c9b5788530fbf8cb7 /cpp/010vm
parentd6852155e5308e2bb347402bf9e069c7153c2319 (diff)
downloadmu-db5c9550e972d114aaabb95b14cfd1e3ea185349.tar.gz
1069 - rename record/field to container/element
This seems more obvious to laypeople.

I've also come up with a design for sum types: I'm going to call them
exclusive containers. You call 'get' on containers, 'index' on arrays,
and 'maybe-convert' on exclusive containers (as well as tagged types,
but that's even later).
Diffstat (limited to 'cpp/010vm')
-rw-r--r--cpp/010vm32
1 files changed, 22 insertions, 10 deletions
diff --git a/cpp/010vm b/cpp/010vm
index 032e1874..df84102b 100644
--- a/cpp/010vm
+++ b/cpp/010vm
@@ -89,6 +89,8 @@ void setup_types() {
   Type[boolean].name = "boolean";
   int character = Type_number["character"] = Next_type_number++;
   Type[character].name = "character";
+  // Array types are a special modifier to any other type. For example,
+  // array:integer or array:address:boolean.
   int array = Type_number["array"] = Next_type_number++;
   Type[array].name = "array";
   // End Mu Types Initialization
@@ -97,20 +99,30 @@ void setup_types() {
 setup_types();
 
 :(before "End Types")
-// You can construct arbitrary new types. Types are either 'records', containing
-// 'fields' of other types, or 'array's of a single type repeated over and over.
+// You can construct arbitrary new types. New types are either 'containers'
+// with multiple 'elements' of other types, or 'exclusive containers' containing
+// one of multiple 'variants'. (These are similar to C structs and unions,
+// respectively, though exclusive containers implicitly include a tag element
+// recording which variant they should be interpreted as.)
 //
-// For example:
-//  storing bank balance next to a person's name might require a record, and
-//  high scores in a game might need an array of numbers.
+// For example, storing bank balance and name for an account might require a
+// container, but if bank accounts may be either for individuals or groups,
+// with different properties for each, that may require an exclusive container
+// whose variants are individual-account and joint-account containers.
+enum kind_of_type {
+  primitive,
+  container,
+  exclusive_container
+};
+
 struct type_info {
   string name;
-  bool is_record;
-  size_t size;  // only if is_record; primitives and addresses have size 1 while arrays are dynamic
-  vector<vector<type_number> > elements;  // only if is_record
-  vector<string> element_names;  // only if is_record
+  kind_of_type kind;
+  size_t size;  // only if type is not primitive; primitives and addresses have size 1 (except arrays are dynamic)
+  vector<vector<type_number> > elements;
+  vector<string> element_names;
   // End type_info Fields
-  type_info() :is_record(false), size(0) {}
+  type_info() :kind(primitive), size(0) {}
 };
 
 :(before "End Globals")