From 9570363aec35e187e2395b1760a4b94e71580ac9 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 29 Jul 2015 15:55:05 -0700 Subject: 1885 --- html/081run_interactive.cc.html | 145 ++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 73 deletions(-) (limited to 'html/081run_interactive.cc.html') diff --git a/html/081run_interactive.cc.html b/html/081run_interactive.cc.html index ab064b17..03c1f523 100644 --- a/html/081run_interactive.cc.html +++ b/html/081run_interactive.cc.html @@ -13,15 +13,14 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Constant { color: #00a0a0; } -.CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } +.CommentedCode { color: #6c6c6c; } .Identifier { color: #804000; } -.traceContains { color: #008000; } --> @@ -38,14 +37,14 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } :(scenario run_interactive_code) recipe main [ - 2:address:array:character <- new [1:number <- copy 34:literal] + 2:address:array:character <- new [1:number <- copy 34] run-interactive 2:address:array:character ] +mem: storing 34 in location 1 :(scenario run_interactive_empty) recipe main [ - 1:address:array:character <- run-interactive 0:literal + 1:address:array:character <- run-interactive 0 ] # result is null +mem: storing 0 in location 1 @@ -60,32 +59,32 @@ RUN_INTERACTIVE, Recipe_ordinal["run-interactive"] = RUN_INTERACTIVE; //? cerr << "run-interactive: " << RUN_INTERACTIVE << '\n'; //? 1 :(before "End Primitive Recipe Implementations") -case RUN_INTERACTIVE: { - if (SIZE(ingredients) != 1) { +case RUN_INTERACTIVE: { + if (SIZE(ingredients) != 1) { raise << current_recipe_name() << ": 'run-interactive' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end(); break; } - if (!scalar(ingredients.at(0))) { + if (!scalar(ingredients.at(0))) { raise << current_recipe_name() << ": first ingredient of 'run-interactive' should be a literal string, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); break; } products.resize(3); - bool new_code_pushed_to_stack = run_interactive(ingredients.at(0).at(0)); - if (!new_code_pushed_to_stack) { + bool new_code_pushed_to_stack = run_interactive(ingredients.at(0).at(0)); + if (!new_code_pushed_to_stack) { products.at(0).push_back(0); products.at(1).push_back(warnings_from_trace()); products.at(2).push_back(0); clean_up_interactive(); break; // done with this instruction } - else { + else { continue; // not done with caller; don't increment current_step_index() } } :(before "End Globals") -bool Running_interactive = false; -long long int Old_screen = 0; // we can support one iteration of screen inside screen +bool Running_interactive = false; +long long int Old_screen = 0; // we can support one iteration of screen inside screen :(before "End Setup") Running_interactive = false; Old_screen = 0; @@ -93,16 +92,16 @@ Old_screen = 0; // reads a string, tries to call it as code (treating it as a test), saving // all warnings. // returns true if successfully called (no errors found during load and transform) -bool run_interactive(long long int address) { - if (Recipe_ordinal.find("interactive") == Recipe_ordinal.end()) +bool run_interactive(long long int address) { + if (Recipe_ordinal.find("interactive") == Recipe_ordinal.end()) Recipe_ordinal["interactive"] = Next_recipe_ordinal++; Old_screen = Memory[SCREEN]; //? cerr << "save screen: " << Old_screen << '\n'; //? 2 // try to sandbox the run as best you can // todo: test this - if (!Current_scenario) { + if (!Current_scenario) { // not already sandboxed - for (long long int i = 1; i < Reserved_for_tests; ++i) + for (long long int i = 1; i < Reserved_for_tests; ++i) Memory.erase(i); Name[Recipe_ordinal["interactive"]].clear(); } @@ -110,12 +109,12 @@ Old_screen = 0; Name[Recipe_ordinal["interactive"]]["screen"] = SCREEN; //? cerr << "screen now at " << Name[Recipe_ordinal["interactive"]]["screen"] << '\n'; //? 1 string command = trim(strip_comments(read_mu_string(address))); - if (command.empty()) return false; + if (command.empty()) return false; Recipe.erase(Recipe_ordinal["interactive"]); Hide_warnings = true; - if (!Trace_stream) { + if (!Trace_stream) { Trace_file = ""; // if there wasn't already a stream we don't want to save it - Trace_stream = new trace_stream; + Trace_stream = new trace_stream; Trace_stream->collect_layer = "warn"; } // call run(string) but without the scheduling @@ -126,7 +125,7 @@ Old_screen = 0; command + "\n" + "]\n"); transform_all(); - if (trace_count("warn") > 0) return false; + if (trace_count("warn") > 0) return false; Running_interactive = true; Current_routine->calls.push_front(call(Recipe_ordinal["interactive"])); return true; @@ -135,9 +134,9 @@ Old_screen = 0; :(scenario "run_interactive_returns_stringified_result") recipe main [ # try to interactively add 2 and 2 - 1:address:array:character <- new [add 2:literal, 2:literal] + 1:address:array:character <- new [add 2, 2] 2:address:array:character <- run-interactive 1:address:array:character - 10:array:character <- copy 2:address:array:character/deref + 10:array:character <- copy 2:address:array:character/lookup ] # first letter in the output should be '4' in unicode +mem: storing 52 in location 11 @@ -145,13 +144,13 @@ recipe main [ :(scenario "run_interactive_returns_string") recipe main [ # try to interactively add 2 and 2 - 1:address:array:character <- new [ - 100:address:array:character <- new [a] - 101:address:array:character <- new [b] + 1:address:array:character <- new [ + 100:address:array:character <- new [a] + 101:address:array:character <- new [b] 102:address:array:character <- string-append 100:address:array:character, 101:address:array:character ] 2:address:array:character <- run-interactive 1:address:array:character - 10:array:character <- copy 2:address:array:character/deref + 10:array:character <- copy 2:address:array:character/lookup ] # output contains "ab" +mem: storing 97 in location 11 @@ -160,9 +159,9 @@ recipe main [ :(scenario "run_interactive_returns_warnings") recipe main [ # run a command that generates a warning - 1:address:array:character <- new [get 1234:number, foo:offset] + 1:address:array:character <- new [get 1234:number, foo:offset] 2:address:array:character, 3:address:array:character <- run-interactive 1:address:array:character - 10:array:character <- copy 3:address:array:character/deref + 10:array:character <- copy 3:address:array:character/lookup ] # warning should be "unknown element foo in container number" +mem: storing 117 in location 11 @@ -175,43 +174,43 @@ string Most_recent_results; :(before "End Setup") Most_recent_results = ""; :(before "End of Instruction") -if (Running_interactive) { +if (Running_interactive) { record_products(current_instruction(), products); } :(code) -void record_products(const instruction& instruction, const vector<vector<double> >& products) { +void record_products(const instruction& instruction, const vector<vector<double> >& products) { ostringstream out; - for (long long int i = 0; i < SIZE(products); ++i) { + for (long long int i = 0; i < SIZE(products); ++i) { // string - if (i < SIZE(instruction.products)) { - if (is_string(instruction.products.at(i))) { + if (i < SIZE(instruction.products)) { + if (is_string(instruction.products.at(i))) { assert(scalar(products.at(i))); out << read_mu_string(products.at(i).at(0)) << '\n'; continue; } // End Record Product Special-cases } - for (long long int j = 0; j < SIZE(products.at(i)); ++j) + for (long long int j = 0; j < SIZE(products.at(i)); ++j) out << products.at(i).at(j) << ' '; out << '\n'; } Most_recent_results = out.str(); } :(before "Complete Call Fallthrough") -if (current_instruction().operation == RUN_INTERACTIVE && !current_instruction().products.empty()) { +if (current_instruction().operation == RUN_INTERACTIVE && !current_instruction().products.empty()) { assert(SIZE(current_instruction().products) <= 3); // Send the results of the most recently executed instruction, regardless of // call depth, to be converted to string and potentially printed to string. - vector<double> result; + vector<double> result; result.push_back(new_mu_string(Most_recent_results)); write_memory(current_instruction().products.at(0), result); - if (SIZE(current_instruction().products) >= 2) { - vector<double> warnings; + if (SIZE(current_instruction().products) >= 2) { + vector<double> warnings; warnings.push_back(warnings_from_trace()); write_memory(current_instruction().products.at(1), warnings); } - if (SIZE(current_instruction().products) >= 3) { - vector<double> screen; + if (SIZE(current_instruction().products) >= 3) { + vector<double> screen; screen.push_back(Memory[SCREEN]); write_memory(current_instruction().products.at(2), screen); } @@ -220,21 +219,21 @@ Most_recent_results = ""//: clean up reply after we've popped it off the call-stack //: however, we need what was on the stack to decide whether to clean up :(after "Starting Reply") -bool must_clean_up_interactive = (current_recipe_name() == "interactive"); +bool must_clean_up_interactive = (current_recipe_name() == "interactive"); :(after "Falling Through End Of Recipe") -bool must_clean_up_interactive = (current_recipe_name() == "interactive"); +bool must_clean_up_interactive = (current_recipe_name() == "interactive"); :(before "End Reply") -if (must_clean_up_interactive) clean_up_interactive(); +if (must_clean_up_interactive) clean_up_interactive(); :(before "Complete Call Fallthrough") -if (must_clean_up_interactive) clean_up_interactive(); +if (must_clean_up_interactive) clean_up_interactive(); :(code) -void clean_up_interactive() { +void clean_up_interactive() { Trace_stream->newline(); // flush trace Hide_warnings = false; Running_interactive = false; // hack: assume collect_layer isn't set anywhere else - if (Trace_stream->collect_layer == "warn") { - delete Trace_stream; + if (Trace_stream->collect_layer == "warn") { + delete Trace_stream; Trace_stream = NULL; } //? cerr << "restore screen: " << Memory[SCREEN] << " to " << Old_screen << '\n'; //? 1 @@ -245,52 +244,52 @@ Most_recent_results = "":(code) string strip_comments(string in) { ostringstream result; - for (long long int i = 0; i < SIZE(in); ++i) { - if (in.at(i) != '#') { + for (long long int i = 0; i < SIZE(in); ++i) { + if (in.at(i) != '#') { result << in.at(i); } - else { - while (i < SIZE(in) && in.at(i) != '\n') + else { + while (i < SIZE(in) && in.at(i) != '\n') ++i; - if (i < SIZE(in) && in.at(i) == '\n') ++i; + if (i < SIZE(in) && in.at(i) == '\n') ++i; } } return result.str(); } -string read_mu_string(long long int address) { - long long int size = Memory[address]; - if (size == 0) return ""; +string read_mu_string(long long int address) { + long long int size = Memory[address]; + if (size == 0) return ""; ostringstream tmp; - for (long long int curr = address+1; curr <= address+size; ++curr) { + for (long long int curr = address+1; curr <= address+size; ++curr) { // todo: unicode - tmp << (char)(int)Memory[curr]; + tmp << (char)(int)Memory[curr]; } return tmp.str(); } -long long int stringified_value_of_location(long long int address) { +long long int stringified_value_of_location(long long int address) { // convert to string ostringstream out; out << Memory[address]; return new_mu_string(out.str()); } -bool is_string(const reagent& x) { +bool is_string(const reagent& x) { return SIZE(x.types) == 3 && x.types.at(0) == Type_ordinal["address"] && x.types.at(1) == Type_ordinal["array"] && x.types.at(2) == Type_ordinal["character"]; } -long long int warnings_from_trace() { - if (!Trace_stream) return 0; - if (trace_count("warn") <= 0) return 0; +long long int warnings_from_trace() { + if (!Trace_stream) return 0; + if (trace_count("warn") <= 0) return 0; ostringstream out; - for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { - if (p->label != "warn") continue; + for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) { + if (p->label != "warn") continue; out << p->contents; - if (*--p->contents.end() != '\n') out << '\n'; + if (*--p->contents.end() != '\n') out << '\n'; } assert(!out.str().empty()); return new_mu_string(out.str()); @@ -303,18 +302,18 @@ RELOAD, :(before "End Primitive Recipe Numbers") Recipe_ordinal["reload"] = RELOAD; :(before "End Primitive Recipe Implementations") -case RELOAD: { - if (SIZE(ingredients) != 1) { +case RELOAD: { + if (SIZE(ingredients) != 1) { raise << current_recipe_name() << ": 'reload' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end(); break; } - if (!scalar(ingredients.at(0))) { + if (!scalar(ingredients.at(0))) { raise << current_recipe_name() << ": first ingredient of 'reload' should be a literal string, but got " << current_instruction().ingredients.at(0).original_string << '\n' << end(); break; } - if (!Trace_stream) { + if (!Trace_stream) { Trace_file = ""; // if there wasn't already a stream we don't want to save it - Trace_stream = new trace_stream; + Trace_stream = new trace_stream; Trace_stream->collect_layer = "warn"; } Hide_warnings = true; @@ -326,8 +325,8 @@ Recipe_ordinal["reload"] = RELOADfalse; products.resize(1); products.at(0).push_back(warnings_from_trace()); - if (Trace_stream->collect_layer == "warn") { - delete Trace_stream; + if (Trace_stream->collect_layer == "warn") { + delete Trace_stream; Trace_stream = NULL; } break; -- cgit 1.4.1-2-gfad0