diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-02-22 00:15:14 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-02-22 00:15:14 -0800 |
commit | 6cc4621602ac00effcfedeeb01593d5e619db0f9 (patch) | |
tree | c14e34d1b0d29708a9064cc453ee1bffe26ed53d | |
parent | ab9e2eaee0e7361a9ea4cb65011873d44100ff51 (diff) | |
download | mu-6cc4621602ac00effcfedeeb01593d5e619db0f9.tar.gz |
814
-rw-r--r-- | cpp/.traces/copy_array | 4 | ||||
-rw-r--r-- | cpp/.traces/get_handles_record_fields | 30 | ||||
-rw-r--r-- | cpp/010vm | 4 | ||||
-rw-r--r-- | cpp/017record | 32 |
4 files changed, 67 insertions, 3 deletions
diff --git a/cpp/.traces/copy_array b/cpp/.traces/copy_array index ccdba2fc..62253d3e 100644 --- a/cpp/.traces/copy_array +++ b/cpp/.traces/copy_array @@ -11,8 +11,8 @@ parse/0: instruction: 1 parse/0: ingredient: {name: "16", type: 0} parse/0: product: {name: "4", type: 1} parse/0: instruction: 1 -parse/0: ingredient: {name: "1", type: 5} -parse/0: product: {name: "5", type: 5} +parse/0: ingredient: {name: "1", type: 6} +parse/0: product: {name: "5", type: 6} run/0: instruction 0 run/0: ingredient 0 is 3 mem/0: storing in location 1 diff --git a/cpp/.traces/get_handles_record_fields b/cpp/.traces/get_handles_record_fields new file mode 100644 index 00000000..6e2f065e --- /dev/null +++ b/cpp/.traces/get_handles_record_fields @@ -0,0 +1,30 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "34", type: 0} +parse/0: product: {name: "12", type: 1} +parse/0: instruction: 1 +parse/0: ingredient: {name: "35", type: 0} +parse/0: product: {name: "13", type: 1} +parse/0: instruction: 1 +parse/0: ingredient: {name: "36", type: 0} +parse/0: product: {name: "14", type: 1} +parse/0: instruction: 18 +parse/0: ingredient: {name: "12", type: 5} +parse/0: ingredient: {name: "1", type: 0} +parse/0: product: {name: "15", type: 1} +run/0: instruction 0 +run/0: ingredient 0 is 34 +mem/0: storing in location 12 +run/0: instruction 1 +run/0: ingredient 0 is 35 +mem/0: storing in location 13 +run/0: instruction 2 +run/0: ingredient 0 is 36 +mem/0: storing in location 14 +run/0: instruction 3 +run/0: ingredient 0 is 12 +run/0: ingredient 1 is 1 +run/0: address to copy is 14 +run/0: its type is 1 +mem/0: location 14 is 36 +run/0: product 0 is 36 +mem/0: storing in location 15 diff --git a/cpp/010vm b/cpp/010vm index 2f2268ba..526d4593 100644 --- a/cpp/010vm +++ b/cpp/010vm @@ -39,6 +39,7 @@ struct reagent { vector<type_number> types; vector<pair<string, property> > properties; reagent(string s); + reagent(type_number t); string to_string(); }; @@ -149,6 +150,9 @@ void setup_recipes() { properties.push_back(pair<string, property>(name, property())); } } + reagent::reagent(type_number t) { + types.push_back(t); + } string reagent::to_string() { ostringstream out; out << "{name: \"" << name << "\", type: "; diff --git a/cpp/017record b/cpp/017record index 3248eb49..8dd02643 100644 --- a/cpp/017record +++ b/cpp/017record @@ -38,7 +38,10 @@ case GET: { assert(instructions[pc].ingredients[1].types.size() == 1); assert(instructions[pc].ingredients[1].types[0] == 0); // must be literal size_t offset = to_int(instructions[pc].ingredients[1].name); - int src = base_address+offset; + int src = base_address; + for (size_t i = 0; i < offset; ++i) { + src += size_of(reagent(Type[base_type].elements[i][0])); + } trace("run") << "address to copy is " << src; assert(Type[base_type].is_record); assert(Type[base_type].elements.size() > offset); @@ -69,6 +72,33 @@ recipe main [ +run: product 0 is 35 +mem: storing in location 15 +:(before "End Mu Types") +// A more complex record, containing another record. +int point_integer = Type_number["point-integer"] = Next_type_number++; +Type[point_integer].size = 2; +Type[point_integer].is_record = true; +vector<type_number> p2; +p2.push_back(point); +Type[point_integer].elements.push_back(p2); +vector<type_number> i2; +i2.push_back(integer); +Type[point_integer].elements.push_back(i2); +:(scenario "get_handles_record_fields") +recipe main [ + 12:integer <- copy 34:literal + 13:integer <- copy 35:literal + 14:integer <- copy 36:literal + 15:integer <- get 12:point-integer, 1:offset +] ++run: instruction 2 ++run: ingredient 0 is 12 ++run: ingredient 1 is 1 ++run: address to copy is 14 ++run: its type is 1 ++mem: location 14 is 36 ++run: product 0 is 36 ++mem: storing in location 15 + :(before "End Globals") // To write to fields of records, you need their address. const int GET_ADDRESS = 19; |