diff options
Diffstat (limited to '050scenario.cc')
-rw-r--r-- | 050scenario.cc | 82 |
1 files changed, 74 insertions, 8 deletions
diff --git a/050scenario.cc b/050scenario.cc index c7d57d96..8a9a57d4 100644 --- a/050scenario.cc +++ b/050scenario.cc @@ -150,6 +150,7 @@ void run_mu_scenario(const scenario& s) { setup(); } vector<recipe_ordinal> tmp = load("recipe scenario_"+s.name+" [ "+s.to_run+" ]"); + mark_autogenerated(tmp.at(0)); bind_special_scenario_names(tmp.at(0)); transform_all(); run(tmp.front()); @@ -170,6 +171,46 @@ void run_mu_scenario(const scenario& s) { Current_scenario = NULL; } +//: Some variables for fake resources always get special /raw addresses in scenarios. + +// Should contain everything passed by is_special_name but failed by is_disqualified. +void bind_special_scenario_names(recipe_ordinal r) { + // Special Scenario Variable Names(r) + // End Special Scenario Variable Names(r) +} +:(before "Done Placing Ingredient(inst, in, caller)") +maybe_make_raw(inst.ingredients.at(in), caller); +:(before "Done Placing Product(inst, out, caller)") +maybe_make_raw(inst.products.at(out), caller); +:(code) +void maybe_make_raw(reagent& r, const recipe& caller) { + if (!is_special_name(r.name)) return; + if (starts_with(caller.name, "scenario_")) + r.properties.push_back(pair<string, string_tree*>("raw", NULL)); + // End maybe_make_raw +} + +//: Test. +:(before "End is_special_name Cases") +if (s == "__maybe_make_raw_test__") return true; +:(before "End Special Scenario Variable Names(r)") +//: ugly: we only need this for this one test, but need to define it for all time +Name[r]["__maybe_make_raw_test__"] = Reserved_for_tests-1; +:(code) +void test_maybe_make_raw() { + // check that scenarios can use local-scope and special variables together + vector<recipe_ordinal> tmp = load( + "def scenario_foo [\n" + " local-scope\n" + " __maybe_make_raw_test__:number <- copy 34\n" + "]\n"); + mark_autogenerated(tmp.at(0)); + bind_special_scenario_names(tmp.at(0)); + transform_all(); + run(tmp.at(0)); + CHECK(trace_count("error") == 0); +} + //: Watch out for redefinitions of scenario routines. We should never ever be //: doing that, regardless of anything else. :(scenarios run) @@ -215,6 +256,7 @@ case RUN: { ostringstream tmp; tmp << "recipe run_" << Next_recipe_ordinal << " [ " << current_instruction().ingredients.at(0).name << " ]"; vector<recipe_ordinal> tmp_recipe = load(tmp.str()); + mark_autogenerated(tmp_recipe.at(0)); bind_special_scenario_names(tmp_recipe.at(0)); transform_all(); if (Trace_stream) { @@ -225,14 +267,9 @@ case RUN: { Current_routine->calls.push_front(call(tmp_recipe.at(0))); continue; // not done with caller; don't increment current_step_index() } - -// Some variables for fake resources always get special addresses in -// scenarios. -:(code) -void bind_special_scenario_names(recipe_ordinal r) { - // Special Scenario Variable Names(r) - // End Special Scenario Variable Names(r) -} +:(before "End maybe_make_raw") +if (starts_with(caller.name, "run_")) + r.properties.push_back(pair<string, string_tree*>("raw", NULL)); :(scenario run_multiple) def main [ @@ -683,6 +720,31 @@ def main [ :(after "case _SYSTEM:") if (Current_scenario) break; +//:: Warn if people use '_' manually in function names. They're reserved for internal use. + +:(scenario recipe_name_with_underscore) +% Hide_errors = true; +def foo_bar [ +] ++error: foo_bar: don't create recipes with '_' in the name + +:(before "End recipe Fields") +bool is_autogenerated; +:(before "End recipe Constructor") +is_autogenerated = false; +:(code) +void mark_autogenerated(recipe_ordinal r) { + get(Recipe, r).is_autogenerated = true; +} + +:(after "void transform_all()") + for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) { + const recipe& r = p->second; + if (r.name.find('_') == string::npos) continue; + if (r.is_autogenerated) continue; // created by previous call to transform_all() + raise << r.name << ": don't create recipes with '_' in the name\n" << end(); + } + //:: Helpers :(code) @@ -697,3 +759,7 @@ void run_mu_scenario(const string& form) { scenario s = parse_scenario(in); run_mu_scenario(s); } + +bool starts_with(const string& s, const string& pat) { + return s.substr(0, pat.size()) == pat; +} |