about summary refs log tree commit diff stats
path: root/309stream.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-07-30 19:34:29 -0700
committerKartik Agaram <vc@akkartik.com>2020-07-30 19:34:29 -0700
commit30012350281844611bda2f4668f6a0b318a95b36 (patch)
tree56ac2b67b2dd02c3caa4aa02f47be9ea492349ad /309stream.subx
parentca237761bf0f9b16838e2d3f7079d1725e3bd87b (diff)
downloadmu-30012350281844611bda2f4668f6a0b318a95b36.tar.gz
6687 - stream-empty? and stream-full?
Diffstat (limited to '309stream.subx')
-rw-r--r--309stream.subx52
1 files changed, 50 insertions, 2 deletions
diff --git a/309stream.subx b/309stream.subx
index 3d38eda9..8e6d0fbf 100644
--- a/309stream.subx
+++ b/309stream.subx
@@ -1,7 +1,55 @@
 # Some unsafe methods not intended to be used directly in SubX, only through
 # Mu after proper type-checking.
 
-write-to-stream:  # s: (addr stream), in: (addr byte), n: int
+stream-empty?:  # s: (addr stream _) -> result/eax: boolean
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    56/push-esi
+    # result = false
+    b8/copy-to-eax 0/imm32/false
+    # esi = s
+    8b/-> *(ebp+8) 6/r32/esi
+    # return s->read >= s->write
+    8b/-> *esi 1/r32/ecx
+    39/compare-with *(esi+4) 1/r32/ecx
+    0f 9d/set-if->= %al
+$stream-empty?:end:
+    # . restore registers
+    5e/pop-to-esi
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+stream-full?:  # s: (addr stream _) -> result/eax: boolean
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    51/push-ecx
+    56/push-esi
+    # result = false
+    b8/copy-to-eax 0/imm32/false
+    # esi = s
+    8b/-> *(ebp+8) 6/r32/esi
+    # return s->write >= s->size
+    8b/-> *(esi+8) 1/r32/ecx
+    39/compare-with *esi 1/r32/ecx
+    0f 9d/set-if->= %al
+$stream-full?:end:
+    # . restore registers
+    5e/pop-to-esi
+    59/pop-to-ecx
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
+write-to-stream:  # s: (addr stream _), in: (addr byte), n: int
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
@@ -54,7 +102,7 @@ $write-to-stream:abort:
     (syscall_exit)
     # never gets here
 
-read-from-stream:  # s: (addr stream), out: (addr byte), n: int
+read-from-stream:  # s: (addr stream _), out: (addr byte), n: int
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp