From 23ea84415c6a028aa3cb9aaf1f8768a7dbb7ed78 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 5 Sep 2015 15:24:11 -0700 Subject: 2166 --- edit/004-programming-environment.mu | 17 +--- edit/005-sandbox.mu | 182 ++++++---------------------------- edit/010-warnings.mu | 190 ++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+), 168 deletions(-) diff --git a/edit/004-programming-environment.mu b/edit/004-programming-environment.mu index 495b183a..5babc9e3 100644 --- a/edit/004-programming-environment.mu +++ b/edit/004-programming-environment.mu @@ -18,7 +18,6 @@ recipe main [ container programming-environment-data [ recipes:address:editor-data - recipe-warnings:address:array:character current-sandbox:address:editor-data sandbox-in-focus?:boolean # false => cursor in recipes; true => cursor in current-sandbox ] @@ -401,14 +400,7 @@ recipe render-all [ # screen <- render-recipes screen, env screen <- render-sandbox-side screen, env - # error message - trace 11, [app], [render status] - recipe-warnings:address:array:character <- get *env, recipe-warnings:offset - { - break-unless recipe-warnings - status:address:array:character <- new [errors found] - update-status screen, status, 1/red - } + # recipes:address:editor-data <- get *env, recipes:offset current-sandbox:address:editor-data <- get *env, current-sandbox:offset @@ -430,13 +422,8 @@ recipe render-recipes [ right:number <- get *recipes, right:offset row:number, column:number, screen <- render screen, recipes clear-line-delimited screen, column, right - recipe-warnings:address:array:character <- get *env, recipe-warnings:offset row <- add row, 1 - { - # print any warnings - break-unless recipe-warnings - row, screen <- render-string screen, recipe-warnings, left, right, 1/red, row - } + # draw dotted line after recipes draw-horizontal screen, row, left, right, 9480/horizontal-dotted row <- add row, 1 diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu index cc17da23..99a44ba6 100644 --- a/edit/005-sandbox.mu +++ b/edit/005-sandbox.mu @@ -11,7 +11,6 @@ container programming-environment-data [ container sandbox-data [ data:address:array:character response:address:array:character - warnings:address:array:character trace:address:array:character expected-response:address:array:character # coordinates to track clicks @@ -108,7 +107,7 @@ after [ break-unless do-run? status:address:array:character <- new [running... ] screen <- update-status screen, status, 245/grey - screen, error?:boolean <- run-sandboxes env, screen + error?:boolean, env, screen <- run-sandboxes env, screen # F4 might update warnings and results on both sides screen <- render-all screen, env { @@ -125,19 +124,8 @@ recipe run-sandboxes [ local-scope env:address:programming-environment-data <- next-ingredient screen:address <- next-ingredient - recipes:address:editor-data <- get *env, recipes:offset - # copy code from recipe editor, persist, load into mu, save any warnings - in:address:array:character <- editor-contents recipes - save [recipes.mu], in - recipe-warnings:address:address:array:character <- get-address *env, recipe-warnings:offset - *recipe-warnings <- reload in - # if recipe editor has errors, stop - { - break-unless *recipe-warnings - status:address:array:character <- new [errors found] - update-status screen, status, 1/red - reply screen/same-as-ingredient:1, 1/errors-found - } + stop?:boolean, env, screen <- update-recipes env, screen + reply-if stop?, 1/errors-found, env/same-as-ingredient:0, screen/same-as-ingredient:1 # check contents of right editor (sandbox) current-sandbox:address:editor-data <- get *env, current-sandbox:offset { @@ -165,22 +153,34 @@ recipe run-sandboxes [ curr:address:sandbox-data <- get *env, sandbox:offset { break-unless curr - data <- get-address *curr, data:offset - response:address:address:array:character <- get-address *curr, response:offset - warnings:address:address:array:character <- get-address *curr, warnings:offset - trace:address:address:array:character <- get-address *curr, trace:offset - fake-screen:address:address:screen <- get-address *curr, screen:offset - *response, *warnings, *fake-screen, *trace, completed?:boolean <- run-interactive *data - { - break-if *warnings - break-if completed?:boolean - *warnings <- new [took too long! -] - } + update-sandbox curr curr <- get *curr, next-sandbox:offset loop } - reply screen/same-as-ingredient:1, 0/no-errors-found + reply 0/no-errors-found, env/same-as-ingredient:0, screen/same-as-ingredient:1 +] + +# copy code from recipe editor, persist, load into mu +# replaced in a later layer +recipe update-recipes [ + local-scope + env:address:programming-environment-data <- next-ingredient + screen:address <- next-ingredient + recipes:address:editor-data <- get *env, recipes:offset + in:address:array:character <- editor-contents recipes + save [recipes.mu], in + reload in + reply 0/no-errors-found, env/same-as-ingredient:0, screen/same-as-ingredient:1 +] + +recipe update-sandbox [ + local-scope + sandbox:address:sandbox-data <- next-ingredient + data:address:array:character <- get *sandbox, data:offset + response:address:address:array:character <- get-address *sandbox, response:offset + trace:address:address:array:character <- get-address *sandbox, trace:offset + fake-screen:address:address:screen <- get-address *sandbox, screen:offset + *response, _, *fake-screen, *trace <- run-interactive data ] recipe update-status [ @@ -266,16 +266,9 @@ recipe render-sandboxes [ # render sandbox warnings, screen or response, in that order response-starting-row:address:number <- get-address *sandbox, response-starting-row-on-screen:offset sandbox-response:address:array:character <- get *sandbox, response:offset - sandbox-warnings:address:array:character <- get *sandbox, warnings:offset - sandbox-screen:address <- get *sandbox, screen:offset { - break-unless sandbox-warnings - *response-starting-row <- copy 0 # no response - row, screen <- render-string screen, sandbox-warnings, left, right, 1/red, row - jump +render-sandbox-end:label - } - { + sandbox-screen:address <- get *sandbox, screen:offset empty-screen?:boolean <- fake-screen-is-empty? sandbox-screen break-if empty-screen? row, screen <- render-screen screen, sandbox-screen, left, right, row @@ -453,92 +446,6 @@ z:number <- add 2, 2 ] ] -scenario run-instruction-and-print-warnings [ - $close-trace # trace too long - assume-screen 100/width, 10/height - # left editor is empty - 1:address:array:character <- new [] - # right editor contains an illegal instruction - 2:address:array:character <- new [get 1234:number, foo:offset] - 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character - # run the code in the editors - assume-console [ - press F4 - ] - run [ - event-loop screen:address, console:address, 3:address:programming-environment-data - ] - # check that screen prints error message in red - screen-should-contain [ - . run (F4) . - . ┊ . - .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. - . ┊ x. - . ┊get 1234:number, foo:offset . - . ┊unknown element foo in container number . - . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. - . ┊ . - ] - screen-should-contain-in-color 7/white, [ - . . - . . - . . - . . - . get 1234:number, foo:offset . - . . - . . - . . - ] - screen-should-contain-in-color 1/red, [ - . . - . . - . . - . . - . . - . unknown element foo in container number . - . . - ] - screen-should-contain-in-color 245/grey, [ - . . - . ┊ . - .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. - . ┊ x. - . ┊ . - . ┊ . - . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. - . ┊ . - ] -] - -scenario run-instruction-and-print-warnings-only-once [ - $close-trace # trace too long - assume-screen 100/width, 10/height - # left editor is empty - 1:address:array:character <- new [] - # right editor contains an illegal instruction - 2:address:array:character <- new [get 1234:number, foo:offset] - 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character - # run the code in the editors multiple times - assume-console [ - press F4 - press F4 - ] - run [ - event-loop screen:address, console:address, 3:address:programming-environment-data - ] - # check that screen prints error message just once - screen-should-contain [ - . run (F4) . - . ┊ . - .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. - . ┊ x. - . ┊get 1234:number, foo:offset . - . ┊unknown element foo in container number . - . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. - . ┊ . - ] -] - scenario run-instruction-manages-screen-per-sandbox [ $close-trace # trace too long assume-screen 100/width, 20/height @@ -572,37 +479,6 @@ scenario run-instruction-manages-screen-per-sandbox [ ] ] -scenario sandbox-can-handle-infinite-loop [ - $close-trace # trace too long - assume-screen 100/width, 20/height - # left editor is empty - 1:address:array:character <- new [recipe foo [ - { - loop - } -]] - # right editor contains an instruction - 2:address:array:character <- new [foo] - 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character - # run the sandbox - assume-console [ - press F4 - ] - run [ - event-loop screen:address, console:address, 3:address:programming-environment-data - ] - screen-should-contain [ - . run (F4) . - .recipe foo [ ┊ . - . { ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. - . loop ┊ x. - . } ┊foo . - .] ┊took too long! . - .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. - . ┊ . - ] -] - recipe editor-contents [ local-scope editor:address:editor-data <- next-ingredient diff --git a/edit/010-warnings.mu b/edit/010-warnings.mu index b20d930b..6605f672 100644 --- a/edit/010-warnings.mu +++ b/edit/010-warnings.mu @@ -1,5 +1,78 @@ ## handling malformed programs +container programming-environment-data [ + recipe-warnings:address:array:character +] + +# copy code from recipe editor, persist, load into mu, save any warnings +recipe! update-recipes [ + local-scope + env:address:programming-environment-data <- next-ingredient + screen:address <- next-ingredient + recipes:address:editor-data <- get *env, recipes:offset + in:address:array:character <- editor-contents recipes + save [recipes.mu], in + recipe-warnings:address:address:array:character <- get-address *env, recipe-warnings:offset + *recipe-warnings <- reload in + # if recipe editor has errors, stop + { + break-unless *recipe-warnings + status:address:array:character <- new [errors found] + update-status screen, status, 1/red + reply 1/errors-found, env/same-as-ingredient:0, screen/same-as-ingredient:1 + } + reply 0/no-errors-found, env/same-as-ingredient:0, screen/same-as-ingredient:1 +] + +before [ + trace 11, [app], [render status] + recipe-warnings:address:array:character <- get *env, recipe-warnings:offset + { + break-unless recipe-warnings + status:address:array:character <- new [errors found] + update-status screen, status, 1/red + } +] + +before [ + { + recipe-warnings:address:array:character <- get *env, recipe-warnings:offset + break-unless recipe-warnings + row, screen <- render-string screen, recipe-warnings, left, right, 1/red, row + } +] + +container sandbox-data [ + warnings:address:array:character +] + +recipe! update-sandbox [ + local-scope + sandbox:address:sandbox-data <- next-ingredient + data:address:array:character <- get *sandbox, data:offset + response:address:address:array:character <- get-address *sandbox, response:offset + warnings:address:address:array:character <- get-address *sandbox, warnings:offset + trace:address:address:array:character <- get-address *sandbox, trace:offset + fake-screen:address:address:screen <- get-address *sandbox, screen:offset + *response, *warnings, *fake-screen, *trace, completed?:boolean <- run-interactive data + { + break-if *warnings + break-if completed?:boolean + *warnings <- new [took too long! +] + } +] + +after [ + { + sandbox-warnings:address:array:character <- get *sandbox, warnings:offset + break-unless sandbox-warnings + *response-starting-row <- copy 0 # no response + row, screen <- render-string screen, sandbox-warnings, left, right, 1/red, row + jump +render-sandbox-end:label + } +] + scenario run-shows-warnings-in-get [ $close-trace # trace too long assume-screen 100/width, 15/height @@ -197,3 +270,120 @@ recipe foo [ . ┊ . ] ] + +scenario run-instruction-and-print-warnings [ + $close-trace # trace too long + assume-screen 100/width, 10/height + # left editor is empty + 1:address:array:character <- new [] + # right editor contains an illegal instruction + 2:address:array:character <- new [get 1234:number, foo:offset] + 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + # run the code in the editors + assume-console [ + press F4 + ] + run [ + event-loop screen:address, console:address, 3:address:programming-environment-data + ] + # check that screen prints error message in red + screen-should-contain [ + . run (F4) . + . ┊ . + .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. + . ┊ x. + . ┊get 1234:number, foo:offset . + . ┊unknown element foo in container number . + . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. + . ┊ . + ] + screen-should-contain-in-color 7/white, [ + . . + . . + . . + . . + . get 1234:number, foo:offset . + . . + . . + . . + ] + screen-should-contain-in-color 1/red, [ + . . + . . + . . + . . + . . + . unknown element foo in container number . + . . + ] + screen-should-contain-in-color 245/grey, [ + . . + . ┊ . + .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. + . ┊ x. + . ┊ . + . ┊ . + . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. + . ┊ . + ] +] + +scenario run-instruction-and-print-warnings-only-once [ + $close-trace # trace too long + assume-screen 100/width, 10/height + # left editor is empty + 1:address:array:character <- new [] + # right editor contains an illegal instruction + 2:address:array:character <- new [get 1234:number, foo:offset] + 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + # run the code in the editors multiple times + assume-console [ + press F4 + press F4 + ] + run [ + event-loop screen:address, console:address, 3:address:programming-environment-data + ] + # check that screen prints error message just once + screen-should-contain [ + . run (F4) . + . ┊ . + .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. + . ┊ x. + . ┊get 1234:number, foo:offset . + . ┊unknown element foo in container number . + . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. + . ┊ . + ] +] + +scenario sandbox-can-handle-infinite-loop [ + $close-trace # trace too long + assume-screen 100/width, 20/height + # left editor is empty + 1:address:array:character <- new [recipe foo [ + { + loop + } +]] + # right editor contains an instruction + 2:address:array:character <- new [foo] + 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character + # run the sandbox + assume-console [ + press F4 + ] + run [ + event-loop screen:address, console:address, 3:address:programming-environment-data + ] + screen-should-contain [ + . run (F4) . + .recipe foo [ ┊ . + . { ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. + . loop ┊ x. + . } ┊foo . + .] ┊took too long! . + .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. + . ┊ . + ] +] -- cgit 1.4.1-2-gfad0