about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--mu.arc18
-rw-r--r--mu.arc.t24
2 files changed, 37 insertions, 5 deletions
diff --git a/mu.arc b/mu.arc
index b8f6137b..75660d15 100644
--- a/mu.arc
+++ b/mu.arc
@@ -181,13 +181,20 @@
   (let (oargs _ _)  (parse-instr ((body context 1) (pc context 1)))
     oargs))
 
-(def run (fn-name)
+(= contexts* (queue))
+
+(def run ((o fn-name))
   (ret result 0
-    (let context (make-context fn-name)
-      (while (~empty context)
-;?         (prn "== " context)
+    (aif fn-name
+      (enq make-context.it contexts*))
+    ; simple round-robin scheduler
+    (while (~empty contexts*)
+      (let context deq.contexts*
+        (trace "schedule" top.context!fn-name)
         (let insts-run (run-for-time-slice context scheduling-interval*)
-          (= result (+ result insts-run)))))))
+          (= result (+ result insts-run)))
+        (if (~empty context)
+          (enq context contexts*))))))
 
 (def run-for-time-slice (context time-slice)
 ;?   (prn "AAA")
@@ -199,6 +206,7 @@
         (pop-stack context)
         (if empty.context (return ninstrs))
         (++ pc.context))
+      (trace "run" top.context!fn-name " " pc.context ": " (body.context pc.context))
 ;?       (prn "--- " top.context!fn-name " " pc.context ": " (body.context pc.context))
 ;?       (prn "  " memory*)
       (let (oarg op arg)  (parse-instr (body.context pc.context))
diff --git a/mu.arc.t b/mu.arc.t
index f02f9610..2ab4d9c8 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -662,3 +662,27 @@
     (prn "F - 'new' returns current high-water mark"))
   (if (~iso Memory-in-use-until (+ before 5))
     (prn "F - 'new' on primitive arrays increments high-water mark by their size")))
+
+(reset)
+(add-fns
+  '((f1
+      ((1 integer) <- literal 3))
+    (f2
+      ((2 integer) <- literal 4))))
+(enq make-context!f1 contexts*)
+(enq make-context!f2 contexts*)
+(let ninsts (run)
+  (when (~iso 2 ninsts)
+    (prn "F - scheduler didn't run the right number of instructions: " ninsts)))
+(if (~iso memory* (obj 1 3  2 4))
+  (prn "F - scheduler runs multiple functions: " memory*))
+(check-trace-contents "scheduler orders functions correctly"
+  '(("schedule" "f1")
+    ("schedule" "f2")
+  ))
+(check-trace-contents "scheduler orders schedule and run events correctly"
+  '(("schedule" "f1")
+    ("run" "f1 0")
+    ("schedule" "f2")
+    ("run" "f2 0")
+  ))
c442a5ad ^

62c6d163 ^
292ccba1 ^

c442a5ad ^
292ccba1 ^




4a943d4e ^

6f6d458f ^

4a943d4e ^

83c67014 ^
4a943d4e ^






6f6d458f ^
4a943d4e ^



292ccba1 ^


c442a5ad ^
222c31db ^
292ccba1 ^

c442a5ad ^

292ccba1 ^


4a943d4e ^

6f6d458f ^

4a943d4e ^

83c67014 ^
4a943d4e ^


83c67014 ^
4a943d4e ^




6f6d458f ^
4a943d4e ^



292ccba1 ^


0f851e48 ^

aa2e2155 ^
4a943d4e ^

6f6d458f ^

36c745f8 ^
4a943d4e ^
83c67014 ^
4a943d4e ^

83c67014 ^
4a943d4e ^







292ccba1 ^


c442a5ad ^

292ccba1 ^
c442a5ad ^
292ccba1 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122