69 |
val stop : unit -> code |
val stop : unit -> code |
70 |
val suspend : unit -> code |
val suspend : unit -> code |
71 |
val action : (machine -> unit) -> code |
val action : (machine -> unit) -> code |
72 |
val exec : { |
val exec : (machine -> {stop : unit -> unit, done : unit -> bool}) -> code |
|
start : machine -> unit, |
|
|
stop : machine -> unit, |
|
|
done : machine -> bool |
|
|
} -> code |
|
73 |
val ifThenElse : ((machine -> bool) * code * code) -> code |
val ifThenElse : ((machine -> bool) * code * code) -> code |
74 |
val repeat : (int * code) -> code |
val repeat : (int * code) -> code |
75 |
val loop : code -> code |
val loop : code -> code |
257 |
} |
} |
258 |
end |
end |
259 |
|
|
260 |
fun exec {start, stop, done} = let |
fun exec f = let |
261 |
val termFlg = ref false |
val termFlg = ref false |
262 |
val running = ref false |
val ops = ref(NONE : {stop : unit -> unit, done : unit -> bool} option) |
263 |
(** NOTE: what if a reset occurs while we are running? We would need to change |
(** NOTE: what if a reset occurs while we are running? We would need to change |
264 |
** the type of resetMeth to take a machine parameter. |
** the type of resetMeth to take a machine parameter. |
265 |
**) |
**) |
266 |
fun resetMeth () = (termFlg := false) |
fun resetMeth () = (termFlg := false) |
267 |
fun preemptMeth m = if !running then (running := false; stop m) else () |
fun preemptMeth m = (case !ops |
268 |
fun activationMeth m = if !running |
of NONE => () |
269 |
then if done m |
| SOME{stop, ...} => (ops := NONE; stop()) |
270 |
then (running := false; TERM) |
(* end case *)) |
271 |
|
fun activationMeth m = (case !ops |
272 |
|
of SOME{done, ...} => if done () |
273 |
|
then (ops := NONE; TERM) |
274 |
else STOP |
else STOP |
275 |
else (running := true; start m; SUSP) |
| NONE => (ops := SOME(f m); SUSP) |
276 |
|
(* end case *)) |
277 |
in |
in |
278 |
C{ isTerm = isTermMeth termFlg, |
C{ isTerm = isTermMeth termFlg, |
279 |
terminate = terminateMeth termFlg, |
terminate = terminateMeth termFlg, |