diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-23 23:15:12 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-23 23:15:12 -0700 |
commit | 2e4f0bbd12231a51ae08df4fe0f8847111fde405 (patch) | |
tree | 581166406a4749ac2dcd87c8555cc95dbb1bbd52 /html/088file.mu.html | |
parent | 2225b945ad5ba9310081b371bf32a9f575646e1b (diff) | |
download | mu-2e4f0bbd12231a51ae08df4fe0f8847111fde405.tar.gz |
3578
Diffstat (limited to 'html/088file.mu.html')
-rw-r--r-- | html/088file.mu.html | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/html/088file.mu.html b/html/088file.mu.html index e6ef6e98..26fa0c7c 100644 --- a/html/088file.mu.html +++ b/html/088file.mu.html @@ -47,15 +47,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> resources - <span class="Comment"># real file system</span> - file:num <span class="Special"><-</span> $open-file-for-reading filename - assert file, <span class="Constant">[file not found]</span> - contents:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> - start-running receive-from-file file, sink + <span class="muControl">break-unless</span> resources + <span class="Comment"># fake file system</span> + contents <span class="Special"><-</span> start-reading-from-fake-resources resources, filename <span class="muControl">return</span> <span class="Delimiter">}</span> - <span class="Comment"># fake file system</span> + <span class="Comment"># real file system</span> + file:num <span class="Special"><-</span> $open-file-for-reading filename + assert file, <span class="Constant">[file not found]</span> + contents:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> + start-running receive-from-file file, sink +] + +<span class="muRecipe">def</span> start-reading-from-fake-resources resources:&:resources, resource:text<span class="muRecipe"> -> </span>contents:&:source:char [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> data:&:@:resource <span class="Special"><-</span> get *resources, <span class="Constant">data:offset</span> len:num <span class="Special"><-</span> length *data @@ -64,8 +70,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">break-if</span> done? tmp:resource <span class="Special"><-</span> index *data, i i <span class="Special"><-</span> add i,<span class="Constant"> 1</span> - curr-filename:text <span class="Special"><-</span> get tmp, <span class="Constant">name:offset</span> - found?:bool <span class="Special"><-</span> equal filename, curr-filename + curr-resource:text <span class="Special"><-</span> get tmp, <span class="Constant">name:offset</span> + found?:bool <span class="Special"><-</span> equal resource, curr-resource <span class="muControl">loop-unless</span> found? contents:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> curr-contents:text <span class="Special"><-</span> get tmp, <span class="Constant">contents:offset</span> @@ -109,16 +115,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="Constant">load-ingredients</span> source:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> resources - <span class="Comment"># real file system</span> - file:num <span class="Special"><-</span> $open-file-for-writing filename - assert file, <span class="Constant">[no such file]</span> - routine-id <span class="Special"><-</span> start-running transmit-to-file file, source + <span class="muControl">break-unless</span> resources + <span class="Comment"># fake file system</span> + <span class="Comment"># beware: doesn't support multiple concurrent writes yet</span> + routine-id <span class="Special"><-</span> start-running transmit-to-fake-file resources, filename, source <span class="muControl">reply</span> <span class="Delimiter">}</span> - <span class="Comment"># fake file system</span> - <span class="Comment"># beware: doesn't support multiple concurrent writes yet</span> - routine-id <span class="Special"><-</span> start-running transmit-to-fake-file resources, filename, source + <span class="Comment"># real file system</span> + file:num <span class="Special"><-</span> $open-file-for-writing filename + assert file, <span class="Constant">[no such file]</span> + routine-id <span class="Special"><-</span> start-running transmit-to-file file, source ] <span class="muRecipe">def</span> transmit-to-file file:num, source:&:source:char<span class="muRecipe"> -> </span>source:&:source:char [ |