about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-18 04:39:24 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-18 04:39:24 -0800
commit67feef8318e04ba8526cd7770b3957de08208b53 (patch)
treefdf56fe433d41ec988c4c81baf8f30ae0d732b20
parent4c97ba914e2627677223c97c04b4532aef9f8025 (diff)
downloadmu-67feef8318e04ba8526cd7770b3957de08208b53.tar.gz
270
-rw-r--r--mu.arc10
1 files changed, 8 insertions, 2 deletions
diff --git a/mu.arc b/mu.arc
index c76b931b..5324f6a1 100644
--- a/mu.arc
+++ b/mu.arc
@@ -876,6 +876,13 @@
   ((channel-buffer-address tagged-value-array-address-address deref) <- new (tagged-value-array literal) (capacity integer))
   (reply (result channel-address)))
 
+(init-fn capacity
+  ((default-scope scope-address) <- new (scope literal) (30 literal))
+  ((chan channel) <- arg)
+  ((q tagged-value-array-address) <- get (chan channel) (circular-buffer offset))
+  ((qlen integer) <- len (q tagged-value-array-address deref))
+  (reply (qlen integer)))
+
 (init-fn write
   ((default-scope scope-address) <- new (scope literal) (30 literal))
   ((chan channel) <- arg)
@@ -949,11 +956,10 @@
   ((chan channel) <- arg)
   ; curr = chan.first-free + 1
   ((curr integer) <- get (chan channel) (first-free offset))
-  ((q tagged-value-array-address) <- get (chan channel) (circular-buffer offset))
-  ((qlen integer) <- len (q tagged-value-array-address deref))
   ((curr integer) <- add (curr integer) (1 literal))
   { begin
     ; if (curr == chan.capacity) curr = 0
+    ((qlen integer) <- capacity (chan channel))
     ((remaining? boolean) <- lt (curr integer) (qlen integer))
     (break-if (remaining? boolean))
     ((curr integer) <- copy (0 literal))