diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-04 12:19:53 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-04 12:19:53 -0700 |
commit | 8a7ad05a804aa4f39d5919a581aba552b7c4f011 (patch) | |
tree | 317dcbb300914cc523734ac158538f7c72683b22 | |
parent | be3fb4e139cff16a472fcde00642bf891e953aaf (diff) | |
download | mu-8a7ad05a804aa4f39d5919a581aba552b7c4f011.tar.gz |
1253 - new notion of 'predefined globals in scenarios'
-rw-r--r-- | cpp/.traces/clear-line-erases-printed-characters2 | 22 | ||||
-rw-r--r-- | cpp/.traces/print-character-at-top-left2 | 10 | ||||
-rw-r--r-- | cpp/.traces/screen_in_scenario | 10 | ||||
-rw-r--r-- | cpp/.traces/screen_in_scenario_error | 10 | ||||
-rw-r--r-- | cpp/050scenario.cc | 8 | ||||
-rw-r--r-- | cpp/072scenario_screen.cc | 26 | ||||
-rw-r--r-- | cpp/999spaces.cc | 7 |
7 files changed, 56 insertions, 37 deletions
diff --git a/cpp/.traces/clear-line-erases-printed-characters2 b/cpp/.traces/clear-line-erases-printed-characters2 index 8c44d490..282bfe35 100644 --- a/cpp/.traces/clear-line-erases-printed-characters2 +++ b/cpp/.traces/clear-line-erases-printed-characters2 @@ -34,7 +34,7 @@ after-brace/0: screen-should-contain ... new/0: routine allocated memory from 1000 to 101000 schedule/0: clear-line-erases-printed-characters2 run/0: instruction clear-line-erases-printed-characters2/0 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- assume-screen/115 {name: "5", value: 5, type: 0, properties: ["5": "literal", "width": ]}, {name: "3", value: 3, type: 0, properties: ["3": "literal", "height": ]} +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- assume-screen/115 {name: "5", value: 5, type: 0, properties: ["5": "literal", "width": ]}, {name: "3", value: 3, type: 0, properties: ["3": "literal", "height": ]} run/0: instruction init-fake-screen/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal", "capacity": ]} mem/0: array size is 30 @@ -746,7 +746,7 @@ run/0: instruction init-fake-screen/14 run/0: reply/33 {name: "result", value: 1, type: 2-11, properties: ["result": "address":"screen"]} mem/0: location 1002 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction clear-line-erases-printed-characters2/1 run/0: run/43 {name: " # print a character @@ -780,8 +780,8 @@ after-brace/0: print-character ... after-brace/0: move-cursor ... after-brace/0: clear-line ... run/0: instruction run1001/0 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- print-character/117 {name: "screen", value: 999, type: 2, properties: ["screen": "address"]}, {name: "97", value: 97, type: 0, properties: ["97": "literal"]} -mem/0: location 999 is 1031 +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- print-character/117 {name: "screen", value: 900, type: 2, properties: ["screen": "address"]}, {name: "97", value: 97, type: 0, properties: ["97": "literal"]} +mem/0: location 900 is 1031 run/0: instruction print-character/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal"]} mem/0: array size is 30 @@ -896,10 +896,10 @@ run/0: instruction print-character/18 run/0: reply/33 {name: "x", value: 1, type: 2-11, properties: ["x": "address":"screen", "same-as-ingredient": "0"]} mem/0: location 1085 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction run1001/1 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- move-cursor/120 {name: "screen", value: 999, type: 2, properties: ["screen": "address"]}, {name: "0", value: 0, type: 0, properties: ["0": "literal", "row": ]}, {name: "0", value: 0, type: 0, properties: ["0": "literal", "column": ]} -mem/0: location 999 is 1031 +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- move-cursor/120 {name: "screen", value: 900, type: 2, properties: ["screen": "address"]}, {name: "0", value: 0, type: 0, properties: ["0": "literal", "row": ]}, {name: "0", value: 0, type: 0, properties: ["0": "literal", "column": ]} +mem/0: location 900 is 1031 run/0: instruction move-cursor/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal"]} mem/0: array size is 30 @@ -953,10 +953,10 @@ run/0: instruction move-cursor/10 run/0: reply/33 {name: "x", value: 1, type: 2-11, properties: ["x": "address":"screen", "same-as-ingredient": "0"]} mem/0: location 1116 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction run1001/2 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- clear-line/118 {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} -mem/0: location 999 is 1031 +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- clear-line/118 {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} +mem/0: location 900 is 1031 run/0: instruction clear-line/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal"]} mem/0: array size is 30 @@ -1689,7 +1689,7 @@ run/0: instruction clear-line/14 run/0: reply/33 {name: "x", value: 1, type: 2-11, properties: ["x": "address":"screen", "same-as-ingredient": "0"]} mem/0: location 1147 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction clear-line-erases-printed-characters2/2 run/0: screen-should-contain/59 {name: " . . diff --git a/cpp/.traces/print-character-at-top-left2 b/cpp/.traces/print-character-at-top-left2 index 10732699..896cc9c5 100644 --- a/cpp/.traces/print-character-at-top-left2 +++ b/cpp/.traces/print-character-at-top-left2 @@ -22,7 +22,7 @@ after-brace/0: screen-should-contain ... new/0: routine allocated memory from 1000 to 101000 schedule/0: print-character-at-top-left2 run/0: instruction print-character-at-top-left2/0 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- assume-screen/115 {name: "3", value: 3, type: 0, properties: ["3": "literal", "width": ]}, {name: "2", value: 2, type: 0, properties: ["2": "literal", "height": ]} +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- assume-screen/115 {name: "3", value: 3, type: 0, properties: ["3": "literal", "width": ]}, {name: "2", value: 2, type: 0, properties: ["2": "literal", "height": ]} run/0: instruction init-fake-screen/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal", "capacity": ]} mem/0: array size is 30 @@ -392,7 +392,7 @@ run/0: instruction init-fake-screen/14 run/0: reply/33 {name: "result", value: 1, type: 2-11, properties: ["result": "address":"screen"]} mem/0: location 1002 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction print-character-at-top-left2/1 run/0: run/43 {name: " screen:address <- print-character screen:address, 97:literal # 'a' @@ -406,8 +406,8 @@ parse/0: product: {name: "screen", value: 0, type: 2, properties: ["screen": " after-brace/0: recipe run1001 after-brace/0: print-character ... run/0: instruction run1001/0 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- print-character/117 {name: "screen", value: 999, type: 2, properties: ["screen": "address"]}, {name: "97", value: 97, type: 0, properties: ["97": "literal"]} -mem/0: location 999 is 1031 +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- print-character/117 {name: "screen", value: 900, type: 2, properties: ["screen": "address"]}, {name: "97", value: 97, type: 0, properties: ["97": "literal"]} +mem/0: location 900 is 1031 run/0: instruction print-character/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal"]} mem/0: array size is 30 @@ -522,7 +522,7 @@ run/0: instruction print-character/18 run/0: reply/33 {name: "x", value: 1, type: 2-11, properties: ["x": "address":"screen", "same-as-ingredient": "0"]} mem/0: location 1076 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction print-character-at-top-left2/2 run/0: screen-should-contain/59 {name: " .a . diff --git a/cpp/.traces/screen_in_scenario b/cpp/.traces/screen_in_scenario index 77089eb9..3605e5f0 100644 --- a/cpp/.traces/screen_in_scenario +++ b/cpp/.traces/screen_in_scenario @@ -26,7 +26,7 @@ after-brace/0: screen-should-contain ... new/0: routine allocated memory from 1000 to 101000 schedule/0: screen-in-scenario run/0: instruction screen-in-scenario/0 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- assume-screen/115 {name: "5", value: 5, type: 0, properties: ["5": "literal", "width": ]}, {name: "3", value: 3, type: 0, properties: ["3": "literal", "height": ]} +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- assume-screen/115 {name: "5", value: 5, type: 0, properties: ["5": "literal", "width": ]}, {name: "3", value: 3, type: 0, properties: ["3": "literal", "height": ]} run/0: instruction init-fake-screen/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal", "capacity": ]} mem/0: array size is 30 @@ -738,7 +738,7 @@ run/0: instruction init-fake-screen/14 run/0: reply/33 {name: "result", value: 1, type: 2-11, properties: ["result": "address":"screen"]} mem/0: location 1002 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction screen-in-scenario/1 run/0: run/43 {name: " screen:address <- print-character screen:address, 97:literal # 'a' @@ -752,8 +752,8 @@ parse/0: product: {name: "screen", value: 0, type: 2, properties: ["screen": " after-brace/0: recipe run1002 after-brace/0: print-character ... run/0: instruction run1002/0 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- print-character/117 {name: "screen", value: 999, type: 2, properties: ["screen": "address"]}, {name: "97", value: 97, type: 0, properties: ["97": "literal"]} -mem/0: location 999 is 1031 +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- print-character/117 {name: "screen", value: 900, type: 2, properties: ["screen": "address"]}, {name: "97", value: 97, type: 0, properties: ["97": "literal"]} +mem/0: location 900 is 1031 run/0: instruction print-character/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal"]} mem/0: array size is 30 @@ -868,7 +868,7 @@ run/0: instruction print-character/18 run/0: reply/33 {name: "x", value: 1, type: 2-11, properties: ["x": "address":"screen", "same-as-ingredient": "0"]} mem/0: location 1085 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction screen-in-scenario/2 run/0: screen-should-contain/59 {name: " # 01234 diff --git a/cpp/.traces/screen_in_scenario_error b/cpp/.traces/screen_in_scenario_error index 570e2cc5..abcf8d15 100644 --- a/cpp/.traces/screen_in_scenario_error +++ b/cpp/.traces/screen_in_scenario_error @@ -26,7 +26,7 @@ after-brace/0: screen-should-contain ... new/0: routine allocated memory from 1000 to 101000 schedule/0: screen-in-scenario-error run/0: instruction screen-in-scenario-error/0 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- assume-screen/115 {name: "5", value: 5, type: 0, properties: ["5": "literal", "width": ]}, {name: "3", value: 3, type: 0, properties: ["3": "literal", "height": ]} +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- assume-screen/115 {name: "5", value: 5, type: 0, properties: ["5": "literal", "width": ]}, {name: "3", value: 3, type: 0, properties: ["3": "literal", "height": ]} run/0: instruction init-fake-screen/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal", "capacity": ]} mem/0: array size is 30 @@ -738,7 +738,7 @@ run/0: instruction init-fake-screen/14 run/0: reply/33 {name: "result", value: 1, type: 2-11, properties: ["result": "address":"screen"]} mem/0: location 1002 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction screen-in-scenario-error/1 run/0: run/43 {name: " screen:address <- print-character screen:address, 97:literal # 'a' @@ -752,8 +752,8 @@ parse/0: product: {name: "screen", value: 0, type: 2, properties: ["screen": " after-brace/0: recipe run1001 after-brace/0: print-character ... run/0: instruction run1001/0 -run/0: {name: "screen", value: 999, type: 2, properties: ["screen": "address"]} <- print-character/117 {name: "screen", value: 999, type: 2, properties: ["screen": "address"]}, {name: "97", value: 97, type: 0, properties: ["97": "literal"]} -mem/0: location 999 is 1031 +run/0: {name: "screen", value: 900, type: 2, properties: ["screen": "address"]} <- print-character/117 {name: "screen", value: 900, type: 2, properties: ["screen": "address"]}, {name: "97", value: 97, type: 0, properties: ["97": "literal"]} +mem/0: location 900 is 1031 run/0: instruction print-character/0 run/0: {name: "default-space", value: 0, type: 2-5-1, properties: ["default-space": "address":"array":"location"]} <- new/42 {name: "location", value: 1, type: 0, properties: ["location": "type"]}, {name: "30", value: 30, type: 0, properties: ["30": "literal"]} mem/0: array size is 30 @@ -868,7 +868,7 @@ run/0: instruction print-character/18 run/0: reply/33 {name: "x", value: 1, type: 2-11, properties: ["x": "address":"screen", "same-as-ingredient": "0"]} mem/0: location 1085 is 1031 run/0: result 0 is 1031 -mem/0: storing 1031 in location 999 +mem/0: storing 1031 in location 900 run/0: instruction screen-in-scenario-error/2 run/0: screen-should-contain/59 {name: " # 01234 diff --git a/cpp/050scenario.cc b/cpp/050scenario.cc index afea6ff6..0688e7b5 100644 --- a/cpp/050scenario.cc +++ b/cpp/050scenario.cc @@ -135,15 +135,13 @@ case RUN: { tmp << "recipe run" << Next_recipe_number << " [ " << current_instruction().ingredients[0].name << " ]"; //? Show_rest_of_stream = true; //? 1 vector<recipe_number> tmp_recipe = load(tmp.str()); - // Predefined Scenario Locals -//? cout << "mapping local screen in recipe " << tmp_recipe[0] << '\n'; //? 1 - Name[tmp_recipe[0]]["screen"] = Reserved_for_tests-1; - // End Predefined Scenario Locals + // Predefined Scenario Locals In Run. + // End Predefined Scenario Locals In Run. transform_all(); // There's a restriction on the number of variables 'run' can use, so that // it can avoid colliding with the dynamic allocator in case it doesn't // initialize a default-space. - assert(Name[tmp_recipe[0]][""] < Reserved_for_tests-1); + assert(Name[tmp_recipe[0]][""] < Max_variables_in_scenarios); //? cout << tmp_recipe[0] << ' ' << Recipe_number["main"] << '\n'; //? 1 Current_routine->calls.push(call(tmp_recipe[0])); continue; // not done with caller; don't increment current_step_index() diff --git a/cpp/072scenario_screen.cc b/cpp/072scenario_screen.cc index e928f867..4bc42940 100644 --- a/cpp/072scenario_screen.cc +++ b/cpp/072scenario_screen.cc @@ -1,4 +1,7 @@ -//: Some cleaner way to manipulate and check the screen in scenarios. +//: Clean syntax to manipulate and check the screen in scenarios. +//: Instructions 'assume-screen' and 'screen-should-contain' implicitly create +//: a variable called 'screen' that is accessible inside other 'run' +//: instructions in the scenario. :(scenarios run_mu_scenario) :(scenario screen_in_scenario) @@ -34,6 +37,22 @@ scenario screen-in-scenario-error [ ] +warn: expected screen location (0, 0) to contain 'b' instead of 'a' +:(before "End Globals") +// Scenarios may not define default-space, so they should fit within the +// initial area of memory reserved for tests. We'll put the predefined +// variables available to them at the end of that region. +const size_t Max_variables_in_scenarios = Reserved_for_tests-100; +size_t Next_predefined_global_for_scenarios = Max_variables_in_scenarios; +:(before "End Setup") +assert(Next_predefined_global_for_scenarios < Reserved_for_tests); + +:(before "End Globals") +// Scenario Globals. +const size_t SCREEN = Next_predefined_global_for_scenarios++; +// End Scenario Globals. +:(before "End Predefined Scenario Locals In Run") +Name[tmp_recipe[0]]["screen"] = SCREEN; + :(before "End Rewrite Instruction(curr)") // rewrite `assume-screen width, height` to // `screen:address <- init-fake-screen width, height` @@ -42,7 +61,7 @@ if (curr.name == "assume-screen") { curr.operation = Recipe_number["init-fake-screen"]; assert(curr.products.empty()); curr.products.push_back(reagent("screen:address")); - curr.products[0].set_value(Reserved_for_tests-1); + curr.products[0].set_value(SCREEN); //? cout << "after: " << curr.to_string() << '\n'; //? 1 //? cout << "AAA " << Recipe_number["init-fake-screen"] << '\n'; //? 1 } @@ -61,9 +80,8 @@ case SCREEN_SHOULD_CONTAIN: { :(code) void check_screen(const string& contents) { - static const int screen_variable = Reserved_for_tests-1; assert(!Current_routine->calls.top().default_space); // not supported - index_t screen_location = Memory[screen_variable]; + index_t screen_location = Memory[SCREEN]; int data_offset = find_element_name(Type_number["screen"], "data"); assert(data_offset >= 0); index_t screen_data_location = screen_location+data_offset; // type: address:array:character diff --git a/cpp/999spaces.cc b/cpp/999spaces.cc index ace149fc..5da0d63b 100644 --- a/cpp/999spaces.cc +++ b/cpp/999spaces.cc @@ -1,11 +1,14 @@ //: Since different layers all carve out different parts of various namespaces //: (recipes, memory, etc.) for their own use, there's no previous place where -//: we can lay out the big picture of what uses what. So we'll do that here. +//: we can lay out the big picture of what uses what. So we'll do that here +//: and just have to manually remember to update it when we move boundaries +//: around. //: //:: Memory //: //: Location 0 - unused (since it can help uncover bugs) -//: Locations 1-999 - reserved for tests +//: Locations 1-899 - reserved for tests +//: Locations 900-999 - reserved for predefined globals in mu scenarios, like keyboard, screen, etc. //: Locations 1000 ('Reserved_for_tests') onward - available to the allocator in chunks of size Initial_memory_per_routine. //: //:: Recipes |