flagxor / ueforth

Apache License 2.0
90 stars 26 forks source link

Extra task words #33

Open Eszartek opened 1 year ago

Eszartek commented 1 year ago

I'm not sure of the usefullness of these words, but it was fun trying to figure them out.

stop-task will stop a running task. It's actually a suspend, as you can restart the task and then the stopped task will continue where it left off. It just takes the task out of the circular task list. ie:mytask stop-task

: stop-task ( t -- ) task-list @ begin 2dup @ = if swap @ swap ! exit then @ dup task-list @ = until ;

.ts works like .s but for a task. If your task has a pause in it to allow the webui to stay responsive, then .ts will show the stack at the pause and print the name of the next word after the pause. If I have multiple pauses, then I usually define empty marker words like : mark1 ; and place this after each pause so that .ts will indicate at which mark it is at, using a different mark word for each pause. ie: mytask .ts

: tdepth ( t -- n ) dup 4 + @ swap 8 +  - cell/ ;  ( current stack depth for a task )
: .ts ( t -- ) dup dup ." <" tdepth 1 - n. ." > " tdepth 0 max for aft dup 4 + @  r@  cells - @ r@ 0= if ."  -> " @ @  >name type else . then then next drop ;

Output example: <4> 2 66 7 1 -> mark1