diff options
-rw-r--r-- | 088file.mu | 12 | ||||
-rw-r--r-- | 090scenario_filesystem_test.mu | 21 | ||||
-rw-r--r-- | html/088file.mu.html | 12 | ||||
-rw-r--r-- | html/090scenario_filesystem_test.mu.html | 21 |
4 files changed, 56 insertions, 10 deletions
diff --git a/088file.mu b/088file.mu index e91723ab..b7358327 100644 --- a/088file.mu +++ b/088file.mu @@ -137,10 +137,13 @@ def transmit-to-fake-file resources:&:resources, filename:text, source:&:source: tmp:resource <- index *data, i curr-filename <- get tmp, name:offset found?:bool <- equal filename, curr-filename - loop-unless found? - put-index *data, i, new-resource - reset lock - return + { + break-unless found? + put-index *data, i, new-resource + jump +unlock-and-exit + } + i <- add i, 1 + loop } # if file didn't already exist, make room for it new-len:num <- add len, 1 @@ -156,5 +159,6 @@ def transmit-to-fake-file resources:&:resources, filename:text, source:&:source: } # write new file put-index *new-data, len, new-resource + +unlock-and-exit reset lock ] diff --git a/090scenario_filesystem_test.mu b/090scenario_filesystem_test.mu index c33eeb81..6d212f88 100644 --- a/090scenario_filesystem_test.mu +++ b/090scenario_filesystem_test.mu @@ -22,7 +22,7 @@ scenario read-from-fake-file [ ] ] -scenario write-to-fake-file [ +scenario write-to-new-fake-file [ local-scope assume-resources [ ] @@ -38,6 +38,25 @@ scenario write-to-fake-file [ ] ] +scenario write-to-new-fake-file-2 [ + local-scope + assume-resources [ + [a] <- [ + |abc| + ] + ] + sink:&:sink:char, writer:num/routine <- start-writing resources, [b] + sink <- write sink, 120/x + sink <- write sink, 121/y + close sink + wait-for-routine writer + contents-read-back:text <- slurp resources, [b] + 10:bool/raw <- equal contents-read-back, [xy] + memory-should-contain [ + 10 <- 1 # file contents read back exactly match what was written + ] +] + scenario write-to-fake-file-that-exists [ local-scope assume-resources [ diff --git a/html/088file.mu.html b/html/088file.mu.html index 8f044eaa..49801745 100644 --- a/html/088file.mu.html +++ b/html/088file.mu.html @@ -170,10 +170,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color tmp:resource <span class="Special"><-</span> index *data, i curr-filename <span class="Special"><-</span> get tmp, <span class="Constant">name:offset</span> found?:bool <span class="Special"><-</span> equal filename, curr-filename - <span class="muControl">loop-unless</span> found? - put-index *data, i, new-resource - reset lock - <span class="muControl">return</span> + <span class="Delimiter">{</span> + <span class="muControl">break-unless</span> found? + put-index *data, i, new-resource + <span class="muControl">jump</span> <span class="Constant">+unlock-and-exit</span> + <span class="Delimiter">}</span> + i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> + <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># if file didn't already exist, make room for it</span> new-len:num <span class="Special"><-</span> add len,<span class="Constant"> 1</span> @@ -189,6 +192,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Delimiter">}</span> <span class="Comment"># write new file</span> put-index *new-data, len, new-resource +<span class="Constant"> +unlock-and-exit</span> reset lock ] </pre> diff --git a/html/090scenario_filesystem_test.mu.html b/html/090scenario_filesystem_test.mu.html index f82e26e0..91d039bb 100644 --- a/html/090scenario_filesystem_test.mu.html +++ b/html/090scenario_filesystem_test.mu.html @@ -55,7 +55,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] ] -<span class="muScenario">scenario</span> write-to-fake-file [ +<span class="muScenario">scenario</span> write-to-new-fake-file [ <span class="Constant">local-scope</span> assume-resources [ ] @@ -71,6 +71,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color ] ] +<span class="muScenario">scenario</span> write-to-new-fake-file-2 [ + <span class="Constant">local-scope</span> + assume-resources [ + <span class="Constant">[a]</span> <span class="Special"><-</span> [ +<span class="Constant"> |abc|</span> + ] + ] + sink:&:sink:char, writer:num/routine <span class="Special"><-</span> start-writing resources, <span class="Constant">[b]</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">120/x</span> + sink <span class="Special"><-</span> write sink, <span class="Constant">121/y</span> + close sink + wait-for-routine writer + contents-read-back:text <span class="Special"><-</span> slurp resources, <span class="Constant">[b]</span> + 10:bool/<span class="Special">raw</span> <span class="Special"><-</span> equal contents-read-back, <span class="Constant">[xy]</span> + memory-should-contain [ + <span class="Constant"> 10</span> <span class="Special"><-</span><span class="Constant"> 1</span> <span class="Comment"># file contents read back exactly match what was written</span> + ] +] + <span class="muScenario">scenario</span> write-to-fake-file-that-exists [ <span class="Constant">local-scope</span> assume-resources [ |