about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--edit/005-sandbox.mu10
-rw-r--r--sandbox/005-sandbox.mu10
2 files changed, 14 insertions, 6 deletions
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index 4d4b93ef..80dd4120 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -325,6 +325,7 @@ def restore-sandboxes env:address:programming-environment-data -> env:address:pr
     filename:address:array:character <- to-text idx
     contents:address:array:character <- restore filename
     break-unless contents  # stop at first error; assuming file didn't exist
+                           # todo: handle empty sandbox
     # create new sandbox for file
     curr <- new sandbox-data:type
     *curr <- put *curr, data:offset, contents
@@ -336,15 +337,18 @@ def restore-sandboxes env:address:programming-environment-data -> env:address:pr
       <end-restore-sandbox>
     }
     +continue
-    idx <- add idx, 1
     {
-      break-unless prev
+      break-if idx
+      *env <- put *env, sandbox:offset, curr
+    }
+    {
+      break-unless idx
       *prev <- put *prev, next-sandbox:offset, curr
     }
+    idx <- add idx, 1
     prev <- copy curr
     loop
   }
-  *env <- put *env, sandbox:offset, curr
   # update sandbox count
   *env <- put *env, number-of-sandboxes:offset, idx
 ]
diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu
index c946fba2..227a1ee0 100644
--- a/sandbox/005-sandbox.mu
+++ b/sandbox/005-sandbox.mu
@@ -317,6 +317,7 @@ def! restore-sandboxes env:address:programming-environment-data -> env:address:p
     filename:address:array:character <- to-text idx
     contents:address:array:character <- restore filename
     break-unless contents  # stop at first error; assuming file didn't exist
+                           # todo: handle empty sandbox
     # create new sandbox for file
     curr <- new sandbox-data:type
     *curr <- put *curr, data:offset, contents
@@ -328,15 +329,18 @@ def! restore-sandboxes env:address:programming-environment-data -> env:address:p
       <end-restore-sandbox>
     }
     +continue
-    idx <- add idx, 1
     {
-      break-unless prev
+      break-if idx
+      *env <- put *env, sandbox:offset, curr
+    }
+    {
+      break-unless idx
       *prev <- put *prev, next-sandbox:offset, curr
     }
+    idx <- add idx, 1
     prev <- copy curr
     loop
   }
-  *env <- put *env, sandbox:offset, curr
   # update sandbox count
   *env <- put *env, number-of-sandboxes:offset, idx
 ]