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 /cpp/017record | |
parent | ab9e2eaee0e7361a9ea4cb65011873d44100ff51 (diff) | |
download | mu-6cc4621602ac00effcfedeeb01593d5e619db0f9.tar.gz |
814
Diffstat (limited to 'cpp/017record')
-rw-r--r-- | cpp/017record | 32 |
1 files changed, 31 insertions, 1 deletions
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; |