From 2e4f0bbd12231a51ae08df4fe0f8847111fde405 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 23 Oct 2016 23:15:12 -0700 Subject: 3578 --- html/088file.mu.html | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'html/088file.mu.html') 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 local-scope load-ingredients { - break-if resources - # real file system - file:num <- $open-file-for-reading filename - assert file, [file not found] - contents:&:source:char, sink:&:sink:char <- new-channel 30 - start-running receive-from-file file, sink + break-unless resources + # fake file system + contents <- start-reading-from-fake-resources resources, filename return } - # fake file system + # real file system + file:num <- $open-file-for-reading filename + assert file, [file not found] + contents:&:source:char, sink:&:sink:char <- new-channel 30 + start-running receive-from-file file, sink +] + +def start-reading-from-fake-resources resources:&:resources, resource:text -> contents:&:source:char [ + local-scope + load-ingredients i:num <- copy 0 data:&:@:resource <- get *resources, data:offset len:num <- length *data @@ -64,8 +70,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color break-if done? tmp:resource <- index *data, i i <- add i, 1 - curr-filename:text <- get tmp, name:offset - found?:bool <- equal filename, curr-filename + curr-resource:text <- get tmp, name:offset + found?:bool <- equal resource, curr-resource loop-unless found? contents:&:source:char, sink:&:sink:char <- new-channel 30 curr-contents:text <- get tmp, contents:offset @@ -109,16 +115,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color load-ingredients source:&:source:char, sink:&:sink:char <- new-channel 30 { - break-if resources - # real file system - file:num <- $open-file-for-writing filename - assert file, [no such file] - routine-id <- start-running transmit-to-file file, source + break-unless resources + # fake file system + # beware: doesn't support multiple concurrent writes yet + routine-id <- start-running transmit-to-fake-file resources, filename, source reply } - # fake file system - # beware: doesn't support multiple concurrent writes yet - routine-id <- start-running transmit-to-fake-file resources, filename, source + # real file system + file:num <- $open-file-for-writing filename + assert file, [no such file] + routine-id <- start-running transmit-to-file file, source ] def transmit-to-file file:num, source:&:source:char -> source:&:source:char [ -- cgit 1.4.1-2-gfad0