diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-11-06 11:36:16 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-11-06 11:36:16 -0800 |
commit | fac6a170edcf1ae79ade2d9d8bdcabacacf6b24f (patch) | |
tree | 56fcabdd92fcd392819f09e81aed1952da4728e1 | |
parent | c6ea9df84135b5accfdaf554c665a8dc49a00e21 (diff) | |
download | mu-fac6a170edcf1ae79ade2d9d8bdcabacacf6b24f.tar.gz |
233 - start tracking global cycle count
We're gonna need this to implement 'sleep'.
-rw-r--r-- | mu.arc | 28 | ||||
-rw-r--r-- | mu.arc.t | 18 |
2 files changed, 25 insertions, 21 deletions
diff --git a/mu.arc b/mu.arc index 06fd2f0b..207349ad 100644 --- a/mu.arc +++ b/mu.arc @@ -135,7 +135,8 @@ (= running-routines* (queue)) (= completed-routines* (queue)) (= routine* nil) - (= abort-routine* (parameter nil))) + (= abort-routine* (parameter nil)) + (= curr-cycle* 0)) ; like arc's 'point' but you can also call ((abort-routine*)) in nested calls (mac routine-mark body @@ -145,18 +146,16 @@ ,@body))))) (def run fn-names - (ret result 0 - (each it fn-names - (enq make-routine.it running-routines*)) - ; simple round-robin scheduler - (while (~empty running-routines*) - (= routine* deq.running-routines*) - (trace "schedule" top.routine*!fn-name) - (whenlet insts-run (routine-mark:run-for-time-slice scheduling-interval*) - (= result (+ result insts-run))) - (if (~empty routine*) - (enq routine* running-routines*) - (enq-limit routine* completed-routines*))))) + (each it fn-names + (enq make-routine.it running-routines*)) + ; simple round-robin scheduler + (while (~empty running-routines*) + (= routine* deq.running-routines*) + (trace "schedule" top.routine*!fn-name) + (routine-mark:run-for-time-slice scheduling-interval*) + (if (~empty routine*) + (enq routine* running-routines*) + (enq-limit routine* completed-routines*)))) (def die (msg) (= rep.routine*!error msg) @@ -358,8 +357,9 @@ (pop-stack routine*) (if empty.routine* (return ninstrs)) (++ pc.routine*)) + (++ curr-cycle*) (trace "run" "-- " int-canon.memory*) - (trace "run" top.routine*!fn-name " " pc.routine* ": " (body.routine* pc.routine*)) + (trace "run" curr-cycle* " " top.routine*!fn-name " " pc.routine* ": " (body.routine* pc.routine*)) ;? (trace "run" routine*) (let (oarg op arg) (parse-instr (body.routine* pc.routine*)) (let tmp diff --git a/mu.arc.t b/mu.arc.t index ecfcb643..0438033a 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -831,8 +831,10 @@ ((1 integer) <- copy (1 literal))) (main (test1)))) -(if (~is 2 (run 'main)) - (prn "F - calling a user-defined function runs its instructions exactly once")) +;? (= dump-trace* (obj whitelist '("run"))) +(run 'main) +(if (~is 2 curr-cycle*) + (prn "F - calling a user-defined function runs its instructions exactly once " curr-cycle*)) ;? (quit) ; User-defined functions communicate with their callers through two @@ -885,8 +887,10 @@ ((1 integer) <- copy (1 literal)) ((2 integer) <- copy (3 literal)) (test1)))) -(if (~is 4 (run 'main)) ; last reply sometimes not counted. worth fixing? - (prn "F - 'reply' executes instructions exactly once")) +;? (= dump-trace* (obj whitelist '("run"))) +(run 'main) +(if (~is 5 curr-cycle*) + (prn "F - 'reply' executes instructions exactly once " curr-cycle*)) ;? (quit) (reset) @@ -1636,9 +1640,9 @@ ((1 integer) <- copy (3 literal))) (f2 ((2 integer) <- copy (4 literal))))) -(let ninsts (run 'f1 'f2) - (when (~iso 2 ninsts) - (prn "F - scheduler didn't run the right number of instructions: " ninsts))) +(run 'f1 'f2) +(when (~iso 2 curr-cycle*) + (prn "F - scheduler didn't run the right number of instructions: " curr-cycle*)) (if (~iso memory* (obj 1 3 2 4)) (prn "F - scheduler runs multiple functions: " memory*)) (check-trace-contents "scheduler orders functions correctly" |