diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-20 00:37:24 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-20 00:37:24 -0700 |
commit | d059fe743df6a5e8a72fc1418f2c3ba1ed5ac1e6 (patch) | |
tree | a532d18a9993d429dfdcba2b87bc9e8897a8a6c2 /html/088file.mu.html | |
parent | f24eeaab13d12b87bb219cb42861c5fe7d091053 (diff) | |
download | mu-d059fe743df6a5e8a72fc1418f2c3ba1ed5ac1e6.tar.gz |
3524
Diffstat (limited to 'html/088file.mu.html')
-rw-r--r-- | html/088file.mu.html | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/html/088file.mu.html b/html/088file.mu.html index ef8987a2..4dd739ea 100644 --- a/html/088file.mu.html +++ b/html/088file.mu.html @@ -31,51 +31,51 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color </head> <body> <pre id='vimCodeElement'> -<span class="Comment"># Wrappers around file system primitives that take a 'filesystem' object and</span> +<span class="Comment"># Wrappers around file system primitives that take a 'resources' object and</span> <span class="Comment"># are thus easier to test.</span> -<span class="muData">container</span> filesystem [ - data:&:@:file-mapping +<span class="muData">container</span> resources [ + data:&:@:resource ] -<span class="muData">container</span> file-mapping [ +<span class="muData">container</span> resource [ name:text contents:text ] -<span class="muRecipe">def</span> start-reading fs:&:filesystem, filename:text<span class="muRecipe"> -> </span>contents:&:source:char [ +<span class="muRecipe">def</span> start-reading resources:&:resources, filename:text<span class="muRecipe"> -> </span>contents:&:source:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> - <span class="muControl">break-if</span> fs + <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 transmit-from-file file, sink + start-running receive-from-file file, sink <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># fake file system</span> i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> - data:&:@:file-mapping<span class="Special"> <- </span>get *fs, <span class="Constant">data:offset</span> + data:&:@:resource<span class="Special"> <- </span>get *resources, <span class="Constant">data:offset</span> len:num<span class="Special"> <- </span>length *data <span class="Delimiter">{</span> done?:bool<span class="Special"> <- </span>greater-or-equal i, len <span class="muControl">break-if</span> done? - tmp:file-mapping<span class="Special"> <- </span>index *data, i + 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 <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> - start-running transmit-from-text curr-contents, sink + start-running receive-from-text curr-contents, sink <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Constant">0/not-found</span> ] -<span class="muRecipe">def</span> transmit-from-file file:num, sink:&:sink:char<span class="muRecipe"> -> </span>sink:&:sink:char [ +<span class="muRecipe">def</span> receive-from-file file:num, sink:&:sink:char<span class="muRecipe"> -> </span>sink:&:sink:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Delimiter">{</span> @@ -88,7 +88,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color file<span class="Special"> <- </span>$close-file file ] -<span class="muRecipe">def</span> transmit-from-text contents:text, sink:&:sink:char<span class="muRecipe"> -> </span>sink:&:sink:char [ +<span class="muRecipe">def</span> receive-from-text contents:text, sink:&:sink:char<span class="muRecipe"> -> </span>sink:&:sink: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> @@ -104,12 +104,12 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color sink<span class="Special"> <- </span>close sink ] -<span class="muRecipe">def</span> start-writing fs:&:filesystem, filename:text<span class="muRecipe"> -> </span>sink:&:sink:char, routine-id:num [ +<span class="muRecipe">def</span> start-writing resources:&:resources, filename:text<span class="muRecipe"> -> </span>sink:&:sink:char, routine-id:num [ <span class="Constant">local-scope</span> <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> fs + <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> @@ -118,7 +118,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <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 fs, filename, source + routine-id<span class="Special"> <- </span>start-running transmit-to-fake-file resources, filename, source ] <span class="muRecipe">def</span> transmit-to-file file:num, source:&:source:char<span class="muRecipe"> -> </span>source:&:source:char [ @@ -133,7 +133,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color file<span class="Special"> <- </span>$close-file file ] -<span class="muRecipe">def</span> transmit-to-fake-file fs:&:filesystem, filename:text, source:&:source:char<span class="muRecipe"> -> </span>fs:&:filesystem, source:&:source:char [ +<span class="muRecipe">def</span> transmit-to-fake-file resources:&:resources, filename:text, source:&:source:char<span class="muRecipe"> -> </span>resources:&:resources, source:&:source:char [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># compute new file contents</span> @@ -145,37 +145,37 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color <span class="muControl">loop</span> <span class="Delimiter">}</span> contents:text<span class="Special"> <- </span>buffer-to-array buf - new-file-mapping:file-mapping<span class="Special"> <- </span>merge filename, contents - <span class="Comment"># write to filesystem</span> + new-resource:resource<span class="Special"> <- </span>merge filename, contents + <span class="Comment"># write to resources</span> curr-filename:text<span class="Special"> <- </span>copy <span class="Constant">0</span> - data:&:@:file-mapping<span class="Special"> <- </span>get *fs, <span class="Constant">data:offset</span> + data:&:@:resource<span class="Special"> <- </span>get *resources, <span class="Constant">data:offset</span> <span class="Comment"># replace file contents if it already exists</span> i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> len:num<span class="Special"> <- </span>length *data <span class="Delimiter">{</span> done?:bool<span class="Special"> <- </span>greater-or-equal i, len <span class="muControl">break-if</span> done? - tmp:file-mapping<span class="Special"> <- </span>index *data, i + 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-file-mapping + put-index *data, i, new-resource <span class="muControl">reply</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> - new-data:&:@:file-mapping<span class="Special"> <- </span>new <span class="Constant">file-mapping:type</span>, new-len - put *fs, <span class="Constant">data:offset</span>, new-data + new-data:&:@:resource<span class="Special"> <- </span>new <span class="Constant">resource:type</span>, new-len + put *resources, <span class="Constant">data:offset</span>, new-data <span class="Comment"># copy over old files</span> i:num<span class="Special"> <- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> done?:bool<span class="Special"> <- </span>greater-or-equal i, len <span class="muControl">break-if</span> done? - tmp:file-mapping<span class="Special"> <- </span>index *data, i + tmp:resource<span class="Special"> <- </span>index *data, i put-index *new-data, i, tmp <span class="Delimiter">}</span> <span class="Comment"># write new file</span> - put-index *new-data, len, new-file-mapping + put-index *new-data, len, new-resource ] </pre> </body> |