From bfdfcf74260485a8ce85a6522583dce948f28c60 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 11 Jan 2015 22:54:51 -0800 Subject: 536 - introduce a notion of helper routines When all you have left to run are helper routines, end the simulation. --- mu.arc | 17 ++++++++++++++++- stdin.mu | 2 +- 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 -- cgit 1.4.1-2-gfad0