about summary refs log tree commit diff stats
path: root/apps
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-28 22:31:52 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-28 22:31:52 -0700
commit583a966d3e0b0f0e0fa9166986c877fda0643196 (patch)
treee62b31a3ed4f615330d7bf42d83a84b54e0c315f /apps
parent429cebf3e4c4ce5ba81443968d28b88bdfd2584e (diff)
downloadmu-583a966d3e0b0f0e0fa9166986c877fda0643196.tar.gz
6422 - size-of for handles
Diffstat (limited to 'apps')
-rwxr-xr-xapps/mubin256130 -> 256151 bytes
-rw-r--r--apps/mu.subx11
-rw-r--r--apps/print-file.mu8
3 files changed, 17 insertions, 2 deletions
diff --git a/apps/mu b/apps/mu
index 5158562c..1f77f3b4 100755
--- a/apps/mu
+++ b/apps/mu
Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx
index 2e657c89..5bc534f1 100644
--- a/apps/mu.subx
+++ b/apps/mu.subx
@@ -7943,10 +7943,17 @@ size-of-type-id:  # t: type-id -> result/eax: int
     89/<- %ecx 4/r32/esp
     # eax = t
     8b/-> *(ebp+8) 0/r32/eax
-    # if v is a literal, return 0
+    # if t is a literal, return 0
     3d/compare-eax-and 0/imm32
     74/jump-if-= $size-of-type-id:end/disp8  # eax changes type from type-id to int
-    # if v has a user-defined type, return its size
+    # if t is a handle, return 8
+    3d/compare-eax-and 4/imm32/handle
+    {
+      75/jump-if-!= break/disp8
+      b8/copy-to-eax 8/imm32
+      eb/jump $size-of-type-id:end/disp8  # eax changes type from type-id to int
+    }
+    # if t is a user-defined type, return its size
     # TODO: support non-atom type
     (find-typeinfo %eax %ecx)
     {
diff --git a/apps/print-file.mu b/apps/print-file.mu
index 5010bafb..b5b5601b 100644
--- a/apps/print-file.mu
+++ b/apps/print-file.mu
@@ -14,8 +14,16 @@ $main-body: {
     {
       break-if-<=
       var filename/edx: (addr addr array byte) <- index args 1
+      var in: (handle buffered-file)
+      {
+        var addr-in/eax: (addr handle buffered-file) <- address in
+        open *filename, 0, addr-in
+      }
+      var in-addr/eax: (addr buffered-file) <- lookup in
       print-string "filename: "
       print-string *filename
+      print-string ": "
+      print-int32-to-screen in-addr
       print-string "\n"
     }
   }