2019-02-04 02:04:02 +00:00
|
|
|
: stdout ' putc task-emit ! ;
|
2019-02-24 17:18:34 +00:00
|
|
|
s" jorth.log" open seekend deactivate const LOGFILE
|
|
|
|
: withfp ( xt fp -- ) fdeactivate r> factivate execute fdeactivate drop r< factivate ;
|
|
|
|
: log-emit ' fputc LOGFILE withfp ;
|
2019-02-04 02:04:02 +00:00
|
|
|
|
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-02-24 15:14:56 +00:00
|
|
|
|
2019-02-11 00:17:58 +00:00
|
|
|
: noop ;
|
|
|
|
|
2019-02-24 15:14:56 +00:00
|
|
|
' cells @ const docolon ( get the colon execution token )
|
|
|
|
: :noname here docolon , ] ;
|
|
|
|
|
|
|
|
: :| inline| :noname ; immediate
|
|
|
|
: |; ' ret , |inline ; immediate
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-11 00:17:58 +00:00
|
|
|
: defer word new-word docolon , ' noop , ' ret , ;
|
2019-02-12 04:23:00 +00:00
|
|
|
: redefine ( cp cpdeferred ) cell + ! ;
|
2019-02-02 20:30:18 +00:00
|
|
|
|
2019-02-24 22:26:28 +00:00
|
|
|
: +towards ( from to -- from+-1 )
|
|
|
|
over > if 1 + else 1 - then ;
|
|
|
|
|
|
|
|
: for ( from to -- ) ' r> , here ' r> , ; immediate ( r: to from )
|
2019-02-24 17:18:34 +00:00
|
|
|
: i ' r@ , ; immediate
|
2019-02-24 22:26:28 +00:00
|
|
|
: next ' r< , ' r@ , ' +towards , ( from+1 r: to )
|
|
|
|
' dup , ' r@ , ' = , ' BZ_ , ,
|
|
|
|
' rdrop , ' drop , ; immediate
|
|
|
|
|
|
|
|
: 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-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 ;
|
|
|
|
|
|
|
|
( 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 + ;
|
|
|
|
|
|
|
|
: 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
|
|
|
|
|
|
|
|
: send ( val task -- )
|
|
|
|
mailbox
|
|
|
|
begin dup @ while suspend repeat ( wait for empty mailbox )
|
|
|
|
! ;
|
|
|
|
|
|
|
|
: 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
|
|
|
|