From 48e40252b005e3c37e3e5c087daf4f14657295f6 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 1 Aug 2015 22:16:09 -0700 Subject: 1913 - save expected response for each sandbox --- 013literal_string.cc | 7 +++++-- 081run_interactive.cc | 4 ++-- 082persist.cc | 22 +++++++++++++++------- edit.mu | 14 +++++++++++--- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/013literal_string.cc b/013literal_string.cc index 8054d60f..92dc75ca 100644 --- a/013literal_string.cc +++ b/013literal_string.cc @@ -132,11 +132,14 @@ if (s.at(0) == '[') { //: b) Escape newlines in the string to make it more friendly to trace(). :(after "string reagent::to_string()") - if (!properties.at(0).second.empty() && properties.at(0).second.at(0) == "literal-string") { + if (is_literal_string(*this)) return emit_literal_string(name); - } :(code) +bool is_literal_string(const reagent& x) { + return !x.properties.at(0).second.empty() && x.properties.at(0).second.at(0) == "literal-string"; +} + string emit_literal_string(string name) { size_t pos = 0; while (pos != string::npos) diff --git a/081run_interactive.cc b/081run_interactive.cc index 1f6c0407..3b0cf32e 100644 --- a/081run_interactive.cc +++ b/081run_interactive.cc @@ -149,7 +149,7 @@ void record_products(const instruction& instruction, const vector for (long long int i = 0; i < SIZE(products); ++i) { // string if (i < SIZE(instruction.products)) { - if (is_string(instruction.products.at(i))) { + if (is_mu_string(instruction.products.at(i))) { assert(scalar(products.at(i))); out << read_mu_string(products.at(i).at(0)) << '\n'; continue; @@ -241,7 +241,7 @@ long long int stringified_value_of_location(long long int address) { return new_mu_string(out.str()); } -bool is_string(const reagent& x) { +bool is_mu_string(const reagent& x) { return SIZE(x.types) == 3 && x.types.at(0) == Type_ordinal["address"] && x.types.at(1) == Type_ordinal["array"] diff --git a/082persist.cc b/082persist.cc index 0cae8c32..3e53ff6a 100644 --- a/082persist.cc +++ b/082persist.cc @@ -58,14 +58,22 @@ case SAVE: { raise << current_recipe_name() << ": 'save' requires exactly two ingredients, but got " << current_instruction().to_string() << '\n' << end(); break; } - if (!scalar(ingredients.at(0))) - raise << current_recipe_name() << ": first ingredient of 'save' should be a literal string, but got " << current_instruction().ingredients.at(0).to_string() << '\n' << end(); - if (!scalar(ingredients.at(1))) - raise << current_recipe_name() << ": second ingredient of 'save' should be an address:array:character, but got " << current_instruction().ingredients.at(1).to_string() << '\n' << end(); if (Current_scenario) break; // do nothing in tests - string filename = current_instruction().ingredients.at(0).name; - if (!is_literal(current_instruction().ingredients.at(0))) - filename = to_string(ingredients.at(0).at(0)); + string filename; + if (is_literal_string(current_instruction().ingredients.at(0))) { + filename = current_instruction().ingredients.at(0).name; + } + else if (is_mu_string(current_instruction().ingredients.at(0))) { + filename = read_mu_string(ingredients.at(0).at(0)); + } + else { + raise << current_recipe_name() << ": first ingredient of 'save' should be a string, but got " << current_instruction().ingredients.at(0).to_string() << '\n' << end(); + break; + } + if (!scalar(ingredients.at(1))) { + raise << current_recipe_name() << ": second ingredient of 'save' should be an address:array:character, but got " << current_instruction().ingredients.at(1).to_string() << '\n' << end(); + break; + } ofstream fout(("lesson/"+filename).c_str()); string contents = read_mu_string(ingredients.at(1).at(0)); fout << contents; diff --git a/edit.mu b/edit.mu index 98741f68..e4a7f340 100644 --- a/edit.mu +++ b/edit.mu @@ -2804,12 +2804,20 @@ recipe run-sandboxes [ # first clear previous versions, in case we deleted some sandbox $system [rm lesson/[0-9]* >/dev/null 2>/dev/null] # some shells can't handle '>&' curr:address:sandbox-data <- get *env, sandbox:offset - filename:number <- copy 0 + suffix:address:array:character <- new [.out] + idx:number <- copy 0 { break-unless curr - data:address:address:array:character <- get-address *curr, data:offset + data <- get-address *curr, data:offset + filename:address:array:character <- integer-to-decimal-string idx save filename, *data - filename <- add filename, 1 + { + expected-response:address:array:character <- get *curr, expected-response:offset + break-unless expected-response + filename <- string-append filename, suffix + save filename, expected-response + } + idx <- add idx, 1 curr <- get *curr, next-sandbox:offset loop } -- cgit 1.4.1-2-gfad0