about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-01-22 08:59:38 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-01-22 08:59:38 -0800
commit6cb233fc43239c67caffadbd47e51594232e23bd (patch)
tree4a21f8ab2c8e988b1a838c6637d4be08e3f68bfd
parent3151fb2387439475e12a354f2905a77ccb80ca19 (diff)
downloadmu-6cb233fc43239c67caffadbd47e51594232e23bd.tar.gz
2586 - show first sandbox with error in status
-rw-r--r--081print.mu1
-rw-r--r--edit/004-programming-environment.mu3
-rw-r--r--edit/005-sandbox.mu15
-rw-r--r--edit/009-sandbox-trace.mu2
-rw-r--r--edit/010-warnings.mu66
-rw-r--r--sandbox/004-programming-environment.mu3
-rw-r--r--sandbox/005-sandbox.mu14
-rw-r--r--sandbox/009-sandbox-trace.mu2
-rw-r--r--sandbox/010-warnings.mu61
9 files changed, 137 insertions, 30 deletions
diff --git a/081print.mu b/081print.mu
index 464e1320..1683b308 100644
--- a/081print.mu
+++ b/081print.mu
@@ -127,6 +127,7 @@ recipe print screen:address:shared:screen, c:character -> screen:address:shared:
     reply-unless legal?
     legal? <- lesser-than *column, width
     reply-unless legal?
