about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-17 01:22:25 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-17 01:22:25 -0700
commit2dab0edbbd5e886fbb7838842afddd6fbf03c6d3 (patch)
tree472927e2e1a2072acb1eb4c21ff4fa9ff9db4108
parenta7d7073512007161cd02a085398893f16128532e (diff)
downloadmu-2dab0edbbd5e886fbb7838842afddd6fbf03c6d3.tar.gz
1582
-rw-r--r--020run.cc1
-rw-r--r--079scenario_events.cc45
2 files changed, 46 insertions, 0 deletions
diff --git a/020run.cc b/020run.cc
index 028aa313..7cc587a8 100644
--- a/020run.cc
+++ b/020run.cc
@@ -88,6 +88,7 @@ void run_current_routine()
     for (long long int i = 0; i < SIZE(current_instruction().products); ++i) {
       write_memory(current_instruction().products.at(i), products.at(i));
     }
+    // End of Instruction
     ++current_step_index();
   }
 //?   cerr << "AAA 9\n"; //? 1
diff --git a/079scenario_events.cc b/079scenario_events.cc
index 72a3b8cf..5641f885 100644
--- a/079scenario_events.cc
+++ b/079scenario_events.cc
@@ -147,3 +147,48 @@ long long int size_of_events() {
   result = size_of(type);
   return result;
 }
+
+//: Warn if a scenario uses both 'keyboard' and 'events'.
+
+:(scenario recipes_should_not_use_events_alongside_keyboard)
+% Hide_warnings = true;
+scenario recipes-should-not-use-events-alongside-keyboard [
+  assume-keyboard [abc]
+  assume-events []
+]
++warn: can't use 'keyboard' and 'events' in the same program/scenario
+
+:(before "End Globals")
+bool Keyboard_used = false;
+bool Events_used = false;
+:(before "End Setup")
+Keyboard_used = Events_used = false;
+:(after "case ASSUME_EVENTS:")
+//? cerr << "events!\n"; //? 1
+Events_used = true;
+:(before "Running One Instruction")
+//? cerr << current_instruction().to_string() << '\n'; //? 1
+for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
+  if (current_instruction().ingredients.at(i).value == KEYBOARD) Keyboard_used = true;
+  if (current_instruction().ingredients.at(i).value == EVENTS) Events_used = true;
+}
+for (long long int i = 0; i < SIZE(current_instruction().products); ++i) {
+  if (current_instruction().products.at(i).value == KEYBOARD) Keyboard_used = true;
+  if (current_instruction().products.at(i).value == EVENTS) Events_used = true;
+}
+:(before "End of Instruction")  // might miss some early returns like 'reply'
+//? cerr << Keyboard_used << Events_used << '\n'; //? 1
+if (Keyboard_used && Events_used)
+  raise << "can't use 'keyboard' and 'events' in the same program/scenario\n" << die();
+
+:(scenario recipes_should_not_use_events_alongside_keyboard_including_nested_run)
+% Hide_warnings = true;
+scenario recipes-should-not-use-events-alongside-keyboard-including-nested-run [
+  assume-events [
+    type [abc]
+  ]
+  run [
+    keyboard:location <- copy 0:literal  # unsafe
+  ]
+]
++warn: can't use 'keyboard' and 'events' in the same program/scenario