|:#############: Scheduler input and config :#############: | || :cycle size: 10 || :: Start from 0 and step by 1000 milliseconds :schedule: Task1 for 1 :schedule: Task2 for 2 :schedule: Task3 for 3 :schedule: ThreeSecondTask for 3 :schedule: Task4 for 4 :schedule: FiveSecondTask for 5 :schedule: EightSecondTask for 8 :schedule: Task9 for 9 :schedule: Task10 for 10 :schedule: Task11 for 11 :schedule: Task15 for 15 :schedule: Task21 for 21 :schedule: Halt for 21 |:#############: Task definitions :#############: | | :run: Halt :clock: $t ? | :@stdio: println Goodbye! :log: Halting from schedule at time $t :: Halt | :run: $task :clock: $t ? | :@stdio: println $task :log: [ Time $t ] running task - $task |:#############: Helpers :#############: | | :let: $variable = :@math: $result | :: $variable = $result |:#############: Debug helpers :#############: | | :clock: $t ? :cycle: $c $i ? :debug: $d | :@stdio: write [dbg] :@stdio: write 32 :@stdio: write [ :@stdio: write clock :@stdio: write 32 :@stdio: print $t :@stdio: write ] :@stdio: write 32 :@stdio: println $d |:#############: Rules :#############: | | :: Start from $start_time and step by $time_step $units | :clock t0: $start_time :clock: 0 :time step: $time_step $units :cycle: 0 0 :: Run process loop | :: Run process loop | :: Check for new tasks :: Run current tasks :: Sleep :: Update clock :: Update future tasks :: Run process loop | :: Sleep :time step: $time_step $unit ? | :: Wake :@time: sleep $time_step $unit :log: Sleeping for $time_step $unit | :: Wake :@time: done | :log: Woken from sleep |:#############: Clock :#############: | | :: Update clock :clock t0: $t0 ? :clock: $t :cycle size: $N ? :cycle: $c $i ? | :let: next_clock = :@math: add $t 1 :let: next_cycle_index = :@math: add $i 1 :log: Updating clock | :: next_clock = $t | :clock: $t | :: next_cycle_index = $i :cycle: $c $_ :cycle size: $N ? | :cycle: $c $i :: check for cycle rollover :@math: compare $i $N :log: Checking for cycle rollover | :: check for cycle rollover :@math: equal | :: reset cycle :log: The cycle rolls over | :: check for cycle rollover :@math: greater | :: reset cycle :log: The cycle rolls over | :: check for cycle rollover :@math: less | :log: No cycle rollover | :: reset cycle :cycle: $c $i ? | :let: next_cycle = :@math: add $c 1 | :: next_cycle = $c :cycle: $_1 $_2 | :cycle: $c 0 :log: Next cycle is $c |:#############: Tasks :#############: | | :: Check for new tasks ? :schedule: $task for $time ? :clock t0: $t0 ? | :log: Calculating cycle for $time :let: time_diff = :@math: subtract $time $t0 | :: time_diff = $result :cycle size: $N ? | :let: time_cycle = :@math: antimodulo $result $N :let: time_index = :@math: modulo $result $N | :schedule: $task for $time ? :: time_index = $index_result :: time_cycle = $cycle_result | :: Time $time will occur at cycle $cycle_result and index $index_result :log: Calculated time $time will occur at cycle $cycle_result and index $index_result | :###: Case A; the new task is in the current cycle | | :: Time $time will occur at cycle $current_cycle and index $i :schedule: $task for $time :cycle: $current_cycle $_ ? | :: Push $task to timestack $i | :###: Case B; the new task is in a future :###: assume that new tasks will not be in the past, so this is a default case | | :: Time $time will occur at cycle $c and index $i :schedule: $task for $time | :future: $time $c $i $task | :: Check for new tasks | |:###: Pulling tasks from the future to the present :###: the future stack is currently unsorted, so this could be optimized | | :: Update future tasks ? :future: $time $c $i $task :cycle: $c 0 ? | :: Push $task to timestack $i | :: Update future tasks ? :future: $time $c $i $task | :next future: $time $c $i $task | :: Update future tasks | :log: No future-era tasks to update | :###: NB this rule has gotta come after the prior rules | | :next future: $time $c $i $task | :future: #time $c $i $task |:#############: pushy push :#############: | | :: Push $task to timestack 0 | :timestack 0: $task | :: Push $task to timestack 1 | :timestack 1: $task | :: Push $task to timestack 2 | :timestack 2: $task | :: Push $task to timestack 3 | :timestack 3: $task | :: Push $task to timestack 4 | :timestack 4: $task | :: Push $task to timestack 5 | :timestack 5: $task | :: Push $task to timestack 6 | :timestack 6: $task | :: Push $task to timestack 7 | :timestack 7: $task | :: Push $task to timestack 8 | :timestack 8: $task | :: Push $task to timestack 9 | :timestack 9: $task |:#############: Task running :#############: | | :: Run current tasks ? :cycle: $_ 0 ? :timestack 0: $task | :run: $task | :: Run current tasks ? :cycle: $_ 1 ? :timestack 1: $task | :run: $task | :: Run current tasks ? :cycle: $_ 2 ? :timestack 2: $task | :run: $task | :: Run current tasks ? :cycle: $_ 3 ? :timestack 3: $task | :run: $task | :: Run current tasks ? :cycle: $_ 4 ? :timestack 4: $task | :run: $task | :: Run current tasks ? :cycle: $_ 5 ? :timestack 5: $task | :run: $task | :: Run current tasks ? :cycle: $_ 6 ? :timestack 6: $task | :run: $task | :: Run current tasks ? :cycle: $_ 7 ? :timestack 7: $task | :run: $task | :: Run current tasks ? :cycle: $_ 8 ? :timestack 8: $task | :run: $task | :: Run current tasks ? :cycle: $_ 9 ? :timestack 9: $task | :run: $task | :: Run current tasks |