From ad8e984fd4590740cb6dc23e951848108f671aac Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 6 Apr 2015 12:02:38 -0700 Subject: 1024 - basic skeleton for running scenarios For now every scenario parses to the same dummy scenario. --- cpp/001test | 1 + cpp/011load | 11 +++++++++-- cpp/013run | 4 +++- cpp/031scenario | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ cpp/032string.mu | 35 +++++++++++++++++++++++++++++++++++ cpp/string-test.mu | 6 ------ 6 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 cpp/031scenario delete mode 100644 cpp/string-test.mu (limited to 'cpp') diff --git a/cpp/001test b/cpp/001test index f0cb2c15..3611ca09 100644 --- a/cpp/001test +++ b/cpp/001test @@ -69,6 +69,7 @@ void run_tests() { for (unsigned long i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) { run_test(i); } + // End Tests } void run_test(int i) { diff --git a/cpp/011load b/cpp/011load index eb8ed8f1..8cbf2e53 100644 --- a/cpp/011load +++ b/cpp/011load @@ -22,9 +22,13 @@ vector add_recipes(istream& in) { if (in.eof()) break; string command = next_word(in); // Command Handlers - if (command == "recipe") + if (command == "recipe") { result.push_back(add_recipe(in)); + } // End Command Handlers + else { + raise << "unknown top-level command: " << command; + } } return result; } @@ -32,7 +36,7 @@ vector add_recipes(istream& in) { recipe_number add_recipe(istream& in) { skip_comments_and_newlines(in); string recipe_name = next_word(in); -//? cout << "recipe name: ^" << recipe_name << "$\n"; //? 1 +//? cout << "recipe name: ^" << recipe_name << "$\n"; //? 2 if (recipe_name.empty()) raise << "empty recipe name\n"; //? raise << "empty recipe name in " << in.str() << '\n'; @@ -114,6 +118,7 @@ bool next_instruction(istream& in, instruction* curr) { } string next_word(istream& in) { +//? cout << "AAA next_word\n"; //? 1 ostringstream out; skip_whitespace(in); slurp_word(in, out); @@ -123,6 +128,7 @@ string next_word(istream& in) { } void slurp_word(istream& in, ostream& out) { +//? cout << "AAA slurp_word\n"; //? 1 char c; if (in.peek() == ',') { in >> c; @@ -130,6 +136,7 @@ void slurp_word(istream& in, ostream& out) { return; } while (in >> c) { +//? cout << c << '\n'; //? 1 if (isspace(c) || c == ',') { in.putback(c); break; diff --git a/cpp/013run b/cpp/013run index 6888d8f5..7399b2e3 100644 --- a/cpp/013run +++ b/cpp/013run @@ -80,10 +80,11 @@ inline bool done(routine& rr) { return running_at(rr) >= steps(rr).size(); } +:(after "int main") + load("core.mu"); :(before "End Main") if (argc > 1) { setup(); - load("core.mu"); for (int i = 1; i < argc; ++i) { load(argv[i]); } @@ -99,6 +100,7 @@ if (argc > 1) { :(code) void load(string filename) { ifstream fin(filename.c_str()); + fin >> std::noskipws; add_recipes(fin); fin.close(); } diff --git a/cpp/031scenario b/cpp/031scenario new file mode 100644 index 00000000..2fbd2ffc --- /dev/null +++ b/cpp/031scenario @@ -0,0 +1,53 @@ +:(before "End Types") +struct scenario { + string name; + string to_run; + map memory_expectations; +}; + +:(before "End Globals") +vector Scenarios; + +:(before "End Tests") +//? cout << "AAA\n"; //? 1 +for (size_t i = 0; i < Scenarios.size(); ++i) { +//? cout << "BBB\n"; //? 1 + run(Scenarios[i].to_run); + for (map::iterator p = Scenarios[i].memory_expectations.begin(); + p != Scenarios[i].memory_expectations.end(); + ++p) { + if (Memory[p->first] != p->second) { + cerr << Scenarios[i].name << ": Expected location " << p->first << " to contain " << p->second << " but saw " << Memory[p->first] << '\n'; + Passed = false; + } + } + if (Passed) cerr << "."; +} + +:(before "End Command Handlers") +else if (command == "scenario") { +//? cout << "AAA scenario\n"; //? 1 + Scenarios.push_back(parse_scenario(in)); +} + +:(code) +scenario parse_scenario(istream& in) { + scenario x; + x.name = next_word(in); +//? cout << "AAA scenario name " << x.name << '\n'; //? 1 + skip_whitespace(in); skip_comments_and_newlines(in); skip_whitespace(in); + assert(in.get() == '['); + int brace_depth = 1; + char c; + while (in >> c) { + x.to_run += c; + if (c == '[') ++brace_depth; + if (c == ']') --brace_depth; + if (brace_depth == 0) break; + } + x.to_run = "recipe main [\n" + " 1:integer/raw <- add 3:literal, 3:literal\n" + "]"; + x.memory_expectations[1] = 6; + return x; +} diff --git a/cpp/032string.mu b/cpp/032string.mu index eff288eb..38d9d06f 100644 --- a/cpp/032string.mu +++ b/cpp/032string.mu @@ -27,3 +27,38 @@ recipe string-equal [ } reply 1:literal ] + +scenario string-equal-reflexive [ + run [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [abc] + 3:boolean/raw <- string-equal x:address:array:character, x:address:array:character + ] + memory should contain [ + 3 <- 1 # x == x for all x + ] +] + +scenario string-equal [ + run [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [abc] + y:address:array:character <- new [abc] + 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character + ] + memory should contain [ + 3 <- 1 # abc == abd + ] +] + +scenario string-equal2 [ + run [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [abc] + y:address:array:character <- new [abcd] + 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character + ] + memory should contain [ + 3 <- 0 # abc != abd + ] +] diff --git a/cpp/string-test.mu b/cpp/string-test.mu deleted file mode 100644 index 5470af60..00000000 --- a/cpp/string-test.mu +++ /dev/null @@ -1,6 +0,0 @@ -recipe main [ - default-space:address:space <- new location:type, 30:literal - x:address:array:character <- new [abc] - y:address:array:character <- new [abc] - 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character -] -- cgit 1.4.1-2-gfad0