about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-04 13:46:31 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-04 13:46:31 -0800
commitda2a15e7d3f3659d0eb06856364d7265a13ca628 (patch)
tree327397197be296710ad87824ad04d969286692d9
parent76e562a862ec19114d5d2f88890121530cee1b64 (diff)
downloadmu-da2a15e7d3f3659d0eb06856364d7265a13ca628.tar.gz
225 - simple writes to channel
-rw-r--r--mu.arc11
-rw-r--r--mu.arc.t17
2 files changed, 28 insertions, 0 deletions
diff --git a/mu.arc b/mu.arc
index 69afae51..7a5e3cab 100644
--- a/mu.arc
+++ b/mu.arc
@@ -808,6 +808,17 @@
   ((channel-buffer-address tagged-value-array-address-address deref) <- copy (buffer-address tagged-value-array-address))
   (reply (result channel-address)))
 
+(init-fn write
+  ((default-scope scope-address) <- new (scope literal) (30 literal))
+  ((chan channel) <- arg)
+  ((val tagged-value) <- arg)
+  ((q tagged-value-array-address) <- get (chan channel) (circular-buffer offset))
+  ((free integer-address) <- get-address (chan channel) (first-free offset))
+  ((dest tagged-value-address) <- index-address (q tagged-value-array-address deref) (free integer-address deref))
+  ((dest tagged-value-address deref) <- copy (val tagged-value))
+  ((free integer-address deref) <- add (free integer-address deref) (1 literal))
+  (reply (chan channel)))
+
 ; drop all traces while processing above functions
 (on-init
   (= traces* (queue)))
diff --git a/mu.arc.t b/mu.arc.t
index 5f24ac81..08fb19b9 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1717,4 +1717,21 @@
         (~is 0 (memory* (+ 1 memory*.1))))
   (prn "F - 'new-channel' initializes 'first-full and 'first-free to 0"))
 
+(reset)
+(new-trace "channel-write")
+(add-fns
+  '((main
+      ((1 channel-address) <- new-channel (3 literal))
+      ((2 integer-address) <- new (integer literal))
+      ((2 integer-address deref) <- copy (34 literal))
+      ((3 tagged-value-address) <- new-tagged-value (integer literal) (2 integer-address))
+      ((1 channel-address deref) <- write (1 channel-address deref) (3 tagged-value-address deref)))))
+;? (set dump-trace*)
+;? (= dump-trace* (obj blacklist '("sz" "m" "setm" "addr" "array-len" "cvt0" "cvt1")))
+(run 'main)
+;? (prn memory*)
+(if (or (~is 0 (memory* memory*.1))
+        (~is 1 (memory* (+ 1 memory*.1))))
+  (prn "F - 'write' enqueues item to channel"))
+
 (reset)  ; end file with this to persist the trace for the final test