2019-02-04 02:04:02 +00:00
|
|
|
: stdout ' putc task-emit ! ;
|
|
|
|
|
2019-02-24 17:18:34 +00:00
|
|
|
: >rot <rot <rot ;
|
2019-02-02 20:30:18 +00:00
|
|
|
: 2dup over over ;
|
2019-02-24 17:18:34 +00:00
|
|
|
: 3dup r> 2dup r@ >rot r< ;
|
|
|
|
: 4dup r> r> 2dup r@ >rot rswap r@ >rot r< r< swap ;
|
2019-03-26 02:05:23 +00:00
|
|
|
: nip swap drop ;
|
2019-02-24 15:14:56 +00:00
|
|
|
|
2019-03-01 02:46:04 +00:00
|
|
|
: 2= ( a b c d -- a=c&b=d )
|
|
|
|
r> <rot = swap r< = and ;
|
|
|
|
|
2019-05-01 01:15:25 +00:00
|
|
|
: 2swap ( a b c d -- c d a b )
|
|
|
|
r> >rot r< >rot ;
|
|
|
|
|
2019-03-26 02:05:23 +00:00
|
|
|
: negate 0 swap - ;
|
|
|
|
: abs dup 0 < if negate then ;
|
|
|
|
|
2019-03-01 02:46:04 +00:00
|
|
|
: ~ -1 ^ ;
|
|
|
|
: f! ( b v flag -- )
|
2019-03-26 02:05:23 +00:00
|
|
|
>rot r> r@ @ >rot ( val flag b r: v )
|
|
|
|
if | else ~ & then r< ! ;
|
2019-03-01 02:46:04 +00:00
|
|
|
: f@ ( v flag -- ) swap @ & ;
|
2019-03-26 02:05:23 +00:00
|
|
|
: fnot! ( v flag -- ) over @ ^ swap ! ;
|
2019-03-01 02:46:04 +00:00
|
|
|
|
2019-03-05 22:35:50 +00:00
|
|
|
: expile state if , else execute then ;
|
|
|
|
|
2019-02-26 03:19:08 +00:00
|
|
|
: :noname here $DOCOLON , ] ;
|
2019-02-24 15:14:56 +00:00
|
|
|
|
2019-04-27 15:12:39 +00:00
|
|
|
: withfp ( xt fp -- ) :| factivate execute fdeactivate drop |; preservefp ;
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-27 02:44:22 +00:00
|
|
|
: array word new-word $DOVAR , ;
|
2019-02-26 03:19:08 +00:00
|
|
|
: create word new-word $DOCREATE , 0 , ;
|
|
|
|
|
|
|
|
: finishcreate ( ipfirst -- )
|
|
|
|
( set cell after codepointer to first instruction of does> )
|
|
|
|
latest codepointer cell + ! ;
|
|
|
|
|
|
|
|
: does> here 4 cells + lit ' finishcreate , ' ret , ] ; immediate
|
|
|
|
|
2019-02-24 22:26:28 +00:00
|
|
|
: +towards ( from to -- from+-1 )
|
|
|
|
over > if 1 + else 1 - then ;
|
|
|
|
|
2019-03-05 22:35:50 +00:00
|
|
|
: for ( from to -- )
|
|
|
|
' r> , [ ' begin , ] ( from r: to )
|
|
|
|
' dup , ' r@ , ' != , [ ' while , ]
|
|
|
|
' r> , ; immediate ( r: to from )
|
2019-02-24 17:18:34 +00:00
|
|
|
: i ' r@ , ; immediate
|
2019-03-05 22:35:50 +00:00
|
|
|
: next
|
|
|
|
' r< , ' r@ , ' +towards , ( from+1 r: to )
|
|
|
|
[ ' repeat , ] ' drop , ' rdrop , ; immediate
|
2019-02-24 22:26:28 +00:00
|
|
|
|
2019-03-01 02:46:04 +00:00
|
|
|
: yield rswap ;
|
2019-04-30 23:32:20 +00:00
|
|
|
: done rdrop 0 r> rswap ;
|
|
|
|
: ;done ' done , ] ; immediate
|
|
|
|
: each [ ' begin , ] ' r@ , [ ' while , ] ; immediate
|
|
|
|
: more ' yield , [ ' repeat , ] ' rdrop , ; immediate
|
|
|
|
: break rswap rdrop :| yield done |; execute rswap ;
|
2019-03-01 02:46:04 +00:00
|
|
|
|
2019-04-30 23:32:20 +00:00
|
|
|
: links begin yield @ dup not until drop ;done
|
2019-03-09 23:49:45 +00:00
|
|
|
|
2019-04-30 23:32:20 +00:00
|
|
|
: files findfile begin dup while yield nextfile repeat drop ;done
|
2019-04-27 15:12:39 +00:00
|
|
|
: .files files each type s" " type more ;
|
|
|
|
|
2019-02-24 22:26:28 +00:00
|
|
|
: min ( x y -- x|y ) 2dup > if swap then drop ;
|
|
|
|
: max ( x y -- x|y ) 2dup < if swap then drop ;
|
2019-02-24 17:18:34 +00:00
|
|
|
|
2019-05-09 00:37:40 +00:00
|
|
|
: +!pos ( n var -- ) dup @ <rot + 0 max swap ! ;
|
|
|
|
|
2019-03-10 23:51:24 +00:00
|
|
|
: checkpoint ( cp -- )
|
|
|
|
create here 4 cells + , latest , tasks , ,
|
|
|
|
does> dup @ here!
|
|
|
|
dup cell + @ latest!
|
|
|
|
dup 2 cells + @ tasks!
|
|
|
|
3 cells + @ execute ;
|
|
|
|
|
|
|
|
: intern create latest wordname , does> @ ;
|
|
|
|
|
2019-05-09 00:37:40 +00:00
|
|
|
: preserving ( cp 0 vars... -- )
|
|
|
|
0 r> begin dup while dup @ r> r> repeat drop
|
|
|
|
execute
|
|
|
|
begin r@ while r< r< swap ! repeat rdrop ;
|
|
|
|
: preserve ( cp var -- ) 0 swap preserves ;
|
|
|
|
|
|
|
|
|
2019-02-02 20:30:18 +00:00
|
|
|
: decompile
|
2019-02-04 02:04:02 +00:00
|
|
|
word lookup if 1 begin ( cp i )
|
2019-02-02 20:30:18 +00:00
|
|
|
2dup cells + @ ( cp i @cp+i )
|
2019-02-04 02:04:02 +00:00
|
|
|
dup ' ret != ( cp i @cp+i bool )
|
2019-02-02 20:30:18 +00:00
|
|
|
while
|
2019-02-04 02:04:02 +00:00
|
|
|
dup ` dup if type drop else drop . then bl ( cp i )
|
2019-02-02 20:30:18 +00:00
|
|
|
1 + ( cp i+1 )
|
2019-02-04 02:04:02 +00:00
|
|
|
repeat drop drop then drop ;
|
|
|
|
|
2019-03-10 00:59:52 +00:00
|
|
|
: words latest links each dup wordname type bl more ;
|
|
|
|
|
2019-02-04 02:04:02 +00:00
|
|
|
( tasks )
|
|
|
|
: mailbox 2 cells + ;
|
|
|
|
: task-ip task-user-size cells + ;
|
|
|
|
: task-sp task-user-size 1 + cells + ;
|
|
|
|
: task-rsp task-user-size 2 + cells + ;
|
|
|
|
: task-stack task-user-size 3 + cells + ;
|
|
|
|
: task-rstack task-stack stacksize cells + ;
|
|
|
|
|
2019-03-09 23:49:45 +00:00
|
|
|
: .wordin ( ptr -- )
|
|
|
|
latest links each
|
|
|
|
2dup > if wordname type drop 0 break then
|
|
|
|
more dup if . else drop then ;
|
|
|
|
|
|
|
|
: tasks.s
|
|
|
|
tasks links each
|
|
|
|
dup .wordin s" : " type
|
|
|
|
dup task-sp @ over task-stack ( task stackLim stack )
|
|
|
|
begin 2dup > while dup @ . cell + repeat
|
2019-03-10 23:51:24 +00:00
|
|
|
cr drop drop more ;
|
2019-03-09 23:49:45 +00:00
|
|
|
|
2019-02-04 02:04:02 +00:00
|
|
|
: doactivate ( task ip -- )
|
|
|
|
over task-ip !
|
|
|
|
dup task-stack over task-sp !
|
|
|
|
dup task-rstack over task-rsp !
|
|
|
|
drop
|
|
|
|
;
|
|
|
|
|
|
|
|
: activate
|
|
|
|
here 4 cells + lit
|
|
|
|
' doactivate ,
|
|
|
|
' ret ,
|
|
|
|
; immediate
|
|
|
|
|
2019-03-09 23:49:45 +00:00
|
|
|
: try-send ( val task -- b )
|
|
|
|
mailbox dup @ if drop drop 0 else ! 1 then ;
|
|
|
|
|
|
|
|
: wait-send ( val task -- )
|
2019-02-04 02:04:02 +00:00
|
|
|
mailbox
|
|
|
|
begin dup @ while suspend repeat ( wait for empty mailbox )
|
|
|
|
! ;
|
|
|
|
|
2019-03-09 23:49:45 +00:00
|
|
|
: send ( val task -- ) try-send drop ;
|
|
|
|
|
2019-02-04 02:04:02 +00:00
|
|
|
: receive ( -- val )
|
|
|
|
running mailbox
|
|
|
|
begin dup @ not while suspend repeat ( wait for mail )
|
2019-02-24 17:18:34 +00:00
|
|
|
dup @ 0 <rot ! ;
|
2019-02-04 02:04:02 +00:00
|
|
|
|