+#?     $print [print-character (], *row, [, ], *column, [): ], c, 10/newline
     # special-case: newline
     {
       newline?:boolean <- equal c, 10/newline
diff --git a/edit/004-programming-environment.mu b/edit/004-programming-environment.mu
index 99cefbb4..359a32e2 100644
--- a/edit/004-programming-environment.mu
+++ b/edit/004-programming-environment.mu
@@ -45,6 +45,7 @@ recipe new-programming-environment screen:address:shared:screen, initial-recipe-
   new-left:number <- add divider, 1
   current-sandbox:address:address:shared:editor-data <- get-address *result, current-sandbox:offset
   *current-sandbox <- new-editor initial-sandbox-contents, screen, new-left, width/right
+  <programming-environment-initialization>
 ]
 
 recipe event-loop screen:address:shared:screen, console:address:shared:console, env:address:shared:programming-environment-data -> screen:address:shared:screen, console:address:shared:console, env:address:shared:programming-environment-data [
@@ -379,7 +380,9 @@ recipe render-all screen:address:shared:screen, env:address:shared:programming-e
   # top menu
   trace 11, [app], [render top menu]
   width:number <- screen-width screen
+#?   $print [draw menu], 10/newline
   draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey
+#?   $print [draw menu end], 10/newline
   button-start:number <- subtract width, 20
   button-on-screen?:boolean <- greater-or-equal button-start, 0
   assert button-on-screen?, [screen too narrow for menu]
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index 6b442a91..cd92bfa9 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -122,14 +122,16 @@ after <global-keypress> [
     do-run?:boolean <- equal *k, 65532/F4
     break-unless do-run?
 #?     $log [F4 pressed]
-    status:address:shared:array:character <- new [running...  ]
+    status:address:shared:array:character <- new [running...       ]
     screen <- update-status screen, status, 245/grey
     error?:boolean, env, screen <- run-sandboxes env, screen
     # F4 might update warnings and results on both sides
+#?     $print [render-all begin], 10/newline
     screen <- render-all screen, env
+#?     $print [render-all end], 10/newline
     {
       break-if error?
-      status:address:shared:array:character <- new [            ]
+      status:address:shared:array:character <- new [                 ]
       screen <- update-status screen, status, 245/grey
     }
     screen <- update-cursor screen, recipes, current-sandbox, *sandbox-in-focus?
@@ -143,6 +145,7 @@ recipe run-sandboxes env:address:shared:programming-environment-data, screen:add
   errors-found?:boolean, env, screen <- update-recipes env, screen
   reply-if errors-found?
   # check contents of right editor (sandbox)
+  <run-sandboxes-begin>
   current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset
   {
     sandbox-contents:address:shared:array:character <- editor-contents current-sandbox
@@ -167,13 +170,15 @@ recipe run-sandboxes env:address:shared:programming-environment-data, screen:add
   save-sandboxes env
   # run all sandboxes
   curr:address:shared:sandbox-data <- get *env, sandbox:offset
+  idx:number <- copy 0
   {
     break-unless curr
-    curr <- update-sandbox curr
+    curr <- update-sandbox curr, env, idx
     curr <- get *curr, next-sandbox:offset
+    idx <- add idx, 1
     loop
   }
-  errors-found? <- copy 0/false
+  <run-sandboxes-end>
 ]
 
 # copy code from recipe editor, persist, load into mu
@@ -189,7 +194,7 @@ recipe update-recipes env:address:shared:programming-environment-data, screen:ad
 ]
 
 # replaced in a later layer
-recipe update-sandbox sandbox:address:shared:sandbox-data -> sandbox:address:shared:sandbox-data [
+recipe! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [
   local-scope
   load-ingredients
   data:address:shared:array:character <- get *sandbox, data:offset
diff --git a/edit/009-sandbox-trace.mu b/edit/009-sandbox-trace.mu
index ddf3dbf5..68dca1ab 100644
--- a/edit/009-sandbox-trace.mu
+++ b/edit/009-sandbox-trace.mu
@@ -127,7 +127,7 @@ container sandbox-data [
 ]
 
 # replaced in a later layer
-recipe! update-sandbox sandbox:address:shared:sandbox-data -> sandbox:address:shared:sandbox-data [
+recipe! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [
   local-scope
   load-ingredients
   data:address:shared:array:character <- get *sandbox, data:offset
diff --git a/edit/010-warnings.mu b/edit/010-warnings.mu
index 313de970..9b886508 100644
--- a/edit/010-warnings.mu
+++ b/edit/010-warnings.mu
@@ -17,7 +17,7 @@ recipe! update-recipes env:address:shared:programming-environment-data, screen:a
   # if recipe editor has errors, stop
   {
     break-unless *recipe-warnings
-    status:address:shared:array:character <- new [errors found]
+    status:address:shared:array:character <- new [errors found     ]
     update-status screen, status, 1/red
     errors-found? <- copy 1/true
     reply
@@ -30,7 +30,7 @@ before <render-components-end> [
   recipe-warnings:address:shared:array:character <- get *env, recipe-warnings:offset
   {
     break-unless recipe-warnings
-    status:address:shared:array:character <- new [errors found]
+    status:address:shared:array:character <- new [errors found     ]
     update-status screen, status, 1/red
   }
 ]
@@ -43,11 +43,49 @@ before <render-recipe-components-end> [
   }
 ]
 
+container programming-environment-data [
+  warning-index:number  # index of first sandbox with an error (or -1 if none)
+]
+
+after <programming-environment-initialization> [
+  warning-index:address:number <- get-address *result, warning-index:offset
+  *warning-index <- copy -1
+]
+
+after <run-sandboxes-begin> [
+  warning-index:address:number <- get-address *env, warning-index:offset
+  *warning-index <- copy -1
+]
+
+before <run-sandboxes-end> [
+  {
+    sandboxes-completed-successfully?:boolean <- equal *warning-index, -1
+    break-if sandboxes-completed-successfully?
+    errors-found? <- copy 1/true
+  }
+]
+
+before <render-components-end> [
+  {
+    break-if recipe-warnings
+    warning-index:number <- get *env, warning-index:offset
+    sandboxes-completed-successfully?:boolean <- equal warning-index, -1
+    break-if sandboxes-completed-successfully?
+    status-template:address:shared:array:character <- new [errors found (_)    ]
+    warning-index-text:address:shared:array:character <- to-text warning-index
+    status:address:shared:array:character <- interpolate status-template, warning-index-text
+#?     $print [update-status: sandbox warning], 10/newline
+    update-status screen, status, 1/red
+#?     $print [run sandboxes end], 10/newline
+    reply
+  }
+]
+
 container sandbox-data [
   warnings:address:shared:array:character
 ]
 
-recipe! update-sandbox sandbox:address:shared:sandbox-data -> sandbox:address:shared:sandbox-data [
+recipe! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [
   local-scope
   load-ingredients
 #?   $log [update sandbox]
@@ -64,6 +102,12 @@ recipe! update-sandbox sandbox:address:shared:sandbox-data -> sandbox:address:sh
     *warnings <- new [took too long!
 ]
   }
+  {
+    break-unless *warnings
+#?     $print [setting warning-index to ], idx, 10/newline
+    warning-index:address:number <- get-address *env, warning-index:offset
+    *warning-index <- copy idx
+  }
 #?   $print [done with run-interactive], 10/newline
 ]
 
@@ -170,7 +214,7 @@ z <- add x, [a]
     event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data
   ]
   screen-should-contain [
-    .                                                                                 run (F4)           .
+    .  errors found (0)                                                               run (F4)           .
     .recipe foo x:_elem -> z:_elem [                   ┊                                                 .
     .local-scope                                       ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .load-ingredients                                  ┊0                                               x.
@@ -189,7 +233,7 @@ z <- add x, [a]
   ]
   # error should remain unchanged
   screen-should-contain [
-    .                                                                                 run (F4)           .
+    .  errors found (0)                                                               run (F4)           .
     .recipe foo x:_elem -> z:_elem [                   ┊                                                 .
     .local-scope                                       ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .load-ingredients                                  ┊0                                               x.
@@ -441,7 +485,7 @@ scenario run-instruction-and-print-warnings [
   ]
   # check that screen prints error message in red
   screen-should-contain [
-    .                                                                                 run (F4)           .
+    .  errors found (0)                                                               run (F4)           .
     .                                                  ┊                                                 .
     .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .                                                  ┊0                                               x.
@@ -463,7 +507,7 @@ scenario run-instruction-and-print-warnings [
     .                                                                                                    .
   ]
   screen-should-contain-in-color 1/red, [
-    .                                                                                                    .
+    .  errors found (0)                                                                                  .
     .                                                                                                    .
     .                                                                                                    .
     .                                                                                                    .
@@ -505,7 +549,7 @@ scenario run-instruction-and-print-warnings-only-once [
   ]
   # check that screen prints error message just once
   screen-should-contain [
-    .                                                                                 run (F4)           .
+    .  errors found (0)                                                               run (F4)           .
     .                                                  ┊                                                 .
     .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .                                                  ┊0                                               x.
@@ -538,7 +582,7 @@ scenario sandbox-can-handle-infinite-loop [
     event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data
   ]
   screen-should-contain [
-    .                                                                                 run (F4)           .
+    .  errors found (0)                                                               run (F4)           .
     .recipe foo [                                      ┊                                                 .
     .  {                                               ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .    loop                                          ┊0                                               x.
@@ -570,7 +614,7 @@ reply b
   event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data
   # screen prints error message
   screen-should-contain [
-    .                                                                                 run (F4)           .
+    .  errors found (0)                                                               run (F4)           .
     .recipe foo [                                      ┊                                                 .
     .local-scope                                       ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .a:number <- next-ingredient                       ┊0                                               x.
@@ -589,7 +633,7 @@ reply b
   ]
   # screen should expand trace
   screen-should-contain [
-    .                                                                                 run (F4)           .
+    .  errors found (0)                                                               run (F4)           .
     .recipe foo [                                      ┊                                                 .
     .local-scope                                       ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .a:number <- next-ingredient                       ┊0                                               x.
diff --git a/sandbox/004-programming-environment.mu b/sandbox/004-programming-environment.mu
index b6c50fbf..81484f0f 100644
--- a/sandbox/004-programming-environment.mu
+++ b/sandbox/004-programming-environment.mu
@@ -36,6 +36,7 @@ recipe new-programming-environment screen:address:shared:screen, initial-sandbox
   # sandbox editor
   current-sandbox:address:address:shared:editor-data <- get-address *result, current-sandbox:offset
   *current-sandbox <- new-editor initial-sandbox-contents, screen, 0, width/right
+  <programming-environment-initialization>
 ]
 
 recipe event-loop screen:address:shared:screen, console:address:shared:console, env:address:shared:programming-environment-data -> screen:address:shared:screen, console:address:shared:console, env:address:shared:programming-environment-data [
@@ -159,7 +160,9 @@ recipe render-all screen:address:shared:screen, env:address:shared:programming-e
   # top menu
   trace 11, [app], [render top menu]
   width:number <- screen-width screen
+#?   $print [draw menu], 10/newline
   draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey
+#?   $print [draw menu end], 10/newline
   button-start:number <- subtract width, 20
   button-on-screen?:boolean <- greater-or-equal button-start, 0
   assert button-on-screen?, [screen too narrow for menu]
diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu
index 2ad25dd4..19bce3d7 100644
--- a/sandbox/005-sandbox.mu
+++ b/sandbox/005-sandbox.mu
@@ -106,14 +106,15 @@ after <global-keypress> [
   {
     do-run?:boolean <- equal *k, 65532/F4
     break-unless do-run?
-    status:address:shared:array:character <- new [running...  ]
+    status:address:shared:array:character <- new [running...       ]
     screen <- update-status screen, status, 245/grey
     error?:boolean, env, screen <- run-sandboxes env, screen
     # F4 might update warnings and results on both sides
     screen <- render-all screen, env
     {
       break-if error?
-      status:address:shared:array:character <- new [            ]
+#?       $print [update-status: clearing], 10/newline
+      status:address:shared:array:character <- new [                 ]
       screen <- update-status screen, status, 245/grey
     }
     screen <- update-cursor screen, current-sandbox
@@ -127,6 +128,7 @@ recipe run-sandboxes env:address:shared:programming-environment-data, screen:add
   errors-found?:boolean, env, screen <- update-recipes env, screen
   reply-if errors-found?
   # check contents of editor
+  <run-sandboxes-begin>
   current-sandbox:address:shared:editor-data <- get *env, current-sandbox:offset
   {
     sandbox-contents:address:shared:array:character <- editor-contents current-sandbox
@@ -151,13 +153,15 @@ recipe run-sandboxes env:address:shared:programming-environment-data, screen:add
   save-sandboxes env
   # run all sandboxes
   curr:address:shared:sandbox-data <- get *env, sandbox:offset
+  idx:number <- copy 0
   {
     break-unless curr
-    curr <- update-sandbox curr, env
+    curr <- update-sandbox curr, env, idx
     curr <- get *curr, next-sandbox:offset
+    idx <- add idx, 1
     loop
   }
-  reply 0/no-errors-found, env/same-as-ingredient:0, screen/same-as-ingredient:1
+  <run-sandboxes-end>
 ]
 
 # load code from recipes.mu
@@ -171,7 +175,7 @@ recipe update-recipes env:address:shared:programming-environment-data, screen:ad
 ]
 
 # replaced in a later layer
-recipe update-sandbox sandbox:address:shared:sandbox-data -> sandbox:address:shared:sandbox-data [
+recipe! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [
   local-scope
   load-ingredients
   data:address:shared:array:character <- get *sandbox, data:offset
diff --git a/sandbox/009-sandbox-trace.mu b/sandbox/009-sandbox-trace.mu
index 06a7cdec..8ca16327 100644
--- a/sandbox/009-sandbox-trace.mu
+++ b/sandbox/009-sandbox-trace.mu
@@ -119,7 +119,7 @@ container sandbox-data [
 ]
 
 # replaced in a later layer
-recipe! update-sandbox sandbox:address:shared:sandbox-data -> sandbox:address:shared:sandbox-data [
+recipe! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [
   local-scope
   load-ingredients
   data:address:shared:array:character <- get *sandbox, data:offset
diff --git a/sandbox/010-warnings.mu b/sandbox/010-warnings.mu
index 16a6a92c..317a857a 100644
--- a/sandbox/010-warnings.mu
+++ b/sandbox/010-warnings.mu
@@ -14,8 +14,10 @@ recipe! update-recipes env:address:shared:programming-environment-data, screen:a
   # if recipe editor has errors, stop
   {
     break-unless *recipe-warnings
-    status:address:shared:array:character <- new [errors found]
+    status:address:shared:array:character <- new [errors found     ]
     update-status screen, status, 1/red
+    errors-found? <- copy 1/true
+    reply
   }
   errors-found? <- copy 0/false
 ]
@@ -25,8 +27,46 @@ before <render-components-end> [
   recipe-warnings:address:shared:array:character <- get *env, recipe-warnings:offset
   {
     break-unless recipe-warnings
-    status:address:shared:array:character <- new [errors found]
+    status:address:shared:array:character <- new [errors found     ]
+    update-status screen, status, 1/red
+  }
+]
+
+container programming-environment-data [
+  warning-index:number  # index of first sandbox with an error (or -1 if none)
+]
+
+after <programming-environment-initialization> [
+  warning-index:address:number <- get-address *result, warning-index:offset
+  *warning-index <- copy -1
+]
+
+after <run-sandboxes-begin> [
+  warning-index:address:number <- get-address *env, warning-index:offset
+  *warning-index <- copy -1
+]
+
+before <run-sandboxes-end> [
+  {
+    sandboxes-completed-successfully?:boolean <- equal *warning-index, -1
+    break-if sandboxes-completed-successfully?
+    errors-found? <- copy 1/true
+  }
+]
+
+before <render-components-end> [
+  {
+    break-if recipe-warnings
+    warning-index:number <- get *env, warning-index:offset
+    sandboxes-completed-successfully?:boolean <- equal warning-index, -1
+    break-if sandboxes-completed-successfully?
+    status-template:address:shared:array:character <- new [errors found (_)    ]
+    warning-index-text:address:shared:array:character <- to-text warning-index
+    status:address:shared:array:character <- interpolate status-template, warning-index-text
+#?     $print [update-status: sandbox warning], 10/newline
     update-status screen, status, 1/red
+#?     $print [run sandboxes end], 10/newline
+    reply
   }
 ]
 
@@ -34,7 +74,7 @@ container sandbox-data [
   warnings:address:shared:array:character
 ]
 
-recipe! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data -> sandbox:address:shared:sandbox-data [
+recipe! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [
   local-scope
   load-ingredients
   data:address:shared:array:character <- get *sandbox, data:offset
@@ -55,6 +95,13 @@ recipe! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:p
     *warnings <- new [took too long!
 ]
   }
+  {
+    break-unless *warnings
+#?     $print [setting warning-index to ], idx, 10/newline
+    warning-index:address:number <- get-address *env, warning-index:offset
+    *warning-index <- copy idx
+  }
+#?   $print [done with run-interactive], 10/newline
 ]
 
 # make sure we render any trace
@@ -86,7 +133,7 @@ scenario run-instruction-and-print-warnings [
     event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data
   ]
   screen-should-contain [
-    .                               run (F4)           .
+    .  errors found (0)             run (F4)           .
     .                                                  .
     .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .0                                                x.
@@ -97,7 +144,7 @@ scenario run-instruction-and-print-warnings [
     .                                                  .
   ]
   screen-should-contain-in-color 1/red, [
-    .                                                  .
+    .  errors found (0)                                .
     .                                                  .
     .                                                  .
     .                                                  .
@@ -127,7 +174,7 @@ scenario run-instruction-and-print-warnings-only-once [
   ]
   # check that screen prints error message just once
   screen-should-contain [
-    .                               run (F4)           .
+    .  errors found (0)             run (F4)           .
     .                                                  .
     .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .0                                                x.
@@ -156,7 +203,7 @@ loop
     event-loop screen:address:shared:screen, console:address:shared:console, 2:address:shared:programming-environment-data
   ]
   screen-should-contain [
-    .                               run (F4)           .
+    .  errors found (0)             run (F4)           .
     .                                                  .
     .━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
     .0                                                x.