From 298f8065857630e414d84e4ee785a6d17e5f99bb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 5 Jul 2016 01:08:00 -0700 Subject: 3102 --- html/050scenario.cc.html | 92 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 13 deletions(-) (limited to 'html/050scenario.cc.html') diff --git a/html/050scenario.cc.html b/html/050scenario.cc.html index 3a26847d..e8a8d028 100644 --- a/html/050scenario.cc.html +++ b/html/050scenario.cc.html @@ -182,11 +182,11 @@ cerr << "\nbool not_already_inside_test = !Trace_stream; //? cerr << s.name << '\n'; if (not_already_inside_test) { - Trace_file = s.name; Trace_stream = new trace_stream; 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()); @@ -197,16 +197,57 @@ cerr << "\n// End Mu Test Teardown if (not_already_inside_test && Trace_stream) { teardown(); - ofstream fout((Trace_dir+Trace_file).c_str()); - fout << Trace_stream->readable_contents(""); - fout.close(); + if (Save_trace) { + ofstream fout("last_trace"); + fout << Trace_stream->readable_contents(""); + fout.close(); + } delete Trace_stream; Trace_stream = NULL; - Trace_file = ""; } 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) @@ -252,6 +293,7 @@ put(Recipe_ordinal,; 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) { @@ -262,14 +304,9 @@ put(Recipe_ordinal,->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 [ @@ -720,6 +757,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) @@ -734,6 +796,10 @@ def main [ 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; +} -- cgit 1.4.1-2-gfad0