diff options
-rw-r--r-- | 082persist.cc | 22 | ||||
-rw-r--r-- | edit.mu | 28 |
2 files changed, 43 insertions, 7 deletions
diff --git a/082persist.cc b/082persist.cc index 73b8aa75..b4817dc0 100644 --- a/082persist.cc +++ b/082persist.cc @@ -11,7 +11,14 @@ case RESTORE: { if (!scalar(ingredients.at(0))) raise << "restore: illegal operand " << current_instruction().ingredients.at(0).to_string() << '\n'; products.resize(1); - products.at(0).push_back(new_mu_string(slurp("lesson/"+current_instruction().ingredients.at(0).name))); + 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 contents = slurp("lesson/"+filename); + if (contents.empty()) + products.at(0).push_back(0); + else + products.at(0).push_back(new_mu_string(contents)); break; } @@ -43,11 +50,8 @@ case SAVE: { if (!scalar(ingredients.at(0))) raise << "save: illegal operand 0 " << current_instruction().ingredients.at(0).to_string() << '\n'; string filename = current_instruction().ingredients.at(0).name; - if (!is_literal(current_instruction().ingredients.at(0))) { - ostringstream tmp; - tmp << ingredients.at(0).at(0); - filename = tmp.str(); - } + if (!is_literal(current_instruction().ingredients.at(0))) + filename = to_string(ingredients.at(0).at(0)); ofstream fout(("lesson/"+filename).c_str()); if (!scalar(ingredients.at(1))) raise << "save: illegal operand 1 " << current_instruction().ingredients.at(1).to_string() << '\n'; @@ -68,5 +72,11 @@ bool exists(const string& filename) { return 0 == stat(filename.c_str(), &dummy); } +string to_string(long long int x) { + ostringstream tmp; + tmp << x; + return tmp.str(); +} + :(before "End Includes") #include<sys/stat.h> diff --git a/edit.mu b/edit.mu index 8b7eb53d..f47553ab 100644 --- a/edit.mu +++ b/edit.mu @@ -4,8 +4,11 @@ recipe main [ local-scope open-console initial-recipe:address:array:character <- restore [recipes.mu] - initial-sandbox:address:array:character <- new [test 2, 2] + initial-sandbox:address:array:character <- new [] env:address:programming-environment-data <- new-programming-environment 0:literal/screen, initial-recipe:address:array:character, initial-sandbox:address:array:character + env:address:programming-environment-data <- restore-sandboxes env:address:programming-environment-data + render-sandbox-side 0:literal/screen, env:address:programming-environment-data + show-screen 0:literal/screen event-loop 0:literal/screen, 0:literal/console, env:address:programming-environment-data # never gets here ] @@ -2818,6 +2821,29 @@ recipe render-sandboxes [ reply row:number/same-as-ingredient:4, screen:address/same-as-ingredient:0 ] +# assumes programming environment has no sandboxes; restores them from previous session +recipe restore-sandboxes [ + local-scope + env:address:programming-environment-data <- next-ingredient + # read all scenarios, pushing them to end of a list of scenarios + filename:number <- copy 0:literal + curr:address:address:sandbox-data <- get-address env:address:programming-environment-data/deref, sandbox:offset + { + contents:address:array:character <- restore filename:number + break-unless contents:address:array:character # stop at first error; assuming file didn't exist +#? $print contents:address:array:character, 10:literal/newline + # create new sandbox for file + curr:address:address:sandbox-data/deref <- new sandbox-data:type + data:address:address:array:character <- get-address curr:address:address:sandbox-data/deref/deref, data:offset + data:address:address:array:character/deref <- copy contents:address:array:character + # increment loop variables + filename:number <- add filename:number, 1:literal + curr:address:address:sandbox-data <- get-address curr:address:address:sandbox-data/deref/deref, next-sandbox:offset + loop + } + reply env:address:programming-environment-data/same-as-ingredient:0 +] + # was-deleted?:boolean <- delete-sandbox t:touch-event, env:address:programming-environment-data recipe delete-sandbox [ local-scope |