From 2dab0edbbd5e886fbb7838842afddd6fbf03c6d3 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 17 Jun 2015 01:22:25 -0700 Subject: 1582 --- 020run.cc | 1 + 079scenario_events.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) 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 -- cgit 1.4.1-2-gfad0