about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-11 22:54:51 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-11 22:55:35 -0800
commitbfdfcf74260485a8ce85a6522583dce948f28c60 (patch)
tree709f9debcbb56e8f39222826abdd7ae767d93c1a
parent337a099d35e0db9693ee1a53095dc8c96b030baa (diff)
downloadmu-bfdfcf74260485a8ce85a6522583dce948f28c60.tar.gz
536 - introduce a notion of helper routines
When all you have left to run are helper routines, end the simulation.
-rw-r--r--mu.arc17
-rw-r--r--stdin.mu2
2 files changed, 17 insertions, 2 deletions
diff --git a/mu.arc b/mu.arc
index dee41c17..81f07f2c 100644
--- a/mu.arc
+++ b/mu.arc
@@ -359,6 +359,12 @@
         (= curr-cycle* (+ 1 next-wakeup-cycle))
         (trace "schedule" "skipping to cycle " curr-cycle*)
         (update-scheduler-state))))
+  (when (and (all [rep._ 'helper] (as cons running-routines*))
+             (all [rep._ 'helper] keys.sleeping-routines*))
+    (until (empty running-routines*)
+      (push (deq running-routines*) completed-routines*))
+    (until sleeping-routines*
+      (push (pop sleeping-routines*) completed-routines*)))
 ;?   (tr 113)
   (detect-deadlock)
 ;?   (tr 114)
@@ -588,6 +594,15 @@
                     (= rep.routine!limit (when (len> arg 2) (m arg.2)))
                     (enq routine running-routines*)
                     rep.routine!id)
+                fork-helper
+                  ; args: fn globals-table args ...
+                  (let routine  (apply make-routine (m arg.0) (map m (nthcdr 3 arg)))
+                    (= rep.routine!id ++.next-routine-id*)
+                    (set rep.routine!helper)
+                    (= rep.routine!globals (when (len> arg 1) (m arg.1)))
+                    (= rep.routine!limit (when (len> arg 2) (m arg.2)))
+                    (enq routine running-routines*)
+                    rep.routine!id)
                 sleep
                   (do
                     (case (v arg.0)
@@ -1871,7 +1886,7 @@
 
 ;; load all provided files and start at 'main'
 (reset)
-(new-trace "main")
+;? (new-trace "main")
 ;? (set dump-trace*)
 (awhen (pos "--" argv)
   (map add-code:readfile (cut argv (+ it 1)))
diff --git a/stdin.mu b/stdin.mu
index 9f2baafb..8d71738c 100644
--- a/stdin.mu
+++ b/stdin.mu
@@ -7,7 +7,7 @@
 ;?   (print-primitive (("main: stdin is " literal)))
 ;?   (print-primitive stdin:channel-address)
 ;?   (print-primitive (("\n" literal)))
-  (fork send-keys-to-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address)
+  (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address)
   ; now read characters from stdin
   (print-primitive (("? " literal)))
   { begin