about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--088file.mu31
-rw-r--r--filesystem.mu16
2 files changed, 47 insertions, 0 deletions
diff --git a/088file.mu b/088file.mu
new file mode 100644
index 00000000..25263fa9
--- /dev/null
+++ b/088file.mu
@@ -0,0 +1,31 @@
+# Wrappers around file-system primitives that take a 'filesystem' object and
+# are thus easier to test.
+
+container filesystem [
+  {data: (address table (address array character) (address array character))}
+]
+
+def start-reading fs:address:filesystem, filename:address:array:character -> contents:address:source:character [
+  local-scope
+  load-ingredients
+  x:number/file <- $open-file-for-reading filename
+  contents:address:source:character, sink:address:sink:character <- new-channel 30
+  $print [sink: ], sink, 10/newline
+  chan:address:channel:character <- get *sink, chan:offset
+  $print [chan in start-reading: ], chan, 10/newline
+  start-running transmit x, sink
+]
+
+def transmit file:number, sink:address:sink:character -> file:number, sink:address:sink:character [
+  local-scope
+  load-ingredients
+  {
+    c:character <- $read-from-file file
+    break-unless c
+    sink <- write sink, c
+    loop
+  }
+  $print [closing chan after reading file], 10/newline
+  sink <- close sink
+  $print [returning from 'transmit'], 10/newline
+]
diff --git a/filesystem.mu b/filesystem.mu
new file mode 100644
index 00000000..7aa919e6
--- /dev/null
+++ b/filesystem.mu
@@ -0,0 +1,16 @@
+def main [
+  local-scope
+  $print [file to read from: ], [/tmp/mu-fs]
+  # initialize filesystem
+  fs:address:filesystem <- copy 0/real-filesystem
+  content-source:address:source:character <- start-reading fs, [/tmp/mu-fs]
+  # read from channel until exhausted and print out characters
+  {
+    c:character, done?:boolean, content-source <- read content-source
+    break-if done?
+    $print [Next: ], c, 10/newline
+    loop
+  }
+  $print [Done reading], 10/newline
+  # TODO: writing to file
+]