From 0e4a335edc7d4e584924fd6b298156e45d2626c8 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 6 Sep 2015 16:35:46 -0700 Subject: 2175 --- html/020run.cc.html | 108 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 33 deletions(-) (limited to 'html/020run.cc.html') diff --git a/html/020run.cc.html b/html/020run.cc.html index a6e9548f..92ad8931 100644 --- a/html/020run.cc.html +++ b/html/020run.cc.html @@ -14,15 +14,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .SalientComment { color: #00ffff; } -.Identifier { color: #804000; } +.CommentedCode { color: #6c6c6c; } +.PreProc { color: #c000c0; } .traceAbsent { color: #c00000; } +.Delimiter { color: #a04060; } +.traceContains { color: #008000; } .cSpecial { color: #008000; } .Comment { color: #9090ff; } -.Delimiter { color: #a04060; } -.Special { color: #ff6060; } -.CommentedCode { color: #6c6c6c; } .Constant { color: #00a0a0; } -.traceContains { color: #008000; } +.Special { color: #ff6060; } +.Identifier { color: #804000; } --> @@ -96,7 +97,7 @@ void run_current_routine() while (!Current_routine->completed()) // later layers will modify condition { // Running One Instruction -//? Instructions_running[current_recipe_name()]++; //? 1 +//? Instructions_running[current_recipe_name()]++; if (current_instruction().is_label) { ++current_step_index(); continue; } trace(Initial_callstack_depth+Callstack_depth, "run") << current_instruction().to_string() << end(); if (Memory[0] != 0) { @@ -110,8 +111,8 @@ void run_current_routine() if (should_copy_ingredients()) { for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) { ingredients.push_back(read_memory(current_instruction().ingredients.at(i))); -//? Locations_read[current_recipe_name()] += SIZE(ingredients.back()); //? 1 -//? Locations_read_by_instruction[current_instruction().name] += SIZE(ingredients.back()); //? 1 +//? Locations_read[current_recipe_name()] += SIZE(ingredients.back()); +//? Locations_read_by_instruction[current_instruction().name] += SIZE(ingredients.back()); } } // Instructions below will write to 'products'. @@ -181,26 +182,46 @@ inline bool routine::completed() const return running_step_index >= SIZE(Recipe[running_recipe].steps); } +//:: Startup flow + +//: Step 1: load all .mu files with numeric prefixes (in order) +:(before "End Load Recipes") +load_permanently("core.mu"); +transform_all(); + +//: Step 2: load any .mu files provided at the commandline :(before "End Commandline Parsing") -// Loading Commandline Files if (argc > 1) { - for (int i = 1; i < argc; ++i) { - load_permanently(argv[i]); + // skip argv[0] + argv++; + argc--; + // ignore argv past '--'; that's commandline args for 'main' + while (argc > 0) { + if (string(*argv) == "--") break; + load_permanently(*argv); + argv++; + argc--; } + transform_all(); + if (Run_tests) Recipe.erase(Recipe_ordinal[string("main")]); } +//: Step 3: if we aren't running tests, locate a recipe called 'main' and +//: start running it. :(before "End Main") if (!Run_tests) { setup(); -//? Trace_file = "interactive"; //? 2 -//? START_TRACING_UNTIL_END_OF_SCOPE; //? 2 -//? Trace_stream->collect_layer.insert("app"); //? 1 - transform_all(); +//? Trace_file = "interactive"; +//? START_TRACING_UNTIL_END_OF_SCOPE; +//? Trace_stream->collect_layers.insert("app"); + run_main(argc, argv); + teardown(); +} + +:(code) +void run_main(int argc, char* argv[]) { recipe_ordinal r = Recipe_ordinal[string("main")]; -//? atexit(dump_profile); //? 1 if (r) run(r); -//? dump_memory(); //? 1 - teardown(); } :(code) @@ -217,6 +238,8 @@ void dump_profile() {->first << ": " << p->second << '\n'; } } +:(before "End One-time Setup") +//? atexit(dump_profile); :(code) void cleanup_main() { @@ -231,6 +254,10 @@ atexit(cleanup_main);:(code) void load_permanently(string filename) { + if (is_directory(filename)) { + load_all_permanently(filename); + return; + } ifstream fin(filename.c_str()); fin.peek(); if (!fin) { @@ -239,31 +266,37 @@ void load_permanently(string filename} fin >> std::noskipws; load(fin); - transform_all(); fin.close(); // freeze everything so it doesn't get cleared by tests recently_added_recipes.clear(); // End load_permanently. } -//:: On startup, load everything in core.mu -:(before "End Load Recipes") -load_permanently("core.mu"); +bool is_directory(string path) { + struct stat info; + if (stat(path.c_str(), &info)) return false; // error + return info.st_mode & S_IFDIR; +} -:(code) -// helper for tests -void run(string form) { -//? cerr << form << '\n'; //? 1 - vector<recipe_ordinal> tmp = load(form); - if (tmp.empty()) return; - transform_all(); - run(tmp.front()); +void load_all_permanently(string dir) { + dirent** files; + int num_files = scandir(dir.c_str(), &files, NULL, alphasort); + for (int i = 0; i < num_files; ++i) { + string curr_file = files[i]->d_name; + if (!isdigit(curr_file.at(0))) continue; + load_permanently(dir+'/'+curr_file); + free(files[i]); + files[i] = NULL; + } + free(files); } +:(before "End Includes") +#include<dirent.h> //:: Reading from memory, writing to memory. +:(code) vector<double> read_memory(reagent x) { -//? cout << "read_memory: " << x.to_string() << '\n'; //? 2 vector<double> result; if (is_literal(x)) { result.push_back(x.value); @@ -284,7 +317,7 @@ void write_memory(reagent x(is_literal(x)) return; long long int base = x.value; if (size_mismatch(x, data)) { - raise << current_recipe_name() << ": size mismatch in storing to " << x.original_string << " at '" << current_instruction().to_string() << "'\n" << end(); + raise << current_recipe_name() << ": size mismatch in storing to " << x.original_string << " (" << size_of(x.types) << " vs " << SIZE(data) << ") at '" << current_instruction().to_string() << "'\n" << end(); return; } for (long long int offset = 0; offset < SIZE(data); ++offset) { @@ -308,7 +341,7 @@ long long int size_of(const vector<type_ordina bool size_mismatch(const reagent& x, const vector<double>& data) { if (x.types.empty()) return true; // End size_mismatch(x) Cases -//? if (size_of(x) != SIZE(data)) cerr << size_of(x) << " vs " << SIZE(data) << '\n'; //? 2 +//? if (size_of(x) != SIZE(data)) cerr << size_of(x) << " vs " << SIZE(data) << '\n'; return size_of(x) != SIZE(data); } @@ -324,6 +357,15 @@ bool is_mu_array(reagent rreturn !r.types.empty() && r.types.at(0) == Type_ordinal["array"]; } +:(code) +// helper for tests +void run(string form) { + vector<recipe_ordinal> tmp = load(form); + transform_all(); + if (tmp.empty()) return; + run(tmp.front()); +} + :(scenario run_label) recipe main [ +foo -- cgit 1.4.1-2-gfad0