about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-07 00:59:23 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-07 00:59:23 -0800
commitd430ce7c3d385fe7c057c0bde12fd0e4b5e6daff (patch)
treea1f29469d53df9492ee92b5c7d0952a31a4f8284
parent0c62881a6f7adc4dfbeca243e44b585dc4cb40fe (diff)
downloadmu-d430ce7c3d385fe7c057c0bde12fd0e4b5e6daff.tar.gz
247
-rw-r--r--mu.arc11
-rw-r--r--mu.arc.t33
2 files changed, 41 insertions, 3 deletions
diff --git a/mu.arc b/mu.arc
index 12202995..ecce0406 100644
--- a/mu.arc
+++ b/mu.arc
@@ -30,7 +30,7 @@
               location (obj size 1  address t  elem 'location)  ; assume it points to an atom
               integer (obj size 1)
               boolean (obj size 1)
-              boolean-address (obj size 1  address t)
+              boolean-address (obj size 1  address t  elem 'boolean)
               byte (obj size 1)
 ;?               string (obj array t  elem 'byte)  ; inspired by Go
               character (obj size 1)  ; int32 like a Go rune
@@ -61,7 +61,7 @@
               list-address (obj size 1  address t  elem 'list)
               list-address-address (obj size 1  address t  elem 'list-address)
               ; parallel routines use channels to synchronize
-              channel (obj size 3  record t  elems '(integer integer tagged-value-array-address)  fields '(first-full first-free circular-buffer))
+              channel (obj size 5  record t  elems '(boolean boolean integer integer tagged-value-array-address)  fields '(write-watch read-watch first-full first-free circular-buffer))
               channel-address (obj size 1  address t  elem 'channel)
               ; editor
               line (obj array t  elem 'character)
@@ -237,7 +237,7 @@
 
 (def typeinfo (operand)
   (or (types* ty.operand)
-      (err "unknown type @operand")))
+      (err "unknown type @(tostring prn.operand)")))
 
 (def sz (operand)
   (trace "sz" operand)
@@ -464,6 +464,7 @@
                   (let type (v arg.0)
                     (assert (is 'literal (ty arg.0)) "new: second arg @arg.0 must be literal")
                     (if (no types*.type)  (err "no such type @type"))
+                    ; todo: initialize memory. currently racket does it for us
                     (if types*.type!array
                       (new-array type (m arg.1))
                       (new-scalar type)))
@@ -842,6 +843,8 @@
   ((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))
+  ((watch boolean-address) <- get-address (chan channel) (write-watch offset))
+  ((watch boolean-address deref) <- copy (t literal))
   (reply (chan channel)))
 
 (init-fn read
@@ -851,6 +854,8 @@
   ((q tagged-value-array-address) <- get (chan channel) (circular-buffer offset))
   ((result tagged-value) <- index (q tagged-value-array-address deref) (full integer-address deref))
   ((full integer-address deref) <- add (full integer-address deref) (1 literal))
+  ((watch boolean-address) <- get-address (chan channel) (read-watch offset))
+  ((watch boolean-address deref) <- copy (t literal))
   (reply (result tagged-value) (chan channel)))
 
 ; drop all traces while processing above functions
diff --git a/mu.arc.t b/mu.arc.t
index 2a18fd86..29132a80 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -1869,4 +1869,37 @@
         (~is 1 memory*.7))
   (prn "F - 'read' dequeues item from channel"))
 
+(reset)
+(new-trace "channel-write-watch")
+(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-address literal) (2 integer-address))
+      ((4 boolean) <- get (1 channel-address deref) (read-watch offset))
+      ((1 channel-address deref) <- write (1 channel-address deref) (3 tagged-value-address deref))
+      ((5 boolean) <- get (1 channel-address deref) (write-watch offset)))))
+(run 'main)
+(if (or (~is nil memory*.4)
+        (~is t memory*.5))
+  (prn "F - 'write' sets channel watch"))
+
+(reset)
+(new-trace "channel-read-watch")
+(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-address literal) (2 integer-address))
+      ((1 channel-address deref) <- write (1 channel-address deref) (3 tagged-value-address deref))
+      ((4 boolean) <- get (1 channel-address deref) (read-watch offset))
+      ((5 tagged-value) (1 channel-address deref) <- read (1 channel-address deref))
+      ((6 integer) <- get (1 channel-address deref) (read-watch offset)))))
+(run 'main)
+(if (or (~is nil memory*.4)
+        (~is t memory*.6))
+  (prn "F - 'read' sets channel watch"))
+
 (reset)  ; end file with this to persist the trace for the final test