about summary refs log tree commit diff stats
path: root/cpp/072scenario_screen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/072scenario_screen.cc')
-rw-r--r--cpp/072scenario_screen.cc26
1 files changed, 22 insertions, 4 deletions
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