From 6cc4621602ac00effcfedeeb01593d5e619db0f9 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 22 Feb 2015 00:15:14 -0800 Subject: 814 --- cpp/017record | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'cpp/017record') 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 p2; +p2.push_back(point); +Type[point_integer].elements.push_back(p2); +vector 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; -- cgit 1.4.1-2-gfad0 ion>
blob: d08783f6532628fab7380643b29e092d9a3e84d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35