about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-10-30 00:37:03 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-10-30 00:37:03 -0700
commit97208a383a5e47a0b611bcaec410dbcd91b1bd4e (patch)
tree0e6a54c4a7577731164e042434b73ccd11220cbd
parent12807afa4f065007d6c818b349764143e2b08c0e (diff)
downloadmu-97208a383a5e47a0b611bcaec410dbcd91b1bd4e.tar.gz
177 - more robust 'die'
-rw-r--r--mu.arc17
1 files changed, 12 insertions, 5 deletions
diff --git a/mu.arc b/mu.arc
index 7d16cdba..21bb4b93 100644
--- a/mu.arc
+++ b/mu.arc
@@ -270,7 +270,15 @@
 (on-init
   (= running-routines* (queue))
   (= completed-routines* (queue))
-  (= routine* nil))
+  (= routine* nil)
+  (= abort-routine* (parameter nil)))
+
+; like arc's 'point' but you can also call ((abort-routine*)) in nested calls
+(mac routine-mark body
+  (w/uniq (g p)
+    `(ccc (fn (,g)
+            (parameterize abort-routine* (fn ((o ,p)) (,g ,p))
+              ,@body)))))
 
 (def run fn-names
   (ret result 0
@@ -280,7 +288,7 @@
     (while (~empty running-routines*)
       (= routine* deq.running-routines*)
       (trace "schedule" top.routine*!fn-name)
-      (let insts-run (run-for-time-slice scheduling-interval*)
+      (whenlet insts-run (routine-mark:run-for-time-slice scheduling-interval*)
         (= result (+ result insts-run)))
       (if (~empty routine*)
         (enq routine* running-routines*)
@@ -289,7 +297,8 @@
 (def die (msg)
   (= rep.routine*!error msg)
   (= rep.routine*!stack-trace rep.routine*!call-stack)
-  (wipe rep.routine*!call-stack))
+  (wipe rep.routine*!call-stack)
+  ((abort-routine*)))
 
 ($:require "charterm/main.rkt")
 
@@ -497,8 +506,6 @@
                         (err "no such op @op"))
                       (continue))
                 )
-              (when rep.routine*!error
-                (return time-slice))
               ; opcode generated some value, stored in 'tmp'
               ; copy to output args
 ;?               (prn "store: " tmp " " oarg)