about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-17 20:36:25 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-17 20:36:25 -0700
commit0acfaaef6a402d332f2c1e83424e9d4d0ada7455 (patch)
tree4c2912b33a27bda361d2b4227954e84801eb366b
parent7f931ef0f27f2815ca435bd63f3aa77329c2f096 (diff)
downloadmu-0acfaaef6a402d332f2c1e83424e9d4d0ada7455.tar.gz
1088 - start porting the 'buffer' type
-rw-r--r--cpp/.traces/init-buffer-allocates204
-rw-r--r--cpp/032array4
-rw-r--r--cpp/034exclusive_container1
-rw-r--r--cpp/050scenario5
-rw-r--r--cpp/060string.mu17
5 files changed, 230 insertions, 1 deletions
diff --git a/cpp/.traces/init-buffer-allocates b/cpp/.traces/init-buffer-allocates
new file mode 100644
index 00000000..2730df91
--- /dev/null
+++ b/cpp/.traces/init-buffer-allocates
@@ -0,0 +1,204 @@
+parse/0: instruction: 33
+parse/0:   ingredient: {name: "location", value: 0, type: 0, properties: ["location": "type"]}
+parse/0:   ingredient: {name: "30", value: 0, type: 0, properties: ["30": "literal"]}
+parse/0:   product: {name: "default-space", value: 0, type: 2-0, properties: ["default-space": "address":"space"]}
+parse/0: instruction: 100
+parse/0:   ingredient: {name: "3", value: 0, type: 0, properties: ["3": "literal"]}
+parse/0:   product: {name: "x", value: 0, type: 2-9, properties: ["x": "address":"buffer"]}
+parse/0: instruction: 19
+parse/0:   ingredient: {name: "x", value: 0, type: 2-9, properties: ["x": "address":"buffer", "deref": ]}
+parse/0:   ingredient: {name: "data", value: 0, type: 0, properties: ["data": "offset"]}
+parse/0:   product: {name: "s1", value: 0, type: 2-5-4, properties: ["s1": "address":"array":"character"]}
+parse/0: instruction: 23
+parse/0:   ingredient: {name: "s1", value: 0, type: 2-5-4, properties: ["s1": "address":"array":"character", "deref": ]}
+parse/0:   product: {name: "len1", value: 0, type: 1, properties: ["len1": "integer"]}
+parse/0: instruction: 99
+parse/0:   ingredient: {name: "len1", value: 0, type: 1, properties: ["len1": "integer"]}
+parse/0: instruction: 99
+parse/0:   ingredient: {name: " ", value: 0, type: 0, properties: [" ": "literal-string"]}
+parse/0: instruction: 99
+parse/0:   ingredient: {name: "x", value: 0, type: 2-9, properties: ["x": "address":"buffer"]}
+parse/0: instruction: 99
+parse/0:   ingredient: {name: "
+", value: 0, type: 0, properties: ["
+": "literal-string"]}
+parse/0: instruction: 100
+parse/0:   ingredient: {name: "4", value: 0, type: 0, properties: ["4": "literal"]}
+parse/0:   product: {name: "y", value: 0, type: 2-9, properties: ["y": "address":"buffer"]}
+parse/0: instruction: 19
+parse/0:   ingredient: {name: "y", value: 0, type: 2-9, properties: ["y": "address":"buffer", "deref": ]}
+parse/0:   ingredient: {name: "data", value: 0, type: 0, properties: ["data": "offset"]}
+parse/0:   product: {name: "s2", value: 0, type: 2-5-4, properties: ["s2": "address":"array":"character"]}
+parse/0: instruction: 23
+parse/0:   ingredient: {name: "s2", value: 0, type: 2-5-4, properties: ["s2": "address":"array":"character", "deref": ]}
+parse/0:   product: {name: "len2", value: 0, type: 1, properties: ["len2": "integer"]}
+parse/0: instruction: 99
+parse/0:   ingredient: {name: "len2", value: 0, type: 1, properties: ["len2": "integer"]}
+parse/0: instruction: 99
+parse/0:   ingredient: {name: " ", value: 0, type: 0, properties: [" ": "literal-string"]}
+parse/0: instruction: 99
+parse/0:   ingredient: {name: "y", value: 0, type: 2-9, properties: ["y": "address":"buffer"]}
+parse/0: instruction: 99
+parse/0:   ingredient: {name: "
+", value: 0, type: 0, properties: ["
+": "literal-string"]}
+parse/0: instruction: 3
+parse/0:   ingredient: {name: "y", value: 0, type: 2-9, properties: ["y": "address":"buffer"]}
+parse/0:   ingredient: {name: "x", value: 0, type: 2-9, properties: ["x": "address":"buffer"]}
+parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer", "raw": ]}
+new/0: location -> 1
+name/0: assign x 1
+name/0: element data of type buffer is at offset 1
+name/0: assign s1 2
+name/0: assign len1 3
+name/0: assign y 4
+name/0: element data of type buffer is at offset 1
+name/0: assign s2 5
+name/0: assign len2 6
+after-brace/0: recipe test-init-buffer-allocates
+after-brace/0: new ...
+after-brace/0: init-buffer ...
+after-brace/0: get ...
+after-brace/0: length ...
+after-brace/0: $print ...
+after-brace/0: $print ...
+after-brace/0: $print ...
+after-brace/0: $print ...
+after-brace/0: init-buffer ...
+after-brace/0: get ...
+after-brace/0: length ...
+after-brace/0: $print ...
+after-brace/0: $print ...
+after-brace/0: $print ...
+after-brace/0: $print ...
+after-brace/0: subtract ...
+run/0: instruction test-init-buffer-allocates/0
+mem/0: new alloc: 1000
+mem/0: array size is 30
+run/0: instruction test-init-buffer-allocates/1
+run/0: instruction init-buffer/0
+mem/0: new alloc: 1030
+mem/0: array size is 30
+run/0: instruction init-buffer/1
+mem/0: new alloc: 1060
+mem/0: storing 1060 in location 1032
+run/0: instruction init-buffer/2
+run/0: ingredient 0 is result
+mem/0: location 1032 is 1060
+run/0: ingredient 1 is length
+run/0: address to copy is 1060
+run/0: product 0 is 1060
+mem/0: storing 1060 in location 1033
+run/0: instruction init-buffer/3
+run/0: ingredient 0 is 0
+mem/0: location 1033 is 1060
+mem/0: storing 0 in location 1060
+run/0: instruction init-buffer/4
+run/0: ingredient 0 is result
+mem/0: location 1032 is 1060
+run/0: ingredient 1 is data
+run/0: address to copy is 1061
+run/0: product 0 is 1061
+mem/0: storing 1061 in location 1034
+run/0: instruction init-buffer/5
+run/0: product 0 is 3
+mem/0: storing 3 in location 1035
+run/0: instruction init-buffer/6
+mem/0: new alloc: 1062
+mem/0: location 1034 is 1061
+mem/0: storing 1062 in location 1061
+mem/0: location 1035 is 3
+mem/0: array size is 3
+run/0: instruction init-buffer/7
+mem/0: location 1032 is 1060
+run/0: result 0 is 1060
+mem/0: storing 1060 in location 1002
+run/0: instruction test-init-buffer-allocates/2
+run/0: ingredient 0 is x
+mem/0: location 1002 is 1060
+run/0: ingredient 1 is data
+run/0: address to copy is 1061
+run/0: its type is 2
+mem/0: location 2062 is 0
+run/0: product 0 is 0
+mem/0: storing 0 in location 1003
+run/0: instruction test-init-buffer-allocates/3
+mem/0: location 1003 is 0
+mem/0: storing 0 in location 1004
+run/0: instruction test-init-buffer-allocates/4
+mem/0: location 1004 is 0
+run/0: $print: 0
+run/0: instruction test-init-buffer-allocates/5
+run/0: $print:  
+run/0: instruction test-init-buffer-allocates/6
+mem/0: location 1002 is 1060
+run/0: $print: 1060
+run/0: instruction test-init-buffer-allocates/7
+run/0: $print: 
+run/0: instruction test-init-buffer-allocates/8
+run/0: instruction init-buffer/0
+mem/0: new alloc: 1065
+mem/0: array size is 30
+run/0: instruction init-buffer/1
+mem/0: new alloc: 1095
+mem/0: storing 1095 in location 1067
+run/0: instruction init-buffer/2
+run/0: ingredient 0 is result
+mem/0: location 1067 is 1095
+run/0: ingredient 1 is length
+run/0: address to copy is 1095
+run/0: product 0 is 1095
+mem/0: storing 1095 in location 1068
+run/0: instruction init-buffer/3
+run/0: ingredient 0 is 0
+mem/0: location 1068 is 1095
+mem/0: storing 0 in location 1095
+run/0: instruction init-buffer/4
+run/0: ingredient 0 is result
+mem/0: location 1067 is 1095
+run/0: ingredient 1 is data
+run/0: address to copy is 1096
+run/0: product 0 is 1096
+mem/0: storing 1096 in location 1069
+run/0: instruction init-buffer/5
+run/0: product 0 is 4
+mem/0: storing 4 in location 1070
+run/0: instruction init-buffer/6
+mem/0: new alloc: 1097
+mem/0: location 1069 is 1096
+mem/0: storing 1097 in location 1096
+mem/0: location 1070 is 4
+mem/0: array size is 4
+run/0: instruction init-buffer/7
+mem/0: location 1067 is 1095
+run/0: result 0 is 1095
+mem/0: storing 1095 in location 1005
+run/0: instruction test-init-buffer-allocates/9
+run/0: ingredient 0 is y
+mem/0: location 1005 is 1095
+run/0: ingredient 1 is data
+run/0: address to copy is 1096
+run/0: its type is 2
+mem/0: location 2097 is 0
+run/0: product 0 is 0
+mem/0: storing 0 in location 1006
+run/0: instruction test-init-buffer-allocates/10
+mem/0: location 1006 is 0
+mem/0: storing 0 in location 1007
+run/0: instruction test-init-buffer-allocates/11
+mem/0: location 1007 is 0
+run/0: $print: 0
+run/0: instruction test-init-buffer-allocates/12
+run/0: $print:  
+run/0: instruction test-init-buffer-allocates/13
+mem/0: location 1005 is 1095
+run/0: $print: 1095
+run/0: instruction test-init-buffer-allocates/14
+run/0: $print: 
+run/0: instruction test-init-buffer-allocates/15
+run/0: ingredient 0 is y
+mem/0: location 1005 is 1095
+run/0: ingredient 1 is x
+mem/0: location 1002 is 1060
+run/0: product 0 is 35
+mem/0: storing 35 in location 1
diff --git a/cpp/032array b/cpp/032array
index fbb5ed7b..a4f5ecba 100644
--- a/cpp/032array
+++ b/cpp/032array
@@ -1,4 +1,8 @@
 //: Arrays contain a variable number of elements of the same type.
+//:
+//: You can create arrays of containers, but containers can only contain
+//: elements of a fixed size, so you can't create containers containing arrays.
+//: Create containers containing addresses to arrays instead.
 
 :(scenario copy_array)
 # Arrays can be copied around with a single instruction just like integers,
diff --git a/cpp/034exclusive_container b/cpp/034exclusive_container
index e38433d6..8f9fe842 100644
--- a/cpp/034exclusive_container
+++ b/cpp/034exclusive_container
@@ -40,6 +40,7 @@ recipe main [
 :(before "End size_of(types) Cases")
 if (t.kind == exclusive_container) {
   // size of an exclusive container is the size of its largest variant
+  // (So like containers, it can't contain arrays.)
 //?   cout << "--- " << types[0] << ' ' << t.size << '\n'; //? 1
 //?   cout << "point: " << Type_number["point"] << " " << Type[Type_number["point"]].name << " " << Type[Type_number["point"]].size << '\n'; //? 1
 //?   cout << t.name << ' ' << t.size << ' ' << t.elements.size() << '\n'; //? 1
diff --git a/cpp/050scenario b/cpp/050scenario
index 9c29d971..199fd692 100644
--- a/cpp/050scenario
+++ b/cpp/050scenario
@@ -19,9 +19,12 @@ for (size_t i = 0; i < Scenarios.size(); ++i) {
   Trace_file = Scenarios[i].name;
   START_TRACING_UNTIL_END_OF_SCOPE
 //?   Trace_stream->dump_layer = "all"; //? 1
+//?   cout << "before: " << Memory[1] << '\n'; //? 1
+//?   Trace_stream->dump_layer = "all"; //? 1
 //?   cout << "Before:\n";  dump_memory(); //? 1
-//?   cout << Scenarios[i].to_run; //? 1
+//?   cout << Scenarios[i].to_run; //? 2
   run(Scenarios[i].to_run);
+//?   cout << "after: " << Memory[1] << '\n'; //? 1
 //?   cout << "After:\n";  dump_memory(); //? 1
   for (map<int, int>::iterator p = Scenarios[i].memory_expectations.begin();
        p != Scenarios[i].memory_expectations.end();
diff --git a/cpp/060string.mu b/cpp/060string.mu
index a437c24f..85ff65b6 100644
--- a/cpp/060string.mu
+++ b/cpp/060string.mu
@@ -96,3 +96,20 @@ scenario string-equal-common-lengths-but-distinct [
     3 <- 0  # abc != abd
   ]
 ]
+
+# A new type to help incrementally construct strings.
+container buffer [
+  length:integer
+  data:address:array:character
+]
+
+recipe init-buffer [
+  default-space:address:space <- new location:type, 30:literal
+  result:address:buffer <- new buffer:type
+  len:address:integer <- get-address result:address:buffer/deref, length:offset
+  len:address:integer/deref <- copy 0:literal
+  s:address:address:array:character <- get-address result:address:buffer/deref, data:offset
+  capacity:integer <- next-ingredient
+  s:address:address:array:character/deref <- new character:type, capacity:integer
+  reply result:address:buffer
+]