From 294b2ab35983ebe95698835bb54bca8bd3eec101 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 11 Dec 2016 16:18:18 -0800 Subject: 3705 - switch to tested file-system primitives --- edit/005-sandbox.mu | 170 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 97 insertions(+), 73 deletions(-) (limited to 'edit/005-sandbox.mu') diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu index 0b1b82f1..7476875d 100644 --- a/edit/005-sandbox.mu +++ b/edit/005-sandbox.mu @@ -10,13 +10,10 @@ def! main [ local-scope open-console - initial-recipe:text <- restore [recipes.mu] - initial-sandbox:text <- new [] - hide-screen 0/screen - env:&:environment <- new-programming-environment 0/screen, initial-recipe, initial-sandbox + env:&:environment <- new-programming-environment 0/filesystem, 0/screen env <- restore-sandboxes env render-all 0/screen, env, render - event-loop 0/screen, 0/console, env + event-loop 0/screen, 0/console, env, 0/filesystem # never gets here ] @@ -46,14 +43,16 @@ scenario run-and-show-results [ trace-until 100/app # trace too long assume-screen 100/width, 15/height # recipe editor is empty + assume-resources [ + ] # sandbox editor contains an instruction without storing outputs - env:&:environment <- new-programming-environment screen, [], [divide-with-remainder 11, 3] + env:&:environment <- new-programming-environment resources, screen, [divide-with-remainder 11, 3] # run the code in the editors assume-console [ press F4 ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # check that screen prints the results screen-should-contain [ @@ -103,7 +102,7 @@ scenario run-and-show-results [ press F4 ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # check that screen prints both sandboxes screen-should-contain [ @@ -129,7 +128,7 @@ after [ do-run?:bool <- equal k, 65532/F4 break-unless do-run? screen <- update-status screen, [running... ], 245/grey - error?:bool, env, screen <- run-sandboxes env, screen + error?:bool <- run-sandboxes env, resources, screen # F4 might update warnings and results on both sides screen <- render-all screen, env, render { @@ -141,10 +140,10 @@ after [ } ] -def run-sandboxes env:&:environment, screen:&:screen -> errors-found?:bool, env:&:environment, screen:&:screen [ +def run-sandboxes env:&:environment, resources:&:resources, screen:&:screen -> errors-found?:bool, env:&:environment, resources:&:resources, screen:&:screen [ local-scope load-ingredients - errors-found?:bool, env, screen <- update-recipes env, screen + errors-found?:bool <- update-recipes env, resources, screen return-if errors-found? # check contents of right editor (sandbox) @@ -170,7 +169,7 @@ def run-sandboxes env:&:environment, screen:&:screen -> errors-found?:bool, env: *current-sandbox <- put *current-sandbox, top-of-screen:offset, init } # save all sandboxes before running, just in case we die when running - save-sandboxes env + save-sandboxes env, resources # run all sandboxes curr:&:sandbox <- get *env, sandbox:offset idx:num <- copy 0 @@ -184,14 +183,14 @@ def run-sandboxes env:&:environment, screen:&:screen -> errors-found?:bool, env: ] -# copy code from recipe editor, persist to disk, load +# load code from disk # replaced in a later layer (whereupon errors-found? will actually be set) -def update-recipes env:&:environment, screen:&:screen -> errors-found?:bool, env:&:environment, screen:&:screen [ +def update-recipes env:&:environment, resources:&:resources, screen:&:screen -> errors-found?:bool, env:&:environment, resources:&:resources, screen:&:screen [ local-scope load-ingredients recipes:&:editor <- get *env, recipes:offset in:text <- editor-contents recipes - save [recipes.mu], in # newlayer: persistence + resources <- dump resources, [lesson/recipes.mu], in reload in errors-found? <- copy 0/false ] @@ -213,7 +212,7 @@ def update-status screen:&:screen, msg:text, color:num -> screen:&:screen [ screen <- print screen, msg, color, 238/grey/background ] -def save-sandboxes env:&:environment [ +def save-sandboxes env:&:environment, resources:&:resources -> resources:&:resources [ local-scope load-ingredients current-sandbox:&:editor <- get *env, current-sandbox:offset @@ -224,8 +223,8 @@ def save-sandboxes env:&:environment [ { break-unless curr data:text <- get *curr, data:offset - filename:text <- to-text idx - save filename, data + filename:text <- append [lesson/], idx + resources <- dump resources, filename, data idx <- add idx, 1 curr <- get *curr, next-sandbox:offset @@ -415,7 +414,7 @@ def render-text screen:&:screen, s:text, left:num, right:num, color:num, row:num ] # assumes programming environment has no sandboxes; restores them from previous session -def restore-sandboxes env:&:environment -> env:&:environment [ +def restore-sandboxes env:&:environment, resources:&:resources -> env:&:environment [ local-scope load-ingredients # read all scenarios, pushing them to end of a list of scenarios @@ -423,8 +422,8 @@ def restore-sandboxes env:&:environment -> env:&:environment [ curr:&:sandbox <- copy 0 prev:&:sandbox <- copy 0 { - filename:text <- to-text idx - contents:text <- restore filename + filename:text <- append [lesson/], idx + contents:text <- slurp resources, filename break-unless contents # stop at first error; assuming file didn't exist # todo: handle empty sandbox # create new sandbox for file @@ -519,27 +518,32 @@ scenario run-updates-results [ trace-until 100/app # trace too long assume-screen 100/width, 12/height # define a recipe (no indent for the 'add' line below so column numbers are more obvious) - recipes:text <- new [ -recipe foo [ -local-scope -z:num <- add 2, 2 -reply z -]] + assume-resources [ + [lesson/recipes.mu] <- [ + || + |recipe foo [| + | local-scope| + | z:num <- add 2, 2| + | reply z| + |]| + ] + ] # sandbox editor contains an instruction without storing outputs - env:&:environment <- new-programming-environment screen, recipes, [foo] + env:&:environment <- new-programming-environment resources, screen, [foo] # contents of sandbox editor # run the code in the editors assume-console [ press F4 ] - event-loop screen, console, env + event-loop screen, console, env, resources screen-should-contain [ . run (F4) . . ┊ . .recipe foo [ ┊─────────────────────────────────────────────────. - .local-scope ┊0 edit copy delete . - .z:num <- add 2, 2 ┊foo . - .reply z ┊4 . + . local-scope ┊0 edit copy delete . + . z:num <- add 2, 2 ┊foo . + . reply z ┊4 . .] ┊─────────────────────────────────────────────────. + . ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . . ┊ . ] @@ -551,17 +555,18 @@ reply z press F4 ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # check that screen updates the result on the right screen-should-contain [ . run (F4) . . ┊ . .recipe foo [ ┊─────────────────────────────────────────────────. - .local-scope ┊0 edit copy delete . - .z:num <- add 2, 3 ┊foo . - .reply z ┊5 . + . local-scope ┊0 edit copy delete . + . z:num <- add 2, 3 ┊foo . + . reply z ┊5 . .] ┊─────────────────────────────────────────────────. + . ┊ . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . . ┊ . ] @@ -571,15 +576,17 @@ scenario run-instruction-manages-screen-per-sandbox [ local-scope trace-until 100/app # trace too long assume-screen 100/width, 20/height - # left editor is empty - # right editor contains an instruction - env:&:environment <- new-programming-environment screen, [], [print-integer screen, 4] + # empty recipes + assume-resources [ + ] + # sandbox editor contains an instruction + env:&:environment <- new-programming-environment resources, screen, [print-integer screen, 4] # contents of sandbox editor # run the code in the editor assume-console [ press F4 ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # check that it prints a little toy screen screen-should-contain [ @@ -642,13 +649,15 @@ scenario scrolling-down-past-bottom-of-recipe-editor [ local-scope trace-until 100/app assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [] + assume-resources [ + ] + env:&:environment <- new-programming-environment resources, screen, [] render-all screen, env, render assume-console [ press enter press down-arrow ] - event-loop screen, console, env + event-loop screen, console, env, resources # no scroll screen-should-contain [ . run (F4) . @@ -663,14 +672,16 @@ scenario cursor-down-in-recipe-editor [ local-scope trace-until 100/app assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [] + assume-resources [ + ] + env:&:environment <- new-programming-environment resources, screen, [] render-all screen, env, render assume-console [ press enter press up-arrow press down-arrow # while cursor isn't at bottom ] - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor # cursor moves back to bottom @@ -741,7 +752,9 @@ scenario scrolling-down-past-bottom-of-recipe-editor-2 [ local-scope trace-until 100/app assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [] + assume-resources [ + ] + env:&:environment <- new-programming-environment resources, screen, [] render-all screen, env, render assume-console [ # add a line @@ -751,7 +764,7 @@ scenario scrolling-down-past-bottom-of-recipe-editor-2 [ # try to scroll press page-down # or ctrl-f ] - event-loop screen, console, env + event-loop screen, console, env, resources # no scroll, and cursor remains at top line screen-should-contain [ . run (F4) . @@ -766,7 +779,9 @@ scenario scrolling-down-past-bottom-of-recipe-editor-3 [ local-scope trace-until 100/app assume-screen 100/width, 10/height - env:&:environment <- new-programming-environment screen, [], [ab + assume-resources [ + ] + env:&:environment <- new-programming-environment resources, screen, [ab cd] render-all screen, env, render assume-console [ @@ -777,7 +792,7 @@ cd] # move cursor press down-arrow ] - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor # no scroll on recipe side, cursor moves on sandbox side @@ -796,14 +811,16 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ local-scope trace-until 100/app # trace too long assume-screen 100/width, 10/height - # initialize sandbox side - env:&:environment <- new-programming-environment screen, [], [add 2, 2] + # initialize + assume-resources [ + ] + env:&:environment <- new-programming-environment resources, screen, [add 2, 2] render-all screen, env, render assume-console [ # create a sandbox press F4 ] - event-loop screen, console, env + event-loop screen, console, env, resources screen-should-contain [ . run (F4) . . ┊ . @@ -817,7 +834,7 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ press page-down ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor ] @@ -835,7 +852,7 @@ scenario scrolling-down-past-bottom-of-sandbox-editor [ press page-up ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor ] @@ -924,30 +941,33 @@ def previous-sandbox env:&:environment, in:&:sandbox -> out:&:sandbox [ return curr ] -scenario scrolling-down-on-recipe-side [ +scenario scrolling-down-past-bottom-on-recipe-side [ local-scope trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize sandbox side and create a sandbox - recipes:text <- new [ -] + assume-resources [ + [lesson/recipes.mu] <- [ + || # file containing just a newline + ] + ] # create a sandbox - env:&:environment <- new-programming-environment screen, recipes:text, [add 2, 2] + env:&:environment <- new-programming-environment resources, screen, [add 2, 2] render-all screen, env, render assume-console [ press F4 ] - event-loop screen, console, env + event-loop screen, console, env, resources # hit 'down' in recipe editor assume-console [ press page-down ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor ] - # cursor moves down on recipe side + # cursor doesn't move when the end is already on-screen screen-should-contain [ . run (F4) . .␣ ┊ . @@ -962,7 +982,9 @@ scenario scrolling-through-multiple-sandboxes [ trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + assume-resources [ + ] + env:&:environment <- new-programming-environment resources, screen, [] render-all screen, env, render # create 2 sandboxes assume-console [ @@ -972,7 +994,7 @@ scenario scrolling-through-multiple-sandboxes [ type [add 1, 1] press F4 ] - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor screen-should-contain [ @@ -992,7 +1014,7 @@ scenario scrolling-through-multiple-sandboxes [ press page-down ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor ] @@ -1014,7 +1036,7 @@ scenario scrolling-through-multiple-sandboxes [ press page-down ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # just second sandbox displayed screen-should-contain [ @@ -1031,7 +1053,7 @@ scenario scrolling-through-multiple-sandboxes [ press page-down ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # no change screen-should-contain [ @@ -1048,7 +1070,7 @@ scenario scrolling-through-multiple-sandboxes [ press page-up ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # back to displaying both sandboxes without editor screen-should-contain [ @@ -1067,7 +1089,7 @@ scenario scrolling-through-multiple-sandboxes [ press page-up ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor ] @@ -1089,7 +1111,7 @@ scenario scrolling-through-multiple-sandboxes [ press page-up ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources cursor:char <- copy 9251/␣ print screen, cursor ] @@ -1113,7 +1135,9 @@ scenario scrolling-manages-sandbox-index-correctly [ trace-until 100/app # trace too long assume-screen 100/width, 10/height # initialize environment - env:&:environment <- new-programming-environment screen, [], [] + assume-resources [ + ] + env:&:environment <- new-programming-environment resources, screen, [] render-all screen, env, render # create a sandbox assume-console [ @@ -1121,7 +1145,7 @@ scenario scrolling-manages-sandbox-index-correctly [ type [add 1, 1] press F4 ] - event-loop screen, console, env + event-loop screen, console, env, resources screen-should-contain [ . run (F4) . . ┊ . @@ -1137,7 +1161,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press page-down ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox @@ -1155,7 +1179,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press page-up ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # back to displaying both sandboxes as well as editor screen-should-contain [ @@ -1173,7 +1197,7 @@ scenario scrolling-manages-sandbox-index-correctly [ press page-down ] run [ - event-loop screen, console, env + event-loop screen, console, env, resources ] # sandbox editor hidden; first sandbox displayed # cursor moves to first sandbox -- cgit 1.4.1-2-gfad0