about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--410file.mu20
-rwxr-xr-xapps/mubin415008 -> 415039 bytes
-rw-r--r--apps/mu.subx10
-rw-r--r--apps/tile/environment.mu6
-rw-r--r--apps/tile/rpn.mu46
-rw-r--r--apps/tile/value-stack.mu26
6 files changed, 106 insertions, 2 deletions
diff --git a/410file.mu b/410file.mu
new file mode 100644
index 00000000..970407cf
--- /dev/null
+++ b/410file.mu
@@ -0,0 +1,20 @@
+fn read-lines in: (addr buffered-file), out: (addr handle array (handle array byte)) {
+  var stream: (stream (handle array byte) 0x10)
+  var stream-a/edi: (addr stream (handle array byte)) <- address stream
+  var line: (stream byte 0x10)
+  var line-a/esi: (addr stream byte) <- address line
+  {
+    clear-stream line-a
+    read-line-buffered in, line-a
+    var done?/eax: boolean <- stream-empty? line-a
+    compare done?, 0  # false
+    break-if-!=
+#?     print-string 0, "AAA\n"
+    var h: (handle array byte)
+    var ah/eax: (addr handle array byte) <- address h
+    stream-to-array line-a, ah
+    write-to-stream stream-a, ah
+    loop
+  }
+  stream-to-array stream-a, out
+}
diff --git a/apps/mu b/apps/mu
index 4c564431..9f53a810 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index db5c8b69..60167e38 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -17120,8 +17120,16 @@ $array-element-type-id:skip-array:
     # if t->is-atom? abort
     81 7/subop/compare *eax 0/imm32/false  # Type-tree-is-atom
     0f 85/jump-if-!= $array-element-type-id:error2/disp32
-    # return t->left->value
+    # t = t->left
     (lookup *(eax+4) *(eax+8))  # Type-tree-left Type-tree-left => eax
+    # if (!t->is-atom?) t = t->left     # TODO: assumes array element size can be determined from just first word of array element type
+    # if (t->is-atom == false) t = lookup(t->left)
+    {
+      81 7/subop/compare *eax 0/imm32/false  # Type-tree-is-atom
+      75/jump-if-!= break/disp8
+      (lookup *(eax+4) *(eax+8))  # Type-tree-left Type-tree-left => eax
+    }
+    # return t->value
     8b/-> *(eax+4) 0/r32/eax  # Type-tree-value
 $array-element-type-id:end:
     # . epilogue
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 230fc1be..971e8d9f 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -790,6 +790,10 @@ fn bound-function? w: (addr word), functions-ah: (addr handle function) -> resul
   subresult <- word-equal? w, "slurp"
   compare subresult, 0  # false
   break-if-!=
+  # if w == "lines" return true
+  subresult <- word-equal? w, "lines"
+  compare subresult, 0  # false
+  break-if-!=
   # if w == "dup" return true
   subresult <- word-equal? w, "dup"
   compare subresult, 0  # false
@@ -1558,7 +1562,7 @@ fn clear-canvas _env: (addr environment) {
   move-cursor screen, 2, start-col
   print-string screen, "+ - * len"
   move-cursor screen, 3, start-col
-  print-string screen, "open read slurp"
+  print-string screen, "open read slurp lines"
   move-cursor screen, 4, start-col
   print-string screen, "dup swap"
   # currently defined functions
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index 7b65b71c..2529e5ca 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -206,6 +206,52 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         copy-handle empty, target-file-ah
         break $evaluate:process-word
       }
+      {
+        var is-lines?/eax: boolean <- stream-data-equal? curr-stream, "lines"
+        compare is-lines?, 0
+        break-if-=
+        # pop target-val from out
+        var out2/esi: (addr value-stack) <- copy out
+        var top-addr/ecx: (addr int) <- get out2, top
+        compare *top-addr, 0
+        break-if-<=
+        var data-ah/eax: (addr handle array value) <- get out2, data
+        var data/eax: (addr array value) <- lookup *data-ah
+        var top/edx: int <- copy *top-addr
+        top <- decrement
+        var dest-offset/edx: (offset value) <- compute-offset data, top
+        var target-val/edx: (addr value) <- index data, dest-offset
+        # check target-val is a file
+        var target-type-addr/eax: (addr int) <- get target-val, type
+        compare *target-type-addr, 3  # file
+        break-if-!=
+        # read all lines from file and save as an array of strings in target-val
+        # read target-val as a filename and save the handle in target-val
+        var file-ah/eax: (addr handle buffered-file) <- get target-val, file-data
+        var file/eax: (addr buffered-file) <- lookup *file-ah
+        var h: (handle array (handle array byte))
+        var ah/ecx: (addr handle array (handle array byte)) <- address h
+#?         enable-screen-type-mode
+#?         clear-screen 0
+        read-lines file, ah
+#?         {
+#?           var x/eax: (addr array (handle array byte)) <- lookup h
+#?           var len/eax: int <- length x
+#?           var foo/eax: int <- copy len
+#?           print-string 0, "aa: "
+#?           print-int32-hex 0, foo
+#?           print-string 0, "\n"
+#?         }
+        var target/eax: (addr handle array value) <- get target-val, array-data
+        save-lines h, target
+        # save result into target-val
+        var type-addr/eax: (addr int) <- get target-val, type
+        copy-to *type-addr, 2  # array
+        var target-file-ah/eax: (addr handle buffered-file) <- get target-val, file-data
+        var empty: (handle buffered-file)
+        copy-handle empty, target-file-ah
+        break $evaluate:process-word
+      }
       # if curr-stream defines a binding, save top of stack to bindings
       {
         var done?/eax: boolean <- stream-empty? curr-stream
diff --git a/apps/tile/value-stack.mu b/apps/tile/value-stack.mu
index 83b1262a..a6ba4f0f 100644
--- a/apps/tile/value-stack.mu
+++ b/apps/tile/value-stack.mu
@@ -227,3 +227,29 @@ fn array-width _a: (addr array value) -> result/eax: int {
   # we won't add 2 for surrounding brackets since we don't surround arrays in
   # spaces like other value types
 }
+
+fn save-lines in-h: (handle array (handle array byte)), _out-ah: (addr handle array value) {
+  var _in/eax: (addr array (handle array byte)) <- lookup in-h
+  var in/esi: (addr array (handle array byte)) <- copy _in
+  var len/ecx: int <- length in
+  var out-ah/edi: (addr handle array value) <- copy _out-ah
+  populate out-ah, len
+  var out/eax: (addr array value) <- lookup *out-ah
+  # copy in into out
+  var i/ebx: int <- copy 0
+  {
+    compare i, len
+    break-if->=
+#?     print-int32-hex 0, i
+#?     print-string 0, "\n"
+    var src/ecx: (addr handle array byte) <- index in, i
+    var dest-offset/edx: (offset value) <- compute-offset out, i
+    var dest-val/edx: (addr value) <- index out, dest-offset
+    var dest/eax: (addr handle array byte) <- get dest-val, text-data
+    copy-object src, dest
+    var type/edx: (addr int) <- get dest-val, type
+    copy-to *type, 1  # string
+    i <- increment
+    loop
+  }
+}