about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-12-28 16:42:18 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-12-28 16:43:18 -0800
commit05295080680c23b6e86c6c92710d00840ddf4aa0 (patch)
tree6151cbc411f7df88d2f63593bf7e04f16933af6b
parent05a2cf45a52c580081ec242251c73b76760a2597 (diff)
downloadmu-05295080680c23b6e86c6c92710d00840ddf4aa0.tar.gz
457 - finally, redirection works
No need for a separate channels array; just pass channels in globals.
The global space is a superset of unix's fd array.
-rw-r--r--mu.arc7
-rw-r--r--mu.arc.t38
2 files changed, 32 insertions, 13 deletions
diff --git a/mu.arc b/mu.arc
index 9106f68b..1c756803 100644
--- a/mu.arc
+++ b/mu.arc
@@ -136,8 +136,6 @@
               channel (obj size 3  and-record t  elems '((integer) (integer) (tagged-value-array-address))  fields '(first-full first-free circular-buffer))
               ; be careful of accidental copies to channels
               channel-address (obj size 1  address t  elem '(channel))
-              channel-address-array (obj array t  elem '(channel-address))
-              channel-address-array-address (obj size 1  address t  elem '(channel-address-array))
               ; editor
               line (obj array t  elem '(character))
               line-address (obj size 1  address t  elem '(line))
@@ -491,12 +489,11 @@
                 run
                   (run (v arg.0))
                 fork
-                  ; args: fn channels globals
-                  (let routine  (apply make-routine (m arg.0) (map m (nthcdr 3 arg)))
+                  ; args: fn globals-table args ...
+                  (let routine  (apply make-routine (m arg.0) (map m (nthcdr 2 arg)))
                     (= rep.routine!alloc rep.routine*!alloc)
                     (++ rep.routine*!alloc 1000)  ; todo: allow routines to expand past initial allocation, or to spawn multiple routines at once
                     (= rep.routine!globals (when (len> arg 1) (m arg.1)))
-                    (= rep.routine!channels (when (len> arg 2) (m arg.2)))
                     (enq routine running-routines*))
                 assert
                   (unless (m arg.0)
diff --git a/mu.arc.t b/mu.arc.t
index e591c6e1..93755cec 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -2581,7 +2581,7 @@
 (new-trace "fork-with-args")
 (add-code
   '((function f1 [
-      (fork f2:fn nil:literal nil:literal 4:literal)
+      (fork f2:fn nil:literal 4:literal)
      ])
     (function f2 [
       (2:integer <- next-input)
@@ -2596,7 +2596,7 @@
   '((function f1 [
       (default-scope:scope-address <- new scope:literal 5:literal)
       (x:integer <- copy 4:literal)
-      (fork f2:fn nil:literal nil:literal x:integer)
+      (fork f2:fn nil:literal x:integer)
       (x:integer <- copy 0:literal)  ; should be ignored
      ])
     (function f2 [
@@ -2934,13 +2934,13 @@
 (reset)
 (new-trace "channel-handoff")
 (add-code
-  '((function f1 [
+  '((function consumer [
       (default-scope:scope-address <- new scope:literal 30:literal)
-      (chan:channel-address <- init-channel 3:literal)
-      (fork f2:fn nil:literal nil:literal chan:channel-address)
-      (1:tagged-value/raw <- read chan:channel-address)  ; output
+      (chan:channel-address <- init-channel 3:literal)  ; create a channel
+      (fork producer:fn nil:literal chan:channel-address)  ; fork a routine to produce a value in it
+      (1:tagged-value/raw <- read chan:channel-address)  ; wait for input on channel
      ])
-    (function f2 [
+    (function producer [
       (default-scope:scope-address <- new scope:literal 30:literal)
       (n:integer-address <- new integer:literal)
       (n:integer-address/deref <- copy 24:literal)
@@ -2951,7 +2951,7 @@
 ;? (set dump-trace*)
 ;? (= dump-trace* (obj whitelist '("schedule" "run" "addr")))
 ;? (= dump-trace* (obj whitelist '("-")))
-(run 'f1)
+(run 'consumer)
 ;? (prn memory*)
 (each routine completed-routines*
   (aif rep.routine!error (prn "error - " it)))
@@ -2959,6 +2959,28 @@
   (prn "F - channels are meant to be shared between routines"))
 ;? (quit)
 
+(reset)
+(new-trace "channel-handoff-routine")
+(add-code
+  '((function consumer [
+      (default-scope:scope-address <- new scope:literal 30:literal)
+      (1:channel-address <- init-channel 3:literal)  ; create a channel
+      (fork producer:fn default-scope:address)  ; pass it as a global to another routine
+      (1:tagged-value/raw <- read 1:channel-address)  ; wait for input on channel
+     ])
+    (function producer [
+      (default-scope:scope-address <- new scope:literal 30:literal)
+      (n:integer-address <- new integer:literal)
+      (n:integer-address/deref <- copy 24:literal)
+      (x:tagged-value <- save-type n:integer-address)
+      (1:channel-address/space:global/deref <- write 1:channel-address/space:global x:tagged-value)
+     ])))
+(run 'consumer)
+(each routine completed-routines*
+  (aif rep.routine!error (prn "error - " it)))
+(if (~is 24 (memory* memory*.2))  ; location 1 contains tagged-value *x above
+  (prn "F - channels are meant to be shared between routines"))
+
 )  ; section 100
 
 (section 10