about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-11-06 15:24:00 -0800
committerKartik K. Agaram <vc@akkartik.com>2014-11-06 15:24:00 -0800
commit6f8b711881db8f4a1f30817ce0ce750b903a47a1 (patch)
tree33365719dd2ad81abd984125ddcd8209b1c1c67d
parentfac6a170edcf1ae79ade2d9d8bdcabacacf6b24f (diff)
downloadmu-6f8b711881db8f4a1f30817ce0ce750b903a47a1.tar.gz
234
-rw-r--r--mu.arc79
1 files changed, 39 insertions, 40 deletions
diff --git a/mu.arc b/mu.arc
index 207349ad..6c1154d9 100644
--- a/mu.arc
+++ b/mu.arc
@@ -131,6 +131,45 @@
     (= function*.name (convert-names:convert-braces body))))
 
 ;; managing concurrent routines
+
+; routine = runtime state for a serial thread of execution
+(def make-routine (fn-name)
+  (annotate 'routine (obj call-stack (list
+      (obj fn-name fn-name  pc 0  caller-arg-idx 0)))))
+
+(defextend empty (x)  (isa x 'routine)
+  (no rep.x!call-stack))
+
+(def stack (routine)
+  ((rep routine) 'call-stack))
+
+(mac push-stack (routine op)
+  `(push (obj fn-name ,op  pc 0  caller-arg-idx 0)
+         ((rep ,routine) 'call-stack)))
+
+(mac pop-stack (routine)
+  `(pop ((rep ,routine) 'call-stack)))
+
+(def top (routine)
+  stack.routine.0)
+
+(def body (routine (o idx 0))
+  (function* stack.routine.idx!fn-name))
+
+(mac pc (routine (o idx 0))  ; assignable
+  `((((rep ,routine) 'call-stack) ,idx) 'pc))
+
+(mac caller-arg-idx (routine (o idx 0))  ; assignable
+  `((((rep ,routine) 'call-stack) ,idx) 'caller-arg-idx))
+
+(= scheduling-interval* 500)
+
+(mac caller-args (routine)  ; assignable
+  `((((rep ,routine) 'call-stack) 0) 'args))
+
+(mac results (routine)  ; assignable
+  `((((rep ,routine) 'call-stack) 0) 'results))
+
 (on-init
   (= running-routines* (queue))
   (= completed-routines* (queue))
@@ -300,40 +339,6 @@
       :else
         (err "can't take len of non-array @operand")))
 
-; data structure: routine
-; runtime state for a serial thread of execution
-
-(def make-routine (fn-name)
-  (annotate 'routine (obj call-stack (list
-      (obj fn-name fn-name  pc 0  caller-arg-idx 0)))))
-
-(defextend empty (x)  (isa x 'routine)
-  (no rep.x!call-stack))
-
-(def stack (routine)
-  ((rep routine) 'call-stack))
-
-(mac push-stack (routine op)
-  `(push (obj fn-name ,op  pc 0  caller-arg-idx 0)
-         ((rep ,routine) 'call-stack)))
-
-(mac pop-stack (routine)
-  `(pop ((rep ,routine) 'call-stack)))
-
-(def top (routine)
-  stack.routine.0)
-
-(def body (routine (o idx 0))
-  (function* stack.routine.idx!fn-name))
-
-(mac pc (routine (o idx 0))  ; assignable
-  `((((rep ,routine) 'call-stack) ,idx) 'pc))
-
-(mac caller-arg-idx (routine (o idx 0))  ; assignable
-  `((((rep ,routine) 'call-stack) ,idx) 'caller-arg-idx))
-
-(= scheduling-interval* 500)
-
 (def parse-instr (instr)
   (iflet delim (pos '<- instr)
     (list (cut instr 0 delim)  ; oargs
@@ -341,12 +346,6 @@
           (cut instr (+ delim 2)))  ; args
     (list nil instr.0 cdr.instr)))
 
-(mac caller-args (routine)  ; assignable
-  `((((rep ,routine) 'call-stack) 0) 'args))
-
-(mac results (routine)  ; assignable
-  `((((rep ,routine) 'call-stack) 0) 'results))
-
 ($:require "charterm/main.rkt")
 
 (def run-for-time-slice (time-slice)