diff options
-rw-r--r-- | cpp/.traces/set_default_space | 9 | ||||
-rw-r--r-- | cpp/.traces/surrounding_space | 20 | ||||
-rw-r--r-- | cpp/010vm | 1 | ||||
-rw-r--r-- | cpp/027space | 11 | ||||
-rw-r--r-- | cpp/028space_surround | 8 |
5 files changed, 39 insertions, 10 deletions
diff --git a/cpp/.traces/set_default_space b/cpp/.traces/set_default_space index 326ca4b1..3292565f 100644 --- a/cpp/.traces/set_default_space +++ b/cpp/.traces/set_default_space @@ -1,4 +1,7 @@ parse/0: instruction: 1 +parse/0: ingredient: {name: "5", value: 0, type: 0, properties: [5: literal]} +parse/0: product: {name: "10", value: 0, type: 1, properties: [10: integer]} +parse/0: instruction: 1 parse/0: ingredient: {name: "10", value: 0, type: 0, properties: [10: literal]} parse/0: product: {name: "default-space", value: 0, type: 2-0, properties: [default-space: address:space]} parse/0: instruction: 1 @@ -8,8 +11,12 @@ name/0: assign default-space 1 after-brace/0: recipe main after-brace/0: copy ... after-brace/0: copy ... +after-brace/0: copy ... run/0: instruction main/0 -run/0: ingredient 0 is 10 +run/0: ingredient 0 is 5 +mem/0: storing 5 in location 10 run/0: instruction main/1 +run/0: ingredient 0 is 10 +run/0: instruction main/2 run/0: ingredient 0 is 23 mem/0: storing 23 in location 12 diff --git a/cpp/.traces/surrounding_space b/cpp/.traces/surrounding_space index 5297428b..baf29200 100644 --- a/cpp/.traces/surrounding_space +++ b/cpp/.traces/surrounding_space @@ -1,4 +1,10 @@ parse/0: instruction: 1 +parse/0: ingredient: {name: "5", value: 0, type: 0, properties: [5: literal]} +parse/0: product: {name: "10", value: 0, type: 1, properties: [10: integer]} +parse/0: instruction: 1 +parse/0: ingredient: {name: "5", value: 0, type: 0, properties: [5: literal]} +parse/0: product: {name: "20", value: 0, type: 1, properties: [20: integer]} +parse/0: instruction: 1 parse/0: ingredient: {name: "10", value: 0, type: 0, properties: [10: literal]} parse/0: product: {name: "default-space", value: 0, type: 2-0, properties: [default-space: address:space]} parse/0: instruction: 1 @@ -16,14 +22,22 @@ after-brace/0: copy ... after-brace/0: copy ... after-brace/0: copy ... after-brace/0: copy ... +after-brace/0: copy ... +after-brace/0: copy ... run/0: instruction main/0 -run/0: ingredient 0 is 10 +run/0: ingredient 0 is 5 +mem/0: storing 5 in location 10 run/0: instruction main/1 +run/0: ingredient 0 is 5 +mem/0: storing 5 in location 20 +run/0: instruction main/2 +run/0: ingredient 0 is 10 +run/0: instruction main/3 run/0: ingredient 0 is 20 mem/0: storing 20 in location 11 -run/0: instruction main/2 +run/0: instruction main/4 run/0: ingredient 0 is 32 mem/0: storing 32 in location 12 -run/0: instruction main/3 +run/0: instruction main/5 run/0: ingredient 0 is 33 mem/0: storing 33 in location 22 diff --git a/cpp/010vm b/cpp/010vm index 2689b7c7..76ccc4bf 100644 --- a/cpp/010vm +++ b/cpp/010vm @@ -81,6 +81,7 @@ void setup_types() { Next_type_number = 1; // Mu Types Initialization. int integer = Type_number["integer"] = Next_type_number++; + Type_number["location"] = Type_number["integer"]; // wildcard type Type[integer].name = "integer"; int address = Type_number["address"] = Next_type_number++; Type[address].name = "address"; diff --git a/cpp/027space b/cpp/027space index 05703e52..11eb36c5 100644 --- a/cpp/027space +++ b/cpp/027space @@ -4,9 +4,10 @@ :(scenarios run) :(scenario "set_default_space") -# if default-space is 10, the array of locals begins at location 11 -# and so location 1 is really location 12 +# if default-space is 10, and if an array of 5 locals lies from location 11 to 15 (inclusive), +# then location 0 is really location 11, location 1 is really location 12, and so on. recipe main [ + 10:integer <- copy 5:literal # pretend array; in practice we'll use new default-space:address:space <- copy 10:literal 1:integer <- copy 23:literal ] @@ -41,7 +42,11 @@ int space(const reagent& x) { int address(int offset, int base) { if (base == 0) return offset; // raw - return base+offset+1; + if (offset >= Memory[base]) { + // todo: test + raise << "location " << offset << " is out of bounds " << Memory[base] << '\n'; + } + return base+1 + offset; } :(after "void write_memory(reagent x, vector<int> data)") diff --git a/cpp/028space_surround b/cpp/028space_surround index 9899ed89..7126911d 100644 --- a/cpp/028space_surround +++ b/cpp/028space_surround @@ -7,16 +7,18 @@ :(scenario "surrounding_space") # location 1 in space 1 refers to the space surrounding the default space, here 20. recipe main [ + 10:integer <- copy 5:literal # pretend array + 20:integer <- copy 5:literal # pretend array default-space:address:space <- copy 10:literal 0:address:space <- copy 20:literal 1:integer <- copy 32:literal 1:integer/space:1 <- copy 33:literal ] -+run: instruction main/1 ++run: instruction main/3 +mem: storing 20 in location 11 -+run: instruction main/2 ++run: instruction main/4 +mem: storing 32 in location 12 -+run: instruction main/3 ++run: instruction main/5 +mem: storing 33 in location 22 //: If you think of a space as a collection of variables with a common |